emacs 使用 auto-complete clang 实现 c++ 代码补全

自从将 <CTRL> 与 <CAPS> 按键调换后,控 emacs 的心又回来了。再也不用 vim 小打小闹了。

 

auto-complete本身就是一款在 emacs 下非常强大的代码补全插件,可是受不了 cedet 的补全速度,只能干着急。众里寻她千百度,重要找到了一款在 emacs 下相当不错的代码补全插件,auto-compete-clang,速度快,配置简单,提示优美~

如下图


emacs 使用 auto-complete clang 实现 c++ 代码补全_第1张图片
 很漂亮吧~

 

贴一份 .emacs 文件吧

 

;; 开启 auto-complete
(add-to-list 'load-path "~/.emacs.d/el-get/auto-complete/")
(require 'auto-complete)
(add-to-list 'ac-dictionary-directories "~/.emacs.d/el-get/auto-complete/ac-dict/")
(add-to-list 'ac-user-dictionary-files "~/.emacs.d/el-get/auto-complete/dict/guotf.dict")
(require 'auto-complete-config)
;; 结束

;; 开启 auto-complete-clang
(add-to-list 'load-path "~/.emacs.d/el-get/auto-complete-clang/")
(require 'auto-complete-clang)  
;;(setq ac-clang-auto-save t)  
;; 设置不自动启动
(setq ac-auto-start nil)  
;; 设置响应时间 0.5
(setq ac-quick-help-delay 0.5)  
;;(ac-set-trigger-key "TAB")  
;;(define-key ac-mode-map  [(control tab)] 'auto-complete)  
;; 提示快捷键为 M-/
(define-key ac-mode-map  (kbd "M-/") 'auto-complete) 
(defun my-ac-config ()  
  (setq ac-clang-flags  
        (mapcar(lambda (item)(concat "-I" item))  
               (split-string  
                "
 /usr/include/c++/4.6
 /usr/include/c++/4.6/i686-linux-gnu/.
 /usr/include/c++/4.6/backward
 /usr/lib/gcc/i686-linux-gnu/4.6/include
 /usr/local/include
 /usr/lib/gcc/i686-linux-gnu/4.6/include-fixed
 /usr/include/i386-linux-gnu
 /usr/include
"
)))  
  (setq-default ac-sources '(ac-source-abbrev ac-source-dictionary ac-source-words-in-same-mode-buffers))  
  (add-hook 'emacs-lisp-mode-hook 'ac-emacs-lisp-mode-setup)  
  (add-hook 'c-mode-common-hook 'ac-cc-mode-setup)  
  (add-hook 'ruby-mode-hook 'ac-ruby-mode-setup)  
  (add-hook 'css-mode-hook 'ac-css-mode-setup)  
  (add-hook 'auto-complete-mode-hook 'ac-common-setup)  
  (global-auto-complete-mode t))  
(defun my-ac-cc-mode-setup ()  
  (setq ac-sources (append '(ac-source-clang ac-source-yasnippet) ac-sources)))  
(add-hook 'c-mode-common-hook 'my-ac-cc-mode-setup)  
;; ac-source-gtags  
(my-ac-config)  
(ac-config-default)
;; 结束

 

详细的配置方式还是自己摸索比较好!可以参考一下两篇

这里 、还有这里

 

你可能感兴趣的:(emacs,auto-complete,Clang)