unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* with-current-buffer
@ 2005-09-11 15:00 Emilio Lopes
  2005-09-11 16:52 ` with-current-buffer Stefan Monnier
  2005-09-11 20:23 ` with-current-buffer Luc Teirlinck
  0 siblings, 2 replies; 11+ messages in thread
From: Emilio Lopes @ 2005-09-11 15:00 UTC (permalink / raw)


Start Emacs (latest CVS on GNU/Linux) with

   ./src/emacs --no-init-file --no-site-file

Display a buffer, let's say "FOO", with some content.  Move point to
its beginning.

Insert the following code in the "*scratch*" buffer:

   (with-current-buffer "FOO"
     (goto-char (point-max))
     (insert "bar"))

Now execute the code above in these two different situations:

   1- The buffer "FOO" is visible along with the "*scratch*" buffer.

   2- The buffer "FOO" is not visible.

In both cases the insertion is done at the right spot, but in case 1
point in buffer "FOO" is restored after the code is executed.

Is that intended behavior?

I expected the point to be moved permanently in both cases.

^ permalink raw reply	[flat|nested] 11+ messages in thread
* fit-window-to-buffer
@ 2005-06-24  5:36 Richard M. Stallman
  2005-06-26 23:33 ` with-current-buffer (was: fit-window-to-buffer) Juri Linkov
  0 siblings, 1 reply; 11+ messages in thread
From: Richard M. Stallman @ 2005-06-24  5:36 UTC (permalink / raw)
  Cc: emacs-devel

    The issue is that `fit-window-to-buffer', when called from
    `occur-hook', changes the current buffer. Puzzling. Not a problem now,

That is very strange.  I looked at the code for fit-window-to-buffer
and see nothing that should be able to change the current buffer.
It must be a bug in some C primitive used there.

If the Lisp debugger interferes with the phenomenon,
I suggest trying inserting debugging statements such as

  (setq foo4 (current-buffer)

in the code at various places.  If you put these in the right places
you should be able to narrow down where the clobberage occurs.

My suspicion is on the window-manipulating functions.  Perhaps
save-selected-window fails to restore the current buffer.

Later:

    And very weird. I traced the call, and the buffer changed on return of
    `save-selected-window'. Nothing that I could see seemed like a likely
    cause.

Oho, so it is there.  I have a suspicion about why.  I think
save-selected-window sets the current buffer to the buffer that is
displayed in the newly restored selected window.  If some other buffer
was current before the save-selected-window form, it will have the
effect of changing the current buffer.

Maybe the best solution is to explicitly save the current buffer
like this.  Does this fix the problem?


(defmacro save-selected-window (&rest body)
  "Execute BODY, then select the window that was selected before BODY.
Also restore the selected window of each frame as it was at the start
of this construct.
However, if a window has become dead, don't get an error,
just refrain from reselecting it.
Return the value of the last form in BODY."
  `(let ((save-selected-window-window (selected-window))
	 ;; It is necessary to save all of these, because calling
	 ;; select-window changes frame-selected-window for whatever
	 ;; frame that window is in.
	 (save-selected-window-alist
	  (mapcar (lambda (frame) (list frame (frame-selected-window frame)))
		  (frame-list))))
     (save-current-buffer
       (unwind-protect
	   (progn ,@body)
	 (dolist (elt save-selected-window-alist)
	   (and (frame-live-p (car elt))
		(window-live-p (cadr elt))
		(set-frame-selected-window (car elt) (cadr elt))))
	 (if (window-live-p save-selected-window-window)
	     (select-window save-selected-window-window))))))

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2005-09-12 17:15 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-09-11 15:00 with-current-buffer Emilio Lopes
2005-09-11 16:52 ` with-current-buffer Stefan Monnier
2005-09-11 19:23   ` with-current-buffer Emilio Lopes
2005-09-11 21:15     ` with-current-buffer Stefan Monnier
2005-09-12 17:15       ` with-current-buffer Emilio Lopes
2005-09-11 20:23 ` with-current-buffer Luc Teirlinck
  -- strict thread matches above, loose matches on Subject: below --
2005-06-24  5:36 fit-window-to-buffer Richard M. Stallman
2005-06-26 23:33 ` with-current-buffer (was: fit-window-to-buffer) Juri Linkov
2005-06-27  6:28   ` Miles Bader
2005-06-28  0:04     ` with-current-buffer Juri Linkov
2005-06-28 17:28       ` with-current-buffer Kevin Rodgers
2005-06-29  3:45         ` with-current-buffer Stefan Monnier
2005-06-29 17:45           ` with-current-buffer Kevin Rodgers
2005-06-28 18:47       ` with-current-buffer Richard M. Stallman

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).