End highlighting of C code in man pages when no longer relevant

This commit is contained in:
Keith Hall 2020-10-19 11:24:15 +03:00 committed by David Peter
parent 41e857ea16
commit cfdb853ea6
4 changed files with 118 additions and 89 deletions

View File

@ -34,28 +34,30 @@ contexts:
scope: markup.heading.title.man
- match: \s\s
pop: true
- match: '(?=\S)'
- match: '(?=\S|$)'
pop: true
- match: '$'
push: body
set: body
body:
# English, ..., ..., ..., Russian, ...
- match: '^(?:SYNOPSIS|SYNTAX|SINTASSI|SKŁADNIA|СИНТАКСИС|書式)'
- match: '^(?:SYNOPSIS|SYNTAX|SINTASSI|SK\u0141ADNIA|\u0421\u0418\u041d\u0422\u0410\u041a\u0421\u0418\u0421|\u66f8\u5f0f)'
scope: markup.heading.synopsis.man
embed: synopsis
escape: '(?={{section_heading}})'
- match: '^(?:USAGE)'
scope: markup.heading.synopsis.man
embed: synopsis
escape: '(?={{section_heading}})'
- match: '{{section_heading}}'
scope: markup.heading.other.man
embed: options # some man pages put command line options under the description heading
escape: '(?={{section_heading}})'
- include: function-call
function-call:
- match: '\b([A-Za-z0-9_\-]+)(\()([^)]*)(\))'
captures:
@ -129,8 +131,12 @@ contexts:
pop: true
c-code:
- match: '^(?=\s+(?:#include|/\*))'
push: scope:source.c
#- match: '^(\s+)(?=#include\b|#define\b|/\*|struct\s+\w+\s*\{)'
- match: '^(?=\s+(?:#include\b|#define\b|/\*|struct\s+(\w+\s*)?\{))'
embed: scope:source.c
#embed_scope: source.c.embedded.man
#escape: ^(?!#|\1|\s*(?:$|/\*|#include\b|#define\b))
escape: ^(?=\s*(?:\(.*\.\)\s*$|[A-Z](?![A-Z])))
synopsis:
- include: c-code
@ -144,6 +150,7 @@ contexts:
captures:
1: keyword.operator.logical.man
#- match: (?={{command_line_option}})
- match: \w+-\w+
- match: (?=-)
push:
- match: (?=\s*\|)

View File

@ -5,7 +5,7 @@ SOMETHING(8) System Manager's Manual SOMETHING(8)
# ^^^^^^^ meta.preprocessor
NAME
#^^^ markup.heading.title
#^^^ markup.heading.other
example - do something useful
SYNOPSIS
@ -45,9 +45,16 @@ SYNOPSIS
[--quiet] [--debug] [--help|-h] [--version] [--conf FILE]
/* According to POSIX.1-2001, POSIX.1-2008 */
# ^^ source comment.block punctuation.definition.comment
# ^^ source.c comment.block punctuation.definition.comment
#include <sys/select.h>
# ^^^^^^^^ source meta.preprocessor.include keyword.control.import.include
# ^^^^^^^^ source.c meta.preprocessor.include keyword.control.import.include
struct timeval {
# ^^^^^^ source.c storage.type
time_t tv_sec; /* seconds */
suseconds_t tv_usec; /* microseconds */
};
DESCRIPTION
@ -126,4 +133,19 @@ OPTIONS
EXAMPLE
#include <stdio.h>
# ^^^^^^^^ source meta.preprocessor.include keyword.control.import.include
# ^^^^^^^^ source.c meta.preprocessor.include keyword.control.import.include
(This is not C code.)
# ^^^^^^^^^^^^^^^^^^^^^^ - source.c
struct timeval {
time_t tv_sec; /* seconds */
suseconds_t tv_usec; /* microseconds */
};
# ^ source.c punctuation.terminator
The corresponding argument for pselect() has the following type:
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - source.c
#define POLLIN_SET (EPOLLRDNORM | EPOLLRDBAND | EPOLLIN |
EPOLLHUP | EPOLLERR)
# ^ source.c meta.preprocessor.macro meta.group punctuation.section.group.end

View File

@ -1,12 +1,12 @@
BAT(1) General Commands Manual BAT(1)
BAT(1) General Commands Manual BAT(1)
NAME
 bat - a cat(1) clone with syntax highlighting and Git integration.
USAGE
 bat [OPTIONS] [FILE]...
 bat [OPTIONS] [FILE]...
 bat cache [CACHE-OPTIONS] [--build|--clear]
 bat cache [CACHE-OPTIONS] [--build|--clear]
DESCRIPTION
 bat prints the syntax-highlighted content of a collection of FILEs to
@ -28,19 +28,19 @@
 values can be specified as either '--language value', '--lan
 guage=value', '-l value' or '-lvalue'.
 -A, --show-all
 -A, --show-all
 Show non-printable characters like space, tab or newline. Use
 '--tabs' to control the width of the tab-placeholders.
 -p, --plain
 -p, --plain
 Only show plain style, no decorations. This is an alias for
 '--style=plain'. When '-p' is used twice ('-pp'), it also dis
 '--style=plain'. When '-p' is used twice ('-pp'), it also dis
 ables automatic paging (alias for '--style=plain
 --pager=never').
 --pager=never').
 -l, --language <language>
 -l, --language <language>
 Explicitly set the language for syntax highlighting. The lan
 guage can be specified as a name (like 'C++' or 'LaTeX') or pos
@ -65,54 +65,54 @@
 --highlight-line 40:
 highlights lines 40 to the end of the file
 --tabs <T>
 --tabs <T>
 Set the tab width to T spaces. Use a width of 0 to pass tabs
 through directly
 --wrap <mode>
 --wrap <mode>
 Specify the text-wrapping mode (*auto*, never, character). The
 '--terminal-width' option can be used in addition to control the
 output width.
 --terminal-width <width>
 --terminal-width <width>
 Explicitly set the width of the terminal instead of determining
 it automatically. If prefixed with '+' or '-', the value will be
 treated as an offset to the actual terminal width. See also:
 '--wrap'.
 -n, --number
 -n, --number
 Only show line numbers, no other decorations. This is an alias
 for '--style=numbers'
 for '--style=numbers'
 --color <when>
 --color <when>
 Specify when to use colored output. The automatic mode only en
 ables colors if an interactive terminal is detected. Possible
 values: *auto*, never, always.
 --italic-text <when>
 --italic-text <when>
 Specify when to use ANSI sequences for italic text in the out
 put. Possible values: always, *never*.
 --decorations <when>
 --decorations <when>
 Specify when to use the decorations that have been specified via
 '--style'. The automatic mode only enables decorations if an in
 teractive terminal is detected. Possible values: *auto*, never,
 always.
 -f, --force-colorization
 -f, --force-colorization
 Alias for '--decorations=always --color=always'. This is useful
 Alias for '--decorations=always --color=always'. This is useful
 if the output of bat is piped to another program, but you want
 to keep the colorization/decorations.
 --paging <when>
 --paging <when>
 Specify when to use the pager. To disable the pager, use '--pag
 ing=never' or its alias, -P. To disable the pager permanently,
@ -120,7 +120,7 @@
 used, see the '--pager' option. Possible values: *auto*, never,
 always.
 --pager <command>
 --pager <command>
 Determine which pager is used. This option will override the
 PAGER and BAT_PAGER environment variables. The default pager is
@ -135,24 +135,24 @@
 '*.build:Python'. To highlight files named '.myignore' with the
 Git Ignore syntax, use -m '.myignore:Git Ignore'.
 --theme <theme>
 --theme <theme>
 Set the theme for syntax highlighting. Use '--list-themes' to
 see all available themes. To set a default theme, add the
 '--theme="..."' option to the configuration file or export the
 '--theme="..."' option to the configuration file or export the
 BAT_THEME environment variable (e.g.: export BAT_THEME="...").
 --list-themes
 Display a list of supported themes for syntax highlighting.
 --style <style-components>
 --style <style-components>
 Configure which elements (line numbers, file headers, grid bor
 ders, Git modifications, ..) to display in addition to the file
 contents. The argument is a comma-separated list of components
 to display (e.g. 'numbers,changes,grid') or a pre-defined style
 ('full'). To set a default style, add the '--style=".."' option
 ('full'). To set a default style, add the '--style=".."' option
 to the configuration file or export the BAT_STYLE environment
 variable (e.g.: export BAT_STYLE=".."). Possible values: *auto*,
 full, plain, changes, header, grid, numbers, snip.
@ -171,21 +171,21 @@
 --line-range 40:
 prints lines 40 to the end of the file
 -L, --list-languages
 -L, --list-languages
 Display a list of supported languages for syntax highlighting.
 -u, --unbuffered
 -u, --unbuffered
 This option exists for POSIX-compliance reasons ('u' is for 'un
 buffered'). The output is always unbuffered - this option is
 simply ignored.
 -h, --help
 -h, --help
 Print this help message.
 -V, --version
 -V, --version
 Show version information.

View File

@ -1,4 +1,4 @@
SELECT(2) Linux Programmer's Manual SELECT(2)
SELECT(2) Linux Programmer's Manual SELECT(2)
NAME
 select, pselect, FD_CLR, FD_ISSET, FD_SET, FD_ZERO - synchronous I/O multiplexing
@ -18,9 +18,9 @@
 fd_set *exceptfds, const struct timespec *timeout,
 const sigset_t *sigmask);
 Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
 Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
 pselect(): _POSIX_C_SOURCE >= 200112L
 pselect(): _POSIX_C_SOURCE >= 200112L
DESCRIPTION
 select() allows a program to monitor multiple file descriptors, waiting until one or more of the file descriptors become
@ -142,17 +142,17 @@
 The timeout
 The timeout argument for select() is a structure of the following type:
 struct timeval {
 time_t tv_sec; /* seconds */
 suseconds_t tv_usec; /* microseconds */
 };
 struct timeval {
 time_t tv_sec; /* seconds */
 suseconds_t tv_usec; /* microseconds */
 };
 The corresponding argument for pselect() has the following type:
 struct timespec {
 time_t tv_sec; /* seconds */
 long tv_nsec; /* nanoseconds */
 };
 struct timespec {
 time_t tv_sec; /* seconds */
 long tv_nsec; /* nanoseconds */
 };
 On Linux, select() modifies timeout to reflect the amount of time not slept; most other implementations do not do this.
 (POSIX.1 permits either behavior.) This causes problems both when Linux code which reads timeout is ported to other operating
@ -213,14 +213,14 @@
 Within the Linux kernel source, we find the following definitions which show the correspondence between the readable,
 writable, and exceptional condition notifications of select() and the event notifications provided by poll(2) and epoll(7):
 #define POLLIN_SET (EPOLLRDNORM | EPOLLRDBAND | EPOLLIN |
 EPOLLHUP | EPOLLERR)
 /* Ready for reading */
 #define POLLOUT_SET (EPOLLWRBAND | EPOLLWRNORM | EPOLLOUT |
 EPOLLERR)
 /* Ready for writing */
 #define POLLEX_SET (EPOLLPRI)
 /* Exceptional condition */
 #define POLLIN_SET (EPOLLRDNORM | EPOLLRDBAND | EPOLLIN |
 EPOLLHUP | EPOLLERR)
 /* Ready for reading */
 #define POLLOUT_SET (EPOLLWRBAND | EPOLLWRNORM | EPOLLOUT |
 EPOLLERR)
 /* Ready for writing */
 #define POLLEX_SET (EPOLLPRI)
 /* Exceptional condition */
 Multithreaded applications
 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 @@
 The final argument of the pselect6() system call is not a sigset_t * pointer, but is instead a structure of the form:
 struct {
 const kernel_sigset_t *ss; /* Pointer to signal set */
 size_t ss_len; /* Size (in bytes) of object
 pointed to by 'ss' */
 };
 struct {
 const kernel_sigset_t *ss; /* Pointer to signal set */
 size_t ss_len; /* Size (in bytes) of object
 pointed to by 'ss' */
 };
 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
 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 @@
 by internally copying the timeout to a local variable and passing that variable to the system call.
EXAMPLES
 #include <stdio.h>
 #include <stdlib.h>
 #include <sys/select.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <sys/select.h>
 int
 main(void)
 {
 fd_set rfds;
 struct timeval tv;
 int retval;
 int
 main(void)
 {
 fd_set rfds;
 struct timeval tv;
 int retval;
 /* Watch stdin (fd 0) to see when it has input. */
 /* Watch stdin (fd 0) to see when it has input. */
 FD_ZERO(&rfds);
 FD_SET(0, &rfds);
 FD_ZERO(&rfds);
 FD_SET(0, &rfds);
 /* Wait up to five seconds. */
 /* Wait up to five seconds. */
 tv.tv_sec = 5;
 tv.tv_usec = 0;
 tv.tv_sec = 5;
 tv.tv_usec = 0;
 retval = select(1, &rfds, NULL, NULL, &tv);
 /* Don't rely on the value of tv now! */
 retval = select(1, &rfds, NULL, NULL, &tv);
 /* Don't rely on the value of tv now! */
 if (retval == -1)
 perror("select()");
 else if (retval)
 printf("Data is available now.\n");
 /* FD_ISSET(0, &rfds) will be true. */
 else
 printf("No data within five seconds.\n");
 if (retval == -1)
 perror("select()");
 else if (retval)
 printf("Data is available now.\n");
 /* FD_ISSET(0, &rfds) will be true. */
 else
 printf("No data within five seconds.\n");
 exit(EXIT_SUCCESS);
 }
 exit(EXIT_SUCCESS);
 }
SEE ALSO
 accept(2), connect(2), poll(2), read(2), recv(2), restart_syscall(2), send(2), sigprocmask(2), write(2), epoll(7), time(7)