annotate lisp/emacs-lisp/tq.el @ 110695:515d80e174ba

Remove some functions, variables and aliases obsolete since at least 21.1. * doc/misc/misc.texi (Shell Mode): Remove reference to old function name. * src/character.c (Fchar_bytes): Remove obsolete function. (syms_of_character): Remove Schar_bytes. * lisp/subr.el (char-bytes): Remove obsolete function. * lisp/emacs-lisp/checkdoc.el (checkdoc-minor-keymap): Remove obsolete alias. * lisp/isearch.el (isearch-return-char): Remove obsolete function. * lisp/mouse.el: No longer provide mldrag. (mldrag-drag-mode-line, mldrag-drag-vertical-line): Remove obsolete aliases. * lisp/comint.el (comint-kill-output): Remove obsolete alias. * lisp/shell.el: Comment fix. * lisp/composite.el (decompose-composite-char): Remove obsolete function. * lisp/ps-def.el (decompose-composite-char): Remove unused function. * lisp/iswitchb.el (iswitchb-default-keybindings): Remove obsolete function. * lisp/outline.el (outline-visible): Remove obsolete function. * lisp/term/pc-win.el (x-frob-font-slant, x-frob-font-weight): * lisp/faces.el (internal-find-face, internal-get-face) (frame-update-faces, frame-update-face-colors) (x-frob-font-weight, x-frob-font-slant) (internal-frob-font-weight, internal-frob-font-slant) (x-make-font-bold, x-make-font-demibold, x-make-font-unbold) (x-make-font-italic, x-make-font-oblique, x-make-font-unitalic) (x-make-font-bold-italic): Remove functions and aliases, obsolete since Emacs 21.1. * lisp/emulation/viper-util.el (viper-get-face): * lisp/obsolete/lucid.el (find-face, get-face): Use facep. * lisp/vc/ediff-init.el (ediff-valid-color-p, ediff-get-face): Remove unused functions. * lisp/vc/ediff-util.el (ediff-submit-report): Doc fix. * etc/NEWS: Mention above changes.
author Glenn Morris <rgm@gnu.org>
date Fri, 01 Oct 2010 19:46:13 -0700
parents 1d1d5d9bd884
children 376148b31b5e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
743
4c88459587e3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1 ;;; tq.el --- utility to maintain a transaction queue
4c88459587e3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2
74466
1d4b1a32fd66 Update copyright years.
Glenn Morris <rgm@gnu.org>
parents: 72548
diff changeset
3 ;; Copyright (C) 1985, 1986, 1987, 1992, 2001, 2002, 2003, 2004,
106815
1d1d5d9bd884 Add 2010 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 100908
diff changeset
4 ;; 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
841
2cdce064065f entered into RCS
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 814
diff changeset
5
783
59dc833c4e0c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 743
diff changeset
6 ;; Author: Scott Draves <spot@cs.cmu.edu>
39461
d9207f337e2d Comment change.
Richard M. Stallman <rms@gnu.org>
parents: 20693
diff changeset
7 ;; Maintainer: FSF
783
59dc833c4e0c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 743
diff changeset
8 ;; Adapted-By: ESR
814
38b2499cb3e9 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 783
diff changeset
9 ;; Keywords: extensions
783
59dc833c4e0c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 743
diff changeset
10
841
2cdce064065f entered into RCS
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 814
diff changeset
11 ;; This file is part of GNU Emacs.
2cdce064065f entered into RCS
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 814
diff changeset
12
94655
90a2847062be Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
13 ;; GNU Emacs is free software: you can redistribute it and/or modify
841
2cdce064065f entered into RCS
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 814
diff changeset
14 ;; it under the terms of the GNU General Public License as published by
94655
90a2847062be Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
15 ;; the Free Software Foundation, either version 3 of the License, or
90a2847062be Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
16 ;; (at your option) any later version.
841
2cdce064065f entered into RCS
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 814
diff changeset
17
2cdce064065f entered into RCS
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 814
diff changeset
18 ;; GNU Emacs is distributed in the hope that it will be useful,
2cdce064065f entered into RCS
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 814
diff changeset
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
2cdce064065f entered into RCS
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 814
diff changeset
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2cdce064065f entered into RCS
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 814
diff changeset
21 ;; GNU General Public License for more details.
2cdce064065f entered into RCS
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 814
diff changeset
22
2cdce064065f entered into RCS
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 814
diff changeset
23 ;; You should have received a copy of the GNU General Public License
94655
90a2847062be Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
24 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
841
2cdce064065f entered into RCS
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 814
diff changeset
25
2cdce064065f entered into RCS
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 814
diff changeset
26 ;;; Commentary:
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 39568
diff changeset
27
70034
db4c2d467e9a Revision: emacs@sv.gnu.org/emacs--devo--0--patch-220
Miles Bader <miles@gnu.org>
parents: 68648
diff changeset
28 ;; This file manages receiving a stream asynchronously, parsing it
db4c2d467e9a Revision: emacs@sv.gnu.org/emacs--devo--0--patch-220
Miles Bader <miles@gnu.org>
parents: 68648
diff changeset
29 ;; into transactions, and then calling the associated handler function
db4c2d467e9a Revision: emacs@sv.gnu.org/emacs--devo--0--patch-220
Miles Bader <miles@gnu.org>
parents: 68648
diff changeset
30 ;; upon the completion of each transaction.
743
4c88459587e3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
31
39568
e67950065cf9 Change ;;; to ;; for outline-minor-mode.
Gerd Moellmann <gerd@gnu.org>
parents: 39461
diff changeset
32 ;; Our basic structure is the queue/process/buffer triple. Each entry
70034
db4c2d467e9a Revision: emacs@sv.gnu.org/emacs--devo--0--patch-220
Miles Bader <miles@gnu.org>
parents: 68648
diff changeset
33 ;; of the queue part is a list of question, regexp, closure, and
db4c2d467e9a Revision: emacs@sv.gnu.org/emacs--devo--0--patch-220
Miles Bader <miles@gnu.org>
parents: 68648
diff changeset
34 ;; function that is consed to the last element.
db4c2d467e9a Revision: emacs@sv.gnu.org/emacs--devo--0--patch-220
Miles Bader <miles@gnu.org>
parents: 68648
diff changeset
35
db4c2d467e9a Revision: emacs@sv.gnu.org/emacs--devo--0--patch-220
Miles Bader <miles@gnu.org>
parents: 68648
diff changeset
36 ;; A transaction queue may be created by calling `tq-create'.
db4c2d467e9a Revision: emacs@sv.gnu.org/emacs--devo--0--patch-220
Miles Bader <miles@gnu.org>
parents: 68648
diff changeset
37
db4c2d467e9a Revision: emacs@sv.gnu.org/emacs--devo--0--patch-220
Miles Bader <miles@gnu.org>
parents: 68648
diff changeset
38 ;; A request may be added to the queue by calling `tq-enqueue'. If
db4c2d467e9a Revision: emacs@sv.gnu.org/emacs--devo--0--patch-220
Miles Bader <miles@gnu.org>
parents: 68648
diff changeset
39 ;; the `delay-question' argument is non-nil, we will wait to send the
db4c2d467e9a Revision: emacs@sv.gnu.org/emacs--devo--0--patch-220
Miles Bader <miles@gnu.org>
parents: 68648
diff changeset
40 ;; question to the process until it has finished sending other input.
db4c2d467e9a Revision: emacs@sv.gnu.org/emacs--devo--0--patch-220
Miles Bader <miles@gnu.org>
parents: 68648
diff changeset
41 ;; Otherwise, once a request is enqueued, we send the given question
db4c2d467e9a Revision: emacs@sv.gnu.org/emacs--devo--0--patch-220
Miles Bader <miles@gnu.org>
parents: 68648
diff changeset
42 ;; immediately to the process.
db4c2d467e9a Revision: emacs@sv.gnu.org/emacs--devo--0--patch-220
Miles Bader <miles@gnu.org>
parents: 68648
diff changeset
43
db4c2d467e9a Revision: emacs@sv.gnu.org/emacs--devo--0--patch-220
Miles Bader <miles@gnu.org>
parents: 68648
diff changeset
44 ;; We then buffer bytes from the process until we see the regexp that
db4c2d467e9a Revision: emacs@sv.gnu.org/emacs--devo--0--patch-220
Miles Bader <miles@gnu.org>
parents: 68648
diff changeset
45 ;; was provided in the call to `tq-enqueue'. Then we call the
db4c2d467e9a Revision: emacs@sv.gnu.org/emacs--devo--0--patch-220
Miles Bader <miles@gnu.org>
parents: 68648
diff changeset
46 ;; provided function with the closure and the collected bytes. If we
db4c2d467e9a Revision: emacs@sv.gnu.org/emacs--devo--0--patch-220
Miles Bader <miles@gnu.org>
parents: 68648
diff changeset
47 ;; have indicated that the question from the next transaction was not
db4c2d467e9a Revision: emacs@sv.gnu.org/emacs--devo--0--patch-220
Miles Bader <miles@gnu.org>
parents: 68648
diff changeset
48 ;; sent immediately, send it at this point, awaiting the response.
743
4c88459587e3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
49
783
59dc833c4e0c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 743
diff changeset
50 ;;; Code:
743
4c88459587e3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
51
70034
db4c2d467e9a Revision: emacs@sv.gnu.org/emacs--devo--0--patch-220
Miles Bader <miles@gnu.org>
parents: 68648
diff changeset
52 ;;; Accessors
db4c2d467e9a Revision: emacs@sv.gnu.org/emacs--devo--0--patch-220
Miles Bader <miles@gnu.org>
parents: 68648
diff changeset
53
db4c2d467e9a Revision: emacs@sv.gnu.org/emacs--devo--0--patch-220
Miles Bader <miles@gnu.org>
parents: 68648
diff changeset
54 ;; This part looks like (queue . (process . buffer))
db4c2d467e9a Revision: emacs@sv.gnu.org/emacs--devo--0--patch-220
Miles Bader <miles@gnu.org>
parents: 68648
diff changeset
55 (defun tq-queue (tq) (car tq))
db4c2d467e9a Revision: emacs@sv.gnu.org/emacs--devo--0--patch-220
Miles Bader <miles@gnu.org>
parents: 68648
diff changeset
56 (defun tq-process (tq) (car (cdr tq)))
db4c2d467e9a Revision: emacs@sv.gnu.org/emacs--devo--0--patch-220
Miles Bader <miles@gnu.org>
parents: 68648
diff changeset
57 (defun tq-buffer (tq) (cdr (cdr tq)))
db4c2d467e9a Revision: emacs@sv.gnu.org/emacs--devo--0--patch-220
Miles Bader <miles@gnu.org>
parents: 68648
diff changeset
58
db4c2d467e9a Revision: emacs@sv.gnu.org/emacs--devo--0--patch-220
Miles Bader <miles@gnu.org>
parents: 68648
diff changeset
59 ;; The structure of `queue' is as follows
db4c2d467e9a Revision: emacs@sv.gnu.org/emacs--devo--0--patch-220
Miles Bader <miles@gnu.org>
parents: 68648
diff changeset
60 ;; ((question regexp closure . fn)
db4c2d467e9a Revision: emacs@sv.gnu.org/emacs--devo--0--patch-220
Miles Bader <miles@gnu.org>
parents: 68648
diff changeset
61 ;; <other queue entries>)
db4c2d467e9a Revision: emacs@sv.gnu.org/emacs--devo--0--patch-220
Miles Bader <miles@gnu.org>
parents: 68648
diff changeset
62 ;; question: string to send to the process
db4c2d467e9a Revision: emacs@sv.gnu.org/emacs--devo--0--patch-220
Miles Bader <miles@gnu.org>
parents: 68648
diff changeset
63 (defun tq-queue-head-question (tq) (car (car (tq-queue tq))))
db4c2d467e9a Revision: emacs@sv.gnu.org/emacs--devo--0--patch-220
Miles Bader <miles@gnu.org>
parents: 68648
diff changeset
64 ;; regexp: regular expression that matches the end of a response from
db4c2d467e9a Revision: emacs@sv.gnu.org/emacs--devo--0--patch-220
Miles Bader <miles@gnu.org>
parents: 68648
diff changeset
65 ;; the process
db4c2d467e9a Revision: emacs@sv.gnu.org/emacs--devo--0--patch-220
Miles Bader <miles@gnu.org>
parents: 68648
diff changeset
66 (defun tq-queue-head-regexp (tq) (car (cdr (car (tq-queue tq)))))
72548
e5542d6aad7f Miscellaneous tq-related fixes.
Miles Bader <miles@gnu.org>
parents: 70034
diff changeset
67 ;; closure: additional data to pass to the function
70034
db4c2d467e9a Revision: emacs@sv.gnu.org/emacs--devo--0--patch-220
Miles Bader <miles@gnu.org>
parents: 68648
diff changeset
68 (defun tq-queue-head-closure (tq) (car (cdr (cdr (car (tq-queue tq))))))
db4c2d467e9a Revision: emacs@sv.gnu.org/emacs--devo--0--patch-220
Miles Bader <miles@gnu.org>
parents: 68648
diff changeset
69 ;; fn: function to call upon receiving a complete response from the
db4c2d467e9a Revision: emacs@sv.gnu.org/emacs--devo--0--patch-220
Miles Bader <miles@gnu.org>
parents: 68648
diff changeset
70 ;; process
db4c2d467e9a Revision: emacs@sv.gnu.org/emacs--devo--0--patch-220
Miles Bader <miles@gnu.org>
parents: 68648
diff changeset
71 (defun tq-queue-head-fn (tq) (cdr (cdr (cdr (car (tq-queue tq))))))
db4c2d467e9a Revision: emacs@sv.gnu.org/emacs--devo--0--patch-220
Miles Bader <miles@gnu.org>
parents: 68648
diff changeset
72
db4c2d467e9a Revision: emacs@sv.gnu.org/emacs--devo--0--patch-220
Miles Bader <miles@gnu.org>
parents: 68648
diff changeset
73 ;; Determine whether queue is empty
db4c2d467e9a Revision: emacs@sv.gnu.org/emacs--devo--0--patch-220
Miles Bader <miles@gnu.org>
parents: 68648
diff changeset
74 (defun tq-queue-empty (tq) (not (tq-queue tq)))
db4c2d467e9a Revision: emacs@sv.gnu.org/emacs--devo--0--patch-220
Miles Bader <miles@gnu.org>
parents: 68648
diff changeset
75
db4c2d467e9a Revision: emacs@sv.gnu.org/emacs--devo--0--patch-220
Miles Bader <miles@gnu.org>
parents: 68648
diff changeset
76 ;;; Core functionality
db4c2d467e9a Revision: emacs@sv.gnu.org/emacs--devo--0--patch-220
Miles Bader <miles@gnu.org>
parents: 68648
diff changeset
77
1187
519c04d69cdc Doc fixes. Make tq-create autoload.
Richard M. Stallman <rms@gnu.org>
parents: 841
diff changeset
78 ;;;###autoload
743
4c88459587e3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
79 (defun tq-create (process)
1187
519c04d69cdc Doc fixes. Make tq-create autoload.
Richard M. Stallman <rms@gnu.org>
parents: 841
diff changeset
80 "Create and return a transaction queue communicating with PROCESS.
519c04d69cdc Doc fixes. Make tq-create autoload.
Richard M. Stallman <rms@gnu.org>
parents: 841
diff changeset
81 PROCESS should be a subprocess capable of sending and receiving
519c04d69cdc Doc fixes. Make tq-create autoload.
Richard M. Stallman <rms@gnu.org>
parents: 841
diff changeset
82 streams of bytes. It may be a local process, or it may be connected
519c04d69cdc Doc fixes. Make tq-create autoload.
Richard M. Stallman <rms@gnu.org>
parents: 841
diff changeset
83 to a tcp server on another machine."
743
4c88459587e3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
84 (let ((tq (cons nil (cons process
4c88459587e3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
85 (generate-new-buffer
4c88459587e3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
86 (concat " tq-temp-"
4c88459587e3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
87 (process-name process)))))))
98251
c1d1eb0b924a tq.el: Disable undo in buffer.
Michael Olson <mwolson@gnu.org>
parents: 94655
diff changeset
88 (buffer-disable-undo (tq-buffer tq))
743
4c88459587e3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
89 (set-process-filter process
49851
fec321336b72 (tq-create): Fix quoted lambda.
Juanma Barranquero <lekktu@gmail.com>
parents: 49598
diff changeset
90 `(lambda (proc string)
52493
04f194e85b4d (tq-create): Fix mixed up unquote style.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
91 (tq-filter ',tq string)))
743
4c88459587e3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
92 tq))
4c88459587e3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
93
70034
db4c2d467e9a Revision: emacs@sv.gnu.org/emacs--devo--0--patch-220
Miles Bader <miles@gnu.org>
parents: 68648
diff changeset
94 (defun tq-queue-add (tq question re closure fn)
743
4c88459587e3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
95 (setcar tq (nconc (tq-queue tq)
70034
db4c2d467e9a Revision: emacs@sv.gnu.org/emacs--devo--0--patch-220
Miles Bader <miles@gnu.org>
parents: 68648
diff changeset
96 (cons (cons question (cons re (cons closure fn))) nil)))
743
4c88459587e3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
97 'ok)
4c88459587e3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
98
70034
db4c2d467e9a Revision: emacs@sv.gnu.org/emacs--devo--0--patch-220
Miles Bader <miles@gnu.org>
parents: 68648
diff changeset
99 (defun tq-queue-pop (tq)
db4c2d467e9a Revision: emacs@sv.gnu.org/emacs--devo--0--patch-220
Miles Bader <miles@gnu.org>
parents: 68648
diff changeset
100 (setcar tq (cdr (car tq)))
db4c2d467e9a Revision: emacs@sv.gnu.org/emacs--devo--0--patch-220
Miles Bader <miles@gnu.org>
parents: 68648
diff changeset
101 (let ((question (tq-queue-head-question tq)))
77890
57715561e846 (tq-queue-pop): Stifle error when a process has died and we are trying
Chong Yidong <cyd@stupidchicken.com>
parents: 75346
diff changeset
102 (condition-case nil
57715561e846 (tq-queue-pop): Stifle error when a process has died and we are trying
Chong Yidong <cyd@stupidchicken.com>
parents: 75346
diff changeset
103 (process-send-string (tq-process tq) question)
57715561e846 (tq-queue-pop): Stifle error when a process has died and we are trying
Chong Yidong <cyd@stupidchicken.com>
parents: 75346
diff changeset
104 (error nil)))
70034
db4c2d467e9a Revision: emacs@sv.gnu.org/emacs--devo--0--patch-220
Miles Bader <miles@gnu.org>
parents: 68648
diff changeset
105 (null (car tq)))
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 39568
diff changeset
106
70034
db4c2d467e9a Revision: emacs@sv.gnu.org/emacs--devo--0--patch-220
Miles Bader <miles@gnu.org>
parents: 68648
diff changeset
107 (defun tq-enqueue (tq question regexp closure fn &optional delay-question)
1187
519c04d69cdc Doc fixes. Make tq-create autoload.
Richard M. Stallman <rms@gnu.org>
parents: 841
diff changeset
108 "Add a transaction to transaction queue TQ.
519c04d69cdc Doc fixes. Make tq-create autoload.
Richard M. Stallman <rms@gnu.org>
parents: 841
diff changeset
109 This sends the string QUESTION to the process that TQ communicates with.
70034
db4c2d467e9a Revision: emacs@sv.gnu.org/emacs--devo--0--patch-220
Miles Bader <miles@gnu.org>
parents: 68648
diff changeset
110
db4c2d467e9a Revision: emacs@sv.gnu.org/emacs--devo--0--patch-220
Miles Bader <miles@gnu.org>
parents: 68648
diff changeset
111 When the corresponding answer comes back, we call FN with two
db4c2d467e9a Revision: emacs@sv.gnu.org/emacs--devo--0--patch-220
Miles Bader <miles@gnu.org>
parents: 68648
diff changeset
112 arguments: CLOSURE, which may contain additional data that FN
db4c2d467e9a Revision: emacs@sv.gnu.org/emacs--devo--0--patch-220
Miles Bader <miles@gnu.org>
parents: 68648
diff changeset
113 needs, and the answer to the question.
db4c2d467e9a Revision: emacs@sv.gnu.org/emacs--devo--0--patch-220
Miles Bader <miles@gnu.org>
parents: 68648
diff changeset
114
1187
519c04d69cdc Doc fixes. Make tq-create autoload.
Richard M. Stallman <rms@gnu.org>
parents: 841
diff changeset
115 REGEXP is a regular expression to match the entire answer;
70034
db4c2d467e9a Revision: emacs@sv.gnu.org/emacs--devo--0--patch-220
Miles Bader <miles@gnu.org>
parents: 68648
diff changeset
116 that's how we tell where the answer ends.
db4c2d467e9a Revision: emacs@sv.gnu.org/emacs--devo--0--patch-220
Miles Bader <miles@gnu.org>
parents: 68648
diff changeset
117
db4c2d467e9a Revision: emacs@sv.gnu.org/emacs--devo--0--patch-220
Miles Bader <miles@gnu.org>
parents: 68648
diff changeset
118 If DELAY-QUESTION is non-nil, delay sending this question until
db4c2d467e9a Revision: emacs@sv.gnu.org/emacs--devo--0--patch-220
Miles Bader <miles@gnu.org>
parents: 68648
diff changeset
119 the process has finished replying to any previous questions.
db4c2d467e9a Revision: emacs@sv.gnu.org/emacs--devo--0--patch-220
Miles Bader <miles@gnu.org>
parents: 68648
diff changeset
120 This produces more reliable results with some processes."
db4c2d467e9a Revision: emacs@sv.gnu.org/emacs--devo--0--patch-220
Miles Bader <miles@gnu.org>
parents: 68648
diff changeset
121 (let ((sendp (or (not delay-question)
72548
e5542d6aad7f Miscellaneous tq-related fixes.
Miles Bader <miles@gnu.org>
parents: 70034
diff changeset
122 (not (tq-queue tq)))))
70034
db4c2d467e9a Revision: emacs@sv.gnu.org/emacs--devo--0--patch-220
Miles Bader <miles@gnu.org>
parents: 68648
diff changeset
123 (tq-queue-add tq (unless sendp question) regexp closure fn)
db4c2d467e9a Revision: emacs@sv.gnu.org/emacs--devo--0--patch-220
Miles Bader <miles@gnu.org>
parents: 68648
diff changeset
124 (when sendp
db4c2d467e9a Revision: emacs@sv.gnu.org/emacs--devo--0--patch-220
Miles Bader <miles@gnu.org>
parents: 68648
diff changeset
125 (process-send-string (tq-process tq) question))))
743
4c88459587e3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
126
4c88459587e3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
127 (defun tq-close (tq)
1187
519c04d69cdc Doc fixes. Make tq-create autoload.
Richard M. Stallman <rms@gnu.org>
parents: 841
diff changeset
128 "Shut down transaction queue TQ, terminating the process."
743
4c88459587e3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
129 (delete-process (tq-process tq))
4c88459587e3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
130 (kill-buffer (tq-buffer tq)))
4c88459587e3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
131
4c88459587e3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
132 (defun tq-filter (tq string)
4c88459587e3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
133 "Append STRING to the TQ's buffer; then process the new data."
72548
e5542d6aad7f Miscellaneous tq-related fixes.
Miles Bader <miles@gnu.org>
parents: 70034
diff changeset
134 (let ((buffer (tq-buffer tq)))
e5542d6aad7f Miscellaneous tq-related fixes.
Miles Bader <miles@gnu.org>
parents: 70034
diff changeset
135 (when (buffer-live-p buffer)
e5542d6aad7f Miscellaneous tq-related fixes.
Miles Bader <miles@gnu.org>
parents: 70034
diff changeset
136 (with-current-buffer buffer
e5542d6aad7f Miscellaneous tq-related fixes.
Miles Bader <miles@gnu.org>
parents: 70034
diff changeset
137 (goto-char (point-max))
e5542d6aad7f Miscellaneous tq-related fixes.
Miles Bader <miles@gnu.org>
parents: 70034
diff changeset
138 (insert string)
e5542d6aad7f Miscellaneous tq-related fixes.
Miles Bader <miles@gnu.org>
parents: 70034
diff changeset
139 (tq-process-buffer tq)))))
743
4c88459587e3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
140
4c88459587e3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
141 (defun tq-process-buffer (tq)
4c88459587e3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
142 "Check TQ's buffer for the regexp at the head of the queue."
72548
e5542d6aad7f Miscellaneous tq-related fixes.
Miles Bader <miles@gnu.org>
parents: 70034
diff changeset
143 (let ((buffer (tq-buffer tq)))
e5542d6aad7f Miscellaneous tq-related fixes.
Miles Bader <miles@gnu.org>
parents: 70034
diff changeset
144 (when (buffer-live-p buffer)
e5542d6aad7f Miscellaneous tq-related fixes.
Miles Bader <miles@gnu.org>
parents: 70034
diff changeset
145 (set-buffer buffer)
e5542d6aad7f Miscellaneous tq-related fixes.
Miles Bader <miles@gnu.org>
parents: 70034
diff changeset
146 (if (= 0 (buffer-size)) ()
e5542d6aad7f Miscellaneous tq-related fixes.
Miles Bader <miles@gnu.org>
parents: 70034
diff changeset
147 (if (tq-queue-empty tq)
e5542d6aad7f Miscellaneous tq-related fixes.
Miles Bader <miles@gnu.org>
parents: 70034
diff changeset
148 (let ((buf (generate-new-buffer "*spurious*")))
e5542d6aad7f Miscellaneous tq-related fixes.
Miles Bader <miles@gnu.org>
parents: 70034
diff changeset
149 (copy-to-buffer buf (point-min) (point-max))
e5542d6aad7f Miscellaneous tq-related fixes.
Miles Bader <miles@gnu.org>
parents: 70034
diff changeset
150 (delete-region (point-min) (point))
e5542d6aad7f Miscellaneous tq-related fixes.
Miles Bader <miles@gnu.org>
parents: 70034
diff changeset
151 (pop-to-buffer buf nil)
e5542d6aad7f Miscellaneous tq-related fixes.
Miles Bader <miles@gnu.org>
parents: 70034
diff changeset
152 (error "Spurious communication from process %s, see buffer %s"
e5542d6aad7f Miscellaneous tq-related fixes.
Miles Bader <miles@gnu.org>
parents: 70034
diff changeset
153 (process-name (tq-process tq))
e5542d6aad7f Miscellaneous tq-related fixes.
Miles Bader <miles@gnu.org>
parents: 70034
diff changeset
154 (buffer-name buf)))
e5542d6aad7f Miscellaneous tq-related fixes.
Miles Bader <miles@gnu.org>
parents: 70034
diff changeset
155 (goto-char (point-min))
e5542d6aad7f Miscellaneous tq-related fixes.
Miles Bader <miles@gnu.org>
parents: 70034
diff changeset
156 (if (re-search-forward (tq-queue-head-regexp tq) nil t)
e5542d6aad7f Miscellaneous tq-related fixes.
Miles Bader <miles@gnu.org>
parents: 70034
diff changeset
157 (let ((answer (buffer-substring (point-min) (point))))
e5542d6aad7f Miscellaneous tq-related fixes.
Miles Bader <miles@gnu.org>
parents: 70034
diff changeset
158 (delete-region (point-min) (point))
e5542d6aad7f Miscellaneous tq-related fixes.
Miles Bader <miles@gnu.org>
parents: 70034
diff changeset
159 (unwind-protect
e5542d6aad7f Miscellaneous tq-related fixes.
Miles Bader <miles@gnu.org>
parents: 70034
diff changeset
160 (condition-case nil
e5542d6aad7f Miscellaneous tq-related fixes.
Miles Bader <miles@gnu.org>
parents: 70034
diff changeset
161 (funcall (tq-queue-head-fn tq)
e5542d6aad7f Miscellaneous tq-related fixes.
Miles Bader <miles@gnu.org>
parents: 70034
diff changeset
162 (tq-queue-head-closure tq)
e5542d6aad7f Miscellaneous tq-related fixes.
Miles Bader <miles@gnu.org>
parents: 70034
diff changeset
163 answer)
e5542d6aad7f Miscellaneous tq-related fixes.
Miles Bader <miles@gnu.org>
parents: 70034
diff changeset
164 (error nil))
e5542d6aad7f Miscellaneous tq-related fixes.
Miles Bader <miles@gnu.org>
parents: 70034
diff changeset
165 (tq-queue-pop tq))
e5542d6aad7f Miscellaneous tq-related fixes.
Miles Bader <miles@gnu.org>
parents: 70034
diff changeset
166 (tq-process-buffer tq))))))))
743
4c88459587e3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
167
841
2cdce064065f entered into RCS
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 814
diff changeset
168 (provide 'tq)
2cdce064065f entered into RCS
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 814
diff changeset
169
93975
1e3a407766b9 Fix up comment convention on the arch-tag lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 79704
diff changeset
170 ;; arch-tag: 65dea08c-4edd-4cde-83a5-e8a15b993b79
743
4c88459587e3 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
171 ;;; tq.el ends here