diff options
Diffstat (limited to 'src/nvim/syntax.c')
-rw-r--r-- | src/nvim/syntax.c | 106 |
1 files changed, 85 insertions, 21 deletions
diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index 5a61238d8c..4aa7c21ce4 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -116,10 +116,12 @@ static int include_link = 0; /* when 2 include "nvim/link" and "clear" */ /// following names, separated by commas (but no spaces!). static char *(hl_name_table[]) = { "bold", "standout", "underline", "undercurl", - "italic", "reverse", "inverse", "strikethrough", "NONE" }; + "italic", "reverse", "inverse", "strikethrough", "nocombine", "NONE" }; static int hl_attr_table[] = { HL_BOLD, HL_STANDOUT, HL_UNDERLINE, HL_UNDERCURL, HL_ITALIC, HL_INVERSE, - HL_INVERSE, HL_STRIKETHROUGH, 0 }; + HL_INVERSE, HL_STRIKETHROUGH, HL_NOCOMBINE, 0 }; + +static char e_illegal_arg[] = N_("E390: Illegal argument: %s"); // The patterns that are being searched for are stored in a syn_pattern. // A match item consists of one pattern. @@ -2460,11 +2462,8 @@ update_si_end( int force /* when TRUE overrule a previous end */ ) { - lpos_T startpos; - lpos_T endpos; lpos_T hl_endpos; lpos_T end_endpos; - int end_idx; /* return quickly for a keyword */ if (sip->si_idx < 0) @@ -2480,9 +2479,12 @@ update_si_end( * We need to find the end of the region. It may continue in the next * line. */ - end_idx = 0; - startpos.lnum = current_lnum; - startpos.col = startcol; + int end_idx = 0; + lpos_T startpos = { + .lnum = current_lnum, + .col = startcol, + }; + lpos_T endpos = { 0 }; find_endpos(sip->si_idx, &startpos, &endpos, &hl_endpos, &(sip->si_flags), &end_endpos, &end_idx, sip->si_extmatch); @@ -3045,7 +3047,7 @@ static void syn_cmd_conceal(exarg_T *eap, int syncing) } else if (STRNICMP(arg, "off", 3) == 0 && next - arg == 3) { curwin->w_s->b_syn_conceal = false; } else { - EMSG2(_("E390: Illegal argument: %s"), arg); + EMSG2(_(e_illegal_arg), arg); } } @@ -3073,7 +3075,42 @@ static void syn_cmd_case(exarg_T *eap, int syncing) } else if (STRNICMP(arg, "ignore", 6) == 0 && next - arg == 6) { curwin->w_s->b_syn_ic = true; } else { - EMSG2(_("E390: Illegal argument: %s"), arg); + EMSG2(_(e_illegal_arg), arg); + } +} + +/// Handle ":syntax foldlevel" command. +static void syn_cmd_foldlevel(exarg_T *eap, int syncing) +{ + char_u *arg = eap->arg; + char_u *arg_end; + + eap->nextcmd = find_nextcmd(arg); + if (eap->skip) + return; + + if (*arg == NUL) { + switch (curwin->w_s->b_syn_foldlevel) { + case SYNFLD_START: MSG(_("syntax foldlevel start")); break; + case SYNFLD_MINIMUM: MSG(_("syntax foldlevel minimum")); break; + default: break; + } + return; + } + + arg_end = skiptowhite(arg); + if (STRNICMP(arg, "start", 5) == 0 && arg_end - arg == 5) { + curwin->w_s->b_syn_foldlevel = SYNFLD_START; + } else if (STRNICMP(arg, "minimum", 7) == 0 && arg_end - arg == 7) { + curwin->w_s->b_syn_foldlevel = SYNFLD_MINIMUM; + } else { + EMSG2(_(e_illegal_arg), arg); + return; + } + + arg = skipwhite(arg_end); + if (*arg != NUL) { + EMSG2(_(e_illegal_arg), arg); } } @@ -3105,7 +3142,7 @@ static void syn_cmd_spell(exarg_T *eap, int syncing) } else if (STRNICMP(arg, "default", 7) == 0 && next - arg == 7) { curwin->w_s->b_syn_spell = SYNSPL_DEFAULT; } else { - EMSG2(_("E390: Illegal argument: %s"), arg); + EMSG2(_(e_illegal_arg), arg); return; } @@ -3161,6 +3198,7 @@ void syntax_clear(synblock_T *block) block->b_syn_error = false; // clear previous error block->b_syn_slow = false; // clear previous timeout block->b_syn_ic = false; // Use case, by default + block->b_syn_foldlevel = SYNFLD_START; block->b_syn_spell = SYNSPL_DEFAULT; // default spell checking block->b_syn_containedin = false; block->b_syn_conceal = false; @@ -3981,7 +4019,7 @@ static void add_keyword(char_u *const name, STRLEN(kp->keyword), hash); // even though it looks like only the kp->keyword member is - // being used here, vim uses some pointer trickery to get the orignal + // being used here, vim uses some pointer trickery to get the original // struct again later by using knowledge of the offset of the keyword // field in the struct. See the definition of the HI2KE macro. if (HASHITEM_EMPTY(hi)) { @@ -5485,6 +5523,7 @@ static struct subcommand subcommands[] = { "cluster", syn_cmd_cluster }, { "conceal", syn_cmd_conceal }, { "enable", syn_cmd_enable }, + { "foldlevel", syn_cmd_foldlevel }, { "include", syn_cmd_include }, { "iskeyword", syn_cmd_iskeyword }, { "keyword", syn_cmd_keyword }, @@ -5763,6 +5802,17 @@ int syn_get_stack_item(int i) return CUR_STATE(i).si_id; } +static int syn_cur_foldlevel(void) +{ + int level = 0; + for (int i = 0; i < current_state.ga_len; i++) { + if (CUR_STATE(i).si_flags & HL_FOLD) { + level++; + } + } + return level; +} + /* * Function called to get folding level for line "lnum" in window "wp". */ @@ -5776,9 +5826,22 @@ int syn_get_foldlevel(win_T *wp, long lnum) && !wp->w_s->b_syn_slow) { syntax_start(wp, lnum); - for (int i = 0; i < current_state.ga_len; ++i) { - if (CUR_STATE(i).si_flags & HL_FOLD) { - ++level; + // Start with the fold level at the start of the line. + level = syn_cur_foldlevel(); + + if (wp->w_s->b_syn_foldlevel == SYNFLD_MINIMUM) { + // Find the lowest fold level that is followed by a higher one. + int cur_level = level; + int low_level = cur_level; + while (!current_finished) { + (void)syn_current_attr(false, false, NULL, false); + cur_level = syn_cur_foldlevel(); + if (cur_level < low_level) { + low_level = cur_level; + } else if (cur_level > low_level) { + level = low_level; + } + current_col++; } } } @@ -5959,6 +6022,7 @@ static const char *highlight_init_both[] = { "IncSearch cterm=reverse gui=reverse", "ModeMsg cterm=bold gui=bold", "NonText ctermfg=Blue gui=bold guifg=Blue", + "Normal cterm=NONE gui=NONE", "PmenuSbar ctermbg=Grey guibg=Grey", "StatusLine cterm=reverse,bold gui=reverse,bold", "StatusLineNC cterm=reverse gui=reverse", @@ -6010,7 +6074,6 @@ static const char *highlight_init_light[] = { "Title ctermfg=DarkMagenta gui=bold guifg=Magenta", "Visual guibg=LightGrey", "WarningMsg ctermfg=DarkRed guifg=Red", - "Normal gui=NONE", NULL }; @@ -6044,7 +6107,6 @@ static const char *highlight_init_dark[] = { "Title ctermfg=LightMagenta gui=bold guifg=Magenta", "Visual guibg=DarkGrey", "WarningMsg ctermfg=LightRed guifg=Red", - "Normal gui=NONE", NULL }; @@ -6401,7 +6463,7 @@ static int color_numbers_88[28] = { 0, 4, 2, 6, 75, 11, 78, 15, -1 }; // for xterm with 256 colors... static int color_numbers_256[28] = { 0, 4, 2, 6, - 1, 5, 130, 130, + 1, 5, 130, 3, 248, 248, 7, 7, 242, 242, 12, 81, 10, 121, @@ -7316,7 +7378,7 @@ static void set_hl_attr(int idx) sgp->sg_attr = hl_get_syn_attr(idx+1, at_en); - // a cursor style uses this syn_id, make sure its atribute is updated. + // a cursor style uses this syn_id, make sure its attribute is updated. if (cursor_mode_uses_syn_id(idx+1)) { ui_mode_info_set(); } @@ -7445,6 +7507,8 @@ static int syn_add_group(char_u *name) return 0; } + char_u *const name_up = vim_strsave_up(name); + // Append another syntax_highlight entry. struct hl_group* hlgp = GA_APPEND_VIA_PTR(struct hl_group, &highlight_ga); memset(hlgp, 0, sizeof(*hlgp)); @@ -7453,7 +7517,7 @@ static int syn_add_group(char_u *name) hlgp->sg_rgb_fg = -1; hlgp->sg_rgb_sp = -1; hlgp->sg_blend = -1; - hlgp->sg_name_u = vim_strsave_up(name); + hlgp->sg_name_u = name_up; return highlight_ga.ga_len; /* ID is index plus one */ } @@ -7569,8 +7633,8 @@ void highlight_changed(void) { int id; char_u userhl[30]; // use 30 to avoid compiler warning - int id_SNC = -1; int id_S = -1; + int id_SNC = 0; int hlcnt; need_highlight_changed = FALSE; |