emacs+auto-complete+etags代码自动补全

来源:互联网 发布:梦里花落知多少豆瓣 编辑:程序博客网 时间:2024/06/04 19:37
    自己用emacs编辑代码想自动补全,也尝试过很多自动补全插件,前端用auto-complete而后端用semantic、 clang、gcclsense等,但是感它们都一个共同的问题,太慢(有人说,需要补全的时候再打开,个人认为这种方式不太方便),这段时间发现auto-complete+etags补全代码,虽然有时候不是那么精确,但是总体上还是比较理想的,对我来说已经够用了,我也不是一个理想主义者,这个主要是针对C/C++代码补全,好了, 废话不多说了,下面说说我的配置步骤吧!
    默认你是装上auto-complete插件了, 现在好像是1.3,自己去网上下一个。
    主要说一说今天的主角etags吧
    下载etags代码补全插件
    git https://github.com/whitypig/auto-complete-etags.git
    将auto-complete- etags.el拷贝到自己的emacs插件加载目录,我自己的是~/.emacs.d/mylisps。然后在你的.emacs添加:
(defun my-c-mode-common-hook-func () (interactive) "Function to be called when entering into c-mode." (when (and (require 'auto-complete nil t) (require 'auto-complete-config nil t)) (make-local-variable 'ac-sources) (setq ac-sources '(ac-source-words-in-same-mode-buffers ac-source-dictionary)) (when (require 'auto-complete-etags nil t) (add-to-list 'ac-sources 'ac-source-etags) (setq ac-etags-use-document t))))(add-hook 'c-mode-common-hook 'my-c-mode-common-hook-func)
当然你要有tags文件了 M-x eshell find . -name "*.[chCH]" -print | etags -
你可以它定义别名在~/.eshell/alias添加:
alias TAG find . -name "*.[chCH]" -print | etags -
好了,基本上大功告成了,剩下就是加载tags文件了,使用M-x visit-tags-table你也可以结合代码段不全插件yasnippet
原创粉丝点击