1 /* neatvi configuration file */
3 /* access mode of new files */
4 #define MKFILE_MODE 0600
6 /* map file names to file types */
7 static struct filetype
{
8 char *ft
; /* file type */
9 char *pat
; /* file name pattern */
10 char *def
; /* pattern for global definitions (for gd command) */
11 char *sec
; /* section start pattern (for [[ and ]] commands) */
13 {"c", "\\.[hc]$", "^([a-zA-Z_].*)?\\<%s\\>"},
14 {"roff", "\\.(ms|me|mom|tr|roff|tmac|[1-9])$", "^\\.(de|nr|ds) +%s\\>"},
16 {"msg", "letter$|mbox$|mail$"},
17 {"mk", "Makefile$|makefile$|\\.mk$", "^%s:"},
18 {"sh", "\\.sh$", "^(function +)?%s(\\(\\))? *\\{", "^(function +)?[a-zA-Z_0-9]+(\\(\\))? *\\{"},
19 {"go", "\\.go$", "^(func|var|const|type)( +\\(.*\\))? +%s\\>", "^(func|type)\\>.*\\{$"},
20 {"py", "\\.py$", "^(def|class) +\\<%s\\>", "^(def|class) "},
23 {"diff", "\\.(patch|diff)$"},
25 {"txt", "$"}, /* matches everything; must be the last pattern */
28 /* colours used in highlights[] for programming languages */
29 #define CKWD (3 | SYN_BD) /* general keywords */
30 #define CCON (CKWD) /* control flow keywords */
31 #define CPRE (2 | SYN_BD) /* preprocessor directives */
32 #define CIMP (4 | SYN_BD) /* imported packages */
33 #define CTYP (3) /* built-in types and values */
34 #define CBIN (3) /* built-in functions */
35 #define CCMT (4 | SYN_IT) /* comments */
36 #define CDEF (4 | SYN_BD) /* top-level definition */
37 #define CFUN (SYN_BD) /* called functions */
38 #define CNUM 4 /* numerical constants */
39 #define CSTR 4 /* string literals */
40 #define CVAR 3 /* macros */
41 #define CIDN 0 /* identifiers */
43 /* syntax highlighting patterns */
44 static struct highlight
{
45 char *ft
; /* the filetype of this pattern */
46 int att
[16]; /* attributes of the matched groups */
47 char *pat
; /* regular expression */
48 int end
; /* the group ending this pattern */
51 {"---", {SYN_BGMK(0) | 7 | SYN_BD
, 2, 1}, "^(\".*\").*(\\[[wr]\\]).*$"},
52 {"---", {SYN_BGMK(0) | 7 | SYN_BD
, 2, 5, 7}, "^(\".*\").*=.*(L[0-9]+) +(C[0-9]+).*$"},
53 {"---", {SYN_BGMK(0) | 7}, "^(\".*\").*-.*(L[0-9]+) +(C[0-9]+).*$"},
54 {"---", {SYN_BGMK(0) | 7 | SYN_BD
, 5, 7, 5}, "^\\[([0-9])\\](.*/)*([^/]*)$"},
55 {"---", {SYN_BGMK(0) | 2 | SYN_BD
}, "^.*$\n?"},
57 {"-ex", {SYN_BGMK(0) | 7 | SYN_BD
}, "^[:/!].*$"},
58 {"-ex", {SYN_BGMK(0) | 7}, "^.*$\n?"},
61 {"c", {CTYP
}, "\\<(signed|unsigned|char|short|int|long|float|double|void|struct|enum|union|typedef)\\>"},
62 {"c", {CKWD
}, "\\<(static|extern|register)\\>"},
63 {"c", {CCON
}, "\\<(return|for|while|if|else|do|sizeof|goto|switch|case|default|break|continue)\\>"},
64 {"c", {CCMT
}, "//.*$"},
65 {"c", {CCMT
}, "/\\*([^*]|\\*+[^*/])*\\*+/"},
66 {"c", {CIMP
, CPRE
}, "^#([ \t]*include).*"},
67 {"c", {CIMP
, CPRE
}, "^#([ \t]*[a-zA-Z0-9_]+)"},
68 {"c", {0, CFUN
}, "([a-zA-Z][a-zA-Z0-9_]+)\\(", 1},
69 {"c", {CSTR
}, "\"([^\"]|\\\\\")*\""},
70 {"c", {CNUM
}, "'([^\\]|\\\\.)'"},
71 {"c", {CNUM
}, "[-+]?\\<(0[xX][0-9a-fA-F]+|[0-9]+)\\>"},
72 {"c", {CCMT
}, "^\t*(/\\*.*|\t* \\*.*|\t* \\*\\//)$"},
73 {"c", {CIDN
}, "[a-zA-Z][a-zA-Z0-9_]*"},
76 {"roff", {0, CKWD
, CDEF
}, "^[.'][ \t]*(SH)(.*)$"},
77 {"roff", {0, CKWD
, CDEF
}, "^[.'][ \t]*de (.*)$"},
78 {"roff", {0, CFUN
, CSTR
}, "^[.']([^ \t\\]{2,})?(.*)$", 1},
79 {"roff", {CCMT
}, "\\\\\".*$"},
80 {"roff", {CFUN
}, "\\\\{1,2}[*$fgkmns]([^[(]|\\(..|\\[[^]]*\\])"},
81 {"roff", {CVAR
}, "\\\\([^[(*$fgkmns]|\\(..|\\[[^]]*\\])"},
82 {"roff", {CSTR
}, "\\$[^$]+\\$"},
85 {"tex", {0, CKWD
, 0, 0, CIMP
, 0, CFUN
},
86 "\\\\([^[{ \t]+)((\\[([^][]+)\\])|(\\{([^}]*)\\}))*"},
87 {"tex", {CSTR
}, "\\$[^$]+\\$"},
88 {"tex", {CCMT
}, "%.*$"},
91 {"msg", {6 | SYN_BD
}, "^From .*20..$"},
92 {"msg", {6 | SYN_BD
, 4 | SYN_BD
}, "^Subject: (.*)$"},
93 {"msg", {6 | SYN_BD
, 2 | SYN_BD
}, "^From: (.*)$"},
94 {"msg", {6 | SYN_BD
, 5 | SYN_BD
}, "^To: (.*)$"},
95 {"msg", {6 | SYN_BD
, 5 | SYN_BD
}, "^Cc: (.*)$"},
96 {"msg", {6 | SYN_BD
}, "^[A-Z][-A-Za-z]+: .+$"},
97 {"msg", {2 | SYN_IT
}, "^> .*$"},
100 {"mk", {0, CDEF
}, "([A-Za-z_][A-Za-z0-9_]*)[ \t]*="},
101 {"mk", {CVAR
}, "\\$\\([a-zA-Z0-9_]+\\)"},
102 {"mk", {CCMT
}, "#.*$"},
103 {"mk", {0, CFUN
}, "([A-Za-z_%.]+):"},
106 {"sh", {0, CKWD
, CDEF
}, "^(function +)?([a-zA-Z_0-9]+) *(\\(\\))? *\\{"},
107 {"sh", {CCON
}, "\\<(break|case|continue|do|done|elif|else|esac|fi|for|if|in|then|until|while|return)\\>"},
108 {"sh", {CSTR
}, "\"([^\"\\]|\\\\.)*\""},
109 {"sh", {CSTR
}, "'[^']*'"},
110 {"sh", {CSTR
}, "`([^`\\]|\\\\.)*`"},
111 {"sh", {CVAR
}, "\\$(\\{[^}]+\\}|[a-zA-Z_0-9]+|[!#$?*@-])"},
112 {"sh", {CVAR
}, "\\$\\([^()]+\\)"},
113 {"sh", {CFUN
}, "^\\. .*$"},
114 {"sh", {CCMT
}, "#.*$"},
117 {"go", {0, CKWD
, CIDN
, CDEF
}, "^\\<(func) (\\([^()]+\\) )?([a-zA-Z0-9_]+)\\>"},
118 {"go", {CKWD
}, "\\<(func|type|var|const|package)\\>"},
119 {"go", {CPRE
, CIMP
}, "^import[ \t]+([^ ]+)"},
120 {"go", {CKWD
}, "\\<(import|interface|struct)\\>"},
121 {"go", {CCON
}, "\\<(break|case|chan|continue|default|defer|else|fallthrough|for|go|goto|if|map|range|return|select|switch)\\>"},
122 {"go", {0, CBIN
}, "\\<(append|copy|delete|len|cap|make|new|complex|real|imag|close|panic|recover|print|println|int|int8|int16|int32|int64|uint|uint8|uint16|uint32|uint64|uintptr|float32|float64|complex128|complex64|bool|byte|rune|string|error)\\>\\("},
123 {"go", {CTYP
}, "\\<(true|false|iota|nil|int8|int16|int32|int64|int|uint8|uint16|uint32|uint64|uint|uintptr|float32|float64|complex128|complex64|bool|byte|rune|string|error)\\>"},
124 {"go", {CCMT
}, "//.*$"},
125 {"go", {CCMT
}, "/\\*([^*]|\\*+[^*/])*\\*+/"},
126 {"go", {0, CFUN
}, "([a-zA-Z][a-zA-Z0-9_]*)\\(", 1},
127 {"go", {CIDN
}, "[a-zA-Z][a-zA-Z0-9_]*"},
128 {"go", {CSTR
}, "\"([^\"]|\\\\\")*\""},
129 {"go", {CNUM
}, "'([^']|\\\\')*'"},
130 {"go", {CSTR
}, "`([^`]|\\\\`)*`"},
131 {"go", {CNUM
}, "[-+]?\\<(0[xX][0-9a-fA-F]+|[0-9.]+)\\>"},
134 {"bib", {0, SYN_BD
, SYN_BGMK(3) | SYN_BD
}, "^(%L) +(.*)$", 1},
135 {"bib", {0, SYN_BD
, 4 | SYN_BD
}, "^(%A) (.*)$", 1},
136 {"bib", {0, SYN_BD
, 5 | SYN_BD
}, "^(%T) (.*)$", 1},
137 {"bib", {0, SYN_BD
, 2 | SYN_BD
}, "^(%[JB]) (.*)$", 1},
138 {"bib", {0, SYN_BD
, 5 | SYN_BD
}, "^(%D) (.*)$", 1},
139 {"bib", {0, SYN_BD
, 7}, "^(%O) (.*)$", 1},
140 {"bib", {0, SYN_BD
, SYN_BD
}, "^(%[A-Z]) (.*)$", 1},
141 {"bib", {4}, "^#.*$", 1},
144 {"py", {CCMT
}, "#.*$"},
145 {"py", {CKWD
}, "\\<(class|def)\\>"},
146 {"py", {CKWD
}, "\\<(and|or|not|is|in)\\>"},
147 {"py", {0, 0, CPRE
, CIDN
, CPRE
, CIMP
}, "((from)[ \t]+([^ ]+)[ \t]+)?(import)[ \t]+([^ ]+)"},
148 {"py", {CKWD
}, "\\<(import|from|global|lambda|del)\\>"},
149 {"py", {CCON
}, "\\<(for|while|if|elif|else|pass|return|break|continue)\\>"},
150 {"py", {CCON
}, "\\<(try|except|as|raise|finally|with)\\>"},
151 {"py", {0, CFUN
}, "([a-zA-Z][a-zA-Z0-9_]+)\\(", 1},
152 {"py", {CSTR
}, "[\"']([^\"']|\\\\\")*[\"']"},
153 {"py", {CIDN
}, "[a-zA-Z][a-zA-Z0-9_]*"},
155 /* neatmail listing */
156 {"nm", {0, 6 | SYN_BD
, 4 | SYN_BD
, 3, 5, SYN_BD
},
157 "^([ROU])([0-9]+)(@[^ ]*)? *\t([^\t]*)\t([^\t]*)"},
158 {"nm", {0 | SYN_BD
| SYN_BGMK(6)}, "^[N].*$"},
159 {"nm", {0 | SYN_BD
| SYN_BGMK(5)}, "^[A-Z][HA].*$"},
160 {"nm", {0 | SYN_BD
| SYN_BGMK(3)}, "^[A-Z][MB].*$"},
161 {"nm", {7}, "^[A-Z][LC].*$"},
162 {"nm", {0 | SYN_BD
| SYN_BGMK(7)}, "^[F].*$"},
163 {"nm", {7 | SYN_IT
}, "^\t.*$"},
164 {"nm", {SYN_BD
}, "^:.*$"},
167 {"diff", {1}, "^-.*$"},
168 {"diff", {2}, "^\\+.*$"},
169 {"diff", {6}, "^@.*$"},
170 {"diff", {SYN_BD
}, "^diff .*$"},
172 /* directory listing */
173 {"ls", {7, 3, SYN_FGMK(0) | SYN_BD
, 2, 6}, "^/?([-a-zA-Z0-9_.]+/)*([-a-zA-Z0-9_.]+)\\>(:[0-9]*:)?(.*)$"},
174 {"ls", {CCMT
}, "^#.*$"},
177 /* how to highlight current line (hll option) */
178 #define SYN_LINE (SYN_BGMK(11))
180 /* how to highlight text in the reverse direction */
181 #define SYN_REVDIR (SYN_RV)
183 /* define it as "\33[8l" to disable BiDi in vte-based terminals */
186 /* right-to-left characters (used only in dircontexts[] and dirmarks[]) */
187 #define CR2L "ءآأؤإئابةتثجحخدذرزسشصضطظعغـفقكلمنهوىييپچژکگی؛،»«؟ًٌٍَُِّْٔ"
188 /* neutral characters (used only in dircontexts[] and dirmarks[]) */
189 #define CNEUT "-!\"#$%&'()*+,./:;<=>?@^_`{|}~ "
191 /* direction context; specifies the base direction of lines */
192 static struct dircontext
{
197 {+1, "^[a-zA-Z_0-9]"},
200 /* direction marks; the direction of contiguous characters in a line */
201 static struct dirmark
{
202 int ctx
; /* the direction context for this mark; 0 means any */
203 int dir
; /* the direction of the matched text */
204 int grp
; /* the nested subgroup; 0 means no groups */
207 {+0, +1, 1, "\\\\\\*\\[([^]]+)\\]"},
208 {+1, -1, 0, "[" CR2L
"][" CNEUT CR2L
"]*[" CR2L
"]"},
209 {-1, +1, 0, "[a-zA-Z0-9_][^" CR2L
"\\\\`$']*[a-zA-Z0-9_]"},
210 {+0, +1, 0, "\\$([^$]+)\\$"},
211 {+0, +1, 1, "\\\\[a-zA-Z0-9_]+\\{([^}]+)\\}"},
212 {-1, +1, 0, "\\\\[^ \t" CR2L
"]+"},
215 /* character placeholders */
216 static struct placeholder
{
217 char *s
; /* the source character */
218 char *d
; /* the placeholder */
219 int wid
; /* the width of the placeholder */
237 /* external commands */
238 #define ECMD "neatvi.sh"