Commit | Line | Data |
---|---|---|
6464ec02 AT |
1 | VVhitespace Syntax Highlighting |
2 | =============================== | |
3 | ||
4 | ![VVS Syntax Highlighting Example](vvs_syntax_highlighting.gif) | |
5 | ||
6 | I find it useful to highlight each IMP a different color as well as highlight | |
7 | code comments and label definitions. The above image is typical of my | |
8 | VVhitespace editing environment. | |
9 | ||
10 | If you would like something similar, the configuration examples below can be | |
11 | used with `vim` or `neatvi`. Other editors that use regex matching can reuse | |
12 | the regular expressions from these examples to achieve similar results. | |
13 | ||
14 | This syntax highlighting definition works only with the way I write VVhitespace | |
15 | code in this repository. Comments in particular can take many forms other | |
16 | than specified here. | |
17 | ||
18 | If you take the time to put together a configuration for other editors, or | |
19 | improve the regex definitions, let me know. | |
20 | ||
21 | ||
22 | VIM Highlighting | |
23 | ---------------- | |
24 | ||
25 | If they don't already exist, create the folders `~/.vim/syntax` and | |
26 | `~/.vim/ftdetect`. | |
27 | ||
28 | % mkdir -p ~/.vim/syntax | |
29 | % mkdir -p ~/.vim/ftdetect | |
30 | ||
31 | Create a file named `~/.vim/ftdetect/vvhitespace.vim` to detect the filetype | |
32 | based on the file extension. It should contain a single line: | |
33 | ||
34 | au BufRead,BufNewFile *.pvvs set filetype=vvhitespace | |
35 | ||
36 | Create a file named `~/.vim/syntax/vvhitespace.vim` containing the following: | |
37 | ||
38 | if exists("b:current_syntax") | |
39 | finish | |
40 | endif | |
41 | ||
42 | let b:current_synax = "vvhitespace" | |
43 | ||
44 | " Stack IMP | |
45 | syn match stackIMP '^[sS][sS]' | |
46 | syn match stackIMP '^[sS][nN][sStTnN]' | |
47 | ||
48 | " Arithmetic IMP | |
49 | syn match arithIMP '^[tT][sS][sStT][sStTnN]' | |
50 | ||
51 | " Heap IMP | |
52 | syn match heapIMP '^[tT][tT][sStT]' | |
53 | ||
54 | " Control Flow IMP | |
55 | syn match controlIMP '^[nN][nNsStT][nNsStT]' | |
56 | ||
57 | " IO IMP | |
58 | syn match ioIMP '^[tT][nN][sStT][sStT]' | |
59 | ||
60 | " Label Definition | |
61 | syn match labelDef 'V[sStT]\+N' | |
62 | ||
63 | " Comments | |
64 | syn match commentBlock '|.*$' | |
65 | syn match commentBlock '@.*$' | |
66 | ||
67 | " Define colors using existing Highlight Groups. | |
68 | " To see a list of other Highlight Groups, type `:highlight` in vim. | |
69 | hi def link stackIMP Type | |
70 | hi def link arithIMP ModeMsg | |
71 | hi def link heapIMP Special | |
72 | hi def link controlIMP Constant | |
73 | hi def link ioIMP Keyword | |
74 | hi def link labelDef Function | |
75 | hi def link commentBlock NonText | |
76 | ||
77 | That's it! You should now see syntax highlighting when opening files with names | |
78 | ending in `*.pvvs`. | |
79 | ||
80 | If you don't any see syntax highlighting, check your `.vimrc` and other config | |
81 | locations for conflicting options. Try manually enabling syntax highlighting | |
82 | with the `syntax on` configuration directive. | |
83 | ||
84 | ||
85 | NeatVI Highlighting | |
86 | ------------------- | |
87 | ||
88 | Open the file `conf.h` for editing. | |
89 | ||
90 | Add the following line to the `filetypes` array, matching all `*.pvvs` files. | |
91 | ||
92 | {"pvvs", "\\.pvvs$"}, /* VVhitespace */ | |
93 | ||
94 | Add the following block to the `highlights` array. | |
95 | ||
96 | {"pvvs", {2}, "^[sS][sS]"}, /* IMP: Stack Manipulation */ | |
97 | {"pvvs", {2}, "^[sS][nN][sStTnN]"}, /* IMP: Stack Manipulation */ | |
98 | {"pvvs", {8}, "^[tT][sS][sStT][sStTnN]"}, /* IMP: Arithmetic */ | |
99 | {"pvvs", {5}, "^[tT][tT][sStT]"}, /* IMP: Heap Access */ | |
100 | {"pvvs", {1}, "^[nN][nNsStT][nNsStT]"}, /* IMP: Control Flow */ | |
101 | {"pvvs", {4}, "^[tT][nN][sStT][sStT]"}, /* IMP: Input/Output */ | |
102 | {"pvvs", {6 | SYN_BD}, "V[sStT]+N "}, /* Label Definitions */ | |
103 | {"pvvs", {3 | SYN_IT}, "\\|.*$"}, /* Comments */ | |
104 | {"pvvs", {3 | SYN_IT}, "\\@.*$"}, /* Comments */ | |
105 | ||
106 | Recompile NeatVI and syntax highlighting should work on all files with names | |
107 | ending in `*.pvvs`. |