java - 在 emacs 中跳转 java 方法

标签 java emacs navigation keyboard-shortcuts shortcut

我想通过方法跳转我的 java 文件,例如当我走到任何地方时,只需使用一个键盘快捷键即可跳转到方法的下一个结尾或方法的开头。

Emacs 使用 C-M-a 和 C-M-e 的“通过 defuns 移动”对于 C 非常有用并且完全符合我的要求。但显然在 Java 中,defun 是一个完整的类。

按 defuns 移动: http://www.gnu.org/software/emacs/manual/html_node/emacs/Moving-by-Defuns.html

我发现我可以强制 C-M-f 和 C-M-b 做我想做的事情。它们在任何括号平衡的表达式上向前和向后移动。问题是,当从方法定义的左括号或右括号外调用时,它们只有我正在寻找的功能,这是非常有限的。

带平衡括号的表达式: http://www.delorie.com/gnu/docs/emacs/emacs_282.html

欢迎任何想法!

最佳答案

imenuspeedbar接近您要找的东西。

否则你可以自己定义。 你可以从这样的事情开始:

(defvar java-function-regexp
  (concat
   "^[ \t]*"                                   ; leading white space
   "\\(public\\|private\\|protected\\|"        ; some of these 8 keywords
   "abstract\\|final\\|static\\|"
   "synchronized\\|native"
   "\\|[ \t\n\r]\\)*"                          ; or whitespace
   "[a-zA-Z0-9_$]+"                            ; return type
   "[ \t\n\r]*[[]?[]]?"                        ; (could be array)
   "[ \t\n\r]+"                                ; whitespace
   "\\([a-zA-Z0-9_$]+\\)"                      ; the name we want!
   "[ \t\n\r]*"                                ; optional whitespace
   "("                                         ; open the param list
   "\\([ \t\n\r]*"                             ; optional whitespace
   "\\<[a-zA-Z0-9_$]+\\>"                      ; typename
   "[ \t\n\r]*[[]?[]]?"                        ; (could be array)
   "[ \t\n\r]+"                                ; whitespace
   "\\<[a-zA-Z0-9_$]+\\>"                      ; variable name
   "[ \t\n\r]*[[]?[]]?"                        ; (could be array)
   "[ \t\n\r]*,?\\)*"                          ; opt whitespace and comma
   "[ \t\n\r]*"                                ; 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-methodmy:prev-java-method 绑定(bind)到您想要转到的任何键上

关于java - 在 emacs 中跳转 java 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13127959/

相关文章:

java - Spring MVC Showcase示例的Maven构建过程中出现错误

emacs - 修改缓冲区焦点控制(pop-to-buffer vs display-buffer)

linux - 我正在尝试使用 gtk+ 2.0 构建 emacs 24.5

html - 如何使用图像创建 Angular 导航

java - 如何使用 DevKit 在 Intellij 中添加选择框以运行工具栏

java - 是否可以通过 GSON 将 ImageView 发送到另一个 Activity?

r - Emacs+ESS+R : How to have help page open in new buffer

WPF 麦哲伦 : is there a way to navigate to a existing view?

javascript - 多级点击子菜单

java - 无法解析名称错误的 View Spring MVC 4 + Apache Tiles 3