跳转emacs中的java方法

Jump through java methods in emacs(跳转emacs中的java方法)
本文介绍了跳转emacs中的java方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我想通过方法跳过我的 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-methodmy: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方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)
How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)
Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)
Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)
How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)
How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)