2008年12月23日星期二

Semantic配置C++自动补全

先上pp, 点击查看大图:

( 我输入了"v.pu" 自动补全为v.push_back, 按一下tab确认)

Semantic is part of cedet(Collection of Emacs Development Environment Tools)

下面内容主要参考这篇文章:

1. Check out the latest cedet src:

cvs -z3 -d:pserver:anonymous@cedet.cvs.sourceforge.net:/cvsroot/cedet co -P cedet

2. Build cedet:

cd cedet
touch `find -name "Makefile"`
make bootstrap

3. Install:
copy the cedet dir to your emacs site-lisp:
/usr/share/emacs/23.0.60/site-lisp/ (press 'ctrl-h v load-path' in emacs to see it)

4. 配置 (.emacs)

(require 'cedet)


  • 通过下面方式查看g++ include paths:
freestyler@effarr:~/program$ touch dummy.cpp
freestyler@effarr:~/program$ gcc -v -E -P dummy.cpp
使用内建 specs。
目标:i486-linux-gnu
配置为:../src/configure -v --enable-languages=c,c++,fortran,objc,obj-c++,treelang --prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --enable-nls --with-gxx-include-dir=/usr/include/c++/4.2 --program-suffix=-4.2 --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --enable-mpfr --enable-targets=all --enable-checking=release --build=i486-linux-gnu --host=i486-linux-gnu --target=i486-linux-gnu
线程模型:posix
gcc 版本 4.2.3 (Ubuntu 4.2.3-2ubuntu7)
/usr/lib/gcc/i486-linux-gnu/4.2.3/cc1plus -E -quiet -v -P -D_GNU_SOURCE dummy.cpp -mtune=generic
忽略不存在的目录“/usr/local/include/i486-linux-gnu”
忽略不存在的目录“/usr/lib/gcc/i486-linux-gnu/4.2.4/../../../../i486-linux-gnu/include”
忽略不存在的目录“/usr/include/i486-linux-gnu”
头文件查找路径(用“:”分隔):
头文件查找路径(用“:”分隔):
/usr/include/c++/4.2
/usr/include/c++/4.2/i486-linux-gnu
/usr/include/c++/4.2/backward
/usr/local/include
/usr/lib/gcc/i486-linux-gnu/4.2.4/include
/usr/include
搜尋結果清單


  • Add the following to your c++-mode-hook:

;;;;semantic
;;;;以下3个按机器适用的强劲程度排列,最下面的对机器需求最低。三选一。
;; (semantic-load-enable-gaudy-code-helpers)
;; (semantic-load-enable-code-helpers)

(semantic-load-enable-minimum-features)
(eval-after-load "semantic-c"
;;下面的路径是通过上面的方式查看到的
'(dolist (d (list
"/usr/include/c++/4.2"
"/usr/include/c++/4.2/i486-linux-gnu"
"/usr/include/c++/4.2/backward"
"/usr/local/include"
"/usr/lib/gcc/i486-linux-gnu/4.2.4/include"
"/usr/include"))
(semantic-add-system-include d)))

(eval-after-load "semantic-complete"
'(setq semantic-complete-inline-analyzer-displayor-class
semantic-displayor-ghost)) ;;; 这是补全弹出方式.

;;;建立这个目录先
(setq semanticdb-default-save-directory
(expand-file-name "~/.emacs.d/semanticdb"))

(local-set-key (kbd "M-/") 'semantic-complete-analyze-inline)
(local-set-key "." 'semantic-complete-self-insert)
(local-set-key ">" 'semantic-complete-self-insert)


附录: g++ option:
-v Print (on standard error output) the commands executed to run the stages of compilation. Also print the version number of the compiler driver program and of the preprocessor and the compiler proper.

-E Stop after the preprocessing stage; do not run the compiler proper. The output is in the form of preprocessed source code, which is sent to the standard output.

-P Inhibit generation of linemarkers in the output from the preprocessor. This might be useful when running the preprocessor on something that is not C code, and will be sent to a program which might be confused by the linemarkers.

1 条评论:

匿名 说...

非常感谢,照着做了一遍果然管用