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...

Drew
  • 75,699
  • 9
  • 109
  • 225
gboffi
  • 594
  • 2
  • 19

1 Answers1

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:

theldoria
  • 1,825
  • 1
  • 13
  • 25
  • 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 01 '17 at 09: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 01 '17 at 09:45
  • Added an example of how it could be started. – theldoria Jun 01 '17 at 09: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 01 '17 at 09:54