首页 > 代码库 > 给树莓派IIraspberrypi安装emacs+ecb+cedet+session+color-theme+cscope+linum

给树莓派IIraspberrypi安装emacs+ecb+cedet+session+color-theme+cscope+linum

类似这篇文章写的不多,为了避免以后大家转来转去而忽略了写文章的时间,这些特别加上是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.
 )