* `save-exursion' makes a comeback!
@ 2011-03-15 15:07 Drew Adams
0 siblings, 0 replies; 5+ messages in thread
From: Drew Adams @ 2011-03-15 15:07 UTC (permalink / raw
To: help-gnu-emacs
Emacs Excursion
---------------
Your mama said when you left the nest,
"Go out and play and learn and test
the waters.
Discover what's right, what's wrong, what's left.
Sow your wildest oats, follow your farthest quest.
But when you're done come back, come home, and rest."
Pun-summary: `save-excursion' makes a comeback!
That's all that can or need ever be said about it.
Maybe you've looked at some of the recent WARNING brouhaha,
maybe not. Whether you were bored or amused, aghast or
confused, this is all you ever need to know about
`save-excursion': it makes a comeback.
It makes (forces) Emacs to come back, to the same buffer at
the same point, with the same mark. NOTHING more.
It does not matter what kind of excursion you make, where you
go or what you do. What you did while in Vegas stays in Vegas.
`save-excursion' just brings you back.
Forget about `save-excursion' "saving" or "restoring" or
"hiding" or "protecting" anything. Forget about it "defeating"
or being "defeated". Forget all of that right now.
The real name of `save-excursion' is `come-back-here'.
Just remember that and Bob's your uncle.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: `save-exursion' makes a comeback!
[not found] <mailman.3.1300201687.14512.help-gnu-emacs@gnu.org>
@ 2011-03-15 15:23 ` David Kastrup
2011-03-15 16:02 ` Drew Adams
[not found] ` <mailman.4.1300204937.1264.help-gnu-emacs@gnu.org>
2011-03-16 12:48 ` Uday S Reddy
1 sibling, 2 replies; 5+ messages in thread
From: David Kastrup @ 2011-03-15 15:23 UTC (permalink / raw
To: help-gnu-emacs
"Drew Adams" <drew.adams@oracle.com> writes:
> Forget about `save-excursion' "saving" or "restoring" or
> "hiding" or "protecting" anything. Forget about it "defeating"
> or being "defeated". Forget all of that right now.
>
> The real name of `save-excursion' is `come-back-here'.
> Just remember that and Bob's your uncle.
M-: (with-temp-buffer (let ((b (current-buffer))) (save-excursion
(set-buffer "*scratch*") (kill-buffer b))) (current-buffer)) RET
--
David Kastrup
^ permalink raw reply [flat|nested] 5+ messages in thread
* RE: `save-exursion' makes a comeback!
2011-03-15 15:23 ` `save-exursion' makes a comeback! David Kastrup
@ 2011-03-15 16:02 ` Drew Adams
[not found] ` <mailman.4.1300204937.1264.help-gnu-emacs@gnu.org>
1 sibling, 0 replies; 5+ messages in thread
From: Drew Adams @ 2011-03-15 16:02 UTC (permalink / raw
To: 'David Kastrup', help-gnu-emacs
> > Forget about `save-excursion' "saving" or "restoring" or
> > "hiding" or "protecting" anything. Forget about it "defeating"
> > or being "defeated". Forget all of that right now.
> >
> > The real name of `save-excursion' is `come-back-here'.
> > Just remember that and Bob's your uncle.
>
> M-: (with-temp-buffer (let ((b (current-buffer))) (save-excursion
> (set-buffer "*scratch*") (kill-buffer b))) (current-buffer)) RET
Yes, David. I explicitly mentioned that case before (though that was no doubt
lost in the bit torrent). This makes it even clearer, I think:
(defun foo ()
(interactive)
(save-excursion
(message "BEFORE KILL, buf: %S, pt: %S, mark: %S"
(current-buffer) (point) (mark))
(sit-for 2)
(kill-buffer (current-buffer))
(message "BEFORE END, buf: %S, pt: %S, mark: %S"
(current-buffer) (point) (mark))
(sit-for 2))
(message "AFTER, buf: %S, pt: %S, mark: %S"
(current-buffer) (point) (mark))
(sit-for 2))
M-x foo RET
This is no different from your father saying "Come back here!" as you run out
the door, and your then burning down the house so there is no place to come back
to.
Really, this kind of thing just adds confusion to the discussion for most users.
There is nothing special here to do with `save-excursion'. `save-excursion'
just does an `unwind-protect' to return where you came from. If in the meantime
you have nuked the place you came from then there is nothing that
`save-excursion', `unwind-protect', or the Emacs god herself can do to bring
your home back.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: `save-exursion' makes a comeback!
[not found] ` <mailman.4.1300204937.1264.help-gnu-emacs@gnu.org>
@ 2011-03-15 16:11 ` David Kastrup
0 siblings, 0 replies; 5+ messages in thread
From: David Kastrup @ 2011-03-15 16:11 UTC (permalink / raw
To: help-gnu-emacs
"Drew Adams" <drew.adams@oracle.com> writes:
>> > Forget about `save-excursion' "saving" or "restoring" or
>> > "hiding" or "protecting" anything. Forget about it "defeating"
>> > or being "defeated". Forget all of that right now.
>> >
>> > The real name of `save-excursion' is `come-back-here'.
>> > Just remember that and Bob's your uncle.
>>
>> M-: (with-temp-buffer (let ((b (current-buffer))) (save-excursion
>> (set-buffer "*scratch*") (kill-buffer b))) (current-buffer)) RET
>
> Yes, David. I explicitly mentioned that case before (though that was
> no doubt lost in the bit torrent).
Don't start a new thread if you want to refer to hypothetical material
from a different thread. If you just want to change the topic,
something like
f C-c C-f s
is your friend and retains the thread references if you are using Gnus.
If you happen to prefer mail readers from Microsoft, you should be able
to find the respective functionality in their documentation, and if not,
manually changing the subject line appropriate should still be possible.
--
David Kastrup
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: `save-exursion' makes a comeback!
[not found] <mailman.3.1300201687.14512.help-gnu-emacs@gnu.org>
2011-03-15 15:23 ` `save-exursion' makes a comeback! David Kastrup
@ 2011-03-16 12:48 ` Uday S Reddy
1 sibling, 0 replies; 5+ messages in thread
From: Uday S Reddy @ 2011-03-16 12:48 UTC (permalink / raw
To: Drew Adams; +Cc: help-gnu-emacs
[Despite David's admonition, I would like to extend this thread
because it is a slightly different slant on the original debate. It
seems to me that this also the first time that Drew has said something
positive about how he would like to use `save-excursion' (rather than
just complaining about the compiler).]
> Pun-summary: `save-excursion' makes a comeback!
>
> That's all that can or need ever be said about it.
"comeback" is a very different application of `save-excursion' from
that described in the ELisp manual.
Going back to the manual first, the Section 30.2 sets out the "motion
commands" to be used for moving the point and Section 30.3 sets out
the additional stuff you use to handle "excursions". Excursions are,
in the words of the manual, temporary point movements within a
*localized* portion of the program (or to switch buffers
temporarily). Such excursions are to be placed in a `save-excursion'
form. So, the manual distinguishes between permanent point movements,
which you handle normally, and temporary pont movements, which you
place inside a `save-excursion' form.
The idea of "comeback" seems to be quite different. It suggests that
no distinctions will be made in the code between permanent movements
of the point and temporary movements. They will all be handled as if
they were permanent. However, a top-level save-excursion (which was
my term for "comeback") will ensure that you will return to the
original point in the current buffer.
As long as your code is dealing with a single buffer, this seems like
a reasonable way to develop your program (though it is not something I
would recommend). Moreover, if you are dealing with a single buffer,
you won't have any `set-buffer' in your code. So, the compiler will
leave you in peace. The warning won't arise.
But, if your code is dealing with multiple buffers, then the top-level
save-excursion, i.e., "comback", will only restore the point in the
current buffer, not the other buffers you might have switched to
temporarily. The point in all the other buffers might move. If the
user cares about the other buffers or if your own code does
modifications to the contents in the other buffers, then the "comback"
idea can lead to quite chaotic results.
If you have an application where
- the point is moved in the current buffer, but not other buffers, or
- the point movement in all buffers other than the current buffers is
unimportant,
then the "comback" idea might be suitable. But these seem to be very
specialized applications. For most Emacs developers, all the buffers
are equally important and random point movements in them would need to
be avoided.
Cheers,
Uday
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2011-03-16 12:48 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <mailman.3.1300201687.14512.help-gnu-emacs@gnu.org>
2011-03-15 15:23 ` `save-exursion' makes a comeback! David Kastrup
2011-03-15 16:02 ` Drew Adams
[not found] ` <mailman.4.1300204937.1264.help-gnu-emacs@gnu.org>
2011-03-15 16:11 ` David Kastrup
2011-03-16 12:48 ` Uday S Reddy
2011-03-15 15:07 Drew Adams
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.