kit-ty-kate / merlin

Context sensitive completion for Ocaml in Vim and Emacs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

merlin completion in gvim

Building and installing Merlin

This README gives only indications on how to install merlin from source. If you want know how to install it from opam, and how to setup your environment to use merlin, have a look at the wiki.

Compilation

Dependencies: ocaml >= 4.00.1, ocamlfind, ocamlbuild, yojson, menhir

$ ./configure
$ make

The configure script will check that all the dependencies are met, and will allow you to choose where to install merlin.

Installation

If you haven't encountered any error in the previous step, just run:

$ make install 

Share directory, <SHARE_DIR>

In the rest of the document, <SHARE_DIR> refers to the directory where merlin data files are installed.

It will usually be:

  • "/usr/local/share" if you used manual configuration merlin
  • "<prefix>/share" if you explicitly specified a prefix when configuring merlin
  • printed by the command opam config var share, if you used opam

Setting-up vim

Makes sure that ocamlmerlin binary can be found in PATH.

The only setup needed is to have the following directories in vim runtime path (append this to your .vimrc):

:set rtp+=<SHARE_DIR>/ocamlmerlin/vim
:set rtp+=<SHARE_DIR>/ocamlmerlin/vimbufsync

The default configuration can be seen in:

<SHARE_DIR>/ocamlmerlin/vim/plugin/merlin.vim  

After adding merlin to vim runtime path, you will probably want to run :helptags <SHARE_DIR>/ocamlmerlin/vim/doc to register merlin documentation inside vim.

Misc: description of plugin's files

  • <SHARE_DIR>/ocamlmerlin/vim -- main vim plugin directory

    • plugin/merlin.vim -- sample configuration
    • autoload/
      • merlin.vim -- main vim script
      • merlin.py -- helper script needed by merlin.vim (has to be in the same directory)
    • syntax_checkers/
      -- integration with syntastic (ocaml or omlet)
      -- set g:syntastic_ocaml_checkers = ['merlin']
      -- or g:syntastic_omlet_checkers = ['merlin']
  • <SHARE_DIR>/ocamlmerlin/vimbufsync
    -- library needed by merlin vim mode to keep buffer synchronized

Emacs interface

merlin comes with an emacs interface (file: emacs/merlin.el) that implements a minor-mode that is supposed to be used on top of tuareg-mode.

All you need to do is add the following to your .emacs:

(push "<SHARE_DIR>/emacs/site-lisp" load-path) ; directory containing merlin.el
(setq merlin-command "<BIN_DIR>/ocamlmerlin")  ; needed only if ocamlmerlin not already in your PATH
(autoload 'merlin-mode "merlin" "Merlin mode" t)
(add-hook 'tuareg-mode-hook 'merlin-mode)
(add-hook 'caml-mode-hook 'merlin-mode)

merlin-mode will make use of auto-complete-mode (available by package.el and the MELPA repository) if is is installed.

Merlin project

When loading a ml file in your editor, merlin will search for a file named .merlin in the same directory as the file or in parent directories.

The ".merlin" allows you to integrate merlin with your project. Each line of this file begin with a directive name followed by zero, one or more arguments:

  • S <src-dir>: add a source directory, used to find *.ml / *.mli files
  • B <build-dir>: add a build directory, used to find *.cmi files
  • PKG <findlib-pkg>: load a findlib package and its dependencies in merlin
  • FLG <flag-list>: activates the given flags, the same effect can be achieved by lauching ocamlmerlin with those flags. For a full list of flags run ocamlmerlin -help.
  • REC : inform merlin that it should look for .merlin files in parent directories, and execute the directives it find in those files as well as the ones in the current file.
  • EXT <extension-list>: (undocumented)

Directory are either absolute or relative to the directory containing ".merlin" file.

Extensions

Merlin doesn't support (nor plan to support) Camlp4. However, a few common extensions are hardcoded:

Lwt

Support for lwt, match_lwt, try_lwt / finally, for_lwt, while_lwt, if_lwt and raise_lwt.
You need to add lwt package (with ":Use lwt" or "PKG lwt" in .merlin) for this to work, and it may be necessary to reload buffer for this change to take effect.

type-conv

A few syntax extensions based on type-conv are supported as well. Namely :

  • sexplib.syntax
  • binprot.syntax
  • fieldslib.syntax
  • comparelib.syntax

Misc.

Other common extensions which are supported :

  • pa_ounit.syntax
  • pa_js.syntax

Screenshots

About

Context sensitive completion for Ocaml in Vim and Emacs

License:MIT License


Languages

Language:OCaml 97.6%Language:Emacs Lisp 1.3%Language:Python 0.6%Language:Vim Script 0.3%Language:TeX 0.1%Language:Shell 0.0%