Patch 8.1.0351
Problem:    'incsearch' for :/foo/s//<Esc> changes last search pattern.
Solution:   Save the last search pattern earlier.
Files:      src/ex_docmd.c, src/ex_getln.c, src/testdir/test_search.vim


*** ../vim-8.1.0350/src/ex_docmd.c      2018-08-30 15:58:23.244944556 +0200
--- src/ex_docmd.c      2018-09-06 21:39:52.646486318 +0200
***************
*** 2911,2916 ****
--- 2911,2917 ----
  
  /*
   * Parse the address range, if any, in "eap".
+  * May set the last search pattern.
   * Return FAIL and set "errormsg" or return OK.
   */
      int
***************
*** 4436,4445 ****
  }
  
  /*
!  * get a single EX address
   *
   * Set ptr to the next character after the part that was interpreted.
   * Set ptr to NULL when an error is encountered.
   *
   * Return MAXLNUM when no Ex address was found.
   */
--- 4437,4447 ----
  }
  
  /*
!  * Get a single EX address.
   *
   * Set ptr to the next character after the part that was interpreted.
   * Set ptr to NULL when an error is encountered.
+  * This may set the last used search pattern.
   *
   * Return MAXLNUM when no Ex address was found.
   */
*** ../vim-8.1.0350/src/ex_getln.c      2018-08-31 22:09:31.561549259 +0200
--- src/ex_getln.c      2018-09-06 21:39:30.638725276 +0200
***************
*** 271,276 ****
--- 271,277 ----
  /*
   * Return TRUE when 'incsearch' highlighting is to be done.
   * Sets search_first_line and search_last_line to the address range.
+  * May change the last search pattern.
   */
      static int
  do_incsearch_highlighting(int firstc, incsearch_state_T *is_state,
***************
*** 470,477 ****
--- 471,482 ----
      int               next_char;
      int               use_last_pat;
  
+     // Parsing range may already set the last search pattern.
+     save_last_search_pattern();
+ 
      if (!do_incsearch_highlighting(firstc, is_state, &skiplen, &patlen))
      {
+       restore_last_search_pattern();
        finish_incsearch_highlighting(FALSE, is_state, TRUE);
        return;
      }
***************
*** 479,484 ****
--- 484,490 ----
      // If there is a character waiting, search and redraw later.
      if (char_avail())
      {
+       restore_last_search_pattern();
        is_state->incsearch_postponed = TRUE;
        return;
      }
***************
*** 493,499 ****
        curwin->w_cursor.lnum = search_first_line;
        curwin->w_cursor.col = 0;
      }
-     save_last_search_pattern();
  
      // Use the previous pattern for ":s//".
      next_char = ccline.cmdbuff[skiplen + patlen];
--- 499,504 ----
***************
*** 627,636 ****
--- 632,650 ----
      int           i;
      int           save;
  
+     // Parsing range may already set the last search pattern.
+     save_last_search_pattern();
+ 
      if (!do_incsearch_highlighting(firstc, is_state, &skiplen, &patlen))
+     {
+       restore_last_search_pattern();
        return OK;
+     }
      if (patlen == 0 && ccline.cmdbuff[skiplen] == NUL)
+     {
+       restore_last_search_pattern();
        return FAIL;
+     }
  
      if (firstc == ccline.cmdbuff[skiplen])
      {
***************
*** 641,647 ****
      else
        pat = ccline.cmdbuff + skiplen;
  
-     save_last_search_pattern();
      cursor_off();
      out_flush();
      if (c == Ctrl_G)
--- 655,660 ----
***************
*** 721,728 ****
--- 734,747 ----
  {
      int               skiplen, patlen;
  
+     // Parsing range may already set the last search pattern.
+     save_last_search_pattern();
+ 
      if (!do_incsearch_highlighting(firstc, is_state, &skiplen, &patlen))
+     {
+       restore_last_search_pattern();
        return FAIL;
+     }
  
      // Add a character from under the cursor for 'incsearch'.
      if (is_state->did_incsearch)
*** ../vim-8.1.0350/src/testdir/test_search.vim 2018-08-31 22:09:31.561549259 
+0200
--- src/testdir/test_search.vim 2018-09-06 21:36:42.844553891 +0200
***************
*** 1043,1048 ****
--- 1043,1065 ----
    call delete('Xis_vimgrep_script')
  endfunc
  
+ func Test_keep_last_search_pattern()
+   if !exists('+incsearch')
+     return
+   endif
+   new
+   call setline(1, ['foo', 'foo', 'foo'])
+   set incsearch
+   call test_override("char_avail", 1)
+   let @/ = 'bar'
+   call feedkeys(":/foo/s//\<Esc>", 'ntx')
+   call assert_equal('bar', @/)
+ 
+   bwipe!
+   call test_override("ALL", 0)
+   set noincsearch
+ endfunc
+ 
  func Test_search_undefined_behaviour()
    if !has("terminal")
      return
*** ../vim-8.1.0350/src/version.c       2018-09-06 16:27:20.664831945 +0200
--- src/version.c       2018-09-06 21:33:45.218506207 +0200
***************
*** 796,797 ****
--- 796,799 ----
  {   /* Add new patch number below this line */
+ /**/
+     351,
  /**/

-- 
How To Keep A Healthy Level Of Insanity:
3. Every time someone asks you to do something, ask if they want fries
   with that.

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Raspunde prin e-mail lui