在emacs中跳过java方法 [英] Jump through java methods in emacs

查看:86
本文介绍了在emacs中跳过java方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过方法跳过我的java文件,例如当我到达任何地方时,单击一个键盘快捷方式跳转到方法的下一个结尾或方法的开头。



使用C-M-a和C-M-e,Emacs通过defuns移动对C来说是非常有用的,并且正是我想要的。但显然在Java中,defun是一个整体。



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



我发现我可以强制CMF和CMB排序做我想要的。他们向前和向后移动任何括号 - 平衡表达。问题是,他们只有在方法定义的开头或结尾括号之外被调用时才寻找的功能,这是非常有限的。



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



欢迎任何想法!

解决方案

imenu speedbar 都接近你要找的。

否则你可以自己定义它。
您可以从这样开始:

 (defvar java-function-regexp 
(concat
^ [\t] *;前导空格
\\(public\\ | private\\ | protected\\ | |;这些8关键字
abstract\\ | final\\ | static\\ | |
synchronized\\ | native
\\ | [\\ \\\\\\\\\\\\\\\\\\\\\\\\,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, n\r] * [[]?[]]?;(可能是数组)
[\t\\\
\r] +;空格
\\ ([a-zA-Z0-9 _ $] + \\);我们想要的名称!
[\t\\\
\r] *;可选的空格
(;开参数列表
\\([\t\\\
\r] *;可选的空格
\\< [a-zA-Z0-9_ $] + \\>; typename
[\t\\\
\r] * [[]?[]]? ; (可以是数组)
[\t\\\
\r] +;空格
\\< [a-zA-Z0-9 _ $] + \\> ;变量名称
[\t\\\
\r] * [[]?[]]? ; (可以是数组)
[\t\\\
\r] * ,? \\)*;选择空格和逗号
[\t\\\
\r] *;可选空格
);结束参数列表
))

(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 到你要去的任何键。


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' "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.

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

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.

Expressions with Balanced Parentheses: http://www.delorie.com/gnu/docs/emacs/emacs_282.html

Any ideas would be welcome!

解决方案

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
   "^[ \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)
)

Then bind my:next-java-method and my:prev-java-method to whatever key you want to go to the

这篇关于在emacs中跳过java方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆