海上月明

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

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

          Posted on 2008-10-16 17:29 pts 閱讀(5449) 評論(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鍵

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


          網站導航:
           
          主站蜘蛛池模板: 长沙市| 神农架林区| 枞阳县| 凤凰县| 仪征市| 石嘴山市| 铁力市| 揭东县| 临沧市| 和平区| 永清县| 佛坪县| 南召县| 喀喇沁旗| 尖扎县| 东阳市| 元朗区| 福州市| 卓尼县| 浦江县| 汉中市| 调兵山市| 平塘县| 化隆| 厦门市| 安陆市| 蒙自县| 苏尼特左旗| 扶绥县| 紫金县| 开江县| 贡嘎县| 明星| 左权县| 黄山市| 任丘市| 廊坊市| 武山县| 会宁县| 靖西县| 霍山县|