on master help sign in
End highlighting of C code in man pages when no longer relevant
commitcfdb853ea60e8d6ff3eb56530079447777216d8b authorKeith Hall <kingkeith+github@gmail.com> dateMon 19 Oct 2020, 11:24 (6 years ago) parent41e857e
4 files changed+118−89
assets/syntaxes/02_Extra/Manpage.sublime-syntax+14−7 assets/syntaxes/02_Extra/syntax_test_man.man+26−4 tests/syntax-tests/highlighted/Manpage/bat-0.16.man+28−28 tests/syntax-tests/highlighted/Manpage/select-2.man+50−50
assets/syntaxes/02_Extra/Manpage.sublime-syntax+14−7
@@ -34,28 +34,30 @@ contexts:
3434 scope: markup.heading.title.man
3535 - match: \s\s
3636 pop: true
37− - match: '(?=\S)'
37+ - match: '(?=\S|$)'
3838 pop: true
3939
4040 - match: '$'
41− push: body
41+ set: body
4242
4343 body:
4444 # English, ..., ..., ..., Russian, ...
4545
46− - match: '^(?:SYNOPSIS|SYNTAX|SINTASSI|SKŁADNIA|СИНТАКСИС|書式)'
46+ - match: '^(?:SYNOPSIS|SYNTAX|SINTASSI|SK\u0141ADNIA|\u0421\u0418\u041d\u0422\u0410\u041a\u0421\u0418\u0421|\u66f8\u5f0f)'
4747 scope: markup.heading.synopsis.man
4848 embed: synopsis
4949 escape: '(?={{section_heading}})'
5050
51+ - match: '^(?:USAGE)'
52+ scope: markup.heading.synopsis.man
53+ embed: synopsis
54+ escape: '(?={{section_heading}})'
5155
5256 - match: '{{section_heading}}'
5357 scope: markup.heading.other.man
5458 embed: options # some man pages put command line options under the description heading
5559 escape: '(?={{section_heading}})'
5660
57− - include: function-call
58−
5961 function-call:
6062 - match: '\b([A-Za-z0-9_\-]+)(\()([^)]*)(\))'
6163 captures:
@@ -129,8 +131,12 @@ contexts:
129131 pop: true
130132
131133 c-code:
132− - match: '^(?=\s+(?:#include|/\*))'
133− push: scope:source.c
134+ #- match: '^(\s+)(?=#include\b|#define\b|/\*|struct\s+\w+\s*\{)'
135+ - match: '^(?=\s+(?:#include\b|#define\b|/\*|struct\s+(\w+\s*)?\{))'
136+ embed: scope:source.c
137+ #embed_scope: source.c.embedded.man
138+ #escape: ^(?!#|\1|\s*(?:$|/\*|#include\b|#define\b))
139+ escape: ^(?=\s*(?:\(.*\.\)\s*$|[A-Z](?![A-Z])))
134140
135141 synopsis:
136142 - include: c-code
@@ -144,6 +150,7 @@ contexts:
144150 captures:
145151 1: keyword.operator.logical.man
146152 #- match: (?={{command_line_option}})
153+ - match: \w+-\w+
147154 - match: (?=-)
148155 push:
149156 - match: (?=\s*\|)
assets/syntaxes/02_Extra/syntax_test_man.man+26−4
@@ -5,7 +5,7 @@ SOMETHING(8) System Manager's Manual SOMETHING(8)
55# ^^^^^^^ meta.preprocessor
66
77NAME
8−#^^^ markup.heading.title
8+#^^^ markup.heading.other
99 example - do something useful
1010
1111SYNOPSIS
@@ -45,9 +45,16 @@ SYNOPSIS
4545 [--quiet] [--debug] [--help|-h] [--version] [--conf FILE]
4646
4747 /* According to POSIX.1-2001, POSIX.1-2008 */
48−# ^^ source comment.block punctuation.definition.comment
48+# ^^ source.c comment.block punctuation.definition.comment
4949 #include <sys/select.h>
50−# ^^^^^^^^ source meta.preprocessor.include keyword.control.import.include
50+# ^^^^^^^^ source.c meta.preprocessor.include keyword.control.import.include
51+ struct timeval {
52+# ^^^^^^ source.c storage.type
53+
54+ time_t tv_sec; /* seconds */
55+ suseconds_t tv_usec; /* microseconds */
56+ };
57+
5158
5259
5360DESCRIPTION
@@ -126,4 +133,19 @@ OPTIONS
126133
127134EXAMPLE
128135 #include <stdio.h>
129−# ^^^^^^^^ source meta.preprocessor.include keyword.control.import.include
136+# ^^^^^^^^ source.c meta.preprocessor.include keyword.control.import.include
137+
138+ (This is not C code.)
139+# ^^^^^^^^^^^^^^^^^^^^^^ - source.c
140+
141+ struct timeval {
142+ time_t tv_sec; /* seconds */
143+ suseconds_t tv_usec; /* microseconds */
144+ };
145+# ^ source.c punctuation.terminator
146+
147+ The corresponding argument for pselect() has the following type:
148+#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - source.c
149+ #define POLLIN_SET (EPOLLRDNORM | EPOLLRDBAND | EPOLLIN |
150+ EPOLLHUP | EPOLLERR)
151+# ^ source.c meta.preprocessor.macro meta.group punctuation.section.group.end
tests/syntax-tests/highlighted/Manpage/bat-0.16.man+28−28
@@ -1,12 +1,12 @@
1−BAT(1) General Commands Manual BAT(1)
1+BAT(1) General Commands Manual BAT(1)
22
33NAME
44 bat - a cat(1) clone with syntax highlighting and Git integration.
55
66USAGE
7− bat [OPTIONS] [FILE]...
7+ bat [OPTIONS] [FILE]...
88
9− bat cache [CACHE-OPTIONS] [--build|--clear]
9+ bat cache [CACHE-OPTIONS] [--build|--clear]
1010
1111DESCRIPTION
1212 bat prints the syntax-highlighted content of a collection of FILEs to
@@ -28,19 +28,19 @@
2828 values can be specified as either '--language value', '--lan‐
2929 guage=value', '-l value' or '-lvalue'.
3030
31− -A, --show-all
31+ -A, --show-all
3232
3333 Show non-printable characters like space, tab or newline. Use
3434 '--tabs' to control the width of the tab-placeholders.
3535
36− -p, --plain
36+ -p, --plain
3737
3838 Only show plain style, no decorations. This is an alias for
39− '--style=plain'. When '-p' is used twice ('-pp'), it also dis‐
39+ '--style=plain'. When '-p' is used twice ('-pp'), it also dis‐
4040 ables automatic paging (alias for '--style=plain
41− --pager=never').
41+ --pager=never').
4242
43− -l, --language <language>
43+ -l, --language <language>
4444
4545 Explicitly set the language for syntax highlighting. The lan‐
4646 guage can be specified as a name (like 'C++' or 'LaTeX') or pos‐
@@ -65,54 +65,54 @@
6565 --highlight-line 40:
6666 highlights lines 40 to the end of the file
6767
68− --tabs <T>
68+ --tabs <T>
6969
7070 Set the tab width to T spaces. Use a width of 0 to pass tabs
7171 through directly
7272
73− --wrap <mode>
73+ --wrap <mode>
7474
7575 Specify the text-wrapping mode (*auto*, never, character). The
7676 '--terminal-width' option can be used in addition to control the
7777 output width.
7878
79− --terminal-width <width>
79+ --terminal-width <width>
8080
8181 Explicitly set the width of the terminal instead of determining
8282 it automatically. If prefixed with '+' or '-', the value will be
8383 treated as an offset to the actual terminal width. See also:
8484 '--wrap'.
8585
86− -n, --number
86+ -n, --number
8787
8888 Only show line numbers, no other decorations. This is an alias
89− for '--style=numbers'
89+ for '--style=numbers'
9090
91− --color <when>
91+ --color <when>
9292
9393 Specify when to use colored output. The automatic mode only en‐
9494 ables colors if an interactive terminal is detected. Possible
9595 values: *auto*, never, always.
9696
97− --italic-text <when>
97+ --italic-text <when>
9898
9999 Specify when to use ANSI sequences for italic text in the out‐
100100 put. Possible values: always, *never*.
101101
102− --decorations <when>
102+ --decorations <when>
103103
104104 Specify when to use the decorations that have been specified via
105105 '--style'. The automatic mode only enables decorations if an in‐
106106 teractive terminal is detected. Possible values: *auto*, never,
107107 always.
108108
109− -f, --force-colorization
109+ -f, --force-colorization
110110
111− Alias for '--decorations=always --color=always'. This is useful
111+ Alias for '--decorations=always --color=always'. This is useful
112112 if the output of bat is piped to another program, but you want
113113 to keep the colorization/decorations.
114114
115− --paging <when>
115+ --paging <when>
116116
117117 Specify when to use the pager. To disable the pager, use '--pag‐
118118 ing=never' or its alias, -P. To disable the pager permanently,
@@ -120,7 +120,7 @@
120120 used, see the '--pager' option. Possible values: *auto*, never,
121121 always.
122122
123− --pager <command>
123+ --pager <command>
124124
125125 Determine which pager is used. This option will override the
126126 PAGER and BAT_PAGER environment variables. The default pager is
@@ -135,24 +135,24 @@
135135 '*.build:Python'. To highlight files named '.myignore' with the
136136 Git Ignore syntax, use -m '.myignore:Git Ignore'.
137137
138− --theme <theme>
138+ --theme <theme>
139139
140140 Set the theme for syntax highlighting. Use '--list-themes' to
141141 see all available themes. To set a default theme, add the
142− '--theme="..."' option to the configuration file or export the
142+ '--theme="..."' option to the configuration file or export the
143143 BAT_THEME environment variable (e.g.: export BAT_THEME="...").
144144
145145 --list-themes
146146
147147 Display a list of supported themes for syntax highlighting.
148148
149− --style <style-components>
149+ --style <style-components>
150150
151151 Configure which elements (line numbers, file headers, grid bor‐
152152 ders, Git modifications, ..) to display in addition to the file
153153 contents. The argument is a comma-separated list of components
154154 to display (e.g. 'numbers,changes,grid') or a pre-defined style
155− ('full'). To set a default style, add the '--style=".."' option
155+ ('full'). To set a default style, add the '--style=".."' option
156156 to the configuration file or export the BAT_STYLE environment
157157 variable (e.g.: export BAT_STYLE=".."). Possible values: *auto*,
158158 full, plain, changes, header, grid, numbers, snip.
@@ -171,21 +171,21 @@
171171 --line-range 40:
172172 prints lines 40 to the end of the file
173173
174− -L, --list-languages
174+ -L, --list-languages
175175
176176 Display a list of supported languages for syntax highlighting.
177177
178− -u, --unbuffered
178+ -u, --unbuffered
179179
180180 This option exists for POSIX-compliance reasons ('u' is for 'un‐
181181 buffered'). The output is always unbuffered - this option is
182182 simply ignored.
183183
184− -h, --help
184+ -h, --help
185185
186186 Print this help message.
187187
188− -V, --version
188+ -V, --version
189189
190190 Show version information.
191191
tests/syntax-tests/highlighted/Manpage/select-2.man+50−50
@@ -1,4 +1,4 @@
1−SELECT(2) Linux Programmer's Manual SELECT(2)
1+SELECT(2) Linux Programmer's Manual SELECT(2)
22
33NAME
44 select, pselect, FD_CLR, FD_ISSET, FD_SET, FD_ZERO - synchronous I/O multiplexing
@@ -18,9 +18,9 @@
1818 fd_set *exceptfds, const struct timespec *timeout,
1919 const sigset_t *sigmask);
2020
21− Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
21+ Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
2222
23− pselect(): _POSIX_C_SOURCE >= 200112L
23+ pselect(): _POSIX_C_SOURCE >= 200112L
2424
2525DESCRIPTION
2626 select() allows a program to monitor multiple file descriptors, waiting until one or more of the file descriptors become
@@ -142,17 +142,17 @@
142142 The timeout
143143 The timeout argument for select() is a structure of the following type:
144144
145− struct timeval {
146− time_t tv_sec; /* seconds */
147− suseconds_t tv_usec; /* microseconds */
148− };
145+ struct timeval {
146+ time_t tv_sec; /* seconds */
147+ suseconds_t tv_usec; /* microseconds */
148+ };
149149
150150 The corresponding argument for pselect() has the following type:
151151
152− struct timespec {
153− time_t tv_sec; /* seconds */
154− long tv_nsec; /* nanoseconds */
155− };
152+ struct timespec {
153+ time_t tv_sec; /* seconds */
154+ long tv_nsec; /* nanoseconds */
155+ };
156156
157157 On Linux, select() modifies timeout to reflect the amount of time not slept; most other implementations do not do this.
158158 (POSIX.1 permits either behavior.) This causes problems both when Linux code which reads timeout is ported to other operating
@@ -213,14 +213,14 @@
213213 Within the Linux kernel source, we find the following definitions which show the correspondence between the readable,
214214 writable, and exceptional condition notifications of select() and the event notifications provided by poll(2) and epoll(7):
215215
216− #define POLLIN_SET (EPOLLRDNORM | EPOLLRDBAND | EPOLLIN |
217− EPOLLHUP | EPOLLERR)
218− /* Ready for reading */
219− #define POLLOUT_SET (EPOLLWRBAND | EPOLLWRNORM | EPOLLOUT |
220− EPOLLERR)
221− /* Ready for writing */
222− #define POLLEX_SET (EPOLLPRI)
223− /* Exceptional condition */
216+ #define POLLIN_SET (EPOLLRDNORM | EPOLLRDBAND | EPOLLIN |
217+ EPOLLHUP | EPOLLERR)
218+ /* Ready for reading */
219+ #define POLLOUT_SET (EPOLLWRBAND | EPOLLWRNORM | EPOLLOUT |
220+ EPOLLERR)
221+ /* Ready for writing */
222+ #define POLLEX_SET (EPOLLPRI)
223+ /* Exceptional condition */
224224
225225 Multithreaded applications
226226 If a file descriptor being monitored by select() is closed in another thread, the result is unspecified. On some UNIX sys‐
@@ -242,11 +242,11 @@
242242
243243 The final argument of the pselect6() system call is not a sigset_t * pointer, but is instead a structure of the form:
244244
245− struct {
246− const kernel_sigset_t *ss; /* Pointer to signal set */
247− size_t ss_len; /* Size (in bytes) of object
248− pointed to by 'ss' */
249− };
245+ struct {
246+ const kernel_sigset_t *ss; /* Pointer to signal set */
247+ size_t ss_len; /* Size (in bytes) of object
248+ pointed to by 'ss' */
249+ };
250250
251251 This allows the system call to obtain both a pointer to the signal set and its size, while allowing for the fact that most ar‐
252252 chitectures support a maximum of 6 arguments to a system call. See sigprocmask(2) for a discussion of the difference between
@@ -283,40 +283,40 @@
283283 by internally copying the timeout to a local variable and passing that variable to the system call.
284284
285285EXAMPLES
286− #include <stdio.h>
287− #include <stdlib.h>
288− #include <sys/select.h>
286+ #include <stdio.h>
287+ #include <stdlib.h>
288+ #include <sys/select.h>
289289
290− int
291− main(void)
292− {
293− fd_set rfds;
294− struct timeval tv;
295− int retval;
290+ int
291+ main(void)
292+ {
293+ fd_set rfds;
294+ struct timeval tv;
295+ int retval;
296296
297− /* Watch stdin (fd 0) to see when it has input. */
297+ /* Watch stdin (fd 0) to see when it has input. */
298298
299− FD_ZERO(&rfds);
300− FD_SET(0, &rfds);
299+ FD_ZERO(&rfds);
300+ FD_SET(0, &rfds);
301301
302− /* Wait up to five seconds. */
302+ /* Wait up to five seconds. */
303303
304− tv.tv_sec = 5;
305− tv.tv_usec = 0;
304+ tv.tv_sec = 5;
305+ tv.tv_usec = 0;
306306
307− retval = select(1, &rfds, NULL, NULL, &tv);
308− /* Don't rely on the value of tv now! */
307+ retval = select(1, &rfds, NULL, NULL, &tv);
308+ /* Don't rely on the value of tv now! */
309309
310− if (retval == -1)
311− perror("select()");
312− else if (retval)
313− printf("Data is available now.\n");
314− /* FD_ISSET(0, &rfds) will be true. */
315− else
316− printf("No data within five seconds.\n");
310+ if (retval == -1)
311+ perror("select()");
312+ else if (retval)
313+ printf("Data is available now.\n");
314+ /* FD_ISSET(0, &rfds) will be true. */
315+ else
316+ printf("No data within five seconds.\n");
317317
318− exit(EXIT_SUCCESS);
319− }
318+ exit(EXIT_SUCCESS);
319+ }
320320
321321SEE ALSO
322322 accept(2), connect(2), poll(2), read(2), recv(2), restart_syscall(2), send(2), sigprocmask(2), write(2), epoll(7), time(7)