mirror of
https://github.com/golang/go
synced 2024-11-18 11:04:42 -07: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:
parent
19c83edf02
commit
d7762ee5c0
@ -127,14 +127,21 @@ a scope if not already set. Return the output buffer."
|
|||||||
(message nil) ; clears/shrinks minibuffer
|
(message nil) ; clears/shrinks minibuffer
|
||||||
(message "Running guru...")
|
(message "Running guru...")
|
||||||
;; Use dynamic binding to modify/restore the environment
|
;; Use dynamic binding to modify/restore the environment
|
||||||
(let ((process-environment (list* goroot-env gopath-env process-environment)))
|
(let* ((process-environment (list* goroot-env gopath-env process-environment))
|
||||||
(apply #'call-process-region (append (list (point-min)
|
(c-p-args (append (list (point-min)
|
||||||
(point-max)
|
(point-max)
|
||||||
go-guru-command
|
go-guru-command
|
||||||
nil ; delete
|
nil ; delete
|
||||||
output-buffer
|
output-buffer
|
||||||
t)
|
t)
|
||||||
args)))))
|
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))
|
output-buffer))
|
||||||
|
|
||||||
(defun go-guru--compilation-markup ()
|
(defun go-guru--compilation-markup ()
|
||||||
@ -227,8 +234,8 @@ function containing the current point."
|
|||||||
;; TODO(adonovan): use -format=sexpr when available to avoid a
|
;; TODO(adonovan): use -format=sexpr when available to avoid a
|
||||||
;; dependency and to simplify parsing.
|
;; dependency and to simplify parsing.
|
||||||
(let* ((res (with-current-buffer (go-guru--exec "definition" nil '("-format=json"))
|
(let* ((res (with-current-buffer (go-guru--exec "definition" nil '("-format=json"))
|
||||||
(goto-char (point-min))
|
(goto-char (point-min))
|
||||||
(cdr (car (json-read)))))
|
(cdr (car (json-read)))))
|
||||||
(desc (cdr (assoc 'desc res))))
|
(desc (cdr (assoc 'desc res))))
|
||||||
(go-guru--goto-pos (cdr (assoc 'objpos res)))
|
(go-guru--goto-pos (cdr (assoc 'objpos res)))
|
||||||
(message "%s" desc)))
|
(message "%s" desc)))
|
||||||
|
Loading…
Reference in New Issue
Block a user