Show
Ignore:
Timestamp:
09/09/06 16:30:10 (2 years ago)
Author:
miyoshi
Message:

Sync up with Emacs CVS HEAD.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lisp/emacs-lisp/tq.el

    r4058 r4161  
    6767;; the process 
    6868(defun tq-queue-head-regexp   (tq) (car (cdr (car (tq-queue tq))))) 
    69 ;; closure: additional data to pass to function 
     69;; closure: additional data to pass to the function 
    7070(defun tq-queue-head-closure  (tq) (car (cdr (cdr (car (tq-queue tq)))))) 
    7171;; fn: function to call upon receiving a complete response from the 
     
    120120This produces more reliable results with some processes." 
    121121  (let ((sendp (or (not delay-question) 
    122                    (not (tq-queue-head-question tq))))) 
     122                   (not (tq-queue tq))))) 
    123123    (tq-queue-add tq (unless sendp question) regexp closure fn) 
    124124    (when sendp 
     
    132132(defun tq-filter (tq string) 
    133133  "Append STRING to the TQ's buffer; then process the new data." 
    134   (with-current-buffer (tq-buffer tq) 
    135     (goto-char (point-max)) 
    136     (insert string) 
    137     (tq-process-buffer tq))) 
     134  (let ((buffer (tq-buffer tq))) 
     135    (when (buffer-live-p buffer) 
     136      (with-current-buffer buffer 
     137        (goto-char (point-max)) 
     138        (insert string) 
     139        (tq-process-buffer tq))))) 
    138140 
    139141(defun tq-process-buffer (tq) 
    140142  "Check TQ's buffer for the regexp at the head of the queue." 
    141   (set-buffer (tq-buffer tq)) 
    142   (if (= 0 (buffer-size)) () 
    143     (if (tq-queue-empty tq) 
    144         (let ((buf (generate-new-buffer "*spurious*"))) 
    145           (copy-to-buffer buf (point-min) (point-max)) 
    146           (delete-region (point-min) (point)) 
    147           (pop-to-buffer buf nil) 
    148           (error "Spurious communication from process %s, see buffer %s" 
    149                  (process-name (tq-process tq)) 
    150                  (buffer-name buf))) 
    151       (goto-char (point-min)) 
    152       (if (re-search-forward (tq-queue-head-regexp tq) nil t) 
    153           (let ((answer (buffer-substring (point-min) (point)))) 
    154             (delete-region (point-min) (point)) 
    155             (unwind-protect 
    156                 (condition-case nil 
    157                     (funcall (tq-queue-head-fn tq) 
    158                              (tq-queue-head-closure tq) 
    159                              answer) 
    160                   (error nil)) 
    161               (tq-queue-pop tq)) 
    162             (tq-process-buffer tq)))))) 
     143  (let ((buffer (tq-buffer tq))) 
     144    (when (buffer-live-p buffer) 
     145      (set-buffer buffer) 
     146      (if (= 0 (buffer-size)) () 
     147        (if (tq-queue-empty tq) 
     148            (let ((buf (generate-new-buffer "*spurious*"))) 
     149              (copy-to-buffer buf (point-min) (point-max)) 
     150              (delete-region (point-min) (point)) 
     151              (pop-to-buffer buf nil) 
     152              (error "Spurious communication from process %s, see buffer %s" 
     153                     (process-name (tq-process tq)) 
     154                     (buffer-name buf))) 
     155          (goto-char (point-min)) 
     156          (if (re-search-forward (tq-queue-head-regexp tq) nil t) 
     157              (let ((answer (buffer-substring (point-min) (point)))) 
     158                (delete-region (point-min) (point)) 
     159                (unwind-protect 
     160                    (condition-case nil 
     161                        (funcall (tq-queue-head-fn tq) 
     162                                 (tq-queue-head-closure tq) 
     163                                 answer) 
     164                      (error nil)) 
     165                  (tq-queue-pop tq)) 
     166                (tq-process-buffer tq)))))))) 
    163167 
    164168(provide 'tq)