" Mike Leary
" Markus Mottl
" Pierre Vittet
" Stefano Zacchiroli
" Vincent Aravantinos
" URL: http://www.ocaml.info/vim/ftplugin/ocaml.vim
" Last Change:
" 2013 Jul 26 - load default compiler settings (MM)
" 2013 Jul 24 - removed superfluous efm-setting (MM)
" 2013 Jul 22 - applied fixes supplied by Hirotaka Hamada (MM)
" 2013 Mar 15 - Improved error format (MM)
if exists("b:did_ftplugin")
finish
endif
let b:did_ftplugin=1
" Use standard compiler settings unless user wants otherwise
if !exists("current_compiler")
:compiler ocaml
endif
" some macro
if exists('*fnameescape')
function! s:Fnameescape(s)
return fnameescape(a:s)
endfun
else
function! s:Fnameescape(s)
return escape(a:s," \t\n*?[{`$\\%#'\"|!<")
endfun
endif
" Error handling -- helps moving where the compiler wants you to go
let s:cposet=&cpoptions
set cpo&vim
" Add mappings, unless the user didn't want this.
if !exists("no_plugin_maps") && !exists("no_ocaml_maps")
" (un)commenting
if !hasmapto('Comment')
nmap c LUncomOn
xmap c BUncomOn
nmap C LUncomOff
xmap C BUncomOff
endif
nnoremap LUncomOn gI(* *)
nnoremap LUncomOff :s/^(\* \(.*\) \*)/\1/:noh
xnoremap BUncomOn :'<,'>`0i(*`>o0i*)`<
xnoremap BUncomOff :'<,'>`dd`<
nmap s OCamlSwitchEdit
nmap S OCamlSwitchNewWin
nmap t OCamlPrintType
xmap t OCamlPrintType
endif
" Let % jump between structure elements (due to Issac Trotts)
let b:mw = ''
let b:mw = b:mw . ',\:\:\(\\|;;\)'
let b:mw = b:mw . ',\:\:\'
let b:mw = b:mw . ',\<\(for\|while\)\>:\:\,'
let b:mw = b:mw . ',\<\(object\|sig\|struct\|begin\)\>:\'
let b:mw = b:mw . ',\<\(match\|try\)\>:\'
let b:match_words = b:mw
let b:match_ignorecase=0
" switching between interfaces (.mli) and implementations (.ml)
if !exists("g:did_ocaml_switch")
let g:did_ocaml_switch = 1
nnoremap OCamlSwitchEdit :call OCaml_switch(0)
nnoremap OCamlSwitchNewWin :call OCaml_switch(1)
fun OCaml_switch(newwin)
if (match(bufname(""), "\\.mli$") >= 0)
let fname = s:Fnameescape(substitute(bufname(""), "\\.mli$", ".ml", ""))
if (a:newwin == 1)
exec "new " . fname
else
exec "arge " . fname
endif
elseif (match(bufname(""), "\\.ml$") >= 0)
let fname = s:Fnameescape(bufname("")) . "i"
if (a:newwin == 1)
exec "new " . fname
else
exec "arge " . fname
endif
endif
endfun
endif
" Folding support
" Get the modeline because folding depends on indentation
let s:s = line2byte(line('.'))+col('.')-1
if search('^\s*(\*:o\?caml:')
let s:modeline = getline(".")
else
let s:modeline = ""
endif
if s:s > 0
exe 'goto' s:s
endif
" Get the indentation params
let s:m = matchstr(s:modeline,'default\s*=\s*\d\+')
if s:m != ""
let s:idef = matchstr(s:m,'\d\+')
elseif exists("g:omlet_indent")
let s:idef = g:omlet_indent
else
let s:idef = 2
endif
let s:m = matchstr(s:modeline,'struct\s*=\s*\d\+')
if s:m != ""
let s:i = matchstr(s:m,'\d\+')
elseif exists("g:omlet_indent_struct")
let s:i = g:omlet_indent_struct
else
let s:i = s:idef
endif
" Set the folding method
if exists("g:ocaml_folding")
setlocal foldmethod=expr
setlocal foldexpr=OMLetFoldLevel(v:lnum)
endif
let b:undo_ftplugin = "setlocal efm< foldmethod< foldexpr<"
\ . "| unlet! b:mw b:match_words b:match_ignorecase"
" - Only definitions below, executed once -------------------------------------
if exists("*OMLetFoldLevel")
finish
endif
function s:topindent(lnum)
let l = a:lnum
while l > 0
if getline(l) =~ '\s*\%(\\|\\|\