问题描述
我想通过方法跳过我的 java 文件,例如当我找到我的任何地方时,执行一个键盘快捷键即可跳转到方法的下一个结尾或方法的开头.
I want to jump through my java files by method, e.g. when I've got my anywhere, do a single keyboard shortcut to jump to the next end of a method or beginning of a method.
Emacs 使用 C-M-a 和 C-M-e 的通过 defuns 移动"对 C 非常有用,并且完全符合我的要求.但显然在 Java 中,一个 defun 是一个完整的类.
Emacs' "moving by defuns" with C-M-a and C-M-e is super-useful for C and does exactly what I want. But apparently in Java a defun is a whole class.
由 defuns 移动:http://www.gnu.org/software/emacs/manual/html_node/emacs/Moving-by-Defuns.html
Moving by defuns: http://www.gnu.org/software/emacs/manual/html_node/emacs/Moving-by-Defuns.html
我发现我可以强制 C-M-f 和 C-M-b 做我想做的事.它们在任何括号平衡的表达式上前后移动.问题是它们只有在从方法定义的左括号或右括号之外调用时才具有我正在寻找的功能,这是极其有限的.
I've found that I can coerce C-M-f and C-M-b to sort of do what I want. They move forward and backward over any parentheses-balanced expression. The problem is that they only have the funcitonality I'm looking for when invoked from right outside the opening or closing brackets of a method definition, which is extremely limiting.
带平衡括号的表达式:http://www.delorie.com/gnu/docs/emacs/emacs_282.html
欢迎任何想法!
推荐答案
imenu 和 speedbar 与您要找的很接近.
imenu and speedbar are close to what you are looking for.
否则你可以自己定义.你可以这样开始:
Otherwise you can define it by yourself. You can start with something like this:
(defvar java-function-regexp
(concat
"^[ ]*" ; leading white space
"\(public\|private\|protected\|" ; some of these 8 keywords
"abstract\|final\|static\|"
"synchronized\|native"
"\|[
]\)*" ; or whitespace
"[a-zA-Z0-9_$]+" ; return type
"[
]*[[]?[]]?" ; (could be array)
"[
]+" ; whitespace
"\([a-zA-Z0-9_$]+\)" ; the name we want!
"[
]*" ; optional whitespace
"(" ; open the param list
"\([
]*" ; optional whitespace
"\<[a-zA-Z0-9_$]+\>" ; typename
"[
]*[[]?[]]?" ; (could be array)
"[
]+" ; whitespace
"\<[a-zA-Z0-9_$]+\>" ; variable name
"[
]*[[]?[]]?" ; (could be array)
"[
]*,?\)*" ; opt whitespace and comma
"[
]*" ; optional whitespace
")" ; end the param list
))
(defun my:next-java-method()
(interactive)
(re-search-forward java-function-regexp nil t)
)
(defun my:prev-java-method()
(interactive)
(re-search-backward java-function-regexp nil t)
)
然后将 my:next-java-method
和 my:prev-java-method
绑定到你想去的任何键
Then bind my:next-java-method
and my:prev-java-method
to whatever key you want to go to the
这篇关于跳转emacs中的java方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!