summaryrefslogtreecommitdiff
path: root/data/vim/patches/8.1.0351
blob: d4427da21eaf9247467f8953259d2228dc189da5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
To: vim_dev@googlegroups.com
Subject: Patch 8.1.0351
Fcc: outbox
From: Bram Moolenaar <Bram@moolenaar.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
------------

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 -- Bram@Moolenaar.net -- 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    ///