Linux カーネル開発プロジェクトで Emacs を IDE として使用しようとしています。そこで、問題なく CEDET と GNU Global (gtags) をインストールしました。
Linux カーネル ソース フォルダーに属する C ソース コードを開くと、Linux プロジェクトが自動的に検出されます。関数、変数、ヘッダー、およびその他のキーワードが正しく強調表示されます。
~/.emacs ファイルを通じて、セマンティックのコード補完とインテリセンスを構成しました。C を押すと、コード補完メニューが表示され、必要なものを選択できます。
問題は、プリプロセッサ定義を使用する場合です。インテリセンス システムは現在の場所にメニューを表示しますが、呼び出されたときに正しいものを検出しません (C-)。emacsを閉じて再起動しても、同じ動作が再現されます。
テストコードは次のとおりです。
//------------------------------------------------ --------------------------------------------
typedef struct
{
int p1;
#ifdef __KERNEL__
int p2;
#endif
#ifdef USE1
char p3;
#endif
#ifdef __LINUX_ARM_ARCH__
int p4;
#endif
}OBJ;
OBJ g_obj;
//------------------------------------------------ --------------------------------------------
KERNEL、 USE1 、およびLINUX_ARM_ARCHは、次のように既に定義されています。
__KERNEL__ : (add-to-list 'semantic-lex-c-preprocessor-symbol-map '("__KERNEL__" . "")) in .emacs
USE1 : defined in a header file included by the current C source file.
__LINUX_ARM_ARCH__ : (add-to-list 'semantic-lex-c-preprocessor-symbol-file "/home/abdellatif/kernel/include/generated/autoconf.h") in .emacs
.emacs ファイルには、カーネル プロジェクトをビルドするために GCC クロス コンパイラ (GCC for ARM) で必要なすべてのインクルードと定義も追加しました。
また、システム GCC の代わりに GCC クロス コンパイラ コマンド ラインを使用して正しく前処理するようにセマンティックに強制しようとしましたが、その方法が見つかりませんでした。
「Mx Semantic-c-describe-environment」コマンドは、正しいインクルード パスと定義 (.emacs で設定) を表示します。ただし、システム GCC 定義もリストされています。
.emacs ファイルとソフトウェア バージョンを以下に示します。
どんな助けや指示も歓迎します:)
############# Software versions #############
- Emacs (23.2.1)
- Ubuntu machine (natty, 11.04)
- Cedet 1.0 (from http://cedet.sourceforge.net/)
############# .emacs #############
;load CEDET
(load-file "~/Documents/my_emacs/cedet-1.0/common/cedet.el")
(require 'ede)
(global-ede-mode t)
; turn on which-func support (plus all other code helpers)
(semantic-load-enable-gaudy-code-helpers)
(semantic-load-enable-excessive-code-helpers)
; turn on all "useful" features
(setq semantic-load-turn-useful-things-on t)
(setq-mode-local c-mode
semanticdb-find-default-throttle
'(project unloaded system recursive))
;init names completion, and displaying of information for tags & classes
(require 'semantic-ia)
;preprocessing of source code
(require 'semantic-c)
(semantic-reset-system-include 'c-mode)
(semantic-reset-system-include 'c++-mode)
(semantic-add-system-include "/home/abdellatif/toolchain/arm-eabi-4.4.3/lib/gcc/arm-eabi/4.4.3/include" 'c-mode)
(semantic-add-system-include "/home/abdellatif/kernel/arch/arm/include" 'c-mode)
(semantic-add-system-include "/home/abdellatif/kernel/include" 'c-mode)
(semantic-add-system-include "/home/abdellatif/kernel/arch/arm/mach-omap2/include" 'c-mode)
(semantic-add-system-include "/home/abdellatif/kernel/arch/arm/plat-omap/include" 'c-mode)
(add-to-list 'semantic-lex-c-preprocessor-symbol-file "/home/abdellatif/kernel/include/generated/autoconf.h")
(add-to-list 'semantic-lex-c-preprocessor-symbol-map '("__KERNEL__" . ""))
(add-to-list 'semantic-lex-c-preprocessor-symbol-map '("__LINUX_ARM_ARCH__" . "7"))
(add-to-list 'semantic-lex-c-preprocessor-symbol-map '("KBUILD_STR(s)" . "#s"))
(add-to-list 'semantic-lex-c-preprocessor-symbol-map '("KBUILD_BASENAME" . "KBUILD_STR(main)"))
(add-to-list 'semantic-lex-c-preprocessor-symbol-map '("KBUILD_MODNAME" . "KBUILD_STR(main)"))
;semantic integration with imenu (display of a menu with a list of functions, variables, and other tags)
(defun my-semantic-hook ()
(imenu-add-to-menubar "TAGS"))
(add-hook 'semantic-init-hooks 'my-semantic-hook)
;names completion (semantic commands)
(defun my-cedet-hook ()
(local-set-key [(control return)] 'semantic-ia-complete-symbol)
(local-set-key "\C-x " 'semantic-ia-complete-symbol-menu)
(local-set-key "\C-x\r" 'gtags-find-tag-from-here))
(add-hook 'c-mode-common-hook 'my-cedet-hook)
;navigating in source code
(semantic-mru-bookmark-mode 1)
;tell semantic to store its tags database between sessions here
(require 'semanticdb)
(setq-default semanticdb-default-save-directory "~/.semantic.cache")
(setq-default semanticdb-default-system-save-directory "~/.semantic.cache")
;allow Semanticdb use databases generated by global(gtags)
(require 'semanticdb-global)
(semanticdb-enable-gnu-global-databases 'c-mode)