]> granicus.if.org Git - vim/commitdiff
patch 8.1.1375: without "TS" in 'shortmess' get a hit-enter prompt often v8.1.1375
authorBram Moolenaar <Bram@vim.org>
Fri, 24 May 2019 11:11:47 +0000 (13:11 +0200)
committerBram Moolenaar <Bram@vim.org>
Fri, 24 May 2019 11:11:47 +0000 (13:11 +0200)
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)

src/main.c
src/search.c
src/testdir/test_search_stat.vim
src/version.c

index 98359505363d042982e71721b747083407027b5d..79b4844540e951429bf139e339fd1b577b830ddb 100644 (file)
@@ -1271,11 +1271,13 @@ main_loop(
            {
                char_u *p;
 
-               /* msg_attr_keep() will set keep_msg to NULL, must free the
-                * string here. Don't reset keep_msg, msg_attr_keep() uses it
-                * to check for duplicates. */
+               // msg_attr_keep() will set keep_msg to NULL, must free the
+               // string here. Don't reset keep_msg, msg_attr_keep() uses it
+               // to check for duplicates.  Never put this message in history.
                p = keep_msg;
+               msg_hist_off = TRUE;
                msg_attr((char *)p, keep_msg_attr);
+               msg_hist_off = FALSE;
                vim_free(p);
            }
            if (need_fileinfo)          /* show file info after redraw */
index 033f16384f4a6ef1101947a42693015414d78408..2bcbf0ae498f6fdf06157bd69ded59225a12589b 100644 (file)
@@ -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;
 }
index 322d137e2ec698867e2ea57f4760f88bedda0d53..ad46b2d0592ab25313fb190e4b8ca45e177e0698 100644 (file)
@@ -11,21 +11,24 @@ func! Test_search_stat()
   " Append 50 lines with text to search for, "foobar" appears 20 times
   call append(0, repeat(['foobar', 'foo', 'fooooobar', 'foba', 'foobar'], 10))
 
-  " 1) match at second line
+  " match at second line
   call cursor(1, 1)
+  let messages_before = execute('messages')
   let @/ = 'fo*\(bar\?\)\?'
   let g:a = execute(':unsilent :norm! n')
   let stat = '\[2/50\]'
   let pat = escape(@/, '()*?'). '\s\+'
   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)
   let g:a = execute(':unsilent :norm! n')
   let stat = '\[50/50\]'
   call assert_match(pat .. stat, g:a)
 
-  " 3) No search stat
+  " No search stat
   set shortmess+=S
   call cursor(1, 1)
   let stat = '\[2/50\]'
@@ -33,7 +36,7 @@ func! Test_search_stat()
   call assert_notmatch(pat .. stat, g:a)
   set shortmess-=S
 
-  " 4) Many matches
+  " Many matches
   call cursor(line('$')-2, 1)
   let @/ = '.'
   let pat = escape(@/, '()*?'). '\s\+'
@@ -45,7 +48,7 @@ func! Test_search_stat()
   let stat = '\[1/>99\] W'
   call assert_match(pat .. stat, g:a)
 
-  " 5) Many matches
+  " Many matches
   call cursor(1, 1)
   let g:a = execute(':unsilent :norm! n')
   let stat = '\[2/>99\]'
@@ -55,7 +58,7 @@ func! Test_search_stat()
   let stat = '\[>99/>99\] W'
   call assert_match(pat .. stat, g:a)
 
-  " 6) right-left
+  " right-left
   if exists("+rightleft")
     set rl
     call cursor(1,1)
@@ -67,7 +70,7 @@ func! Test_search_stat()
     set norl
   endif
 
-  " 7) right-left bottom
+  " right-left bottom
   if exists("+rightleft")
     set rl
     call cursor('$',1)
@@ -78,7 +81,7 @@ func! Test_search_stat()
     set norl
   endif
 
-  " 8) right-left back at top
+  " right-left back at top
   if exists("+rightleft")
     set rl
     call cursor('$',1)
@@ -90,7 +93,7 @@ func! Test_search_stat()
     set norl
   endif
 
-  " 9) normal, back at bottom
+  " normal, back at bottom
   call cursor(1,1)
   let @/ = 'foobar'
   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('\[20/20\] W', Screenline(&lines))
 
-  " 10) normal, no match
+  " normal, no match
   call cursor(1,1)
   let @/ = 'zzzzzz'
   let g:a = ''
@@ -114,7 +117,7 @@ func! Test_search_stat()
     call assert_false(1)
   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(.
   nnoremap n nzv
   call cursor(1,1)
@@ -130,7 +133,7 @@ func! Test_search_stat()
   call assert_match(pat .. stat, g:b)
   unmap n
 
-  " 11) normal, but silent
+  " normal, but silent
   call cursor(1,1)
   let @/ = 'find this'
   let pat = '/find this\s\+'
index e8da844e4a89f37e95f75f4991c2acb6c386c9b9..0fd12fe432b62543a6ca1c4fa5bd0cf2a099d0e6 100644 (file)
@@ -767,6 +767,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1375,
 /**/
     1374,
 /**/