Skip to content

Instantly share code, notes, and snippets.

@vbsteven
Created January 24, 2014 08:41
Show Gist options
  • Save vbsteven/8594030 to your computer and use it in GitHub Desktop.
Save vbsteven/8594030 to your computer and use it in GitHub Desktop.
;; json formatting functions
;; replace region with json formatted version
(defun json-format ()
(interactive)
(save-excursion
(shell-command-on-region (mark) (point) "python -m json.tool" (buffer-name) t)
)
)
;; format json and output result in new new buffer
(defun json-format-other-buffer ()
(interactive)
(shell-command-on-region (mark) (point) "python -m json.tool" (get-buffer-create "*json*"))
(view-buffer-other-window "*json*")
(javascript-mode)
(view-mode)
)
(global-set-key "\C-cfj" 'json-format)
(global-set-key "\C-cvj" 'json-format-other-buffer)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment