1121
|
1 " Vim filetype plugin file
|
|
2 " Language: cobol
|
16086
|
3 " Maintainer: Ankit Jain <ajatkj@yahoo.co.in>
|
|
4 " (formerly Tim Pope <vimNOSPAM@tpope.info>)
|
21825
|
5 " Last Update: By Ankit Jain (add gtk support) on 15.08.2020
|
1121
|
6
|
|
7 " Insert mode mappings: <C-T> <C-D> <Tab>
|
|
8 " Normal mode mappings: < > << >> [[ ]] [] ][
|
|
9 " Visual mode mappings: < >
|
|
10
|
|
11 if exists("b:did_ftplugin")
|
|
12 finish
|
|
13 endif
|
|
14 let b:did_ftplugin = 1
|
|
15
|
|
16 let s:cpo_save = &cpo
|
|
17 set cpo&vim
|
|
18
|
|
19 setlocal commentstring=\ \ \ \ \ \ *%s
|
|
20 setlocal comments=:*
|
|
21 setlocal fo+=croqlt
|
|
22 setlocal expandtab
|
|
23 setlocal textwidth=72
|
|
24
|
|
25 " matchit support
|
|
26 if exists("loaded_matchit")
|
|
27 let s:ordot = '\|\ze\.\%( \@=\|$\)'
|
|
28 let b:match_ignorecase=1
|
|
29 "let b:match_skip = 'getline(".") =~ "^.\\{6\\}[*/C]"'
|
|
30 let b:match_words=
|
|
31 \ '\$if\>:$else\>:\$endif\>,' .
|
|
32 \ '[$-]\@<!\<if\>:\<\%(then\|else\)\>:\<end-if\>'.s:ordot.',' .
|
|
33 \ '-\@<!\<perform\s\+\%(\d\+\s\+times\|until\|varying\|with\s\+test\)\>:\<end-perform\>'.s:ordot . ',' .
|
|
34 \ '-\@<!\<\%(search\|evaluate\)\>:\<\%(when\)\>:\<end-\%(search\|evaluate\)\>' .s:ordot . ',' .
|
|
35 \ '-\@<!\<\%(add\|compute\|divide\|multiply\|subtract\)\>\%(.*\(\%$\|\%(\n\%(\%(\s*\|.\{6\}\)[*/].*\n\)*\)\=\s*\%(not\s\+\)\=on\s\+size\s\+error\>\)\)\@=:\%(\<not\s\+\)\@<!\<\%(not\s\+\)\=on\s\+size\s\+error\>:\<end-\%(add\|compute\|divide\|multiply\|subtract\)\>' .s:ordot . ',' .
|
|
36 \ '-\@<!\<\%(string\|unstring\|accept\|display\|call\)\>\%(.*\(\%$\|\%(\n\%(\%(\s*\|.\{6\}\)[*/].*\n\)*\)\=\s*\%(not\s\+\)\=on\s\+\%(overflow\|exception\)\>\)\)\@=:\%(\<not\s\+\)\@<!\<\%(not\s\+\)\=on\s\+\%(overflow\|exception\)\>:\<end-\%(string\|unstring\|accept\|display\|call\)\>' .s:ordot . ',' .
|
|
37 \ '-\@<!\<\%(delete\|rewrite\|start\|write\|read\)\>\%(.*\(\%$\|\%(\n\%(\%(\s*\|.\{6\}\)[*/].*\n\)*\)\=\s*\%(invalid\s\+key\|at\s\+end\|no\s\+data\|at\s\+end-of-page\)\>\)\)\@=:\%(\<not\s\+\)\@<!\<\%(not\s\+\)\=\%(invalid\s\+key\|at\s\+end\|no\s\+data\|at\s\+end-of-page\)\>:\<end-\%(delete\|rewrite\|start\|write\|read\)\>' .s:ordot
|
|
38 endif
|
|
39
|
21825
|
40 " add gtk support
|
|
41 if (has("gui_win32") || has("gui_gtk")) && !exists("b:browsefilter")
|
1121
|
42 let b:browsefilter = "COBOL Source Files (*.cbl, *.cob)\t*.cbl;*.cob;*.lib\n".
|
|
43 \ "All Files (*.*)\t*.*\n"
|
|
44 endif
|
|
45
|
|
46 let b:undo_ftplugin = "setlocal com< cms< fo< et< tw<" .
|
|
47 \ " | unlet! b:browsefilter b:match_words b:match_ignorecase b:match_skip"
|
|
48 if !exists("g:no_plugin_maps") && !exists("g:no_cobol_maps")
|
|
49 let b:undo_ftplugin = b:undo_ftplugin .
|
|
50 \ " | sil! exe 'nunmap <buffer> <'" .
|
|
51 \ " | sil! exe 'nunmap <buffer> >'" .
|
|
52 \ " | sil! exe 'nunmap <buffer> <<'" .
|
|
53 \ " | sil! exe 'nunmap <buffer> >>'" .
|
|
54 \ " | sil! exe 'vunmap <buffer> <'" .
|
|
55 \ " | sil! exe 'vunmap <buffer> >'" .
|
|
56 \ " | sil! exe 'iunmap <buffer> <C-D>'" .
|
|
57 \ " | sil! exe 'iunmap <buffer> <C-T>'" .
|
|
58 \ " | sil! exe 'iunmap <buffer> <Tab>'" .
|
|
59 \ " | sil! exe 'nunmap <buffer> <Plug>Traditional'" .
|
|
60 \ " | sil! exe 'nunmap <buffer> <Plug>Comment'" .
|
|
61 \ " | sil! exe 'nunmap <buffer> <Plug>DeComment'" .
|
|
62 \ " | sil! exe 'vunmap <buffer> <Plug>VisualTraditional'" .
|
|
63 \ " | sil! exe 'vunmap <buffer> <Plug>VisualComment'" .
|
|
64 \ " | sil! exe 'iunmap <buffer> <Plug>VisualDeComment'" .
|
|
65 \ " | sil! exe 'unmap <buffer> [['" .
|
|
66 \ " | sil! exe 'unmap <buffer> ]]'" .
|
|
67 \ " | sil! exe 'unmap <buffer> []'" .
|
|
68 \ " | sil! exe 'unmap <buffer> ]['"
|
|
69 endif
|
|
70
|
|
71 if !exists("g:no_plugin_maps") && !exists("g:no_cobol_maps")
|
|
72 if version >= 700
|
|
73 nnoremap <silent> <buffer> > :set opfunc=<SID>IncreaseFunc<CR>g@
|
|
74 nnoremap <silent> <buffer> < :set opfunc=<SID>DecreaseFunc<CR>g@
|
|
75 endif
|
|
76 nnoremap <silent> <buffer> >> :call CobolIndentBlock(1)<CR>
|
|
77 nnoremap <silent> <buffer> << :call CobolIndentBlock(-1)<CR>
|
|
78 vnoremap <silent> <buffer> > :call CobolIndentBlock(v:count1)<CR>
|
|
79 vnoremap <silent> <buffer> < :call CobolIndentBlock(-v:count1)<CR>
|
|
80 inoremap <silent> <buffer> <C-T> <C-R>=<SID>IncreaseIndent()<CR><C-R>=<SID>RestoreShiftwidth()<CR>
|
|
81 inoremap <silent> <buffer> <C-D> <C-R>=<SID>DecreaseIndent()<CR><C-R>=<SID>RestoreShiftwidth()<CR>
|
|
82 if !maparg("<Tab>","i")
|
|
83 inoremap <silent> <buffer> <Tab> <C-R>=<SID>Tab()<CR><C-R>=<SID>RestoreShiftwidth()<CR>
|
|
84 endif
|
|
85 noremap <silent> <buffer> [[ m':call search('\c^\%(\s*\<Bar>.\{6\}\s\+\)\zs[A-Za-z0-9-]\+\s\+\%(division\<Bar>section\)\s*\.','bW')<CR>
|
|
86 noremap <silent> <buffer> ]] m':call search('\c^\%(\s*\<Bar>.\{6\}\s\+\)\zs[A-Za-z0-9-]\+\s\+\%(division\<Bar>section\)\.','W')<CR>
|
|
87 noremap <silent> <buffer> [] m':call <SID>toend('b')<CR>
|
|
88 noremap <silent> <buffer> ][ m':call <SID>toend('')<CR>
|
|
89 " For EnhancedCommentify
|
|
90 noremap <silent> <buffer> <Plug>Traditional :call <SID>Comment('t')<CR>
|
|
91 noremap <silent> <buffer> <Plug>Comment :call <SID>Comment('c')<CR>
|
|
92 noremap <silent> <buffer> <Plug>DeComment :call <SID>Comment('u')<CR>
|
|
93 noremap <silent> <buffer> <Plug>VisualTraditional :'<,'>call <SID>Comment('t')<CR>
|
|
94 noremap <silent> <buffer> <Plug>VisualComment :'<,'>call <SID>Comment('c')<CR>
|
|
95 noremap <silent> <buffer> <Plug>VisualDeComment :'<,'>call <SID>Comment('u')<CR>
|
|
96 endif
|
|
97
|
|
98 let &cpo = s:cpo_save
|
|
99 unlet s:cpo_save
|
|
100
|
|
101 if exists("g:did_cobol_ftplugin_functions")
|
|
102 finish
|
|
103 endif
|
|
104 let g:did_cobol_ftplugin_functions = 1
|
|
105
|
|
106 function! s:repeat(str,count)
|
|
107 let i = 0
|
|
108 let ret = ""
|
|
109 while i < a:count
|
|
110 let ret = ret . a:str
|
|
111 let i = i + 1
|
|
112 endwhile
|
|
113 return ret
|
|
114 endfunction
|
|
115
|
|
116 function! s:increase(...)
|
|
117 let lnum = '.'
|
5618
|
118 let sw = shiftwidth()
|
1121
|
119 let i = a:0 ? a:1 : indent(lnum)
|
|
120 if i >= 11
|
|
121 return sw - (i - 11) % sw
|
|
122 elseif i >= 7
|
|
123 return 11-i
|
|
124 elseif i == 6
|
|
125 return 1
|
|
126 else
|
|
127 return 6-i
|
|
128 endif
|
|
129 endfunction
|
|
130
|
|
131 function! s:decrease(...)
|
|
132 let lnum = '.'
|
5618
|
133 let sw = shiftwidth()
|
1121
|
134 let i = indent(a:0 ? a:1 : lnum)
|
|
135 if i >= 11 + sw
|
|
136 return 1 + (i + 12) % sw
|
|
137 elseif i > 11
|
|
138 return i-11
|
|
139 elseif i > 7
|
|
140 return i-7
|
|
141 elseif i == 7
|
|
142 return 1
|
|
143 else
|
|
144 return i
|
|
145 endif
|
|
146 endfunction
|
|
147
|
|
148 function! CobolIndentBlock(shift)
|
|
149 let head = strpart(getline('.'),0,7)
|
|
150 let tail = strpart(getline('.'),7)
|
|
151 let indent = match(tail,'[^ ]')
|
5618
|
152 let sw = shiftwidth()
|
1121
|
153 let shift = a:shift
|
|
154 if shift > 0
|
|
155 if indent < 4
|
|
156 let tail = s:repeat(" ",4-indent).tail
|
|
157 let shift = shift - 1
|
|
158 endif
|
|
159 let tail = s:repeat(" ",shift*sw).tail
|
|
160 let shift = 0
|
|
161 elseif shift < 0
|
|
162 if (indent-4) > -shift * sw
|
|
163 let tail = strpart(tail,-shift * sw)
|
|
164 elseif (indent-4) > (-shift-1) * sw
|
|
165 let tail = strpart(tail,indent - 4)
|
|
166 else
|
|
167 let tail = strpart(tail,indent)
|
|
168 endif
|
|
169 endif
|
|
170 call setline('.',head.tail)
|
|
171 endfunction
|
|
172
|
|
173 function! s:IncreaseFunc(type)
|
|
174 '[,']call CobolIndentBlock(1)
|
|
175 endfunction
|
|
176
|
|
177 function! s:DecreaseFunc(type)
|
|
178 '[,']call CobolIndentBlock(-1)
|
|
179 endfunction
|
|
180
|
|
181 function! s:IncreaseIndent()
|
|
182 let c = "\<C-T>"
|
|
183 if exists("*InsertCtrlTWrapper")
|
|
184 let key = InsertCtrlTWrapper()
|
|
185 if key != c
|
|
186 return key
|
|
187 endif
|
|
188 endif
|
|
189 let interval = s:increase()
|
|
190 let b:cobol_shiftwidth = &shiftwidth
|
|
191 let &shiftwidth = 1
|
|
192 let lastchar = strpart(getline('.'),col('.')-2,1)
|
|
193 if lastchar == '0' || lastchar == '^'
|
|
194 return "\<BS>".lastchar.c
|
|
195 else
|
|
196 return s:repeat(c,interval)
|
|
197 endif
|
|
198 endfunction
|
|
199
|
|
200 function! s:DecreaseIndent()
|
|
201 let c = "\<C-D>"
|
|
202 if exists("*InsertCtrlDWrapper")
|
|
203 " I hack Ctrl-D to delete when not at the end of the line.
|
|
204 let key = InsertCtrlDWrapper()
|
|
205 if key != c
|
|
206 return key
|
|
207 endif
|
|
208 endif
|
|
209 let interval = s:decrease()
|
|
210 let b:cobol_shiftwidth = &shiftwidth
|
|
211 let &shiftwidth = 1
|
|
212 return s:repeat(c,interval)
|
|
213 endfunction
|
|
214
|
|
215 function! s:RestoreShiftwidth()
|
|
216 if exists("b:cobol_shiftwidth")
|
|
217 let &shiftwidth=b:cobol_shiftwidth
|
|
218 unlet b:cobol_shiftwidth
|
|
219 endif
|
|
220 return ""
|
|
221 endfunction
|
|
222
|
|
223 function! s:Tab()
|
|
224 if (strpart(getline('.'),0,col('.')-1) =~ '^\s*$' && &sta)
|
|
225 return s:IncreaseIndent()
|
5618
|
226 " &softtabstop < 0: &softtabstop follows &shiftwidth
|
|
227 elseif (&sts < 0 || &sts == shiftwidth()) && &sts != 8 && &et
|
1121
|
228 return s:repeat(" ",s:increase(col('.')-1))
|
|
229 else
|
|
230 return "\<Tab>"
|
|
231 endif
|
|
232 endfunction
|
|
233
|
|
234 function! s:Comment(arg)
|
|
235 " For EnhancedCommentify
|
|
236 let line = getline('.')
|
|
237 if (line =~ '^.\{6\}[*/C]' || a:arg == 'c') && a:arg != 'u'
|
|
238 let line = substitute(line,'^.\{6\}\zs.',' ','')
|
|
239 else
|
|
240 let line = substitute(line,'^.\{6\}\zs.','*','')
|
|
241 endif
|
|
242 call setline('.',line)
|
|
243 endfunction
|
|
244
|
|
245 function! s:toend(direction)
|
|
246 let ignore = '^\(\s*\|.\{6\}\)\%([*/]\|\s*$\)'
|
|
247 let keep = line('.')
|
|
248 keepjumps +
|
|
249 while line('.') < line('$') && getline('.') =~ ignore
|
|
250 keepjumps +
|
|
251 endwhile
|
|
252 let res = search('\c^\%(\s*\|.\{6\}\s\+\)\zs[A-Za-z0-9-]\+\s\+\%(division\|section\)\s*\.',a:direction.'W')
|
|
253 if a:direction != 'b' && !res
|
|
254 let res = line('$')
|
|
255 keepjumps $
|
|
256 elseif res
|
|
257 keepjumps -
|
|
258 endif
|
|
259 if res
|
|
260 while line('.') > 1 && getline('.') =~ ignore
|
|
261 keepjumps -
|
|
262 endwhile
|
|
263 if line('.') == 1 && getline('.') =~ ignore
|
|
264 exe "keepjumps ".keep
|
|
265 endif
|
|
266 else
|
|
267 exe "keepjumps ".keep
|
|
268 endif
|
|
269 endfunction
|