在emacs中使用tuareg-mode时,是否有指定注释文件的路径? 我试图找出我的功能的类型和模式抱怨 “不是注释文件”。如何指定tuareg-mode emacs中的注释文件的自定义路径?
我构建结构是:
lib
obj
*.o
*.cmi
*.cmx
*.annot
src
*.ml
*.mli
在emacs中使用tuareg-mode时,是否有指定注释文件的路径? 我试图找出我的功能的类型和模式抱怨 “不是注释文件”。如何指定tuareg-mode emacs中的注释文件的自定义路径?
我构建结构是:
lib
obj
*.o
*.cmi
*.cmx
*.annot
src
*.ml
*.mli
我不认为你可以轻松地配置这一点:在你的ocaml的安装看看caml-types-locate-type-file
功能在caml-types.el
文件。
这是搜索.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` ... – 2014-03-19 01:33:05
# 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
感谢托尼奥,你的建议非常完美。如果我有时间,也许我会擦亮解决方案并发送补丁。 – Calin 2011-02-16 17:40:30