GNU bug report logs -
#12079
23.3; erroneous byte-compile-file warning
Previous Next
Reported by: Winston <wbe <at> psr.com>
Date: Sat, 28 Jul 2012 18:11:01 UTC
Severity: minor
Tags: notabug
Found in version 23.3
Done: Glenn Morris <rgm <at> gnu.org>
Bug is archived. No further changes may be made.
Full log
View this message in rfc822 format
Winston wrote:
> (progn
> (save-excursion
> (set-buffer "foo") ; I'd already created this
> (barf-if-buffer-read-only)
> )
> (current-buffer)
> )
> #<buffer *scratch*>
>
> 3) However, when I write that code to foo.el and run byte-compile-file
> on it, I get the following error:
>
> Compiling file /home/wbe/foo.el at Sat Jul 28 09:07:28 2012
> Entering directory `/home/wbe/'
> --> foo.el:1:1:Warning: `save-excursion' defeated by `set-buffer'
>
> It looks to me like the Warning message is untrue.
In an example such as you show, you should use with-current-buffer
instead of save-excursion+set-buffer. I think this has been discussed
several times on this list and/or emacs-devel.
The compilation warning is because save-excursion is pointless in the
code as shown. Eg it doesn't preserve point in buffer foo (unless foo
happened to be current beforehand).
This bug report was last modified 12 years and 357 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.