[英]How can I specify a custom path to the annotation files in tuareg-mode emacs?
无论如何在emacs中使用tuareg-mode时指定annot文件的路径? 我试图找出我的函数的类型,模式抱怨“不是注释文件”。
我的构建结构是:
lib
obj
*.o
*.cmi
*.cmx
*.annot
src
*.ml
*.mli
我不认为您可以轻松配置它:查看ocaml安装中caml-types.el
文件中的caml-types-locate-type-file
函数。
这是搜索.annot
文件的函数。 你可以编辑它来用obj
替换"_build"
(这是ocamlbuild
放置生成的文件的地方)并完成它。
一个更好的选择是在.emacs.el
定义一个变量,并在caml-types.el
文件中使用它。 这样,你甚至可以向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
以下代码对我来说足够了:它创建了一个新的自定义变量(我没有绑定到自定义组,但您可以根据需要),然后将该变量用作要搜索的目录列表。
(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.