emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: 23.0.50; `read-event' changes `current-buffer'


From: Johan Bockgård
Subject: Re: 23.0.50; `read-event' changes `current-buffer'
Date: Sat, 03 Nov 2007 18:14:16 +0100
User-agent: Gnus/5.110007 (No Gnus v0.7) Emacs/23.0.50 (gnu/linux)

David Hansen <address@hidden> writes:

> $ emacs -Q
> M-x eshell RET
> $ while #'(lambda () t) { echo XXX; sleep 1}
> C-x b *scratch* RET
>
> (with-temp-buffer
>   (let ((buf (current-buffer)))
>     (read-event nil nil 3)
>     (format ":%s: :%s:" (buffer-name buf) (current-buffer))))
>
> C-u C-x C-e
>
> ": *temp*: :*eshell*:"

It is caused by an unprotected set-buffer call in eshell-sentinel.

This patch fixes this. It also uses with-current-buffer in
eshell-insertion-filter, and in eshell-output-filter (instead of
(set-buffer BUF) ... (set-buffer OLDBUF)).


2007-11-03  Johan Bockgård  <address@hidden>

        * eshell/esh-proc.el (eshell-insertion-filter, eshell-sentinel):
        Use `with-current-buffer'.

        * eshell/esh-mode.el (eshell-output-filter): Ditto.


Index: lisp/eshell/esh-mode.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/eshell/esh-mode.el,v
retrieving revision 1.31
diff -u -r1.31 esh-mode.el
--- lisp/eshell/esh-mode.el     21 Oct 2007 07:33:32 -0000      1.31
+++ lisp/eshell/esh-mode.el     3 Nov 2007 16:58:32 -0000
@@ -775,38 +775,36 @@
        (setq string (funcall (car functions) string))
        (setq functions (cdr functions))))
     (if (and string oprocbuf (buffer-name oprocbuf))
-       (let ((obuf (current-buffer))
-             opoint obeg oend)
-         (set-buffer oprocbuf)
-         (setq opoint (point))
-         (setq obeg (point-min))
-         (setq oend (point-max))
-         (let ((buffer-read-only nil)
-               (nchars (length string))
-               (ostart nil))
-           (widen)
-           (goto-char eshell-last-output-end)
-           (setq ostart (point))
-           (if (<= (point) opoint)
-               (setq opoint (+ opoint nchars)))
-           (if (< (point) obeg)
-               (setq obeg (+ obeg nchars)))
-           (if (<= (point) oend)
-               (setq oend (+ oend nchars)))
-           (insert-before-markers string)
-           (if (= (window-start (selected-window)) (point))
-               (set-window-start (selected-window)
-                                 (- (point) nchars)))
-           (if (= (point) eshell-last-input-end)
-               (set-marker eshell-last-input-end
-                           (- eshell-last-input-end nchars)))
-           (set-marker eshell-last-output-start ostart)
-           (set-marker eshell-last-output-end (point))
-           (force-mode-line-update))
-         (narrow-to-region obeg oend)
-         (goto-char opoint)
-         (eshell-run-output-filters)
-         (set-buffer obuf)))))
+       (let (opoint obeg oend)
+         (with-current-buffer oprocbuf
+           (setq opoint (point))
+           (setq obeg (point-min))
+           (setq oend (point-max))
+           (let ((buffer-read-only nil)
+                 (nchars (length string))
+                 (ostart nil))
+             (widen)
+             (goto-char eshell-last-output-end)
+             (setq ostart (point))
+             (if (<= (point) opoint)
+                 (setq opoint (+ opoint nchars)))
+             (if (< (point) obeg)
+                 (setq obeg (+ obeg nchars)))
+             (if (<= (point) oend)
+                 (setq oend (+ oend nchars)))
+             (insert-before-markers string)
+             (if (= (window-start (selected-window)) (point))
+                 (set-window-start (selected-window)
+                                   (- (point) nchars)))
+             (if (= (point) eshell-last-input-end)
+                 (set-marker eshell-last-input-end
+                             (- eshell-last-input-end nchars)))
+             (set-marker eshell-last-output-start ostart)
+             (set-marker eshell-last-output-end (point))
+             (force-mode-line-update))
+           (narrow-to-region obeg oend)
+           (goto-char opoint)
+           (eshell-run-output-filters))))))
 
 (defun eshell-run-output-filters ()
   "Run the `eshell-output-filter-functions' on the current output."
Index: lisp/eshell/esh-proc.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/eshell/esh-proc.el,v
retrieving revision 1.16
diff -u -r1.16 esh-proc.el
--- lisp/eshell/esh-proc.el     26 Jul 2007 05:26:54 -0000      1.16
+++ lisp/eshell/esh-proc.el     3 Nov 2007 16:58:33 -0000
@@ -335,39 +335,39 @@
 PROC is the process for which we're inserting output.  STRING is the
 output."
   (when (buffer-live-p (process-buffer proc))
-    (set-buffer (process-buffer proc))
-    (let ((entry (assq proc eshell-process-list)))
-      (when entry
-       (setcar (nthcdr 3 entry)
-               (concat (nth 3 entry) string))
-       (unless (nth 4 entry)           ; already being handled?
-         (while (nth 3 entry)
-           (let ((data (nth 3 entry)))
-             (setcar (nthcdr 3 entry) nil)
-             (setcar (nthcdr 4 entry) t)
-             (eshell-output-object data nil (cadr entry))
-             (setcar (nthcdr 4 entry) nil))))))))
+    (with-current-buffer (process-buffer proc)
+      (let ((entry (assq proc eshell-process-list)))
+       (when entry
+         (setcar (nthcdr 3 entry)
+                 (concat (nth 3 entry) string))
+         (unless (nth 4 entry)         ; already being handled?
+           (while (nth 3 entry)
+             (let ((data (nth 3 entry)))
+               (setcar (nthcdr 3 entry) nil)
+               (setcar (nthcdr 4 entry) t)
+               (eshell-output-object data nil (cadr entry))
+               (setcar (nthcdr 4 entry) nil)))))))))
 
 (defun eshell-sentinel (proc string)
   "Generic sentinel for command processes.  Reports only signals.
 PROC is the process that's exiting.  STRING is the exit message."
   (when (buffer-live-p (process-buffer proc))
-    (set-buffer (process-buffer proc))
-    (unwind-protect
-       (let* ((entry (assq proc eshell-process-list)))
-;        (if (not entry)
-;            (error "Sentinel called for unowned process `%s'"
-;                   (process-name proc))
-         (when entry
-           (unwind-protect
-               (progn
-                 (unless (string= string "run")
-                   (unless (string-match "^\\(finished\\|exited\\)" string)
-                     (eshell-insertion-filter proc string))
-                   (eshell-close-handles (process-exit-status proc) 'nil
-                                         (cadr entry))))
-             (eshell-remove-process-entry entry))))
-      (run-hook-with-args 'eshell-kill-hook proc string))))
+    (with-current-buffer (process-buffer proc)
+      (unwind-protect
+         (let* ((entry (assq proc eshell-process-list)))
+;;;        (if (not entry)
+;;;            (error "Sentinel called for unowned process `%s'"
+;;;                   (process-name proc))
+           (when entry
+             (unwind-protect
+                 (progn
+                   (unless (string= string "run")
+                     (unless (string-match "^\\(finished\\|exited\\)" string)
+                       (eshell-insertion-filter proc string))
+                     (eshell-close-handles (process-exit-status proc) 'nil
+                                           (cadr entry))))
+               (eshell-remove-process-entry entry))))
+       (run-hook-with-args 'eshell-kill-hook proc string)))))
 
 (defun eshell-process-interact (func &optional all query)
   "Interact with a process, using PROMPT if more than one, via FUNC.


-- 
Johan Bockgård





reply via email to

[Prev in Thread] Current Thread [Next in Thread]