]> gitweb.factorcode.org Git - factor.git/commitdiff
FUEL: Ooops, infinite recursion fix.
authorJose A. Ortega Ruiz <jao@gnu.org>
Sat, 13 Dec 2008 02:40:36 +0000 (03:40 +0100)
committerJose A. Ortega Ruiz <jao@gnu.org>
Sat, 13 Dec 2008 02:40:36 +0000 (03:40 +0100)
misc/fuel/fuel-connection.el
misc/fuel/fuel-debug.el
misc/fuel/fuel-help.el

index 191424589c93bf87110484803d425106c8b1766c..247657aa8cae7d0a51c84abf2a3a7812d6647bdb 100644 (file)
@@ -96,7 +96,8 @@
   (let ((reqs (assoc :requests c))
         (current (assoc :current c)))
     (setcdr current (prog1 (cadr reqs) (setcdr reqs (cddr reqs))))
-    (if (and current (fuel-con--request-deactivated-p current))
+    (if (and (cdr current)
+             (fuel-con--request-deactivated-p (cdr current)))
         (fuel-con--connection-pop-request c)
       current)))
 
   (add-hook 'comint-redirect-filter-functions
             'fuel-con--comint-redirect-filter t t))
 
+\f
+;;; Logging:
+
+(defvar fuel-con--log-size 32000
+  "Maximum size of the Factor messages log.")
+
+(defvar fuel-con--log-verbose-p t
+  "Log level for Factor messages.")
+
+(define-derived-mode factor-messages-mode fundamental-mode "Factor Messages"
+  "Simple mode to log interactions with the factor listener"
+  (kill-all-local-variables)
+  (buffer-disable-undo)
+  (set (make-local-variable 'comint-redirect-subvert-readonly) t)
+  (add-hook 'after-change-functions
+            '(lambda (b e len)
+               (let ((inhibit-read-only t))
+                 (when (> b fuel-con--log-size)
+                   (delete-region (point-min) b))))
+            nil t)
+  (setq buffer-read-only t))
+
+(defun fuel-con--log-buffer ()
+  (or (get-buffer "*factor messages*")
+      (save-current-buffer
+        (set-buffer (get-buffer-create "*factor messages*"))
+        (factor-messages-mode)
+        (current-buffer))))
+
+(defsubst fuel-con--log-msg (type &rest args)
+  (format "\n%s: %s\n" type (apply 'format args)))
+
+(defsubst fuel-con--log-warn (&rest args)
+  (apply 'fuel-con--log-msg 'WARNING args))
+
+(defsubst fuel-con--log-error (&rest args)
+  (apply 'fuel-con--log-msg 'ERROR args))
+
+(defsubst fuel-con--log-info (&rest args)
+  (if fuel-con--log-verbose-p (apply 'fuel-con--log-msg 'INFO args) ""))
+
 \f
 ;;; Requests handling:
 
            (str (and req (fuel-con--request-string req))))
       (when (and buffer req str)
         (set-buffer buffer)
-        (comint-redirect-send-command str
-                                      (get-buffer-create "*factor messages*")
-                                      nil
-                                      t)))))
+        (when fuel-con--log-verbose-p
+          (with-current-buffer (fuel-con--log-buffer)
+            (let ((inhibit-read-only t))
+              (insert (fuel-con--log-info "<%s>: %s"
+                                          (fuel-con--request-id req) str)))))
+        (comint-redirect-send-command str (fuel-con--log-buffer) nil t)))))
 
 (defun fuel-con--comint-redirect-filter (str)
   (if (not fuel-con--connection)
-      (format "\nERROR: No connection in buffer (%s)\n" str)
+      (fuel-con--log-error "No connection in buffer (%s)" str)
     (let ((req (fuel-con--connection-current-request fuel-con--connection)))
-      (if (not req) (format "\nERROR: No current request (%s)\n" str)
+      (if (not req) (fuel-con--log-error "No current request (%s)" str)
         (let ((cont (fuel-con--request-continuation req))
               (id (fuel-con--request-id req))
               (rstr (fuel-con--request-string req))
               (buffer (fuel-con--request-buffer req)))
           (prog1
               (if (not cont)
-                  (format "\nWARNING: Droping result for request %s:%S (%s)\n"
-                          id rstr str)
+                  (fuel-con--log-warn "<%s> Droping result for request %S (%s)"
+                                      id rstr str)
                 (condition-case cerr
                     (with-current-buffer (or buffer (current-buffer))
                       (funcall cont str)
-                      (format "\nINFO: %s:%S processed\nINFO: %s\n" id rstr str))
-                  (error (format "\nERROR: continuation failed %s:%S \nERROR: %s\n"
-                                 id rstr cerr))))
+                      (fuel-con--log-info "<%s>: processed\n\t%s" id str))
+                  (error (fuel-con--log-error "<%s>: continuation failed %S \n\t%s"
+                                              id rstr cerr))))
             (fuel-con--connection-clean-current-request fuel-con--connection)))))))
 
 \f
index ad9f47ceb1a62fba34bdab6d907fdf0ea06c215f..a7c06e4b3e92485a8d606a1a818b1045f1c1a16a 100644 (file)
@@ -253,13 +253,14 @@ invoking restarts as needed.
 \\{fuel-debug-mode-map}"
   (interactive)
   (kill-all-local-variables)
+  (buffer-disable-undo)
   (setq major-mode 'factor-mode)
   (setq mode-name "Fuel Debug")
   (use-local-map fuel-debug-mode-map)
   (fuel-debug--font-lock-setup)
   (setq fuel-debug--file nil)
   (setq fuel-debug--last-ret nil)
-  (toggle-read-only 1)
+  (setq buffer-read-only t)
   (run-hooks 'fuel-debug-mode-hook))
 
 \f
index 227778934a889800cdda1befb6d6a763bd993b7c..1d39d1571dc95bcd3d10bc61a4ad6f996da48e25 100644 (file)
@@ -261,6 +261,7 @@ buffer."
 \\{fuel-help-mode-map}"
   (interactive)
   (kill-all-local-variables)
+  (buffer-disable-undo)
   (use-local-map fuel-help-mode-map)
   (setq mode-name "Factor Help")
   (setq major-mode 'fuel-help-mode)
@@ -271,7 +272,7 @@ buffer."
   (fuel-autodoc-mode)
 
   (run-mode-hooks 'fuel-help-mode-hook)
-  (toggle-read-only 1))
+  (setq buffer-read-only t))
 
 \f
 (provide 'fuel-help)