diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/nvim/globals.h | 61 | ||||
| -rw-r--r-- | src/nvim/option.c | 29 | ||||
| -rw-r--r-- | src/nvim/syntax.c | 112 | 
3 files changed, 77 insertions, 125 deletions
| diff --git a/src/nvim/globals.h b/src/nvim/globals.h index b820965680..a3657f2122 100644 --- a/src/nvim/globals.h +++ b/src/nvim/globals.h @@ -413,8 +413,7 @@ EXTERN int no_check_timestamps INIT(= 0);       /* Don't check timestamps */  /*   * Values for index in highlight_attr[]. - * When making changes, also update HL_FLAGS below!  And update the default - * value of 'highlight' in option.c. + * When making changes, also update hlf_names below!   */  typedef enum {    HLF_8 = 0         /* Meta & special keys listed with ":map", text that is @@ -447,8 +446,8 @@ typedef enum {    , HLF_CHD         // Changed diff line    , HLF_DED         // Deleted diff line    , HLF_TXD         // Text Changed in diff line -  , HLF_CONCEAL     // Concealed text    , HLF_SC          // Sign column +  , HLF_CONCEAL     // Concealed text    , HLF_SPB         // SpellBad    , HLF_SPC         // SpellCap    , HLF_SPR         // SpellRare @@ -469,12 +468,56 @@ typedef enum {    , HLF_COUNT       // MUST be the last one  } hlf_T; -/* The HL_FLAGS must be in the same order as the HLF_ enums! - * When changing this also adjust the default for 'highlight'. */ -#define HL_FLAGS { '8', '~', 'z', 'Z', '@', 'd', 'e', 'i', 'l', 'm', 'M', 'n', \ -                   'N', 'r', 's', 'S', 'c', 't', 'v', 'V', 'w', 'W', 'f', 'F', \ -                   'A', 'C', 'D', 'T', '-', '>', 'B', 'P', 'R', 'L', '+', '=', \ -                   'x', 'X', '*', '#', '_', '!', '.', 'o', 'q', '0', 'I' } +EXTERN const char *hlf_names[] INIT(= { +  [HLF_8] = "SpecialKey", +  [HLF_EOB] = "EndOfBuffer", +  [HLF_TERM] = "TermCursor", +  [HLF_TERMNC] = "TermCursorNC", +  [HLF_AT] = "NonText", +  [HLF_D] = "Directory", +  [HLF_E] = "ErrorMsg", +  [HLF_I] = "IncSearch", +  [HLF_L] = "Search", +  [HLF_M] = "MoreMsg", +  [HLF_CM] = "ModeMsg", +  [HLF_N] = "LineNr", +  [HLF_CLN] = "CursorLineNr", +  [HLF_R] = "Question", +  [HLF_S] = "StatusLine", +  [HLF_SNC] = "StatusLineNC", +  [HLF_C] = "VertSplit", +  [HLF_T] = "Title", +  [HLF_V] = "Visual", +  [HLF_VNC] = "VisualNOS", +  [HLF_W] = "WarningMsg", +  [HLF_WM] = "WildMenu", +  [HLF_FL] = "Folded", +  [HLF_FC] = "FoldColumn", +  [HLF_ADD] = "DiffAdd", +  [HLF_CHD] = "DiffChange", +  [HLF_DED] = "DiffDelete", +  [HLF_TXD] = "DiffText", +  [HLF_SC] = "SignColumn", +  [HLF_CONCEAL] = "Conceal", +  [HLF_SPB] = "SpellBad", +  [HLF_SPC] = "SpellCap", +  [HLF_SPR] = "SpellRare", +  [HLF_SPL] = "SpellLocal", +  [HLF_PNI] = "Pmenu", +  [HLF_PSI] = "PmenuSel", +  [HLF_PSB] = "PmenuSbar", +  [HLF_PST] = "PmenuThumb", +  [HLF_TP] = "TabLine", +  [HLF_TPS] = "TabLineSel", +  [HLF_TPF] = "TabLineFill", +  [HLF_CUC] = "CursorColumn", +  [HLF_CUL] = "CursorLine", +  [HLF_MC] = "ColorColumn", +  [HLF_QFL] = "QuickFixLine", +  [HLF_0] = "Whitespace", +  [HLF_INACTIVE] = "NormalNC", +}); +  EXTERN int highlight_attr[HLF_COUNT];       /* Highl. attr for each context. */  EXTERN int highlight_user[9];                   /* User[1-9] attributes */ diff --git a/src/nvim/option.c b/src/nvim/option.c index 9b4cd0924b..c36ca1bfe9 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -247,7 +247,7 @@ typedef struct vimoption {    "8:SpecialKey,~:EndOfBuffer,z:TermCursor,Z:TermCursorNC,@:NonText," \    "d:Directory,e:ErrorMsg,i:IncSearch,l:Search,m:MoreMsg,M:ModeMsg,n:LineNr," \    "N:CursorLineNr,r:Question,s:StatusLine,S:StatusLineNC,c:VertSplit,t:Title," \ -  "v:Visual,w:WarningMsg,W:WildMenu,f:Folded,F:FoldColumn," \ +  "v:Visual,V:VisualNOS,w:WarningMsg,W:WildMenu,f:Folded,F:FoldColumn," \    "A:DiffAdd,C:DiffChange,D:DiffDelete,T:DiffText,>:SignColumn,-:Conceal," \    "B:SpellBad,P:SpellCap,R:SpellRare,L:SpellLocal,+:Pmenu,=:PmenuSel," \    "x:PmenuSbar,X:PmenuThumb,*:TabLine,#:TabLineSel,_:TabLineFill," \ @@ -2124,7 +2124,7 @@ static void didset_options(void)  static void didset_options2(void)  {    // Initialize the highlight_attr[] table. -  (void)highlight_changed(); +  highlight_changed();    // Parse default for 'clipboard'.    (void)opt_strings_flags(p_cb, p_cb_values, &cb_flags, true); @@ -2538,11 +2538,11 @@ did_set_string_option (        if (s[2] == NUL)          break;      } -  } -  /* 'highlight' */ -  else if (varp == &p_hl) { -    if (highlight_changed() == FAIL) -      errmsg = e_invarg;        /* invalid flags */ +  } else if (varp == &p_hl) { +    // 'highlight' +    if (strcmp((char *)(*varp), HIGHLIGHT_INIT) != 0) { +      errmsg = e_unsupportedoption; +    }    }    /* 'nrformats' */    else if (gvarp == &p_nf) { @@ -2639,7 +2639,7 @@ did_set_string_option (        if (varp == &p_enc) {          // only encoding=utf-8 allowed          if (STRCMP(p_enc, "utf-8") != 0) { -          errmsg = e_invarg; +          errmsg = e_unsupportedoption;          }        }      } @@ -3207,8 +3207,6 @@ did_set_string_option (       */      if (did_chartab)        (void)init_chartab(); -    if (varp == &p_hl) -      (void)highlight_changed();    } else {      /* Remember where the option was set. */      set_option_scriptID_idx(opt_idx, opt_flags, current_SID); @@ -4827,17 +4825,6 @@ char *set_option_value(const char *const name, const long number,    return NULL;  } -char_u *get_highlight_default(void) -{ -  int i; - -  i = findoption("hl"); -  if (i >= 0) { -    return options[i].def_val[VI_DEFAULT]; -  } -  return (char_u *)NULL; -} -  /*   * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.   */ diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index ce48547163..a0725c5831 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -7304,110 +7304,34 @@ static void highlight_attr_set_all(void)    }  } -/* - * Translate the 'highlight' option 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 the 'highlight' option has been changed and upon first - * screen redraw after any :highlight command. - * Return FAIL when an invalid flag is found in 'highlight'.  OK otherwise. - */ -int highlight_changed(void) +/// Tranlate 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. +void highlight_changed(void)  { -  int hlf; -  int i; -  char_u      *p;    int attr; -  char_u      *end;    int id;    char_u userhl[10];    int id_SNC = -1;    int id_S = -1;    int hlcnt; -  static int hl_flags[HLF_COUNT] = HL_FLAGS;    need_highlight_changed = FALSE; -  /* -   * Clear all attributes. -   */ -  for (hlf = 0; hlf < (int)HLF_COUNT; ++hlf) -    highlight_attr[hlf] = 0; - -  /* -   * First set all attributes to their default value. -   * Then use the attributes from the 'highlight' option. -   */ -  for (i = 0; i < 2; ++i) { -    if (i) -      p = p_hl; -    else -      p = get_highlight_default(); -    if (p == NULL)          /* just in case */ -      continue; - -    while (*p) { -      for (hlf = 0; hlf < (int)HLF_COUNT; ++hlf) -        if (hl_flags[hlf] == *p) -          break; -      ++p; -      if (hlf == (int)HLF_COUNT || *p == NUL) -        return FAIL; - -      /* -       * Allow several hl_flags to be combined, like "bu" for -       * bold-underlined. -       */ -      attr = 0; -      bool colon = false; -      for (; *p && *p != ','; ++p) {  // parse upto comma -        if (ascii_iswhite(*p)) {  // ignore white space -          continue; -        } - -        if (colon)          /* Combination with ':' is not allowed. */ -          return FAIL; - -        switch (*p) { -        case 'b':   attr |= HL_BOLD; -          break; -        case 'i':   attr |= HL_ITALIC; -          break; -        case '-': -        case 'n':                                   /* no highlighting */ -          break; -        case 'r':   attr |= HL_INVERSE; -          break; -        case 's':   attr |= HL_STANDOUT; -          break; -        case 'u':   attr |= HL_UNDERLINE; -          break; -        case 'c':   attr |= HL_UNDERCURL; -          break; -        case ':':   ++p;                            /* highlight group name */ -          if (attr || *p == NUL)                         /* no combinations */ -            return FAIL; -          colon = true; -          end = vim_strchr(p, ','); -          if (end == NULL) -            end = p + STRLEN(p); -          id = syn_check_group(p, (int)(end - p)); -          if (id == 0) -            return FAIL; -          attr = syn_id2attr(id); -          p = end - 1; -          if (hlf == (int)HLF_SNC) -            id_SNC = syn_get_final_id(id); -          else if (hlf == (int)HLF_S) -            id_S = syn_get_final_id(id); -          break; -        default:    return FAIL; -        } -      } -      highlight_attr[hlf] = attr; - -      p = skip_to_option_part(p);           /* skip comma and spaces */ +  /// Translate builtin highlight groups into attributes for quick lookup. +  for (int hlf = 0; hlf < (int)HLF_COUNT; hlf++) { +    id = syn_check_group((char_u *)hlf_names[hlf], STRLEN(hlf_names[hlf])); +    if (id == 0) { +      abort(); +    } +    attr = syn_id2attr(id); +    if (hlf == (int)HLF_SNC) { +      id_SNC = syn_get_final_id(id); +    } else if (hlf == (int)HLF_S) { +      id_S = syn_get_final_id(id);      } +    highlight_attr[hlf] = attr;    }    /* Setup the user highlights @@ -7472,8 +7396,6 @@ int highlight_changed(void)      }    }    highlight_ga.ga_len = hlcnt; - -  return OK;  } | 
