|
| 1 | +" Vim filetype plugin |
| 2 | +" Language: Forth |
| 3 | +" Maintainer: Johan Kotlinski <[email protected]> |
| 4 | +" Last Change: 2023 Aug 08 |
| 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" |
| 61 | +endif |
| 62 | + |
| 63 | +if (has("gui_win32") || has("gui_gtk")) && !exists("b:browsefilter") |
| 64 | + let b:browsefilter = "Forth Source Files (*.f *.fs *.ft *.fth *.4th)\t*.f;*.fs;*.ft;*.fth;*.4th\n" .. |
| 65 | + \ "All Files (*.*)\t*.*\n" |
| 66 | + let b:undo_ftplugin ..= " | unlet! b:browsefilter" |
| 67 | +endif |
| 68 | + |
| 69 | +let &cpo = s:cpo_save |
| 70 | +unlet s:cpo_save |
| 71 | +unlet s:define_patterns s:include_patterns s:matchit_patterns |
0 commit comments