[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/go-mode a88f1d5 115/495: add support for godef
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/go-mode a88f1d5 115/495: add support for godef |
Date: |
Sat, 7 Aug 2021 09:04:55 -0400 (EDT) |
branch: elpa/go-mode
commit a88f1d5c63ec7f9f35eb5b46c01f969b5b6bc287
Author: Dominik Honnef <dominikh@fork-bomb.org>
Commit: Dominik Honnef <dominikh@fork-bomb.org>
add support for godef
this allows us to jump to definitions as well as get descriptions for
expressions
---
README.md | 5 ++++-
go-mode.el | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 60 insertions(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 1d4fde7..5066d5f 100644
--- a/README.md
+++ b/README.md
@@ -36,6 +36,8 @@ Features
- A function for jumping to the file's imports (`go-goto-imports`)
- A function for adding imports, including tab completion (`go-import-add`,
bound to `C-c C-a`)
- A function for removing or commenting unused imports
(`go-remove-unused-imports`)
+- `godef-describe` and `godef-jump` (`C-c C-d` and `C-c C-j`) to
+ describe expressions and jump to their declarations.
- Adds basic support for imenu (functions and variables)
Other extensions
@@ -43,7 +45,8 @@ Other extensions
For a richer experience, consider installing
[goflymake](https://github.com/dougm/goflymake) for on-the-fly syntax
checking and [gocode](https://github.com/nsf/gocode) for auto
-completion.
+completion. Some features require you to install godef via `go get
+code.google.com/p/rog-go/exp/cmd/godef`.
Also, if you're using YASnippet, consider using the snippets from
[yasnippet-go](https://github.com/dominikh/yasnippet-go).
diff --git a/go-mode.el b/go-mode.el
index 980a182..4e615d4 100644
--- a/go-mode.el
+++ b/go-mode.el
@@ -123,6 +123,8 @@
(define-key m ":" 'go-mode-insert-and-indent)
(define-key m "=" 'go-mode-insert-and-indent)
(define-key m (kbd "C-c C-a") 'go-import-add)
+ (define-key m (kbd "C-c C-j") 'godef-jump)
+ (define-key m (kbd "C-c C-d") 'godef-describe)
m)
"Keymap used by Go mode to implement electric keys.")
@@ -718,4 +720,58 @@ will be commented, otherwise they will be removed
completely."
(message "Removed %d imports" (length lines)))
(if flymake-state (flymake-mode-on)))))
+(defun godef--find-file-line-column (specifier)
+ "Given a file name in the format of `filename:line:column',
+visit FILENAME and go to line LINE and column COLUMN."
+ (let* ((components (split-string specifier ":"))
+ (line (string-to-number (nth 1 components)))
+ (column (string-to-number (nth 2 components))))
+ (with-current-buffer (find-file (car components))
+ (goto-char (point-min))
+ (forward-line (1- line))
+ (beginning-of-line)
+ (forward-char (1- column))
+ (if (buffer-modified-p)
+ (message "Buffer is modified, file position might not have been
correct")))))
+
+(defun godef--call (point)
+ "Call godef, acquiring definition position and expression
+description at POINT."
+ (if (go--xemacs-p)
+ (error "godef does not reliably work in XEmacs, sorry"))
+ (if (not buffer-file-name)
+ (message "Cannot use godef on a buffer without a file name")
+ (let ((outbuf (get-buffer-create "*godef*")))
+ (with-current-buffer outbuf
+ (erase-buffer))
+ (call-process-region (point-min) (point-max) "godef" nil outbuf nil "-i"
"-t" "-f" (file-truename buffer-file-name) "-o" (number-to-string
(position-bytes (point))))
+ (with-current-buffer outbuf
+ (split-string (buffer-substring-no-properties (point-min) (point-max))
"\n")))))
+
+(defun godef-describe (point)
+ "Describe the expression at POINT."
+ (interactive "d")
+ (condition-case nil
+ (let ((description (nth 1 (godef--call point))))
+ (if (string= "" description)
+ (message "No description found for expression at point")
+ (message "%s" description)))
+ (file-error (message "Could not run godef binary"))))
+
+(defun godef-jump (point)
+ "Jump to the definition of the expression at POINT."
+ (interactive "d")
+ (condition-case nil
+ (let ((file (car (godef--call point))))
+ (cond
+ ((string= "-" file)
+ (message "godef: expression is not defined anywhere"))
+ ((string= "godef: no identifier found" file)
+ (message "%s" file))
+ ((go--string-prefix-p "godef: no declaration found for " file)
+ (message "%s" file))
+ (t
+ (godef--find-file-line-column file))))
+ (file-error (message "Could not run godef binary"))))
+
(provide 'go-mode)
- [nongnu] elpa/go-mode 3139c0f 107/495: fix regexp-opt usage for emacs <24, (continued)
- [nongnu] elpa/go-mode 3139c0f 107/495: fix regexp-opt usage for emacs <24, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 8fb900e 062/495: refactor, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 183c028 068/495: use (car (last)) instead of (car (reverse)), ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 0f71cee 083/495: add autoload cookie to gofmt-before-save, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode f0059f6 098/495: in go-packages, skip over directories that do not contain a /pkg subdirectory, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 3d3ba73 103/495: Use completing-read in godoc--read-query, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 67bb849 108/495: use \\_< instead of \\< and do so in a way that won't break XEmacs, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 4637dd6 110/495: Mention gofmt rewrite in README, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode d910a0d 112/495: Make _ a word constituent to accomodate inferiority of XEmacs, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode c1074a1 114/495: improve regexps for array, slice and map types, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode a88f1d5 115/495: add support for godef,
ELPA Syncer <=
- [nongnu] elpa/go-mode 4935203 117/495: add guidelines for contributions, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 0e5fd93 119/495: update LEGAL, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 92102a5 120/495: do not rely on find-lisp, xemacs doesn't have that, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode bb66ca4 122/495: xemacs comment handling, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 8476d21 123/495: provide alternative to syntax-ppss for older versions of xemacs, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 052a356 125/495: remove unused variables, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 60dec2c 126/495: add godef documentation, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode dc68bd2 124/495: add a lot of compatibility for xemacs, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode b880a36 139/495: derive go-mode from prog-mode if possible, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 7411757 141/495: readme: move godef install instructions up to first mentioning of godef, ELPA Syncer, 2021/08/07