all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Michael Olson <mwolson@gnu.org>
Subject: RFC: Backwards-compatible change to tq.el
Date: Tue, 11 Apr 2006 18:38:44 -0400	[thread overview]
Message-ID: <877j5vhh57.fsf@tuxtanker.mwolson.org> (raw)


[-- Attachment #1.1: Type: text/plain, Size: 391 bytes --]

While looking at tq.el, I found that it interacts poorly with
processes that cannot receive input while sending output.  The
following patch will allow developers of new programs to fix this, but
retains backwards compatibility with older programs that use tq.el (if
any exist -- apparently no program that comes with Emacs uses tq.el).

If this patch receives approval, I will install it.


[-- Attachment #1.2: Type: application/pgp-signature, Size: 190 bytes --]

[-- Attachment #2: tq.el.patch --]
[-- Type: text/plain, Size: 3893 bytes --]

--- orig/lisp/ChangeLog
+++ mod/lisp/ChangeLog
@@ -1,3 +1,15 @@
+2006-04-11  Michael Olson  <mwolson@gnu.org>
+
+	* emacs-lisp/tq.el (tq-queue-head-question): New accessor
+	function.
+	(tq-queue-head-regexp, tq-queue-head-closure, tq-queue-head-fn):
+	Update for modified queue structure.
+	(tq-queue-add): Accept `question' argument.
+	(tq-queue-pop): If a question is pending, send it.
+	(tq-enqueue): Accept new optional argument `delay-question'.  If
+	this is non-nil, and at least one other question is pending a
+	response, queue the question rather than sending it immediately.
+
 2006-04-10  Bill Wohler  <wohler@newt.com>
 
 	* custom.el (defcustom, custom-handle-keyword): Add


--- orig/lisp/emacs-lisp/tq.el
+++ mod/lisp/emacs-lisp/tq.el
@@ -32,9 +32,9 @@
 ;; handler functions
 
 ;; Our basic structure is the queue/process/buffer triple.  Each entry
-;; of the queue is a regexp/closure/function triple.  We buffer
-;; bytes from the process until we see the regexp at the head of the
-;; queue.  Then we call the function with the closure and the
+;; of the queue is a question/regexp/closure/function quadruple.  We
+;; buffer bytes from the process until we see the regexp at the head
+;; of the queue.  Then we call the function with the closure and the
 ;; collected bytes.
 
 ;;; Code:
@@ -55,32 +55,45 @@
     tq))
 
 ;;; accessors
-(defun tq-queue   (tq) (car tq))
-(defun tq-process (tq) (car (cdr tq)))
-(defun tq-buffer  (tq) (cdr (cdr tq)))
+(defun tq-queue               (tq) (car tq))
+(defun tq-process             (tq) (car (cdr tq)))
+(defun tq-buffer              (tq) (cdr (cdr tq)))
+(defun tq-queue-head-question (tq) (car (car (tq-queue tq))))
+(defun tq-queue-head-regexp   (tq) (car (cdr (car (tq-queue tq)))))
+(defun tq-queue-head-closure  (tq) (car (cdr (cdr (car (tq-queue tq))))))
+(defun tq-queue-head-fn       (tq) (cdr (cdr (cdr (car (tq-queue tq))))))
 
-(defun tq-queue-add (tq re closure fn)
+(defun tq-queue-empty         (tq) (not (tq-queue tq)))
+
+(defun tq-queue-add (tq question re closure fn)
   (setcar tq (nconc (tq-queue tq)
-		    (cons (cons re (cons closure fn)) nil)))
+		    (cons (cons question (cons re (cons closure fn))) nil)))
   'ok)
 
-(defun tq-queue-head-regexp  (tq) (car (car (tq-queue tq))))
-(defun tq-queue-head-fn      (tq) (cdr (cdr (car (tq-queue tq)))))
-(defun tq-queue-head-closure (tq) (car (cdr (car (tq-queue tq)))))
-(defun tq-queue-empty        (tq) (not (tq-queue tq)))
-(defun tq-queue-pop          (tq) (setcar tq (cdr (car tq))) (null (car tq)))
-
+(defun tq-queue-pop (tq)
+  (setcar tq (cdr (car tq)))
+  (let ((question (tq-queue-head-question tq)))
+    (when question
+      (process-send-string (tq-process tq) question)))
+  (null (car tq)))
 
 ;;; must add to queue before sending!
-(defun tq-enqueue (tq question regexp closure fn)
+(defun tq-enqueue (tq question regexp closure fn &optional delay-question)
   "Add a transaction to transaction queue TQ.
 This sends the string QUESTION to the process that TQ communicates with.
 When the corresponding answer comes back, we call FN
 with two arguments: CLOSURE, and the answer to the question.
 REGEXP is a regular expression to match the entire answer;
-that's how we tell where the answer ends."
-  (tq-queue-add tq regexp closure fn)
-  (process-send-string (tq-process tq) question))
+that's how we tell where the answer ends.
+
+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)))))
+    (tq-queue-add tq (and delay-question question) regexp closure fn)
+    (when sendp
+      (process-send-string (tq-process tq) question))))
 
 (defun tq-close (tq)
   "Shut down transaction queue TQ, terminating the process."





[-- Attachment #3: Type: text/plain, Size: 262 bytes --]


-- 
Michael Olson -- FSF Associate Member #652 -- http://www.mwolson.org/
Interests: Emacs Lisp, text markup, protocols -- Muse, Planner, ERC, EMMS
  /` |\ | | | IRC: mwolson on freenode.net: #hcoop, #muse, #PurdueLUG
 |_] | \| |_| Jabber: mwolson_at_hcoop.net

[-- Attachment #4: Type: text/plain, Size: 142 bytes --]

_______________________________________________
Emacs-devel mailing list
Emacs-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-devel

             reply	other threads:[~2006-04-11 22:38 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-04-11 22:38 Michael Olson [this message]
  -- strict thread matches above, loose matches on Subject: below --
2006-04-12 14:58 RFC: Backwards-compatible change to tq.el Stuart D. Herring
2006-04-12 20:58 ` Michael Olson
2006-04-13  3:20   ` Richard Stallman
2006-04-14 12:04     ` Michael Olson
2006-04-15 17:32       ` Richard Stallman
2006-04-15 21:43         ` Michael Olson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=877j5vhh57.fsf@tuxtanker.mwolson.org \
    --to=mwolson@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.