diff options
author | Miles Bader <miles@gnu.org> | 2006-08-27 10:42:40 +0000 |
---|---|---|
committer | Miles Bader <miles@gnu.org> | 2006-08-27 10:42:40 +0000 |
commit | 7a210b69c7f92650c524766d1b9d3f3eefdd67c7 (patch) | |
tree | 6d64433b8933041600d772b7ff68ad8bdcaa38af /lisp/emacs-lisp/tq.el | |
parent | eb411049435acd5469021b64ce3f59c4ac05f491 (diff) | |
download | emacs-7a210b69c7f92650c524766d1b9d3f3eefdd67c7.tar.gz |
Miscellaneous tq-related fixes.
* lisp/emacs-lisp/tq.el: Small grammar fix in comments.
(tq-enqueue): Check for existence of queue rather than the head queue
item's question, which was a no-op.
(tq-filter, tq-process-buffer): Make sure the process buffer exists
before making it the current buffer.
* lispref/processes.texi (Transaction Queues): Remove stray quote
character.
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-411
Creator: Michael Olson <mwolson@gnu.org>
Diffstat (limited to 'lisp/emacs-lisp/tq.el')
-rw-r--r-- | lisp/emacs-lisp/tq.el | 60 |
1 files changed, 32 insertions, 28 deletions
diff --git a/lisp/emacs-lisp/tq.el b/lisp/emacs-lisp/tq.el index 2126d7663fc..1e1e143f0f0 100644 --- a/lisp/emacs-lisp/tq.el +++ b/lisp/emacs-lisp/tq.el @@ -66,7 +66,7 @@ ;; regexp: regular expression that matches the end of a response from ;; the process (defun tq-queue-head-regexp (tq) (car (cdr (car (tq-queue tq))))) -;; closure: additional data to pass to function +;; closure: additional data to pass to the function (defun tq-queue-head-closure (tq) (car (cdr (cdr (car (tq-queue tq)))))) ;; fn: function to call upon receiving a complete response from the ;; process @@ -119,7 +119,7 @@ If DELAY-QUESTION is non-nil, delay sending this question until the process has finished replying to any previous questions. This produces more reliable results with some processes." (let ((sendp (or (not delay-question) - (not (tq-queue-head-question tq))))) + (not (tq-queue tq))))) (tq-queue-add tq (unless sendp question) regexp closure fn) (when sendp (process-send-string (tq-process tq) question)))) @@ -131,35 +131,39 @@ This produces more reliable results with some processes." (defun tq-filter (tq string) "Append STRING to the TQ's buffer; then process the new data." - (with-current-buffer (tq-buffer tq) - (goto-char (point-max)) - (insert string) - (tq-process-buffer tq))) + (let ((buffer (tq-buffer tq))) + (when (buffer-live-p buffer) + (with-current-buffer buffer + (goto-char (point-max)) + (insert string) + (tq-process-buffer tq))))) (defun tq-process-buffer (tq) "Check TQ's buffer for the regexp at the head of the queue." - (set-buffer (tq-buffer tq)) - (if (= 0 (buffer-size)) () - (if (tq-queue-empty tq) - (let ((buf (generate-new-buffer "*spurious*"))) - (copy-to-buffer buf (point-min) (point-max)) - (delete-region (point-min) (point)) - (pop-to-buffer buf nil) - (error "Spurious communication from process %s, see buffer %s" - (process-name (tq-process tq)) - (buffer-name buf))) - (goto-char (point-min)) - (if (re-search-forward (tq-queue-head-regexp tq) nil t) - (let ((answer (buffer-substring (point-min) (point)))) - (delete-region (point-min) (point)) - (unwind-protect - (condition-case nil - (funcall (tq-queue-head-fn tq) - (tq-queue-head-closure tq) - answer) - (error nil)) - (tq-queue-pop tq)) - (tq-process-buffer tq)))))) + (let ((buffer (tq-buffer tq))) + (when (buffer-live-p buffer) + (set-buffer buffer) + (if (= 0 (buffer-size)) () + (if (tq-queue-empty tq) + (let ((buf (generate-new-buffer "*spurious*"))) + (copy-to-buffer buf (point-min) (point-max)) + (delete-region (point-min) (point)) + (pop-to-buffer buf nil) + (error "Spurious communication from process %s, see buffer %s" + (process-name (tq-process tq)) + (buffer-name buf))) + (goto-char (point-min)) + (if (re-search-forward (tq-queue-head-regexp tq) nil t) + (let ((answer (buffer-substring (point-min) (point)))) + (delete-region (point-min) (point)) + (unwind-protect + (condition-case nil + (funcall (tq-queue-head-fn tq) + (tq-queue-head-closure tq) + answer) + (error nil)) + (tq-queue-pop tq)) + (tq-process-buffer tq)))))))) (provide 'tq) |