2013-08-14 12 views
6

私はemacs c/C++開発環境でcedetとsemanticを実験していましたが、1つの細部を除いてそれにはかなり満足しています。私はプロジェクトを作成し、ファイルをインクルードディレクトリと一緒に私のプロジェクトのルートディレクトリを与えるためにede-cpp-root-projectを使用セマンティック、cedetソースファイルの構文解析を強制する方法

は、以下のような存在:

(ede-cpp-root-project "My Project" 
       :name "My Project" 
       :file "/path/to/rootdir/AFILE" 
       :include-path '( 
       "/include2" 
       "/include1" 
           ) 

       ) 

これは私が簡単にsemantic-ia-fast-jumpと関数の宣言にジャンプすることができますしかし、私はそれらの関数の定義に惑わされません。だから、ヘッダファイルを扱うだけで、ソースファイルは完全に無視されるようです。関数の宣言に続き、semantic-analyze-proto-impl-toggleをトリガしても、適切な実装が見つからないことがわかります。

関数の実装があるソースファイルを手動で開くと、それだけが意味論によって解析され、上記のすべての関数が機能します。

は、だから私の質問は短いの手動でディレクトリの下にすべてのソースファイルの解析を強制する他の方法がある:spp-files引数を経由してede-cpp-root-projectでそれらを含め、手動で私のプロジェクトのルートディレクトリの下に含まれるすべてのソースファイルを開いたり、ありますか?

ありがとうございます!

答えて

7

この問題を長年無視してから、私はelispで読んで、回避策を見つけようとしました。それは私がemacsのニーズのためだけにelispを使用するので、そこにある最もきれいなelispコードではありませんが、私は必要なものを行います。

(defvar c-files-regex ".*\\.\\(c\\|cpp\\|h\\|hpp\\)" 
    "A regular expression to match any c/c++ related files under a directory") 

(defun my-semantic-parse-dir (root regex) 
    " 
    This function is an attempt of mine to force semantic to 
    parse all source files under a root directory. Arguments: 
    -- root: The full path to the root directory 
    -- regex: A regular expression against which to match all files in the directory 
    " 
    (let (
     ;;make sure that root has a trailing slash and is a dir 
     (root (file-name-as-directory root)) 
     (files (directory-files root t)) 
     ) 
    ;; remove current dir and parent dir from list 
    (setq files (delete (format "%s." root) files)) 
    (setq files (delete (format "%s.." root) files)) 
    (while files 
     (setq file (pop files)) 
     (if (not(file-accessible-directory-p file)) 
      ;;if it's a file that matches the regex we seek 
      (progn (when (string-match-p regex file) 
       (save-excursion 
       (semanticdb-file-table-object file)) 
      )) 
      ;;else if it's a directory 
      (my-semantic-parse-dir file regex) 
    ) 
    ) 
) 
) 

(defun my-semantic-parse-current-dir (regex) 
    " 
    Parses all files under the current directory matching regex 
    " 
    (my-semantic-parse-dir (file-name-directory(buffer-file-name)) regex) 
) 

(defun lk-parse-curdir-c() 
    " 
    Parses all the c/c++ related files under the current directory 
    and inputs their data into semantic 
    " 
    (interactive) 
    (my-semantic-parse-current-dir c-files-regex) 
) 

(defun lk-parse-dir-c (dir) 
    "Prompts the user for a directory and parses all c/c++ related files 
    under the directory 
    " 
    (interactive (list (read-directory-name "Provide the directory to search in:"))) 
    (my-semantic-parse-dir (expand-file-name dir) c-files-regex) 
) 

(provide 'lk-file-search) 

のいずれかを使用しそうのような関数を直接呼び出すには:(my-semantic-parse-dir "path/to/dir/root/" ".*regex")やプレスM-x lk-parse-curdir-cをバッファから再帰的にそのbuferrの訪問ファイル名のディレクトリからすべてのC/C++関連のファイルをスキャンします。

関数を呼び出す代わりに、おそらく好きな方法は、lk-parse-dir-cを対話的に呼び出すことです。これによって、解析するディレクトリを求めるプロンプトが表示されます。

コードを改善するための優れた解決策や提案があれば、私はそれを聞いてみたいと思います。

+0

bovinate'が私の状況にどのように役立つか '表示されていないと、このソリューションは良いようだが、Emacsはしませんタグデータベースをセッション間で保存します。何か不足していますか? – jarvisteve

+0

ねえ、それは変です。それらは.emacsディレクトリ内の.semanticdbというディレクトリに保存する必要があります – Lefteris

+1

私のファイルリストが非常に長くて、emacsが停止して一見、それ以上の進歩を見せないという問題がありました。私は次のディレクトリに移動する前に(semanticdb-save-all-db)の呼び出しを追加して解決します。このようにして、キャッシュは継続的に更新されます。多分それが助けになるでしょう。通常、セマンティックはemacsを終了するときだけ保存します。 – RealityMonster

0

"bovinate"コマンドを実行してみてください。これはMeta + Xのキーコンビネーションで行い、 "bovinate"と打ち込み、 "Enter"キーを押してください。 「メタ」キーは、ウィンドウ内の「Alt」キーと呼ばれます。

+0

ちょっと返事をドロップするように時間を割いてくれてありがとう私は – Lefteris

1

私はこれを最近Pythonに実装しました。 C/C++ではマイナーチェンジを採用することができます。私はあまりにもあなたのブログを偶然見つけねえ

(defvar python-extention-list (list "py")) 

(defun semanticdb-rescan-directory (pathname) 
    (dolist (file (cddr (directory-files pathname t))) 
    (if (file-directory-p file) 
     (semanticdb-rescan-directory file) 
     (when (member (file-name-extension file) python-extention-list) 
     (message "Parsing %s file." file) 
     (ignore-errors 
      (semanticdb-file-table-object file)))))) 

(defun semantic-python-rescan-includes() 
    (interactive) 
    (dolist (includes (semantic-python-get-system-include-path)) 
    (message "Parsing %s" includes) 
    (semanticdb-rescan-directory includes)))