1
0
mirror of https://github.com/golang/go synced 2024-09-30 14:18:32 -06:00

cmd/guru: emacs: report an error when the guru command fails

Don't just display the output buffer or, worse, parse it as JSON.

Change-Id: I1125ff235a5073b07f45f587ef8844b8a12f05ac
Reviewed-on: https://go-review.googlesource.com/19508
Reviewed-by: Michael Matloob <matloob@golang.org>
This commit is contained in:
Alan Donovan 2016-02-15 15:43:58 -05:00 committed by Alan Donovan
parent 19c83edf02
commit d7762ee5c0

View File

@ -127,14 +127,21 @@ a scope if not already set. Return the output buffer."
(message nil) ; clears/shrinks minibuffer
(message "Running guru...")
;; Use dynamic binding to modify/restore the environment
(let ((process-environment (list* goroot-env gopath-env process-environment)))
(apply #'call-process-region (append (list (point-min)
(point-max)
go-guru-command
nil ; delete
output-buffer
t)
args)))))
(let* ((process-environment (list* goroot-env gopath-env process-environment))
(c-p-args (append (list (point-min)
(point-max)
go-guru-command
nil ; delete
output-buffer
t)
args))
(exitcode (apply #'call-process-region c-p-args)))
;; If the command fails, don't show the output buffer,
;; but use its contents (sans final \n) as an error.
(unless (zerop exitcode)
(with-current-buffer output-buffer
(bury-buffer)
(error "%s" (buffer-substring (point-min) (1- (point-max)))))))))
output-buffer))
(defun go-guru--compilation-markup ()
@ -227,8 +234,8 @@ function containing the current point."
;; TODO(adonovan): use -format=sexpr when available to avoid a
;; dependency and to simplify parsing.
(let* ((res (with-current-buffer (go-guru--exec "definition" nil '("-format=json"))
(goto-char (point-min))
(cdr (car (json-read)))))
(goto-char (point-min))
(cdr (car (json-read)))))
(desc (cdr (assoc 'desc res))))
(go-guru--goto-pos (cdr (assoc 'objpos res)))
(message "%s" desc)))