diff options
author | Martin Polden <mpolden@mpolden.no> | 2017-06-22 17:30:59 +0200 |
---|---|---|
committer | Martin Polden <mpolden@mpolden.no> | 2017-06-22 17:30:59 +0200 |
commit | fdb7cbdb8964cdf355b82eec66ddf7f9df7a84e7 (patch) | |
tree | 26ec9521aad22c6373e179a4a03af7f9188618f7 /lisp/init-javascript.el | |
parent | 5a4b2d2a0a7ac10d1e4d759f267b0244d6e9d154 (diff) |
Use built-in function
Diffstat (limited to 'lisp/init-javascript.el')
-rw-r--r-- | lisp/init-javascript.el | 30 |
1 files changed, 1 insertions, 29 deletions
diff --git a/lisp/init-javascript.el b/lisp/init-javascript.el index 3a4cd7f..4d18a70 100644 --- a/lisp/init-javascript.el +++ b/lisp/init-javascript.el @@ -1,31 +1,3 @@ -;; use jq for reformatting json -(defun jq-reformat-region (begin end) - (interactive "r") - (if (executable-find "jq") - (let* ((tmpfile (make-temp-file "jq")) - (errbuf (get-buffer-create "*jq errors*")) - (result (call-process-region begin end "jq" nil - `((:file ,tmpfile) ,tmpfile) nil - "--monochrome-output" "--ascii-output" - ".")) - (success (zerop result)) - (resbuf (if success (current-buffer) errbuf))) - (with-current-buffer resbuf - (insert-file-contents tmpfile nil nil nil t)) - (if success - (progn - (kill-buffer errbuf) - (message "Reformatted JSON")) - (message "Failed to reformat JSON. Check errors for details")) - (delete-file tmpfile)) - (message "Could not find jq in PATH."))) - -(defun jq-reformat () - (interactive) - (if (use-region-p) - (jq-reformat-region (region-beginning) (region-end)) - (jq-reformat-region (point-min) (point-max)))) - (use-package js :ensure nil ;; package is bundled with emacs @@ -39,6 +11,6 @@ :bind (:map js-mode-map ;; C-c p runs formats json with jq - ("C-c p" . jq-reformat))) + ("C-c p" . json-pretty-print-buffer))) (provide 'init-javascript) |