From a7934ef2872ce42c06cbb8080b47c18acbd4b53f Mon Sep 17 00:00:00 2001 From: Martin Polden Date: Sat, 28 Jun 2014 20:53:39 +0200 Subject: Output jq errors to a separate buffer --- lisp/init-javascript.el | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'lisp/init-javascript.el') 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 () -- cgit v1.2.3