all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: Juanma Barranquero <lekktu@gmail.com>
Cc: Markus Rost <rost@math.uni-bielefeld.de>,
	4655@emacsbugs.donarmstrong.com
Subject: bug#4655: 23.1.50; buffer-swap-text oddity
Date: Wed, 07 Oct 2009 10:29:11 -0400	[thread overview]
Message-ID: <jwv63arwazq.fsf-monnier+emacsbugreports@gnu.org> (raw)
In-Reply-To: <f7ccd24b0910070307x183fb5b7xa34d29f436a56dcc@mail.gmail.com> (Juanma Barranquero's message of "Wed, 7 Oct 2009 12:07:47 +0200")

>> 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"





  reply	other threads:[~2009-10-07 14:29 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <jwv3a2eiia3.fsf-monnier+emacs@gnu.org>
2009-10-06 18:46 ` bug#4655: 23.1.50; buffer-swap-text oddity Markus Rost
2009-10-07  4:01   ` Juanma Barranquero
2009-10-07  5:41     ` Stefan Monnier
2009-10-07  8:53       ` Markus Rost
2009-10-07 10:07       ` Juanma Barranquero
2009-10-07 14:29         ` Stefan Monnier [this message]
2009-10-08 16:48           ` Markus Rost
2011-07-13 14:08           ` Lars Magne Ingebrigtsen
2016-07-11  1:58             ` npostavs
2016-07-11 14:37               ` Eli Zaretskii
2016-07-11 18:50                 ` Markus Rost
2016-07-11 19:07                   ` Dmitry Gutov
2016-07-12  1:58                     ` npostavs
2016-07-12  5:16                       ` Eli Zaretskii
2016-07-13 23:50                         ` npostavs
2016-07-14 15:03                           ` Eli Zaretskii
2016-07-15  0:05                             ` npostavs
2010-01-10  7:36   ` bug#5273: marked as done (23.1; format-alist encode vs write-region-post-annotation-function) Emacs bug Tracking System
2010-01-13  0:45   ` bug#5256: marked as done (conjunct formation should follow input sequence when inserting text) Emacs bug Tracking System
2010-01-13  0:49   ` bug#5265: marked as done (23.1.90; vc - can't reread redirected stdin for log message) Emacs bug Tracking System
2010-01-14  1:22   ` bug#5276: marked as done (23.1; Doc string of bookmark-bmenu-execute-deletions) Emacs bug Tracking System
2010-01-16 20:05   ` bug#5267: 23.1; doc string of defstruct Chong Yidong
2010-01-16 21:39   ` bug#5279: 23.1; VC: should set LC_MESSAGES to C (with patch) Chong Yidong
2010-05-13 19:20   ` bug#5284: 23.1; gnus-summary-expire-thread does not work Glenn Morris
2010-05-24 19:53   ` bug#5270: [PATCH] * lisp/image-dired.el (image-dired-dired-insert-marked-thumbs) Insert thumbnails before file names of marked files in the dired buffer Thierry Volpiatto
2010-05-25 15:49     ` Juri Linkov
2010-05-25 16:59       ` Thierry Volpiatto
2010-05-25 17:46         ` Juri Linkov
2010-06-30 20:35   ` bug#5281: 23.1; xml-parse-region causes infinite loops if the region is not well-formed XML Chong Yidong
2009-12-29 18:19 bug#5284: 23.1; gnus-summary-expire-thread does not work Tom Tromey
2010-05-11  6:04 ` Andreas Seltenreich
     [not found]   ` <mailman.7.1273778942.8369.bug-gnu-emacs@gnu.org>
2010-06-30 21:35     ` Ted Zlatanov

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

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

  git send-email \
    --in-reply-to=jwv63arwazq.fsf-monnier+emacsbugreports@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=4655@emacsbugs.donarmstrong.com \
    --cc=lekktu@gmail.com \
    --cc=rost@math.uni-bielefeld.de \
    /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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.