嵌入式之行(4):我的emacs(下) | 迟思堂工作室
A-A+

嵌入式之行(4):我的emacs(下)

2014-08-30 15:13 嵌入式Linux 暂无评论 阅读 37,974 次

本文继续讲解emacs的各种配置及使用,并结合图片演示。

 3、配置及使用 

(1)doxymacs 

先讲一下doxymacs,上面说过,我主要用于代码的注释,因为从代码生成文档我还不会。配置文件如下: 

;;; 加载 

(add-to-list 'load-path "~/.emacs.d/doxymacs/share/emacs/site-lisp")

(require 'doxymacs)

(defun my-doxymacs-font-lock-hook ()

    (if (or (eq major-mode 'c-mode) (eq major-mode 'c++-mode))

        (doxymacs-font-lock)))

 

(add-hook 'font-lock-mode-hook 'my-doxymacs-font-lock-hook)

(add-hook 'c-mode-common-hook 'doxymacs-mode)

(add-hook 'c++-mode-common-hook 'doxymacs-mode)

 

    注释形式有很多种。 

 - C-c d f will insert a Doxygen comment for the next function.

(在某一函数前插入注释)

- C-c d i will insert a Doxygen comment for the current file.

(在当前文件插入注释)

- C-c d ; will insert a Doxygen comment for the current member.

(为一个变量插入注释)

- C-c d m will insert a blank multi-line Doxygen comment.

(多行注释)

- C-c d s will insert a blank single-line Doxygen comment.

(单行注释)

 

多行注释(C-c d m)如图1所示。(可以看到自己添加的与doxymacs生成的颜色是不同的) 

多行注释 

 

1 多行注释 

函数之前的注释(C-c d f)如图2所示。 

 函数前注释

 

2 函数前注释 

一个文件中插入的注释(C-c d i)如图3所示。——关于出现的作者及e-mail是在emacs配置文件中添加的,配置见下文。 

   文件前注释

3 文件前注释 

(2)cedet 

配置文件如下: 

;;; 加载 

 (load-file "~/.emacs.d/cedet/common/cedet.el")

 

(global-ede-mode 1)

(global-srecode-minor-mode 1)

 

;;;  选择一个就可以了,可以看一下每一个的效果再作选择 

(semantic-load-enable-code-helpers)

;;; (semantic-load-enable-guady-code-helpers)

;;; (semantic-load-enable-excessive-code-helpers)

 

;;; 搜索路径 

(setq semanticdb-project-roots

      (list

      (expand-file-name "/")))

;;; 数据库位置,可以随意选择,我选择在家目录下(后面有说明)

(require 'semanticdb)

(setq semanticdb-default-save-directory

(expand-file-name "~/semanticdb"))

 

(global-semanticdb-minor-mode 1)

;;; 空闲调度时间 

(setq-default semantic-idle-scheduler-idle-time 432000)

(setq semanticdb-search-system-databases t)

;;; 针对于结构体和指针的补齐 

(global-set-key "." 'semantic-complete-self-insert)

(global-set-key ">" 'semantic-complete-self-insert)

;;; 补齐的其它按键 

(global-set-key [(control return)] 'semantic-ia-complete-symbol)

(global-set-key "C-c?" 'semantic-ia-complete-symbol-menu)

(global-set-key "C-c>" 'semantic-complete-analyze-inline)

(global-set-key "C-cp" 'semantic-analyze-proto-impl-toggle)

 

;;; 可以看一下效果再作选择。那个菜单式补齐(VC6.0补齐那种)我截图不到,但我负责地告诉你,是可以的。 

;;;(global-set-key [(control tab)] 'senator-completion-menu-popup)

;;;(global-set-key [(meta ?/)] 'semantic-ia-complete-symbol-menu)

;;; this will be fine!!

(global-set-key [(meta ?/)] 'semantic-ia-complete-symbol-menu)

 自动补齐的一种方式(指针方式)一种示例如图4所示。 

自动补齐 

4 自动补齐 

我将cedet的数据库(自动补齐所需要的数据)位置设置为自己的家目录,在没有创建该数据目录前,emacs会寻问是否创建,单击“Yes”即可。如图5所示。 

 

数据库位置

5 数据库位置

我们看一下这个所谓的数据库的真实面目,说白了,它们就是一些文件,至于文件内容,我是看不懂的。如图6所示。

  “数据库”

6 “数据库”

该工具还有一个功能,就是函数原型与定义之间的切换,我绑定于C-c p上,如下:

(global-set-key "C-cp" 'semantic-analyze-proto-impl-toggle)

效果如图7所示,图中所示为从函数原型找到函数定义瞬间的截图。那种效果有点炫。 

  原型to定义

7 原型to定义

下面这些主要是从曹乐的个人主页(http://www.caole.net/diary/index.html)上拷过来,再修改的:

;;; auto complete

(defun my-indent-or-complete()

      (interactive)

      (if (looking-at "\>")

             (hippie-expand nil)

             (indent-for-tab-command))

)

(global-set-key [(control tab)] 'my-indent-or-complete)

 

(autoload 'senator-try-expand-semantic "senator")

 

;;; NOTE:i put xxx-dabbrev first

;;; i think it will be fine

(setq hippie-expand-try-functions-list

       '(

      ;;;senator-try-expand-semantic

      try-expand-dabbrev

      try-expand-dabbrev-visible

      senator-try-expand-semantic

      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

        )

)

 

;;; cc-mode

;;; what does it mean?puzzle

(require 'cc-mode)

(c-set-offset 'inline-open 0)

(c-set-offset 'friend '-)

(c-set-offset 'substatement-open 0)

 

(defun my-c-mode-common-hook()

      ;; c style,this will be good

      (c-set-style "stroustrup")

      ;; tab is 4 NOT 8

      (setq-default tab-width 4)

      ;; this is better than the next line! so i choose this one

      (global-set-key(kbd "RET") 'newline-and-indent)

      ;; OK here replace "make -k" to "gcc"

      (setq compile-command "gcc")

     

      ;;; some  key map

      (define-key c-mode-base-map [(f7)] 'compile)

      (define-key c-mode-base-map [(control `)] 'hs-toggle-hiding)

      (define-key c-mode-base-map [(meta `)] 'c-indent-command)

      (define-key c-mode-base-map [(tab)] 'my-indent-or-complete)

      ;;;(define-key c-mode-base-map [(meta ?/)] 'semantic-ia-complete-symbol)

      ;;; pre process

      (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)

      (setq tab-width 4 indent-tabs-mode nil)

     

)

(add-hook 'c-mode-common-hook 'my-c-mode-common-hook)

 

;;; I know it is not very good ,bu I have no good idea

(defun my-c++-mode-hook()

      ;; c++ style,this will be good

      (c-set-style "stroustrup")

      ;; tab is 4 NOT 8

      (setq-default tab-width 4)

      ;; OK here replace "make -k" to "g++"

      (setq compile-command "g++")

     

      ;;; some  key map

      (define-key c-mode-base-map [(f7)] 'compile)

      (define-key c-mode-base-map [(control `)] 'hs-toggle-hiding)

      (define-key c-mode-base-map [(meta `)] 'c-indent-command)

      (define-key c-mode-base-map [(tab)] 'my-indent-or-complete)

      ;;;(define-key c-mode-base-map [(meta ?/)] 'semantic-ia-complete-symbol-menu)

      ;;; pre process

      (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)

      (setq tab-width 4 indent-tabs-mode nil)

)

(add-hook 'c++-mode-hook 'my-c++-mode-hook)

 

 

(3)ecb

配置文件如下:

;;; 加载

(add-to-list 'load-path "~/.emacs.d/ecb-2.40")

(require 'ecb)

;;;(require 'ecb-autoloads)

;;; 不要每日提示

(setq ecb-tip-of-the-day nil)

(setq ecb-version-check nil)

;;; 激活

(global-set-key [(f12)] 'ecb-activate)

;;; 禁止

(global-set-key [(f11)] 'ecb-deactivate)

 

效果如图8所示,这个工具在阅读代码时,如果配合cscope的话,会很方便。 

  ecb效果图

8 ecb效果图

(4)cscope

配置文件如下:

(add-to-list 'load-path "~/.emacs.d/cscope-15.7a/contrib/xcscope")

(require 'xcscope)

它的一些默认的命令如下:

查找定义:

下面的截图9中说明了查找一个变量的定义。我同时打开3窗口,都是同一个文件,我的光标定位于左上方的窗口的V4L2_PIX_FMT_YUYV,再按C-c s g,之后,在该窗口显示找到的定义的那个文件,在最下窗口显示路径及命中的变量,图中光标在右上方窗口中,纯粹是为了说明问题,不具有实际意义。

 查找定义示例

图9 查找定义示例

这些都是编程所经常要使用到的,下面讲一下其它的配置。

四、其它

emacs中显示时间:

(display-time-mode 1)

(setq display-time-24hr-format t)

(setq display-time-day-and-date t)

(setq display-time-interval 1)

不要备份文件,即那个讨厌的~

(setq make-backup-files nil)

不要响铃及开始画面信息:

(setq visible-bell nil)

(setq inhibit-startup-message t)

(setq gnus-inhibit-startup-message t)

(setq inhibit-startup-message t)

行号 (需要line-num.el,附录有,不过在FC上出错,显示不出行号,RF上可以)

(require 'linum)

(global-linum-mode t)

在多个窗口移动(Shit/Alt + 光标,这样不用c-c o一个一个移动了)

(windmove-default-keybindings)

(setq windwove-wrap-around t)

(global-set-key [(meta left)] 'windmove-left)

(global-set-key [(meta right)] 'windmove-right)

(global-set-key [(meta up)] 'windmove-up)

(global-set-key [(meta down)] 'windmove-down)

当光标改为竖的(bar)

(setq-default cursor-type 'bar)

    不让光标闪烁:

(blink-cursor-mode nil)

鼠标躲开光标(试一试吧,很爽的)

(mouse-avoidance-mode 'animate)

允许emacs与其它程序之间复制内容,比如在终端上复制,可以在emacs中粘贴内容。

(setq x-select-enable-clipboard t)

一些个人信息(上面doxymacs文件前插入注释的作者就是这个了!)

(setq user-full-name "Late Lee")

(setq user-mail-address "latelee@163.com")

多窗口gdb调试(下面有文章演示)

(setq gdb-many-windows t)

 

又:我学习emacs时间很久了,在网络上找了很久资料,一点点积累起来,所以,配置这些七七八八的东西花费不少时日。现在才写总结,估计有点晚了,有些东西也记不起来的,如果文中有什么出错的地方,希望大家提提意见。毕竟,有错误的文章会误人子弟,害人害己。

附录

1、如果你想自己手动安装文中的工具,可以在google搜索,如果实在不想,可以点击这里的连接来下载:



如果本文对阁下有帮助,不妨赞助笔者以输出更多好文章,谢谢!
donate




给我留言