diff src/search.c @ 16746:73ff6357da5b v8.1.1375

patch 8.1.1375: without "TS" in 'shortmess' get a hit-enter prompt often commit https://github.com/vim/vim/commit/984f031fb02fe301a8dbf8a35b871c9f60b8f61e Author: Bram Moolenaar <Bram@vim.org> Date: Fri May 24 13:11:47 2019 +0200 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)
author Bram Moolenaar <Bram@vim.org>
date Fri, 24 May 2019 13:15:05 +0200
parents b52ea9c5f1db
children 75703a39d875
line wrap: on
line diff
--- 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
-		    }
-		}
-
-		trunc = msg_strtrunc(msgbuf, FALSE);
+		if (off_len > 0)
+		    mch_memmove(msgbuf + STRLEN(p) + 1, off_buf, off_len);
+
+		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;
 }