]> granicus.if.org Git - vim/commitdiff
patch 8.1.0392: error while typing :/foo/s// with 'incsearch' enabled v8.1.0392
authorBram Moolenaar <Bram@vim.org>
Sat, 15 Sep 2018 13:42:40 +0000 (15:42 +0200)
committerBram Moolenaar <Bram@vim.org>
Sat, 15 Sep 2018 13:42:40 +0000 (15:42 +0200)
Problem:    Error while typing :/foo/s// with 'incsearch' enabled.
Solution:   Do not give search errors when highlighting matches.

src/ex_docmd.c
src/ex_getln.c
src/proto/ex_docmd.pro
src/testdir/test_search.vim
src/version.c

index e9f661bcad5f725db55f20050cffb5628f85e46b..82904eeaf0e48f2b365f16a1910a90e76cf09a3b 100644 (file)
@@ -117,7 +117,7 @@ static int  getargopt(exarg_T *eap);
 #endif
 
 static int     check_more(int, int);
-static linenr_T get_address(exarg_T *, char_u **, int addr_type, int skip, int to_other_file, int address_count);
+static linenr_T get_address(exarg_T *, char_u **, int addr_type, int skip, int silent, int to_other_file, int address_count);
 static void    get_flags(exarg_T *eap);
 #if !defined(FEAT_PERL) \
        || !defined(FEAT_PYTHON) || !defined(FEAT_PYTHON3) \
@@ -1853,7 +1853,7 @@ do_one_cmd(
     }
 
     ea.cmd = cmd;
-    if (parse_cmd_address(&ea, &errormsg) == FAIL)
+    if (parse_cmd_address(&ea, &errormsg, FALSE) == FAIL)
        goto doend;
 
 /*
@@ -2836,7 +2836,7 @@ parse_command_modifiers(exarg_T *eap, char_u **errormsg, int skip_only)
            case 't':   if (checkforcmd(&p, "tab", 3))
                        {
                            long tabnr = get_address(eap, &eap->cmd, ADDR_TABS,
-                                                           eap->skip, FALSE, 1);
+                                              eap->skip, skip_only, FALSE, 1);
                            if (tabnr == MAXLNUM)
                                cmdmod.tab = tabpage_index(curtab) + 1;
                            else
@@ -2911,11 +2911,11 @@ free_cmdmod(void)
 
 /*
  * Parse the address range, if any, in "eap".
- * May set the last search pattern.
+ * May set the last search pattern, unless "silent" is TRUE.
  * Return FAIL and set "errormsg" or return OK.
  */
     int
-parse_cmd_address(exarg_T *eap, char_u **errormsg)
+parse_cmd_address(exarg_T *eap, char_u **errormsg, int silent)
 {
     int                address_count = 1;
     linenr_T   lnum;
@@ -2955,7 +2955,7 @@ parse_cmd_address(exarg_T *eap, char_u **errormsg)
 #endif
        }
        eap->cmd = skipwhite(eap->cmd);
-       lnum = get_address(eap, &eap->cmd, eap->addr_type, eap->skip,
+       lnum = get_address(eap, &eap->cmd, eap->addr_type, eap->skip, silent,
                                        eap->addr_count == 0, address_count++);
        if (eap->cmd == NULL)   // error detected
            return FAIL;
@@ -4450,10 +4450,11 @@ skip_range(
 get_address(
     exarg_T    *eap UNUSED,
     char_u     **ptr,
-    int                addr_type,  /* flag: one of ADDR_LINES, ... */
-    int                skip,       /* only skip the address, don't use it */
-    int                to_other_file,  /* flag: may jump to other file */
-    int                address_count UNUSED) /* 1 for first address, >1 after comma */
+    int                addr_type,      // flag: one of ADDR_LINES, ...
+    int                skip,           // only skip the address, don't use it
+    int                silent,         // no errors or side effects
+    int                to_other_file,  // flag: may jump to other file
+    int                address_count UNUSED) // 1 for first address, >1 after comma
 {
     int                c;
     int                i;
@@ -4599,28 +4600,28 @@ get_address(
                }
                else
                {
-                   pos = curwin->w_cursor; /* save curwin->w_cursor */
-                   /*
-                    * When '/' or '?' follows another address, start
-                    * from there.
-                    */
+                   int flags;
+
+                   pos = curwin->w_cursor; // save curwin->w_cursor
+
+                   // When '/' or '?' follows another address, start from
+                   // there.
                    if (lnum != MAXLNUM)
                        curwin->w_cursor.lnum = lnum;
-                   /*
-                    * Start a forward search at the end of the line (unless
-                    * before the first line).
-                    * Start a backward search at the start of the line.
-                    * This makes sure we never match in the current
-                    * line, and can match anywhere in the
-                    * next/previous line.
-                    */
+
+                   // Start a forward search at the end of the line (unless
+                   // before the first line).
+                   // Start a backward search at the start of the line.
+                   // This makes sure we never match in the current
+                   // line, and can match anywhere in the
+                   // next/previous line.
                    if (c == '/' && curwin->w_cursor.lnum > 0)
                        curwin->w_cursor.col = MAXCOL;
                    else
                        curwin->w_cursor.col = 0;
                    searchcmdlen = 0;
-                   if (!do_search(NULL, c, cmd, 1L,
-                                         SEARCH_HIS | SEARCH_MSG, NULL, NULL))
+                   flags = silent ? 0 : SEARCH_HIS | SEARCH_MSG;
+                   if (!do_search(NULL, c, cmd, 1L, flags, NULL, NULL))
                    {
                        curwin->w_cursor = pos;
                        cmd = NULL;
@@ -9529,7 +9530,7 @@ ex_copymove(exarg_T *eap)
 {
     long       n;
 
-    n = get_address(eap, &eap->arg, eap->addr_type, FALSE, FALSE, 1);
+    n = get_address(eap, &eap->arg, eap->addr_type, FALSE, FALSE, FALSE, 1);
     if (eap->arg == NULL)          /* error detected */
     {
        eap->nextcmd = NULL;
index a72b9a4096df35c61c1b8d2aa54bbed3dd09d39d..8f3833162bfb76b79d0f31aafabfc85a8114fa02 100644 (file)
@@ -388,7 +388,7 @@ do_incsearch_highlighting(int firstc, incsearch_state_T *is_state,
     // parse the address range
     save_cursor = curwin->w_cursor;
     curwin->w_cursor = is_state->search_start;
-    parse_cmd_address(&ea, &dummy);
+    parse_cmd_address(&ea, &dummy, TRUE);
     if (ea.addr_count > 0)
     {
        // Allow for reverse match.
index 04bc0c3abdadda6ff1fea0a40b5b9293dc4534fe..8baf953b74f567df1b89d56e77f3d119d75d268c 100644 (file)
@@ -5,7 +5,7 @@ int do_cmdline(char_u *cmdline, char_u *(*fgetline)(int, void *, int), void *coo
 int getline_equal(char_u *(*fgetline)(int, void *, int), void *cookie, char_u *(*func)(int, void *, int));
 void *getline_cookie(char_u *(*fgetline)(int, void *, int), void *cookie);
 int parse_command_modifiers(exarg_T *eap, char_u **errormsg, int skip_only);
-int parse_cmd_address(exarg_T *eap, char_u **errormsg);
+int parse_cmd_address(exarg_T *eap, char_u **errormsg, int silent);
 int checkforcmd(char_u **pp, char *cmd, int len);
 int modifier_len(char_u *cmd);
 int cmd_exists(char_u *name);
index 79f864502cce5f9b22f66fcd01b58cb64bad503b..56e0bf28ebb0435b3623a69c3869dd1be89b9dc3 100644 (file)
@@ -1055,6 +1055,10 @@ func Test_keep_last_search_pattern()
   call feedkeys(":/foo/s//\<Esc>", 'ntx')
   call assert_equal('bar', @/)
 
+  " no error message if pattern not found
+  call feedkeys(":/xyz/s//\<Esc>", 'ntx')
+  call assert_equal('bar', @/)
+
   bwipe!
   call test_override("ALL", 0)
   set noincsearch
index 3a2b065bc7e3852f8744518f8cf0cfde895b4abe..d04bdab682b935e733e1899b5da85b9d3a3834b1 100644 (file)
@@ -794,6 +794,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    392,
 /**/
     391,
 /**/