unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: "Richard M. Stallman" <rms@gnu.org>
Cc: emacs-devel@gnu.org
Subject: fit-window-to-buffer
Date: Fri, 24 Jun 2005 01:36:30 -0400	[thread overview]
Message-ID: <E1Dlgre-0001WA-8W@fencepost.gnu.org> (raw)

    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))))))

             reply	other threads:[~2005-06-24  5:36 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-06-24  5:36 Richard M. Stallman [this message]
2005-06-24  8:21 ` fit-window-to-buffer Juanma Barranquero
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
2005-06-28 23:52         ` next-error-hook (was: with-current-buffer) Juri Linkov
2005-06-27 16:46   ` with-current-buffer (was: fit-window-to-buffer) Richard M. Stallman

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

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=E1Dlgre-0001WA-8W@fencepost.gnu.org \
    --to=rms@gnu.org \
    --cc=emacs-devel@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 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).