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

时间:2011-02-15 13:33:45

标签: emacs configuration ocaml tuareg

在emacs中使用tuareg-mode时,是否还要指定annot文件的路径? 我试图找出我的功能的类型和模式抱怨 “不是注释文件”。

我的构建结构是:

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

3 个答案:

答案 0 :(得分:2)

我认为您无法轻松配置此功能:查看ocaml安装中caml-types-locate-type-file文件中的caml-types.el函数。

这是搜索.annot文件的功能。您可以对其进行编辑,以将"_build"ocamlbuild放置生成的文件的位置)替换为obj,并将其完成。

更好的选择是在.emacs.el中定义变量,并在caml-types.el文件中使用它。这样,你甚至可以向ocaml人提出补丁。

答案 1 :(得分:0)

以下代码对我来说足够了:它创建了一个新的自定义变量(我没有绑定到自定义组,但您可以根据需要),然后将该变量用作要搜索的目录列表。

(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))))))

答案 2 :(得分:0)

# 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
相关问题