简体   繁体   English

如何在tuareg-mode emacs中指定注释文件的自定义路径?

[英]How can I specify a custom path to the annotation files in tuareg-mode emacs?

Is there anyway to specify the path to the annot files when using tuareg-mode in emacs? 无论如何在emacs中使用tuareg-mode时指定annot文件的路径? I am trying to find out the type for my functions and the mode complains with "not annotation file". 我试图找出我的函数的类型,模式抱怨“不是注释文件”。

My build structure is: 我的构建结构是:

lib 
 obj
  *.o
  *.cmi
  *.cmx
  *.annot
 src
  *.ml
  *.mli

I don't think you can easily configure this: have a look at the caml-types-locate-type-file function in the caml-types.el file in your ocaml installation. 我不认为您可以轻松配置它:查看ocaml安装中caml-types.el文件中的caml-types-locate-type-file函数。

This is the function that searches for .annot files. 这是搜索.annot文件的函数。 You can probably edit it to replace the "_build" (which is where ocamlbuild puts the generated files) with obj and be done with that. 你可以编辑它来用obj替换"_build" (这是ocamlbuild放置生成的文件的地方)并完成它。

A much better option is to define a variable in your .emacs.el , and use it in the caml-types.el file. 一个更好的选择是在.emacs.el定义一个变量,并在caml-types.el文件中使用它。 this way, you could even propose the patch to the ocaml people. 这样,你甚至可以向ocaml人提出补丁。

# soft link .annot files so that Emacs' tuareg-mode can find them
mkdir -p _build
for f in `find lib/obj -name *.annot` ; do ln -s ../$f _build/ ; done

The following code suffices for me: it creates a new customization variable (which I haven't bound to a customization group, but you can if you want), then uses that variable as a list of directories to search. 以下代码对我来说足够了:它创建了一个新的自定义变量(我没有绑定到自定义组,但您可以根据需要),然后将该变量用作要搜索的目录列表。

(defcustom caml-types-annot-directories-search
  '("_build" "obj" "../obj")
  "List of directories to search for .annot files"
  :type '(repeat string)
)
(defun or-list (f lst)
  (if (null lst) nil
    (if (apply f (car lst) nil)
        (car lst)
        (or-list f (cdr lst)))))

(add-hook 'tuareg-mode-hook
          (lambda ()
            (defun caml-types-locate-type-file (target-path)
              (let ((sibling (concat (file-name-sans-extension target-path) ".annot")))
                (if (file-exists-p sibling)
                    sibling
                  (let ((project-dir (file-name-directory sibling))
                        (test-dir (lambda (prefix)
                                    (message "Prefix is %s" prefix)
                                    (setq type-path
                                          (expand-file-name
                                           (file-relative-name sibling project-dir)
                                           (expand-file-name prefix project-dir)))
                                    (message "Testing %s" type-path)
                                    (file-exists-p type-path)))
                        type-path)
                    (while (not (or-list test-dir caml-types-annot-directories-search))
                      (if (equal project-dir (caml-types-parent-dir project-dir))
                          (error (concat "No annotation file. "
                                         "You should compile with option \"-annot\".")))
                      (setq project-dir (caml-types-parent-dir project-dir)))
                    type-path))))))

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

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