[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/go-mode 3d801ed 268/495: Ignore anonymous functions if cal
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/go-mode 3d801ed 268/495: Ignore anonymous functions if called with prefix |
Date: |
Sat, 7 Aug 2021 09:05:29 -0400 (EDT) |
branch: elpa/go-mode
commit 3d801eded993b24be2a2c666a7a558a4e73a79a0
Author: Lowe Thiderman <lowe.thiderman@gmail.com>
Commit: Dominik Honnef <dominik@honnef.co>
Ignore anonymous functions if called with prefix
Adds support for ignoring anonymous functions when using the
function-based goto calls. go-goto-docstring and go-goto-method-receiver
both always skip anonymous functions since their targets don't exist for
them.
go-goto-imports is unaffected.
---
go-mode.el | 96 +++++++++++++++++++++++++++++++++++++++++---------------------
1 file changed, 63 insertions(+), 33 deletions(-)
diff --git a/go-mode.el b/go-mode.el
index 131ce75..49c7346 100644
--- a/go-mode.el
+++ b/go-mode.el
@@ -1568,7 +1568,7 @@ for."
(if (not (eq cur-buffer (current-buffer)))
(display-buffer (current-buffer)
`(,go-coverage-display-buffer-func))))))
-(defun go-goto-function ()
+(defun go-goto-function (&optional arg)
"Go to the function defintion above point.
If we are on a docstring, follow the docstring down.
@@ -1577,8 +1577,10 @@ and search forward instead.
If we are inside an anonymous function, go to that.
If we are inside a function that has an anonymous function inside of it and we
-are below that anonymous function, go to the root function."
- (interactive)
+are below that anonymous function, go to the root function.
+
+If one prefix argument is given, anonymous functions are skipped."
+ (interactive "P")
(let ((p (point)))
(cond
((save-excursion
@@ -1591,7 +1593,7 @@ are below that anonymous function, go to the root
function."
(forward-line 1))
;; If we are still not looking at a function, retry by calling self
again.
(when (not (looking-at "^func"))
- (go-goto-function)))
+ (go-goto-function arg)))
((not (looking-at "^func"))
;; If we are not looking at the beginning of a function line, do a regexp
@@ -1608,11 +1610,17 @@ are below that anonymous function, go to the root
function."
;; were not inside it but below it. If we were not inside it, we should
;; go to the containing function.
(while (go--in-function-p p)
- (go-goto-function)))))
+ (go-goto-function arg)))))
- ;; If we are still in a comment, redo the call so that we get out of it.
- (when (go-in-comment-p)
- (go-goto-function)))
+ (cond
+ ((go-in-comment-p)
+ ;; If we are still in a comment, redo the call so that we get out of it.
+ (go-goto-function arg))
+
+ ((and (looking-at "func(") (equal arg '(4)))
+ ;; If we are looking at an anonymous function and a prefix argument has
+ ;; been supplied, redo the call so that we skip the anonymous function.
+ (go-goto-function arg))))
(defun go--in-function-p (compare-point)
"Return t if `compare-point' is inside the function that point is currently
on.
@@ -1641,14 +1649,16 @@ Returns nil in all other cases."
;; comparing point. Return t if it is.
(< (point) compare-point)))))
-(defun go-goto-function-name ()
+(defun go-goto-function-name (&optional arg)
"Go to the name of the current function.
If the function is a test, place point after 'Test'.
-If the function is anonymous, place point on the 'func' keyword."
- (interactive)
+If the function is anonymous, place point on the 'func' keyword.
+
+If one prefix argument is given, anonymous functions are skipped."
+ (interactive "P")
(when (not (looking-at "func"))
- (go-goto-function))
+ (go-goto-function arg))
;; If we are looking at func( we are on an anonymous function and
;; nothing else should be done.
(when (not (looking-at "func("))
@@ -1662,27 +1672,31 @@ If the function is anonymous, place point on the 'func'
keyword."
(when (looking-at "Test")
(forward-char 4)))))
-(defun go-goto-arguments ()
- "Go to the arguments of the current function."
- (interactive)
- (go-goto-function-name)
+(defun go-goto-arguments (&optional arg)
+ "Go to the arguments of the current function.
+
+If one prefix argument is given, anonymous functions are skipped."
+ (interactive "P")
+ (go-goto-function-name arg)
(forward-word 1)
(forward-char 1))
-(defun go--goto-return-values ()
+(defun go--goto-return-values (&optional arg)
"Go to the declaration of return values for the current function."
- (go-goto-arguments)
+ (go-goto-arguments arg)
(backward-char)
(forward-list)
(forward-char))
-(defun go-goto-return-value ()
+(defun go-goto-return-value (&optional arg)
"Go to the return value declaration of the current function.
If there are multiple ones contained in a parenthesis, enter the parenthesis.
-If there is none, make space for one to be added."
- (interactive)
- (go--goto-return-values)
+If there is none, make space for one to be added.
+
+If one prefix argument is given, anonymous functions are skipped."
+ (interactive "P")
+ (go--goto-return-values arg)
;; Opening parenthesis, enter it
(when (looking-at "(")
@@ -1693,28 +1707,42 @@ If there is none, make space for one to be added."
(insert " ")
(backward-char 1)))
-(defun go-goto-method-receiver ()
+(defun go-goto-method-receiver (&optional arg)
"Go to the receiver of the current method.
-If there is none, add parenthesis to add one."
- (interactive)
+If there is none, add parenthesis to add one.
- (when (go--in-anonymous-funcion-p)
+Anonymous functions cannot have method receivers, so when this is called
+interactively anonymous functions will be skipped. If called programmatically,
+an error is raised."
+ (interactive "P")
+
+ (when (and (not (called-interactively-p 'interactive))
+ (go--in-anonymous-funcion-p))
(error "Anonymous functions cannot have method receivers"))
- (go-goto-function)
+ (go-goto-function '(4)) ; Always skip anonymous functions
(forward-char 5)
(when (not (looking-at "("))
(save-excursion
(insert "() ")))
(forward-char 1))
-(defun go-goto-docstring ()
+(defun go-goto-docstring (&optional arg)
"Go to the top of the docstring of the current function.
-If there is none, add slashes to start writing one."
- (interactive)
- (go-goto-function)
+If there is none, add slashes to start writing one.
+
+Anonymous functions do not have docstrings, so when this is called
+interactively anonymous functions will be skipped. If called programmatically,
+an error is raised."
+ (interactive "P")
+
+ (when (and (not (called-interactively-p 'interactive))
+ (go--in-anonymous-funcion-p))
+ (error "Anonymous functions do not have docstrings"))
+
+ (go-goto-function '(4))
(forward-line -1)
(beginning-of-line)
@@ -1739,9 +1767,11 @@ If there is none, add slashes to start writing one."
(insert (format "// %s " (go--get-function-name))))))
(defun go--get-function-name ()
- "Return the current function name as a string"
+ "Return the current function name as a string.
+
+Will skip anonymous functions since they do not have names."
(save-excursion
- (go-goto-function-name)
+ (go-goto-function-name '(4))
(symbol-name (symbol-at-point))))
(defun go--in-anonymous-funcion-p ()
- [nongnu] elpa/go-mode 466e188 239/495: add `go-play-browse-function', (continued)
- [nongnu] elpa/go-mode 466e188 239/495: add `go-play-browse-function', ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 8c13a82 240/495: match identifiers, not type names, when highlighting struct literal, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 775c77a 241/495: immediately store match data in go-unused-imports-lines, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode aaea941 242/495: bump version to 1.2.0, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode bf4a097 243/495: add Iwasaki Yudai to AUTHORS, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 498452d 244/495: Don't set old buffer as active after godef--find-file-line-column, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 7041a20 245/495: Bump version to 1.2.1, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode bbaba91 246/495: Add godoc-mode, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 26493e3 264/495: Fix bug in go-goto-function if point is on a non-docstring, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode fa29aea 265/495: go-goto-method-receiver: handle anonymous functions, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 3d801ed 268/495: Ignore anonymous functions if called with prefix,
ELPA Syncer <=
- [nongnu] elpa/go-mode c0a3a16 269/495: Update README.md to reflect the latest version of the truth, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode c849d72 273/495: Don't throw errors in some go-goto-* functions, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 37b9f9c 272/495: Change handling of prefix args to consider them booleans, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode c8c6bb0 275/495: go--function-name: return nil for anonymous functions, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode f58910a 276/495: Reimplement go--in-function-p to do as the name says, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode f44854b 278/495: More idiomatic docstrings, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 9424ab3 283/495: Map C-g f to goto-function and C-g n to goto-function-name, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode abc56d4 286/495: Rename go-goto-return-value to go-goto-return-values, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode e4cd631 288/495: Update AUTHORS, automate process, ELPA Syncer, 2021/08/07
- [nongnu] elpa/go-mode 63e67b1 290/495: go-goto-docstring: fix insertion of function name, ELPA Syncer, 2021/08/07