7

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

1
  • 1
    I haven't used emacs, but I think you might be looking for some sort of ctags integration. Aug 7, 2013 at 14:16

5 Answers 5

12

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

2
  • 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. Aug 7, 2013 at 20:36
  • 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
    Nov 5, 2014 at 20:03
9

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.

3
  • I've seen ECB before, but always shied away because it seems awfully heavyweight. How have you found it? Aug 7, 2013 at 14:41
  • @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
    Aug 7, 2013 at 15:15
  • 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. :) Aug 7, 2013 at 16:06
7

Use Imenu:

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

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:

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .