The following requirements are available in Emacs programming
- Jump from where a function is called to the definition of a function
- Or, in turn, list all the places where the function was called from the function definition.
Implementation approach
Need to install the following software
- GNU Global (Tools for reading source code) official website
- Emacs's Gtags Plugin
- After starting Emacs, enter the following command to start the Gtags function
M-x ggtags-mode
GNU Global Installation
apt-get install global
Emacs Gtags Plug-in installation
M-x list-packages
After finding the Ggtags, click on the mouse, then point to install
How to use
1, execute in the root directory where the code is stored:
$ gtags
After execution, you will find that 3 files have been generated, Gpath grtags gtags
2, activate Emacs
3, after starting Emacs, enter the following command to start the Gtags function
M-x ggtags-mode
4, use the following function can be implemented, to see the various requirements of the code.
Ggtags-find-tag-dwim find a tag by context. If Point was at a definition tag,FindReferences andVice versa. If Point was at a line that matches ' Ggtags-include-pattern ',Find theInclude file instead. To force finding a definition tag, call it with a prefix ("C-u"). Ggtags-find-tag-mouse like ' ggtags-find-tag-dwim ' B UT suitable for binding to mouse events.ggtags-find-definition find definition tags. With "C-u" ask for theTag name with completion.ggtags-find-reference Find reference tags. With "C-u" ask for theTag name with Completion.ggtags-find-other-symbol find tags that has no definitions. With "C-u" ask for theTag name with completion.ggtags-find-tag-regexp find definition tags matching a regexp. By default it lists all matching tags in theProject. With ' c-u ' restrict theLists to aDirectoryof choice.ggtags-idutils-query use Idutils toFindMatches.ggtags-grep grep for lines matching a regexp. This is usually theSlowest.ggtags-find-file find a file from all theFiles indexed by "Gtags". Ggtags-query-replace do a queryReplaceIn all files found in aSearch. Handling multiple Matches+++++++++++++++++++++++++when ASearchFinds multiple matches, a buffer named ' *ggtags-global* ' is popped up and' Ggtags-navigation-mode ' isturned on to facilitate locating theRight match. "Ggtags-navigation-mode" makes a few commands in the' *ggtags-global* ' buffer globally accessible: ' M-n ' Move to theNext match. ' M-p ' Move to thePrevious match. "M-}" move to next file. "m-{" move to previous file. "m-=" move to theFile where navigation session starts. ' m-< ' Move to the FirstMatch. ' M-> ' Move to the LastMatch. ' C-m-s 'or"M-s S" use "ISearch" toFind theMatch. ' RET ' Found theRight match so exit navigation mode. Resumable by ' M-, ' (' tags-loop-continue '). ' m-* ' Abort and GoBack to theLocation where the Searchwas started. Miscellaneous Commands++++++++++++++++++++++commands is available from the"Ggtags" menu in "Ggtags-mode". Ggtags-prev-mark Move to thePreviously (older) visited location. Unlike ' m-* ' this doesn ' tDelete theLocation from theTag Ring.ggtags-next-mark Move to theNext (newer) visited Location.ggtags-view-tag-history Pop to a buffer listing all visited locations from newest to old Est. The buffer is a nextErrorBuffer andWorks with StandardCommands ' Next-error ' and"' Previous-error '." In addition ' TAB ' and' S-tab ' move to Next/prev entry, and' RET ' visits theLocation. "' M-n ' and' M-p ' move to andDisplay theNext/previous entry.ggtags-view-search-history VieworRe-run past searches as kept in "ggtags-global-search-history". Ggtags-kill-file-buffers Kill all File-visiting Buffe RS of current project.ggtags-toggle-project-read-only toggle opening files in ' read-only ' mode. Handyif theMain purpose of source navigation is toReadCode.ggtags-visit-project-root Open theProject RootDirectoryIn ' dired '. Ggtags-delete-tags Delete theGtags, Grtags, Gpath andID Files of current project.ggtags-explain-tags explain how each file is indexed in current Project.ggtags-browse-file-as -hypertext use "htags" to generate HTML of theSource tree. This allows browsing theProject in a browser with cross-references.
Examples of Use
1, jump from where a function is called to where the function is defined
M-x ggtags-find-definition
2, returning to the place where the function was called after jumping from where a function was called to the definition of the function
M-x ggtags-prev-mark
3, or, in turn, lists all the places where the function is called from the function definition.
M-x ggtags-find-reference
4. View the history of navigation
M-x ggtags-view-tag-history
Read the C + + code with Emacs