Skip to content

Instantly share code, notes, and snippets.

@ataka
Last active August 29, 2015 14:04
Show Gist options
  • Save ataka/1eae020d49260f8e3594 to your computer and use it in GitHub Desktop.
Save ataka/1eae020d49260f8e3594 to your computer and use it in GitHub Desktop.
Format JSON script aligned with colon
(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