在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