Ubuntu 14.10系统,通过emacs package system安装了模块auto-complete-clang
然后进入.emacs.d/init.el中如下配置:
;; auto complete (require 'auto-complete) (add-to-list 'ac-dictionary-directories "~/.emacs.d/elpa/auto-complete-20150408.1132/ac-dict/") (add-to-list 'ac-user-dictionary-files "~/.emacs.d/elpa/auto-complete-20150408.1132/ac-dict//dean.dict") (require 'auto-complete-config) ;; end ;; 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.9 /usr/include/c++/4.9/backward /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) ;; end
现在打开代码,在vector对象v后面输入v.pu
然后用M-/ 后等待,会自动显示push_back。
有时候不显示的原因是之前没有键入代码,不过没有关系,会逐渐学习。
现在还有个问题, auto-complete-clang貌似没有真正工作,因为提示过于简陋。还需要继续研究。