[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Recursive edits in `save-excursion'
From: |
Stuart D. Herring |
Subject: |
Re: Recursive edits in `save-excursion' |
Date: |
Fri, 29 Sep 2006 16:13:53 -0700 (PDT) |
User-agent: |
SquirrelMail/1.4.6-7.el3.7lanl |
> The explanation for this is that save-excursion saves the current
> buffer, but what you set when you switch buffers is the selected
> window's buffer. save-excursion does not restore that. The first
> save-excursion restores the original current buffer but doesn't
> switch to it. The second recursive edit notices that the current
> buffer isn't the same one you've switched to, so it arranges to
> save and restore the current buffer.
So -- just to make sure that I understand correctly -- `recursive-edit'
acts like it was implemented as follows?
(defun recursive-edit ()
"..."
(let ((obuf (unless (eq (current-buffer) (window-buffer))
(current-buffer)))
(set-buffer (window-buffer))
(unwind-protect
(if (eq (catch 'exit (command-loop) nil) t) (signal 'quit nil))
(if (obuf (set-buffer obuf))))))
In other words, it acts like it is a `save-excursion' embedded if and only
if the current buffer and current window's buffer differ? So you could
defeat this by doing something like what follows?
(save-excursion (set-buffer (window-buffer)) (recursive-edit) ...)
My concern is not which buffer is current around this form, or in which
buffer the `recursive-edit' starts, but just that the `...' be evaluated
with the buffer current that was current when the recursive edit was
exited.
I also wonder if it would be profitable to use the original form, but
calling `window-buffer' instead of `current-buffer'?
(save-excursion (recursive-edit) (window-buffer))
A quick test with the 21.3 I have in front of me seems to support my
theory (both of the modified examples work as I would expect). Assuming
I'm correct that they work reliably, is there a reason to prefer one or
the other?
Thanks,
Davis
--
This product is sold by volume, not by mass. If it appears too dense or
too sparse, it is because mass-energy conversion has occurred during
shipping.