1

Is there a built-in option or a package that can help me navigate the C-source code to jump to functions, variables and other items with underscores in the name?

Example # 1:  I would like to place my cursor on optional_new_start in window.c -- hit an M-x find-... -- and be automatically transported to window.h at the location that tells me:

/* True means we have explicitly changed the value of start,
   but that the next redisplay is not obliged to use the new value.
   This is used in Fdelete_other_windows to force a call to
   Vwindow_scroll_functions; also by Frecenter with argument.  */
bool_bf optional_new_start : 1;

Example # 2:  I would like to place my cursor on redisplay_window -- hit an M-x find-... -- and be automatically transported to xdisp.c -- where I can read about:

static void
redisplay_window (Lisp_Object window, bool just_this_one_p)
{
  struct window *w = XWINDOW (window);
  struct frame *f = XFRAME (w->frame);
***
1
  • I don't work in C, but I came across this recently: tuhdo.github.io/c-ide.html Check out the section on source code navigation.
    – elethan
    Commented Jan 22, 2016 at 16:04

2 Answers 2

4

Emacs can do this "out of the box". See Tags in the manual. (Press C-h r m tags RET to read this section in Emacs.)

Here's what I did to make sure it works.

  1. Got Emacs sources from https://github.com/emacs-mirror/emacs
  2. Ran find . -iname "*.c" -or -iname "*.h" | xargs etags to create a TAGS table.
  3. Added this TAGS table using M-x visit-tags-table.

Now I can put my cursor on optional_new_start in window.c, press M-. RET and end up on the appropriate line in window.h.

You can then press M-* to go back to the point you started from.

PS: It does not matter if variable and function names have underscores in them.

0
1

You can also use ggtags, a frontend GNU Global.
It works pretty well and it is similar to the standard etags package.

From the Usage instructions:

Open any file in a project and type M-x ggtags-mode. Use M-. (ggtags-find-tag-dwim) to find the tag at point. If the project has not been indexed (i.e. no GTAGS file exists), ggtags will ask for the project root directory and index it recursively.

So, open window.c, then type M-x ggtags-mode.
Place the cursor on optional_new_start and hit M-..
The first time you will get a prompt (ggtags-create-tags) to create the GTAGS file needed.
(In fact, it will create four files: GPATH, GTAGS, GRTAGS, GSYMS.)

Hit RET and you will get a prompt like: Use 'ctags' backend? (yes or no).
Type yes and you are done.

You can jump to definitions, find references, etc...

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.