Data Structures | Macros | Typedefs | Enumerations | Functions | Variables
syntax.c File Reference
#include <assert.h>
#include <ctype.h>
#include <inttypes.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include "nvim/api/private/helpers.h"
#include "nvim/ascii.h"
#include "nvim/buffer.h"
#include "nvim/charset.h"
#include "nvim/cursor_shape.h"
#include "nvim/eval.h"
#include "nvim/ex_cmds2.h"
#include "nvim/ex_docmd.h"
#include "nvim/fileio.h"
#include "nvim/fold.h"
#include "nvim/garray.h"
#include "nvim/hashtab.h"
#include "nvim/highlight.h"
#include "nvim/indent_c.h"
#include "nvim/keymap.h"
#include "nvim/macros.h"
#include "nvim/mbyte.h"
#include "nvim/memline.h"
#include "nvim/memory.h"
#include "nvim/message.h"
#include "nvim/misc1.h"
#include "nvim/option.h"
#include "nvim/os/os.h"
#include "nvim/os/time.h"
#include "nvim/os_unix.h"
#include "nvim/path.h"
#include "nvim/regexp.h"
#include "nvim/screen.h"
#include "nvim/sign.h"
#include "nvim/strings.h"
#include "nvim/syntax.h"
#include "nvim/syntax_defs.h"
#include "nvim/terminal.h"
#include "nvim/ui.h"
#include "nvim/vim.h"

Data Structures

struct  hl_group
struct  syn_pattern
struct  syn_cluster_S
struct  state_item
struct  syn_opt_arg_T
struct  time_entry_T
struct  name_list
struct  subcommand


#define SG_CTERM   2
#define SG_GUI   4
#define SG_LINK   8
#define MAX_HL_ID   20000
#define SPO_MS_OFF   0
#define SPO_ME_OFF   1
#define SPO_HS_OFF   2
#define SPO_HE_OFF   3
#define SPO_RS_OFF   4
#define SPO_RE_OFF   5
#define SPO_LC_OFF   6
#define SPO_COUNT   7
#define SPTYPE_MATCH   1
#define SPTYPE_START   2
#define SPTYPE_END   3
#define SPTYPE_SKIP   4
#define SYN_ITEMS(buf)   ((synpat_T *)((buf)->b_syn_patterns.ga_data))
#define NONE_IDX   -2
#define SF_CCOMMENT   0x01
#define SF_MATCH   0x02
#define SYN_STATE_P(ssp)   ((bufstate_T *)((ssp)->ga_data))
#define MAXKEYWLEN   80
#define CLUSTER_ADD   2
#define SYN_CLSTR(buf)   ((syn_cluster_T *)((buf)->b_syn_clusters.ga_data))
#define SYNID_TOP   21000
#define SYNID_CONTAINED   22000
#define SYNID_CLUSTER   23000
#define MAX_SYN_INC_TAG   999
#define MAX_CLUSTER_ID   (32767 - SYNID_CLUSTER)
#define KE2HIKEY(kp)   ((kp)->keyword)
#define HIKEY2KE(p)   ((keyentry_T *)((p) - (dumkey.keyword - (char_u *)&dumkey)))
#define HI2KE(hi)   HIKEY2KE((hi)->hi_key)
#define KEYWORD_IDX   -1
#define ID_LIST_ALL   (int16_t *)-1
#define INVALID_STATE(ssp)   ((ssp)->ga_itemsize == 0)
#define VALID_STATE(ssp)   ((ssp)->ga_itemsize != 0)
#define CUR_STATE(idx)   ((stateitem_T *)(current_state.ga_data))[idx]
#define IF_SYN_TIME(p)   (p)
#define UNREF_BUFSTATE_EXTMATCH(bs)   unref_extmatch((bs)->bs_extmatch)
#define UNREF_STATEITEM_EXTMATCH(si)   unref_extmatch((si)->si_extmatch)
#define ITEM_START   0
#define ITEM_SKIP   1
#define ITEM_END   2
#define LIST_ATTR   1
#define LIST_STRING   2
#define LIST_INT   3


typedef struct hl_group HlGroup
typedef struct syn_pattern synpat_T
typedef struct syn_cluster_S syn_cluster_T
typedef struct state_item stateitem_T




 Map (cstr_t, int)
void syn_set_timeout (proftime_T *tm)
void syntax_start (win_T *wp, linenr_T lnum)
void syn_stack_free_all (synblock_T *block)
void syn_stack_apply_changes (buf_T *buf)
void syntax_end_parsing (linenr_T lnum)
bool syntax_check_changed (linenr_T lnum)
int get_syntax_attr (const colnr_T col, bool *const can_spell, const bool keep_state)
void syntax_clear (synblock_T *block)
void reset_synblock (win_T *wp)
void syn_maybe_enable (void)
void ex_syntax (exarg_T *eap)
void ex_ownsyntax (exarg_T *eap)
bool syntax_present (win_T *win)
void reset_expand_highlight (void)
void set_context_in_echohl_cmd (expand_T *xp, const char *arg)
void set_context_in_syntax_cmd (expand_T *xp, const char *arg)
char_uget_syntax_name (expand_T *xp, int idx)
int syn_get_id (win_T *wp, long lnum, colnr_T col, int trans, bool *spellp, int keep_state)
int get_syntax_info (int *seqnrp)
int syn_get_concealed_id (win_T *wp, linenr_T lnum, colnr_T col)
int syn_get_sub_char (void)
int syn_get_stack_item (int i)
int syn_get_foldlevel (win_T *wp, long lnum)
void ex_syntime (exarg_T *eap)
char_uget_syntime_arg (expand_T *xp, int idx)
void syn_init_cmdline_highlight (bool reset, bool init)
 Create default links for Nvim* highlight groups used for cmdline coloring. More...
void init_highlight (bool both, bool reset)
int load_colors (char_u *name)
int lookup_color (const int idx, const bool foreground, TriState *const boldp)
void do_highlight (const char *line, const bool forceit, const bool init) FUNC_ATTR_NONNULL_ALL
void restore_cterm_colors (void)
Dictionary get_global_hl_defs (void)
const char * highlight_has_attr (const int id, const int flag, const int modec) FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_PURE
const char * highlight_color (const int id, const char *const what, const int modec) FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL
int syn_name2id (const char *name) FUNC_ATTR_NONNULL_ALL
int syn_name2id_len (const char_u *name, size_t len) FUNC_ATTR_NONNULL_ALL
int syn_name2attr (const char_u *name) FUNC_ATTR_NONNULL_ALL
int highlight_exists (const char *name)
char_usyn_id2name (int id)
int syn_check_group (const char *name, int len)
int syn_id2attr (int hl_id)
int syn_get_final_id (int hl_id)
void highlight_attr_set_all (void)
 Refresh the color attributes of all highlight groups. More...
void highlight_changed (void)
void set_context_in_highlight_cmd (expand_T *xp, const char *arg)
const char * get_highlight_name (expand_T *const xp, int idx) FUNC_ATTR_WARN_UNUSED_RESULT
 Function given to ExpandGeneric() to obtain the list of group names. More...
const char * get_highlight_name_ext (expand_T *xp, int idx, bool skip_cleared) FUNC_ATTR_WARN_UNUSED_RESULT
RgbValue name_to_color (const char *name)


const char *const highlight_init_cmdline []
 Array of highlight definitions, used for unit testing. More...
color_name_table_T color_name_table []

Macro Definition Documentation


#define CLUSTER_ADD   2






#define CUR_STATE (   idx)    ((stateitem_T *)(current_state.ga_data))[idx]


#define HI2KE (   hi)    HIKEY2KE((hi)->hi_key)


#define HIKEY2KE (   p)    ((keyentry_T *)((p) - (dumkey.keyword - (char_u *)&dumkey)))


#define ID_LIST_ALL   (int16_t *)-1


#define IF_SYN_TIME (   p)    (p)


#define INVALID_STATE (   ssp)    ((ssp)->ga_itemsize == 0)


#define ITEM_END   2




#define ITEM_SKIP   1


#define ITEM_START   0


#define KE2HIKEY (   kp)    ((kp)->keyword)


#define KEYWORD_IDX   -1


#define MAX_CLUSTER_ID   (32767 - SYNID_CLUSTER)


#define MAX_HL_ID   20000


#define MAX_SYN_INC_TAG   999


#define MAXKEYWLEN   80


#define NONE_IDX   -2


#define SF_CCOMMENT   0x01


#define SF_MATCH   0x02


#define SPO_COUNT   7


#define SPO_HE_OFF   3


#define SPO_HS_OFF   2


#define SPO_LC_OFF   6


#define SPO_ME_OFF   1


#define SPO_MS_OFF   0


#define SPO_RE_OFF   5


#define SPO_RS_OFF   4


#define SPTYPE_END   3


#define SPTYPE_MATCH   1


#define SPTYPE_SKIP   4


#define SPTYPE_START   2


#define SYN_CLSTR (   buf)    ((syn_cluster_T *)((buf)->b_syn_clusters.ga_data))


#define SYN_ITEMS (   buf)    ((synpat_T *)((buf)->b_syn_patterns.ga_data))


#define SYN_STATE_P (   ssp)    ((bufstate_T *)((ssp)->ga_data))




#define SYNID_CLUSTER   23000


#define SYNID_CONTAINED   22000


#define SYNID_TOP   21000


#define UNREF_BUFSTATE_EXTMATCH (   bs)    unref_extmatch((bs)->bs_extmatch)


#define UNREF_STATEITEM_EXTMATCH (   si)    unref_extmatch((si)->si_extmatch)


#define VALID_STATE (   ssp)    ((ssp)->ga_itemsize != 0)

Typedef Documentation

◆ HlGroup

typedef struct hl_group HlGroup

Structure that stores information about a highlight group. The ID of a highlight group is also called group ID. It is the index in the highlight_ga array PLUS ONE.

◆ stateitem_T

typedef struct state_item stateitem_T

◆ syn_cluster_T

typedef struct syn_cluster_S syn_cluster_T

◆ synpat_T

typedef struct syn_pattern synpat_T

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

Function Documentation

◆ do_highlight()

void do_highlight ( const char *  line,
const bool  forceit,
const bool  init 

Handle ":highlight" command

When using ":highlight clear" this is called recursively for each group with forceit and init being both true.

[in]lineCommand arguments.
[in]forceitTrue when bang is given, allows to link group even if it has its own settings.
[in]initTrue when initializing.

◆ ex_ownsyntax()

void ex_ownsyntax ( exarg_T eap)

◆ ex_syntax()

void ex_syntax ( exarg_T eap)

◆ ex_syntime()

void ex_syntime ( exarg_T eap)

◆ get_global_hl_defs()

Dictionary get_global_hl_defs ( void  )

◆ get_highlight_name()

const char* get_highlight_name ( expand_T *const  xp,
int  idx 

Function given to ExpandGeneric() to obtain the list of group names.

◆ get_highlight_name_ext()

const char* get_highlight_name_ext ( expand_T xp,
int  idx,
bool  skip_cleared 

Obtain a highlight group name.

skip_clearedif true don't return a cleared entry.

◆ get_syntax_attr()

int get_syntax_attr ( const colnr_T  col,
bool *const  can_spell,
const bool  keep_state 

Gets highlight attributes for next character. Must first call syntax_start() once for the line. "col" is normally 0 for the first use in a line, and increments by one each time. It's allowed to skip characters and to stop before the end of the line. But only a "col" after a previously used column is allowed. When "can_spell" is not NULL set it to TRUE when spell-checking should be done.

keep_statekeep state of char at "col"
highlight attributes for next character.

◆ get_syntax_info()

int get_syntax_info ( int *  seqnrp)

◆ get_syntax_name()

char_u* get_syntax_name ( expand_T xp,
int  idx 

◆ get_syntime_arg()

char_u* get_syntime_arg ( expand_T xp,
int  idx 

◆ highlight_attr_set_all()

void highlight_attr_set_all ( void  )

Refresh the color attributes of all highlight groups.

◆ highlight_changed()

void highlight_changed ( void  )

Translate highlight groups into attributes in highlight_attr[] and set up the user highlights User1..9. A set of corresponding highlights to use on top of HLF_SNC is computed. Called only when nvim starts and upon first screen redraw after any :highlight command.

Translate builtin highlight groups into attributes for quick lookup.

◆ highlight_color()

const char* highlight_color ( const int  id,
const char *const  what,
const int  modec 

Return color name of the given highlight group

[in]idHighlight group to work with.
[in]whatWhat to return: one of "font", "fg", "bg", "sp", "fg#", "bg#" or "sp#".
[in]modec'g' for GUI, 'c' for cterm and 't' for term.
color name, possibly in a static buffer. Buffer will be overwritten on next highlight_color() call. May return NULL.

◆ highlight_exists()

int highlight_exists ( const char *  name)

◆ highlight_has_attr()

const char* highlight_has_attr ( const int  id,
const int  flag,
const int  modec 

Check whether highlight group has attribute

[in]idHighlight group to check.
[in]flagAttribute to check.
[in]modec'g' for GUI, 'c' for term.
"1" if highlight group has attribute, NULL otherwise.

◆ init_highlight()

void init_highlight ( bool  both,
bool  reset 

Load colors from a file if "g:colors_name" is set, otherwise load builtin colors

bothinclude groups where 'bg' doesn't matter
resetclear groups first

◆ load_colors()

int load_colors ( char_u name)

◆ lookup_color()

int lookup_color ( const int  idx,
const bool  foreground,
TriState *const  boldp 

◆ Map()

Map ( cstr_t  ,

◆ name_to_color()

RgbValue name_to_color ( const char *  name)

Translate to RgbValue if name is an hex value (e.g. #XXXXXX), else look into color_name_table to translate a color name to its hex value

[in]namestring value to convert to RGB return the hex value or -1 if could not find a correct value

◆ reset_expand_highlight()

void reset_expand_highlight ( void  )

◆ reset_synblock()

void reset_synblock ( win_T wp)

◆ restore_cterm_colors()

void restore_cterm_colors ( void  )

◆ set_context_in_echohl_cmd()

void set_context_in_echohl_cmd ( expand_T xp,
const char *  arg 

◆ set_context_in_highlight_cmd()

void set_context_in_highlight_cmd ( expand_T xp,
const char *  arg 

◆ set_context_in_syntax_cmd()

void set_context_in_syntax_cmd ( expand_T xp,
const char *  arg 

◆ syn_check_group()

int syn_check_group ( const char *  name,
int  len 

Find highlight group name in the table and return its ID. If it doesn't exist yet, a new entry is created.

ppHighlight group name
lenlength of pp
0 for failure else the id of the group

◆ syn_get_concealed_id()

int syn_get_concealed_id ( win_T wp,
linenr_T  lnum,
colnr_T  col 

Get the sequence number of the concealed file position.

seqnr if the file position is concealed, 0 otherwise.

◆ syn_get_final_id()

int syn_get_final_id ( int  hl_id)

◆ syn_get_foldlevel()

int syn_get_foldlevel ( win_T wp,
long  lnum 

◆ syn_get_id()

int syn_get_id ( win_T wp,
long  lnum,
colnr_T  col,
int  trans,
bool spellp,
int  keep_state 

Function called for expression evaluation: get syntax ID at file position.

transremove transparency
spellpreturn: can do spell checking
keep_statekeep state of char at "col"

◆ syn_get_stack_item()

int syn_get_stack_item ( int  i)

◆ syn_get_sub_char()

int syn_get_sub_char ( void  )

◆ syn_id2attr()

int syn_id2attr ( int  hl_id)

Translate a group ID to highlight attributes.

See also

◆ syn_id2name()

char_u* syn_id2name ( int  id)

◆ syn_init_cmdline_highlight()

void syn_init_cmdline_highlight ( bool  reset,
bool  init 

Create default links for Nvim* highlight groups used for cmdline coloring.

◆ syn_maybe_enable()

void syn_maybe_enable ( void  )

◆ syn_name2attr()

int syn_name2attr ( const char_u name)

Lookup a highlight group name and return its attributes. Return zero if not found.

◆ syn_name2id()

int syn_name2id ( const char *  name)

◆ syn_name2id_len()

int syn_name2id_len ( const char_u name,
size_t  len 

Lookup a highlight group name and return its ID.

highlightname e.g. 'Cursor', 'Normal'
the highlight id, else 0 if name does not exist

◆ syn_set_timeout()

void syn_set_timeout ( proftime_T tm)

◆ syn_stack_apply_changes()

void syn_stack_apply_changes ( buf_T buf)

◆ syn_stack_free_all()

void syn_stack_free_all ( synblock_T block)

◆ syntax_check_changed()

bool syntax_check_changed ( linenr_T  lnum)

This will only be called just after get_syntax_attr() for the previous line, to check if the next line needs to be redrawn too.

true if the syntax at start of lnum changed since last time.

◆ syntax_clear()

void syntax_clear ( synblock_T block)

◆ syntax_end_parsing()

void syntax_end_parsing ( linenr_T  lnum)

◆ syntax_present()

bool syntax_present ( win_T win)

◆ syntax_start()

void syntax_start ( win_T wp,
linenr_T  lnum 

Variable Documentation

◆ color_name_table

color_name_table_T color_name_table[]

◆ highlight_init_cmdline

const char* const highlight_init_cmdline[]

Array of highlight definitions, used for unit testing.