Emacs 通过 CEDET 实现 Tag 跳转 (C/C++/Python)
2011-09-04 08:49
453 查看
1 Preface
前面曾经介绍过 GNU Global , 也提到了它没有直接支持 python 解析, 想要用它来生成 python 文件的 tags 的话,需要自己编写相应的插件。 此外, GNU Global 对 C++ 的支持程度和 C 相同, 如果两个类从包含了同名的成员函数, 在查找这个成员函数的定义时, global 不会准确的跳到相应的函数上, 还需要我们手动去选择相应的 tag 。CEDET 是 Emacs 中的一个强大的插件,它提供了基于语义的 Tag 跳转, 该功能对 C/C++, Python, Java 等的支持都非常准确, 并且通过 mru-bookmark-mode 中的 semantic-mrub-switch-tags 提供了在多个 Tag 中来回跳转的功能。 但是, 这个跳转需要用户去指定待跳回的 Tag, 且由于默认跳转到最近一次访问的 tag , 常常会弄的很乱。
2 Solution
新建一个栈,每次通过 semantic-ia-fast-jump 或者 semantic-ia-complete-jump 跳转的时候, 都将原 Tag 信息入栈,而每次想要跳回的时候,都从栈中 pop 出一个,并跳到刚刚 pop 出的 tag 中。代码如下:
(require 'cedet) ;; Enable code helpers. (semantic-load-enable-code-helpers) (global-semantic-mru-bookmark-mode 1) (defvar mru-tag-stack '() "Tag stack, when jumping to new tag, current tag will be stored here, and when jumping back, it will be removed.") (defun yc/store-mru-tag (pt) "Store tag info into mru-tag-stack" (interactive "d") (let* ((tag (semantic-mrub-find-nearby-tag pt))) (if tag (let ((sbm (semantic-bookmark (semantic-tag-name tag) :tag tag))) (semantic-mrub-update sbm pt 'mark) (add-to-list 'mru-tag-stack sbm) ) (error "No tag to go!"))) ) (defun yc/goto-func (pt) "Store current postion and call (semantic-ia-fast-jump)" (interactive "d") (yc/store-mru-tag pt) (semantic-ia-fast-jump pt) ) (defun yc/goto-func-any (pt) "Store current postion and call (semantic-ia-fast-jump)" (interactive "d") (yc/store-mru-tag pt) (semantic-complete-jump) ) (defun yc/symref (pt) (interactive "d") (yc/store-mru-tag pt) (semantic-symref)) (defun yc/return-func() "Return to previous tag." (interactive) (if (car mru-tag-stack) (semantic-mrub-switch-tags (pop mru-tag-stack)) (error "TagStack is empty!"))) (defun setup-program-keybindings() ;;;; Common program-keybindings (interactive) (local-set-key "\C-cR" 'yc/symref) (local-set-key "\C-cb" 'semantic-mrub-switch-tags) (local-set-key "\C-c\C-j" 'yc/goto-func-any) (local-set-key "\C-cj" 'yc/goto-func) (local-set-key [S-f12] 'yc/return-func) (local-set-key [M-S-f12] 'yc/return-func) (local-set-key (kbd "C-x SPC") 'yc/store-mru-tag) )
用法: 参考函数 setup-program-keybindings 。
相关文章推荐
- c/c++语言实现堆栈修改,通过ret跳转到自定义函数
- c/c++语言实现堆栈修改,通过ret跳转到自定义函数
- 【工作总结】通过SWIG实现 python 和 c++ 互相通信
- [cocos2dx]在cocos2dx中通过Jni实现Java与C++的互相调用(一)
- 纯C++版的Faster-Rcnn(通过caffe自定义RPN层实现)
- python通过pip更新所有已安装的包实现方法
- C++ 通过ADO.Net实现与MySql数据库连接 入门教程
- C++通过虚函数实现多态
- 使用scipy实现最小二乘法,以及通过曲线对数据进行拟合(Python)
- td中通过button绑定click事件实现跳转,以及获取同一table中另一td的值
- Cocos2d-x通过Jni实现Cocos2d-x界面跳转到新的Activity
- 通过JNI实现Java和C++的相互调用(转)
- python通过BF算法实现关键词匹配的方法
- 使用boost实现c++与python的相互调用
- C语言中的可变参数-printf的实现原理 在C/C++中,对函数参数的扫描是从后向前的。C/C++的函数参数是通过压入堆栈的方式来给函数传参数的(堆栈是一种先进后出的数据结构),最先压入的参数最后出
- 如何通过html标记或js代码实现跳转返回页面顶部
- cocos2d-x中通过Jni实现Java与C++的互相调用
- 使用Visual Studio,几步实现Python C++扩展,以及DLL调用
- 通过Tag接口实现自定义标签
- python之通过“反射”实现不同的url指向不同函数进行处理(反射应用一)