mirror of
https://github.com/vim/vim.git
synced 2025-10-01 04:54:07 -04:00
patch 8.1.1375: without "TS" in 'shortmess' get a hit-enter prompt often
Problem: Without "TS" in 'shortmess' get a hit-enter prompt often. Solution: Always truncate the search message. Also avoid putting it in the message history. (closes #4413)
This commit is contained in:
@@ -1271,11 +1271,13 @@ main_loop(
|
|||||||
{
|
{
|
||||||
char_u *p;
|
char_u *p;
|
||||||
|
|
||||||
/* msg_attr_keep() will set keep_msg to NULL, must free the
|
// msg_attr_keep() will set keep_msg to NULL, must free the
|
||||||
* string here. Don't reset keep_msg, msg_attr_keep() uses it
|
// string here. Don't reset keep_msg, msg_attr_keep() uses it
|
||||||
* to check for duplicates. */
|
// to check for duplicates. Never put this message in history.
|
||||||
p = keep_msg;
|
p = keep_msg;
|
||||||
|
msg_hist_off = TRUE;
|
||||||
msg_attr((char *)p, keep_msg_attr);
|
msg_attr((char *)p, keep_msg_attr);
|
||||||
|
msg_hist_off = FALSE;
|
||||||
vim_free(p);
|
vim_free(p);
|
||||||
}
|
}
|
||||||
if (need_fileinfo) /* show file info after redraw */
|
if (need_fileinfo) /* show file info after redraw */
|
||||||
|
54
src/search.c
54
src/search.c
@@ -1381,10 +1381,29 @@ do_search(
|
|||||||
&& !cmd_silent && msg_silent == 0)
|
&& !cmd_silent && msg_silent == 0)
|
||||||
{
|
{
|
||||||
char_u *trunc;
|
char_u *trunc;
|
||||||
|
char_u off_buf[40];
|
||||||
|
int off_len = 0;
|
||||||
|
|
||||||
// Compute msg_row early.
|
// Compute msg_row early.
|
||||||
msg_start();
|
msg_start();
|
||||||
|
|
||||||
|
// Get the offset, so we know how long it is.
|
||||||
|
if (spats[0].off.line || spats[0].off.end || spats[0].off.off)
|
||||||
|
{
|
||||||
|
p = off_buf;
|
||||||
|
*p++ = dirc;
|
||||||
|
if (spats[0].off.end)
|
||||||
|
*p++ = 'e';
|
||||||
|
else if (!spats[0].off.line)
|
||||||
|
*p++ = 's';
|
||||||
|
if (spats[0].off.off > 0 || spats[0].off.line)
|
||||||
|
*p++ = '+';
|
||||||
|
*p = NUL;
|
||||||
|
if (spats[0].off.off != 0 || spats[0].off.line)
|
||||||
|
sprintf((char *)p, "%ld", spats[0].off.off);
|
||||||
|
off_len = STRLEN(off_buf);
|
||||||
|
}
|
||||||
|
|
||||||
if (*searchstr == NUL)
|
if (*searchstr == NUL)
|
||||||
p = spats[0].pat;
|
p = spats[0].pat;
|
||||||
else
|
else
|
||||||
@@ -1393,19 +1412,21 @@ do_search(
|
|||||||
if (!shortmess(SHM_SEARCHCOUNT))
|
if (!shortmess(SHM_SEARCHCOUNT))
|
||||||
{
|
{
|
||||||
// Reserve enough space for the search pattern + offset +
|
// Reserve enough space for the search pattern + offset +
|
||||||
// search stat.
|
// search stat. Use all the space available, so that the
|
||||||
|
// search state is right aligned. If there is not enough space
|
||||||
|
// msg_strtrunc() will shorten in the middle.
|
||||||
if (msg_scrolled != 0)
|
if (msg_scrolled != 0)
|
||||||
// Use all the columns.
|
// Use all the columns.
|
||||||
len = (int)(Rows - msg_row) * Columns - 1;
|
len = (int)(Rows - msg_row) * Columns - 1;
|
||||||
else
|
else
|
||||||
// Use up to 'showcmd' column.
|
// Use up to 'showcmd' column.
|
||||||
len = (int)(Rows - msg_row - 1) * Columns + sc_col - 1;
|
len = (int)(Rows - msg_row - 1) * Columns + sc_col - 1;
|
||||||
if (len < STRLEN(p) + 40 + SEARCH_STAT_BUF_LEN + 1)
|
if (len < STRLEN(p) + off_len + SEARCH_STAT_BUF_LEN + 3)
|
||||||
len = STRLEN(p) + 40 + SEARCH_STAT_BUF_LEN + 1;
|
len = STRLEN(p) + off_len + SEARCH_STAT_BUF_LEN + 3;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
// Reserve enough space for the search pattern + offset.
|
// Reserve enough space for the search pattern + offset.
|
||||||
len = STRLEN(p) + 40;
|
len = STRLEN(p) + off_len + 3;
|
||||||
|
|
||||||
msgbuf = alloc((int)len);
|
msgbuf = alloc((int)len);
|
||||||
if (msgbuf != NULL)
|
if (msgbuf != NULL)
|
||||||
@@ -1422,25 +1443,10 @@ do_search(
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
mch_memmove(msgbuf + 1, p, STRLEN(p));
|
mch_memmove(msgbuf + 1, p, STRLEN(p));
|
||||||
if (spats[0].off.line || spats[0].off.end || spats[0].off.off)
|
if (off_len > 0)
|
||||||
{
|
mch_memmove(msgbuf + STRLEN(p) + 1, off_buf, off_len);
|
||||||
p = msgbuf + STRLEN(p) + 1;
|
|
||||||
*p++ = dirc;
|
|
||||||
if (spats[0].off.end)
|
|
||||||
*p++ = 'e';
|
|
||||||
else if (!spats[0].off.line)
|
|
||||||
*p++ = 's';
|
|
||||||
if (spats[0].off.off > 0 || spats[0].off.line)
|
|
||||||
*p++ = '+';
|
|
||||||
if (spats[0].off.off != 0 || spats[0].off.line)
|
|
||||||
{
|
|
||||||
int l = 0;
|
|
||||||
l = sprintf((char *)p, "%ld", spats[0].off.off);
|
|
||||||
p[l] = ' '; // remove NUL from sprintf
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
trunc = msg_strtrunc(msgbuf, FALSE);
|
trunc = msg_strtrunc(msgbuf, TRUE);
|
||||||
if (trunc != NULL)
|
if (trunc != NULL)
|
||||||
{
|
{
|
||||||
vim_free(msgbuf);
|
vim_free(msgbuf);
|
||||||
@@ -5028,8 +5034,10 @@ search_stat(
|
|||||||
lbuf = curbuf;
|
lbuf = curbuf;
|
||||||
lastpos = p;
|
lastpos = p;
|
||||||
|
|
||||||
// keep the message even after redraw
|
// keep the message even after redraw, but don't put in history
|
||||||
|
msg_hist_off = TRUE;
|
||||||
give_warning(msgbuf, FALSE);
|
give_warning(msgbuf, FALSE);
|
||||||
|
msg_hist_off = FALSE;
|
||||||
}
|
}
|
||||||
p_ws = save_ws;
|
p_ws = save_ws;
|
||||||
}
|
}
|
||||||
|
@@ -11,21 +11,24 @@ func! Test_search_stat()
|
|||||||
" Append 50 lines with text to search for, "foobar" appears 20 times
|
" Append 50 lines with text to search for, "foobar" appears 20 times
|
||||||
call append(0, repeat(['foobar', 'foo', 'fooooobar', 'foba', 'foobar'], 10))
|
call append(0, repeat(['foobar', 'foo', 'fooooobar', 'foba', 'foobar'], 10))
|
||||||
|
|
||||||
" 1) match at second line
|
" match at second line
|
||||||
call cursor(1, 1)
|
call cursor(1, 1)
|
||||||
|
let messages_before = execute('messages')
|
||||||
let @/ = 'fo*\(bar\?\)\?'
|
let @/ = 'fo*\(bar\?\)\?'
|
||||||
let g:a = execute(':unsilent :norm! n')
|
let g:a = execute(':unsilent :norm! n')
|
||||||
let stat = '\[2/50\]'
|
let stat = '\[2/50\]'
|
||||||
let pat = escape(@/, '()*?'). '\s\+'
|
let pat = escape(@/, '()*?'). '\s\+'
|
||||||
call assert_match(pat .. stat, g:a)
|
call assert_match(pat .. stat, g:a)
|
||||||
|
" didn't get added to message history
|
||||||
|
call assert_equal(messages_before, execute('messages'))
|
||||||
|
|
||||||
" 2) Match at last line
|
" Match at last line
|
||||||
call cursor(line('$')-2, 1)
|
call cursor(line('$')-2, 1)
|
||||||
let g:a = execute(':unsilent :norm! n')
|
let g:a = execute(':unsilent :norm! n')
|
||||||
let stat = '\[50/50\]'
|
let stat = '\[50/50\]'
|
||||||
call assert_match(pat .. stat, g:a)
|
call assert_match(pat .. stat, g:a)
|
||||||
|
|
||||||
" 3) No search stat
|
" No search stat
|
||||||
set shortmess+=S
|
set shortmess+=S
|
||||||
call cursor(1, 1)
|
call cursor(1, 1)
|
||||||
let stat = '\[2/50\]'
|
let stat = '\[2/50\]'
|
||||||
@@ -33,7 +36,7 @@ func! Test_search_stat()
|
|||||||
call assert_notmatch(pat .. stat, g:a)
|
call assert_notmatch(pat .. stat, g:a)
|
||||||
set shortmess-=S
|
set shortmess-=S
|
||||||
|
|
||||||
" 4) Many matches
|
" Many matches
|
||||||
call cursor(line('$')-2, 1)
|
call cursor(line('$')-2, 1)
|
||||||
let @/ = '.'
|
let @/ = '.'
|
||||||
let pat = escape(@/, '()*?'). '\s\+'
|
let pat = escape(@/, '()*?'). '\s\+'
|
||||||
@@ -45,7 +48,7 @@ func! Test_search_stat()
|
|||||||
let stat = '\[1/>99\] W'
|
let stat = '\[1/>99\] W'
|
||||||
call assert_match(pat .. stat, g:a)
|
call assert_match(pat .. stat, g:a)
|
||||||
|
|
||||||
" 5) Many matches
|
" Many matches
|
||||||
call cursor(1, 1)
|
call cursor(1, 1)
|
||||||
let g:a = execute(':unsilent :norm! n')
|
let g:a = execute(':unsilent :norm! n')
|
||||||
let stat = '\[2/>99\]'
|
let stat = '\[2/>99\]'
|
||||||
@@ -55,7 +58,7 @@ func! Test_search_stat()
|
|||||||
let stat = '\[>99/>99\] W'
|
let stat = '\[>99/>99\] W'
|
||||||
call assert_match(pat .. stat, g:a)
|
call assert_match(pat .. stat, g:a)
|
||||||
|
|
||||||
" 6) right-left
|
" right-left
|
||||||
if exists("+rightleft")
|
if exists("+rightleft")
|
||||||
set rl
|
set rl
|
||||||
call cursor(1,1)
|
call cursor(1,1)
|
||||||
@@ -67,7 +70,7 @@ func! Test_search_stat()
|
|||||||
set norl
|
set norl
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" 7) right-left bottom
|
" right-left bottom
|
||||||
if exists("+rightleft")
|
if exists("+rightleft")
|
||||||
set rl
|
set rl
|
||||||
call cursor('$',1)
|
call cursor('$',1)
|
||||||
@@ -78,7 +81,7 @@ func! Test_search_stat()
|
|||||||
set norl
|
set norl
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" 8) right-left back at top
|
" right-left back at top
|
||||||
if exists("+rightleft")
|
if exists("+rightleft")
|
||||||
set rl
|
set rl
|
||||||
call cursor('$',1)
|
call cursor('$',1)
|
||||||
@@ -90,7 +93,7 @@ func! Test_search_stat()
|
|||||||
set norl
|
set norl
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" 9) normal, back at bottom
|
" normal, back at bottom
|
||||||
call cursor(1,1)
|
call cursor(1,1)
|
||||||
let @/ = 'foobar'
|
let @/ = 'foobar'
|
||||||
let pat = '?foobar\s\+'
|
let pat = '?foobar\s\+'
|
||||||
@@ -100,7 +103,7 @@ func! Test_search_stat()
|
|||||||
call assert_match('search hit TOP, continuing at BOTTOM', g:a)
|
call assert_match('search hit TOP, continuing at BOTTOM', g:a)
|
||||||
call assert_match('\[20/20\] W', Screenline(&lines))
|
call assert_match('\[20/20\] W', Screenline(&lines))
|
||||||
|
|
||||||
" 10) normal, no match
|
" normal, no match
|
||||||
call cursor(1,1)
|
call cursor(1,1)
|
||||||
let @/ = 'zzzzzz'
|
let @/ = 'zzzzzz'
|
||||||
let g:a = ''
|
let g:a = ''
|
||||||
@@ -114,7 +117,7 @@ func! Test_search_stat()
|
|||||||
call assert_false(1)
|
call assert_false(1)
|
||||||
endtry
|
endtry
|
||||||
|
|
||||||
" 11) normal, n comes from a mapping
|
" normal, n comes from a mapping
|
||||||
" Need to move over more than 64 lines to trigger char_avail(.
|
" Need to move over more than 64 lines to trigger char_avail(.
|
||||||
nnoremap n nzv
|
nnoremap n nzv
|
||||||
call cursor(1,1)
|
call cursor(1,1)
|
||||||
@@ -130,7 +133,7 @@ func! Test_search_stat()
|
|||||||
call assert_match(pat .. stat, g:b)
|
call assert_match(pat .. stat, g:b)
|
||||||
unmap n
|
unmap n
|
||||||
|
|
||||||
" 11) normal, but silent
|
" normal, but silent
|
||||||
call cursor(1,1)
|
call cursor(1,1)
|
||||||
let @/ = 'find this'
|
let @/ = 'find this'
|
||||||
let pat = '/find this\s\+'
|
let pat = '/find this\s\+'
|
||||||
|
@@ -767,6 +767,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
1375,
|
||||||
/**/
|
/**/
|
||||||
1374,
|
1374,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user