Last active
August 29, 2015 14:04
-
-
Save ataka/1eae020d49260f8e3594 to your computer and use it in GitHub Desktop.
Format JSON script aligned with colon
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
(defun json-reformat-region-align-colon (beg end) | |
(interactive "r") | |
(save-restriction | |
(narrow-to-region beg end) | |
(goto-char (point-min)) | |
(while (search-forward "," nil t) | |
(insert "\n") | |
(let ((col-prev (progn (forward-line -1) | |
(end-of-line) | |
(search-backward ":") | |
(current-column))) | |
(col (progn (forward-line 1) | |
(search-forward ":") | |
(1- (current-column))))) | |
(forward-line 0) | |
(insert (format (concat "% " (number-to-string (- col-prev col)) "s") "")))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment