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 scope: markup.heading.title.man
- match: \s\s - match: \s\s
pop: true pop: true
- match: '(?=\S)' - match: '(?=\S|$)'
pop: true pop: true
- match: '$' - match: '$'
push: body set: body
body: body:
# English, ..., ..., ..., Russian, ... # 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 scope: markup.heading.synopsis.man
embed: synopsis embed: synopsis
escape: '(?={{section_heading}})' escape: '(?={{section_heading}})'
- match: '^(?:USAGE)'
scope: markup.heading.synopsis.man
embed: synopsis
escape: '(?={{section_heading}})'
- match: '{{section_heading}}' - match: '{{section_heading}}'
scope: markup.heading.other.man scope: markup.heading.other.man
embed: options # some man pages put command line options under the description heading embed: options # some man pages put command line options under the description heading
escape: '(?={{section_heading}})' escape: '(?={{section_heading}})'
- include: function-call
function-call: function-call:
- match: '\b([A-Za-z0-9_\-]+)(\()([^)]*)(\))' - match: '\b([A-Za-z0-9_\-]+)(\()([^)]*)(\))'
captures: captures:
@ -129,8 +131,12 @@ contexts:
pop: true pop: true
c-code: c-code:
- match: '^(?=\s+(?:#include|/\*))' #- match: '^(\s+)(?=#include\b|#define\b|/\*|struct\s+\w+\s*\{)'
push: scope:source.c - 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: synopsis:
- include: c-code - include: c-code
@ -144,6 +150,7 @@ contexts:
captures: captures:
1: keyword.operator.logical.man 1: keyword.operator.logical.man
#- match: (?={{command_line_option}}) #- match: (?={{command_line_option}})
- match: \w+-\w+
- match: (?=-) - match: (?=-)
push: push:
- match: (?=\s*\|) - match: (?=\s*\|)

View File

@ -5,7 +5,7 @@ SOMETHING(8) System Manager's Manual SOMETHING(8)
# ^^^^^^^ meta.preprocessor # ^^^^^^^ meta.preprocessor
NAME NAME
#^^^ markup.heading.title #^^^ markup.heading.other
example - do something useful example - do something useful
SYNOPSIS SYNOPSIS
@ -45,9 +45,16 @@ SYNOPSIS
[--quiet] [--debug] [--help|-h] [--version] [--conf FILE] [--quiet] [--debug] [--help|-h] [--version] [--conf FILE]
/* According to POSIX.1-2001, POSIX.1-2008 */ /* 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> #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 DESCRIPTION
@ -126,4 +133,19 @@ OPTIONS
EXAMPLE EXAMPLE
#include <stdio.h> #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 NAME
 bat - a cat(1) clone with syntax highlighting and Git integration.  bat - a cat(1) clone with syntax highlighting and Git integration.
USAGE USAGE
 bat [OPTIONS] [FILE]...  bat [OPTIONS] [FILE]...
 bat cache [CACHE-OPTIONS] [--build|--clear]  bat cache [CACHE-OPTIONS] [--build|--clear]
DESCRIPTION DESCRIPTION
 bat prints the syntax-highlighted content of a collection of FILEs to  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  values can be specified as either '--language value', '--lan
 guage=value', '-l value' or '-lvalue'.  guage=value', '-l value' or '-lvalue'.
 -A, --show-all  -A, --show-all
 Show non-printable characters like space, tab or newline. Use  Show non-printable characters like space, tab or newline. Use
 '--tabs' to control the width of the tab-placeholders.  '--tabs' to control the width of the tab-placeholders.
 -p, --plain  -p, --plain
 Only show plain style, no decorations. This is an alias for  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  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  Explicitly set the language for syntax highlighting. The lan
 guage can be specified as a name (like 'C++' or 'LaTeX') or pos  guage can be specified as a name (like 'C++' or 'LaTeX') or pos
@ -65,54 +65,54 @@
 --highlight-line 40:  --highlight-line 40:
 highlights lines 40 to the end of the file  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  Set the tab width to T spaces. Use a width of 0 to pass tabs
 through directly  through directly
 --wrap <mode>  --wrap <mode>
 Specify the text-wrapping mode (*auto*, never, character). The  Specify the text-wrapping mode (*auto*, never, character). The
 '--terminal-width' option can be used in addition to control the  '--terminal-width' option can be used in addition to control the
 output width.  output width.
 --terminal-width <width>  --terminal-width <width>
 Explicitly set the width of the terminal instead of determining  Explicitly set the width of the terminal instead of determining
 it automatically. If prefixed with '+' or '-', the value will be  it automatically. If prefixed with '+' or '-', the value will be
 treated as an offset to the actual terminal width. See also:  treated as an offset to the actual terminal width. See also:
 '--wrap'.  '--wrap'.
 -n, --number  -n, --number
 Only show line numbers, no other decorations. This is an alias  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  Specify when to use colored output. The automatic mode only en
 ables colors if an interactive terminal is detected. Possible  ables colors if an interactive terminal is detected. Possible
 values: *auto*, never, always.  values: *auto*, never, always.
 --italic-text <when>  --italic-text <when>
 Specify when to use ANSI sequences for italic text in the out  Specify when to use ANSI sequences for italic text in the out
 put. Possible values: always, *never*.  put. Possible values: always, *never*.
 --decorations <when>  --decorations <when>
 Specify when to use the decorations that have been specified via  Specify when to use the decorations that have been specified via
 '--style'. The automatic mode only enables decorations if an in  '--style'. The automatic mode only enables decorations if an in
 teractive terminal is detected. Possible values: *auto*, never,  teractive terminal is detected. Possible values: *auto*, never,
 always.  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  if the output of bat is piped to another program, but you want
 to keep the colorization/decorations.  to keep the colorization/decorations.
 --paging <when>  --paging <when>
 Specify when to use the pager. To disable the pager, use '--pag  Specify when to use the pager. To disable the pager, use '--pag
 ing=never' or its alias, -P. To disable the pager permanently,  ing=never' or its alias, -P. To disable the pager permanently,
@ -120,7 +120,7 @@
 used, see the '--pager' option. Possible values: *auto*, never,  used, see the '--pager' option. Possible values: *auto*, never,
 always.  always.
 --pager <command>  --pager <command>
 Determine which pager is used. This option will override the  Determine which pager is used. This option will override the
 PAGER and BAT_PAGER environment variables. The default pager is  PAGER and BAT_PAGER environment variables. The default pager is
@ -135,24 +135,24 @@
 '*.build:Python'. To highlight files named '.myignore' with the  '*.build:Python'. To highlight files named '.myignore' with the
 Git Ignore syntax, use -m '.myignore:Git Ignore'.  Git Ignore syntax, use -m '.myignore:Git Ignore'.
 --theme <theme>  --theme <theme>
 Set the theme for syntax highlighting. Use '--list-themes' to  Set the theme for syntax highlighting. Use '--list-themes' to
 see all available themes. To set a default theme, add the  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="...").  BAT_THEME environment variable (e.g.: export BAT_THEME="...").
 --list-themes  --list-themes
 Display a list of supported themes for syntax highlighting.  Display a list of supported themes for syntax highlighting.
 --style <style-components>  --style <style-components>
 Configure which elements (line numbers, file headers, grid bor  Configure which elements (line numbers, file headers, grid bor
 ders, Git modifications, ..) to display in addition to the file  ders, Git modifications, ..) to display in addition to the file
 contents. The argument is a comma-separated list of components  contents. The argument is a comma-separated list of components
 to display (e.g. 'numbers,changes,grid') or a pre-defined style  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  to the configuration file or export the BAT_STYLE environment
 variable (e.g.: export BAT_STYLE=".."). Possible values: *auto*,  variable (e.g.: export BAT_STYLE=".."). Possible values: *auto*,
 full, plain, changes, header, grid, numbers, snip.  full, plain, changes, header, grid, numbers, snip.
@ -171,21 +171,21 @@
 --line-range 40:  --line-range 40:
 prints lines 40 to the end of the file  prints lines 40 to the end of the file
 -L, --list-languages  -L, --list-languages
 Display a list of supported languages for syntax highlighting.  Display a list of supported languages for syntax highlighting.
 -u, --unbuffered  -u, --unbuffered
 This option exists for POSIX-compliance reasons ('u' is for 'un  This option exists for POSIX-compliance reasons ('u' is for 'un
 buffered'). The output is always unbuffered - this option is  buffered'). The output is always unbuffered - this option is
 simply ignored.  simply ignored.
 -h, --help  -h, --help
 Print this help message.  Print this help message.
 -V, --version  -V, --version
 Show version information.  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 NAME
 select, pselect, FD_CLR, FD_ISSET, FD_SET, FD_ZERO - synchronous I/O multiplexing  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,  fd_set *exceptfds, const struct timespec *timeout,
 const sigset_t *sigmask);  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 DESCRIPTION
 select() allows a program to monitor multiple file descriptors, waiting until one or more of the file descriptors become  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
 The timeout argument for select() is a structure of the following type:  The timeout argument for select() is a structure of the following type:
 struct timeval {  struct timeval {
 time_t tv_sec; /* seconds */  time_t tv_sec; /* seconds */
 suseconds_t tv_usec; /* microseconds */  suseconds_t tv_usec; /* microseconds */
 };  };
 The corresponding argument for pselect() has the following type:  The corresponding argument for pselect() has the following type:
 struct timespec {  struct timespec {
 time_t tv_sec; /* seconds */  time_t tv_sec; /* seconds */
 long tv_nsec; /* nanoseconds */  long tv_nsec; /* nanoseconds */
 };  };
 On Linux, select() modifies timeout to reflect the amount of time not slept; most other implementations do not do this.  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  (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,  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):  writable, and exceptional condition notifications of select() and the event notifications provided by poll(2) and epoll(7):
 #define POLLIN_SET (EPOLLRDNORM | EPOLLRDBAND | EPOLLIN |  #define POLLIN_SET (EPOLLRDNORM | EPOLLRDBAND | EPOLLIN |
 EPOLLHUP | EPOLLERR)  EPOLLHUP | EPOLLERR)
 /* Ready for reading */  /* Ready for reading */
 #define POLLOUT_SET (EPOLLWRBAND | EPOLLWRNORM | EPOLLOUT |  #define POLLOUT_SET (EPOLLWRBAND | EPOLLWRNORM | EPOLLOUT |
 EPOLLERR)  EPOLLERR)
 /* Ready for writing */  /* Ready for writing */
 #define POLLEX_SET (EPOLLPRI)  #define POLLEX_SET (EPOLLPRI)
 /* Exceptional condition */  /* Exceptional condition */
 Multithreaded applications  Multithreaded applications
 If a file descriptor being monitored by select() is closed in another thread, the result is unspecified. On some UNIX sys  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:  The final argument of the pselect6() system call is not a sigset_t * pointer, but is instead a structure of the form:
 struct {  struct {
 const kernel_sigset_t *ss; /* Pointer to signal set */  const kernel_sigset_t *ss; /* Pointer to signal set */
 size_t ss_len; /* Size (in bytes) of object  size_t ss_len; /* Size (in bytes) of object
 pointed to by 'ss' */  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  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  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.  by internally copying the timeout to a local variable and passing that variable to the system call.
EXAMPLES EXAMPLES
 #include <stdio.h>  #include <stdio.h>
 #include <stdlib.h>  #include <stdlib.h>
 #include <sys/select.h>  #include <sys/select.h>
 int  int
 main(void)  main(void)
 {  {
 fd_set rfds;  fd_set rfds;
 struct timeval tv;  struct timeval tv;
 int retval;  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_ZERO(&rfds);
 FD_SET(0, &rfds);  FD_SET(0, &rfds);
 /* Wait up to five seconds. */  /* Wait up to five seconds. */
 tv.tv_sec = 5;  tv.tv_sec = 5;
 tv.tv_usec = 0;  tv.tv_usec = 0;
 retval = select(1, &rfds, NULL, NULL, &tv);  retval = select(1, &rfds, NULL, NULL, &tv);
 /* Don't rely on the value of tv now! */  /* Don't rely on the value of tv now! */
 if (retval == -1)  if (retval == -1)
 perror("select()");  perror("select()");
 else if (retval)  else if (retval)
 printf("Data is available now.\n");  printf("Data is available now.\n");
 /* FD_ISSET(0, &rfds) will be true. */  /* FD_ISSET(0, &rfds) will be true. */
 else  else
 printf("No data within five seconds.\n");  printf("No data within five seconds.\n");
 exit(EXIT_SUCCESS);  exit(EXIT_SUCCESS);
 }  }
SEE ALSO 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)  accept(2), connect(2), poll(2), read(2), recv(2), restart_syscall(2), send(2), sigprocmask(2), write(2), epoll(7), time(7)