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