unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: "Drew Adams" <drew.adams@oracle.com>
Cc: 'David Kastrup' <dak@gnu.org>, emacs-devel@gnu.org
Subject: Re: `save-excursion' defeated by `set-buffer'
Date: Mon, 04 Jan 2010 13:30:04 -0500	[thread overview]
Message-ID: <jwvvdfh3f8n.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <1DA372296B5F41A1A3317F557D27355D@us.oracle.com> (Drew Adams's message of "Mon, 4 Jan 2010 01:09:53 -0800")

> I would like to see a clear, logical presentation of what your position is,
> Stefan.  It's not obvious to me what this is all about.

It's really not about much.  Feel free to completely ignore it.
I've updated the manual (except for the lisp-intro) to eliminate the
more obvious problems.

> The explanation in that node is just what I've always understood wrt
> `save-excursion'.  It makes it clear that only point and mark of the
> current buffer are saved and restored, along with the identity of the
> current buffer.  So I really don't see what the problem is.

The propblem is that even tho it's clear, people tend to forget about
it.  Proof is the dired-mouse-find-file-other-window example code in the
manual which did

   (save-excursion
     ...
     (set-buffer ...)
     (goto-char ...)
     ...)

The problem with that code is that point in current buffer will be moved
depending on whether the buffer we switch to is the same as the
current buffer.  That's unlikely to be what the author intended.
She probably either didn't want to save point (and juse use
save-current-buffer instead), or did want to save point (in which case
she needed save-current-buffer around and an additional save-excursion
inside).

> But that's not a general problem of using the two together; that's just
> misunderstanding what they do. If that's the only "problem" we are warning
> programmers about, then I think the warning is misguided.

The precise behavior of (save-excusrion (set-buffer foo) ...) is
sufficiently odd that I still haven't come upon a single real case where
it was the right thing to do.  Yet, this precise form is (well, was)
found more than a hundred times in the Emacs source code.



        Stefan




  reply	other threads:[~2010-01-04 18:30 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-12-20 19:19 `save-excursion' defeated by `set-buffer' Roland Winkler
2009-12-21 15:26 ` Stefan Monnier
2009-12-21 16:23   ` David Kastrup
2009-12-22 12:51     ` martin rudalics
2009-12-23  0:45     ` Stefan Monnier
2009-12-23  9:07       ` David Kastrup
2009-12-24  4:35         ` Stefan Monnier
2009-12-24  9:03           ` David Kastrup
2009-12-29 16:01             ` Stefan Monnier
2010-01-04  9:09               ` Drew Adams
2010-01-04 18:30                 ` Stefan Monnier [this message]
2010-01-05 20:17                   ` David Kastrup
2010-01-06  0:02                     ` Drew Adams
2010-01-06  4:20                       ` Stefan Monnier
2010-01-06  8:07                         ` David Kastrup
2010-01-06  8:57                           ` Drew Adams
2010-01-10  4:57                             ` Stefan Monnier
2010-01-10  8:12                               ` David Kastrup
2010-01-10 21:43                                 ` Stefan Monnier
2010-01-11  8:24                                   ` David Kastrup
2010-01-11  9:21                                     ` martin rudalics
2010-01-11 16:50                                       ` Stefan Monnier
2010-01-10 17:03                               ` Drew Adams
2010-01-10  4:51                           ` Stefan Monnier
2010-01-10 15:58                         ` Harald Hanche-Olsen
2010-01-10 18:05                           ` martin rudalics
2010-01-10 18:06                           ` Drew Adams
2010-01-10 19:44                             ` Harald Hanche-Olsen
2009-12-24 14:04   ` Roland Winkler
2010-01-04 17:08   ` Davis Herring
2010-01-04 17:34     ` David Kastrup
2010-01-04 18:33     ` Stefan Monnier
  -- strict thread matches above, loose matches on Subject: below --
2009-12-18  9:20 Eli Zaretskii
2009-12-18 15:29 ` Juanma Barranquero
2009-12-18 15:58   ` Thierry Volpiatto

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=jwvvdfh3f8n.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=dak@gnu.org \
    --cc=drew.adams@oracle.com \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).