diff options
author | Jose Antonio Ortega Ruiz <jao@gnu.org> | 2010-11-12 22:55:40 +0100 |
---|---|---|
committer | Jose Antonio Ortega Ruiz <jao@gnu.org> | 2010-11-12 23:21:02 +0100 |
commit | 46d12e9318538dfab7c36415415b3e5f12b84b85 (patch) | |
tree | c2f77f5fa6649e9fdd02beb29d3cd8139d92b4f0 | |
parent | fe966fe13a6c65d7ea2dcd84544de7522789bedf (diff) | |
download | geiser-46d12e9318538dfab7c36415415b3e5f12b84b85.tar.gz geiser-46d12e9318538dfab7c36415415b3e5f12b84b85.tar.bz2 |
Make do with a single connection
Separate connections for the REPL and Geiser commands was kind of
neat, but it had the problem of synchronising the current namespace
for both connections. A quick fix would have been to ask the scheme
for the current namespace for every Geiser command in the REPL, but
that, besides clunky, would add potentially prohibitive overhead for
(real) remote connections.
As it happens, using a single connection turned out to be not that
difficult and relatively clean code-wise. We could even turn back to
not use inferior schemes, and the net result of this refactoring would
be the replacement of comint-redirect (which wasn't able to match the
whole EOT token if it didn't arrive all at once) by transaction queues
(which also makes geiser-connection's implementation cleaner).
But using an inferior scheme has a dog-food value, and allows external
processes to connect to the scheme being used by Geiser without
further ado, which could be useful for debugging (although this is a
lame excuse: nothing prevents you from starting a REPL server from
emacs if you want). We'll see.
-rw-r--r-- | elisp/geiser-connection.el | 49 | ||||
-rw-r--r-- | elisp/geiser-repl.el | 29 |
2 files changed, 46 insertions, 32 deletions
diff --git a/elisp/geiser-connection.el b/elisp/geiser-connection.el index 76ba24a..0225964 100644 --- a/elisp/geiser-connection.el +++ b/elisp/geiser-connection.el @@ -74,37 +74,48 @@ (format "\\(%s%s\\)" prompt (if debug (format "\\|%s" debug) ""))) (defun geiser-con--connection-eot-re (prompt debug) - (geiser-con--combined-prompt (format "\0\n%s" prompt) + (geiser-con--combined-prompt (format "\n%s" prompt) (and debug (format "\n%s" debug)))) (defun geiser-con--make-connection (proc prompt debug-prompt) - (list :geiser-connection + (list t + (cons :filter (process-filter proc)) (cons :tq (tq-create proc)) + (cons :tq-filter (process-filter proc)) (cons :eot (geiser-con--connection-eot-re prompt debug-prompt)) (cons :prompt prompt) (cons :debug-prompt debug-prompt) (cons :count 0) (cons :completed (make-hash-table :weakness 'value)))) -(defun geiser-con--connection-swap-proc (con proc) - (let* ((this-proc (geiser-con--connection-process con)) - (this-filter (process-filter this-proc)) - (filter (process-filter proc)) - (buffer (process-buffer proc)) - (tq (geiser-con--connection-tq con))) - (set-process-filter this-proc filter) - (set-process-buffer this-proc buffer) - (set-process-filter proc this-filter) - (set-process-buffer proc nil) - (setcdr tq (cons proc (tq-buffer tq))) - this-proc)) - -(defsubst geiser-con--connection-p (c) - (and (listp c) (eq (car c) :geiser-connection))) +(defun geiser-con--connection-deactivate (c) + (when (car c) + (let* ((tq (geiser-con--connection-tq c)) + (proc (geiser-con--connection-process c)) + (proc-filter (geiser-con--connection-filter c))) + (while (not (tq-queue-empty tq)) + (accept-process-output proc 0.1)) + (set-process-filter proc proc-filter) + (setcar c nil)))) + +(defun geiser-con--connection-activate (c) + (when (not (car c)) + (let* ((tq (geiser-con--connection-tq c)) + (proc (geiser-con--connection-process c)) + (tq-filter (geiser-con--connection-tq-filter c))) + (while (accept-process-output proc 0.01)) + (set-process-filter proc tq-filter) + (setcar c t)))) (defsubst geiser-con--connection-process (c) (tq-process (cdr (assoc :tq c)))) +(defsubst geiser-con--connection-filter (c) + (cdr (assoc :filter c))) + +(defsubst geiser-con--connection-tq-filter (c) + (cdr (assoc :tq-filter c))) + (defsubst geiser-con--connection-tq (c) (cdr (assoc :tq c))) @@ -164,7 +175,8 @@ `((error (key . geiser-debugger)) (output . ,answer)) (condition-case err - (car (read-from-string answer)) + (let ((form (car (read-from-string answer)))) + (and (listp form) form)) (error `((error (key . geiser-con-error)) (output . ,(format "%s\n(%s)" answer @@ -192,6 +204,7 @@ (geiser-log--info "REQUEST: <%s>: %s" (geiser-con--request-id r) (geiser-con--request-string r)) + (geiser-con--connection-activate c) (tq-enqueue (geiser-con--connection-tq c) (concat (geiser-con--request-string r) "\n") (geiser-con--connection-eot c) diff --git a/elisp/geiser-repl.el b/elisp/geiser-repl.el index f73bd90..e6f01d4 100644 --- a/elisp/geiser-repl.el +++ b/elisp/geiser-repl.el @@ -228,6 +228,10 @@ module command as a string") nil nil defhost)) (or port (read-number "Port: " defport))))) +(defun geiser-repl--autodoc-mode (n) + (when (or geiser-repl-autodoc-p (< n 0)) + (geiser--save-msg (geiser-autodoc-mode n)))) + (defun geiser-repl--save-remote-data (address remote) (setq geiser-repl--address address) (setq geiser-repl--remote-p remote) @@ -240,6 +244,7 @@ module command as a string") (message "Starting Geiser REPL for %s ..." impl) (geiser-repl--to-repl-buffer impl) (goto-char (point-max)) + (geiser-repl--autodoc-mode -1) (let ((address (geiser-repl--get-address host port)) (prompt-rx (geiser-repl--prompt-regexp impl)) (deb-prompt-rx (geiser-repl--debugger-prompt-regexp impl)) @@ -249,11 +254,6 @@ module command as a string") (geiser-repl--save-remote-data address remote) (condition-case err (progn - (setq geiser-repl--connection - (geiser-con--open-connection (car address) - (cdr address) - prompt-rx - deb-prompt-rx)) (set (make-local-variable 'comint-prompt-regexp) (geiser-con--combined-prompt prompt-rx deb-prompt-rx)) (apply 'make-comint-in-buffer `(,cname ,(current-buffer) ,address))) @@ -264,7 +264,12 @@ module command as a string") (geiser-repl--history-setup) (add-to-list 'geiser-repl--repls (current-buffer)) (geiser-repl--set-this-buffer-repl (current-buffer)) + (setq geiser-repl--connection + (geiser-con--make-connection (get-buffer-process (current-buffer)) + prompt-rx + deb-prompt-rx)) (geiser-repl--startup impl remote) + (geiser-repl--autodoc-mode 1) (message "%s up and running!" (geiser-repl--repl-name impl)))) (defun geiser-repl--connection () @@ -276,16 +281,12 @@ module command as a string") (setq geiser-eval--default-connection-function 'geiser-repl--connection) -(defun geiser-repl--swap () - (let ((p (get-buffer-process (current-buffer)))) - (when (and p geiser-repl--connection) - (let ((p (geiser-con--connection-swap-proc geiser-repl--connection - p))) - (goto-char (point-max)) - (set-marker (process-mark p) (point)))))) +(defun geiser-repl--prepare-send () + (geiser-con--connection-deactivate geiser-repl--connection)) (defun geiser-repl--send (cmd) (when (and cmd (eq major-mode 'geiser-repl-mode)) + (geiser-repl--prepare-send) (goto-char (point-max)) (comint-kill-input) (insert cmd) @@ -293,6 +294,7 @@ module command as a string") (comint-send-input nil t)))) (defun geiser-repl--send-silent (cmd) + (geiser-repl--prepare-send) (comint-redirect-results-list cmd ".+" 0)) @@ -415,6 +417,7 @@ module command as a string") ;;; (not (geiser-con--is-debugging))) ) (compilation-forget-errors)) + (geiser-repl--prepare-send) (comint-send-input) (when (string-match "^\\s-*$" intxt) (comint-send-string proc (geiser-eval--scheme-str '(:ge no-values))) @@ -459,8 +462,6 @@ buffer." (set (make-local-variable 'comint-input-ignoredups) geiser-repl-history-no-dups-p) (setq geiser-eval--get-module-function 'geiser-repl--module-function) - (when geiser-repl-autodoc-p - (geiser--save-msg (geiser-autodoc-mode 1))) (geiser-company--setup geiser-repl-company-p) ;; enabling compilation-shell-minor-mode without the annoying highlighter (compilation-setup t)) |