cmd/guru: emacs: package.el compatibility changes

Make go-guru compatible with package.el prior to uploading this pacakge to
MELPA.

Also add ;;;###autoload magic comments, so that the go-guru-xxx commands can
be used without need to explicitly (require 'go-guru) first.

Change-Id: I21c7f5f354fb7b39877a05c2a9ffecd02ab022f6
Reviewed-on: https://go-review.googlesource.com/19789
Reviewed-by: Dominik Honnef <dominik@honnef.co>
Reviewed-by: Alan Donovan <adonovan@google.com>
This commit is contained in:
Konstantin Shaposhnikov 2016-02-24 08:44:10 +08:00 committed by Alan Donovan
parent 06f9f0dd88
commit a917fb9d7b
1 changed files with 37 additions and 10 deletions

View File

@ -1,13 +1,25 @@
;;; ;;; go-guru.el --- Integration of the Go 'guru' analysis tool into Emacs.
;;; Integration of the Go 'guru' analysis tool into Emacs.
;;; ;; Copyright 2016 The Go Authors. All rights reserved.
;;; To install the Go guru, run: ;; Use of this source code is governed by a BSD-style
;;; $ go get golang.org/x/tools/cmd/guru ;; license that can be found in the LICENSE file.
;;;
;;; Load this file into Emacs and set go-guru-scope to your ;; Version: 0.1
;;; configuration. Then, find a file of Go source code, enable ;; Package-Requires: ((go-mode "1.3.1") (cl-lib "0.5"))
;;; go-guru-mode, select an expression of interest, and press `C-c C-o d' ;; Keywords: tools
;;; (for "describe") or run one of the other go-guru-xxx commands.
;;; Commentary:
;; To install the Go guru, run:
;;
;; $ go get golang.org/x/tools/cmd/guru
;;
;; Load this file into Emacs and set go-guru-scope to your
;; configuration. Then, find a file of Go source code,
;; select an expression of interest, and press `C-c C-o d' (for "describe")
;; or run one of the other go-guru-xxx commands.
;;; Code:
(require 'compile) (require 'compile)
(require 'go-mode) (require 'go-mode)
@ -55,6 +67,7 @@
;; would be having two different functions, but then we can't ;; would be having two different functions, but then we can't
;; automatically call it when no scope has been set. Also it wouldn't ;; automatically call it when no scope has been set. Also it wouldn't
;; easily allow specifying more than one file/package. ;; easily allow specifying more than one file/package.
;;;###autoload
(defun go-guru-set-scope () (defun go-guru-set-scope ()
"Set the scope for the Go guru, prompting the user to edit the "Set the scope for the Go guru, prompting the user to edit the
previous scope. previous scope.
@ -213,27 +226,32 @@ set the point to it, switching the current buffer."
(forward-line (1- (string-to-number (cadr file-line-pos)))) (forward-line (1- (string-to-number (cadr file-line-pos))))
(forward-char (1- (string-to-number (caddr file-line-pos)))))) (forward-char (1- (string-to-number (caddr file-line-pos))))))
;;;###autoload
(defun go-guru-callees () (defun go-guru-callees ()
"Show possible callees of the function call at the current point." "Show possible callees of the function call at the current point."
(interactive) (interactive)
(go-guru--run "callees" t)) (go-guru--run "callees" t))
;;;###autoload
(defun go-guru-callers () (defun go-guru-callers ()
"Show the set of callers of the function containing the current point." "Show the set of callers of the function containing the current point."
(interactive) (interactive)
(go-guru--run "callers" t)) (go-guru--run "callers" t))
;;;###autoload
(defun go-guru-callgraph () (defun go-guru-callgraph ()
"Show the callgraph of the current program." "Show the callgraph of the current program."
(interactive) (interactive)
(go-guru--run "callgraph" t)) (go-guru--run "callgraph" t))
;;;###autoload
(defun go-guru-callstack () (defun go-guru-callstack ()
"Show an arbitrary path from a root of the call graph to the "Show an arbitrary path from a root of the call graph to the
function containing the current point." function containing the current point."
(interactive) (interactive)
(go-guru--run "callstack" t)) (go-guru--run "callstack" t))
;;;###autoload
(defun go-guru-definition () (defun go-guru-definition ()
"Jump to the definition of the selected identifier." "Jump to the definition of the selected identifier."
(interactive) (interactive)
@ -246,39 +264,46 @@ function containing the current point."
(go-guru--goto-pos (cdr (assoc 'objpos res))) (go-guru--goto-pos (cdr (assoc 'objpos res)))
(message "%s" desc))) (message "%s" desc)))
;;;###autoload
(defun go-guru-describe () (defun go-guru-describe ()
"Describe the selected syntax, its kind, type and methods." "Describe the selected syntax, its kind, type and methods."
(interactive) (interactive)
(go-guru--run "describe")) (go-guru--run "describe"))
;;;###autoload
(defun go-guru-pointsto () (defun go-guru-pointsto ()
"Show what the selected expression points to." "Show what the selected expression points to."
(interactive) (interactive)
(go-guru--run "pointsto" t)) (go-guru--run "pointsto" t))
;;;###autoload
(defun go-guru-implements () (defun go-guru-implements ()
"Describe the 'implements' relation for types in the package "Describe the 'implements' relation for types in the package
containing the current point." containing the current point."
(interactive) (interactive)
(go-guru--run "implements")) (go-guru--run "implements"))
;;;###autoload
(defun go-guru-freevars () (defun go-guru-freevars ()
"Enumerate the free variables of the current selection." "Enumerate the free variables of the current selection."
(interactive) (interactive)
(go-guru--run "freevars")) (go-guru--run "freevars"))
;;;###autoload
(defun go-guru-peers () (defun go-guru-peers ()
"Enumerate the set of possible corresponding sends/receives for "Enumerate the set of possible corresponding sends/receives for
this channel receive/send operation." this channel receive/send operation."
(interactive) (interactive)
(go-guru--run "peers" t)) (go-guru--run "peers" t))
;;;###autoload
(defun go-guru-referrers () (defun go-guru-referrers ()
"Enumerate all references to the object denoted by the selected "Enumerate all references to the object denoted by the selected
identifier." identifier."
(interactive) (interactive)
(go-guru--run "referrers")) (go-guru--run "referrers"))
;;;###autoload
(defun go-guru-whicherrs () (defun go-guru-whicherrs ()
"Show globals, constants and types to which the selected "Show globals, constants and types to which the selected
expression (of type 'error') may refer." expression (of type 'error') may refer."
@ -286,3 +311,5 @@ expression (of type 'error') may refer."
(go-guru--run "whicherrs" t)) (go-guru--run "whicherrs" t))
(provide 'go-guru) (provide 'go-guru)
;;; go-guru.el ends here