diff options
-rw-r--r-- | runtime/doc/options.txt | 80 | ||||
-rw-r--r-- | runtime/doc/syntax.txt | 7 | ||||
-rw-r--r-- | runtime/doc/vim_diff.txt | 1 | ||||
-rw-r--r-- | src/nvim/globals.h | 61 | ||||
-rw-r--r-- | src/nvim/option.c | 29 | ||||
-rw-r--r-- | src/nvim/syntax.c | 112 | ||||
-rw-r--r-- | test/functional/ex_cmds/encoding_spec.lua | 4 | ||||
-rw-r--r-- | test/functional/ui/cursor_spec.lua | 4 |
8 files changed, 89 insertions, 209 deletions
diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt index afc7c20ed5..5452bacffc 100644 --- a/runtime/doc/options.txt +++ b/runtime/doc/options.txt @@ -3120,82 +3120,10 @@ A jump table for the options with a short description can be found at |Q_op|. Think twice when using ":q!" or ":qa!". *'highlight'* *'hl'* -'highlight' 'hl' string (default: string of "c:group,..." pairs) - global - This option can be used to set highlighting mode for various - occasions. It is a comma separated list of character pairs. The - first character in a pair gives the occasion, the second the mode to - use for that occasion. The occasions are: - |hl-SpecialKey| 8 Meta and special keys listed with ":map" - |hl-Whitespace| 0 - |hl-EndOfBuffer| ~ lines after the last line in the buffer - |hl-NormalNC| I non-current ("inactive") window - |hl-TermCursor| z Cursor in a focused terminal - |hl-TermCursorNC| Z Cursor in an unfocused terminal - |hl-NonText| @ '@' at the end of the window and - characters from 'showbreak' - |hl-Directory| d directories in CTRL-D listing and other special - things in listings - |hl-ErrorMsg| e error messages - |hl-IncSearch| i 'incsearch' highlighting - |hl-Search| l last search pattern highlighting (see 'hlsearch') - |hl-MoreMsg| m |more-prompt| - |hl-ModeMsg| M Mode (e.g., "-- INSERT --") - |hl-LineNr| n line number for ":number" and ":#" commands, and - when 'number' or 'relativenumber' option is set. - |hl-CursorLineNr| N like n for when 'cursorline' or 'relativenumber' is - set. - |hl-Question| r |hit-enter| prompt and yes/no questions - |hl-StatusLine| s status line of current window |status-line| - |hl-StatusLineNC| S status lines of not-current windows - |hl-Title| t Titles for output from ":set all", ":autocmd" etc. - |hl-VertSplit| c column used to separate vertically split windows - |hl-Visual| v Visual mode - |hl-WarningMsg| w warning messages - |hl-WildMenu| W wildcard matches displayed for 'wildmenu' - |hl-Folded| f line used for closed folds - |hl-FoldColumn| F 'foldcolumn' - |hl-DiffAdd| A added line in diff mode - |hl-DiffChange| C changed line in diff mode - |hl-DiffDelete| D deleted line in diff mode - |hl-DiffText| T inserted text in diff mode - |hl-SignColumn| > column used for |signs| - |hl-SpellBad| B misspelled word |spell| - |hl-SpellCap| P word that should start with capital |spell| - |hl-SpellRare| R rare word |spell| - |hl-SpellLocal| L word from other region |spell| - |hl-Conceal| - the placeholders used for concealed characters - (see 'conceallevel') - |hl-Pmenu| + popup menu normal line - |hl-PmenuSel| = popup menu normal line - |hl-PmenuSbar| x popup menu scrollbar - |hl-PmenuThumb| X popup menu scrollbar thumb - - |hl-TabLine| * - |hl-TabLineFill| _ - |hl-TabLineSel| # - - |hl-ColorColumn| o - |hl-CursorColumn| ! - |hl-CursorLine| . - |hl-QuickFixLine| q - - The display modes are: - r reverse (termcap entry "mr" and "me") - i italic (termcap entry "ZH" and "ZR") - b bold (termcap entry "md" and "me") - s standout (termcap entry "so" and "se") - u underline (termcap entry "us" and "ue") - c undercurl (termcap entry "Cs" and "Ce") - n no highlighting - - no highlighting - : use a highlight group - The default is used for occasions that are not included. - When using the ':' display mode, this must be followed by the name of - a highlight group. A highlight group can be used to define any type - of highlighting, including using color. See |:highlight| on how to - define one. The default uses a different group for each occasion. - See |highlight-default| for the default highlight groups. +'highlight' 'hl' Removed. |vim-differences| + global + In nvim the highlight group names for ui highlighting are fixed. + See |highlight-groups|. *'hlsearch'* *'hls'* *'nohlsearch'* *'nohls'* 'hlsearch' 'hls' boolean (default on) diff --git a/runtime/doc/syntax.txt b/runtime/doc/syntax.txt index 18920d81e3..f3f11dcd34 100644 --- a/runtime/doc/syntax.txt +++ b/runtime/doc/syntax.txt @@ -4849,10 +4849,9 @@ guisp={color-name} *highlight-guisp* :highlight Comment guifg=#11f0c3 guibg=#ff00ff < *highlight-groups* *highlight-default* -These are the default highlighting groups. These groups are used by the -'highlight' option default. Note that the highlighting depends on the value -of 'background'. You can see the current settings with the ":highlight" -command. +These are the builtin highlighting groups. Note that the highlighting depends +on the value of 'background'. You can see the current settings with the +":highlight" command. *hl-ColorColumn* ColorColumn used for the columns set with 'colorcolumn' *hl-Conceal* diff --git a/runtime/doc/vim_diff.txt b/runtime/doc/vim_diff.txt index aba4420ebe..4fa84c12b3 100644 --- a/runtime/doc/vim_diff.txt +++ b/runtime/doc/vim_diff.txt @@ -310,6 +310,7 @@ Other options: 'esckeys' 'guioptions' "t" flag was removed *'guipty'* (Nvim uses pipes and PTYs consistently on all platforms.) + 'highlight' (the builtin default group names are always used) *'imactivatefunc'* *'imaf'* *'imactivatekey'* *'imak'* *'imstatusfunc'* *'imsf'* diff --git a/src/nvim/globals.h b/src/nvim/globals.h index b820965680..94f4f27a0c 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; } diff --git a/test/functional/ex_cmds/encoding_spec.lua b/test/functional/ex_cmds/encoding_spec.lua index 0769259be4..7f2bd78a47 100644 --- a/test/functional/ex_cmds/encoding_spec.lua +++ b/test/functional/ex_cmds/encoding_spec.lua @@ -15,7 +15,7 @@ describe('&encoding', function() feed_command('set encoding=latin1') -- error message expected feed('<cr>') - neq(nil, string.find(eval('v:errmsg'), '^E474:')) + neq(nil, string.find(eval('v:errmsg'), '^E519:')) eq('utf-8', eval('&encoding')) -- check nvim is still in utf-8 mode eq(3, eval('strwidth("Bär")')) @@ -25,7 +25,7 @@ describe('&encoding', function() clear('--cmd', 'set enc=latin1') -- error message expected feed('<cr>') - neq(nil, string.find(eval('v:errmsg'), '^E474:')) + neq(nil, string.find(eval('v:errmsg'), '^E519:')) eq('utf-8', eval('&encoding')) eq(3, eval('strwidth("Bär")')) end) diff --git a/test/functional/ui/cursor_spec.lua b/test/functional/ui/cursor_spec.lua index f4eec4bdc7..b47210a777 100644 --- a/test/functional/ui/cursor_spec.lua +++ b/test/functional/ui/cursor_spec.lua @@ -194,8 +194,8 @@ describe('ui/cursor', function() if m.blinkoff then m.blinkoff = 400 end if m.blinkwait then m.blinkwait = 700 end end - if m.hl_id then m.hl_id = 47 end - if m.id_lm then m.id_lm = 48 end + if m.hl_id then m.hl_id = 48 end + if m.id_lm then m.id_lm = 49 end end -- Assert the new expectation. |