Last active
June 26, 2018 17:52
-
-
Save cipharius/5ffb6eb18e840c12f63d9719756ed4d4 to your computer and use it in GitHub Desktop.
Emacs JSON sort
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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
Does it work with a region?, I want to sort a js object, not a json