annotate runtime/ftplugin/ocaml.vim @ 29448:8f1e16995118 v9.0.0066

patch 9.0.0066: switching window uneccarily when getting buffer options Commit: https://github.com/vim/vim/commit/cd6ad6439da2ee2d1a8a6934c9d69e9c2664ba55 Author: zeertzjq <zeertzjq@outlook.com> Date: Mon Jul 25 12:28:09 2022 +0100 patch 9.0.0066: switching window uneccarily when getting buffer options Problem: Switching window uneccarily when getting buffer options. Solution: Do not switch window when getting buffer options. (closes https://github.com/vim/vim/issues/10767)
author Bram Moolenaar <Bram@vim.org>
date Mon, 25 Jul 2022 13:30:05 +0200
parents 11b656e74444
children 7c7432a53a6c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
557
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
1 " Language: OCaml
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
2 " Maintainer: David Baelde <firstname.name@ens-lyon.org>
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
3 " Mike Leary <leary@nwlink.com>
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
4 " Markus Mottl <markus.mottl@gmail.com>
3312
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 3224
diff changeset
5 " Pierre Vittet <pierre-vittet@pvittet.com>
557
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
6 " Stefano Zacchiroli <zack@bononia.it>
1620
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
7 " Vincent Aravantinos <firstname.name@imag.fr>
23466
15fa3923cc49 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 17261
diff changeset
8 " URL: https://github.com/ocaml/vim-ocaml
3312
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 3224
diff changeset
9 " Last Change:
17261
432714f5c0f7 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 16610
diff changeset
10 " 2013 Oct 27 - Added commentstring (MM)
5244
eb7ce2918a03 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 5055
diff changeset
11 " 2013 Jul 26 - load default compiler settings (MM)
eb7ce2918a03 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 5055
diff changeset
12 " 2013 Jul 24 - removed superfluous efm-setting (MM)
eb7ce2918a03 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 5055
diff changeset
13 " 2013 Jul 22 - applied fixes supplied by Hirotaka Hamada (MM)
3312
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 3224
diff changeset
14
826
1cdd2661f34c updated for version 7.0d01
vimboss
parents: 659
diff changeset
15 if exists("b:did_ftplugin")
1cdd2661f34c updated for version 7.0d01
vimboss
parents: 659
diff changeset
16 finish
1cdd2661f34c updated for version 7.0d01
vimboss
parents: 659
diff changeset
17 endif
557
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
18 let b:did_ftplugin=1
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
19
5244
eb7ce2918a03 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 5055
diff changeset
20 " Use standard compiler settings unless user wants otherwise
eb7ce2918a03 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 5055
diff changeset
21 if !exists("current_compiler")
eb7ce2918a03 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 5055
diff changeset
22 :compiler ocaml
eb7ce2918a03 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 5055
diff changeset
23 endif
eb7ce2918a03 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 5055
diff changeset
24
1698
f4f8014d516e updated for version 7.2c-000
vimboss
parents: 1620
diff changeset
25 " some macro
f4f8014d516e updated for version 7.2c-000
vimboss
parents: 1620
diff changeset
26 if exists('*fnameescape')
f4f8014d516e updated for version 7.2c-000
vimboss
parents: 1620
diff changeset
27 function! s:Fnameescape(s)
f4f8014d516e updated for version 7.2c-000
vimboss
parents: 1620
diff changeset
28 return fnameescape(a:s)
f4f8014d516e updated for version 7.2c-000
vimboss
parents: 1620
diff changeset
29 endfun
f4f8014d516e updated for version 7.2c-000
vimboss
parents: 1620
diff changeset
30 else
f4f8014d516e updated for version 7.2c-000
vimboss
parents: 1620
diff changeset
31 function! s:Fnameescape(s)
f4f8014d516e updated for version 7.2c-000
vimboss
parents: 1620
diff changeset
32 return escape(a:s," \t\n*?[{`$\\%#'\"|!<")
f4f8014d516e updated for version 7.2c-000
vimboss
parents: 1620
diff changeset
33 endfun
f4f8014d516e updated for version 7.2c-000
vimboss
parents: 1620
diff changeset
34 endif
f4f8014d516e updated for version 7.2c-000
vimboss
parents: 1620
diff changeset
35
557
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
36 " Error handling -- helps moving where the compiler wants you to go
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
37 let s:cposet=&cpoptions
3224
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2292
diff changeset
38 set cpo&vim
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
39
17261
432714f5c0f7 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 16610
diff changeset
40 " Comment string
23466
15fa3923cc49 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 17261
diff changeset
41 setlocal comments=sr:(*\ ,mb:\ ,ex:*)
15fa3923cc49 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 17261
diff changeset
42 setlocal comments^=sr:(**,mb:\ \ ,ex:*)
17261
432714f5c0f7 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 16610
diff changeset
43 setlocal commentstring=(*%s*)
432714f5c0f7 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 16610
diff changeset
44
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
45 " Add mappings, unless the user didn't want this.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
46 if !exists("no_plugin_maps") && !exists("no_ocaml_maps")
557
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
47 " (un)commenting
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
48 if !hasmapto('<Plug>Comment')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
49 nmap <buffer> <LocalLeader>c <Plug>LUncomOn
5244
eb7ce2918a03 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 5055
diff changeset
50 xmap <buffer> <LocalLeader>c <Plug>BUncomOn
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
51 nmap <buffer> <LocalLeader>C <Plug>LUncomOff
5244
eb7ce2918a03 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 5055
diff changeset
52 xmap <buffer> <LocalLeader>C <Plug>BUncomOff
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
53 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
54
5244
eb7ce2918a03 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 5055
diff changeset
55 nnoremap <buffer> <Plug>LUncomOn gI(* <End> *)<ESC>
557
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
56 nnoremap <buffer> <Plug>LUncomOff :s/^(\* \(.*\) \*)/\1/<CR>:noh<CR>
5244
eb7ce2918a03 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 5055
diff changeset
57 xnoremap <buffer> <Plug>BUncomOn <ESC>:'<,'><CR>`<O<ESC>0i(*<ESC>`>o<ESC>0i*)<ESC>`<
eb7ce2918a03 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 5055
diff changeset
58 xnoremap <buffer> <Plug>BUncomOff <ESC>:'<,'><CR>`<dd`>dd`<
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
59
5244
eb7ce2918a03 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 5055
diff changeset
60 nmap <buffer> <LocalLeader>s <Plug>OCamlSwitchEdit
eb7ce2918a03 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 5055
diff changeset
61 nmap <buffer> <LocalLeader>S <Plug>OCamlSwitchNewWin
eb7ce2918a03 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 5055
diff changeset
62
eb7ce2918a03 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 5055
diff changeset
63 nmap <buffer> <LocalLeader>t <Plug>OCamlPrintType
eb7ce2918a03 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 5055
diff changeset
64 xmap <buffer> <LocalLeader>t <Plug>OCamlPrintType
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
65 endif
20
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 7
diff changeset
66
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 7
diff changeset
67 " Let % jump between structure elements (due to Issac Trotts)
17261
432714f5c0f7 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 16610
diff changeset
68 let b:mw = '\<let\>:\<and\>:\(\<in\>\|;;\)'
557
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
69 let b:mw = b:mw . ',\<if\>:\<then\>:\<else\>'
17261
432714f5c0f7 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 16610
diff changeset
70 let b:mw = b:mw . ',\<\(for\|while\)\>:\<do\>:\<done\>'
557
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
71 let b:mw = b:mw . ',\<\(object\|sig\|struct\|begin\)\>:\<end\>'
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
72 let b:mw = b:mw . ',\<\(match\|try\)\>:\<with\>'
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
73 let b:match_words = b:mw
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
74
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
75 let b:match_ignorecase=0
20
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 7
diff changeset
76
17261
432714f5c0f7 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 16610
diff changeset
77 function! s:OcpGrep(bang,args) abort
432714f5c0f7 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 16610
diff changeset
78 let grepprg = &l:grepprg
432714f5c0f7 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 16610
diff changeset
79 let grepformat = &l:grepformat
432714f5c0f7 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 16610
diff changeset
80 let shellpipe = &shellpipe
432714f5c0f7 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 16610
diff changeset
81 try
432714f5c0f7 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 16610
diff changeset
82 let &l:grepprg = "ocp-grep -c never"
432714f5c0f7 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 16610
diff changeset
83 setlocal grepformat=%f:%l:%m
432714f5c0f7 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 16610
diff changeset
84 if &shellpipe ==# '2>&1| tee' || &shellpipe ==# '|& tee'
432714f5c0f7 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 16610
diff changeset
85 let &shellpipe = "| tee"
432714f5c0f7 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 16610
diff changeset
86 endif
432714f5c0f7 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 16610
diff changeset
87 execute 'grep! '.a:args
432714f5c0f7 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 16610
diff changeset
88 if empty(a:bang) && !empty(getqflist())
432714f5c0f7 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 16610
diff changeset
89 return 'cfirst'
432714f5c0f7 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 16610
diff changeset
90 else
432714f5c0f7 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 16610
diff changeset
91 return ''
432714f5c0f7 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 16610
diff changeset
92 endif
432714f5c0f7 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 16610
diff changeset
93 finally
432714f5c0f7 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 16610
diff changeset
94 let &l:grepprg = grepprg
432714f5c0f7 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 16610
diff changeset
95 let &l:grepformat = grepformat
432714f5c0f7 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 16610
diff changeset
96 let &shellpipe = shellpipe
432714f5c0f7 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 16610
diff changeset
97 endtry
432714f5c0f7 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 16610
diff changeset
98 endfunction
432714f5c0f7 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 16610
diff changeset
99 command! -bar -bang -complete=file -nargs=+ Ocpgrep exe s:OcpGrep(<q-bang>, <q-args>)
432714f5c0f7 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 16610
diff changeset
100
20
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 7
diff changeset
101 " switching between interfaces (.mli) and implementations (.ml)
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 7
diff changeset
102 if !exists("g:did_ocaml_switch")
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 7
diff changeset
103 let g:did_ocaml_switch = 1
5244
eb7ce2918a03 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 5055
diff changeset
104 nnoremap <Plug>OCamlSwitchEdit :<C-u>call OCaml_switch(0)<CR>
eb7ce2918a03 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 5055
diff changeset
105 nnoremap <Plug>OCamlSwitchNewWin :<C-u>call OCaml_switch(1)<CR>
20
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 7
diff changeset
106 fun OCaml_switch(newwin)
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 7
diff changeset
107 if (match(bufname(""), "\\.mli$") >= 0)
1698
f4f8014d516e updated for version 7.2c-000
vimboss
parents: 1620
diff changeset
108 let fname = s:Fnameescape(substitute(bufname(""), "\\.mli$", ".ml", ""))
20
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 7
diff changeset
109 if (a:newwin == 1)
557
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
110 exec "new " . fname
20
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 7
diff changeset
111 else
557
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
112 exec "arge " . fname
20
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 7
diff changeset
113 endif
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 7
diff changeset
114 elseif (match(bufname(""), "\\.ml$") >= 0)
1698
f4f8014d516e updated for version 7.2c-000
vimboss
parents: 1620
diff changeset
115 let fname = s:Fnameescape(bufname("")) . "i"
20
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 7
diff changeset
116 if (a:newwin == 1)
557
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
117 exec "new " . fname
20
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 7
diff changeset
118 else
557
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
119 exec "arge " . fname
20
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 7
diff changeset
120 endif
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 7
diff changeset
121 endif
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 7
diff changeset
122 endfun
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 7
diff changeset
123 endif
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 7
diff changeset
124
557
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
125 " Folding support
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
126
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
127 " Get the modeline because folding depends on indentation
17261
432714f5c0f7 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 16610
diff changeset
128 let lnum = search('^\s*(\*:o\?caml:', 'n')
432714f5c0f7 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 16610
diff changeset
129 let s:modeline = lnum? getline(lnum): ""
557
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
130
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
131 " Get the indentation params
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
132 let s:m = matchstr(s:modeline,'default\s*=\s*\d\+')
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
133 if s:m != ""
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
134 let s:idef = matchstr(s:m,'\d\+')
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
135 elseif exists("g:omlet_indent")
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
136 let s:idef = g:omlet_indent
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
137 else
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
138 let s:idef = 2
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
139 endif
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
140 let s:m = matchstr(s:modeline,'struct\s*=\s*\d\+')
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
141 if s:m != ""
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
142 let s:i = matchstr(s:m,'\d\+')
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
143 elseif exists("g:omlet_indent_struct")
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
144 let s:i = g:omlet_indent_struct
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
145 else
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
146 let s:i = s:idef
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
147 endif
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
148
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
149 " Set the folding method
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
150 if exists("g:ocaml_folding")
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
151 setlocal foldmethod=expr
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
152 setlocal foldexpr=OMLetFoldLevel(v:lnum)
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
153 endif
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
154
5244
eb7ce2918a03 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 5055
diff changeset
155 let b:undo_ftplugin = "setlocal efm< foldmethod< foldexpr<"
eb7ce2918a03 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 5055
diff changeset
156 \ . "| unlet! b:mw b:match_words b:match_ignorecase"
eb7ce2918a03 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 5055
diff changeset
157
eb7ce2918a03 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 5055
diff changeset
158
557
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
159 " - Only definitions below, executed once -------------------------------------
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
160
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
161 if exists("*OMLetFoldLevel")
23737
34b4eb3a8458 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 23466
diff changeset
162 let &cpoptions = s:cposet
34b4eb3a8458 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 23466
diff changeset
163 unlet s:cposet
557
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
164 finish
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
165 endif
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
166
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
167 function s:topindent(lnum)
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
168 let l = a:lnum
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
169 while l > 0
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
170 if getline(l) =~ '\s*\%(\<struct\>\|\<sig\>\|\<object\>\)'
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
171 return indent(l)
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
172 endif
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
173 let l = l-1
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
174 endwhile
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
175 return -s:i
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
176 endfunction
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
177
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
178 function OMLetFoldLevel(l)
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
179
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
180 " This is for not merging blank lines around folds to them
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
181 if getline(a:l) !~ '\S'
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
182 return -1
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
183 endif
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
184
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
185 " We start folds for modules, classes, and every toplevel definition
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
186 if getline(a:l) =~ '^\s*\%(\<val\>\|\<module\>\|\<class\>\|\<type\>\|\<method\>\|\<initializer\>\|\<inherit\>\|\<exception\>\|\<external\>\)'
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
187 exe 'return ">' (indent(a:l)/s:i)+1 '"'
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
188 endif
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
189
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
190 " Toplevel let are detected thanks to the indentation
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
191 if getline(a:l) =~ '^\s*let\>' && indent(a:l) == s:i+s:topindent(a:l)
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
192 exe 'return ">' (indent(a:l)/s:i)+1 '"'
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
193 endif
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
194
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
195 " We close fold on end which are associated to struct, sig or object.
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
196 " We use syntax information to do that.
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
197 if getline(a:l) =~ '^\s*end\>' && synIDattr(synID(a:l, indent(a:l)+1, 0), "name") != "ocamlKeyword"
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
198 return (indent(a:l)/s:i)+1
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
199 endif
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
200
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
201 " Folds end on ;;
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
202 if getline(a:l) =~ '^\s*;;'
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
203 exe 'return "<' (indent(a:l)/s:i)+1 '"'
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
204 endif
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
205
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
206 " Comments around folds aren't merged to them.
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
207 if synIDattr(synID(a:l, indent(a:l)+1, 0), "name") == "ocamlComment"
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
208 return -1
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
209 endif
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
210
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
211 return '='
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
212 endfunction
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
213
1620
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
214 " Vim support for OCaml .annot files
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
215 "
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
216 " Last Change: 2007 Jul 17
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
217 " Maintainer: Vincent Aravantinos <vincent.aravantinos@gmail.com>
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
218 " License: public domain
20
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 7
diff changeset
219 "
1620
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
220 " Originally inspired by 'ocaml-dtypes.vim' by Stefano Zacchiroli.
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
221 " The source code is quite radically different for we not use python anymore.
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
222 " However this plugin should have the exact same behaviour, that's why the
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
223 " following lines are the quite exact copy of Stefano's original plugin :
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
224 "
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
225 " <<
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
226 " Executing Ocaml_print_type(<mode>) function will display in the Vim bottom
20
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 7
diff changeset
227 " line(s) the type of an ocaml value getting it from the corresponding .annot
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 7
diff changeset
228 " file (if any). If Vim is in visual mode, <mode> should be "visual" and the
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 7
diff changeset
229 " selected ocaml value correspond to the highlighted text, otherwise (<mode>
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 7
diff changeset
230 " can be anything else) it corresponds to the literal found at the current
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 7
diff changeset
231 " cursor position.
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 7
diff changeset
232 "
1620
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
233 " Typing '<LocalLeader>t' (LocalLeader defaults to '\', see :h LocalLeader)
3224
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2292
diff changeset
234 " will cause " Ocaml_print_type function to be invoked with the right
1620
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
235 " argument depending on the current mode (visual or not).
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
236 " >>
20
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 7
diff changeset
237 "
1620
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
238 " If you find something not matching this behaviour, please signal it.
20
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 7
diff changeset
239 "
1620
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
240 " Differences are:
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
241 " - no need for python support
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
242 " + plus : more portable
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
243 " + minus: no more lazy parsing, it looks very fast however
3224
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2292
diff changeset
244 "
1620
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
245 " - ocamlbuild support, ie.
3224
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2292
diff changeset
246 " + the plugin finds the _build directory and looks for the
1620
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
247 " corresponding file inside;
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
248 " + if the user decides to change the name of the _build directory thanks
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
249 " to the '-build-dir' option of ocamlbuild, the plugin will manage in
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
250 " most cases to find it out (most cases = if the source file has a unique
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
251 " name among your whole project);
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
252 " + if ocamlbuild is not used, the usual behaviour holds; ie. the .annot
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
253 " file should be in the same directory as the source file;
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
254 " + for vim plugin programmers:
3224
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2292
diff changeset
255 " the variable 'b:_build_dir' contains the inferred path to the build
1620
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
256 " directory, even if this one is not named '_build'.
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
257 "
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
258 " Bonus :
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
259 " - latin1 accents are handled
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
260 " - lists are handled, even on multiple lines, you don't need the visual mode
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
261 " (the cursor must be on the first bracket)
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
262 " - parenthesized expressions, arrays, and structures (ie. '(...)', '[|...|]',
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
263 " and '{...}') are handled the same way
20
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 7
diff changeset
264
1620
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
265 " Copied from Stefano's original plugin :
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
266 " <<
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
267 " .annot ocaml file representation
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
268 "
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
269 " File format (copied verbatim from caml-types.el)
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
270 "
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
271 " file ::= block *
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
272 " block ::= position <SP> position <LF> annotation *
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
273 " position ::= filename <SP> num <SP> num <SP> num
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
274 " annotation ::= keyword open-paren <LF> <SP> <SP> data <LF> close-paren
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
275 "
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
276 " <SP> is a space character (ASCII 0x20)
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
277 " <LF> is a line-feed character (ASCII 0x0A)
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
278 " num is a sequence of decimal digits
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
279 " filename is a string with the lexical conventions of O'Caml
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
280 " open-paren is an open parenthesis (ASCII 0x28)
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
281 " close-paren is a closed parenthesis (ASCII 0x29)
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
282 " data is any sequence of characters where <LF> is always followed by
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
283 " at least two space characters.
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
284 "
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
285 " - in each block, the two positions are respectively the start and the
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
286 " end of the range described by the block.
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
287 " - in a position, the filename is the name of the file, the first num
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
288 " is the line number, the second num is the offset of the beginning
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
289 " of the line, the third num is the offset of the position itself.
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
290 " - the char number within the line is the difference between the third
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
291 " and second nums.
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
292 "
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
293 " For the moment, the only possible keyword is \"type\"."
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
294 " >>
20
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 7
diff changeset
295
1698
f4f8014d516e updated for version 7.2c-000
vimboss
parents: 1620
diff changeset
296
1620
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
297 " 1. Finding the annotation file even if we use ocamlbuild
20
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 7
diff changeset
298
1620
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
299 " In: two strings representing paths
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
300 " Out: one string representing the common prefix between the two paths
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
301 function! s:Find_common_path (p1,p2)
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
302 let temp = a:p2
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
303 while matchstr(a:p1,temp) == ''
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
304 let temp = substitute(temp,'/[^/]*$','','')
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
305 endwhile
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
306 return temp
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
307 endfun
20
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 7
diff changeset
308
1620
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
309 " After call:
3312
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 3224
diff changeset
310 "
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 3224
diff changeset
311 " Following information have been put in s:annot_file_list, using
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 3224
diff changeset
312 " annot_file_name name as key:
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 3224
diff changeset
313 " - annot_file_path :
1620
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
314 " path to the .annot file corresponding to the
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
315 " source file (dealing with ocamlbuild stuff)
3312
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 3224
diff changeset
316 " - _build_path:
1620
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
317 " path to the build directory even if this one is
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
318 " not named '_build'
3312
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 3224
diff changeset
319 " - date_of_last annot:
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 3224
diff changeset
320 " Set to 0 until we load the file. It contains the
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 3224
diff changeset
321 " date at which the file has been loaded.
1620
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
322 function! s:Locate_annotation()
3312
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 3224
diff changeset
323 let annot_file_name = s:Fnameescape(expand('%:t:r')).'.annot'
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 3224
diff changeset
324 if !exists ("s:annot_file_list[annot_file_name]")
1698
f4f8014d516e updated for version 7.2c-000
vimboss
parents: 1620
diff changeset
325 silent exe 'cd' s:Fnameescape(expand('%:p:h'))
1620
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
326 " 1st case : the annot file is in the same directory as the buffer (no ocamlbuild)
3312
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 3224
diff changeset
327 let annot_file_path = findfile(annot_file_name,'.')
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 3224
diff changeset
328 if annot_file_path != ''
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 3224
diff changeset
329 let annot_file_path = getcwd().'/'.annot_file_path
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 3224
diff changeset
330 let _build_path = ''
1620
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
331 else
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
332 " 2nd case : the buffer and the _build directory are in the same directory
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
333 " ..
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
334 " / \
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
335 " / \
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
336 " _build .ml
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
337 "
3312
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 3224
diff changeset
338 let _build_path = finddir('_build','.')
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 3224
diff changeset
339 if _build_path != ''
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 3224
diff changeset
340 let _build_path = getcwd().'/'._build_path
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 3224
diff changeset
341 let annot_file_path = findfile(annot_file_name,'_build')
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 3224
diff changeset
342 if annot_file_path != ''
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 3224
diff changeset
343 let annot_file_path = getcwd().'/'.annot_file_path
1620
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
344 endif
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
345 else
3224
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2292
diff changeset
346 " 3rd case : the _build directory is in a directory higher in the file hierarchy
1620
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
347 " (it can't be deeper by ocamlbuild requirements)
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
348 " ..
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
349 " / \
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
350 " / \
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
351 " _build ...
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
352 " \
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
353 " \
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
354 " .ml
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
355 "
3312
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 3224
diff changeset
356 let _build_path = finddir('_build',';')
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 3224
diff changeset
357 if _build_path != ''
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 3224
diff changeset
358 let project_path = substitute(_build_path,'/_build$','','')
1698
f4f8014d516e updated for version 7.2c-000
vimboss
parents: 1620
diff changeset
359 let path_relative_to_project = s:Fnameescape(substitute(expand('%:p:h'),project_path.'/','',''))
3312
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 3224
diff changeset
360 let annot_file_path = findfile(annot_file_name,project_path.'/_build/'.path_relative_to_project)
1620
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
361 else
3312
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 3224
diff changeset
362 let annot_file_path = findfile(annot_file_name,'**')
1620
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
363 "4th case : what if the user decided to change the name of the _build directory ?
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
364 " -> we relax the constraints, it should work in most cases
3312
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 3224
diff changeset
365 if annot_file_path != ''
1620
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
366 " 4a. we suppose the renamed _build directory is in the current directory
3312
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 3224
diff changeset
367 let _build_path = matchstr(annot_file_path,'^[^/]*')
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 3224
diff changeset
368 if annot_file_path != ''
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 3224
diff changeset
369 let annot_file_path = getcwd().'/'.annot_file_path
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 3224
diff changeset
370 let _build_path = getcwd().'/'._build_path
1620
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
371 endif
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
372 else
3312
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 3224
diff changeset
373 let annot_file_name = ''
25773
11b656e74444 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 23737
diff changeset
374 "(Pierre Vittet: I have commented 4b because this was crashing
3312
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 3224
diff changeset
375 "my vim (it produced infinite loop))
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 3224
diff changeset
376 "
1620
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
377 " 4b. anarchy : the renamed _build directory may be higher in the hierarchy
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
378 " this will work if the file for which we are looking annotations has a unique name in the whole project
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
379 " if this is not the case, it may still work, but no warranty here
3312
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 3224
diff changeset
380 "let annot_file_path = findfile(annot_file_name,'**;')
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 3224
diff changeset
381 "let project_path = s:Find_common_path(annot_file_path,expand('%:p:h'))
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 3224
diff changeset
382 "let _build_path = matchstr(annot_file_path,project_path.'/[^/]*')
1620
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
383 endif
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
384 endif
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
385 endif
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
386 endif
20
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 7
diff changeset
387
3312
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 3224
diff changeset
388 if annot_file_path == ''
1620
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
389 throw 'E484: no annotation file found'
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
390 endif
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
391
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
392 silent exe 'cd' '-'
3312
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 3224
diff changeset
393 let s:annot_file_list[annot_file_name]= [annot_file_path, _build_path, 0]
1620
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
394 endif
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
395 endfun
20
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 7
diff changeset
396
23466
15fa3923cc49 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 17261
diff changeset
397 " This variable contains a dictionary of lists. Each element of the dictionary
15fa3923cc49 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 17261
diff changeset
398 " represents an annotation system. An annotation system is a list with:
15fa3923cc49 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 17261
diff changeset
399 " - annotation file name as its key
3312
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 3224
diff changeset
400 " - annotation file path as first element of the contained list
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 3224
diff changeset
401 " - build path as second element of the contained list
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 3224
diff changeset
402 " - annot_file_last_mod (contain the date of .annot file) as third element
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 3224
diff changeset
403 let s:annot_file_list = {}
1620
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
404
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
405 " 2. Finding the type information in the annotation file
3224
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2292
diff changeset
406
1620
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
407 " a. The annotation file is opened in vim as a buffer that
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
408 " should be (almost) invisible to the user.
20
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 7
diff changeset
409
1620
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
410 " After call:
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
411 " The current buffer is now the one containing the .annot file.
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
412 " We manage to keep all this hidden to the user's eye.
3312
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 3224
diff changeset
413 function! s:Enter_annotation_buffer(annot_file_path)
1620
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
414 let s:current_pos = getpos('.')
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
415 let s:current_hidden = &l:hidden
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
416 set hidden
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
417 let s:current_buf = bufname('%')
3312
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 3224
diff changeset
418 if bufloaded(a:annot_file_path)
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 3224
diff changeset
419 silent exe 'keepj keepalt' 'buffer' s:Fnameescape(a:annot_file_path)
1620
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
420 else
3312
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 3224
diff changeset
421 silent exe 'keepj keepalt' 'view' s:Fnameescape(a:annot_file_path)
1620
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
422 endif
3312
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 3224
diff changeset
423 call setpos(".", [0, 0 , 0 , 0])
1620
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
424 endfun
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
425
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
426 " After call:
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
427 " The original buffer has been restored in the exact same state as before.
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
428 function! s:Exit_annotation_buffer()
1698
f4f8014d516e updated for version 7.2c-000
vimboss
parents: 1620
diff changeset
429 silent exe 'keepj keepalt' 'buffer' s:Fnameescape(s:current_buf)
1620
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
430 let &l:hidden = s:current_hidden
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
431 call setpos('.',s:current_pos)
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
432 endfun
20
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 7
diff changeset
433
1620
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
434 " After call:
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
435 " The annot file is loaded and assigned to a buffer.
3224
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2292
diff changeset
436 " This also handles the modification date of the .annot file, eg. after a
3312
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 3224
diff changeset
437 " compilation (return an updated annot_file_list).
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 3224
diff changeset
438 function! s:Load_annotation(annot_file_name)
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 3224
diff changeset
439 let annot = s:annot_file_list[a:annot_file_name]
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 3224
diff changeset
440 let annot_file_path = annot[0]
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 3224
diff changeset
441 let annot_file_last_mod = 0
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 3224
diff changeset
442 if exists("annot[2]")
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 3224
diff changeset
443 let annot_file_last_mod = annot[2]
1620
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
444 endif
3312
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 3224
diff changeset
445 if bufloaded(annot_file_path) && annot_file_last_mod < getftime(annot_file_path)
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 3224
diff changeset
446 " if there is a more recent file
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 3224
diff changeset
447 let nr = bufnr(annot_file_path)
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 3224
diff changeset
448 silent exe 'keepj keepalt' 'bunload' nr
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 3224
diff changeset
449 endif
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 3224
diff changeset
450 if !bufloaded(annot_file_path)
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 3224
diff changeset
451 call s:Enter_annotation_buffer(annot_file_path)
1620
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
452 setlocal nobuflisted
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
453 setlocal bufhidden=hide
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
454 setlocal noswapfile
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
455 setlocal buftype=nowrite
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
456 call s:Exit_annotation_buffer()
3312
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 3224
diff changeset
457 let annot[2] = getftime(annot_file_path)
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 3224
diff changeset
458 " List updated with the new date
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 3224
diff changeset
459 let s:annot_file_list[a:annot_file_name] = annot
1620
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
460 endif
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
461 endfun
3224
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2292
diff changeset
462
1620
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
463 "b. 'search' and 'match' work to find the type information
3224
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2292
diff changeset
464
25773
11b656e74444 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 23737
diff changeset
465 "In: - lin1,col1: position of expression first char
11b656e74444 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 23737
diff changeset
466 " - lin2,col2: position of expression last char
1620
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
467 "Out: - the pattern to be looked for to find the block
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
468 " Must be called in the source buffer (use of line2byte)
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
469 function! s:Block_pattern(lin1,lin2,col1,col2)
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
470 let start_num1 = a:lin1
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
471 let start_num2 = line2byte(a:lin1) - 1
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
472 let start_num3 = start_num2 + a:col1
2292
ea3c3f13385c Update spell files for Ubuntu locale names.
Bram Moolenaar <bram@vim.org>
parents: 1698
diff changeset
473 let path = '"\(\\"\|[^"]\)\+"'
ea3c3f13385c Update spell files for Ubuntu locale names.
Bram Moolenaar <bram@vim.org>
parents: 1698
diff changeset
474 let start_pos = path.' '.start_num1.' '.start_num2.' '.start_num3
1620
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
475 let end_num1 = a:lin2
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
476 let end_num2 = line2byte(a:lin2) - 1
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
477 let end_num3 = end_num2 + a:col2
2292
ea3c3f13385c Update spell files for Ubuntu locale names.
Bram Moolenaar <bram@vim.org>
parents: 1698
diff changeset
478 let end_pos = path.' '.end_num1.' '.end_num2.' '.end_num3
1620
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
479 return '^'.start_pos.' '.end_pos."$"
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
480 " rq: the '^' here is not totally correct regarding the annot file "grammar"
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
481 " but currently the annotation file respects this, and it's a little bit faster with the '^';
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
482 " can be removed safely.
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
483 endfun
20
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 7
diff changeset
484
1620
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
485 "In: (the cursor position should be at the start of an annotation)
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
486 "Out: the type information
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
487 " Must be called in the annotation buffer (use of search)
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
488 function! s:Match_data()
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
489 " rq: idem as previously, in the following, the '^' at start of patterns is not necessary
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
490 keepj while search('^type($','ce',line(".")) == 0
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
491 keepj if search('^.\{-}($','e') == 0
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
492 throw "no_annotation"
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
493 endif
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
494 keepj if searchpair('(','',')') == 0
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
495 throw "malformed_annot_file"
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
496 endif
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
497 endwhile
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
498 let begin = line(".") + 1
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
499 keepj if searchpair('(','',')') == 0
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
500 throw "malformed_annot_file"
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
501 endif
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
502 let end = line(".") - 1
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
503 return join(getline(begin,end),"\n")
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
504 endfun
3224
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2292
diff changeset
505
1620
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
506 "In: the pattern to look for in order to match the block
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
507 "Out: the type information (calls s:Match_data)
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
508 " Should be called in the annotation buffer
3312
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 3224
diff changeset
509 function! s:Extract_type_data(block_pattern, annot_file_name)
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 3224
diff changeset
510 let annot_file_path = s:annot_file_list[a:annot_file_name][0]
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 3224
diff changeset
511 call s:Enter_annotation_buffer(annot_file_path)
1620
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
512 try
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
513 if search(a:block_pattern,'e') == 0
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
514 throw "no_annotation"
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
515 endif
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
516 call cursor(line(".") + 1,1)
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
517 let annotation = s:Match_data()
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
518 finally
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
519 call s:Exit_annotation_buffer()
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
520 endtry
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
521 return annotation
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
522 endfun
3224
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2292
diff changeset
523
1620
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
524 "c. link this stuff with what the user wants
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
525 " ie. get the expression selected/under the cursor
3224
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2292
diff changeset
526
23466
15fa3923cc49 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 17261
diff changeset
527 let s:ocaml_word_char = '\w|[\xc0-\xff]|'''
20
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 7
diff changeset
528
1620
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
529 "In: the current mode (eg. "visual", "normal", etc.)
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
530 "Out: the borders of the expression we are looking for the type
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
531 function! s:Match_borders(mode)
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
532 if a:mode == "visual"
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
533 let cur = getpos(".")
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
534 normal `<
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
535 let col1 = col(".")
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
536 let lin1 = line(".")
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
537 normal `>
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
538 let col2 = col(".")
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
539 let lin2 = line(".")
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
540 call cursor(cur[1],cur[2])
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
541 return [lin1,lin2,col1-1,col2]
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
542 else
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
543 let cursor_line = line(".")
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
544 let cursor_col = col(".")
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
545 let line = getline('.')
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
546 if line[cursor_col-1:cursor_col] == '[|'
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
547 let [lin2,col2] = searchpairpos('\[|','','|\]','n')
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
548 return [cursor_line,lin2,cursor_col-1,col2+1]
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
549 elseif line[cursor_col-1] == '['
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
550 let [lin2,col2] = searchpairpos('\[','','\]','n')
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
551 return [cursor_line,lin2,cursor_col-1,col2]
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
552 elseif line[cursor_col-1] == '('
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
553 let [lin2,col2] = searchpairpos('(','',')','n')
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
554 return [cursor_line,lin2,cursor_col-1,col2]
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
555 elseif line[cursor_col-1] == '{'
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
556 let [lin2,col2] = searchpairpos('{','','}','n')
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
557 return [cursor_line,lin2,cursor_col-1,col2]
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
558 else
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
559 let [lin1,col1] = searchpos('\v%('.s:ocaml_word_char.'|\.)*','ncb')
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
560 let [lin2,col2] = searchpos('\v%('.s:ocaml_word_char.'|\.)*','nce')
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
561 if col1 == 0 || col2 == 0
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
562 throw "no_expression"
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
563 endif
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
564 return [cursor_line,cursor_line,col1-1,col2]
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
565 endif
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
566 endif
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
567 endfun
20
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 7
diff changeset
568
1620
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
569 "In: the current mode (eg. "visual", "normal", etc.)
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
570 "Out: the type information (calls s:Extract_type_data)
3312
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 3224
diff changeset
571 function! s:Get_type(mode, annot_file_name)
1620
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
572 let [lin1,lin2,col1,col2] = s:Match_borders(a:mode)
3312
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 3224
diff changeset
573 return s:Extract_type_data(s:Block_pattern(lin1,lin2,col1,col2), a:annot_file_name)
1620
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
574 endfun
3224
8b8ef1fed009 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2292
diff changeset
575
5244
eb7ce2918a03 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 5055
diff changeset
576 "In: A string destined to be printed in the 'echo buffer'. It has line
eb7ce2918a03 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 5055
diff changeset
577 "break and 2 space at each line beginning.
eb7ce2918a03 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 5055
diff changeset
578 "Out: A string destined to be yanked, without space and double space.
eb7ce2918a03 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 5055
diff changeset
579 function s:unformat_ocaml_type(res)
eb7ce2918a03 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 5055
diff changeset
580 "Remove end of line.
eb7ce2918a03 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 5055
diff changeset
581 let res = substitute (a:res, "\n", "", "g" )
eb7ce2918a03 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 5055
diff changeset
582 "remove double space
eb7ce2918a03 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 5055
diff changeset
583 let res =substitute(res , " ", " ", "g")
25773
11b656e74444 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 23737
diff changeset
584 "remove space at beginning of string.
5244
eb7ce2918a03 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 5055
diff changeset
585 let res = substitute(res, "^ *", "", "g")
eb7ce2918a03 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 5055
diff changeset
586 return res
eb7ce2918a03 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 5055
diff changeset
587 endfunction
eb7ce2918a03 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 5055
diff changeset
588
1620
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
589 "d. main
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
590 "In: the current mode (eg. "visual", "normal", etc.)
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
591 "After call: the type information is displayed
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
592 if !exists("*Ocaml_get_type")
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
593 function Ocaml_get_type(mode)
3312
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 3224
diff changeset
594 let annot_file_name = s:Fnameescape(expand('%:t:r')).'.annot'
1620
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
595 call s:Locate_annotation()
3312
b7811ab264bf updated for version 7.3.423
Bram Moolenaar <bram@vim.org>
parents: 3224
diff changeset
596 call s:Load_annotation(annot_file_name)
5244
eb7ce2918a03 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 5055
diff changeset
597 let res = s:Get_type(a:mode, annot_file_name)
eb7ce2918a03 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 5055
diff changeset
598 " Copy result in the unnamed buffer
eb7ce2918a03 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 5055
diff changeset
599 let @" = s:unformat_ocaml_type(res)
eb7ce2918a03 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 5055
diff changeset
600 return res
1620
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
601 endfun
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
602 endif
20
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 7
diff changeset
603
1620
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
604 if !exists("*Ocaml_get_type_or_not")
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
605 function Ocaml_get_type_or_not(mode)
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
606 let t=reltime()
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
607 try
5244
eb7ce2918a03 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 5055
diff changeset
608 let res = Ocaml_get_type(a:mode)
eb7ce2918a03 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 5055
diff changeset
609 return res
1620
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
610 catch
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
611 return ""
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
612 endtry
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
613 endfun
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
614 endif
20
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 7
diff changeset
615
1620
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
616 if !exists("*Ocaml_print_type")
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
617 function Ocaml_print_type(mode)
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
618 if expand("%:e") == "mli"
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
619 echohl ErrorMsg | echo "No annotations for interface (.mli) files" | echohl None
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
620 return
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
621 endif
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
622 try
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
623 echo Ocaml_get_type(a:mode)
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
624 catch /E484:/
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
625 echohl ErrorMsg | echo "No type annotations (.annot) file found" | echohl None
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
626 catch /no_expression/
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
627 echohl ErrorMsg | echo "No expression found under the cursor" | echohl None
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
628 catch /no_annotation/
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
629 echohl ErrorMsg | echo "No type annotation found for the given text" | echohl None
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
630 catch /malformed_annot_file/
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
631 echohl ErrorMsg | echo "Malformed .annot file" | echohl None
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
632 endtry
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
633 endfun
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
634 endif
20
4ac1dce8dd5e updated for version 7.0012
vimboss
parents: 7
diff changeset
635
1620
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
636 " Maps
5244
eb7ce2918a03 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 5055
diff changeset
637 nnoremap <silent> <Plug>OCamlPrintType :<C-U>call Ocaml_print_type("normal")<CR>
eb7ce2918a03 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 5055
diff changeset
638 xnoremap <silent> <Plug>OCamlPrintType :<C-U>call Ocaml_print_type("visual")<CR>`<
557
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
639
23737
34b4eb3a8458 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 23466
diff changeset
640 let &cpoptions = s:cposet
557
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
641 unlet s:cposet
862863033fdd updated for version 7.0158
vimboss
parents: 20
diff changeset
642
1620
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
643 " vim:sw=2 fdm=indent