Skip to content

Instantly share code, notes, and snippets.

@cipharius
Last active June 26, 2018 17:52
Show Gist options
  • Save cipharius/5ffb6eb18e840c12f63d9719756ed4d4 to your computer and use it in GitHub Desktop.
Save cipharius/5ffb6eb18e840c12f63d9719756ed4d4 to your computer and use it in GitHub Desktop.
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))))
@danielpza
Copy link

Does it work with a region?, I want to sort a js object, not a json

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment