diff options
author | Martin Polden <martin.polden@gmail.com> | 2016-02-26 10:54:45 +0100 |
---|---|---|
committer | Martin Polden <martin.polden@gmail.com> | 2016-02-26 10:55:58 +0100 |
commit | 35a1f2f2ff44eff6e40642fb8bf0c981e292fb32 (patch) | |
tree | 60a4da3d398dc07897ce7955b12a5ce8d8fbd95f | |
parent | fa8e9cf7837f998cb0ae0ab6f86c905d6d7763fd (diff) |
Cleanup go-mode config
-rw-r--r-- | lisp/init-go-mode.el | 60 |
1 files changed, 29 insertions, 31 deletions
diff --git a/lisp/init-go-mode.el b/lisp/init-go-mode.el index 51440d5..1b9a67e 100644 --- a/lisp/init-go-mode.el +++ b/lisp/init-go-mode.el @@ -8,15 +8,38 @@ ;; run gofmt before saving file (add-hook 'before-save-hook 'gofmt-before-save) - ;; configure company-mode - ;; requires https://github.com/nsf/gocode for the backend - (when (and (featurep 'company) (featurep 'company-go)) - (add-hook 'go-mode-hook (lambda () - (setq-local company-backends '(company-go)) - (company-mode)))) + (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)))) (add-hook 'go-mode-hook (lambda () + ;; company-mode + ;; requires https://github.com/nsf/gocode for the backend + (when (and (featurep 'company) (featurep 'company-go)) + (setq-local company-backends '(company-go)) + (company-mode 1)) ;; C-c p runs gofmt on the buffer (define-key go-mode-map (kbd "C-c p") 'gofmt) ;; adjust fill-column @@ -25,29 +48,4 @@ (setq-local imenu-create-index-function #'go-mode-create-flat-imenu-index)))) -(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)))) - (provide 'init-go-mode) |