在emacs中使用像source insight 一样的函数预览窗口(升级版)
发表于 : 2009-04-22 23:33
以前就写过一个类似的小程序,这次又改进了一下。
这个程序主要用于在emacs中读程序时使用鼠标导航,预设功能是这样的:
先建立一个名叫“*preview*"的buffer。
鼠标左键单击一个函数或变量名,在“*preview*" buffer中显示出函数或变量的定义。
鼠标中键点击一个函数或变量名,在“*preview*" buffer中显示出函数或变量被调用的地方。
如果某个函数的定义只有唯一一处,那么“*preview*" buffer就会显示出它的定义所在。鼠标左键单击“*preview*" buffer可以把该定义所在的文件打开到另一个buffer。如果函数的定义不唯一,那么“*preview*" buffer会列出所有定义该函数的地址,鼠标左键单击任一地址可以在“*preview*" buffer中显示该定义,左键单击可以在另一个窗口中打开该文件,或者右键单击“*preview*" buffer可以返回到地址列表。
当跳转到一个函数的定义后,单击鼠标右键可以返回到跳转前的地方。对于变量定义以及函数和变量的调用也类似。
大体上,行为就和source insight 或slick editor这些代码浏览工具差不多。
需要重点说明的是,我这个程序只是一个前端显示程序,它依赖于cedet 和gnu global,必须要把这两者装好,否则我这个程序无法工作。
下载附件中的程序,安装方法是emacs扩展的标准方法,在.emacs中加上这几句话:
(require 'yp-preview)
(pv-enable)
(defun my-pv-c-map ()
(interactive)
(define-key c-mode-map [mouse-1] 'pv-find-def-and-delay)
(define-key c-mode-map [mouse-2] 'pv-find-ref-or-paste)
(define-key c-mode-map [mouse-3] 'pv-pop-mark)
)
(add-hook 'c-mode-hook 'my-pv-c-map)
这样,就可以在emacs中用鼠标进行导航了。
呃,还有个不得不说的问题,这个扩展要用的舒服,还需要ecb,把"*preview*" buffer加入到ecb的compile buffer列表里面,我只会直接改动ecb的源程序然后直接编译,这是我自己在ecb-compilation.el中对ecb-compilation-buffer-name做的修改:
(defcustom ecb-compilation-buffer-names `(("*Calculator*" . nil)
("*vc*" . nil)
("*vc-diff*" . nil)
("*preview*" . nil)
,(if ecb-running-xemacs
'("\\*Apropos.*\\*" . t)
'("*Apropos*" . nil))
("*Occur*" . nil)
("*shell*" . nil)
("\\*[cC]ompilation.*\\*" . t)
("\\*i?grep.*\\*" . t)
("*JDEE Compile Server*" . nil)
,(if ecb-running-xemacs
'("\\*Help.*\\*" . t)
'("*Help*" . nil))
("*Completions*" . nil)
("*Backtrace*" . nil)
("*Compile-log*" . nil)
("*bsh*" . nil)
(,(if ecb-running-xemacs
" *Message-Log*"
"*Messages*") . nil))
"*Additional buffer names that should be displayed in the compile-window.
Buffer names can either be defined as strings or as regexps. If the
buffer-name of a buffer matches one of the defined string or regexp then it
will be displayed in the compile-window of ECB even if `compilation-buffer-p'
says nil for this buffer.
It is not recommended to add the name of eshell-buffers to this list because
ECB already handles the eshell-integration as best as possible.
See also the options `ecb-compilation-major-modes' and
`ecb-compilation-predicates'."
:group 'ecb-compilation
:group 'ecb-most-important
:type '(repeat (cons (string :tag "Buffer name")
(boolean :tag "Handled as regexp"))))
这样,使能ecb 的compilation buffer之后就几乎可以和source insight 以及slick editor 的样子差不多了。
现在已知两个问题,一是如果在cedet中使能对global 的支持的话每次调用semantic分析都会调用一次global,把global找到的东西打开把line-number转换成point-number,再把这些文件关闭。这样其实效率很低,如果没必要的话干脆就不要打开semantic对global的支持好了,我这个扩展自己也会调用global. 如果你用ede建立了一个project的话可以在ede中使能global,这没关系。另一个问题就是我这个扩展在linux下很正常,在windows下会有及个别的文件用鼠标点击后会乱蹦,不知道咋回事,没理它。
基本上,我就是按照我自己的喜好弄的,可能不符合别人的胃口,谁有什么好的建议可以把它做得通用一点,可以跟我提提。
这个程序主要用于在emacs中读程序时使用鼠标导航,预设功能是这样的:
先建立一个名叫“*preview*"的buffer。
鼠标左键单击一个函数或变量名,在“*preview*" buffer中显示出函数或变量的定义。
鼠标中键点击一个函数或变量名,在“*preview*" buffer中显示出函数或变量被调用的地方。
如果某个函数的定义只有唯一一处,那么“*preview*" buffer就会显示出它的定义所在。鼠标左键单击“*preview*" buffer可以把该定义所在的文件打开到另一个buffer。如果函数的定义不唯一,那么“*preview*" buffer会列出所有定义该函数的地址,鼠标左键单击任一地址可以在“*preview*" buffer中显示该定义,左键单击可以在另一个窗口中打开该文件,或者右键单击“*preview*" buffer可以返回到地址列表。
当跳转到一个函数的定义后,单击鼠标右键可以返回到跳转前的地方。对于变量定义以及函数和变量的调用也类似。
大体上,行为就和source insight 或slick editor这些代码浏览工具差不多。
需要重点说明的是,我这个程序只是一个前端显示程序,它依赖于cedet 和gnu global,必须要把这两者装好,否则我这个程序无法工作。
下载附件中的程序,安装方法是emacs扩展的标准方法,在.emacs中加上这几句话:
(require 'yp-preview)
(pv-enable)
(defun my-pv-c-map ()
(interactive)
(define-key c-mode-map [mouse-1] 'pv-find-def-and-delay)
(define-key c-mode-map [mouse-2] 'pv-find-ref-or-paste)
(define-key c-mode-map [mouse-3] 'pv-pop-mark)
)
(add-hook 'c-mode-hook 'my-pv-c-map)
这样,就可以在emacs中用鼠标进行导航了。
呃,还有个不得不说的问题,这个扩展要用的舒服,还需要ecb,把"*preview*" buffer加入到ecb的compile buffer列表里面,我只会直接改动ecb的源程序然后直接编译,这是我自己在ecb-compilation.el中对ecb-compilation-buffer-name做的修改:
(defcustom ecb-compilation-buffer-names `(("*Calculator*" . nil)
("*vc*" . nil)
("*vc-diff*" . nil)
("*preview*" . nil)
,(if ecb-running-xemacs
'("\\*Apropos.*\\*" . t)
'("*Apropos*" . nil))
("*Occur*" . nil)
("*shell*" . nil)
("\\*[cC]ompilation.*\\*" . t)
("\\*i?grep.*\\*" . t)
("*JDEE Compile Server*" . nil)
,(if ecb-running-xemacs
'("\\*Help.*\\*" . t)
'("*Help*" . nil))
("*Completions*" . nil)
("*Backtrace*" . nil)
("*Compile-log*" . nil)
("*bsh*" . nil)
(,(if ecb-running-xemacs
" *Message-Log*"
"*Messages*") . nil))
"*Additional buffer names that should be displayed in the compile-window.
Buffer names can either be defined as strings or as regexps. If the
buffer-name of a buffer matches one of the defined string or regexp then it
will be displayed in the compile-window of ECB even if `compilation-buffer-p'
says nil for this buffer.
It is not recommended to add the name of eshell-buffers to this list because
ECB already handles the eshell-integration as best as possible.
See also the options `ecb-compilation-major-modes' and
`ecb-compilation-predicates'."
:group 'ecb-compilation
:group 'ecb-most-important
:type '(repeat (cons (string :tag "Buffer name")
(boolean :tag "Handled as regexp"))))
这样,使能ecb 的compilation buffer之后就几乎可以和source insight 以及slick editor 的样子差不多了。
现在已知两个问题,一是如果在cedet中使能对global 的支持的话每次调用semantic分析都会调用一次global,把global找到的东西打开把line-number转换成point-number,再把这些文件关闭。这样其实效率很低,如果没必要的话干脆就不要打开semantic对global的支持好了,我这个扩展自己也会调用global. 如果你用ede建立了一个project的话可以在ede中使能global,这没关系。另一个问题就是我这个扩展在linux下很正常,在windows下会有及个别的文件用鼠标点击后会乱蹦,不知道咋回事,没理它。
基本上,我就是按照我自己的喜好弄的,可能不符合别人的胃口,谁有什么好的建议可以把它做得通用一点,可以跟我提提。