77" Vincent Aravantinos <[email protected] >88" URL: http://www.ocaml.info/vim/ftplugin/ocaml.vim
99" Last Change:
10- " 2012 Jan 15 - Bugfix :reloading .annot file does not close
11- " splitted view (Pierre Vittet)
12- " 2011 Nov 28 - Bugfix + support of multiple ml annotation file
13- " (Pierre Vittet)
14- " 2010 Jul 10 - Bugfix, thanks to Pat Rondon
15- " 2008 Jul 17 - Bugfix related to fnameescape (VA)
16- " 2013 Jul - moving errorformat into compiler/ocaml.vim Marc Weber
17- "
18- " Marc Weber's comment: This file may contain a lot of (very custom) stuff
19- " which eventually should be moved somewhere else ..
20- "
10+ " 2013 Jul 26 - load default compiler settings (MM)
11+ " 2013 Jul 24 - removed superfluous efm-setting (MM)
12+ " 2013 Jul 22 - applied fixes supplied by Hirotaka Hamada (MM)
13+ " 2013 Mar 15 - Improved error format (MM)
2114
2215if exists (" b:did_ftplugin" )
2316 finish
2417endif
2518let b: did_ftplugin= 1
2619
20+ " Use standard compiler settings unless user wants otherwise
21+ if ! exists (" current_compiler" )
22+ :compiler ocaml
23+ endif
24+
2725" some macro
2826if exists (' *fnameescape' )
2927 function ! s: Fnameescape (s )
@@ -44,19 +42,21 @@ if !exists("no_plugin_maps") && !exists("no_ocaml_maps")
4442 " (un)commenting
4543 if ! hasmapto (' <Plug>Comment' )
4644 nmap <buffer> <LocalLeader> c <Plug> LUncomOn
47- vmap <buffer> <LocalLeader> c <Plug> BUncomOn
45+ xmap <buffer> <LocalLeader> c <Plug> BUncomOn
4846 nmap <buffer> <LocalLeader> C <Plug> LUncomOff
49- vmap <buffer> <LocalLeader> C <Plug> BUncomOff
47+ xmap <buffer> <LocalLeader> C <Plug> BUncomOff
5048 endif
5149
52- nnoremap <buffer> <Plug> LUncomOn mz0i (* <ESC> $A *)<ESC> `z
50+ nnoremap <buffer> <Plug> LUncomOn gI (* <End> *)<ESC>
5351 nnoremap <buffer> <Plug> LUncomOff :s/^(\* \(.*\) \*)/\1/<CR> :noh<CR>
54- vnoremap <buffer> <Plug> BUncomOn <ESC> :'<,'><CR> `<O<ESC> 0i(*<ESC> `>o<ESC> 0i*)<ESC> `<
55- vnoremap <buffer> <Plug> BUncomOff <ESC> :'<,'><CR> `<dd`> dd`<
52+ xnoremap <buffer> <Plug> BUncomOn <ESC> :'<,'><CR> `<O<ESC> 0i(*<ESC> `>o<ESC> 0i*)<ESC> `<
53+ xnoremap <buffer> <Plug> BUncomOff <ESC> :'<,'><CR> `<dd`> dd`<
5654
57- if ! hasmapto (' <Plug>Abbrev' )
58- iabbrev <buffer> ASS (assert (0 = 1 ) (* XXX * ))
59- endif
55+ nmap <buffer> <LocalLeader> s <Plug> OCamlSwitchEdit
56+ nmap <buffer> <LocalLeader> S <Plug> OCamlSwitchNewWin
57+
58+ nmap <buffer> <LocalLeader> t <Plug> OCamlPrintType
59+ xmap <buffer> <LocalLeader> t <Plug> OCamlPrintType
6060endif
6161
6262" Let % jump between structure elements (due to Issac Trotts)
@@ -73,8 +73,8 @@ let b:match_ignorecase=0
7373" switching between interfaces (.mli) and implementations (.ml)
7474if ! exists (" g:did_ocaml_switch" )
7575 let g: did_ocaml_switch = 1
76- map <LocalLeader> s : call OCaml_switch(0)<CR>
77- map <LocalLeader> S : call OCaml_switch(1)<CR>
76+ nnoremap <Plug> OCamlSwitchEdit : <C-u> call OCaml_switch(0)<CR>
77+ nnoremap <Plug> OCamlSwitchNewWin : <C-u> call OCaml_switch(1)<CR>
7878 fun OCaml_switch (newwin)
7979 if (match (bufname (" " ), " \\ .mli$" ) >= 0 )
8080 let fname = s: Fnameescape (substitute (bufname (" " ), " \\ .mli$" , " .ml" , " " ))
@@ -131,6 +131,10 @@ if exists("g:ocaml_folding")
131131 setlocal foldexpr = OMLetFoldLevel (v: lnum )
132132endif
133133
134+ let b: undo_ftplugin = " setlocal efm< foldmethod< foldexpr<"
135+ \ . " | unlet! b:mw b:match_words b:match_ignorecase"
136+
137+
134138" - Only definitions below, executed once -------------------------------------
135139
136140if exists (" *OMLetFoldLevel" )
@@ -546,6 +550,19 @@ endfunction
546550 return s: Extract_type_data (s: Block_pattern (lin1,lin2,col1,col2), a: annot_file_name )
547551 endfun
548552
553+ " In: A string destined to be printed in the 'echo buffer'. It has line
554+ " break and 2 space at each line beginning.
555+ " Out: A string destined to be yanked, without space and double space.
556+ function s: unformat_ocaml_type (res )
557+ " Remove end of line.
558+ let res = substitute (a: res , " \n " , " " , " g" )
559+ " remove double space
560+ let res = substitute (res , " " , " " , " g" )
561+ " remove space at begining of string.
562+ let res = substitute (res , " ^ *" , " " , " g" )
563+ return res
564+ endfunction
565+
549566 " d. main
550567 " In: the current mode (eg. "visual", "normal", etc.)
551568 " After call: the type information is displayed
@@ -554,15 +571,19 @@ endfunction
554571 let annot_file_name = s: Fnameescape (expand (' %:t:r' )).' .annot'
555572 call s: Locate_annotation ()
556573 call s: Load_annotation (annot_file_name)
557- return s: Get_type (a: mode , annot_file_name)
574+ let res = s: Get_type (a: mode , annot_file_name)
575+ " Copy result in the unnamed buffer
576+ let @" = s: unformat_ocaml_type (res )
577+ return res
558578 endfun
559579 endif
560580
561581 if ! exists (" *Ocaml_get_type_or_not" )
562582 function Ocaml_get_type_or_not (mode )
563583 let t = reltime ()
564584 try
565- return Ocaml_get_type (a: mode )
585+ let res = Ocaml_get_type (a: mode )
586+ return res
566587 catch
567588 return " "
568589 endtry
@@ -590,8 +611,8 @@ endfunction
590611 endif
591612
592613" Maps
593- map <silent> <LocalLeader> t : call Ocaml_print_type("normal")<CR>
594- vmap <silent> <LocalLeader> t :<C-U> call Ocaml_print_type("visual")<CR> `<
614+ nnoremap <silent> <Plug> OCamlPrintType : <C-U> call Ocaml_print_type("normal")<CR>
615+ xnoremap <silent> <Plug> OCamlPrintType :<C-U> call Ocaml_print_type("visual")<CR> `<
595616
596617let &cpoptions = s: cposet
597618unlet s: cposet
0 commit comments