blob: e193110cdeab75e3e210887a5d5c48bc2656bb7c [file] [log] [blame]
Bram Moolenaarf3913272016-02-25 00:00:01 +01001" Vim filetype plugin
2" Language: Eiffel
3" Maintainer: Doug Kearns <dougkearns@gmail.com>
Doug Kearns93197fd2024-01-14 20:59:02 +01004" Last Change: 2024 Jan 14
Bram Moolenaarf3913272016-02-25 00:00:01 +01005
6if (exists("b:did_ftplugin"))
7 finish
8endif
9let b:did_ftplugin = 1
10
11let s:cpo_save = &cpo
12set cpo&vim
13
14setlocal comments=:--
15setlocal commentstring=--\ %s
16
17setlocal formatoptions-=t formatoptions+=croql
18
19if (has("gui_win32") || has("gui_gtk")) && !exists("b:browsefilter")
20 let b:browsefilter = "Eiffel Source Files (*.e)\t*.e\n" .
Doug Kearns93197fd2024-01-14 20:59:02 +010021 \ "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
Bram Moolenaarf3913272016-02-25 00:00:01 +010027endif
28
29if 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>
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")
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> ]-'"
95endif
96
97let &cpo = s:cpo_save
98unlet s:cpo_save
99
100" vim: nowrap sw=2 sts=2 ts=8