eiffel.vim 4.0 KB

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