From: Tassilo Horn <tsdh@gnu.org>
To: help-gnu-emacs@gnu.org
Subject: save-excursion doesn't restore point with json-pretty-print
Date: Fri, 01 Feb 2019 10:32:20 +0100 [thread overview]
Message-ID: <87lg2z7t23.fsf@gnu.org> (raw)
Hi all,
I have this small command in my ~/.emacs:
--8<---------------cut here---------------start------------->8---
(defun th/json-pretty-print-snippet-at-point ()
"Pretty-print the json snippet at point."
(interactive)
(save-excursion
(when (beginning-of-defun)
(let ((beg (point)))
(end-of-defun)
(when (looking-back "\n")
(backward-char))
(json-pretty-print beg (point))))))
--8<---------------cut here---------------end--------------->8---
It works pretty well except that point is not restored. No matter where
I execute it, after reformatting the snippet, point will sit on the
character where `beginning-of-defun' moved it.
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.
Bye,
Tassilo
next reply other threads:[~2019-02-01 9:32 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-01 9:32 Tassilo Horn [this message]
2019-02-01 9:55 ` save-excursion doesn't restore point with json-pretty-print tomas
2019-02-01 10:11 ` Eli Zaretskii
2019-02-01 10:33 ` Robert Pluim
2019-02-01 13:09 ` Eli Zaretskii
2019-02-01 18:02 ` Tassilo Horn
2019-02-01 18:55 ` Eli Zaretskii
2019-02-01 19:14 ` Tassilo Horn
2019-02-01 20:00 ` Tassilo Horn
2019-02-01 20:58 ` Eli Zaretskii
2019-02-01 21:04 ` Tassilo Horn
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=87lg2z7t23.fsf@gnu.org \
--to=tsdh@gnu.org \
--cc=help-gnu-emacs@gnu.org \
/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.