octave.vim 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. " Vim filetype plugin file
  2. " Language: GNU Octave
  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. " 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. if has("win32")
  48. let b:browsefilter ..= "All Files (*.*)\t*\n"
  49. else
  50. let b:browsefilter ..= "All Files (*)\t*\n"
  51. endif
  52. endif
  53. let b:undo_ftplugin = "setl com< cms< fo< kp< " ..
  54. \ "| unlet! b:browsefilter b:match_words"
  55. let &cpo = s:cpo_save
  56. unlet s:cpo_save
  57. " vim: nowrap sw=2 sts=2 ts=8 noet: