2011-09-04 59 views
3

我試圖在我的Linux內核開發項目中使用Emacs作爲IDE。所以我安裝了CEDET和GNU Global(gtags),沒有任何問題。C預處理器定義不被Cedet/Semantic考慮

當我打開屬於我的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)所需的所有include和定義來構建內核項目。

我還試圖強制語義使用GCC交叉編譯器命令行來代替系統GCC正確預處理,但還沒有找到如何做到這一點。

「M-x語義-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) 

回答

0
  1. 你應該從主線得到CEDET:
    bzr://cedet.bzr.sourceforge.net/bzrroot/cedet/code/trunk/
    有幾個修復預處理最近處理。

  2. 在更改了semantic-lex-c-preprocessor-symbol-file和類似 的東西之後,您應該刪除語義緩存並允許它從頭開始重新創建它。

+0

謝謝。我會盡力 :) –