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 ()
(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."
(unless (boundp 'my-is-buffer-file-temp-var)
(setq my-is-buffer-file-temp-var (my-is-buffer-file-temp-work)))
(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
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: