summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--elisp/geiser-connection.el49
-rw-r--r--elisp/geiser-repl.el29
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))