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