Emacs中的C++程序智能提示是个不容易的活。我使用的是auto-completion插件。该插件依赖clang编译器进行代码分析,当然还依赖其他的emacs插件。下面是我的Emacs配置文件。
- ;;------------------------------------------------------------------------------
- ;; auto complete
- ;;------------------------------------------------------------------------------
- ;;(load-file (expand-file-name "/opt/emacs_plugins/c++/auto-complete-1.3.1")
- ;;(add-to-list 'load-path "/opt")
- ;;(require 'auto-complete-config)
- ;;(add-to-list 'ac-dictionary-directories "/opt/ac-dict")
- ;;(ac-config-default)
- (add-to-list 'load-path "/opt/emacs_plugins/c++/auto-complete-1.3.1")
- (require 'auto-complete-config)
- (add-to-list 'ac-dictionary-directories "/opt/ac-dict")
-
-
-
-
- ;;------------------------------------------------------------------------------
- ;; yasnippet
- ;;------------------------------------------------------------------------------
- ;;sudo apt-get install yasnippet
- (add-to-list 'load-path "/opt/emacs_plugins/c++")
- (add-to-list 'ac-dictionary-directories "/opt/emacs_plugins/c++")
- (require 'yasnippet-bundle)
-
-
-
-
- ;;------------------------------------------------------------------------------
- ;; clang for c++
- ;;------------------------------------------------------------------------------
- (load-file "/opt/emacs_plugins/c++/brianjcj-auto-complete-clang-9db79f4/auto-complete-clang.el")
- (require 'auto-complete-clang)
- (setq ac-auto-start nil)
- (setq ac-quick-help-delay 0.5)
- (define-key ac-mode-map [(control tab)] 'auto-complete)
- (defun my-ac-config ()
- (setq ac-clang-flags (split-string "-I/usr/local/gcc-4.6.1/include/c++/4.6.1 -I/usr/src/boost_1_47_0"))
- (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)
需要提示的时候,就按下Ctrl+Tab键。