all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* fit-window-to-buffer
@ 2005-06-24  5:36 Richard M. Stallman
  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
  0 siblings, 2 replies; 24+ 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] 24+ messages in thread
* 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; 24+ 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] 24+ messages in thread
* with-current-buffer
@ 2019-11-11  8:31 Andreas Röhler
  2019-11-11  9:04 ` with-current-buffer tomas
  2019-11-11 11:16 ` with-current-buffer Joost Kremers
  0 siblings, 2 replies; 24+ messages in thread
From: Andreas Röhler @ 2019-11-11  8:31 UTC (permalink / raw)
  To: help-gnu-emacs

Hi,

docstring of "with-current-buffer" says:

"Execute the forms in BODY with BUFFER-OR-NAME temporarily current."

However, seems the old buffer isn't stored, buffer-or-name specified 
here remain current.

Also don't see inside the macro which way the old buffer should be restored:

(defmacro with-current-buffer (buffer-or-name &rest body)
   "Execute the forms in BODY with BUFFER-OR-NAME temporarily current.
BUFFER-OR-NAME must be a buffer or the name of an existing buffer.
The value returned is the value of the last form in BODY.  See
also `with-temp-buffer'."
   (declare (indent 1) (debug t))
   `(save-current-buffer
      (set-buffer ,buffer-or-name)
      ,@body))


A bug?

Thanks,

Andreas,

GNU Emacs 26.3 (build 1, i686-pc-linux-gnu, GTK+ Version 3.14.5) of 
2019-09-04




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

end of thread, other threads:[~2019-11-11 11:31 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-06-24  5:36 fit-window-to-buffer Richard M. Stallman
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
  -- strict thread matches above, loose matches on Subject: below --
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
2019-11-11  8:31 with-current-buffer Andreas Röhler
2019-11-11  9:04 ` with-current-buffer tomas
2019-11-11 10:58   ` with-current-buffer Andreas Röhler
2019-11-11 11:09     ` with-current-buffer tomas
2019-11-11 11:17     ` with-current-buffer Joost Kremers
2019-11-11 11:16 ` with-current-buffer Joost Kremers
2019-11-11 11:31   ` with-current-buffer Andreas Röhler

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.