mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 11:28:22 +00:00
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)
264cf5cfaf
This commit is contained in:
@@ -307,16 +307,16 @@ static bool do_incsearch_highlighting(int firstc, incsearch_state_T *s,
|
|||||||
cmdmod = save_cmdmod;
|
cmdmod = save_cmdmod;
|
||||||
|
|
||||||
cmd = skip_range(ea.cmd, NULL);
|
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.
|
// Skip over "substitute" to find the pattern separator.
|
||||||
for (p = cmd; ASCII_ISALPHA(*p); p++) {}
|
for (p = cmd; ASCII_ISALPHA(*p); p++) {}
|
||||||
if (*skipwhite(p) != NUL
|
if (*skipwhite(p) != NUL) {
|
||||||
&& (STRNCMP(cmd, "substitute", p - cmd) == 0
|
if (STRNCMP(cmd, "substitute", p - cmd) == 0
|
||||||
|| STRNCMP(cmd, "smagic", p - cmd) == 0
|
|| STRNCMP(cmd, "smagic", p - cmd) == 0
|
||||||
|| STRNCMP(cmd, "snomagic", MAX(p - cmd, 3)) == 0
|
|| STRNCMP(cmd, "snomagic", MAX(p - cmd, 3)) == 0
|
||||||
|| STRNCMP(cmd, "sort", p - cmd) == 0
|
|| STRNCMP(cmd, "sort", MAX(p - cmd,3)) == 0
|
||||||
|| STRNCMP(cmd, "global", p - cmd) == 0
|
|| STRNCMP(cmd, "global", p - cmd) == 0
|
||||||
|| STRNCMP(cmd, "vglobal", p - cmd) == 0)) {
|
|| STRNCMP(cmd, "vglobal", p - cmd) == 0) {
|
||||||
if (*cmd == 's' && cmd[1] == 'm') {
|
if (*cmd == 's' && cmd[1] == 'm') {
|
||||||
p_magic = true;
|
p_magic = true;
|
||||||
}
|
}
|
||||||
@@ -345,10 +345,29 @@ static bool do_incsearch_highlighting(int firstc, incsearch_state_T *s,
|
|||||||
p = skipwhite(p);
|
p = skipwhite(p);
|
||||||
delim = *p++;
|
delim = *p++;
|
||||||
end = skip_regexp(p, delim, p_magic, NULL);
|
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;
|
||||||
|
}
|
||||||
if (end > p || *end == delim) {
|
if (end > p || *end == delim) {
|
||||||
pos_T save_cursor = curwin->w_cursor;
|
pos_T save_cursor = curwin->w_cursor;
|
||||||
|
|
||||||
// found a non-empty pattern
|
// found a non-empty pattern or //
|
||||||
*skiplen = (int)(p - ccline.cmdbuff);
|
*skiplen = (int)(p - ccline.cmdbuff);
|
||||||
*patlen = (int)(end - p);
|
*patlen = (int)(end - p);
|
||||||
|
|
||||||
|
@@ -719,6 +719,53 @@ func Test_incsearch_ssort_dump()
|
|||||||
call delete('Xis_sort_script')
|
call delete('Xis_sort_script')
|
||||||
endfunc
|
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()
|
func Test_incsearch_with_change()
|
||||||
if !has('timers') || !exists('+incsearch') || !CanRunVimInTerminal()
|
if !has('timers') || !exists('+incsearch') || !CanRunVimInTerminal()
|
||||||
throw 'Skipped: cannot make screendumps and/or timers feature and/or incsearch option missing'
|
throw 'Skipped: cannot make screendumps and/or timers feature and/or incsearch option missing'
|
||||||
|
@@ -587,4 +587,56 @@ describe('search cmdline', function()
|
|||||||
]])
|
]])
|
||||||
feed('<esc>')
|
feed('<esc>')
|
||||||
end)
|
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)
|
end)
|
||||||
|
Reference in New Issue
Block a user