on master help sign in
End highlighting of C code in man pages when no longer relevant
cfdb853Keith Hall
assets/syntaxes/02_Extra/Manpage.sublime-syntax+14−7
@@ -34,28 +34,30 @@ contexts:
34 scope: markup.heading.title.man
34 scope: markup.heading.title.man
35 - match: \s\s
35 - match: \s\s
36 pop: true
36 pop: true
37− - match: '(?=\S)'
37+ - match: '(?=\S|$)'
38 pop: true
38 pop: true
39
39
40 - match: '$'
40 - match: '$'
41− push: body
41+ set: body
42
42
43 body:
43 body:
44 # English, ..., ..., ..., Russian, ...
44 # English, ..., ..., ..., Russian, ...
45
45
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)'
47 scope: markup.heading.synopsis.man
47 scope: markup.heading.synopsis.man
48 embed: synopsis
48 embed: synopsis
49 escape: '(?={{section_heading}})'
49 escape: '(?={{section_heading}})'
50
50
51+ - match: '^(?:USAGE)'
52+ scope: markup.heading.synopsis.man
53+ embed: synopsis
54+ escape: '(?={{section_heading}})'
51
55
52 - match: '{{section_heading}}'
56 - match: '{{section_heading}}'
53 scope: markup.heading.other.man
57 scope: markup.heading.other.man
54 embed: options # some man pages put command line options under the description heading
58 embed: options # some man pages put command line options under the description heading
55 escape: '(?={{section_heading}})'
59 escape: '(?={{section_heading}})'
56
60
57− - include: function-call
58−
59 function-call:
61 function-call:
60 - match: '\b([A-Za-z0-9_\-]+)(\()([^)]*)(\))'
62 - match: '\b([A-Za-z0-9_\-]+)(\()([^)]*)(\))'
61 captures:
63 captures:
@@ -129,8 +131,12 @@ contexts:
129 pop: true
131 pop: true
130
132
131 c-code:
133 c-code:
132− - match: '^(?=\s+(?:#include|/\*))'
134+ #- match: '^(\s+)(?=#include\b|#define\b|/\*|struct\s+\w+\s*\{)'
135+ - match: '^(?=\s+(?:#include\b|#define\b|/\*|struct\s+(\w+\s*)?\{))'
133− push: scope:source.c
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])))
134
140
135 synopsis:
141 synopsis:
136 - include: c-code
142 - include: c-code
@@ -144,6 +150,7 @@ contexts:
144 captures:
150 captures:
145 1: keyword.operator.logical.man
151 1: keyword.operator.logical.man
146 #- match: (?={{command_line_option}})
152 #- match: (?={{command_line_option}})
153+ - match: \w+-\w+
147 - match: (?=-)
154 - match: (?=-)
148 push:
155 push:
149 - match: (?=\s*\|)
156 - match: (?=\s*\|)
assets/syntaxes/02_Extra/syntax_test_man.man+26−4
@@ -5,7 +5,7 @@ SOMETHING(8) System Manager's Manual SOMETHING(8)
5# ^^^^^^^ meta.preprocessor
5# ^^^^^^^ meta.preprocessor
6
6
7NAME
7NAME
8−#^^^ markup.heading.title
8+#^^^ markup.heading.other
9 example - do something useful
9 example - do something useful
10
10
11SYNOPSIS
11SYNOPSIS
@@ -45,9 +45,16 @@ SYNOPSIS
45 [--quiet] [--debug] [--help|-h] [--version] [--conf FILE]
45 [--quiet] [--debug] [--help|-h] [--version] [--conf FILE]
46
46
47 /* According to POSIX.1-2001, POSIX.1-2008 */
47 /* According to POSIX.1-2001, POSIX.1-2008 */
48−# ^^ source comment.block punctuation.definition.comment
48+# ^^ source.c comment.block punctuation.definition.comment
49 #include <sys/select.h>
49 #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+
51
58
52
59
53DESCRIPTION
60DESCRIPTION
@@ -126,4 +133,19 @@ OPTIONS
126
133
127EXAMPLE
134EXAMPLE
128 #include <stdio.h>
135 #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)
2
2
3NAME
3NAME
4 bat - a cat(1) clone with syntax highlighting and Git integration.
4 bat - a cat(1) clone with syntax highlighting and Git integration.
5
5
6USAGE
6USAGE
7− bat [OPTIONS] [FILE]...
7+ bat [OPTIONS] [FILE]...
8
8
9− bat cache [CACHE-OPTIONS] [--build|--clear]
9+ bat cache [CACHE-OPTIONS] [--build|--clear]
10
10
11DESCRIPTION
11DESCRIPTION
12 bat prints the syntax-highlighted content of a collection of FILEs to
12 bat prints the syntax-highlighted content of a collection of FILEs to
@@ -28,19 +28,19 @@
28 values can be specified as either '--language value', '--lan‐
28 values can be specified as either '--language value', '--lan‐
29 guage=value', '-l value' or '-lvalue'.
29 guage=value', '-l value' or '-lvalue'.
30
30
31− -A, --show-all
31+ -A, --show-all
32
32
33 Show non-printable characters like space, tab or newline. Use
33 Show non-printable characters like space, tab or newline. Use
34 '--tabs' to control the width of the tab-placeholders.
34 '--tabs' to control the width of the tab-placeholders.
35
35
36− -p, --plain
36+ -p, --plain
37
37
38 Only show plain style, no decorations. This is an alias for
38 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‐
40 ables automatic paging (alias for '--style=plain
40 ables automatic paging (alias for '--style=plain
41− --pager=never').
41+ --pager=never').
42
42
43− -l, --language <language>
43+ -l, --language <language>
44
44
45 Explicitly set the language for syntax highlighting. The lan‐
45 Explicitly set the language for syntax highlighting. The lan‐
46 guage can be specified as a name (like 'C++' or 'LaTeX') or pos‐
46 guage can be specified as a name (like 'C++' or 'LaTeX') or pos‐
@@ -65,54 +65,54 @@
65 --highlight-line 40:
65 --highlight-line 40:
66 highlights lines 40 to the end of the file
66 highlights lines 40 to the end of the file
67
67
68− --tabs <T>
68+ --tabs <T>
69
69
70 Set the tab width to T spaces. Use a width of 0 to pass tabs
70 Set the tab width to T spaces. Use a width of 0 to pass tabs
71 through directly
71 through directly
72
72
73− --wrap <mode>
73+ --wrap <mode>
74
74
75 Specify the text-wrapping mode (*auto*, never, character). The
75 Specify the text-wrapping mode (*auto*, never, character). The
76 '--terminal-width' option can be used in addition to control the
76 '--terminal-width' option can be used in addition to control the
77 output width.
77 output width.
78
78
79− --terminal-width <width>
79+ --terminal-width <width>
80
80
81 Explicitly set the width of the terminal instead of determining
81 Explicitly set the width of the terminal instead of determining
82 it automatically. If prefixed with '+' or '-', the value will be
82 it automatically. If prefixed with '+' or '-', the value will be
83 treated as an offset to the actual terminal width. See also:
83 treated as an offset to the actual terminal width. See also:
84 '--wrap'.
84 '--wrap'.
85
85
86− -n, --number
86+ -n, --number
87
87
88 Only show line numbers, no other decorations. This is an alias
88 Only show line numbers, no other decorations. This is an alias
89− for '--style=numbers'
89+ for '--style=numbers'
90
90
91− --color <when>
91+ --color <when>
92
92
93 Specify when to use colored output. The automatic mode only en‐
93 Specify when to use colored output. The automatic mode only en‐
94 ables colors if an interactive terminal is detected. Possible
94 ables colors if an interactive terminal is detected. Possible
95 values: *auto*, never, always.
95 values: *auto*, never, always.
96
96
97− --italic-text <when>
97+ --italic-text <when>
98
98
99 Specify when to use ANSI sequences for italic text in the out‐
99 Specify when to use ANSI sequences for italic text in the out‐
100 put. Possible values: always, *never*.
100 put. Possible values: always, *never*.
101
101
102− --decorations <when>
102+ --decorations <when>
103
103
104 Specify when to use the decorations that have been specified via
104 Specify when to use the decorations that have been specified via
105 '--style'. The automatic mode only enables decorations if an in‐
105 '--style'. The automatic mode only enables decorations if an in‐
106 teractive terminal is detected. Possible values: *auto*, never,
106 teractive terminal is detected. Possible values: *auto*, never,
107 always.
107 always.
108
108
109− -f, --force-colorization
109+ -f, --force-colorization
110
110
111− Alias for '--decorations=always --color=always'. This is useful
111+ Alias for '--decorations=always --color=always'. This is useful
112 if the output of bat is piped to another program, but you want
112 if the output of bat is piped to another program, but you want
113 to keep the colorization/decorations.
113 to keep the colorization/decorations.
114
114
115− --paging <when>
115+ --paging <when>
116
116
117 Specify when to use the pager. To disable the pager, use '--pag‐
117 Specify when to use the pager. To disable the pager, use '--pag‐
118 ing=never' or its alias, -P. To disable the pager permanently,
118 ing=never' or its alias, -P. To disable the pager permanently,
@@ -120,7 +120,7 @@
120 used, see the '--pager' option. Possible values: *auto*, never,
120 used, see the '--pager' option. Possible values: *auto*, never,
121 always.
121 always.
122
122
123− --pager <command>
123+ --pager <command>
124
124
125 Determine which pager is used. This option will override the
125 Determine which pager is used. This option will override the
126 PAGER and BAT_PAGER environment variables. The default pager is
126 PAGER and BAT_PAGER environment variables. The default pager is
@@ -135,24 +135,24 @@
135 '*.build:Python'. To highlight files named '.myignore' with the
135 '*.build:Python'. To highlight files named '.myignore' with the
136 Git Ignore syntax, use -m '.myignore:Git Ignore'.
136 Git Ignore syntax, use -m '.myignore:Git Ignore'.
137
137
138− --theme <theme>
138+ --theme <theme>
139
139
140 Set the theme for syntax highlighting. Use '--list-themes' to
140 Set the theme for syntax highlighting. Use '--list-themes' to
141 see all available themes. To set a default theme, add the
141 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
143 BAT_THEME environment variable (e.g.: export BAT_THEME="...").
143 BAT_THEME environment variable (e.g.: export BAT_THEME="...").
144
144
145 --list-themes
145 --list-themes
146
146
147 Display a list of supported themes for syntax highlighting.
147 Display a list of supported themes for syntax highlighting.
148
148
149− --style <style-components>
149+ --style <style-components>
150
150
151 Configure which elements (line numbers, file headers, grid bor‐
151 Configure which elements (line numbers, file headers, grid bor‐
152 ders, Git modifications, ..) to display in addition to the file
152 ders, Git modifications, ..) to display in addition to the file
153 contents. The argument is a comma-separated list of components
153 contents. The argument is a comma-separated list of components
154 to display (e.g. 'numbers,changes,grid') or a pre-defined style
154 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
156 to the configuration file or export the BAT_STYLE environment
156 to the configuration file or export the BAT_STYLE environment
157 variable (e.g.: export BAT_STYLE=".."). Possible values: *auto*,
157 variable (e.g.: export BAT_STYLE=".."). Possible values: *auto*,
158 full, plain, changes, header, grid, numbers, snip.
158 full, plain, changes, header, grid, numbers, snip.
@@ -171,21 +171,21 @@
171 --line-range 40:
171 --line-range 40:
172 prints lines 40 to the end of the file
172 prints lines 40 to the end of the file
173
173
174− -L, --list-languages
174+ -L, --list-languages
175
175
176 Display a list of supported languages for syntax highlighting.
176 Display a list of supported languages for syntax highlighting.
177
177
178− -u, --unbuffered
178+ -u, --unbuffered
179
179
180 This option exists for POSIX-compliance reasons ('u' is for 'un‐
180 This option exists for POSIX-compliance reasons ('u' is for 'un‐
181 buffered'). The output is always unbuffered - this option is
181 buffered'). The output is always unbuffered - this option is
182 simply ignored.
182 simply ignored.
183
183
184− -h, --help
184+ -h, --help
185
185
186 Print this help message.
186 Print this help message.
187
187
188− -V, --version
188+ -V, --version
189
189
190 Show version information.
190 Show version information.
191
191
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)
2
2
3NAME
3NAME
4 select, pselect, FD_CLR, FD_ISSET, FD_SET, FD_ZERO - synchronous I/O multiplexing
4 select, pselect, FD_CLR, FD_ISSET, FD_SET, FD_ZERO - synchronous I/O multiplexing
@@ -18,9 +18,9 @@
18 fd_set *exceptfds, const struct timespec *timeout,
18 fd_set *exceptfds, const struct timespec *timeout,
19 const sigset_t *sigmask);
19 const sigset_t *sigmask);
20
20
21− Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
21+ Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
22
22
23− pselect(): _POSIX_C_SOURCE >= 200112L
23+ pselect(): _POSIX_C_SOURCE >= 200112L
24
24
25DESCRIPTION
25DESCRIPTION
26 select() allows a program to monitor multiple file descriptors, waiting until one or more of the file descriptors become
26 select() allows a program to monitor multiple file descriptors, waiting until one or more of the file descriptors become
@@ -142,17 +142,17 @@
142 The timeout
142 The timeout
143 The timeout argument for select() is a structure of the following type:
143 The timeout argument for select() is a structure of the following type:
144
144
145− struct timeval {
145+ struct timeval {
146− time_t tv_sec; /* seconds */
146+ time_t tv_sec; /* seconds */
147− suseconds_t tv_usec; /* microseconds */
147+ suseconds_t tv_usec; /* microseconds */
148− };
148+ };
149
149
150 The corresponding argument for pselect() has the following type:
150 The corresponding argument for pselect() has the following type:
151
151
152− struct timespec {
152+ struct timespec {
153− time_t tv_sec; /* seconds */
153+ time_t tv_sec; /* seconds */
154− long tv_nsec; /* nanoseconds */
154+ long tv_nsec; /* nanoseconds */
155− };
155+ };
156
156
157 On Linux, select() modifies timeout to reflect the amount of time not slept; most other implementations do not do this.
157 On Linux, select() modifies timeout to reflect the amount of time not slept; most other implementations do not do this.
158 (POSIX.1 permits either behavior.) This causes problems both when Linux code which reads timeout is ported to other operating
158 (POSIX.1 permits either behavior.) This causes problems both when Linux code which reads timeout is ported to other operating
@@ -213,14 +213,14 @@
213 Within the Linux kernel source, we find the following definitions which show the correspondence between the readable,
213 Within the Linux kernel source, we find the following definitions which show the correspondence between the readable,
214 writable, and exceptional condition notifications of select() and the event notifications provided by poll(2) and epoll(7):
214 writable, and exceptional condition notifications of select() and the event notifications provided by poll(2) and epoll(7):
215
215
216− #define POLLIN_SET (EPOLLRDNORM | EPOLLRDBAND | EPOLLIN |
216+ #define POLLIN_SET (EPOLLRDNORM | EPOLLRDBAND | EPOLLIN |
217− EPOLLHUP | EPOLLERR)
217+ EPOLLHUP | EPOLLERR)
218− /* Ready for reading */
218+ /* Ready for reading */
219− #define POLLOUT_SET (EPOLLWRBAND | EPOLLWRNORM | EPOLLOUT |
219+ #define POLLOUT_SET (EPOLLWRBAND | EPOLLWRNORM | EPOLLOUT |
220− EPOLLERR)
220+ EPOLLERR)
221− /* Ready for writing */
221+ /* Ready for writing */
222− #define POLLEX_SET (EPOLLPRI)
222+ #define POLLEX_SET (EPOLLPRI)
223− /* Exceptional condition */
223+ /* Exceptional condition */
224
224
225 Multithreaded applications
225 Multithreaded applications
226 If a file descriptor being monitored by select() is closed in another thread, the result is unspecified. On some UNIX sys‐
226 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 @@
242
242
243 The final argument of the pselect6() system call is not a sigset_t * pointer, but is instead a structure of the form:
243 The final argument of the pselect6() system call is not a sigset_t * pointer, but is instead a structure of the form:
244
244
245− struct {
245+ struct {
246− const kernel_sigset_t *ss; /* Pointer to signal set */
246+ const kernel_sigset_t *ss; /* Pointer to signal set */
247− size_t ss_len; /* Size (in bytes) of object
247+ size_t ss_len; /* Size (in bytes) of object
248− pointed to by 'ss' */
248+ pointed to by 'ss' */
249− };
249+ };
250
250
251 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‐
251 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‐
252 chitectures support a maximum of 6 arguments to a system call. See sigprocmask(2) for a discussion of the difference between
252 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 @@
283 by internally copying the timeout to a local variable and passing that variable to the system call.
283 by internally copying the timeout to a local variable and passing that variable to the system call.
284
284
285EXAMPLES
285EXAMPLES
286− #include <stdio.h>
286+ #include <stdio.h>
287− #include <stdlib.h>
287+ #include <stdlib.h>
288− #include <sys/select.h>
288+ #include <sys/select.h>
289
289
290− int
290+ int
291− main(void)
291+ main(void)
292− {
292+ {
293− fd_set rfds;
293+ fd_set rfds;
294− struct timeval tv;
294+ struct timeval tv;
295− int retval;
295+ int retval;
296
296
297− /* Watch stdin (fd 0) to see when it has input. */
297+ /* Watch stdin (fd 0) to see when it has input. */
298
298
299− FD_ZERO(&rfds);
299+ FD_ZERO(&rfds);
300− FD_SET(0, &rfds);
300+ FD_SET(0, &rfds);
301
301
302− /* Wait up to five seconds. */
302+ /* Wait up to five seconds. */
303
303
304− tv.tv_sec = 5;
304+ tv.tv_sec = 5;
305− tv.tv_usec = 0;
305+ tv.tv_usec = 0;
306
306
307− retval = select(1, &rfds, NULL, NULL, &tv);
307+ retval = select(1, &rfds, NULL, NULL, &tv);
308− /* Don't rely on the value of tv now! */
308+ /* Don't rely on the value of tv now! */
309
309
310− if (retval == -1)
310+ if (retval == -1)
311− perror("select()");
311+ perror("select()");
312− else if (retval)
312+ else if (retval)
313− printf("Data is available now.\n");
313+ printf("Data is available now.\n");
314− /* FD_ISSET(0, &rfds) will be true. */
314+ /* FD_ISSET(0, &rfds) will be true. */
315− else
315+ else
316− printf("No data within five seconds.\n");
316+ printf("No data within five seconds.\n");
317
317
318− exit(EXIT_SUCCESS);
318+ exit(EXIT_SUCCESS);
319− }
319+ }
320
320
321SEE ALSO
321SEE ALSO
322 accept(2), connect(2), poll(2), read(2), recv(2), restart_syscall(2), send(2), sigprocmask(2), write(2), epoll(7), time(7)
322 accept(2), connect(2), poll(2), read(2), recv(2), restart_syscall(2), send(2), sigprocmask(2), write(2), epoll(7), time(7)