Emacs: displaying list of subroutines/functions/classes in a source file

5

I have been using a little-known editor called "FTE" (or eFTE) for years; it has a nice utility that can display the list of the subroutines/functions/classes (or any such thing--depending on what regexp you define in its configuration file) in a source text file (C, C++, Fortran, ... what have you). This function allows me to jump quickly from one point to another in a source file. Perhaps the original shortcut in FTE is ^I (Control+I). Does emacs have a similar functionality? Emacs is much more advanced than FTE and I would be surprised if no one ever developed such a facility.

Thanks, Wirawan

Wirawan Purwanto

Posted 2013-08-07T14:04:43.393

Reputation: 201

1I haven't used emacs, but I think you might be looking for some sort of ctags integration. – user1686 – 2013-08-07T14:16:59.357

Answers

10

Try M-x occur RET exp RET - this lists in a new buffer all the occurrences of the exp in the current buffer.

Dror

Posted 2013-08-07T14:04:43.393

Reputation: 1 510

3@AaronMiller Welcome to the secret forest hiding very useful but little-known Emacs function fairies :-) Another (related) very useful function is re-builder, which lets you build up regular expressions interactively, incrementally, highlighting all matches in the buffer from which it was called. Enjoy :-) – ack – 2014-11-05T20:03:31.597

How have I been using Emacs for well over two years and not found out about that yet? If I could upvote your answer more than once, I would. – Aaron Miller – 2013-08-07T20:36:44.197

7

Most people of course will tell you to just use a modern IDE but they don't understand the power of emacs. Personally, I use ECB which makes my emacs look like this:

enter image description here

The middle window on the left hand side is the list of functions of the current source file. Middle clicking the name moves the cursor to that function's definition.

To install, follow the instructions on the ECB website to install ECB and then add this line to your ~/.emacs (changing the location accordingly):

(add-to-list 'load-path
             "~/.emacs-lisp/ecb/")

Another option is CEDET but I have not used it.

terdon

Posted 2013-08-07T14:04:43.393

Reputation: 45 216

I've seen ECB before, but always shied away because it seems awfully heavyweight. How have you found it? – Aaron Miller – 2013-08-07T14:41:39.990

@AaronMiller Honestly, I am in love with it. I finally got all my eclipse using friends to shut up. It is kinda heavyweight but I switch it on with a shortcut when necessary and that takes around a second, maybe two, no more (on my 3-year old laptop). I am very pleased with it though I seem to recall that installation was not painless. I would recommend you try it out and if its too heavy, don't use it. Mind you ecb is old (last version ~2009) so CEDET might be a better option. – terdon – 2013-08-07T15:15:06.953

Thanks! I'll try it and CEDET both (I gather 24.3 has CEDET 2 built in), not least because I find your point about Eclipse compelling. :) – Aaron Miller – 2013-08-07T16:06:03.053

2

Use Imenu:

  1. M-X imenu
  2. tab, All.Methods
  3. tab to see all methods

cweiske

Posted 2013-08-07T14:04:43.393

Reputation: 1 010

1

Emacs has a couple of ways to obtain this functionality.

The lighter-weight method is by means of tags, which with suitable customization can serve most purposes. Once you've built a tags file (which is done in a shell, via e.g. cd /path/to/project; ctags -e -R .) and selected it via M-x visit-tags-table RET /path/to/TAGS RET, you can, for example, use M-. on a function call to jump to the function definition, M-x tags-search to grep your way through the files described in the tags table, &c. See the linked page for a fairly thorough description of the tools available.

The heavier-weight method is by means of Semantic, a lexer/parser combination implemented entirely in Emacs Lisp. While I'm not as familiar with Semantic as with tags, the impression I get is that Semantic incurs a heavier initial setup burden, in exchange for a more generally useful result. In addition to the linked manual page, (the Emacs Wiki article)[http://www.emacswiki.org/emacs/SemanticBovinator] may be of additional help here.

Aaron Miller

Posted 2013-08-07T14:04:43.393

Reputation: 8 849

1

You said "display the list of the subroutines/functions/classes (or any such thing--depending on what regexp you define in its configuration file) in a source text file". Ignoring the part in parens for the moment, to which others have responded, it's not clear what you mean by a function etc. being "in" a source file.

If you are asking about seeing a list of the functions etc. that are defined in a given source file, and then navigating among their definitions, then look at Imenu in Emacs. See the Emacs manual, node Imenu. See also this EmacsWiki page about Imenu:

Drew

Posted 2013-08-07T14:04:43.393

Reputation: 1 898