eiffel.vim 4.1 KB

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