海上月明

          editer by sun
          posts - 162, comments - 51, trackbacks - 0, articles - 8
             :: 首頁 :: 新隨筆 ::  :: 聚合  :: 管理

          [轉]emacs 代碼自動補齊的三個方法

          Posted on 2008-10-16 17:29 pts 閱讀(5454) 評論(0)  編輯  收藏 所屬分類: Emacs
          Emacs -- 自動補齊

          在編寫代碼時,自動補齊(成員函數變量,以及……)能提高很大的效率,emacs的自動補齊方法有很多種,我參考了很多其他網友的文章,簡單總結了下,希望其他網友不要怪罪我哈,呵呵,我希望把我的學習過程記錄下來,能對其他網友有所幫助.以下是幾種不同的方法(也可以一塊用哈)
          1. Emacs 自帶的hippie-expand (參考的是王垠的)
          hippie-expand是 Emacs 自帶的功能,
          把M-/ 綁定到 hippie-expand,在.emacs文件中加入
          ;;綁定按鍵
          (global-set-key [(meta ?/)] 'hippie-expand)

          hippie-expand 的補全方式。它是一個優先列表, hippie-expand 會優先使用表最前面的函數來補全。通常的設置是:

          (setq hippie-expand-try-functions-list
          '(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
          try-expand-list
          try-expand-line
          try-complete-lisp-symbol-partially
          try-complete-lisp-symbol))
          首先使用當前的buffer補全,如果找不到,就到別的可見的窗口里尋找,
          如果還找不到,那么到所有打開的buffer去找,如果還……那么到kill-ring里,
          到文件名,到簡稱列表里,到list,…… 當前使用的匹配方式會在 echo 區域
          顯示.
          確實是非常好用,基本上我M-/就能到達我想要的了.

          2 采用etags
          etags能像cscope那樣,在代碼里跳來跳去,比如查找函數,變量等,它還能夠自動補齊代碼.
          1),先生成etags文件
          find . /usr/include/ -name "*.c" -or -name "*.cpp" -or -name "*.hpp" -or -name "*.h" |xargs etags --members --language=c++
          2).配置.emacs
          (setq tags-file-name "~/TAGS")
          3),使用
          在emacs中,M-tab 就可以自動補齊了,不過有時候還是不是很好用.
          M-. 查找一個tag,比如函數定義類型定義等。
          C-u M-. 查找下一個tag的位置
          M-* 回到上一次運行M-.前的光標位置。 M-TAB 自動補齊函數名。

          3 采用cedet包
          1)下載cedet
          網址是 http://cedet.sourceforge.net/
          2)編譯
          tar -zxf cedet-1.0pre3.tar.gz
          cd cedet-1.0pre3
          make
          如果make不成功的話,就看看那個說明吧
          3)配置
          查看emacs的配置文件在哪里
          whereis emacs
          拷貝編譯好了的cedet
          cp -r cedet-1.0pre3 /usr/share/emacs/
          查看是否有我們需要的那個文件
          ls /usr/share/emacs/cedet-1.0pre3/common/cedet.el

          配置.emacs文件,在.emacs文件中加入
          ;;;;;;;;;;cedet
          (load-file "/usr/share/emacs/cedet-1.0pre3/common/cedet.el")

          ;;設置檢索范圍
          (setq semanticdb-project-roots
          (list
          (expand-file-name "/")));;可以設置為項目的頂級目錄

          ;;綁定按鍵,ctr+tab,以下三種,任意選擇一個,我喜歡第二個
          ;;(global-set-key [(control tab)] 'senator-complete-symbol);
          (global-set-key [(control tab)] ' senator-completion-menu-popup)
          ;; (global-set-key [(control tab)] 'semantic-ia-complete-symbol-menu)

          4)使用
          在一個未輸入完成的函數上嘗試下ctr+tab鍵

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 深泽县| 旌德县| 新邵县| 都安| 天峨县| 花莲市| 惠水县| 四平市| 中超| 双江| 界首市| 茶陵县| 馆陶县| 沾化县| 浮梁县| 武宁县| 庐江县| 绍兴县| 伊金霍洛旗| 正定县| 曲靖市| 都安| 岑溪市| 桐乡市| 涞源县| 兴安县| 巴彦淖尔市| 平陆县| 普兰店市| 峨山| 横山县| 庄河市| 玛多县| 红安县| 准格尔旗| 明水县| 资源县| 容城县| 永川市| 南宁市| 乃东县|