octave.vim 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. " Vim filetype plugin file
  2. " Language: GNU Octave
  3. " Maintainer: Doug Kearns <dougkearns@gmail.com>
  4. " Last Change: 2021 Sep 02
  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. " TODO: update Matlab ftplugin and source it as the base file?
  12. setlocal comments=s:%{,m:\ ,e:%},s:#{,m:\ ,e:#},:%,:#
  13. setlocal commentstring=#\ %s
  14. setlocal formatoptions-=t formatoptions+=croql
  15. setlocal keywordprg=info\ octave\ --vi-keys\ --index-search
  16. if exists("loaded_matchit") && !exists("b:match_words")
  17. let b:match_words = '\<unwind_protect\>:\<unwind_protect_cleanup\>:\<end_unwind_protect\>'
  18. if exists("octave_use_matlab_end")
  19. let b:match_words ..= ',' ..
  20. \ '\<\%(classdef\|enumeration\|events\|for\|function\|if\|methods\|parfor\|properties\|switch\|while\|try\)\>' ..
  21. \ ':' ..
  22. \ '\<\%(elseif\|else\|case\|otherwise\|break\|continue\|catch\)\>' ..
  23. \ ':' ..
  24. \ '\<end\>'
  25. else
  26. let b:match_words ..= ',' ..
  27. \ '\<classdef\>:\<endclassdef\>,' ..
  28. \ '\<enumeration\>:\<endenumeration\>,' ..
  29. \ '\<events\>:\<endevents\>,' ..
  30. \ '\<do\>:\<\%(break\|continue\)\>:\<until\>' ..
  31. \ '\<for\>:\<\%(break\|continue\)\>:\<endfor\>,' ..
  32. \ '\<function\>:\<return\>:\<endfunction\>,' ..
  33. \ '\<if\>:\<\%(elseif\|else\)\>:\<endif\>,' ..
  34. \ '\<methods\>:\<endmethods\>,' ..
  35. \ '\<parfor\>:\<endparfor\>,' ..
  36. \ '\<properties\>:\<endproperties\>,' ..
  37. \ '\<switch\>:\<\%(case\|otherwise\)\>:\<endswitch\>,' ..
  38. \ '\<while\>:\<\%(break\|continue\)\>:\<endwhile\>,' ..
  39. \ '\<try\>:\<catch\>:\<end_try_catch\>'
  40. endif
  41. " only match in statement position
  42. let s:statement_start = escape('\%(\%(^\|;\)\s*\)\@<=', '\')
  43. let b:match_words = substitute(b:match_words, '\\<', s:statement_start, 'g')
  44. endif
  45. if (has("gui_win32") || has("gui_gtk")) && !exists("b:browsefilter")
  46. let b:browsefilter = "GNU Octave Source Files (*.m)\t*.m\n" ..
  47. \ "All Files (*.*)\t*.*\n"
  48. endif
  49. let b:undo_ftplugin = "setl com< cms< fo< kp< " ..
  50. \ "| unlet! b:browsefilter b:match_words"
  51. let &cpo = s:cpo_save
  52. unlet s:cpo_save
  53. " vim: nowrap sw=2 sts=2 ts=8 noet: