简体   繁体   English

使用tuareg在Emacs中启动自定义OCaml顶级的便捷方式

[英]Convenient way to start a custom OCaml toplevel in Emacs with tuareg

If I start a custom toplevel in Emacs/tuareg with the tuareg-run-caml function, I need to give the path to the toplevel and the various -I options it requires to find the CMI files. 如果我使用tuareg-run-caml函数在Emacs / tuareg中启动自定义顶层,我需要提供顶层的路径以及查找CMI文件所需的各种-I选项。 This typing is tedious, is there a more convenient way to start a custom toplevel? 这种打字很乏味,是否有更方便的方式来启动自定义顶层?

One approach is to add a .ocamlinit in the project directory that uses #directory to add whatever paths are necessary to the toplevel. 一种方法是在项目目录中添加.ocamlinit ,该目录使用#directory添加顶层所需的任何路径。 You can also use this to install printers, add shorter names for commonly used modules, run test code, etc. 您也可以使用它来安装打印机,为常用模块添加更短的名称,运行测试代码等。

Note that you probably want that project specific .ocamlinit to execute ~/.ocamlinit , since things like opam tend to put bits and pieces in there. 请注意,您可能希望该项目特定的.ocamlinit执行~/.ocamlinit ,因为像opam这样的东西往往会在那里放置点点滴滴。 It might look something like this: 它可能看起来像这样:

#use "/home/foo/.ocamlinit"

#directory "_build"

open Printf
module V = VeryLongModuleName

Note that #use expects a hard-coded path. 请注意, #use需要硬编码路径。 This unfortunately interferes with distributing the file. 遗憾的是,这会干扰分发文件。

I further automate this by having an emacs command to start a toplevel that searches the current directory for a file called *.top to execute, falling back to ocaml if none is found. 我通过使用emacs命令启动一个顶层来进一步自动化,该命令在当前目录中搜索一个名为*.top的文件来执行,如果没有找到则返回ocaml As ocamlbuild provides a fairly simple method of building these files, this avoids much of the tedium of getting a project loaded into a useable toplevel. 由于ocamlbuild提供了一种构建这些文件的相当简单的方法,因此避免了将项目加载到可用的顶层中的繁琐工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM