help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: `save-exursion' makes a comeback!


From: Uday S Reddy
Subject: Re: `save-exursion' makes a comeback!
Date: Wed, 16 Mar 2011 12:48:08 +0000

[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



reply via email to

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