annotate runtime/ftplugin/ocaml.vim @ 14215:b0083bebf159

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