diff options
author | Bram Moolenaar <Bram@vim.org> | 2019-05-24 13:11:47 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2019-05-24 13:11:47 +0200 |
commit | 984f031fb02fe301a8dbf8a35b871c9f60b8f61e (patch) | |
tree | 9b6cd362927d00e776e7b476181ee9cbfc3a724b /src/search.c | |
parent | c97582b0296cb6f63f3c2e5a0eb954f5920a8e42 (diff) | |
download | vim-git-984f031fb02fe301a8dbf8a35b871c9f60b8f61e.tar.gz |
patch 8.1.1375: without "TS" in 'shortmess' get a hit-enter prompt oftenv8.1.1375
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)
Diffstat (limited to 'src/search.c')
-rw-r--r-- | src/search.c | 54 |
1 files changed, 31 insertions, 23 deletions
diff --git a/src/search.c b/src/search.c index 033f16384..2bcbf0ae4 100644 --- a/src/search.c +++ b/src/search.c @@ -1381,10 +1381,29 @@ do_search( && !cmd_silent && msg_silent == 0) { char_u *trunc; + char_u off_buf[40]; + int off_len = 0; // Compute msg_row early. 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) p = spats[0].pat; else @@ -1393,19 +1412,21 @@ do_search( if (!shortmess(SHM_SEARCHCOUNT)) { // 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) // Use all the columns. len = (int)(Rows - msg_row) * Columns - 1; else // Use up to 'showcmd' column. len = (int)(Rows - msg_row - 1) * Columns + sc_col - 1; - if (len < STRLEN(p) + 40 + SEARCH_STAT_BUF_LEN + 1) - len = STRLEN(p) + 40 + SEARCH_STAT_BUF_LEN + 1; + if (len < STRLEN(p) + off_len + SEARCH_STAT_BUF_LEN + 3) + len = STRLEN(p) + off_len + SEARCH_STAT_BUF_LEN + 3; } else // Reserve enough space for the search pattern + offset. - len = STRLEN(p) + 40; + len = STRLEN(p) + off_len + 3; msgbuf = alloc((int)len); if (msgbuf != NULL) @@ -1422,25 +1443,10 @@ do_search( } else mch_memmove(msgbuf + 1, p, STRLEN(p)); - if (spats[0].off.line || spats[0].off.end || spats[0].off.off) - { - 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 - } - } + if (off_len > 0) + mch_memmove(msgbuf + STRLEN(p) + 1, off_buf, off_len); - trunc = msg_strtrunc(msgbuf, FALSE); + trunc = msg_strtrunc(msgbuf, TRUE); if (trunc != NULL) { vim_free(msgbuf); @@ -5028,8 +5034,10 @@ search_stat( lbuf = curbuf; 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); + msg_hist_off = FALSE; } p_ws = save_ws; } |