emacs-devel
[Top][All Lists]
Advanced

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

fit-window-to-buffer


From: Richard M. Stallman
Subject: fit-window-to-buffer
Date: Fri, 24 Jun 2005 01:36:30 -0400

    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 via email to

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