GNU bug report logs - #4655
23.1.50; buffer-swap-text oddity

Previous Next

Package: emacs;

Reported by: Markus Rost <rost <at> math.uni-bielefeld.de>

Date: Tue, 6 Oct 2009 18:55:07 UTC

Severity: minor

Tags: patch

Done: npostavs <at> users.sourceforge.net

Bug is archived. No further changes may be made.

Full log


Message #30 received at 4655 <at> emacsbugs.donarmstrong.com (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Juanma Barranquero <lekktu <at> gmail.com>
Cc: 4655 <at> debbugs.gnu.org, Markus Rost <rost <at> math.uni-bielefeld.de>
Subject: Re: bug#4655: 23.1.50; buffer-swap-text oddity
Date: Wed, 07 Oct 2009 10:29:11 -0400
>> 2- save-excursion saves the "position and current buffer" as a marker.
>> Combine 1 and 2 together, and you'll see that save-excursion ends up
>> changing the current buffer.

> Oops. Yes, I see.
> Well, we could document it, but from my POV it looks more like a bug
> than a "feature".

Agreed.  This said, we have a problem.

If we consider the buffer-swap-text as a kind of "two-way copy&paste",
just with a more efficient implementation, then it would be OK for
save-excursion to not preserve the position, i.e. handle save-excursion
markers similarly to window-markers.

I see some problems with it, tho:
1- how to find all the save-excursion markers (we'd probably have to
   walk the specpdl list and compare the restore function with
   save_excursion_restore, which is very ugly).
2- if we reset those marker's position in buffer-swap-text, then
   (save-excursion (buffer-swap-text BUF) (dosomething) (buffer-swap-text BUF))
   would end up moving point to (point-min) for no good reason, which is
   rather inconvenient and might be worse than the OP.
3- we could change save-excursion itself to check the the markers still
   points to the same buffer.  That would solve the OP, but the cost of
   making all save-excursions more expensive (for the sake of a rare
   corner case).
4- should save-excursion care more about preserving the position inside
   the current text, or preserving the current buffer?
5- most uses of save-excursion are wrong, and the OP is among them.

I.e. I'd tend to prefer documenting it (in buffer-swap-text), and remind
people that they should usually use with-current-buffer rather than
save-excursion.


        Stefan "who thinks save-excursion is an ugly beast"



This bug report was last modified 9 years and 28 days ago.

Previous Next


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