blob: 5343784a21de6177a2fac9b17c3c374c93b66ea5 [file] [log] [blame]
dkearns16105282023-08-31 16:17:16 +10001" Vim filetype plugin
2" Language: Forth
3" Maintainer: Johan Kotlinski <kotlinski@gmail.com>
4" Last Change: 2023 Aug 08
5" URL: https://github.com/jkotlinski/forth.vim
6
7if exists("b:did_ftplugin")
8 finish
9endif
10let b:did_ftplugin = 1
11
12let s:cpo_save = &cpo
13set cpo&vim
14
15setlocal commentstring=\\\ %s
16setlocal comments=s:(,mb:\ ,e:),b:\\
17setlocal iskeyword=33-126,128-255
18
19let s:include_patterns =<< trim EOL
20
21 \<\%(INCLUDE\|REQUIRE\)\>\s\+\zs\k\+\ze
22 \<S"\s\+\zs[^"]*\ze"\s\+\%(INCLUDED\|REQUIRED\)\>
23EOL
24let &l:include = $'\c{ s:include_patterns[1:]->join('\|') }'
25
26let 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
37EOL
38let &l:define = $'\c\<\%({ s:define_patterns->join('\|') }\)'
39
40" assume consistent intra-project file extensions
41let &l:suffixesadd = "." .. expand("%:e")
42
43let b:undo_ftplugin = "setl cms< com< def< inc< isk< sua<"
44
45if 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"
61endif
62
63if (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"
67endif
68
69let &cpo = s:cpo_save
70unlet s:cpo_save
71unlet s:define_patterns s:include_patterns s:matchit_patterns