emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: save-excursion and the mark


From: Oleh Krehel
Subject: Re: save-excursion and the mark
Date: Tue, 24 Feb 2015 09:47:47 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux)

Artur Malabarba <address@hidden> writes:

> 2015-02-23 23:14 GMT+00:00 Oleh Krehel <address@hidden>:
>> Stefan Monnier <address@hidden> writes:
>>
>>>> I have a package that might be using the feature.
>>>
>>> Where and how?
>>
>> It's at https://github.com/abo-abo/lispy. There's a bunch of functions
>> that manipulate the active region sexp-wise. Some of them might use the
>> fact that the mark is restored. I can't be sure until I get a
>> `save-excursion' version that doesn't touch the mark.
>
> I think the following should do it.
>
> (cl-letf* (((point-marker))
>           ((current-buffer)))
>     ;; Your code here.
>     )
>
>> Supposing that you would disable the mark storing/restoring in
>> `save-excursion', I rewrote my code to save/restore the mark on top of
>> that. It didn't hurt the tests.
> It couldn't have hut the tests, given that it's redundant :-) (for now
> at least).

It might well could. If I was storing the point in this naive way, the
tests would have failed, since the point is adjusted by `save-excursion'
to the amount of text deleted. If I suppose that the mark was adjusted
as well, and the tests were using this aspect, then they would fail with
my naive approach on top of regular `save-excursion'.

>> It was hard for me to write my own `save-excursion' in Elisp to
>> completely test it, since it's not obvious how it works when chunks of
>> text are deleted.
>
> I think it just follows the point marker. Test the snippet above and
> see if it works for you.

It works! Thanks.

Oleh



reply via email to

[Prev in Thread] Current Thread [Next in Thread]