[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: |
Tue, 15 Mar 2011 09:00:37 -0700 |
> There is no proof that save-excursion+set-buffer is wrong, because it
> just is not wrong: it's just a combination of function that performs
> something.
Correct.
> That's why the byte-compiler emits a warning and not an
> error message.
A warning about what? There is not only no proof that save-excursion+set-buffer
is wrong - it is not at all wrong. As you admit.
> What there is, OTOH, is damning evidence that:
> - it can be replaced by with-current-buffer in more than 90% of the
> cases (which is more concise and more efficient).
Cases where? In old Emacs source code?
Really, you don't have to tell people to replace `save-excursion+set-buffer'
with `with-current-buffer', especially since such a replacement might not be
appropriate.
Just tell people of the existence of `with-current-buffer' and
`save-current-buffer', and they will naturally use those for their intended
purpose. People will not naturally use `save-excursion' nowadays just to save
the current buffer.
> - in the remaining cases it is usually hiding an error and that error
> can be fixed by using (with-current-buffer <foo>
> (save-excursion ...)).
In the remaining cases in old Emacs source code? See above.
> - in my more than 10 years of maintaining Emacs I have not found
> a single case where the semantics of save-excursion+set-buffer is
> indeed exactly what we're after (i.e. where it's used without
> introducing a bug and without introducing an inefficiency fixable by
> with-current-buffer).
You are fixated on `set-buffer'. `save-excursion' doesn't care what you do
while excursioning. You can `set-buffer' all you want or not change buffers at
all. It simply doesn't matter. All that's important about `save-excursion' is
what it does: bring you back.
> So the warning was introduced to help Elisp coders improve their code.
> That's what byte-compiler warnings are for.
It won't help, but will hurt, at least with users writing new code. If someone
uses `save-excursion' nowadays it is only in order to do what `save-excursion'
does: return you where you were. There is nothing wrong with calling
`set-buffer' (or anything else) inside a `save-excursion'.
Your real message should be just to remind people that `save-excursion' does not
do more than it does - e.g., remove any misconceptions that it saves and
restores positions in other buffers.
- Re: `save-excursion' defeated by `set-buffer', (continued)
- Message not available
- Re: `save-excursion' defeated by `set-buffer', David Kastrup, 2011/03/12
- Re: `save-excursion' defeated by `set-buffer', Eli Zaretskii, 2011/03/12
- Re: `save-excursion' defeated by `set-buffer', Uday Reddy, 2011/03/12
- Re: `save-excursion' defeated by `set-buffer', David Kastrup, 2011/03/12
- Re: `save-excursion' defeated by `set-buffer', Uday Reddy, 2011/03/12
- Re: `save-excursion' defeated by `set-buffer', Stefan Monnier, 2011/03/14
- Re: `save-excursion' defeated by `set-buffer', Andreas Röhler, 2011/03/14
- Message not available
- Re: `save-excursion' defeated by `set-buffer', Stefan Monnier, 2011/03/15
- Re: `save-excursion' defeated by `set-buffer', PJ Weisberg, 2011/03/15
- Re: `save-excursion' defeated by `set-buffer', David Kastrup, 2011/03/15
- RE: `save-excursion' defeated by `set-buffer',
Drew Adams <=
- Message not available
- Re: `save-excursion' defeated by `set-buffer', Stefan Monnier, 2011/03/15
- Message not available
- Re: `save-excursion' defeated by `set-buffer', Stefan Monnier, 2011/03/15
- RE: `save-excursion' defeated by `set-buffer', Drew Adams, 2011/03/15
- Re: `save-excursion' defeated by `set-buffer', Stefan Monnier, 2011/03/15
- Re: `save-excursion' defeated by `set-buffer', Jason Earl, 2011/03/15
- RE: `save-excursion' defeated by `set-buffer', Drew Adams, 2011/03/15
- Re: `save-excursion' defeated by `set-buffer', rusi, 2011/03/16
- Re: `save-excursion' defeated by `set-buffer', David Kastrup, 2011/03/16
- Re: `save-excursion' defeated by `set-buffer', rusi, 2011/03/17
- Re: `save-excursion' defeated by `set-buffer', rusi, 2011/03/17