all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* save-excursion doesn't restore point with json-pretty-print
@ 2019-02-01  9:32 Tassilo Horn
  2019-02-01  9:55 ` tomas
  0 siblings, 1 reply; 11+ messages in thread
From: Tassilo Horn @ 2019-02-01  9:32 UTC (permalink / raw)
  To: help-gnu-emacs

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



^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2019-02-01 21:04 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-02-01  9:32 save-excursion doesn't restore point with json-pretty-print Tassilo Horn
2019-02-01  9:55 ` 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

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.