【发布时间】:2011-02-15 13:33:45
【问题描述】:
在 emacs 中使用 tuareg-mode 时,是否可以指定 annot 文件的路径? 我正在尝试找出我的功能的类型,并且模式抱怨 “不是注释文件”。
我的构建结构是:
lib
obj
*.o
*.cmi
*.cmx
*.annot
src
*.ml
*.mli
【问题讨论】:
标签: emacs configuration ocaml tuareg
在 emacs 中使用 tuareg-mode 时,是否可以指定 annot 文件的路径? 我正在尝试找出我的功能的类型,并且模式抱怨 “不是注释文件”。
我的构建结构是:
lib
obj
*.o
*.cmi
*.cmx
*.annot
src
*.ml
*.mli
【问题讨论】:
标签: emacs configuration ocaml tuareg
我认为您无法轻松配置此功能:查看 ocaml 安装中 caml-types.el 文件中的 caml-types-locate-type-file 函数。
这是搜索.annot 文件的函数。您可能可以对其进行编辑以将"_build"(ocamlbuild 放置生成的文件的位置)替换为obj 并完成。
更好的选择是在.emacs.el 中定义一个变量,并在caml-types.el 文件中使用它。这样,您甚至可以向 ocaml 人提出补丁。
【讨论】:
以下代码对我来说就足够了:它创建了一个新的自定义变量(我没有绑定到自定义组,但如果你愿意,你可以),然后使用该变量作为要搜索的目录列表。
(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))))))
【讨论】:
caml-types.el...
【讨论】: