branch: elpa/go-mode
commit f03998154bbed359f1912284a49b598fef074406
Author: Dominik Honnef <[email protected]>
Commit: Dominik Honnef <[email protected]>

    go-beginning-of-defun: only move to end of line when we're on a declaration
    
    Some code (e.g. evil-mode) doesn't expect beginning-of-defun (with
    positive arguments) to move the point forward. We move it to the end of
    line to ensure we find the function declaration that point might already
    be on. Do this conditionally to ensure we only move the point to eol
    when a later re-search-backward will undo that motion.
    
    Updates gh-186
---
 go-mode.el | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/go-mode.el b/go-mode.el
index f31e4bffdd..8bc912e1ab 100644
--- a/go-mode.el
+++ b/go-mode.el
@@ -1240,8 +1240,18 @@ INDENT is the normal indent of this line, i.e. that of 
the case body."
           (goto-char (- (point-max) pos))))))
 
 (defun go-beginning-of-defun (&optional count)
-  (unless (bolp)
-    (end-of-line))
+  (when (and (not (go-in-string-or-comment-p))
+                        (not (bolp))
+                        (save-excursion
+                          (beginning-of-line)
+                          (looking-at go-func-meth-regexp)))
+       ;; Point is already somewhere on the function definition. Move to the 
end of line so that searching backwards finds
+       ;; it. We don't go to the end of line unconditionally because that 
confuses evil-mode
+       ;; (https://github.com/dominikh/go-mode.el/issues/186)
+       ;;
+       ;; If point is already at the beginning of line and looking at a 
function, then we want go-beginning-of-defun to
+       ;; jump to the previous function instead.
+       (end-of-line))
   (setq count (or count 1))
   (let (first failure)
     (dotimes (i (abs count))

Reply via email to