cmd/guru: emacs: report most specific element in expand-region

Keep the leftmost element when removing duplicates, so that we report
"function call" instead of "expression statement".

Also split go-guru--enclosing into two functions.

Change-Id: Ie325613e292e36dda9558eda54bc7323fbf0bc6d
Reviewed-on: https://go-review.googlesource.com/22132
Reviewed-by: Alan Donovan <adonovan@google.com>
This commit is contained in:
Dominik Honnef 2016-04-16 12:42:08 +02:00 committed by Alan Donovan
parent 321c6fd171
commit 837ce23ea3
1 changed files with 10 additions and 3 deletions

View File

@ -453,9 +453,16 @@ timeout."
;; of an identifier. ;; of an identifier.
(defun go-guru--enclosing () (defun go-guru--enclosing ()
"Return a list of enclosing regions, with duplicates removed." "Return a list of enclosing regions."
(let ((enclosing (cdr (assoc 'enclosing (go-guru-what))))) (cdr (assoc 'enclosing (go-guru-what))))
(defun go-guru--enclosing-unique ()
"Return a list of enclosing regions, with duplicates removed.
Two regions are considered equal if they have the same start and
end point."
(let ((enclosing (go-guru--enclosing)))
(cl-remove-duplicates enclosing (cl-remove-duplicates enclosing
:from-end t
:test (lambda (a b) :test (lambda (a b)
(and (= (cdr (assoc 'start a)) (and (= (cdr (assoc 'start a))
(cdr (assoc 'start b))) (cdr (assoc 'start b)))
@ -467,7 +474,7 @@ timeout."
(interactive) (interactive)
(let* ((enclosing (if (eq last-command #'go-guru-expand-region) (let* ((enclosing (if (eq last-command #'go-guru-expand-region)
go-guru--last-enclosing go-guru--last-enclosing
(go-guru--enclosing))) (go-guru--enclosing-unique)))
(block (if (> (length enclosing) 0) (elt enclosing 0)))) (block (if (> (length enclosing) 0) (elt enclosing 0))))
(when block (when block
(goto-char (1+ (cdr (assoc 'start block)))) (goto-char (1+ (cdr (assoc 'start block))))