aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAufar Gilbran <aufargilbran@gmail.com>2020-08-19 00:49:51 +0800
committerAufar Gilbran <aufargilbran@gmail.com>2020-09-11 10:33:20 +0800
commit77bb48e740b260acd884242d77dc3e306ff9795c (patch)
tree2245f611a02f272458d29142c8f92606784027b4
parentab7e101540435b7de221ded309b34f2f000105f4 (diff)
downloadrneovim-77bb48e740b260acd884242d77dc3e306ff9795c.tar.gz
rneovim-77bb48e740b260acd884242d77dc3e306ff9795c.tar.bz2
rneovim-77bb48e740b260acd884242d77dc3e306ff9795c.zip
vim-patch:8.1.0295: no 'incsearch' highlighting for :vimgrep and similar
Problem: No 'incsearch' highlighting for :vimgrep and similar commands. Solution: Parse the :vimgrep command and similar ones to locate the search pattern. (Hirohito Higashi, closes vim/vim#3344) https://github.com/vim/vim/commit/264cf5cfaf40e704aea2578e70c15ed9a9d0161e
-rw-r--r--src/nvim/ex_getln.c81
-rw-r--r--src/nvim/testdir/test_search.vim47
-rw-r--r--test/functional/legacy/search_spec.lua52
3 files changed, 149 insertions, 31 deletions
diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c
index 95348de320..8e7d114820 100644
--- a/src/nvim/ex_getln.c
+++ b/src/nvim/ex_getln.c
@@ -307,48 +307,67 @@ static bool do_incsearch_highlighting(int firstc, incsearch_state_T *s,
cmdmod = save_cmdmod;
cmd = skip_range(ea.cmd, NULL);
- if (*cmd == 's' || *cmd == 'g' || *cmd == 'v') {
+ if (*cmd == 's' || *cmd == 'g' || *cmd == 'v' || *cmd == 'l') {
// Skip over "substitute" to find the pattern separator.
for (p = cmd; ASCII_ISALPHA(*p); p++) {}
- if (*skipwhite(p) != NUL
- && (STRNCMP(cmd, "substitute", p - cmd) == 0
- || STRNCMP(cmd, "smagic", p - cmd) == 0
- || STRNCMP(cmd, "snomagic", MAX(p - cmd, 3)) == 0
- || STRNCMP(cmd, "sort", p - cmd) == 0
- || STRNCMP(cmd, "global", p - cmd) == 0
- || STRNCMP(cmd, "vglobal", p - cmd) == 0)) {
- if (*cmd == 's' && cmd[1] == 'm') {
- p_magic = true;
- }
- else if (*cmd == 's' && cmd[1] == 'n') {
- p_magic = false;
- }
+ if (*skipwhite(p) != NUL) {
+ if (STRNCMP(cmd, "substitute", p - cmd) == 0
+ || STRNCMP(cmd, "smagic", p - cmd) == 0
+ || STRNCMP(cmd, "snomagic", MAX(p - cmd, 3)) == 0
+ || STRNCMP(cmd, "sort", MAX(p - cmd,3)) == 0
+ || STRNCMP(cmd, "global", p - cmd) == 0
+ || STRNCMP(cmd, "vglobal", p - cmd) == 0) {
+ if (*cmd == 's' && cmd[1] == 'm') {
+ p_magic = true;
+ }
+ else if (*cmd == 's' && cmd[1] == 'n') {
+ p_magic = false;
+ }
- // Check for "global!/".
- if (*cmd == 'g' && *p == '!') {
- p++;
- if (*skipwhite(p) == NUL) {
- return false;
+ // Check for "global!/".
+ if (*cmd == 'g' && *p == '!') {
+ p++;
+ if (*skipwhite(p) == NUL) {
+ return false;
+ }
}
- }
- // For ":sort" skip over flags.
- if (cmd[0] == 's' && cmd[1] == 'o') {
- while (ASCII_ISALPHA(*(p = skipwhite(p)))) {
- ++p;
+ // For ":sort" skip over flags.
+ if (cmd[0] == 's' && cmd[1] == 'o') {
+ while (ASCII_ISALPHA(*(p = skipwhite(p)))) {
+ ++p;
+ }
+ if (*p == NUL) {
+ return false;
+ }
}
- if (*p == NUL) {
- return false;
+
+ p = skipwhite(p);
+ delim = *p++;
+ end = skip_regexp(p, delim, p_magic, NULL);
+ } else if (STRNCMP(cmd, "vimgrep", MAX(p - cmd, 3)) == 0
+ || STRNCMP(cmd, "vimgrepadd", MAX(p - cmd, 8)) == 0
+ || STRNCMP(cmd, "lvimgrep", MAX(p - cmd, 2)) == 0
+ || STRNCMP(cmd, "lvimgrepadd", MAX(p - cmd, 9)) == 0) {
+ // Check for "!/".
+ if (*p == '!') {
+ p++;
+ if (*skipwhite(p) == NUL) {
+ return false;
+ }
}
+ p = skipwhite(p);
+ delim = (vim_isIDc(*p)) ? ' ' : *p++;
+ end = skip_regexp(p, delim, p_magic, NULL);
+ }
+ else {
+ end = p;
+ delim = -1;
}
-
- p = skipwhite(p);
- delim = *p++;
- end = skip_regexp(p, delim, p_magic, NULL);
if (end > p || *end == delim) {
pos_T save_cursor = curwin->w_cursor;
- // found a non-empty pattern
+ // found a non-empty pattern or //
*skiplen = (int)(p - ccline.cmdbuff);
*patlen = (int)(end - p);
diff --git a/src/nvim/testdir/test_search.vim b/src/nvim/testdir/test_search.vim
index 96315faf2d..ef25a3c14d 100644
--- a/src/nvim/testdir/test_search.vim
+++ b/src/nvim/testdir/test_search.vim
@@ -719,6 +719,53 @@ func Test_incsearch_ssort_dump()
call delete('Xis_sort_script')
endfunc
+" Similar to Test_incsearch_substitute_dump() for :vimgrep famiry
+func Test_incsearch_vimgrep_dump()
+ if !exists('+incsearch')
+ return
+ endif
+ if !CanRunVimInTerminal()
+ throw 'Skipped: cannot make screendumps'
+ endif
+ call writefile([
+ \ 'set incsearch hlsearch scrolloff=0',
+ \ 'call setline(1, ["another one 2", "that one 3", "the one 1"])',
+ \ ], 'Xis_vimgrep_script')
+ let buf = RunVimInTerminal('-S Xis_vimgrep_script', {'rows': 9, 'cols': 70})
+ " Give Vim a chance to redraw to get rid of the spaces in line 2 caused by
+ " the 'ambiwidth' check.
+ sleep 100m
+
+ " Need to send one key at a time to force a redraw.
+ call term_sendkeys(buf, ':vimgrep on')
+ sleep 100m
+ call VerifyScreenDump(buf, 'Test_incsearch_vimgrep_01', {})
+ call term_sendkeys(buf, "\<Esc>")
+
+ call term_sendkeys(buf, ':vimg /on/ *.txt')
+ sleep 100m
+ call VerifyScreenDump(buf, 'Test_incsearch_vimgrep_02', {})
+ call term_sendkeys(buf, "\<Esc>")
+
+ call term_sendkeys(buf, ':vimgrepadd "\<on')
+ sleep 100m
+ call VerifyScreenDump(buf, 'Test_incsearch_vimgrep_03', {})
+ call term_sendkeys(buf, "\<Esc>")
+
+ call term_sendkeys(buf, ':lv "tha')
+ sleep 100m
+ call VerifyScreenDump(buf, 'Test_incsearch_vimgrep_04', {})
+ call term_sendkeys(buf, "\<Esc>")
+
+ call term_sendkeys(buf, ':lvimgrepa "the" **/*.txt')
+ sleep 100m
+ call VerifyScreenDump(buf, 'Test_incsearch_vimgrep_05', {})
+ call term_sendkeys(buf, "\<Esc>")
+
+ call StopVimInTerminal(buf)
+ call delete('Xis_vimgrep_script')
+endfunc
+
func Test_incsearch_with_change()
if !has('timers') || !exists('+incsearch') || !CanRunVimInTerminal()
throw 'Skipped: cannot make screendumps and/or timers feature and/or incsearch option missing'
diff --git a/test/functional/legacy/search_spec.lua b/test/functional/legacy/search_spec.lua
index 0802b43689..bb039a585c 100644
--- a/test/functional/legacy/search_spec.lua
+++ b/test/functional/legacy/search_spec.lua
@@ -587,4 +587,56 @@ describe('search cmdline', function()
]])
feed('<esc>')
end)
+
+ it('incsearch works with :vimgrep family', function()
+ -- oldtest: Test_incsearch_vimgrep_dump().
+ screen:try_resize(30, 4)
+ command('set incsearch hlsearch scrolloff=0')
+ funcs.setline(1, {'another one 2', 'that one 3', 'the one 1'})
+
+ feed(':vimgrep on')
+ screen:expect([[
+ another {inc:on}e 2 |
+ that {hl:on}e 3 |
+ the {hl:on}e 1 |
+ :vimgrep on^ |
+ ]])
+ feed('<esc>')
+
+ feed(':vimg /on/ *.txt')
+ screen:expect([[
+ another {inc:on}e 2 |
+ that {hl:on}e 3 |
+ the {hl:on}e 1 |
+ :vimg /on/ *.txt^ |
+ ]])
+ feed('<esc>')
+
+ feed(':vimgrepadd "\\<LT>on')
+ screen:expect([[
+ another {inc:on}e 2 |
+ that {hl:on}e 3 |
+ the {hl:on}e 1 |
+ :vimgrepadd "\<on^ |
+ ]])
+ feed('<esc>')
+
+ feed(':lv "tha')
+ screen:expect([[
+ another one 2 |
+ {inc:tha}t one 3 |
+ the one 1 |
+ :lv "tha^ |
+ ]])
+ feed('<esc>')
+
+ feed(':lvimgrepa "the" **/*.txt')
+ screen:expect([[
+ ano{inc:the}r one 2 |
+ that one 3 |
+ {hl:the} one 1 |
+ :lvimgrepa "the" **/*.txt^ |
+ ]])
+ feed('<esc>')
+ end)
end)