Take the following sample code:

#include <cmath>

int main() {
    double a = -10;
    double b = std::abs(a);
    return 0;

When I place the cursor over abs, for example between b and s, I want to have a command which would make Emacs jump to where abs is defined in the cmath header. It's a ctags or gtags kind of functionality, but which allows to jump to definitions in header files that are outside of the project root directory. How can I do that?

  • You could generate a ctags/gtags tags database, system-wide, for your standard libraries (/usr/include and the like), and add that path to each of your project-based ctags/gtags configurations.
    – VanLaser
    Oct 25 '16 at 13:09

The following code demonstrates the direct use of semantic for jumping to tags.

Make sure you configured semantic-c-dependency-system-include-path right.

The following code displays the tag in another buffer. You can adapt the code to jump to the tag if you really want that. There should already exist something like that. But, I did not find it.

(defun semantic-display-tag (&optional pt)
  "Display tag at point."
  (interactive "d")
  (unless pt (setq pt (point)))
  (let (analyze tag buf loc start pt)
    (when (and (setq analyze (semantic-analyze-current-context pt))
           (setq tag (semantic-analyze-interesting-tag analyze))
           (setq buf (semantic-tag-buffer tag))
           (setq start (semantic-tag-start tag)))
      (with-selected-window (display-buffer buf #'display-buffer-pop-up-window)
    (goto-char start)

(global-set-key (kbd "C-c , d") #'semantic-display-tag)
(easy-menu-add-item cedet-menu-map '("Navigate Tags") ["Display Tag" semantic-display-tag (semantic-active-p)] 'semantic-complete-jump-local)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.