]> gitweb.factorcode.org Git - factor.git/commitdiff
FUEL: More robust listener/emacs protocol; small fixes to the help mode.
authorJose A. Ortega Ruiz <jao@gnu.org>
Tue, 16 Dec 2008 23:08:05 +0000 (00:08 +0100)
committerJose A. Ortega Ruiz <jao@gnu.org>
Tue, 16 Dec 2008 23:08:05 +0000 (00:08 +0100)
extra/fuel/fuel.factor
misc/fuel/README
misc/fuel/fuel-connection.el
misc/fuel/fuel-eval.el
misc/fuel/fuel-help.el
misc/fuel/fuel-listener.el

index bf36969219123597e8cd936cd652fb14dc713929..4535ac7fd6612e1b02f22dc0f20ef28f1e203f2a 100644 (file)
@@ -112,7 +112,7 @@ M: source-file fuel-pprint path>> fuel-pprint ;
     error get
     fuel-eval-result get-global
     fuel-eval-output get-global
-    3array fuel-pprint ;
+    3array fuel-pprint flush nl "EOT:" write ;
 
 : fuel-forget-error ( -- ) f error set-global ; inline
 : fuel-forget-result ( -- ) f fuel-eval-result set-global ; inline
index 9686124813c6ca4536868da8b066cfae6954293e..79c24ec69f0c3bc57a61db582ebf2b1432511b1f 100644 (file)
@@ -47,8 +47,8 @@ M-x customize-group fuel will show you how many.
 Quick key reference
 -------------------
 
-(Chords ending in a single letter <x> accept also C-<x> (e.g. C-cC-z is
-the same as C-cz)).
+(Triple chords ending in a single letter <x> accept also C-<x> (e.g.
+C-cC-eC-r is the same as C-cC-er)).
 
 * In factor source files:
 
index af793057ff6f894a9f9e3f7449e1cb69773960cd..da621b3bebf6fa4d61c688299e66e36d18484fb0 100644 (file)
 
 ;;; Code:
 
-(require 'fuel-base)
 (require 'fuel-log)
+(require 'fuel-base)
+
+(require 'comint)
+(require 'advice)
 
 \f
 ;;; Default connection:
 \f
 ;;; Connection setup:
 
+(defun fuel-con--cleanup-connection (c)
+  (fuel-con--connection-cancel-timer c))
+
 (defun fuel-con--setup-connection (buffer)
   (set-buffer buffer)
+  (fuel-con--cleanup-connection fuel-con--connection)
   (let ((conn (fuel-con--make-connection buffer)))
     (fuel-con--setup-comint)
     (prog1
         (setq fuel-con--connection conn)
       (fuel-con--connection-start-timer conn))))
 
+(defconst fuel-con--prompt-regex "( .+ ) ")
+(defconst fuel-con--eot-marker "EOT:")
+(defconst fuel-con--init-stanza (format "USE: fuel %S write" fuel-con--eot-marker))
+
+(defconst fuel-con--comint-finished-regex
+  (format "%s%s" fuel-con--eot-marker fuel-con--prompt-regex))
+
 (defun fuel-con--setup-comint ()
+  (comint-redirect-cleanup)
   (add-hook 'comint-redirect-filter-functions
             'fuel-con--comint-redirect-filter t t)
   (add-hook 'comint-redirect-hook
-            'fuel-con--comint-redirect-hook))
+            'fuel-con--comint-redirect-hook nil t))
+
+(defadvice comint-redirect-setup (after fuel-con--advice activate)
+  (setq comint-redirect-finished-regexp fuel-con--comint-finished-regex))
 
 \f
 ;;; Requests handling:
         (error (fuel-log--error "<%s>: continuation failed %S \n\t%s"
                                 id rstr cerr))))))
 
+(defvar fuel-con--debug-comint-p nil)
+
 (defun fuel-con--comint-redirect-filter (str)
   (if (not fuel-con--connection)
       (fuel-log--error "No connection in buffer (%s)" str)
       (if (not req) (fuel-log--error "No current request (%s)" str)
         (fuel-con--request-output req str)
         (fuel-log--info "<%s>: in progress" (fuel-con--request-id req)))))
-  (fuel--shorten-str str 70))
+  (if fuel-con--debug-comint-p (fuel--shorten-str str 256) ""))
 
 (defun fuel-con--comint-redirect-hook ()
   (if (not fuel-con--connection)
       (fuel-log--error "No connection in buffer")
     (let ((req (fuel-con--connection-current-request fuel-con--connection)))
-      (if (not req) (fuel-log--error "No current request (%s)" str)
+      (if (not req) (fuel-log--error "No current request")
         (fuel-con--process-completed-request req)
         (fuel-con--connection-clean-current-request fuel-con--connection)))))
 
index f14e4a922cdcd0d197613339bc6ed3d111542ac9..ca71012ec54777532ee5fbdca6a517ae583c766e 100644 (file)
@@ -76,7 +76,6 @@
         ((listp usings) `(:array ,@usings))
         (t (error "Invalid 'usings' (%s)" usings))))
 
-
 \f
 ;;; Code sending:
 
index 8170b31a1bb89529fddbfea8d707ad9dab48e93d..1b9cd9b1212f188f19244fbceb49d9f0caecd055 100644 (file)
@@ -108,14 +108,15 @@ displayed in the minibuffer."
 ;;; Help browser history:
 
 (defvar fuel-help--history
-  (list nil
-        (make-ring fuel-help-history-cache-size)
-        (make-ring fuel-help-history-cache-size)))
+  (list nil                                        ; current
+        (make-ring fuel-help-history-cache-size)   ; previous
+        (make-ring fuel-help-history-cache-size))) ; next
 
 (defvar fuel-help--history-idx 0)
 
 (defun fuel-help--history-push (term)
-  (when (car fuel-help--history)
+  (when (and (car fuel-help--history)
+             (not (string= (caar fuel-help--history) (car term))))
     (ring-insert (nth 1 fuel-help--history) (car fuel-help--history)))
   (setcar fuel-help--history term))
 
@@ -135,7 +136,7 @@ displayed in the minibuffer."
 ;;; Fuel help buffer and internals:
 
 (defun fuel-help--help-buffer ()
-  (with-current-buffer (get-buffer-create "*fuel-help*")
+  (with-current-buffer (get-buffer-create "*fuel help*")
     (fuel-help-mode)
     (current-buffer)))
 
@@ -157,7 +158,7 @@ displayed in the minibuffer."
 (defun fuel-help--show-help-cont (def ret)
   (let ((out (fuel-eval--retort-output ret)))
     (if (or (fuel-eval--retort-error ret) (empty-string-p out))
-        (message "No help for '%s'" ret)
+        (message "No help for '%s'" def)
       (fuel-help--insert-contents def out))))
 
 (defun fuel-help--insert-contents (def str &optional nopush)
@@ -167,14 +168,15 @@ displayed in the minibuffer."
     (set-buffer hb)
     (erase-buffer)
     (insert str)
-    (goto-char (point-min))
-    (when (re-search-forward (format "^%s" def) nil t)
-      (beginning-of-line)
-      (kill-region (point-min) (point))
-      (next-line)
-      (open-line 1))
+    (unless nopush
+      (goto-char (point-min))
+      (when (re-search-forward (format "^%s" def) nil t)
+        (beginning-of-line)
+        (kill-region (point-min) (point))
+        (next-line)
+        (open-line 1)
+        (fuel-help--history-push (cons def (buffer-string)))))
     (set-buffer-modified-p nil)
-    (unless nopush (fuel-help--history-push (cons def str)))
     (pop-to-buffer hb)
     (goto-char (point-min))
     (message "%s" def)))
index f2dc760f94e58827bd56529b3a83373f5ece451d..c1e8d670cf8705920c26cc8aba9fc067bfd65209 100644 (file)
 ;;; Code:
 
 (require 'fuel-eval)
-(require 'fuel-base)
 (require 'fuel-completion)
+(require 'fuel-connection)
 (require 'fuel-syntax)
+(require 'fuel-base)
+
 (require 'comint)
 
 \f
@@ -63,19 +65,21 @@ buffer."
 
 (defun fuel-listener--start-process ()
   (let ((factor (expand-file-name fuel-listener-factor-binary))
-        (image (expand-file-name fuel-listener-factor-image)))
+        (image (expand-file-name fuel-listener-factor-image))
+        (comint-redirect-perform-sanity-check nil))
     (unless (file-executable-p factor)
       (error "Could not run factor: %s is not executable" factor))
     (unless (file-readable-p image)
       (error "Could not run factor: image file %s not readable" image))
     (message "Starting FUEL listener ...")
-    (comint-exec (fuel-listener--buffer) "factor"
-                 factor nil `("-run=listener" ,(format "-i=%s" image)))
     (pop-to-buffer (fuel-listener--buffer))
-    (goto-char (point-max))
-    (comint-send-string nil "USE: fuel \"FUEL loaded\\n\" write\n")
-    (fuel-listener--wait-for-prompt 30)
-    (message "FUEL listener up and running!")))
+    (make-comint-in-buffer "fuel listener" (current-buffer) factor nil
+                           "-run=listener" (format "-i=%s" image))
+    (fuel-listener--wait-for-prompt 10000)
+    (fuel-con--send-string/wait (current-buffer)
+                                fuel-con--init-stanza
+                                '(lambda (s) (message "FUEL listener up and running!"))
+                                20000)))
 
 (defun fuel-listener--process (&optional start)
   (or (and (buffer-live-p (fuel-listener--buffer))
@@ -87,21 +91,15 @@ buffer."
 
 (setq fuel-eval--default-proc-function 'fuel-listener--process)
 
-\f
-;;; Prompt chasing
-
-(defun fuel-listener--wait-for-prompt (&optional timeout)
-  (let ((proc (get-buffer-process (fuel-listener--buffer)))
-        (seen))
-    (with-current-buffer (fuel-listener--buffer)
-      (goto-char (or comint-last-input-end (point-max)))
-      (while (and (not seen)
-                  (accept-process-output proc (or timeout 10) nil t))
-        (sleep-for 0 1)
-        (goto-char comint-last-input-end)
-        (setq seen (re-search-forward comint-prompt-regexp nil t)))
-      (goto-char (point-max))
-      (unless seen (error "No prompt found!")))))
+(defun fuel-listener--wait-for-prompt (timeout)
+  (let ((p (point)) (seen))
+    (while (and (not seen) (> timeout 0))
+      (sleep-for 0.1)
+      (setq timeout (- timeout 100))
+      (goto-char p)
+      (setq seen (re-search-forward comint-prompt-regexp nil t)))
+    (goto-char (point-max))
+    (unless seen (error "No prompt found!"))))
 
 \f
 ;;; Completion support
@@ -132,12 +130,10 @@ buffer."
 \f
 ;;; Fuel listener mode:
 
-(defconst fuel-listener--prompt-regex ".* ) ")
-
 (define-derived-mode fuel-listener-mode comint-mode "Fuel Listener"
   "Major mode for interacting with an inferior Factor listener process.
 \\{fuel-listener-mode-map}"
-  (set (make-local-variable 'comint-prompt-regexp) fuel-listener--prompt-regex)
+  (set (make-local-variable 'comint-prompt-regexp) fuel-con--prompt-regex)
   (set (make-local-variable 'comint-prompt-read-only) t)
   (fuel-listener--setup-completion))