問題描述
我想通過方法跳過我的 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方法的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!