5

Is there anyway to specify the path to the annot files when using tuareg-mode in emacs? I am trying to find out the type for my functions and the mode complains with "not annotation file".

My build structure is:

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

3 Answers 3

2

I don't think you can easily configure this: have a look at the caml-types-locate-type-file function in the caml-types.el file in your ocaml installation.

This is the function that searches for .annot files. You can probably edit it to replace the "_build" (which is where ocamlbuild puts the generated files) with obj and be done with that.

A much better option is to define a variable in your .emacs.el, and use it in the caml-types.el file. this way, you could even propose the patch to the ocaml people.

1
  • Thanks tonio, your suggestion worked perfectly. If I have time maybe I'll polish the solution and send a patch.
    – Calin
    Feb 16, 2011 at 17:40
0

The following code suffices for me: it creates a new customization variable (which I haven't bound to a customization group, but you can if you want), then uses that variable as a list of directories to search.

(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))))))
1
  • Why was this downvoted? It in fact implements the patch suggested by the accepted answer, without having to manually modify caml-types.el...
    – Ben Lerner
    Mar 19, 2014 at 1:33
0
# 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.