[Top][All Lists]

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

RE: `save-excursion' defeated by `set-buffer'

From: Drew Adams
Subject: RE: `save-excursion' defeated by `set-buffer'
Date: Sun, 13 Mar 2011 11:25:33 -0700

> > They should be restored if the parentese closes.
> > Every setting of buffer, mark and point between then 
> > doesn't matter as far as the buffer now current again
> > is concerned.
> >
> > Maybe there have been other `save-excursion' intercurse. 
> > But every one tells it's own story.
> I don't fully understand what you are trying to say.

He's saying that each `save-excursion' does the same thing: it remembers which
buffer is current, and point and mark in that buffer, and then it restores them.
Nothing more.

That's very simple.  It doesn't matter how many `save-excursion's there are or
how convoluted the code might be: when it finishes, each restores what it

> save-excursion should be placed *as close as possible* to the point 
> movements that it is trying to revert.

Agreed.  I don't think anyone disputes that.

But you seem to think that `save-excursion' should never have been defined to
remember which buffer is current and restore that.  `save-excursion' is _not_
only about point movement.  It is not designed only to save point and mark in
the current buffer.  It is _designed_ to also restore that buffer, making it
current again.

> Placing it far away may result in the connection being broken
> sometime down the road when the code is modified or reused in new ways.

Again, that's common sense programming practice.  Good to remember, sometimes
forgotten at one's peril.  We all agree AFAIK.

> Another way to think about the problem is, for every 
> save-excursion in the code:
> - are you clear which point movements it is trying to revert,
> - is it placed as close as possible to those point movements?

Again, no disagreement.

Though `save-excursion' is not only about point movement.  And even wrt point
movement it really doesn't matter which movements a `save-excursion' is "trying
to revert".  It is trying to revert them all (in its body) - and it does.

Your real point here, I think, is again that it helps understanding and
modularity to keep the scope of a `save-excursion' as tight as possible.
Everyone agrees AFAIK.

The same is true of other Lisp constructs, starting with `let'.  There is
nothing in any of this that argues for a _WARNING_ about `save-excursion'
"defeating" `set-buffer'.

And you seem to have missed that `save-excursion' is about buffer restoration,
not just point restoration.  Or perhaps you want to redefine it to not restore
the buffer.

reply via email to

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