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