emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/go-mode c8c6bb0 275/495: go--function-name: return nil for


From: ELPA Syncer
Subject: [nongnu] elpa/go-mode c8c6bb0 275/495: go--function-name: return nil for anonymous functions
Date: Sat, 7 Aug 2021 09:05:30 -0400 (EDT)

branch: elpa/go-mode
commit c8c6bb0667091b0412c3714db32f7057a53b6f64
Author: Lowe Thiderman <lowe.thiderman@gmail.com>
Commit: Dominik Honnef <dominik@honnef.co>

    go--function-name: return nil for anonymous functions
    
    Also add a similar API to the other functions that modify things that
    don't apply to anonymous functions; an optional argument that toggles
    if the function should ignore anonymous functions or not. The function
    returns nil if the argument is nil and point is in an anonymous
    function.
---
 go-mode.el | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/go-mode.el b/go-mode.el
index 65fe48e..adf3927 100644
--- a/go-mode.el
+++ b/go-mode.el
@@ -1757,7 +1757,7 @@ an error is raised."
    ;; If we are looking at an empty comment, add a single space in front of it.
    ((looking-at "^//$")
     (forward-char 2)
-    (insert (format " %s " (go--function-name))))
+    (insert (format " %s " (go--function-name t))))
    ;; If we are not looking at the function signature, we are looking at a 
docstring.
    ;; Move to the beginning of the first word of it.
    ((not (looking-at "^func"))
@@ -1766,15 +1766,20 @@ an error is raised."
    (t
     (forward-line -1)
     (newline)
-    (insert (format "// %s " (go--function-name))))))
+    (insert (format "// %s " (go--function-name t))))))
 
-(defun go--function-name ()
+(defun go--function-name (&optional arg)
   "Return the current function name as a string.
 
-Will skip anonymous functions since they do not have names."
-  (save-excursion
-    (go-goto-function-name t)
-    (symbol-name (symbol-at-point))))
+If `arg' is non-nil anonymous functions will be ignored and the
+name returned will be of the top-level function.
+
+Returns nil otherwise."
+  (when (or (not (go--in-anonymous-funcion-p))
+            arg)
+    (save-excursion
+      (go-goto-function-name t)
+      (symbol-name (symbol-at-point)))))
 
 (defun go--in-anonymous-funcion-p ()
   "Return t if point is inside an anonymous function, nil otherwise."



reply via email to

[Prev in Thread] Current Thread [Next in Thread]