diff --git a/misc/fuel/factor-mode.el b/misc/fuel/factor-mode.el index 394f6c41f9..d3a633910c 100644 --- a/misc/fuel/factor-mode.el +++ b/misc/fuel/factor-mode.el @@ -241,7 +241,7 @@ code in the buffer." (defun factor-mode-insert-and-indent (n) (interactive "p") (self-insert-command n) - (indent-for-tab-command)) + (indent-according-to-mode)) (defvar factor-mode-map (let ((map (make-sparse-keymap))) diff --git a/misc/fuel/fuel-autodoc.el b/misc/fuel/fuel-autodoc.el index 53b5228965..76919702bb 100644 --- a/misc/fuel/fuel-autodoc.el +++ b/misc/fuel/fuel-autodoc.el @@ -57,7 +57,10 @@ (defun fuel-autodoc--eldoc-function () (or (and fuel-autodoc--fallback-function (funcall fuel-autodoc--fallback-function)) - (fuel-autodoc--word-synopsis))) + (condition-case e + (fuel-autodoc--word-synopsis) + (error (format "Autodoc not available (%s)" + (error-message-string e)))))) ;;; Autodoc mode: diff --git a/misc/fuel/fuel-connection.el b/misc/fuel/fuel-connection.el index 09d1ddfb51..f9cc1fb0f3 100644 --- a/misc/fuel/fuel-connection.el +++ b/misc/fuel/fuel-connection.el @@ -29,10 +29,7 @@ (defun fuel-con--get-connection (buffer/proc) (if (processp buffer/proc) (fuel-con--get-connection (process-buffer buffer/proc)) - (with-current-buffer buffer/proc - (or fuel-con--connection - (setq fuel-con--connection - (fuel-con--setup-connection buffer/proc)))))) + (with-current-buffer buffer/proc fuel-con--connection))) ;;; Request and connection datatypes: @@ -126,19 +123,20 @@ (defun fuel-con--setup-connection (buffer) (set-buffer buffer) (fuel-con--cleanup-connection fuel-con--connection) + (setq fuel-con--connection nil) (let ((conn (fuel-con--make-connection buffer))) (fuel-con--setup-comint) - (prog1 - (setq fuel-con--connection conn) - (fuel-con--connection-start-timer conn)))) + (fuel-con--establish-connection conn buffer))) (defconst fuel-con--prompt-regex "( .+ ) ") (defconst fuel-con--eot-marker "<~FUEL~>") (defconst fuel-con--init-stanza "USE: fuel fuel-retort") -(defconst fuel-con--comint-finished-regex +(defconst fuel-con--comint-finished-regex-connected (format "^%s$" fuel-con--eot-marker)) +(defvar fuel-con--comint-finished-regex fuel-con--prompt-regex) + (defun fuel-con--setup-comint () (set (make-local-variable 'comint-redirect-insert-matching-regexp) t) (add-hook 'comint-redirect-filter-functions @@ -154,17 +152,43 @@ (setq comint-redirect-finished-regexp fuel-con--prompt-regex)) str) +(defun fuel-con--establish-connection (conn buffer) + (with-current-buffer (fuel-con--comint-buffer) (erase-buffer)) + (with-current-buffer buffer + (setq fuel-con--connection conn) + (setq fuel-con--comint-finished-regex fuel-con--prompt-regex) + (fuel-con--send-string/wait buffer + fuel-con--init-stanza + 'fuel-con--establish-connection-cont + 20000) + conn)) + +(defun fuel-con--establish-connection-cont (ignore) + (let ((str (with-current-buffer (fuel-con--comint-buffer) (buffer-string)))) + (if (string-match fuel-con--eot-marker str) + (progn + (setq fuel-con--comint-finished-regex + fuel-con--comint-finished-regex-connected) + (fuel-con--connection-start-timer conn) + (message "FUEL listener up and running!")) + (fuel-con--connection-clean-current-request fuel-con--connection) + (setq fuel-con--connection nil) + (message "An error occurred initialising FUEL's Factor library!") + (pop-to-buffer (fuel-con--comint-buffer))))) + ;;; Requests handling: (defsubst fuel-con--comint-buffer () (get-buffer-create " *fuel connection retort*")) -(defsubst fuel-con--comint-buffer-form () +(defun fuel-con--comint-buffer-form () (with-current-buffer (fuel-con--comint-buffer) (goto-char (point-min)) (condition-case nil - (read (current-buffer)) + (let ((form (read (current-buffer)))) + (if (listp form) form + (list 'fuel-con-error (buffer-string)))) (error (list 'fuel-con-error (buffer-string)))))) (defun fuel-con--process-next (con) @@ -208,11 +232,12 @@ ;;; Message sending interface: +(defconst fuel-con--error-message "FUEL connection not active") + (defun fuel-con--send-string (buffer/proc str cont &optional sender-buffer) (save-current-buffer (let ((con (fuel-con--get-connection buffer/proc))) - (unless con - (error "FUEL: couldn't find connection")) + (unless con (error fuel-con--error-message)) (let ((req (fuel-con--make-request str cont sender-buffer))) (fuel-con--connection-queue-request con req) (fuel-con--process-next con) @@ -223,22 +248,23 @@ (defun fuel-con--send-string/wait (buffer/proc str cont &optional timeout sbuf) (save-current-buffer - (let* ((con (fuel-con--get-connection buffer/proc)) - (req (fuel-con--send-string buffer/proc str cont sbuf)) - (id (and req (fuel-con--request-id req))) - (time (or timeout fuel-connection-timeout)) - (step 100) - (waitsecs (/ step 1000.0))) - (when id - (condition-case nil - (while (and (> time 0) - (not (fuel-con--connection-completed-p con id))) - (accept-process-output nil waitsecs) - (setq time (- time step))) - (error (setq time 0))) - (or (> time 0) - (fuel-con--request-deactivate req) - nil))))) + (let ((con (fuel-con--get-connection buffer/proc))) + (unless con (error fuel-con--error-message)) + (let* ((req (fuel-con--send-string buffer/proc str cont sbuf)) + (id (and req (fuel-con--request-id req))) + (time (or timeout fuel-connection-timeout)) + (step 100) + (waitsecs (/ step 1000.0))) + (when id + (condition-case nil + (while (and (> time 0) + (not (fuel-con--connection-completed-p con id))) + (accept-process-output nil waitsecs) + (setq time (- time step))) + (error (setq time 0))) + (or (> time 0) + (fuel-con--request-deactivate req) + nil)))))) (provide 'fuel-connection) diff --git a/misc/fuel/fuel-listener.el b/misc/fuel/fuel-listener.el index ecb47f68a2..d4fa5aed1f 100644 --- a/misc/fuel/fuel-listener.el +++ b/misc/fuel/fuel-listener.el @@ -78,11 +78,7 @@ buffer." (make-comint-in-buffer "fuel listener" (current-buffer) factor nil "-run=listener" (format "-i=%s" image)) (fuel-listener--wait-for-prompt 10000) - (fuel-con--setup-connection (current-buffer)) - (fuel-con--send-string/wait (current-buffer) - fuel-con--init-stanza - '(lambda (s) (message "FUEL listener up and running!")) - 20000))) + (fuel-con--setup-connection (current-buffer)))) (defun fuel-listener--process (&optional start) (or (and (buffer-live-p (fuel-listener--buffer))