annotate runtime/ftplugin/ocaml.vim @ 4685:d721ef7d73b6

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