Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
cobol.vim275 linesDownload Raw Back to ftplugin
1" Vim filetype plugin file2" Language:	cobol3" Maintainer: Ankit Jain <ajatkj@yahoo.co.in>4"     (formerly Tim Pope <vimNOSPAM@tpope.info>)5" Last Update:	By Ankit Jain (add gtk support) on 15.08.20206"		2024 Jan 14 by Vim Project (browsefilter)7 8" Insert mode mappings: <C-T> <C-D> <Tab>9" Normal mode mappings: < > << >> [[ ]] [] ][10" Visual mode mappings: < >11 12if exists("b:did_ftplugin")13    finish14endif15let b:did_ftplugin = 116 17let s:cpo_save = &cpo18set cpo&vim19 20setlocal commentstring=\ \ \ \ \ \ *%s21setlocal comments=:*22setlocal fo+=croqlt23setlocal expandtab24setlocal textwidth=7225 26" matchit support27if exists("loaded_matchit")28    let s:ordot = '\|\ze\.\%( \@=\|$\)'29    let b:match_ignorecase=130    "let b:match_skip = 'getline(".") =~ "^.\\{6\\}[*/C]"'31    let b:match_words=32    \ '\$if\>:$else\>:\$endif\>,' .33    \ '[$-]\@<!\<if\>:\<\%(then\|else\)\>:\<end-if\>'.s:ordot.',' .34    \ '-\@<!\<perform\s\+\%(\d\+\s\+times\|until\|varying\|with\s\+test\)\>:\<end-perform\>'.s:ordot . ',' .35    \ '-\@<!\<\%(search\|evaluate\)\>:\<\%(when\)\>:\<end-\%(search\|evaluate\)\>' .s:ordot . ',' .36    \ '-\@<!\<\%(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 . ',' .37    \ '-\@<!\<\%(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 . ',' .38    \ '-\@<!\<\%(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:ordot39endif40 41" add gtk support42if (has("gui_win32") || has("gui_gtk")) && !exists("b:browsefilter")43  let b:browsefilter = "COBOL Source Files (*.cbl, *.cob)\t*.cbl;*.cob;*.lib\n"44  if has("win32")45    let b:browsefilter .= "All Files (*.*)\t*\n"46  else47    let b:browsefilter .= "All Files (*)\t*\n"48  endif49endif50 51let b:undo_ftplugin = "setlocal com< cms< fo< et< tw<" .52            \ " | unlet! b:browsefilter b:match_words b:match_ignorecase b:match_skip"53if !exists("g:no_plugin_maps") && !exists("g:no_cobol_maps")54    let b:undo_ftplugin = b:undo_ftplugin .55            \ " | sil! exe 'nunmap <buffer> <'" .56            \ " | sil! exe 'nunmap <buffer> >'" .57            \ " | sil! exe 'nunmap <buffer> <<'" .58            \ " | sil! exe 'nunmap <buffer> >>'" .59            \ " | sil! exe 'vunmap <buffer> <'" .60            \ " | sil! exe 'vunmap <buffer> >'" .61            \ " | sil! exe 'iunmap <buffer> <C-D>'" .62            \ " | sil! exe 'iunmap <buffer> <C-T>'" .63            \ " | sil! exe 'iunmap <buffer> <Tab>'" .64            \ " | sil! exe 'nunmap <buffer> <Plug>Traditional'" .65            \ " | sil! exe 'nunmap <buffer> <Plug>Comment'" .66            \ " | sil! exe 'nunmap <buffer> <Plug>DeComment'" .67            \ " | sil! exe 'vunmap <buffer> <Plug>VisualTraditional'" .68            \ " | sil! exe 'vunmap <buffer> <Plug>VisualComment'" .69            \ " | sil! exe 'iunmap <buffer> <Plug>VisualDeComment'" .70            \ " | sil! exe 'unmap  <buffer> [['" .71            \ " | sil! exe 'unmap  <buffer> ]]'" .72            \ " | sil! exe 'unmap  <buffer> []'" .73            \ " | sil! exe 'unmap  <buffer> ]['"74endif75 76if !exists("g:no_plugin_maps") && !exists("g:no_cobol_maps")77    if version >= 70078        nnoremap <silent> <buffer> > :set opfunc=<SID>IncreaseFunc<CR>g@79        nnoremap <silent> <buffer> < :set opfunc=<SID>DecreaseFunc<CR>g@80    endif81    nnoremap <silent> <buffer> >> :call CobolIndentBlock(1)<CR>82    nnoremap <silent> <buffer> << :call CobolIndentBlock(-1)<CR>83    vnoremap <silent> <buffer> > :call CobolIndentBlock(v:count1)<CR>84    vnoremap <silent> <buffer> < :call CobolIndentBlock(-v:count1)<CR>85    inoremap <silent> <buffer> <C-T> <C-R>=<SID>IncreaseIndent()<CR><C-R>=<SID>RestoreShiftwidth()<CR>86    inoremap <silent> <buffer> <C-D> <C-R>=<SID>DecreaseIndent()<CR><C-R>=<SID>RestoreShiftwidth()<CR>87    if !maparg("<Tab>","i")88        inoremap <silent> <buffer> <Tab> <C-R>=<SID>Tab()<CR><C-R>=<SID>RestoreShiftwidth()<CR>89    endif90    noremap <silent> <buffer> [[ m':call search('\c^\%(\s*\<Bar>.\{6\}\s\+\)\zs[A-Za-z0-9-]\+\s\+\%(division\<Bar>section\)\s*\.','bW')<CR>91    noremap <silent> <buffer> ]] m':call search('\c^\%(\s*\<Bar>.\{6\}\s\+\)\zs[A-Za-z0-9-]\+\s\+\%(division\<Bar>section\)\.','W')<CR>92    noremap <silent> <buffer> [] m':call <SID>toend('b')<CR>93    noremap <silent> <buffer> ][ m':call <SID>toend('')<CR>94    " For EnhancedCommentify95    noremap <silent> <buffer> <Plug>Traditional      :call <SID>Comment('t')<CR>96    noremap <silent> <buffer> <Plug>Comment          :call <SID>Comment('c')<CR>97    noremap <silent> <buffer> <Plug>DeComment        :call <SID>Comment('u')<CR>98    noremap <silent> <buffer> <Plug>VisualTraditional :'<,'>call <SID>Comment('t')<CR>99    noremap <silent> <buffer> <Plug>VisualComment     :'<,'>call <SID>Comment('c')<CR>100    noremap <silent> <buffer> <Plug>VisualDeComment   :'<,'>call <SID>Comment('u')<CR>101endif102 103let &cpo = s:cpo_save104unlet s:cpo_save105 106if exists("g:did_cobol_ftplugin_functions")107    finish108endif109let g:did_cobol_ftplugin_functions = 1110 111function! s:repeat(str,count)112    let i = 0113    let ret = ""114    while i < a:count115        let ret = ret . a:str116        let i = i + 1117    endwhile118    return ret119endfunction120 121function! s:increase(...)122    let lnum = '.'123    let sw = shiftwidth()124    let i = a:0 ? a:1 : indent(lnum)125    if i >= 11126        return sw - (i - 11) % sw127    elseif i >= 7128        return 11-i129    elseif i == 6130        return 1131    else132        return 6-i133    endif134endfunction135 136function! s:decrease(...)137    let lnum = '.'138    let sw = shiftwidth()139    let i = indent(a:0 ? a:1 : lnum)140    if i >= 11 + sw141        return 1 + (i + 12) % sw142    elseif i > 11143        return i-11144    elseif i > 7145        return i-7146    elseif i == 7147        return 1148    else149        return i150    endif151endfunction152 153function! CobolIndentBlock(shift)154    let head = strpart(getline('.'),0,7)155    let tail = strpart(getline('.'),7)156    let indent = match(tail,'[^ ]')157    let sw = shiftwidth()158    let shift = a:shift159    if shift > 0160        if indent < 4161            let tail = s:repeat(" ",4-indent).tail162            let shift = shift - 1163        endif164        let tail = s:repeat(" ",shift*sw).tail165        let shift = 0166    elseif shift < 0167        if (indent-4) > -shift * sw168            let tail = strpart(tail,-shift * sw)169        elseif (indent-4) > (-shift-1) * sw170            let tail = strpart(tail,indent - 4)171        else172            let tail = strpart(tail,indent)173        endif174    endif175    call setline('.',head.tail)176endfunction177 178function! s:IncreaseFunc(type)179    '[,']call CobolIndentBlock(1)180endfunction181 182function! s:DecreaseFunc(type)183    '[,']call CobolIndentBlock(-1)184endfunction185 186function! s:IncreaseIndent()187    let c = "\<C-T>"188    if exists("*InsertCtrlTWrapper")189        let key = InsertCtrlTWrapper()190        if key != c191            return key192        endif193    endif194    let interval = s:increase()195    let b:cobol_shiftwidth = &shiftwidth196    let &shiftwidth = 1197    let lastchar = strpart(getline('.'),col('.')-2,1)198    if lastchar == '0' || lastchar == '^'199        return "\<BS>".lastchar.c200    else201        return s:repeat(c,interval)202    endif203endfunction204 205function! s:DecreaseIndent()206    let c = "\<C-D>"207    if exists("*InsertCtrlDWrapper")208        " I hack Ctrl-D to delete when not at the end of the line.209        let key = InsertCtrlDWrapper()210        if key != c211            return key212        endif213    endif214    let interval = s:decrease()215    let b:cobol_shiftwidth = &shiftwidth216    let &shiftwidth = 1217    return s:repeat(c,interval)218endfunction219 220function! s:RestoreShiftwidth()221    if exists("b:cobol_shiftwidth")222        let &shiftwidth=b:cobol_shiftwidth223        unlet b:cobol_shiftwidth224    endif225    return ""226endfunction227 228function! s:Tab()229    if (strpart(getline('.'),0,col('.')-1) =~ '^\s*$' && &sta)230        return s:IncreaseIndent()231    " &softtabstop < 0: &softtabstop follows &shiftwidth232    elseif (&sts < 0 || &sts == shiftwidth()) && &sts != 8 && &et233        return s:repeat(" ",s:increase(col('.')-1))234    else235        return "\<Tab>"236    endif237endfunction238 239function! s:Comment(arg)240    " For EnhancedCommentify241    let line = getline('.')242    if (line =~ '^.\{6\}[*/C]' || a:arg == 'c') && a:arg != 'u'243        let line = substitute(line,'^.\{6\}\zs.',' ','')244    else245        let line = substitute(line,'^.\{6\}\zs.','*','')246    endif247    call setline('.',line)248endfunction249 250function! s:toend(direction)251    let ignore = '^\(\s*\|.\{6\}\)\%([*/]\|\s*$\)'252    let keep = line('.')253    keepjumps +254    while line('.') < line('$') && getline('.') =~ ignore255        keepjumps +256    endwhile257    let res = search('\c^\%(\s*\|.\{6\}\s\+\)\zs[A-Za-z0-9-]\+\s\+\%(division\|section\)\s*\.',a:direction.'W')258    if a:direction != 'b' && !res259        let res = line('$')260        keepjumps $261    elseif res262        keepjumps -263    endif264    if res265        while line('.') > 1 && getline('.') =~ ignore266            keepjumps -267        endwhile268        if line('.') == 1 && getline('.') =~ ignore269            exe "keepjumps ".keep270        endif271    else272        exe "keepjumps ".keep273    endif274endfunction275 
codekingpro/portable-devtools · Team Ai