diff options
author | Björn Linse <bjorn.linse@gmail.com> | 2021-08-18 14:29:42 +0200 |
---|---|---|
committer | Björn Linse <bjorn.linse@gmail.com> | 2021-08-19 15:08:50 +0200 |
commit | fca52f5f32844d8820e6a1ef2678bc79c5e6d8d8 (patch) | |
tree | 8db37b73b1f5d2b7b176ab8deaf08d19f33f778b | |
parent | a9f563ab62f6035729f79c3c701a5b219f1b982f (diff) | |
download | rneovim-fca52f5f32844d8820e6a1ef2678bc79c5e6d8d8.tar.gz rneovim-fca52f5f32844d8820e6a1ef2678bc79c5e6d8d8.tar.bz2 rneovim-fca52f5f32844d8820e6a1ef2678bc79c5e6d8d8.zip |
feat(match): allow hl group to be defined after :match command
-rw-r--r-- | runtime/doc/vim_diff.txt | 2 | ||||
-rw-r--r-- | src/nvim/testdir/test_match.vim | 5 | ||||
-rw-r--r-- | src/nvim/window.c | 3 | ||||
-rw-r--r-- | test/functional/eval/match_functions_spec.lua | 15 |
4 files changed, 14 insertions, 11 deletions
diff --git a/runtime/doc/vim_diff.txt b/runtime/doc/vim_diff.txt index 7e1bd3e087..79fb996bc1 100644 --- a/runtime/doc/vim_diff.txt +++ b/runtime/doc/vim_diff.txt @@ -159,6 +159,7 @@ Commands: |:drop| is always available |:Man| is available by default, with many improvements such as completion |:sign-define| accepts a `numhl` argument, to highlight the line number + |:match| can be invoked before highlight group is defined Events: |Signal| @@ -176,6 +177,7 @@ Functions: |msgpackdump()|, |msgpackparse()| provide msgpack de/serialization |stdpath()| |system()|, |systemlist()| can run {cmd} directly (without 'shell') + |matchadd()| can be called before highlight group is defined Highlight groups: |highlight-blend| controls blend level for a highlight group diff --git a/src/nvim/testdir/test_match.vim b/src/nvim/testdir/test_match.vim index 09448ca71b..0fd76a23ea 100644 --- a/src/nvim/testdir/test_match.vim +++ b/src/nvim/testdir/test_match.vim @@ -157,7 +157,10 @@ func Test_match_error() endfunc func Test_matchadd_error() - call assert_fails("call matchadd('GroupDoesNotExist', 'X')", 'E28:') + call clearmatches() + " Nvim: not an error anymore: + call matchadd('GroupDoesNotExist', 'X') + call assert_equal([{'group': 'GroupDoesNotExist', 'pattern': 'X', 'priority': 10, 'id': 13}], getmatches()) call assert_fails("call matchadd('Search', '\\(')", 'E475:') call assert_fails("call matchadd('Search', 'XXX', 1, 123, 1)", 'E715:') call assert_fails("call matchadd('Error', 'XXX', 1, 3)", 'E798:') diff --git a/src/nvim/window.c b/src/nvim/window.c index 5677a4d39d..fefbab822e 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -6534,8 +6534,7 @@ int match_add(win_T *wp, const char *const grp, const char *const pat, cur = cur->next; } } - if ((hlg_id = syn_name2id((const char_u *)grp)) == 0) { - EMSG2(_(e_nogroup), grp); + if ((hlg_id = syn_check_group((const char_u *)grp, strlen(grp))) == 0) { return -1; } if (pat != NULL && (regprog = vim_regcomp((char_u *)pat, RE_MAGIC)) == NULL) { diff --git a/test/functional/eval/match_functions_spec.lua b/test/functional/eval/match_functions_spec.lua index f399ef47d3..9f168c913a 100644 --- a/test/functional/eval/match_functions_spec.lua +++ b/test/functional/eval/match_functions_spec.lua @@ -6,7 +6,6 @@ local clear = helpers.clear local funcs = helpers.funcs local command = helpers.command local exc_exec = helpers.exc_exec -local pcall_err = helpers.pcall_err before_each(clear) @@ -40,13 +39,13 @@ describe('setmatches()', function() }}, funcs.getmatches()) end) - it('fails with -1 if highlight group is not defined', function() - eq('Vim:E28: No such highlight group name: 1', - pcall_err(funcs.setmatches, {{group=1, pattern=2, id=3, priority=4}})) - eq({}, funcs.getmatches()) - eq('Vim:E28: No such highlight group name: 1', - pcall_err(funcs.setmatches, {{group=1, pos1={2}, pos2={6}, id=3, priority=4, conceal=5}})) - eq({}, funcs.getmatches()) + it('does not fail if highlight group is not defined', function() + eq(0, funcs.setmatches{{group=1, pattern=2, id=3, priority=4}}) + eq({{group='1', pattern='2', id=3, priority=4}}, + funcs.getmatches()) + eq(0, funcs.setmatches{{group=1, pos1={2}, pos2={6}, id=3, priority=4, conceal=5}}) + eq({{group='1', pos1={2}, pos2={6}, id=3, priority=4, conceal='5'}}, + funcs.getmatches()) end) end) |