设为首页 加入收藏

TOP

用emacs 阅读 c/c++ 代码(一)
2018-10-21 14:13:48 】 浏览:74
Tags:emacs 阅读 c/c 代码

在emacs编程中有以下需求

  • 从调用一个函数的地方跳转到函数的定义的地方
  • 或是反过来从函数定义的地方列出所有调用这个函数的地方

实现办法

需要安装以下软件

  • gnu global(阅读源代码的工具)官网
  • emacs的gtags插件
  • 启动emacs后,输入下面的命令,来启动gtags的功能
M-x ggtags-mode
gnu global安装
apt-get install global

emacs的gtags插件安装

M-x list-packages

找到ggtags后,鼠标点击,再点安装

使用方法

1,在存放代码的根目录执行:

$ gtags

执行后,会发现在生成了3个文件, GPATH GRTAGS GTAGS

2,启动emacs

3,启动emacs后,输入下面的命令,来启动gtags的功能

M-x ggtags-mode

4,使用下面的函数就可以实现,查看代码的各种需求了。

ggtags-find-tag-dwim

   Find a tag by context.

   If point is at a definition tag, find references, and vice versa.
   If point is at a line that matches ``ggtags-include-pattern``, find
   the include file instead.

   To force finding a definition tag, call it with a prefix (``C-u``).

ggtags-find-tag-mouse

   Like ``ggtags-find-tag-dwim`` but suitable for binding to mouse
   events.

ggtags-find-definition

   Find definition tags. With ``C-u`` ask for the tag name with
   completion.

ggtags-find-reference

   Find reference tags. With ``C-u`` ask for the tag name with completion.

ggtags-find-other-symbol

   Find tags that have no definitions. With ``C-u`` ask for the tag
   name with completion.

ggtags-find-tag-regexp

   Find definition tags matching a regexp. By default it lists all
   matching tags in the project. With ``C-u`` restrict the lists to a
   directory of choice.

ggtags-idutils-query

   Use idutils to find matches.

ggtags-grep

   Grep for lines matching a regexp. This is usually the slowest.

ggtags-find-file

   Find a file from all the files indexed by ``gtags``.

ggtags-query-replace

   Do a query replace in all files found in a search.

Handling multiple matches
+++++++++++++++++++++++++

When a search finds multiple matches, a buffer named
``*ggtags-global*`` is popped up and ``ggtags-navigation-mode`` is
turned on to facilitate locating the right match.
``ggtags-navigation-mode`` makes a few commands in the
``*ggtags-global*`` buffer globally accessible:

``M-n``

   Move to the next match.

``M-p``

   Move to the previous match.

``M-}``

   Move to next file.

``M-{``

   Move to previous file.

``M-=``

   Move to the file where navigation session starts.

``M-<``

   Move to the first match.

``M->``

   Move to the last match.

``C-M-s`` or ``M-s s``

   Use ``isearch`` to find the match.

``RET``

   Found the right match so exit navigation mode. Resumable by ``M-,``
   (``tags-loop-continue``).

``M-*``

   Abort and go back to the location where the search was started.

Miscellaneous commands
++++++++++++++++++++++

Commands are available from the ``Ggtags`` menu in ``ggtags-mode``.

ggtags-prev-mark

   Move to the previously (older) visited location. Unlike ``M-*``
   this doesn't delete the location from the tag ring.

ggtags-next-mark

   Move to the next (newer) visited location.

ggtags-view-tag-history

   Pop to a buffer listing all visited locations from newest to
   oldest. The buffer is a next error buffer and works with standard
   commands ``next-error`` and ``previous-error``. In addition ``TAB``
   and ``S-TAB`` move to next/prev entry, and ``RET`` visits the
   location. ``M-n`` and ``M-p`` move to and display the next/previous
   entry.

ggtags-view-search-history

   View or re-run past searches as kept in
   ``ggtags-global-search-history``.

ggtags-kill-file-buffers

   Kill all file-visiting buffers of current project.

ggtags-toggle-project-read-only

   Toggle opening files in ``read-only`` mode. Handy if the main
   purpose of source nav
首页 上一页 1 2 下一页 尾页 1/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇c/c++ 线性表之顺序表 下一篇[日常] C语言中指针变量

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目