【问题标题】:How can I specify a custom path to the annotation files in tuareg-mode emacs?如何在 tuareg-mode emacs 中指定注释文件的自定义路径?
【发布时间】:2011-02-15 13:33:45
【问题描述】:

在 emacs 中使用 tuareg-mode 时,是否可以指定 annot 文件的路径? 我正在尝试找出我的功能的类型,并且模式抱怨 “不是注释文件”。

我的构建结构是:

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

【问题讨论】:

    标签: emacs configuration ocaml tuareg


    【解决方案1】:

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

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

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

    【讨论】:

    • 感谢 tonio,您的建议非常有效。如果我有时间,也许我会完善解决方案并发送补丁。
    【解决方案2】:

    以下代码对我来说就足够了:它创建了一个新的自定义变量(我没有绑定到自定义组,但如果你愿意,你可以),然后使用该变量作为要搜索的目录列表。

    (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...
    【解决方案3】:
    # 软链接 .annot 文件,以便 Emacs 的 tuareg-mode 可以找到它们 mkdir -p _build for f in `find lib/obj -name *.annot` ;执行 ln -s ../$f _build/ ;完毕

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-22
      • 2017-01-10
      相关资源
      最近更新 更多