2

Is it available a mode that, entering a source file, scans it to find all the function, class and methods declarations and eventually install a menu that enables jumping around in the source file?

I used to use fume-mode (?) where fume is for function menu, but I haven't seen it in the list of installable packages...

0

1 Answer 1

3

You can use imenu-mode for that purpose. It comes shipped with emacs and most programming modes support it.

EDIT2: You could simply start it with this:

(add-hook 'prog-mode-hook (lambda () (imenu-add-to-menubar "Imenu")))

EDIT: I activate it by this code:

(defun my-try-to-add-imenu ()
  (unless (my-is-buffer-file-temp)
    (condition-case nil (imenu-add-to-menubar "Imenu") (error nil))))

(defun my-is-buffer-file-temp ()
  "Returns t if buffer is temporary buffer. This is useful to disable hooks in org export."
  (interactive)
  (unless (boundp 'my-is-buffer-file-temp-var)
    (make-local-variable 'my-is-buffer-file-temp-var)
    (setq my-is-buffer-file-temp-var (my-is-buffer-file-temp-work)))
  my-is-buffer-file-temp-var)

(add-hook 'prog-mode-hook 'my-try-to-add-imenu)

This only activates imenu-mode if the current buffer has a corresponding file. I do this in order to avoid activation of some minor modes during org-export.

The are more options available, which may require some customization to get them to work and which depend on the programming envirnment. Just to mention some:

4
  • Useful answer. M-x imenu-add-menubar-index RET is exactly what I need — now, if only I could write a hook that is activated for all the programming modes...
    – gboffi
    Jun 1, 2017 at 9:41
  • Re your mention of ECB end CEDET, my modest needs are probably best met by imenu but it's however interesting to know, especially for different readers.
    – gboffi
    Jun 1, 2017 at 9:45
  • Added an example of how it could be started.
    – theldoria
    Jun 1, 2017 at 9:51
  • Over complicated... however the relevant info is there, the mode sufficiently generic and necessarily specific is prog-mode and (add-hook 'prog-mode-hook 'imenu-add-menubar-index) has done the trick. Tx a lot.
    – gboffi
    Jun 1, 2017 at 9:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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