用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
每打开一个文件都输入ggtags-mode,太麻烦了,所以在.emacs文件里加一个钩子,当打开c,c++,java的源文件时,自动启动ggtags-mode
(add-hook 'c-mode-common-hook
(lambda ()
(when (derived-mode-p 'c-mode 'c++-mode 'java-mode)
(ggtags-mode 1))))
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 navigation is to read code.
ggtags-visit-project-root
Open the project root directory in ``dired``.
ggtags-delete-tags
Delete the GTAGS, GRTAGS, GPATH and ID 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 the source tree. This allows
browsing the project in a browser with cross-references.
使用举例
1,从调用一个函数的地方跳转到函数的定义的地方
M-x ggtags-find-definition
对应的快捷键:M-.
2,从调用一个函数的地方跳转到函数的定义的地方后,返回到调用函数的地方
M-x ggtags-prev-mark
对应的快捷键:M-,
3,或是反过来从函数定义的地方列出所有调用这个函数的地方
M-x ggtags-find-reference
对应的快捷键:M-]
4,查看导航过的历史记录
M-x ggtags-view-tag-history
对应的快捷键:C-c M-h
用emacs 阅读 c/c++ 代码的更多相关文章
- [emacs] 使用ggtags浏览代码
[emacs] 使用ggtags浏览代码 // */ // ]]> [emacs] 使用ggtags浏览代码 Table of Contents 1 相关的连接 2 global简介 2.1 ...
- Emacs阅读chm文档
.title { text-align: center; margin-bottom: .2em } .subtitle { text-align: center; font-size: medium ...
- Kaldi阅读并更改代码
Common utilities base/kaldi-common.h 几乎所有Kaldi程序都会include该头文件. 该头文件include了一些其他位于base/目录的头文件,主要提供: 错 ...
- Week3 博客阅读感想和代码复审
一.关于博客阅读感想 阅读了十多篇老程序员(大多在计算机相关行业工作超过10年)关于自身经历的博客,很有感触.这里一方面总结一下看博客的收获,另一方面写点自己的感受. 首先,这些博客不少涉及到了两大类 ...
- 改变Emacs下的注释代码方式以支持当前行(未选中情况下)的注释/反注释
Emacs下支持多行代码的注释/反注释,命令是comment-or-uncomment-region. 我喜欢把它绑定在快捷键C-c C-/上,如下: (global-set-key [?\C-c ? ...
- 如何阅读luajit的代码——用vs调试篇
为什么要看luajit的源码 作为目前最快的脚本语言之一,luajit确实是一个杰作,但相比原生lua仅仅几万行的代码而言,luajit却可以说是巨无霸.更要命的是,luajit之所以快,是因为大量使 ...
- perl 里面如何写出阅读友好的代码提示
在我们使用别人写好的程序时,经常会使用-h 之类的东西查看一下简单的帮助手册或者说明信息: 对于perl 语言而言,写起来简单,经常随手一写,解决了当时的问题,但是过几天去看,你都不知道这个脚本该怎么 ...
- 阅读prettytable 一些代码、get、set 检查参数
阅读代码是因为我发现官方教程里的代码在本地不能用,所以就通过”查看定义“转到了源代码里. 通过阅读源代码,查看方法内是否有教程中所说的方法名和参数名,然后再通过”查看引用“来试图了解函数的流程,如果没 ...
- 利用Eclipse CDT 阅读C/C++代码
本文转自: https://xbgd.iteye.com/blog/1259544 常见阅读代码的工具有 , visual c++, visual studio + va(visual assista ...
随机推荐
- Spring Boot (五)Spring Data JPA 操作 MySQL 8
一.Spring Data JPA 介绍 JPA(Java Persistence API)Java持久化API,是 Java 持久化的标准规范,Hibernate是持久化规范的技术实现,而Sprin ...
- 【Vue.js】vue项目目录作用
1. build文件夹:打包配置的文件夹 1.1 webpack.base.conf.js :打包的核心配置 1.2 build.js:构建生产版本,项目开发完成之后,通过build.js打包(加 ...
- FFmpeg中overlay滤镜用法-水印及画中画
本文为作者原创,转载请注明出处:https://www.cnblogs.com/leisure_chn/p/10434209.html 1. overlay技术简介 overlay技术又称视频叠加技术 ...
- QApplication:No such file or directory 错误解决
首先打开 Makefile 文件,查看其中 INCPATH 变量的值是否包含程序中所涉及到的头文件路径. MAKEFILE = Makefile ####### Compiler, tools and ...
- 为Spring Cloud Config插上管理的翅膀
最近一致在更新Spring Cloud Config的相关内容,主要也是为这篇埋个伏笔,相信不少调研过Spring Cloud Config的用户都会吐槽它的管理能力太弱.因此,就有了下面为讲推荐的这 ...
- iOS-CoreData详解与使用
上面已经说完了SQLite和FMDB以及两者的区别,本篇将讲述iOS中另一个存储方式,CoreData的使用.通读下来大约10分钟,后续还会根据项目中问题,不断更新. 一.预备知识 在了解CoreDa ...
- RNN入门(三)利用LSTM生成旅游点评
介绍 前几天,某个公众号发文质疑马蜂窝网站,认为它搬运其它网站的旅游点评,对此,马蜂窝网站迅速地做出了回应.相信大多数关注时事的群众已经了解了整个事情的经过,在这里,我们且不论这件事的是是非非,也 ...
- 【转载】 C#工具类:Csv文件转换类
CSV是逗号分隔值格式的文件,其文件以纯文本形式存储表格数据(数字和文本).CSV文件由任意数目的记录组成,记录间以某种换行符分隔:每条记录由字段组成,字段间的分隔符是其它字符或字符串,最常见的是逗号 ...
- MEF 基础简介 二
MEF的导出(Export)和导入(Import) using System; using System.Collections.Generic; using System.Linq; using S ...
- 关于我空间那篇名为《JavaScript axError:Unexpected token ILLEGAL 很简单的代码……》的随笔
如图所示,我是空间的那片随笔,这里就不贴出链接了,也不希望你有这个兴趣,不知道会不会有人无意间闯入,额,自从日志用windows live writer 2009 发了那篇随笔后,我在网页上一直没能正 ...