標籤:樹莓派 raspberrypi emacs cc++ ecbcedet
類似這篇文章寫的不多,為了避免以後大家轉來轉去而忽略了寫文章的時間,這些特別加上是2014年6月28日,省的對不上一些軟體的版本(下文中有些“最新”的說法就對應這個時間)。如果轉寄的時候能夠加上我老顧的原文連結就更好了:)
還是在2008~2010年的時候,比較粉Emacs,然後花了很多時間在上面,編程效率的確高了,但是在上面花的時間也不少。2010年底的時候,放棄Emacs,而是選用所有支援emacs key的IDE,比如Eclipse,NetBean,VS等,說到底Emacs的編程效率最主要就體現在emacs key上,而直接用Emacs的話,各種外掛程式的版本衝突解決和配置要花開發人員不少時間,而使用現代IDE,既能享受emacs key的快捷,又能省去Emacs配置和麻煩,何樂而不為。
但是最近在樹莓派II上開發一些嵌入式(主要是讀取各種感應器,然後通過網路傳給伺服器)應用,通過我的主機SSH串連樹莓派II,而且考慮到效能,已經不使用樹莓派II上raspberrypi的介面,那麼只能在控制台下進行開發,所以不得不重新拾起emacs這個IDE。說實話,做了12年多的各種技術的應用,最近是剛開始學習嵌入式的開發,生命不止、學習不止:)
花了大半天,總算在處理了各種版本問題後,把開發環境搭建起來了,下面簡單記錄一下。
首先,Emacs的設定檔在~/.emacs,所有外掛程式在~/.emacs.d/lisp/。
整個環境使用軟體的版本。
- Emacs 23.4.1,raspberrypi內建。
- cscope-15.7a,raspberrypi內建,但是沒有cscope-indexer和xcscope.el,奇怪,可能只是raspberrypi是這樣。
- cscope-15.8a,下載,只解壓,然後把cscope-indexer加上執行許可權然後複製到/usr/bin中,把xcsope.el複製到~/.emacs.d/lisp/。
- ecb-2.40,下載,這個沒得選,解壓後放到~/.emacs.d/lisp/ecb中。
- cedet-1.0.1,下載,不要用1.1,避免了還要修改ecb的版本檢查,?解壓後放到~/.emacs.d/lisp/cedet中。
- linum.el,下載最新的,放到~/.emacs.d/lisp/。?
- session.el,下載最新的,放到~/.emacs.d/lisp/。?
- ?color-theme.el,下載最新的,放到~/.emacs.d/lisp/。?
- session-2.3.a,下載,解壓到~/.emacs.d/lisp/。
?然後把以上所有的*.el都編譯成*.elc,用過Emacs的都直到為啥要做這個,其中ecb和cedet是單獨用make編譯的。其他都用emacs的命令編譯:? emacs -batch -f batch-byte-compile *.el?。但即使編譯了成了.elc,在樹莓派上的速度還是很慢,不過也合理。
能把上面搞定,然後就差.emacs這個檔案的配置了。我的開發需要是C/C++,以C為主。下面是詳細的配置:;; Nomral setting
(setq default-major-mode ‘text-mode)
(global-font-lock-mode t)
(auto-image-file-mode t)
(transient-mark-mode t)
(show-paren-mode t)
(column-number-mode t)
(tool-bar-mode nil)
(setq-default make-backup-files nil)
(mouse-avoidance-mode ‘animate)
(setq x-select-enable-clipboard t)
;; Autorevert stuff
(autoload ‘auto-revert-mode "autorevert" nil t)
(autoload ‘turn-on-auto-revert-mode "autorevert" nil nil)
(autoload ‘global-auto-revert-mode "autorevert" nil t)
(global-auto-revert-mode 1)
(add-to-list ‘load-path "~/.emacs.d/lisp")
;; Load session
(require ‘session)
(add-hook ‘after-init-hook ‘session-initialize)
;; Load linum
(require ‘linum)
(global-linum-mode t)(setq linum-format "%4d \u2502 ")
;; load color-theme
(require ‘color-theme)
(color-theme-hober)
;; Load xcscope
(require ‘xcscope)
;; Load cedet
(load-file "~/.emacs.d/lisp/cedet/common/cedet.elc")
(global-ede-mode 1)
(ede-cpp-root-project "sensor_worker" :file "~/workspace/c/sensor_worker/Makefile")
(semantic-load-enable-code-helpers)
(global-srecode-minor-mode 1)
(global-set-key [(f5)] ‘speedbar)
(defun my-indent-or-complete ()
(interactive)
(if (looking-at "//>")
(hippie-expand nil)
(indent-for-tab-command)
)
)
(autoload ‘senator-try-expand-semantic "senator")
(setq hippie-expand-try-functions-list
‘(
senator-try-expand-semantic
try-expand-dabbrev
try-expand-dabbrev-visible
try-expand-dabbrev-all-buffers
try-expand-dabbrev-from-kill
try-expand-list
try-expand-list-all-buffers
try-expand-line
try-expand-line-all-buffers
try-complete-file-name-partially
try-complete-file-name
try-expand-whole-kill
)
)
;; C/C++ setting
(require ‘cc-mode)
(setq c-basic-offset 4)
(c-set-offset ‘inline-open 0)
(c-set-offset ‘friend ‘-)
(c-set-offset ‘substatement-open 0)
(defun my-c-mode-common-hook()
(setq tab-width 4)
(setq indent-tabs-mode nil)
(setq tab-stop-list ‘(4 8 12 16 20 24 28 32 36 40 44 48 52 56 60 64 68 72 76 80))
(define-key c-mode-base-map [(tab)] ‘my-indent-or-complete)
(define-key c-mode-base-map [(ctrl tab)] ‘semantic-ia-complete-symbol-menu)
(define-key c-mode-base-map [(f9)] ‘compile)
(setq c-macro-shrink-window-flag t)
(setq c-macro-preprocessor "cpp")
(setq c-macro-cppflags " ")
(setq c-macro-prompt-flag t)
(setq hs-minor-mode t)
(setq abbrev-mode t)
(c-set-style "user")
(hl-line-mode t)
)
(add-hook ‘c-mode-common-hook ‘my-c-mode-common-hook)
(add-hook ‘c++-mode-common-hook ‘my-c-mode-common-hook)
(setq auto-mode-alist (cons ‘("//.h$" . c++-mode) auto-mode-alist))
(setq auto-mode-alist (cons ‘("//.cpp$" . c++-mode) auto-mode-alist))
;; Load ecb
(add-to-list ‘load-path "~/.emacs.d/lisp/ecb")
(require ‘ecb)
(global-set-key [f12] ‘ecb-activate)
(global-set-key [C-f12] ‘ecb-deactivate)
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won‘t work right.
‘(ecb-options-version "2.40"))
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won‘t work right.
)