定义函数的简单方法(Emacs、Ocaml)
我正在 Emacs 下编写 Ocaml...
我想知道是否有快捷方式可以跳转到函数的定义(光标所在的位置)。目前,要做到这一点,我必须在整个文件中搜索函数的名称,或者查找 let the_name_of_the_function
和 let rec the_name_of_the_function
和 and the_name_of_the_function
这显然很乏味......
顺便说一下,我已经有了文件.annot
。
有人可以帮忙吗?谢谢你!
I am coding Ocaml under Emacs...
I would like to know if there is a shortcut to jump to the definition of a function (where the cursor is). At the moment, to do so I have to search the name of the function in the whole file, or look for let the_name_of_the_function
and let rec the_name_of_the_function
and and the_name_of_the_function
which is obviously tedious...
By the way, I have alreay the file .annot
.
Could anyone help? Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我的
ctags(1)
(来自exuberant-ctags
包)支持 OCaml 语言,并且 Emacs 在作为执行时支持
。ctags
etags所以尝试: cd /path/to/Ocaml/sources/ && etags -R . 构建索引,然后在
emacs
中,M-.ret搜索光标下的标签。My
ctags(1)
(from theexuberant-ctags
package) supports the OCaml language and Emacs supportsctags
when it is executed asetags
.So try:
cd /path/to/Ocaml/sources/ && etags -R .
to build an index, and then withinemacs
, M-.ret to search for the tag under the cursor.这个问题可以用 merlin 解决(https://github.com/the-lambda-church/merlin )。 Merlin 可以使用 opam 轻松安装:
按照 opam 提供的说明配置 ~/.emacs 文件。要完成配置,您必须提供一个 .merlin 文件,该文件告诉 merlin 源文件和构建文件的位置以及项目中使用了哪些包。 https://github.com/the-lambda-church/merlin/wiki/emacs-from-scratch#configuring-your-project
现在,跳转到 Emacs 中的函数定义:
返回到这函数调用:
The problem could be solved with merlin (https://github.com/the-lambda-church/merlin). Merlin can be installed easily with opam:
Follow the instructions provided by opam to configure ~/.emacs file. To finish the configuration you will have to provide a .merlin file that tells merlin where the source files and build files are located and which packages are used in the project. A brief overview of the .merlin file is given in https://github.com/the-lambda-church/merlin/wiki/emacs-from-scratch#configuring-your-project
Now, to jump to the function definition in Emacs:
To move back to the function call:
当您等待更好的解决方案时(其中有一些,请参见例如 OCamlSpotter),您可以使用下面列出的穷人命令。假定图阿雷格模式。
While you are waiting for a better solution (of which there are some, see for example OCamlSpotter) you can use the poor-man commands listed below. Assumes tuareg-mode.
您可以尝试位于此处的
otags
:http://askra.de/software/otags/
从项目页面:
要使用它,请尝试以下操作:
其中 src 是包含 OCaml 源文件的子目录。
它应该创建一个
TAGS
文件。那么您应该能够在 Emacs 中执行
M-.
。您可以使用
opam
安装otags
。You can try
otags
located here:http://askra.de/software/otags/
From the project page:
To use it, try something like:
where
src
is the subdirectory containing your OCaml source files.It should create a
TAGS
file.Then you should be able to do
M-.
in Emacs.You can install
otags
withopam
.