Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Emacs JSON sort
(require 'json)
(defun sort-json (point)
"Sort JSON-like structure surrounding the point."
(interactive "d")
(let ((object-begin (nth 1 (syntax-ppss point)))
(begin-point (point)))
(when object-begin
(goto-char object-begin)
(forward-list)
(with-current-buffer (current-buffer)
(json-pretty-print-ordered object-begin (point))
(indent-region object-begin (point)))
(goto-char begin-point))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment