ocp-index
ocp-index is designed as a simple and light-weight documentation extractor for
OCaml, for command-line use or integrated in other tools (e.g. for
completion). It gathers information from .cmi (à la ocamlbrowser) and
.cmt/cmti files, including structure, location, type, and ocamldoc comments
when available.
Ressources
| ocp-index on Github | Latest sources in the official GIT repository |
Usage
ocp-index COMMAND params OPTIONS
Examples:
ocp-index type Module.identocp-index complete idenocp-index locate Module.identocp-index print Module.ident <format>
Options:
-Iinclude dirs / loaded libraries-Oconsider given module as open-Fopen the given module, not limiting to its exported interface--contextautomatically open/bind modules according to the given source file position.--rootspecify the root of the current project, for finding cmt files and source lookups. It's generally safe to let ocp-indent guess.output format:
--color,--show/--hideto control the kinds of idents to display--format FORMAT, display using the given format string:string contents examples %nname "map" %qqualified ident in context "List.map", "map" %pfull ident path "List.map" %kident kind "type", "val", "exception", "field( )"... %ttype ('a -> 'b) -> 'a list -> 'a list %docamldoc comment "Applies the function..." %lImplementation location "src/list.ml:83:0" %sInterface location "src/list.mli:51:0" %fFile of origin "_build/list.cmti" %iSummary List.map val ('a -> 'b) -> 'a list -> 'b list
Build
./configure
make
make install
See below to compile and install the optional ocp-browser.
Other tools
Emacs mode
A script ocp-index.el is included under tools/, and can be used together
with tuareg-mode or ocaml-mode and
auto-complete (packaged as
auto-complete-el in Debian) to get completions and types in a popup menu.
You can run the script tools/emacs-setup.sh to get hints on the configuration
of emacs for ocp-index (it won't modify any files). Adding the following
line to your .emacs:
(add-to-list 'load-path "/path/to/ocp-index.el/")
(require 'ocp-index)
Will give you:
C-c TABto auto-complete ((global-set-key (kbd "KEY") 'auto-complete)to add your own binding)C-c tto print the type of the identifier under cursorC-c ;to jump to the definition of the identifier under cursor (useC-c C-;to do that in the current window)C-c :to jump to the interface of the identifier under cursor (useC-c C-:to do that in the current window)C-c /to lookup all occurences of the ident under point in the current project (ocp-grep)
See M-x customize ocp-index for more options.
Vim
A script ocp-index.vim, contributed by Daisuke Inajima, is available under
tools. It supports:
- omni completion
- type information printing
- jump to definitions
To use, add vim-ocp-index directory to runtimepath:
:set runtimepath^=/path/to/ocp-index.vim
Then create your own after/ftplugin/ocaml.vim to override vim's
builtin ocaml settings::
if exists('b:did_ftplugin_after')
finish
endif
let b:did_ftplugin_after = 1
call ocpindex#init()
nmap <buffer> K <Plug>(ocpindex-echo-type)
nmap <buffer> <C-]> <Plug>(ocpindex-jump)
nmap <buffer> <C-t> <Plug>(ocpindex-jump-back)
You get:
KEcho type information of the identifier under the cursorC-]Push the current position to the jump stack and jump to the definition of the identifier under the cursorC-tPop the previons position from the jump stack and jump back thereC-x C-oOmni completion
If needed, you can specify ocp-index path explicitly: let g:ocpindex_program = "/path/to/ocp-index"
Sublime Text
There is a binding written by Peter Zotov on Github
ocp-browser

A nice terminal interface leveraging the power of ocp-index is included. It provides a quick way to browser external and in-project interfaces. Thanks to the contribution from Gabriel Radanne.
To compile it, make sure that you have lambda-term installed, e.g. opam install
lambda-term ocp-index.