vim

Fork of vim, an acceptable text editor
git clone git://git.laack.co/vim.git
Log | Files | Refs | README | LICENSE

eiffel.vim (4181B)


      1 " Vim filetype plugin
      2 " Language:	Eiffel
      3 " Maintainer:	Doug Kearns <dougkearns@gmail.com>
      4 " Last Change:	2024 Jan 14
      5 
      6 if (exists("b:did_ftplugin"))
      7   finish
      8 endif
      9 let b:did_ftplugin = 1
     10 
     11 let s:cpo_save = &cpo
     12 set cpo&vim
     13 
     14 setlocal comments=:--
     15 setlocal commentstring=--\ %s
     16 
     17 setlocal formatoptions-=t formatoptions+=croql
     18 
     19 if (has("gui_win32") || has("gui_gtk")) && !exists("b:browsefilter")
     20   let b:browsefilter = "Eiffel Source Files (*.e)\t*.e\n" .
     21 		     \ "Eiffel Control Files (*.ecf, *.ace, *.xace)\t*.ecf;*.ace;*.xace\n"
     22   if has("win32")
     23     let b:browsefilter .= "All Files (*.*)\t*\n"
     24   else
     25     let b:browsefilter .= "All Files (*)\t*\n"
     26   endif
     27 endif
     28 
     29 if exists("loaded_matchit") && !exists("b:match_words")
     30   let b:match_ignorecase = 0
     31   " Silly \%^ trick to match note at head of pair and in middle prevents
     32   " 'g%' wrapping from 'note' to 'end'
     33   let b:match_words = '\%^:' .
     34 		  \	'\<\%(^note\|indexing\|class\|^obsolete\|inherit\|insert\|^create\|convert\|feature\|^invariant\)\>:' .
     35 		  \   '^end\>,' .
     36 		  \   '\<\%(do\|deferred\|external\|once\%(\s\+"\)\@!\|check\|debug\|if\|inspect\|from\|across\)\>:' .
     37 		  \	'\%(\%(^\s\+\)\@<=\%(then\|until\|loop\)\|\%(then\|until\|loop\)\s\+[^ -]\|' .
     38 		  \	'\<\%(ensure\%(\s\+then\)\=\|rescue\|_then\|elseif\|else\|when\|\s\@<=invariant\|_until\|_loop\|variant\|_as\|alias\)\>\):' .
     39 		  \   '\s\@<=end\>'
     40   let b:match_skip = 's:\<eiffel\%(Comment\|String\|Operator\)\>'
     41   noremap  [% <Nop>
     42   noremap  ]% <Nop>
     43   vnoremap a% <Nop>
     44 endif
     45 
     46 let b:undo_ftplugin = "setl fo< com< cms<" .
     47   \ "| unlet! b:browsefilter b:match_ignorecase b:match_words b:match_skip"
     48 
     49 if !exists("g:no_plugin_maps") && !exists("g:no_eiffel_maps")
     50   function! s:DoMotion(pattern, count, flags) abort
     51     normal! m'
     52     for i in range(a:count)
     53       call search(a:pattern, a:flags)
     54     endfor
     55   endfunction
     56 
     57   let sections = '^\%(note\|indexing\|' .
     58 	     \	 '\%(\%(deferred\|expanded\|external\|frozen\)\s\+\)*class\|' .
     59 	     \	 'obsolete\|inherit\|insert\|create\|convert\|feature\|' .
     60 	     \	 'invariant\|end\)\>'
     61 
     62   nnoremap <silent> <buffer> ]] :<C-U>call <SID>DoMotion(sections, v:count1, 'W')<CR>
     63   xnoremap <silent> <buffer> ]] :<C-U>exe "normal! gv"<Bar>call <SID>DoMotion(sections, v:count1, 'W')<CR>
     64   nnoremap <silent> <buffer> [[ :<C-U>call <SID>DoMotion(sections, v:count1, 'Wb')<CR>
     65   xnoremap <silent> <buffer> [[ :<C-U>exe "normal! gv"<Bar>call <SID>DoMotion(sections, v:count1, 'Wb')<CR>
     66 
     67   function! s:DoFeatureMotion(count, flags)
     68     let view = winsaveview()
     69     call cursor(1, 1)
     70     let [features_start, _] = searchpos('^feature\>')
     71     call search('^\s\+\a') " find the first feature
     72     let spaces = indent(line('.'))
     73     let [features_end, _] = searchpos('^\%(invariant\|note\|end\)\>')
     74     call winrestview(view)
     75     call s:DoMotion('\%>' . features_start . 'l\%<' . features_end . 'l^\s*\%' . (spaces + 1) . 'v\zs\a', a:count, a:flags)
     76   endfunction
     77 
     78   nnoremap <silent> <buffer> ]m :<C-U>call <SID>DoFeatureMotion(v:count1, 'W')<CR>
     79   xnoremap <silent> <buffer> ]m :<C-U>exe "normal! gv"<Bar>call <SID>DoFeatureMotion(v:count1, 'W')<CR>
     80   nnoremap <silent> <buffer> [m :<C-U>call <SID>DoFeatureMotion(v:count1, 'Wb')<CR>
     81   xnoremap <silent> <buffer> [m :<C-U>exe "normal! gv"<Bar>call <SID>DoFeatureMotion(v:count1, 'Wb')<CR>
     82 
     83   let comment_block_start = '^\%(\s\+--.*\n\)\@<!\s\+--'
     84   let comment_block_end = '^\s\+--.*\n\%(\s\+--\)\@!'
     85 
     86   nnoremap <silent> <buffer> ]- :<C-U>call <SID>DoMotion(comment_block_start, 1, 'W')<CR>
     87   xnoremap <silent> <buffer> ]- :<C-U>exe "normal! gv"<Bar>call <SID>DoMotion(comment_block_start, 1, 'W')<CR>
     88   nnoremap <silent> <buffer> [- :<C-U>call <SID>DoMotion(comment_block_end, 1, 'Wb')<CR>
     89   xnoremap <silent> <buffer> [- :<C-U>exe "normal! gv"<Bar>call <SID>DoMotion(comment_block_end, 1, 'Wb')<CR>
     90 
     91   let b:undo_ftplugin = b:undo_ftplugin .
     92     \ "| silent! execute 'unmap <buffer> [[' | silent! execute 'unmap <buffer> ]]'" .
     93     \ "| silent! execute 'unmap <buffer> [m' | silent! execute 'unmap <buffer> ]m'" .
     94     \ "| silent! execute 'unmap <buffer> [-' | silent! execute 'unmap <buffer> ]-'"
     95 endif
     96 
     97 let &cpo = s:cpo_save
     98 unlet s:cpo_save
     99 
    100 " vim: nowrap sw=2 sts=2 ts=8