GNU bug report logs - #12079
23.3; erroneous byte-compile-file warning

Previous Next

Package: emacs;

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


Message #8 received at 12079 <at> debbugs.gnu.org (full text, mbox):

From: Glenn Morris <rgm <at> gnu.org>
To: Winston <wbe <at> psr.com>
Cc: 12079 <at> debbugs.gnu.org
Subject: Re: bug#12079: 23.3; erroneous byte-compile-file warning
Date: Sun, 29 Jul 2012 19:12:47 -0400
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 358 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.