all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: bojohan+news@dd.chalmers.se (Johan Bockgård)
To: emacs-devel@gnu.org
Cc: emacs-pretest-bug@gnu.org
Subject: Re: 23.0.50; `read-event' changes `current-buffer'
Date: Sat, 03 Nov 2007 18:14:16 +0100	[thread overview]
Message-ID: <yoijir4j8d5j.fsf@remote4.student.chalmers.se> (raw)
In-Reply-To: 87abpvq4k9.fsf@localhorst.mine.nu

David Hansen <david.hansen@gmx.net> 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  <bojohan@gnu.org>

	* 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	other threads:[~2007-11-03 17:14 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-11-03  5:30 23.0.50; `read-event' changes `current-buffer' David Hansen
2007-11-03 17:14 ` Johan Bockgård [this message]
2007-11-07  3:47   ` Glenn Morris

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=yoijir4j8d5j.fsf@remote4.student.chalmers.se \
    --to=bojohan+news@dd.chalmers.se \
    --cc=emacs-devel@gnu.org \
    --cc=emacs-pretest-bug@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.