Needed: OCaml 4, ocamlfind, ocamlbuild, yojson, menhir
Merlin requires OCaml >=4.00.1 (may work with newer versions, but it is tightly
bound to compiler internals).
Then ensures that "yojson" and "menhir" are installed and are registered in
ocamlfind.
$ ./configure
$ make
If you don't get any error in step above:
$ make install
Don't forget to checkout submodules after pulling/cloning:
$ git submodule init
$ git submodule update
Needed: opam,
OCaml 4.00.1 (can be installed via opam typing opam switch 4.00.1
).
Then, just do :
$ opam install merlin
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
Now you may be interested by Features and interaction with other plugins, Merlin project and Extensions sections.
Alternatively you can install vim support using Vundle. Add the following to your .vimrc
Bundle 'def-lkb/merlin', {'rtp' : 'vim/'}
Bundle 'def-lkb/vimbufsync'
Omnicompletion should be available out-of-box.
The documentation is accessible through :h merlin.txt
and should provide all
the necessary information on how to set-up merlin with other plugins (
Supertab,
neocomplcache,
syntastic).
It also lists, and explain, all the available commands.
-
$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
Merlin plugin now relies on another vim helper called vimbufsync. If you installed from opam and/or archive, just make sure that vimbufsync is in vim runtime path:
:set rtp+=$SHARE_DIR/ocamlmerlin/vimbufsync
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.
To get it working you only to load the file `emacs/merlin.el' of the distribution.
If you installed through opam, a good thing to do is:
(add-to-list 'load-path "~/.opam/4.00.1/share/emacs/site-lisp/")
(require 'merlin)
To use it, you will need
- json.el (available by package.el)
- auto-complete-mode (optional, available by package.el and the MELPA repository)
Once it is done, to enable merlin in a buffer, just type M-x merlin-mode. If you want merlin to be started on every ML buffer issue:
(add-hook 'tuareg-mode-hook 'merlin-mode)
merlin implements a locked zone like proofgeneral to know what merlin knows of the buffer. To advance or retract the locked zone to the point, use C-c C-RET. Note that retraction can go before the point in case the point is not at the end of the last definition. Lock zone is by default shown using a marker in the margin of the last line of it. The behaviour is controlled by the variable `merlin-display-lock-zone'.
Main keybindings:
-
C-c l allows you to load a findlib package inside merlin. For a project you should use a .merlin file
-
C-c C-t will show you the type of the expression under point. The behaviour of this is quite complex. It will:
-
try to find the node of the typed AST the current point is in, and returns this type. Further call to C-c C-t allow to go up (or down with a prefix argument) in the AST
-
try to type the ident under point within the local environment
-
try to type the ident under point within the local environment.
Moreover, C-u C-c C-t is used to type the region (if there is no selected AST node)
-
-
C-c C-x goes to the next error
-
C-c C-u refreshes merlin's cache (when you recompiled other files, might be handy)
-
C-c C-r retracts the whole buffer (useful when merlin seems confused)
-
C-c d will print the definition of the type of the expression underpoint if any. If the type is compliated (eg. 'a -> 'a option) it will print the definition of the codomain
Moreover, you have regular auto-completion (M-TAB by default) using completion-at-point. There is auto-complete integration you can enable by setting merlin-use-auto-complete-mode to t:
(setq merlin-use-auto-complete-mode t)
When loading a ml file in your editor, merlin mode will search a file named .merlin in the same directory or in parent directories.
The ".merlin" allows you to integrate merlin with your project. Each line of this file begin with a command name followed by one argument:
- 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
Directory are either absolute or relative to the directory containing ".merlin" file.
Merlin doesn't support (nor plan to support) Camlp4. However, a few common extensions are hardcoded:
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.
A few syntax extensions based on type-conv are supported as well. Namely :
- sexplib.syntax
- binprot.syntax