diff options
author | Martin Polden <martin.polden@gmail.com> | 2014-06-28 20:53:39 +0200 |
---|---|---|
committer | Martin Polden <martin.polden@gmail.com> | 2014-06-28 20:57:00 +0200 |
commit | a7934ef2872ce42c06cbb8080b47c18acbd4b53f (patch) | |
tree | f8852b87d712931ee7b4eeed31d12b8475727b09 /lisp | |
parent | 4ec089e19a07fe155cddf07d7ca91adb7fe321a2 (diff) |
Output jq errors to a separate buffer
Diffstat (limited to 'lisp')
-rw-r--r-- | lisp/init-javascript.el | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/lisp/init-javascript.el b/lisp/init-javascript.el index 4cbed8a..0a8d0f3 100644 --- a/lisp/init-javascript.el +++ b/lisp/init-javascript.el @@ -12,8 +12,19 @@ (defun jq-reformat-region (begin end) (interactive "r") (if (executable-find "jq") - (shell-command-on-region - begin end "jq --monochrome-output --ascii-output ." (current-buffer) t) + (let* ((tmpfile (make-temp-file "jq")) + (errbuf (get-buffer-create "*jq errors*")) + (success (zerop (call-process-region begin end "jq" nil + `((:file ,tmpfile) ,tmpfile) + nil "--monochrome-output" + "--ascii-output" "."))) + (resbuf (if success (current-buffer) errbuf))) + (with-current-buffer resbuf + (insert-file-contents tmpfile nil nil nil t)) + (if success + (kill-buffer errbuf) + (message "Failed to reformat JSON. Check errors for details")) + (delete-file tmpfile)) (message "Could not find jq in PATH."))) (defun jq-reformat () |