1

When a golang function signature is split with a linebreak it does not appear in imenu nor helm-imenu. I would like to jump between functions using helm-imenu, but this issue is in my way. Not hard-wrapping the function signatures is not a solution because others on my team have other preferences.

For example:

// This function does _not_ appear in imenu.
func (b *Foo) LongFunction(ctx context.Context, a A,
    b B, c C) foobar.Bazzybaz {
...
}

// But this one does!
func (b *Foo) ShortFunction(ctx context.Context, d D) foobar.Wazoo {
...
}

Short of fixing the problem for me, it would be super helpful if you could point me towards where helm-menu/imenu gets its symbol list in the first place. Or another package suggestion for fuzzy-searching the file's function list.

emacs 24.5 (9.0)
osx 10.12.3

1
  • 2
    See imenu.el, variable imenu-generic-expression
    – Drew
    Feb 17 '17 at 17:02
1

Fixed it by changing the value of imenu-generic-expression to

'(("type" "^[ \t]*type *\\([^ \t\n\r\f]*[ \t]*\\(struct\\|interface\\)\\)" 1)
  ("func" "^func *\\(.*\\)" 1)))

Which has two advantages over the original value. it recognizes split-line functions, and it notices embedded types.

I'll probably submit a PR to go-mode, but until then to get this rolling you can do

;;; Go mode.
(defun my-go-mode-hook ()
  ; Custom imenu regexes
  (setq imenu-generic-expression
        '(("type" "^[ \t]*type *\\([^ \t\n\r\f]*[ \t]*\\(struct\\|interface\\)\\)" 1)
          ("func" "^func *\\(.*\\)" 1)))
  )

 (add-hook 'go-mode-hook 'my-go-mode-hook)

Thanks for the tip about imenu-generic-expression Drew!

1
  • 1
    Thanks for posting your solution! Could you please accept your own answer so we can mark this post as done?
    – Dan
    Mar 19 '17 at 21:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.