Last active
May 8, 2019 04:30
-
-
Save leavesofgrass/23cf0f61e0092e36dbbaa3f33e4dd060 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
;; pretty print json files when they're opened and minify them when they are saved | |
(add-to-list 'auto-mode-alist | |
'("\\.json\\'" . (lambda () | |
(json-mode) | |
(json-pretty-print (point-min) (point-max)) | |
(goto-char (point-min)) | |
(set-buffer-modified-p nil)))) | |
(defun minify-json-buffer-contents() | |
"Minifies the buffer contents by removing whitespaces." | |
(interactive) | |
(delete-whitespace-rectangle (point-min) (point-max)) | |
(mark-whole-buffer) | |
(goto-char (point-min)) | |
(while (search-forward "\n" nil t) (replace-match "" nil t))) | |
(add-hook 'json-mode-hook | |
(lambda () | |
(add-hook 'before-save-hook 'minify-json-buffer-contents))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment