From 837ce23ea348dcb09182fe7a87437b76ec39107b Mon Sep 17 00:00:00 2001 From: Dominik Honnef Date: Sat, 16 Apr 2016 12:42:08 +0200 Subject: [PATCH] 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 --- cmd/guru/go-guru.el | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/cmd/guru/go-guru.el b/cmd/guru/go-guru.el index 564791b6..b837de05 100644 --- a/cmd/guru/go-guru.el +++ b/cmd/guru/go-guru.el @@ -453,9 +453,16 @@ timeout." ;; of an identifier. (defun go-guru--enclosing () - "Return a list of enclosing regions, with duplicates removed." - (let ((enclosing (cdr (assoc 'enclosing (go-guru-what))))) + "Return a list of enclosing regions." + (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 + :from-end t :test (lambda (a b) (and (= (cdr (assoc 'start a)) (cdr (assoc 'start b))) @@ -467,7 +474,7 @@ timeout." (interactive) (let* ((enclosing (if (eq last-command #'go-guru-expand-region) go-guru--last-enclosing - (go-guru--enclosing))) + (go-guru--enclosing-unique))) (block (if (> (length enclosing) 0) (elt enclosing 0)))) (when block (goto-char (1+ (cdr (assoc 'start block))))