Merge #6737 "options: make 'highlight' read-only"

This commit is contained in:
Justin M. Keyes
2017-05-15 14:53:31 +02:00
9 changed files with 91 additions and 214 deletions

View File

@@ -26,9 +26,6 @@ Events ~
*EncodingChanged* Never fired; 'encoding' is always "utf-8". *EncodingChanged* Never fired; 'encoding' is always "utf-8".
*FileEncoding* Never fired; equivalent to |EncodingChanged|. *FileEncoding* Never fired; equivalent to |EncodingChanged|.
Highlight groups ~
*hl-VisualNOS* Obsolete. |vim-differences| {Nvim}
Keycodes ~ Keycodes ~
*<MouseDown>* Use <ScrollWheelUp> instead. *<MouseDown>* Use <ScrollWheelUp> instead.
*<MouseUp>* Use <ScrollWheelDown> instead. *<MouseUp>* Use <ScrollWheelDown> instead.

View File

@@ -3120,82 +3120,9 @@ A jump table for the options with a short description can be found at |Q_op|.
Think twice when using ":q!" or ":qa!". Think twice when using ":q!" or ":qa!".
*'highlight'* *'hl'* *'highlight'* *'hl'*
'highlight' 'hl' string (default: string of "c:group,..." pairs) 'highlight' 'hl' Removed. |vim-differences|
global global
This option can be used to set highlighting mode for various The builtin |highlight-groups| cannot be changed.
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.
*'hlsearch'* *'hls'* *'nohlsearch'* *'nohls'* *'hlsearch'* *'hls'* *'nohlsearch'* *'nohls'*
'hlsearch' 'hls' boolean (default on) 'hlsearch' 'hls' boolean (default on)

View File

@@ -4849,10 +4849,9 @@ guisp={color-name} *highlight-guisp*
:highlight Comment guifg=#11f0c3 guibg=#ff00ff :highlight Comment guifg=#11f0c3 guibg=#ff00ff
< <
*highlight-groups* *highlight-default* *highlight-groups* *highlight-default*
These are the default highlighting groups. These groups are used by the These are the builtin highlighting groups. Note that the highlighting depends
'highlight' option default. Note that the highlighting depends on the value on the value of 'background'. You can see the current settings with the
of 'background'. You can see the current settings with the ":highlight" ":highlight" command.
command.
*hl-ColorColumn* *hl-ColorColumn*
ColorColumn used for the columns set with 'colorcolumn' ColorColumn used for the columns set with 'colorcolumn'
*hl-Conceal* *hl-Conceal*
@@ -4973,6 +4972,8 @@ TabLineSel tab pages line, active tab page label
Title titles for output from ":set all", ":autocmd" etc. Title titles for output from ":set all", ":autocmd" etc.
*hl-Visual* *hl-Visual*
Visual Visual mode selection Visual Visual mode selection
*hl-VisualNOS*
VisualNOS Visual mode selection when vim is "Not Owning the Selection".
*hl-WarningMsg* *hl-WarningMsg*
WarningMsg warning messages WarningMsg warning messages
*hl-Whitespace* *hl-Whitespace*

View File

@@ -107,8 +107,10 @@ Options:
'cpoptions' flags: |cpo-_| 'cpoptions' flags: |cpo-_|
'guicursor' works in the terminal 'guicursor' works in the terminal
'inccommand' shows interactive results for |:substitute|-like commands 'inccommand' shows interactive results for |:substitute|-like commands
'scrollback'
'statusline' supports unlimited alignment sections 'statusline' supports unlimited alignment sections
'tabline' %@Func@foo%X can call any function on mouse-click 'tabline' %@Func@foo%X can call any function on mouse-click
'winhighlight' window-local highlights
Variables: Variables:
|v:event| |v:event|
@@ -291,9 +293,6 @@ MS-DOS support:
'bioskey' 'bioskey'
'conskey' 'conskey'
Highlight groups:
|hl-VisualNOS|
Test functions: Test functions:
test_alloc_fail() test_alloc_fail()
test_autochdir() test_autochdir()
@@ -314,6 +313,7 @@ Other options:
'esckeys' 'esckeys'
'guioptions' "t" flag was removed 'guioptions' "t" flag was removed
*'guipty'* (Nvim uses pipes and PTYs consistently on all platforms.) *'guipty'* (Nvim uses pipes and PTYs consistently on all platforms.)
'highlight' (the builtin |highlight-groups| cannot be changed)
*'imactivatefunc'* *'imaf'* *'imactivatefunc'* *'imaf'*
*'imactivatekey'* *'imak'* *'imactivatekey'* *'imak'*
*'imstatusfunc'* *'imsf'* *'imstatusfunc'* *'imsf'*

View File

@@ -413,8 +413,7 @@ EXTERN int no_check_timestamps INIT(= 0); /* Don't check timestamps */
/* /*
* Values for index in highlight_attr[]. * Values for index in highlight_attr[].
* When making changes, also update HL_FLAGS below! And update the default * When making changes, also update hlf_names below!
* value of 'highlight' in option.c.
*/ */
typedef enum { typedef enum {
HLF_8 = 0 /* Meta & special keys listed with ":map", text that is HLF_8 = 0 /* Meta & special keys listed with ":map", text that is
@@ -447,8 +446,8 @@ typedef enum {
, HLF_CHD // Changed diff line , HLF_CHD // Changed diff line
, HLF_DED // Deleted diff line , HLF_DED // Deleted diff line
, HLF_TXD // Text Changed in diff line , HLF_TXD // Text Changed in diff line
, HLF_CONCEAL // Concealed text
, HLF_SC // Sign column , HLF_SC // Sign column
, HLF_CONCEAL // Concealed text
, HLF_SPB // SpellBad , HLF_SPB // SpellBad
, HLF_SPC // SpellCap , HLF_SPC // SpellCap
, HLF_SPR // SpellRare , HLF_SPR // SpellRare
@@ -469,12 +468,56 @@ typedef enum {
, HLF_COUNT // MUST be the last one , HLF_COUNT // MUST be the last one
} hlf_T; } hlf_T;
/* The HL_FLAGS must be in the same order as the HLF_ enums! EXTERN const char *hlf_names[] INIT(= {
* When changing this also adjust the default for 'highlight'. */ [HLF_8] = "SpecialKey",
#define HL_FLAGS { '8', '~', 'z', 'Z', '@', 'd', 'e', 'i', 'l', 'm', 'M', 'n', \ [HLF_EOB] = "EndOfBuffer",
'N', 'r', 's', 'S', 'c', 't', 'v', 'V', 'w', 'W', 'f', 'F', \ [HLF_TERM] = "TermCursor",
'A', 'C', 'D', 'T', '-', '>', 'B', 'P', 'R', 'L', '+', '=', \ [HLF_TERMNC] = "TermCursorNC",
'x', 'X', '*', '#', '_', '!', '.', 'o', 'q', '0', 'I' } [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_attr[HLF_COUNT]; /* Highl. attr for each context. */
EXTERN int highlight_user[9]; /* User[1-9] attributes */ EXTERN int highlight_user[9]; /* User[1-9] attributes */

View File

@@ -247,7 +247,7 @@ typedef struct vimoption {
"8:SpecialKey,~:EndOfBuffer,z:TermCursor,Z:TermCursorNC,@:NonText," \ "8:SpecialKey,~:EndOfBuffer,z:TermCursor,Z:TermCursorNC,@:NonText," \
"d:Directory,e:ErrorMsg,i:IncSearch,l:Search,m:MoreMsg,M:ModeMsg,n:LineNr," \ "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," \ "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," \ "A:DiffAdd,C:DiffChange,D:DiffDelete,T:DiffText,>:SignColumn,-:Conceal," \
"B:SpellBad,P:SpellCap,R:SpellRare,L:SpellLocal,+:Pmenu,=:PmenuSel," \ "B:SpellBad,P:SpellCap,R:SpellRare,L:SpellLocal,+:Pmenu,=:PmenuSel," \
"x:PmenuSbar,X:PmenuThumb,*:TabLine,#:TabLineSel,_:TabLineFill," \ "x:PmenuSbar,X:PmenuThumb,*:TabLine,#:TabLineSel,_:TabLineFill," \
@@ -2124,7 +2124,7 @@ static void didset_options(void)
static void didset_options2(void) static void didset_options2(void)
{ {
// Initialize the highlight_attr[] table. // Initialize the highlight_attr[] table.
(void)highlight_changed(); highlight_changed();
// Parse default for 'clipboard'. // Parse default for 'clipboard'.
(void)opt_strings_flags(p_cb, p_cb_values, &cb_flags, true); (void)opt_strings_flags(p_cb, p_cb_values, &cb_flags, true);
@@ -2538,11 +2538,11 @@ did_set_string_option (
if (s[2] == NUL) if (s[2] == NUL)
break; break;
} }
} else if (varp == &p_hl) {
// 'highlight'
if (strcmp((char *)(*varp), HIGHLIGHT_INIT) != 0) {
errmsg = e_unsupportedoption;
} }
/* 'highlight' */
else if (varp == &p_hl) {
if (highlight_changed() == FAIL)
errmsg = e_invarg; /* invalid flags */
} }
/* 'nrformats' */ /* 'nrformats' */
else if (gvarp == &p_nf) { else if (gvarp == &p_nf) {
@@ -2639,7 +2639,7 @@ did_set_string_option (
if (varp == &p_enc) { if (varp == &p_enc) {
// only encoding=utf-8 allowed // only encoding=utf-8 allowed
if (STRCMP(p_enc, "utf-8") != 0) { if (STRCMP(p_enc, "utf-8") != 0) {
errmsg = e_invarg; errmsg = e_unsupportedoption;
} }
} }
} }
@@ -3207,8 +3207,6 @@ did_set_string_option (
*/ */
if (did_chartab) if (did_chartab)
(void)init_chartab(); (void)init_chartab();
if (varp == &p_hl)
(void)highlight_changed();
} else { } else {
/* Remember where the option was set. */ /* Remember where the option was set. */
set_option_scriptID_idx(opt_idx, opt_flags, current_SID); 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; 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. * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
*/ */

View File

@@ -7304,110 +7304,34 @@ static void highlight_attr_set_all(void)
} }
} }
/* /// Tranlate highlight groups into attributes in highlight_attr[] and set up
* Translate the 'highlight' option into attributes in highlight_attr[] and /// the user highlights User1..9. A set of corresponding highlights to use on
* set up the user highlights User1..9. A set of /// top of HLF_SNC is computed. Called only when nvim starts and upon first
* corresponding highlights to use on top of HLF_SNC is computed. /// screen redraw after any :highlight command.
* Called only when the 'highlight' option has been changed and upon first void highlight_changed(void)
* screen redraw after any :highlight command.
* Return FAIL when an invalid flag is found in 'highlight'. OK otherwise.
*/
int highlight_changed(void)
{ {
int hlf;
int i;
char_u *p;
int attr; int attr;
char_u *end;
int id; int id;
char_u userhl[10]; char_u userhl[10];
int id_SNC = -1; int id_SNC = -1;
int id_S = -1; int id_S = -1;
int hlcnt; int hlcnt;
static int hl_flags[HLF_COUNT] = HL_FLAGS;
need_highlight_changed = FALSE; need_highlight_changed = FALSE;
/* /// Translate builtin highlight groups into attributes for quick lookup.
* Clear all attributes. for (int hlf = 0; hlf < (int)HLF_COUNT; hlf++) {
*/ id = syn_check_group((char_u *)hlf_names[hlf], STRLEN(hlf_names[hlf]));
for (hlf = 0; hlf < (int)HLF_COUNT; ++hlf) if (id == 0) {
highlight_attr[hlf] = 0; abort();
/*
* 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); attr = syn_id2attr(id);
p = end - 1; if (hlf == (int)HLF_SNC) {
if (hlf == (int)HLF_SNC)
id_SNC = syn_get_final_id(id); id_SNC = syn_get_final_id(id);
else if (hlf == (int)HLF_S) } else if (hlf == (int)HLF_S) {
id_S = syn_get_final_id(id); id_S = syn_get_final_id(id);
break;
default: return FAIL;
}
} }
highlight_attr[hlf] = attr; highlight_attr[hlf] = attr;
p = skip_to_option_part(p); /* skip comma and spaces */
}
} }
/* Setup the user highlights /* Setup the user highlights
@@ -7472,8 +7396,6 @@ int highlight_changed(void)
} }
} }
highlight_ga.ga_len = hlcnt; highlight_ga.ga_len = hlcnt;
return OK;
} }

View File

@@ -15,7 +15,7 @@ describe('&encoding', function()
feed_command('set encoding=latin1') feed_command('set encoding=latin1')
-- error message expected -- error message expected
feed('<cr>') feed('<cr>')
neq(nil, string.find(eval('v:errmsg'), '^E474:')) neq(nil, string.find(eval('v:errmsg'), '^E519:'))
eq('utf-8', eval('&encoding')) eq('utf-8', eval('&encoding'))
-- check nvim is still in utf-8 mode -- check nvim is still in utf-8 mode
eq(3, eval('strwidth("Bär")')) eq(3, eval('strwidth("Bär")'))
@@ -25,7 +25,7 @@ describe('&encoding', function()
clear('--cmd', 'set enc=latin1') clear('--cmd', 'set enc=latin1')
-- error message expected -- error message expected
feed('<cr>') feed('<cr>')
neq(nil, string.find(eval('v:errmsg'), '^E474:')) neq(nil, string.find(eval('v:errmsg'), '^E519:'))
eq('utf-8', eval('&encoding')) eq('utf-8', eval('&encoding'))
eq(3, eval('strwidth("Bär")')) eq(3, eval('strwidth("Bär")'))
end) end)

View File

@@ -194,8 +194,8 @@ describe('ui/cursor', function()
if m.blinkoff then m.blinkoff = 400 end if m.blinkoff then m.blinkoff = 400 end
if m.blinkwait then m.blinkwait = 700 end if m.blinkwait then m.blinkwait = 700 end
end end
if m.hl_id then m.hl_id = 47 end if m.hl_id then m.hl_id = 48 end
if m.id_lm then m.id_lm = 48 end if m.id_lm then m.id_lm = 49 end
end end
-- Assert the new expectation. -- Assert the new expectation.