What is the short-cut key to jump to declaration in Emacs?

前端 未结 4 1200
误落风尘
误落风尘 2021-01-31 03:18

In visual studio it \'s easier to push F12 button to jump to a declaration of a function or variable when editing C/C++ code.

Is there a short-cut key in emacs to do th

相关标签:
4条回答
  • 2021-01-31 04:12

    There are multiple ways to do this. As darioo mentioned, Ctags is one, but it goes to the definition by default (which might work for you). Looking further, though, you can see that prefixing M-.(ie, C-u M-.) will take you to the next tag match (which is often the declaration). There is also a --declarations option, but Exuberant Ctags doesn't seem to support it.

    CEDET is another option, but in my experience, it's still not ready for production. Often times in C++ semantic-ia-fast-jump will go to forward declarations instead of the definition or the declaration.

    0 讨论(0)
  • 2021-01-31 04:19

    As others have said there is no built-in universal solution for this in emacs. That said, after having this functionality in IntelliJ I wanted it in emacs too so I made Dumb Jump.

    Right now Dumb Jump has basic support for:

    • JavaScript
    • Emacs Lisp
    • Python
    • Go
    • PHP
    • Ruby
    • Faust
    • and more... (over 20 now)

    It's available via MELPA and is actively being developed.

    0 讨论(0)
  • 2021-01-31 04:20

    Well, it's a bit more involved than that.

    By default, Emacs doesn't "know" about function declarations for C or C++ code. First, obtain Exuberant Ctags. Then, use command etags (ctags for Emacs) on your source code. A file named TAGS will be generated.

    Then, while editing your source code, when you want to jump to a declaration, press M-. (meta and dot, or alt and dot on modern keyboards). At first, Emacs will ask you for location of your tags file. Point it to the one you generated and afterwards navigation will be automatic.

    I'd suggest reading Emacswiki article about tags for a better understanding of this functionality.

    The newest version of Emacs (23.2) comes with CEDET integrated, which has more advanced features for C and C++ navigation, but it can be a bit difficult to set up right, so read more about it if you're interested.

    0 讨论(0)
  • 2021-01-31 04:23

    M-. key will take you to the function definition emacs.

    0 讨论(0)
提交回复
热议问题