summaryrefslogtreecommitdiffstats
path: root/lisp/init-go.el
diff options
context:
space:
mode:
authorMartin Polden <mpolden@mpolden.no>2020-01-26 13:24:51 +0100
committerMartin Polden <mpolden@mpolden.no>2020-01-26 13:29:41 +0100
commit5683530e98a45dcc3163b4ddea038868efdb466a (patch)
tree1504b39ecb6e6d3f978bdefe60e61053dd2605f9 /lisp/init-go.el
parentc9d8509c5bf2f1aee7d4859c2234a683d0a4cb9a (diff)
Remove "-mode" suffix from filenames
Diffstat (limited to 'lisp/init-go.el')
-rw-r--r--lisp/init-go.el37
1 files changed, 37 insertions, 0 deletions
diff --git a/lisp/init-go.el b/lisp/init-go.el
new file mode 100644
index 0000000..07141e1
--- /dev/null
+++ b/lisp/init-go.el
@@ -0,0 +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)
+ ;; use flat imenu index
+ (setq-local imenu-create-index-function
+ #'go-mode-create-flat-imenu-index))))
+
+(provide 'init-go)