From b1a4db0b69e4744f9a4b4e4844021bb9026f03a6 Mon Sep 17 00:00:00 2001 From: nate Date: Thu, 9 Nov 2017 13:33:37 -0800 Subject: [PATCH 1/2] :highlight : avoid redraw on error do_highlight() should not redraw if a validation error occurred. closes #7489 --- src/nvim/syntax.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index d28e996581..bc7362af72 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -6648,7 +6648,7 @@ do_highlight(char_u *line, int forceit, int init) { if (error && idx == highlight_ga.ga_len) { syn_unadd_group(); } else { - if (is_normal_group) { + if (!error && is_normal_group) { // Need to update all groups, because they might be using "bg" and/or // "fg", which have been changed now. highlight_attr_set_all(); From ebed8c6a2eb641397bd7a7b34ea46ca5c02ea346 Mon Sep 17 00:00:00 2001 From: nate Date: Fri, 24 Nov 2017 09:03:06 -0800 Subject: [PATCH 2/2] test: :highlight validation errors add test when highlight group doesn't exist. add test when an invalid color name is used for `cterm`. --- test/functional/ex_cmds/highlight_spec.lua | 43 ++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 test/functional/ex_cmds/highlight_spec.lua diff --git a/test/functional/ex_cmds/highlight_spec.lua b/test/functional/ex_cmds/highlight_spec.lua new file mode 100644 index 0000000000..25968b8204 --- /dev/null +++ b/test/functional/ex_cmds/highlight_spec.lua @@ -0,0 +1,43 @@ +local Screen = require('test.functional.ui.screen') +local helpers = require("test.functional.helpers")(after_each) +local eq, command = helpers.eq, helpers.command +local clear = helpers.clear +local eval, exc_exec = helpers.eval, helpers.exc_exec + +describe(':highlight', function() + local screen + + before_each(function() + clear() + screen = Screen.new() + screen:attach() + end) + + after_each(function() + screen:detach() + end) + + it('invalid color name', function() + eq('Vim(highlight):E421: Color name or number not recognized: ctermfg=#181818', + exc_exec("highlight normal ctermfg=#181818")) + eq('Vim(highlight):E421: Color name or number not recognized: ctermbg=#181818', + exc_exec("highlight normal ctermbg=#181818")) + end) + + it('invalid group name', function() + eq('Vim(highlight):E411: highlight group not found: foo', + exc_exec("highlight foo")) + end) + + it('"Normal" foreground with red', function() + eq('', eval('synIDattr(hlID("Normal"), "fg", "cterm")')) + command('highlight normal ctermfg=red') + eq('9', eval('synIDattr(hlID("Normal"), "fg", "cterm")')) + end) + + it('"Normal" background with red', function() + eq('', eval('synIDattr(hlID("Normal"), "bg", "cterm")')) + command('highlight normal ctermbg=red') + eq('9', eval('synIDattr(hlID("Normal"), "bg", "cterm")')) + end) +end)