]>
Commit | Line | Data |
---|---|---|
05618db8 AG |
1 | To: vim-dev@vim.org |
2 | Subject: Patch 6.3.055 | |
3 | Fcc: outbox | |
4 | From: Bram Moolenaar <Bram@moolenaar.net> | |
5 | Mime-Version: 1.0 | |
6 | Content-Type: text/plain; charset=ISO-8859-1 | |
7 | Content-Transfer-Encoding: 8bit | |
8 | ------------ | |
9 | ||
10 | Patch 6.3.055 (after 6.3.013) | |
11 | Problem: Can't use getcmdline(), getcmdpos() or setcmdpos() with <C-R>= | |
12 | when editing a command line. Using <C-\>e may crash Vim. (Peter | |
13 | Winters) | |
14 | Solution: When moving ccline out of the way for recursive use, make it | |
15 | available to the functions that need it. Also save and restore | |
16 | ccline when calling get_expr_line(). Make ccline.cmdbuf NULL at | |
17 | the end of getcmdline(). | |
18 | Files: src/ex_getln.c | |
19 | ||
20 | ||
21 | *** ../vim-6.3.054/src/ex_getln.c Fri Oct 22 11:45:17 2004 | |
22 | --- src/ex_getln.c Thu Jan 13 14:06:56 2005 | |
23 | *************** | |
24 | *** 80,85 **** | |
25 | --- 80,87 ---- | |
26 | static void alloc_cmdbuff __ARGS((int len)); | |
27 | static int realloc_cmdbuff __ARGS((int len)); | |
28 | static void draw_cmdline __ARGS((int start, int len)); | |
29 | + static void save_cmdline __ARGS((struct cmdline_info *ccp)); | |
30 | + static void restore_cmdline __ARGS((struct cmdline_info *ccp)); | |
31 | static int cmdline_paste __ARGS((int regname, int literally)); | |
32 | #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) | |
33 | static void redrawcmd_preedit __ARGS((void)); | |
34 | *************** | |
35 | *** 589,596 **** | |
36 | #ifdef FEAT_EVAL | |
37 | else if (c == 'e') | |
38 | { | |
39 | ! struct cmdline_info save_ccline; | |
40 | ! char_u *p; | |
41 | ||
42 | /* | |
43 | * Replace the command line with the result of an expression. | |
44 | --- 591,598 ---- | |
45 | #ifdef FEAT_EVAL | |
46 | else if (c == 'e') | |
47 | { | |
48 | ! struct cmdline_info save_ccline; | |
49 | ! char_u *p = NULL; | |
50 | ||
51 | /* | |
52 | * Replace the command line with the result of an expression. | |
53 | *************** | |
54 | *** 601,614 **** | |
55 | new_cmdpos = 99999; /* keep it at the end */ | |
56 | else | |
57 | new_cmdpos = ccline.cmdpos; | |
58 | ! save_ccline = ccline; | |
59 | ! ccline.cmdbuff = NULL; | |
60 | ! ccline.cmdprompt = NULL; | |
61 | c = get_expr_register(); | |
62 | ! ccline = save_ccline; | |
63 | if (c == '=') | |
64 | { | |
65 | p = get_expr_line(); | |
66 | if (p != NULL | |
67 | && realloc_cmdbuff((int)STRLEN(p) + 1) == OK) | |
68 | { | |
69 | --- 603,618 ---- | |
70 | new_cmdpos = 99999; /* keep it at the end */ | |
71 | else | |
72 | new_cmdpos = ccline.cmdpos; | |
73 | ! | |
74 | ! save_cmdline(&save_ccline); | |
75 | c = get_expr_register(); | |
76 | ! restore_cmdline(&save_ccline); | |
77 | if (c == '=') | |
78 | { | |
79 | + save_cmdline(&save_ccline); | |
80 | p = get_expr_line(); | |
81 | + restore_cmdline(&save_ccline); | |
82 | + | |
83 | if (p != NULL | |
84 | && realloc_cmdbuff((int)STRLEN(p) + 1) == OK) | |
85 | { | |
86 | *************** | |
87 | *** 1027,1037 **** | |
88 | } | |
89 | else | |
90 | { | |
91 | ! save_ccline = ccline; | |
92 | ! ccline.cmdbuff = NULL; | |
93 | ! ccline.cmdprompt = NULL; | |
94 | c = get_expr_register(); | |
95 | ! ccline = save_ccline; | |
96 | } | |
97 | } | |
98 | #endif | |
99 | --- 1031,1039 ---- | |
100 | } | |
101 | else | |
102 | { | |
103 | ! save_cmdline(&save_ccline); | |
104 | c = get_expr_register(); | |
105 | ! restore_cmdline(&save_ccline); | |
106 | } | |
107 | } | |
108 | #endif | |
109 | *************** | |
110 | *** 1723,1729 **** | |
111 | ui_cursor_shape(); /* may show different cursor shape */ | |
112 | #endif | |
113 | ||
114 | ! return ccline.cmdbuff; | |
115 | } | |
116 | ||
117 | #if (defined(FEAT_CRYPT) || defined(FEAT_EVAL)) || defined(PROTO) | |
118 | --- 1725,1737 ---- | |
119 | ui_cursor_shape(); /* may show different cursor shape */ | |
120 | #endif | |
121 | ||
122 | ! { | |
123 | ! char_u *p = ccline.cmdbuff; | |
124 | ! | |
125 | ! /* Make ccline empty, getcmdline() may try to use it. */ | |
126 | ! ccline.cmdbuff = NULL; | |
127 | ! return p; | |
128 | ! } | |
129 | } | |
130 | ||
131 | #if (defined(FEAT_CRYPT) || defined(FEAT_EVAL)) || defined(PROTO) | |
132 | *************** | |
133 | *** 1743,1754 **** | |
134 | struct cmdline_info save_ccline; | |
135 | int msg_col_save = msg_col; | |
136 | ||
137 | ! save_ccline = ccline; | |
138 | ! ccline.cmdbuff = NULL; | |
139 | ccline.cmdprompt = prompt; | |
140 | ccline.cmdattr = attr; | |
141 | s = getcmdline(firstc, 1L, 0); | |
142 | ! ccline = save_ccline; | |
143 | /* Restore msg_col, the prompt from input() may have changed it. */ | |
144 | msg_col = msg_col_save; | |
145 | ||
146 | --- 1751,1761 ---- | |
147 | struct cmdline_info save_ccline; | |
148 | int msg_col_save = msg_col; | |
149 | ||
150 | ! save_cmdline(&save_ccline); | |
151 | ccline.cmdprompt = prompt; | |
152 | ccline.cmdattr = attr; | |
153 | s = getcmdline(firstc, 1L, 0); | |
154 | ! restore_cmdline(&save_ccline); | |
155 | /* Restore msg_col, the prompt from input() may have changed it. */ | |
156 | msg_col = msg_col_save; | |
157 | ||
158 | *************** | |
159 | *** 2537,2542 **** | |
160 | --- 2544,2583 ---- | |
161 | return retval; | |
162 | } | |
163 | ||
164 | + static struct cmdline_info prev_ccline; | |
165 | + static int prev_ccline_used = FALSE; | |
166 | + | |
167 | + /* | |
168 | + * Save ccline, because obtaining the "=" register may execute "normal :cmd" | |
169 | + * and overwrite it. But get_cmdline_str() may need it, thus make it | |
170 | + * available globally in prev_ccline. | |
171 | + */ | |
172 | + static void | |
173 | + save_cmdline(ccp) | |
174 | + struct cmdline_info *ccp; | |
175 | + { | |
176 | + if (!prev_ccline_used) | |
177 | + { | |
178 | + vim_memset(&prev_ccline, 0, sizeof(struct cmdline_info)); | |
179 | + prev_ccline_used = TRUE; | |
180 | + } | |
181 | + *ccp = prev_ccline; | |
182 | + prev_ccline = ccline; | |
183 | + ccline.cmdbuff = NULL; | |
184 | + ccline.cmdprompt = NULL; | |
185 | + } | |
186 | + | |
187 | + /* | |
188 | + * Resture ccline after it has been saved with save_cmdline(). | |
189 | + */ | |
190 | + static void | |
191 | + restore_cmdline(ccp) | |
192 | + struct cmdline_info *ccp; | |
193 | + { | |
194 | + ccline = prev_ccline; | |
195 | + prev_ccline = *ccp; | |
196 | + } | |
197 | + | |
198 | /* | |
199 | * paste a yank register into the command line. | |
200 | * used by CTRL-R command in command-line mode | |
201 | *************** | |
202 | *** 2571,2583 **** | |
203 | regname = may_get_selection(regname); | |
204 | #endif | |
205 | ||
206 | ! /* Need to save and restore ccline, because obtaining the "=" register may | |
207 | ! * execute "normal :cmd" and overwrite it. */ | |
208 | ! save_ccline = ccline; | |
209 | ! ccline.cmdbuff = NULL; | |
210 | ! ccline.cmdprompt = NULL; | |
211 | i = get_spec_reg(regname, &arg, &allocated, TRUE); | |
212 | ! ccline = save_ccline; | |
213 | ||
214 | if (i) | |
215 | { | |
216 | --- 2612,2621 ---- | |
217 | regname = may_get_selection(regname); | |
218 | #endif | |
219 | ||
220 | ! /* Need to save and restore ccline. */ | |
221 | ! save_cmdline(&save_ccline); | |
222 | i = get_spec_reg(regname, &arg, &allocated, TRUE); | |
223 | ! restore_cmdline(&save_ccline); | |
224 | ||
225 | if (i) | |
226 | { | |
227 | *************** | |
228 | *** 4541,4546 **** | |
229 | --- 4579,4602 ---- | |
230 | return history[histype][hisidx[histype]].hisnum; | |
231 | } | |
232 | ||
233 | + static struct cmdline_info *get_ccline_ptr __ARGS((void)); | |
234 | + | |
235 | + /* | |
236 | + * Get pointer to the command line info to use. cmdline_paste() may clear | |
237 | + * ccline and put the previous value in prev_ccline. | |
238 | + */ | |
239 | + static struct cmdline_info * | |
240 | + get_ccline_ptr() | |
241 | + { | |
242 | + if ((State & CMDLINE) == 0) | |
243 | + return NULL; | |
244 | + if (ccline.cmdbuff != NULL) | |
245 | + return &ccline; | |
246 | + if (prev_ccline_used && prev_ccline.cmdbuff != NULL) | |
247 | + return &prev_ccline; | |
248 | + return NULL; | |
249 | + } | |
250 | + | |
251 | /* | |
252 | * Get the current command line in allocated memory. | |
253 | * Only works when the command line is being edited. | |
254 | *************** | |
255 | *** 4549,4557 **** | |
256 | char_u * | |
257 | get_cmdline_str() | |
258 | { | |
259 | ! if (ccline.cmdbuff == NULL || (State & CMDLINE) == 0) | |
260 | return NULL; | |
261 | ! return vim_strnsave(ccline.cmdbuff, ccline.cmdlen); | |
262 | } | |
263 | ||
264 | /* | |
265 | --- 4605,4615 ---- | |
266 | char_u * | |
267 | get_cmdline_str() | |
268 | { | |
269 | ! struct cmdline_info *p = get_ccline_ptr(); | |
270 | ! | |
271 | ! if (p == NULL) | |
272 | return NULL; | |
273 | ! return vim_strnsave(p->cmdbuff, p->cmdlen); | |
274 | } | |
275 | ||
276 | /* | |
277 | *************** | |
278 | *** 4563,4571 **** | |
279 | int | |
280 | get_cmdline_pos() | |
281 | { | |
282 | ! if (ccline.cmdbuff == NULL || (State & CMDLINE) == 0) | |
283 | return -1; | |
284 | ! return ccline.cmdpos; | |
285 | } | |
286 | ||
287 | /* | |
288 | --- 4621,4631 ---- | |
289 | int | |
290 | get_cmdline_pos() | |
291 | { | |
292 | ! struct cmdline_info *p = get_ccline_ptr(); | |
293 | ! | |
294 | ! if (p == NULL) | |
295 | return -1; | |
296 | ! return p->cmdpos; | |
297 | } | |
298 | ||
299 | /* | |
300 | *************** | |
301 | *** 4577,4583 **** | |
302 | set_cmdline_pos(pos) | |
303 | int pos; | |
304 | { | |
305 | ! if (ccline.cmdbuff == NULL || (State & CMDLINE) == 0) | |
306 | return 1; | |
307 | ||
308 | /* The position is not set directly but after CTRL-\ e or CTRL-R = has | |
309 | --- 4637,4645 ---- | |
310 | set_cmdline_pos(pos) | |
311 | int pos; | |
312 | { | |
313 | ! struct cmdline_info *p = get_ccline_ptr(); | |
314 | ! | |
315 | ! if (p == NULL) | |
316 | return 1; | |
317 | ||
318 | /* The position is not set directly but after CTRL-\ e or CTRL-R = has | |
319 | *** ../vim-6.3.054/src/version.c Wed Jan 5 11:17:36 2005 | |
320 | --- src/version.c Thu Jan 13 14:08:12 2005 | |
321 | *************** | |
322 | *** 643,644 **** | |
323 | --- 643,646 ---- | |
324 | { /* Add new patch number below this line */ | |
325 | + /**/ | |
326 | + 55, | |
327 | /**/ | |
328 | ||
329 | -- | |
330 | ARTHUR: Well, I AM king... | |
331 | DENNIS: Oh king, eh, very nice. An' how'd you get that, eh? By exploitin' | |
332 | the workers -- by 'angin' on to outdated imperialist dogma which | |
333 | perpetuates the economic an' social differences in our society! If | |
334 | there's ever going to be any progress-- | |
335 | The Quest for the Holy Grail (Monty Python) | |
336 | ||
337 | /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ | |
338 | /// Sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ | |
339 | \\\ Project leader for A-A-P -- http://www.A-A-P.org /// | |
340 | \\\ Buy LOTR 3 and help AIDS victims -- http://ICCF.nl/lotr.html /// |