forth.vim 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. " Vim filetype plugin
  2. " Language: Forth
  3. " Maintainer: Johan Kotlinski <kotlinski@gmail.com>
  4. " Last Change: 2023 Sep 15
  5. " 2024 Jan 14 by Vim Project (browsefilter)
  6. " URL: https://github.com/jkotlinski/forth.vim
  7. if exists("b:did_ftplugin")
  8. finish
  9. endif
  10. let b:did_ftplugin = 1
  11. let s:cpo_save = &cpo
  12. set cpo&vim
  13. setlocal commentstring=\\\ %s
  14. setlocal comments=s:(,mb:\ ,e:),b:\\
  15. setlocal iskeyword=33-126,128-255
  16. let s:include_patterns =<< trim EOL
  17. \<\%(INCLUDE\|REQUIRE\)\>\s\+\zs\k\+\ze
  18. \<S"\s\+\zs[^"]*\ze"\s\+\%(INCLUDED\|REQUIRED\)\>
  19. EOL
  20. let &l:include = $'\c{ s:include_patterns[1:]->join('\|') }'
  21. let s:define_patterns =<< trim EOL
  22. :
  23. [2F]\=CONSTANT
  24. [2F]\=VALUE
  25. [2F]\=VARIABLE
  26. BEGIN-STRUCTURE
  27. BUFFER:
  28. CODE
  29. CREATE
  30. MARKER
  31. SYNONYM
  32. EOL
  33. let &l:define = $'\c\<\%({ s:define_patterns->join('\|') }\)'
  34. " assume consistent intra-project file extensions
  35. let &l:suffixesadd = "." .. expand("%:e")
  36. let b:undo_ftplugin = "setl cms< com< def< inc< isk< sua<"
  37. if exists("loaded_matchit") && !exists("b:match_words")
  38. let s:matchit_patterns =<< trim EOL
  39. \<\:\%(NONAME\)\=\>:\<EXIT\>:\<;\>
  40. \<IF\>:\<ELSE\>:\<THEN\>
  41. \<\[IF]\>:\<\[ELSE]\>:\<\[THEN]\>
  42. \<?\=DO\>:\<LEAVE\>:\<+\=LOOP\>
  43. \<CASE\>:\<ENDCASE\>
  44. \<OF\>:\<ENDOF\>
  45. \<BEGIN\>:\<WHILE\>:\<\%(AGAIN\|REPEAT\|UNTIL\)\>
  46. \<CODE\>:\<END-CODE\>
  47. \<BEGIN-STRUCTURE\>:\<END-STRUCTURE\>
  48. EOL
  49. let b:match_ignorecase = 1
  50. let b:match_words = s:matchit_patterns[1:]->join(',')
  51. let b:undo_ftplugin ..= "| unlet! b:match_ignorecase b:match_words"
  52. unlet s:matchit_patterns
  53. endif
  54. if (has("gui_win32") || has("gui_gtk")) && !exists("b:browsefilter")
  55. let b:browsefilter = "Forth Source Files (*.f, *.fs, *.ft, *.fth, *.4th)\t*.f;*.fs;*.ft;*.fth;*.4th\n"
  56. if has("win32")
  57. let b:browsefilter ..= "All Files (*.*)\t*\n"
  58. else
  59. let b:browsefilter ..= "All Files (*)\t*\n"
  60. endif
  61. let b:undo_ftplugin ..= " | unlet! b:browsefilter"
  62. endif
  63. let &cpo = s:cpo_save
  64. unlet s:cpo_save
  65. unlet s:define_patterns s:include_patterns