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

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

bug#12079: 23.3; erroneous byte-compile-file warning


From: Glenn Morris
Subject: bug#12079: 23.3; erroneous byte-compile-file warning
Date: Sun, 29 Jul 2012 19:12:47 -0400
User-agent: Gnus (www.gnus.org), GNU Emacs (www.gnu.org/software/emacs/)

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).





reply via email to

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