西西軟件園多重安全檢測(cè)下載網(wǎng)站、值得信賴的軟件下載站!
軟件
軟件
文章
搜索

首頁西西教程軟件使用 → Emacs 23.2 自帶的Cedet的使用

Emacs 23.2 自帶的Cedet的使用

相關(guān)軟件相關(guān)文章發(fā)表評(píng)論 來源:本站整理時(shí)間:2010/11/29 11:54:17字體大小:A-A+

作者:佚名點(diǎn)擊:1770次評(píng)論:0次標(biāo)簽: CEDET Emacs Helpter

emacs for windows23.1 免費(fèi)英文版
  • 類型:文本編輯大。38.1M語言:英文 評(píng)分:7.7
  • 標(biāo)簽:
立即下載
3 頁 Cedet的使用
4 Cedet的使用

4.1 命名補(bǔ)齊
這里的補(bǔ)齊包括函數(shù)名稱,變量名等等,是很常用的一個(gè)功能。 個(gè)人以為最實(shí)用的一個(gè)補(bǔ)齊是 semantic-ia-complete-symbol, 他可以通過快捷鍵"C-c, /" 來調(diào)用。為了使用方便并和其他Package統(tǒng)一, 我將該函數(shù)添加到了hippie-expand中, 并將hippie-expand包進(jìn)了自定義的函數(shù)indent-or-complete (從別人的配置文件中找到的)中,并將這個(gè)函數(shù)綁定到了Tab上。 這樣,大多數(shù)情況下,通過Tab即可實(shí)現(xiàn)補(bǔ)齊或者對(duì)齊。 如果偶爾Tab不成功,再使用"M-/"或者"C-c, /"來修正一下。

這段配置的Lisp代碼如下:

;;;; 縮進(jìn)或者補(bǔ)齊
;;; hippie-try-expand settings
(setq hippie-expand-try-functions-list
'(
yas/hippie-try-expand
semantic-ia-complete-symbol
try-expand-dabbrev
try-expand-dabbrev-visible
try-expand-dabbrev-all-buffers
try-expand-dabbrev-from-kill
try-complete-file-name-partially
try-complete-file-name
try-expand-all-abbrevs))

(defun indent-or-complete ()
"Complete if point is at end of a word, otherwise indent line."
(interactive)
(if (looking-at "\\>")
(hippie-expand nil)
(indent-for-tab-command)
))

(defun yyc/indent-key-setup ()
"Set tab as key for indent-or-complete"
(local-set-key [(tab)] 'indent-or-complete)
)
此外,對(duì)于C和C++的struct/class結(jié)構(gòu),函數(shù)semantic-complete-self-insert 可以插入類或結(jié)構(gòu)中的成員變量,將至綁定到"."或者">",會(huì)加速代碼編寫的效率:

;;;; C-mode-hooks .
(defun yyc/c-mode-keys ()
"description"
;; Semantic functions.
(semantic-default-c-setup)
(local-set-key "\C-c?" 'semantic-ia-complete-symbol-menu)
(local-set-key "\C-cb" 'semantic-mrub-switch-tags)
(local-set-key "\C-cR" 'semantic-symref)
(local-set-key "\C-cj" 'semantic-ia-fast-jump)
(local-set-key "\C-cp" 'semantic-ia-show-summary)
(local-set-key "\C-cl" 'semantic-ia-show-doc)
(local-set-key "\C-cr" 'semantic-symref-symbol)
(local-set-key "\C-c/" 'semantic-ia-complete-symbol)
(local-set-key [(control return)] 'semantic-ia-complete-symbol)
(local-set-key "." 'semantic-complete-self-insert)
(local-set-key ">" 'semantic-complete-self-insert)
;; Indent or complete
(local-set-key [(tab)] 'indent-or-complete)
)
(add-hook 'c-mode-common-hook 'yyc/c-mode-keys)
4.2 獲取Tag信息
semantic-ia-show-doc, semantic-ia-show-summary, semantic-ia-describe-class 這三個(gè)函數(shù)可以用來獲取Tag信息,顯示出代碼的注釋(包括Doxgen的注釋), 對(duì)于閱讀代碼有很大幫助。

這些函數(shù)可以按照自己的習(xí)慣去綁定。其中前面兩個(gè)的綁定過程在前面的 yyc/c-mode-keys中可以找到。

4.3 代碼中的跳轉(zhuǎn)
閱讀代碼時(shí)候,在不同的Tag中跳轉(zhuǎn)是一個(gè)很有用的功能。 Cedet提供了這個(gè)功能,但是我手頭上的Emacs 23.2 中自帶的Cedet在Tag 跳轉(zhuǎn)上有個(gè)問題————可以用 semantic-ia-fast-jump 跳轉(zhuǎn)到Tag定義, 但是每次跳轉(zhuǎn)后,卻不能跳回來。

按照本文3.1節(jié)的方法設(shè)置Helper以后,在配置文件中添加下面的代碼可以解決這一問題:

(defadvice push-mark (around semantic-mru-bookmark activate)
"Push a mark at LOCATION with NOMSG and ACTIVATE passed to `push-mark'.
If `semantic-mru-bookmark-mode' is active, also push a tag onto
the mru bookmark stack."
(semantic-mrub-push semantic-mru-bookmark-ring
(point)
'mark)
ad-do-it)
4.4 查找函數(shù)調(diào)用
前面一節(jié)說的是在當(dāng)前函數(shù)中,跳到Tag定義;而這里, 說的是查看當(dāng)前光標(biāo)下面的函數(shù)被哪些函數(shù)調(diào)用了。 Cedet中的 semantic-symref 實(shí)現(xiàn)了這一功能。 可以將該函數(shù)綁定到自己喜歡的快捷鍵上,如4.1中所示。

對(duì)于代碼的瀏覽這個(gè)部分,我大部分時(shí)候使用的是global這個(gè)工具, global配置Xgtags來用,很方便。

4.5 Srecode的使用
Cedet提供了srecode,用于自動(dòng)生成代碼。但,個(gè)人感覺這個(gè)功能不怎么好用, 或者說是我不會(huì)用吧。

Emacs 23.2中自帶的Cedet,僅提供了srecode的功能,但卻沒有將需要的template 一起和emacs一同發(fā)布出來。

對(duì)此,我的做法是修改了srecode-map-load-path,添加了 "~/.emacs.d/templates/srecode",

;;;; Custom template for srecode
(setq srecode-map-load-path
(list (srecode-map-base-template-dir)
(expand-file-name "~/.emacs.d/templates/srecode")
))
然后從cedet官網(wǎng)上 下載源碼包,并把template解壓到 "~/.emacs.d/templates/srecode"中。

然后將可以使用srecode-insert之類的函數(shù)來插入代碼模版了。

本文導(dǎo)航

    相關(guān)評(píng)論

    閱讀本文后您有什么感想? 已有人給出評(píng)價(jià)!

    • 8 喜歡喜歡
    • 3 頂
    • 1 難過難過
    • 5 囧
    • 3 圍觀圍觀
    • 2 無聊無聊

    熱門評(píng)論

    最新評(píng)論

    發(fā)表評(píng)論 查看所有評(píng)論(0)

    昵稱:
    表情: 高興 可 汗 我不要 害羞 好 下下下 送花 屎 親親
    字?jǐn)?shù): 0/500 (您的評(píng)論需要經(jīng)過審核才能顯示)