How can I specify a custom path to the annotation files in tuareg-mode emacs?

423 views Asked by At

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

There are 3 answers

1
tonio On BEST ANSWER

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
Ben Lerner On

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))))))
0
Francois B. On
# 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