summaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorMartin Polden <mpolden@mpolden.no>2020-01-19 00:01:38 +0100
committerMartin Polden <mpolden@mpolden.no>2020-01-19 00:04:06 +0100
commit3f001067dab9082562bdd9819227296869921a2a (patch)
treeeca60a931f15aa21480069c0046db7c90f0763a5 /lisp
parentb816316a9d0fd459030a6ca85b5d776791c13077 (diff)
Revert "Remove imenu customization for go-mode"
This reverts commit f6868dac674a8c2520027fcea8ca279e7d3a7b6e.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/init-go-mode.el30
1 files changed, 29 insertions, 1 deletions
diff --git a/lisp/init-go-mode.el b/lisp/init-go-mode.el
index 2ea28cc..2870978 100644
--- a/lisp/init-go-mode.el
+++ b/lisp/init-go-mode.el
@@ -1,9 +1,37 @@
+(defun go-mode-create-imenu-index ()
+ "Create and return an imenu index alist. Unlike the default
+alist created by go-mode, this method creates an alist where
+items follow a style that is consistent with other prog-modes."
+ (let* ((patterns '(("type" "^type *\\([^ \t\n\r\f]*\\)" 1)))
+ (type-index (imenu--generic-function patterns))
+ (func-index))
+ (save-excursion
+ (goto-char (point-min))
+ (while (re-search-forward go-func-meth-regexp (point-max) t)
+ (let* ((var (match-string-no-properties 1))
+ (func (match-string-no-properties 2))
+ (name (if var
+ (concat (substring var 0 -1) "." func)
+ func))
+ (beg (match-beginning 0))
+ (marker (copy-marker beg))
+ (item (cons name marker)))
+ (setq func-index (cons item func-index)))))
+ (nconc type-index (list (cons "func" func-index)))))
+
+(defun go-mode-create-flat-imenu-index ()
+ "Return a flat imenu index alist. See `go-mode-create-imenu-index'."
+ (apply 'nconc (mapcar 'cdr (go-mode-create-imenu-index))))
+
(use-package go-mode
:init
:config
(add-hook 'go-mode-hook
(lambda ()
;; adjust fill-column
- (setq-local fill-column 120))))
+ (setq-local fill-column 120)
+ ;; use flat imenu index
+ (setq-local imenu-create-index-function
+ #'go-mode-create-flat-imenu-index))))
(provide 'init-go-mode)