From: "Garreau\, Alexandre" <galex-713@galex-713.eu>
To: Yuri Khan <yurivkhan@gmail.com>
Cc: help-gnu-emacs <help-gnu-emacs@gnu.org>
Subject: Re: point moved despite save-excursion, after deleting/reinserting region
Date: Thu, 18 Oct 2018 13:45:36 +0200 [thread overview]
Message-ID: <87efcnxyu7.fsf@portable.galex-713.eu> (raw)
In-Reply-To: <CAP_d_8UjAT-g_=M49rimxM3qY2Ef86A5MebvHgTcsC91dUykng@mail.gmail.com> (Yuri Khan's message of "Thu, 18 Oct 2018 18:32:24 +0700")
Le 18/10/2018 à 18h32, Yuri Khan a écrit :
> On Thu, Oct 18, 2018 at 4:51 PM Garreau, Alexandre
> <galex-713@galex-713.eu> wrote:
>
>> > When you delete text, markers pointing into that text cannot follow,
>> > they get relocated to the beginning/end of the deletion/insertion.
>> > What else can Emacs do, given that it doesn't know your future
>> > intentions?
>>
>> I thought something such as `save-excursion' would do that, or that it
>> would be saved with the string, or something alike.
>
> Imagine if that was true: that save-excursion could somehow magically
> restore point across deletion of a fragment of text and subsequent
> re-insertion of the same fragment.
>
> Now comes the next guy (me!) and says, what if I re-insert not the
> same fragment but a slight modification of it? Maybe I wrapped it in a
> pair of XML tags. Or removed a pair of XML tags. Anyway, plz restore
> the point Doing The Right Thing, kthx.
>
> How would the hypothetical implementation of save-excursion do that?
>
> …
Yes, if that modification comes from the same string.
> You’d probably want to make buffer-substring to return not only the
> buffer substring but also a representation of all markers within. You
> can’t put them into the string itself because that will confuse the
> algorithms that do the modification. You could probably put it into
> properties, but then those who use buffer-substring-no-properties
> lose. Further, insert would scan the inserted fragment and restore
> markers.
I’d say a function such as buffer-substring-no-properties clearly
indicates you *want* to loose/clear all associated metadata.
Though I’m not sure it may be properly done with text properties: aren’t
these made for storing metadata about *interval* of text, rather than
points? would something such as “#("text" 2 2 plist)” be appropriate?
here it is just taken away at evaluation, and anyway it looks redundant
as well.
> The practical answer to my position-preserving modifications is, do
> them directly in the buffer. If the modifications do not span the
> point, point will be preserved by save-excursion.
>
> Now returning to your modify-evaluate-undo scenario. How important is
> it to you that the evaluation happens in the original buffer? Maybe
> you could copy the fragment to a temporary buffer, modify and evaluate
> it there, have the temporary buffer killed for you? This way, the
> original buffer content is unmodified and the point is unmoved.
> Moreover, the undo history is untouched.
The problem is doing that elsewhere might have other side effects as
well: for instance a source block might use definitions of some other
source block or part of the org-file, or refer to some file, etc. and
anyway copying it in a new buffer, then parsing what its output is, then
putting it in the original buffer, is a lot more complex and error
prone.
The other alternative, of copying the whole widened buffer in a new
buffer, seems overkill, and may, I guess, still cause issues: if there
is a relative path affecting the evaluation, while the
“current-directory” of a such buffer, with no buffer-file, be guaranteed
the same?
next prev parent reply other threads:[~2018-10-18 11:45 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-10-17 1:43 point moved despite save-excursion, after deleting/reinserting region Garreau, Alexandre
2018-10-17 16:12 ` Eli Zaretskii
2018-10-17 20:13 ` Garreau, Alexandre
2018-10-18 2:38 ` Eli Zaretskii
2018-10-18 9:50 ` Garreau, Alexandre
2018-10-18 11:32 ` Yuri Khan
2018-10-18 11:45 ` Garreau, Alexandre [this message]
2018-10-18 13:16 ` Eli Zaretskii
2018-10-18 18:08 ` Saving (and finding) markers (Was: Re: point moved despite save-excursion, after deleting/reinserting region) Garreau, Alexandre
2018-10-18 18:32 ` Eli Zaretskii
2018-10-18 19:36 ` Saving (and finding) markers Garreau, Alexandre
2018-10-18 20:11 ` Eli Zaretskii
2018-10-19 1:15 ` Stefan Monnier
2018-10-19 6:38 ` Eli Zaretskii
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=87efcnxyu7.fsf@portable.galex-713.eu \
--to=galex-713@galex-713.eu \
--cc=help-gnu-emacs@gnu.org \
--cc=yurivkhan@gmail.com \
/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.