help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: save-excursion doesn't restore point with json-pretty-print


From: tomas
Subject: Re: save-excursion doesn't restore point with json-pretty-print
Date: Fri, 1 Feb 2019 10:55:16 +0100
User-agent: Mutt/1.5.21 (2010-09-15)

On Fri, Feb 01, 2019 at 10:32:20AM +0100, Tassilo Horn wrote:
> Hi all,
> 
> I have this small command in my ~/.emacs:

[...]

> For example, when point is on the 1 below,
> 
> {"foo": 1, "bar":27}
> 
> I'll end up with
> 
> {
>   "foo": 1,
>   "bar": 27
> }
> 
> and point is on the {.  I'd expect it to still sit on the 1.
> 
> Obviously, `save-excursion' works just fine in all other places.  It
> seems like it's just not playing well with `json-pretty-print', and I
> don't know why.

AFAIK the mechanism for save-excursion is to set a special marker
to return to after the excursion.

Now the pretty print probably replaces the whole region in the
process: the marker can't be at the same place where it was. If
you're lucky, it'll be at one of both region's borders.

A more careful pretty-print process which is capable of "floating"
existing markers around sounds like an interesting challenge :-)

(Note that this is just armchair analysis, and I could be totally
wrong).

Cheers
-- tomás

Attachment: signature.asc
Description: Digital signature


reply via email to

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