vi.c revision 1.16 1 1.16 dsl /* $NetBSD: vi.c,v 1.16 2003/03/10 11:09:25 dsl Exp $ */
2 1.2 lukem
3 1.1 cgd /*-
4 1.1 cgd * Copyright (c) 1992, 1993
5 1.1 cgd * The Regents of the University of California. All rights reserved.
6 1.1 cgd *
7 1.1 cgd * This code is derived from software contributed to Berkeley by
8 1.1 cgd * Christos Zoulas of Cornell University.
9 1.1 cgd *
10 1.1 cgd * Redistribution and use in source and binary forms, with or without
11 1.1 cgd * modification, are permitted provided that the following conditions
12 1.1 cgd * are met:
13 1.1 cgd * 1. Redistributions of source code must retain the above copyright
14 1.1 cgd * notice, this list of conditions and the following disclaimer.
15 1.1 cgd * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 cgd * notice, this list of conditions and the following disclaimer in the
17 1.1 cgd * documentation and/or other materials provided with the distribution.
18 1.1 cgd * 3. All advertising materials mentioning features or use of this software
19 1.1 cgd * must display the following acknowledgement:
20 1.1 cgd * This product includes software developed by the University of
21 1.1 cgd * California, Berkeley and its contributors.
22 1.1 cgd * 4. Neither the name of the University nor the names of its contributors
23 1.1 cgd * may be used to endorse or promote products derived from this software
24 1.1 cgd * without specific prior written permission.
25 1.1 cgd *
26 1.1 cgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 1.1 cgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 1.1 cgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 1.1 cgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 1.1 cgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 1.1 cgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 1.1 cgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 1.1 cgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 1.1 cgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 1.1 cgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 1.1 cgd * SUCH DAMAGE.
37 1.1 cgd */
38 1.1 cgd
39 1.9 christos #include "config.h"
40 1.12 christos #include <stdlib.h>
41 1.12 christos #include <unistd.h>
42 1.12 christos #include <sys/wait.h>
43 1.12 christos
44 1.1 cgd #if !defined(lint) && !defined(SCCSID)
45 1.2 lukem #if 0
46 1.1 cgd static char sccsid[] = "@(#)vi.c 8.1 (Berkeley) 6/4/93";
47 1.2 lukem #else
48 1.16 dsl __RCSID("$NetBSD: vi.c,v 1.16 2003/03/10 11:09:25 dsl Exp $");
49 1.2 lukem #endif
50 1.1 cgd #endif /* not lint && not SCCSID */
51 1.1 cgd
52 1.1 cgd /*
53 1.1 cgd * vi.c: Vi mode commands.
54 1.1 cgd */
55 1.1 cgd #include "el.h"
56 1.1 cgd
57 1.8 lukem private el_action_t cv_action(EditLine *, int);
58 1.8 lukem private el_action_t cv_paste(EditLine *, int);
59 1.1 cgd
60 1.1 cgd /* cv_action():
61 1.1 cgd * Handle vi actions.
62 1.1 cgd */
63 1.1 cgd private el_action_t
64 1.8 lukem cv_action(EditLine *el, int c)
65 1.1 cgd {
66 1.1 cgd
67 1.12 christos if (el->el_chared.c_vcmd.action != NOP) {
68 1.12 christos /* 'cc', 'dd' and (possibly) friends */
69 1.12 christos if (c != el->el_chared.c_vcmd.action)
70 1.12 christos return CC_ERROR;
71 1.12 christos
72 1.12 christos if (!(c & YANK))
73 1.12 christos cv_undo(el);
74 1.12 christos cv_yank(el, el->el_line.buffer,
75 1.12 christos el->el_line.lastchar - el->el_line.buffer);
76 1.8 lukem el->el_chared.c_vcmd.action = NOP;
77 1.8 lukem el->el_chared.c_vcmd.pos = 0;
78 1.8 lukem el->el_line.lastchar = el->el_line.buffer;
79 1.8 lukem el->el_line.cursor = el->el_line.buffer;
80 1.8 lukem if (c & INSERT)
81 1.8 lukem el->el_map.current = el->el_map.key;
82 1.7 simonb
83 1.8 lukem return (CC_REFRESH);
84 1.1 cgd }
85 1.8 lukem el->el_chared.c_vcmd.pos = el->el_line.cursor;
86 1.8 lukem el->el_chared.c_vcmd.action = c;
87 1.8 lukem return (CC_ARGHACK);
88 1.1 cgd }
89 1.1 cgd
90 1.1 cgd /* cv_paste():
91 1.1 cgd * Paste previous deletion before or after the cursor
92 1.1 cgd */
93 1.3 christos private el_action_t
94 1.8 lukem cv_paste(EditLine *el, int c)
95 1.1 cgd {
96 1.8 lukem char *ptr;
97 1.12 christos c_kill_t *k = &el->el_chared.c_kill;
98 1.12 christos int len = k->last - k->buf;
99 1.8 lukem
100 1.12 christos if (k->buf == NULL || len == 0)
101 1.12 christos return (CC_ERROR);
102 1.1 cgd #ifdef DEBUG_PASTE
103 1.12 christos (void) fprintf(el->el_errfile, "Paste: \"%.*s\"\n", len, k->buf);
104 1.1 cgd #endif
105 1.1 cgd
106 1.12 christos cv_undo(el);
107 1.10 christos
108 1.8 lukem if (!c && el->el_line.cursor < el->el_line.lastchar)
109 1.8 lukem el->el_line.cursor++;
110 1.8 lukem ptr = el->el_line.cursor;
111 1.8 lukem
112 1.12 christos c_insert(el, len);
113 1.12 christos if (el->el_line.cursor + len > el->el_line.lastchar)
114 1.8 lukem return (CC_ERROR);
115 1.12 christos (void) memcpy(ptr, k->buf, len +0u);
116 1.8 lukem return (CC_REFRESH);
117 1.1 cgd }
118 1.1 cgd
119 1.1 cgd
120 1.7 simonb /* vi_paste_next():
121 1.1 cgd * Vi paste previous deletion to the right of the cursor
122 1.1 cgd * [p]
123 1.1 cgd */
124 1.1 cgd protected el_action_t
125 1.1 cgd /*ARGSUSED*/
126 1.8 lukem vi_paste_next(EditLine *el, int c)
127 1.1 cgd {
128 1.8 lukem
129 1.8 lukem return (cv_paste(el, 0));
130 1.1 cgd }
131 1.1 cgd
132 1.1 cgd
133 1.7 simonb /* vi_paste_prev():
134 1.1 cgd * Vi paste previous deletion to the left of the cursor
135 1.1 cgd * [P]
136 1.1 cgd */
137 1.1 cgd protected el_action_t
138 1.1 cgd /*ARGSUSED*/
139 1.8 lukem vi_paste_prev(EditLine *el, int c)
140 1.1 cgd {
141 1.8 lukem
142 1.8 lukem return (cv_paste(el, 1));
143 1.1 cgd }
144 1.1 cgd
145 1.1 cgd
146 1.10 christos /* vi_prev_big_word():
147 1.1 cgd * Vi move to the previous space delimited word
148 1.1 cgd * [B]
149 1.1 cgd */
150 1.1 cgd protected el_action_t
151 1.1 cgd /*ARGSUSED*/
152 1.10 christos vi_prev_big_word(EditLine *el, int c)
153 1.8 lukem {
154 1.8 lukem
155 1.8 lukem if (el->el_line.cursor == el->el_line.buffer)
156 1.8 lukem return (CC_ERROR);
157 1.1 cgd
158 1.10 christos el->el_line.cursor = cv_prev_word(el->el_line.cursor,
159 1.8 lukem el->el_line.buffer,
160 1.8 lukem el->el_state.argument,
161 1.10 christos cv__isWord);
162 1.8 lukem
163 1.12 christos if (el->el_chared.c_vcmd.action != NOP) {
164 1.8 lukem cv_delfini(el);
165 1.8 lukem return (CC_REFRESH);
166 1.8 lukem }
167 1.8 lukem return (CC_CURSOR);
168 1.1 cgd }
169 1.1 cgd
170 1.1 cgd
171 1.7 simonb /* vi_prev_word():
172 1.1 cgd * Vi move to the previous word
173 1.10 christos * [b]
174 1.1 cgd */
175 1.1 cgd protected el_action_t
176 1.1 cgd /*ARGSUSED*/
177 1.8 lukem vi_prev_word(EditLine *el, int c)
178 1.8 lukem {
179 1.1 cgd
180 1.8 lukem if (el->el_line.cursor == el->el_line.buffer)
181 1.8 lukem return (CC_ERROR);
182 1.8 lukem
183 1.10 christos el->el_line.cursor = cv_prev_word(el->el_line.cursor,
184 1.8 lukem el->el_line.buffer,
185 1.8 lukem el->el_state.argument,
186 1.10 christos cv__isword);
187 1.8 lukem
188 1.12 christos if (el->el_chared.c_vcmd.action != NOP) {
189 1.8 lukem cv_delfini(el);
190 1.8 lukem return (CC_REFRESH);
191 1.8 lukem }
192 1.8 lukem return (CC_CURSOR);
193 1.1 cgd }
194 1.1 cgd
195 1.1 cgd
196 1.10 christos /* vi_next_big_word():
197 1.1 cgd * Vi move to the next space delimited word
198 1.1 cgd * [W]
199 1.1 cgd */
200 1.1 cgd protected el_action_t
201 1.1 cgd /*ARGSUSED*/
202 1.10 christos vi_next_big_word(EditLine *el, int c)
203 1.8 lukem {
204 1.1 cgd
205 1.12 christos if (el->el_line.cursor >= el->el_line.lastchar - 1)
206 1.8 lukem return (CC_ERROR);
207 1.1 cgd
208 1.8 lukem el->el_line.cursor = cv_next_word(el, el->el_line.cursor,
209 1.12 christos el->el_line.lastchar, el->el_state.argument, cv__isWord);
210 1.8 lukem
211 1.8 lukem if (el->el_map.type == MAP_VI)
212 1.12 christos if (el->el_chared.c_vcmd.action != NOP) {
213 1.8 lukem cv_delfini(el);
214 1.8 lukem return (CC_REFRESH);
215 1.8 lukem }
216 1.8 lukem return (CC_CURSOR);
217 1.1 cgd }
218 1.1 cgd
219 1.8 lukem
220 1.7 simonb /* vi_next_word():
221 1.1 cgd * Vi move to the next word
222 1.1 cgd * [w]
223 1.1 cgd */
224 1.1 cgd protected el_action_t
225 1.1 cgd /*ARGSUSED*/
226 1.8 lukem vi_next_word(EditLine *el, int c)
227 1.8 lukem {
228 1.1 cgd
229 1.12 christos if (el->el_line.cursor >= el->el_line.lastchar - 1)
230 1.8 lukem return (CC_ERROR);
231 1.1 cgd
232 1.8 lukem el->el_line.cursor = cv_next_word(el, el->el_line.cursor,
233 1.12 christos el->el_line.lastchar, el->el_state.argument, cv__isword);
234 1.8 lukem
235 1.8 lukem if (el->el_map.type == MAP_VI)
236 1.12 christos if (el->el_chared.c_vcmd.action != NOP) {
237 1.8 lukem cv_delfini(el);
238 1.8 lukem return (CC_REFRESH);
239 1.8 lukem }
240 1.8 lukem return (CC_CURSOR);
241 1.1 cgd }
242 1.1 cgd
243 1.1 cgd
244 1.7 simonb /* vi_change_case():
245 1.1 cgd * Vi change case of character under the cursor and advance one character
246 1.1 cgd * [~]
247 1.1 cgd */
248 1.1 cgd protected el_action_t
249 1.8 lukem vi_change_case(EditLine *el, int c)
250 1.8 lukem {
251 1.10 christos int i;
252 1.10 christos
253 1.10 christos if (el->el_line.cursor >= el->el_line.lastchar)
254 1.10 christos return (CC_ERROR);
255 1.12 christos cv_undo(el);
256 1.10 christos for (i = 0; i < el->el_state.argument; i++) {
257 1.8 lukem
258 1.12 christos c = *(unsigned char *)el->el_line.cursor;
259 1.8 lukem if (isupper(c))
260 1.12 christos *el->el_line.cursor = tolower(c);
261 1.8 lukem else if (islower(c))
262 1.12 christos *el->el_line.cursor = toupper(c);
263 1.12 christos
264 1.12 christos if (++el->el_line.cursor >= el->el_line.lastchar) {
265 1.12 christos el->el_line.cursor--;
266 1.12 christos re_fastaddc(el);
267 1.12 christos break;
268 1.12 christos }
269 1.8 lukem re_fastaddc(el);
270 1.8 lukem }
271 1.12 christos return CC_NORM;
272 1.1 cgd }
273 1.1 cgd
274 1.1 cgd
275 1.7 simonb /* vi_change_meta():
276 1.1 cgd * Vi change prefix command
277 1.1 cgd * [c]
278 1.1 cgd */
279 1.1 cgd protected el_action_t
280 1.1 cgd /*ARGSUSED*/
281 1.8 lukem vi_change_meta(EditLine *el, int c)
282 1.8 lukem {
283 1.8 lukem
284 1.8 lukem /*
285 1.8 lukem * Delete with insert == change: first we delete and then we leave in
286 1.8 lukem * insert mode.
287 1.8 lukem */
288 1.8 lukem return (cv_action(el, DELETE | INSERT));
289 1.1 cgd }
290 1.1 cgd
291 1.1 cgd
292 1.7 simonb /* vi_insert_at_bol():
293 1.1 cgd * Vi enter insert mode at the beginning of line
294 1.1 cgd * [I]
295 1.1 cgd */
296 1.1 cgd protected el_action_t
297 1.1 cgd /*ARGSUSED*/
298 1.8 lukem vi_insert_at_bol(EditLine *el, int c)
299 1.1 cgd {
300 1.1 cgd
301 1.8 lukem el->el_line.cursor = el->el_line.buffer;
302 1.12 christos cv_undo(el);
303 1.8 lukem el->el_map.current = el->el_map.key;
304 1.8 lukem return (CC_CURSOR);
305 1.1 cgd }
306 1.1 cgd
307 1.1 cgd
308 1.7 simonb /* vi_replace_char():
309 1.1 cgd * Vi replace character under the cursor with the next character typed
310 1.1 cgd * [r]
311 1.1 cgd */
312 1.1 cgd protected el_action_t
313 1.1 cgd /*ARGSUSED*/
314 1.8 lukem vi_replace_char(EditLine *el, int c)
315 1.8 lukem {
316 1.8 lukem
317 1.12 christos if (el->el_line.cursor >= el->el_line.lastchar)
318 1.10 christos return CC_ERROR;
319 1.10 christos
320 1.8 lukem el->el_map.current = el->el_map.key;
321 1.8 lukem el->el_state.inputmode = MODE_REPLACE_1;
322 1.12 christos cv_undo(el);
323 1.10 christos return (CC_ARGHACK);
324 1.1 cgd }
325 1.1 cgd
326 1.1 cgd
327 1.7 simonb /* vi_replace_mode():
328 1.1 cgd * Vi enter replace mode
329 1.1 cgd * [R]
330 1.1 cgd */
331 1.1 cgd protected el_action_t
332 1.1 cgd /*ARGSUSED*/
333 1.8 lukem vi_replace_mode(EditLine *el, int c)
334 1.8 lukem {
335 1.8 lukem
336 1.8 lukem el->el_map.current = el->el_map.key;
337 1.8 lukem el->el_state.inputmode = MODE_REPLACE;
338 1.12 christos cv_undo(el);
339 1.8 lukem return (CC_NORM);
340 1.1 cgd }
341 1.1 cgd
342 1.1 cgd
343 1.7 simonb /* vi_substitute_char():
344 1.1 cgd * Vi replace character under the cursor and enter insert mode
345 1.10 christos * [s]
346 1.1 cgd */
347 1.1 cgd protected el_action_t
348 1.1 cgd /*ARGSUSED*/
349 1.8 lukem vi_substitute_char(EditLine *el, int c)
350 1.8 lukem {
351 1.8 lukem
352 1.8 lukem c_delafter(el, el->el_state.argument);
353 1.8 lukem el->el_map.current = el->el_map.key;
354 1.8 lukem return (CC_REFRESH);
355 1.1 cgd }
356 1.1 cgd
357 1.1 cgd
358 1.7 simonb /* vi_substitute_line():
359 1.1 cgd * Vi substitute entire line
360 1.1 cgd * [S]
361 1.1 cgd */
362 1.1 cgd protected el_action_t
363 1.1 cgd /*ARGSUSED*/
364 1.8 lukem vi_substitute_line(EditLine *el, int c)
365 1.8 lukem {
366 1.8 lukem
367 1.12 christos cv_undo(el);
368 1.12 christos cv_yank(el, el->el_line.buffer,
369 1.12 christos el->el_line.lastchar - el->el_line.buffer);
370 1.8 lukem (void) em_kill_line(el, 0);
371 1.8 lukem el->el_map.current = el->el_map.key;
372 1.8 lukem return (CC_REFRESH);
373 1.1 cgd }
374 1.1 cgd
375 1.1 cgd
376 1.7 simonb /* vi_change_to_eol():
377 1.1 cgd * Vi change to end of line
378 1.1 cgd * [C]
379 1.1 cgd */
380 1.1 cgd protected el_action_t
381 1.1 cgd /*ARGSUSED*/
382 1.8 lukem vi_change_to_eol(EditLine *el, int c)
383 1.8 lukem {
384 1.8 lukem
385 1.12 christos cv_undo(el);
386 1.12 christos cv_yank(el, el->el_line.cursor,
387 1.12 christos el->el_line.lastchar - el->el_line.cursor);
388 1.8 lukem (void) ed_kill_line(el, 0);
389 1.8 lukem el->el_map.current = el->el_map.key;
390 1.8 lukem return (CC_REFRESH);
391 1.1 cgd }
392 1.1 cgd
393 1.1 cgd
394 1.1 cgd /* vi_insert():
395 1.1 cgd * Vi enter insert mode
396 1.1 cgd * [i]
397 1.1 cgd */
398 1.1 cgd protected el_action_t
399 1.1 cgd /*ARGSUSED*/
400 1.8 lukem vi_insert(EditLine *el, int c)
401 1.1 cgd {
402 1.1 cgd
403 1.8 lukem el->el_map.current = el->el_map.key;
404 1.12 christos cv_undo(el);
405 1.8 lukem return (CC_NORM);
406 1.1 cgd }
407 1.1 cgd
408 1.1 cgd
409 1.1 cgd /* vi_add():
410 1.7 simonb * Vi enter insert mode after the cursor
411 1.1 cgd * [a]
412 1.1 cgd */
413 1.1 cgd protected el_action_t
414 1.1 cgd /*ARGSUSED*/
415 1.8 lukem vi_add(EditLine *el, int c)
416 1.8 lukem {
417 1.8 lukem int ret;
418 1.8 lukem
419 1.8 lukem el->el_map.current = el->el_map.key;
420 1.8 lukem if (el->el_line.cursor < el->el_line.lastchar) {
421 1.8 lukem el->el_line.cursor++;
422 1.8 lukem if (el->el_line.cursor > el->el_line.lastchar)
423 1.8 lukem el->el_line.cursor = el->el_line.lastchar;
424 1.8 lukem ret = CC_CURSOR;
425 1.8 lukem } else
426 1.8 lukem ret = CC_NORM;
427 1.8 lukem
428 1.12 christos cv_undo(el);
429 1.1 cgd
430 1.8 lukem return (ret);
431 1.1 cgd }
432 1.1 cgd
433 1.1 cgd
434 1.1 cgd /* vi_add_at_eol():
435 1.1 cgd * Vi enter insert mode at end of line
436 1.1 cgd * [A]
437 1.1 cgd */
438 1.1 cgd protected el_action_t
439 1.1 cgd /*ARGSUSED*/
440 1.8 lukem vi_add_at_eol(EditLine *el, int c)
441 1.8 lukem {
442 1.8 lukem
443 1.8 lukem el->el_map.current = el->el_map.key;
444 1.8 lukem el->el_line.cursor = el->el_line.lastchar;
445 1.12 christos cv_undo(el);
446 1.8 lukem return (CC_CURSOR);
447 1.1 cgd }
448 1.1 cgd
449 1.1 cgd
450 1.1 cgd /* vi_delete_meta():
451 1.7 simonb * Vi delete prefix command
452 1.1 cgd * [d]
453 1.1 cgd */
454 1.1 cgd protected el_action_t
455 1.1 cgd /*ARGSUSED*/
456 1.8 lukem vi_delete_meta(EditLine *el, int c)
457 1.1 cgd {
458 1.8 lukem
459 1.8 lukem return (cv_action(el, DELETE));
460 1.1 cgd }
461 1.1 cgd
462 1.1 cgd
463 1.10 christos /* vi_end_big_word():
464 1.7 simonb * Vi move to the end of the current space delimited word
465 1.7 simonb * [E]
466 1.1 cgd */
467 1.1 cgd protected el_action_t
468 1.1 cgd /*ARGSUSED*/
469 1.10 christos vi_end_big_word(EditLine *el, int c)
470 1.8 lukem {
471 1.8 lukem
472 1.8 lukem if (el->el_line.cursor == el->el_line.lastchar)
473 1.8 lukem return (CC_ERROR);
474 1.1 cgd
475 1.8 lukem el->el_line.cursor = cv__endword(el->el_line.cursor,
476 1.10 christos el->el_line.lastchar, el->el_state.argument, cv__isWord);
477 1.8 lukem
478 1.12 christos if (el->el_chared.c_vcmd.action != NOP) {
479 1.8 lukem el->el_line.cursor++;
480 1.8 lukem cv_delfini(el);
481 1.8 lukem return (CC_REFRESH);
482 1.8 lukem }
483 1.8 lukem return (CC_CURSOR);
484 1.1 cgd }
485 1.1 cgd
486 1.1 cgd
487 1.10 christos /* vi_end_word():
488 1.1 cgd * Vi move to the end of the current word
489 1.1 cgd * [e]
490 1.1 cgd */
491 1.1 cgd protected el_action_t
492 1.1 cgd /*ARGSUSED*/
493 1.10 christos vi_end_word(EditLine *el, int c)
494 1.8 lukem {
495 1.8 lukem
496 1.8 lukem if (el->el_line.cursor == el->el_line.lastchar)
497 1.8 lukem return (CC_ERROR);
498 1.8 lukem
499 1.8 lukem el->el_line.cursor = cv__endword(el->el_line.cursor,
500 1.10 christos el->el_line.lastchar, el->el_state.argument, cv__isword);
501 1.1 cgd
502 1.12 christos if (el->el_chared.c_vcmd.action != NOP) {
503 1.8 lukem el->el_line.cursor++;
504 1.8 lukem cv_delfini(el);
505 1.8 lukem return (CC_REFRESH);
506 1.8 lukem }
507 1.8 lukem return (CC_CURSOR);
508 1.1 cgd }
509 1.1 cgd
510 1.1 cgd
511 1.1 cgd /* vi_undo():
512 1.1 cgd * Vi undo last change
513 1.1 cgd * [u]
514 1.1 cgd */
515 1.1 cgd protected el_action_t
516 1.1 cgd /*ARGSUSED*/
517 1.8 lukem vi_undo(EditLine *el, int c)
518 1.8 lukem {
519 1.10 christos c_undo_t un = el->el_chared.c_undo;
520 1.1 cgd
521 1.10 christos if (un.len == -1)
522 1.10 christos return CC_ERROR;
523 1.1 cgd
524 1.10 christos /* switch line buffer and undo buffer */
525 1.10 christos el->el_chared.c_undo.buf = el->el_line.buffer;
526 1.10 christos el->el_chared.c_undo.len = el->el_line.lastchar - el->el_line.buffer;
527 1.10 christos el->el_chared.c_undo.cursor = el->el_line.cursor - el->el_line.buffer;
528 1.10 christos el->el_line.limit = un.buf + (el->el_line.limit - el->el_line.buffer);
529 1.10 christos el->el_line.buffer = un.buf;
530 1.10 christos el->el_line.cursor = un.buf + un.cursor;
531 1.10 christos el->el_line.lastchar = un.buf + un.len;
532 1.1 cgd
533 1.8 lukem return (CC_REFRESH);
534 1.1 cgd }
535 1.1 cgd
536 1.1 cgd
537 1.1 cgd /* vi_command_mode():
538 1.1 cgd * Vi enter command mode (use alternative key bindings)
539 1.1 cgd * [<ESC>]
540 1.1 cgd */
541 1.1 cgd protected el_action_t
542 1.1 cgd /*ARGSUSED*/
543 1.8 lukem vi_command_mode(EditLine *el, int c)
544 1.8 lukem {
545 1.8 lukem
546 1.8 lukem /* [Esc] cancels pending action */
547 1.8 lukem el->el_chared.c_vcmd.action = NOP;
548 1.8 lukem el->el_chared.c_vcmd.pos = 0;
549 1.8 lukem
550 1.8 lukem el->el_state.doingarg = 0;
551 1.1 cgd
552 1.8 lukem el->el_state.inputmode = MODE_INSERT;
553 1.8 lukem el->el_map.current = el->el_map.alt;
554 1.1 cgd #ifdef VI_MOVE
555 1.8 lukem if (el->el_line.cursor > el->el_line.buffer)
556 1.8 lukem el->el_line.cursor--;
557 1.1 cgd #endif
558 1.8 lukem return (CC_CURSOR);
559 1.1 cgd }
560 1.1 cgd
561 1.8 lukem
562 1.1 cgd /* vi_zero():
563 1.7 simonb * Vi move to the beginning of line
564 1.1 cgd * [0]
565 1.1 cgd */
566 1.1 cgd protected el_action_t
567 1.8 lukem vi_zero(EditLine *el, int c)
568 1.8 lukem {
569 1.8 lukem
570 1.12 christos if (el->el_state.doingarg)
571 1.12 christos return ed_argument_digit(el, c);
572 1.12 christos
573 1.12 christos el->el_line.cursor = el->el_line.buffer;
574 1.12 christos if (el->el_chared.c_vcmd.action != NOP) {
575 1.12 christos cv_delfini(el);
576 1.12 christos return (CC_REFRESH);
577 1.8 lukem }
578 1.12 christos return (CC_CURSOR);
579 1.1 cgd }
580 1.1 cgd
581 1.1 cgd
582 1.1 cgd /* vi_delete_prev_char():
583 1.7 simonb * Vi move to previous character (backspace)
584 1.10 christos * [^H] in insert mode only
585 1.7 simonb */
586 1.1 cgd protected el_action_t
587 1.1 cgd /*ARGSUSED*/
588 1.8 lukem vi_delete_prev_char(EditLine *el, int c)
589 1.8 lukem {
590 1.10 christos char *cp;
591 1.1 cgd
592 1.10 christos cp = el->el_line.cursor;
593 1.10 christos if (cp <= el->el_line.buffer)
594 1.8 lukem return (CC_ERROR);
595 1.8 lukem
596 1.10 christos /* do the delete here so we dont mess up the undo and paste buffers */
597 1.10 christos el->el_line.cursor = --cp;
598 1.10 christos for (; cp < el->el_line.lastchar; cp++)
599 1.10 christos cp[0] = cp[1];
600 1.10 christos el->el_line.lastchar = cp - 1;
601 1.8 lukem
602 1.8 lukem return (CC_REFRESH);
603 1.8 lukem }
604 1.1 cgd
605 1.1 cgd
606 1.1 cgd /* vi_list_or_eof():
607 1.1 cgd * Vi list choices for completion or indicate end of file if empty line
608 1.1 cgd * [^D]
609 1.1 cgd */
610 1.1 cgd protected el_action_t
611 1.1 cgd /*ARGSUSED*/
612 1.8 lukem vi_list_or_eof(EditLine *el, int c)
613 1.1 cgd {
614 1.8 lukem
615 1.1 cgd #ifdef notyet
616 1.8 lukem if (el->el_line.cursor == el->el_line.lastchar &&
617 1.8 lukem el->el_line.cursor == el->el_line.buffer) {
618 1.1 cgd #endif
619 1.8 lukem term_overwrite(el, STReof, 4); /* then do a EOF */
620 1.8 lukem term__flush();
621 1.8 lukem return (CC_EOF);
622 1.1 cgd #ifdef notyet
623 1.8 lukem } else {
624 1.8 lukem re_goto_bottom(el);
625 1.8 lukem *el->el_line.lastchar = '\0'; /* just in case */
626 1.8 lukem return (CC_LIST_CHOICES);
627 1.8 lukem }
628 1.1 cgd #endif
629 1.1 cgd }
630 1.1 cgd
631 1.1 cgd
632 1.1 cgd /* vi_kill_line_prev():
633 1.7 simonb * Vi cut from beginning of line to cursor
634 1.1 cgd * [^U]
635 1.1 cgd */
636 1.1 cgd protected el_action_t
637 1.1 cgd /*ARGSUSED*/
638 1.8 lukem vi_kill_line_prev(EditLine *el, int c)
639 1.8 lukem {
640 1.8 lukem char *kp, *cp;
641 1.8 lukem
642 1.8 lukem cp = el->el_line.buffer;
643 1.8 lukem kp = el->el_chared.c_kill.buf;
644 1.8 lukem while (cp < el->el_line.cursor)
645 1.8 lukem *kp++ = *cp++; /* copy it */
646 1.8 lukem el->el_chared.c_kill.last = kp;
647 1.8 lukem c_delbefore(el, el->el_line.cursor - el->el_line.buffer);
648 1.8 lukem el->el_line.cursor = el->el_line.buffer; /* zap! */
649 1.8 lukem return (CC_REFRESH);
650 1.1 cgd }
651 1.1 cgd
652 1.1 cgd
653 1.1 cgd /* vi_search_prev():
654 1.1 cgd * Vi search history previous
655 1.1 cgd * [?]
656 1.1 cgd */
657 1.1 cgd protected el_action_t
658 1.1 cgd /*ARGSUSED*/
659 1.8 lukem vi_search_prev(EditLine *el, int c)
660 1.1 cgd {
661 1.8 lukem
662 1.8 lukem return (cv_search(el, ED_SEARCH_PREV_HISTORY));
663 1.1 cgd }
664 1.1 cgd
665 1.1 cgd
666 1.1 cgd /* vi_search_next():
667 1.1 cgd * Vi search history next
668 1.1 cgd * [/]
669 1.1 cgd */
670 1.1 cgd protected el_action_t
671 1.1 cgd /*ARGSUSED*/
672 1.8 lukem vi_search_next(EditLine *el, int c)
673 1.1 cgd {
674 1.8 lukem
675 1.8 lukem return (cv_search(el, ED_SEARCH_NEXT_HISTORY));
676 1.1 cgd }
677 1.1 cgd
678 1.1 cgd
679 1.1 cgd /* vi_repeat_search_next():
680 1.1 cgd * Vi repeat current search in the same search direction
681 1.1 cgd * [n]
682 1.1 cgd */
683 1.1 cgd protected el_action_t
684 1.1 cgd /*ARGSUSED*/
685 1.8 lukem vi_repeat_search_next(EditLine *el, int c)
686 1.8 lukem {
687 1.8 lukem
688 1.8 lukem if (el->el_search.patlen == 0)
689 1.8 lukem return (CC_ERROR);
690 1.8 lukem else
691 1.8 lukem return (cv_repeat_srch(el, el->el_search.patdir));
692 1.1 cgd }
693 1.1 cgd
694 1.1 cgd
695 1.1 cgd /* vi_repeat_search_prev():
696 1.1 cgd * Vi repeat current search in the opposite search direction
697 1.1 cgd * [N]
698 1.1 cgd */
699 1.1 cgd /*ARGSUSED*/
700 1.1 cgd protected el_action_t
701 1.8 lukem vi_repeat_search_prev(EditLine *el, int c)
702 1.8 lukem {
703 1.8 lukem
704 1.8 lukem if (el->el_search.patlen == 0)
705 1.8 lukem return (CC_ERROR);
706 1.8 lukem else
707 1.8 lukem return (cv_repeat_srch(el,
708 1.8 lukem el->el_search.patdir == ED_SEARCH_PREV_HISTORY ?
709 1.8 lukem ED_SEARCH_NEXT_HISTORY : ED_SEARCH_PREV_HISTORY));
710 1.1 cgd }
711 1.1 cgd
712 1.1 cgd
713 1.1 cgd /* vi_next_char():
714 1.1 cgd * Vi move to the character specified next
715 1.1 cgd * [f]
716 1.1 cgd */
717 1.1 cgd protected el_action_t
718 1.1 cgd /*ARGSUSED*/
719 1.8 lukem vi_next_char(EditLine *el, int c)
720 1.1 cgd {
721 1.12 christos return cv_csearch(el, CHAR_FWD, -1, el->el_state.argument, 0);
722 1.1 cgd }
723 1.1 cgd
724 1.1 cgd
725 1.1 cgd /* vi_prev_char():
726 1.1 cgd * Vi move to the character specified previous
727 1.1 cgd * [F]
728 1.1 cgd */
729 1.1 cgd protected el_action_t
730 1.1 cgd /*ARGSUSED*/
731 1.8 lukem vi_prev_char(EditLine *el, int c)
732 1.1 cgd {
733 1.12 christos return cv_csearch(el, CHAR_BACK, -1, el->el_state.argument, 0);
734 1.1 cgd }
735 1.1 cgd
736 1.1 cgd
737 1.1 cgd /* vi_to_next_char():
738 1.1 cgd * Vi move up to the character specified next
739 1.1 cgd * [t]
740 1.1 cgd */
741 1.1 cgd protected el_action_t
742 1.1 cgd /*ARGSUSED*/
743 1.8 lukem vi_to_next_char(EditLine *el, int c)
744 1.1 cgd {
745 1.12 christos return cv_csearch(el, CHAR_FWD, -1, el->el_state.argument, 1);
746 1.1 cgd }
747 1.1 cgd
748 1.1 cgd
749 1.1 cgd /* vi_to_prev_char():
750 1.1 cgd * Vi move up to the character specified previous
751 1.1 cgd * [T]
752 1.1 cgd */
753 1.1 cgd protected el_action_t
754 1.1 cgd /*ARGSUSED*/
755 1.8 lukem vi_to_prev_char(EditLine *el, int c)
756 1.8 lukem {
757 1.12 christos return cv_csearch(el, CHAR_BACK, -1, el->el_state.argument, 1);
758 1.1 cgd }
759 1.1 cgd
760 1.1 cgd
761 1.1 cgd /* vi_repeat_next_char():
762 1.1 cgd * Vi repeat current character search in the same search direction
763 1.1 cgd * [;]
764 1.1 cgd */
765 1.1 cgd protected el_action_t
766 1.1 cgd /*ARGSUSED*/
767 1.8 lukem vi_repeat_next_char(EditLine *el, int c)
768 1.8 lukem {
769 1.8 lukem
770 1.12 christos return cv_csearch(el, el->el_search.chadir, el->el_search.chacha,
771 1.12 christos el->el_state.argument, el->el_search.chatflg);
772 1.1 cgd }
773 1.1 cgd
774 1.1 cgd
775 1.1 cgd /* vi_repeat_prev_char():
776 1.1 cgd * Vi repeat current character search in the opposite search direction
777 1.1 cgd * [,]
778 1.1 cgd */
779 1.1 cgd protected el_action_t
780 1.1 cgd /*ARGSUSED*/
781 1.8 lukem vi_repeat_prev_char(EditLine *el, int c)
782 1.8 lukem {
783 1.12 christos el_action_t r;
784 1.12 christos int dir = el->el_search.chadir;
785 1.8 lukem
786 1.12 christos r = cv_csearch(el, -dir, el->el_search.chacha,
787 1.12 christos el->el_state.argument, el->el_search.chatflg);
788 1.12 christos el->el_search.chadir = dir;
789 1.12 christos return r;
790 1.11 christos }
791 1.11 christos
792 1.11 christos
793 1.11 christos /* vi_match():
794 1.11 christos * Vi go to matching () {} or []
795 1.11 christos * [%]
796 1.11 christos */
797 1.11 christos protected el_action_t
798 1.11 christos /*ARGSUSED*/
799 1.11 christos vi_match(EditLine *el, int c)
800 1.11 christos {
801 1.11 christos const char match_chars[] = "()[]{}";
802 1.11 christos char *cp;
803 1.11 christos int delta, i, count;
804 1.11 christos char o_ch, c_ch;
805 1.11 christos
806 1.11 christos *el->el_line.lastchar = '\0'; /* just in case */
807 1.11 christos
808 1.11 christos i = strcspn(el->el_line.cursor, match_chars);
809 1.11 christos o_ch = el->el_line.cursor[i];
810 1.11 christos if (o_ch == 0)
811 1.11 christos return CC_ERROR;
812 1.11 christos delta = strchr(match_chars, o_ch) - match_chars;
813 1.11 christos c_ch = match_chars[delta ^ 1];
814 1.11 christos count = 1;
815 1.11 christos delta = 1 - (delta & 1) * 2;
816 1.11 christos
817 1.11 christos for (cp = &el->el_line.cursor[i]; count; ) {
818 1.11 christos cp += delta;
819 1.11 christos if (cp < el->el_line.buffer || cp >= el->el_line.lastchar)
820 1.11 christos return CC_ERROR;
821 1.11 christos if (*cp == o_ch)
822 1.11 christos count++;
823 1.11 christos else if (*cp == c_ch)
824 1.11 christos count--;
825 1.11 christos }
826 1.11 christos
827 1.11 christos el->el_line.cursor = cp;
828 1.11 christos
829 1.12 christos if (el->el_chared.c_vcmd.action != NOP) {
830 1.12 christos /* NB posix says char under cursor should NOT be deleted
831 1.12 christos for -ve delta - this is different to netbsd vi. */
832 1.11 christos if (delta > 0)
833 1.11 christos el->el_line.cursor++;
834 1.11 christos cv_delfini(el);
835 1.11 christos return (CC_REFRESH);
836 1.11 christos }
837 1.11 christos return (CC_CURSOR);
838 1.12 christos }
839 1.12 christos
840 1.12 christos /* vi_undo_line():
841 1.12 christos * Vi undo all changes to line
842 1.12 christos * [U]
843 1.12 christos */
844 1.12 christos protected el_action_t
845 1.12 christos /*ARGSUSED*/
846 1.12 christos vi_undo_line(EditLine *el, int c)
847 1.12 christos {
848 1.12 christos
849 1.12 christos cv_undo(el);
850 1.12 christos return hist_get(el);
851 1.12 christos }
852 1.12 christos
853 1.12 christos /* vi_to_column():
854 1.12 christos * Vi go to specified column
855 1.12 christos * [|]
856 1.12 christos * NB netbsd vi goes to screen column 'n', posix says nth character
857 1.12 christos */
858 1.12 christos protected el_action_t
859 1.12 christos /*ARGSUSED*/
860 1.12 christos vi_to_column(EditLine *el, int c)
861 1.12 christos {
862 1.12 christos
863 1.12 christos el->el_line.cursor = el->el_line.buffer;
864 1.12 christos el->el_state.argument--;
865 1.12 christos return ed_next_char(el, 0);
866 1.12 christos }
867 1.12 christos
868 1.12 christos /* vi_yank_end():
869 1.12 christos * Vi yank to end of line
870 1.12 christos * [Y]
871 1.12 christos */
872 1.12 christos protected el_action_t
873 1.12 christos /*ARGSUSED*/
874 1.12 christos vi_yank_end(EditLine *el, int c)
875 1.12 christos {
876 1.12 christos
877 1.12 christos cv_yank(el, el->el_line.cursor,
878 1.12 christos el->el_line.lastchar - el->el_line.cursor);
879 1.12 christos return CC_REFRESH;
880 1.12 christos }
881 1.12 christos
882 1.12 christos /* vi_yank():
883 1.12 christos * Vi yank
884 1.12 christos * [y]
885 1.12 christos */
886 1.12 christos protected el_action_t
887 1.12 christos /*ARGSUSED*/
888 1.12 christos vi_yank(EditLine *el, int c)
889 1.12 christos {
890 1.12 christos
891 1.12 christos return cv_action(el, YANK);
892 1.12 christos }
893 1.12 christos
894 1.12 christos /* vi_comment_out():
895 1.12 christos * Vi comment out current command
896 1.12 christos * [c]
897 1.12 christos */
898 1.12 christos protected el_action_t
899 1.12 christos /*ARGSUSED*/
900 1.12 christos vi_comment_out(EditLine *el, int c)
901 1.12 christos {
902 1.12 christos
903 1.12 christos el->el_line.cursor = el->el_line.buffer;
904 1.12 christos c_insert(el, 1);
905 1.12 christos *el->el_line.cursor = '#';
906 1.12 christos re_refresh(el);
907 1.12 christos return ed_newline(el, 0);
908 1.12 christos }
909 1.12 christos
910 1.12 christos /* vi_alias():
911 1.12 christos * Vi include shell alias
912 1.12 christos * [@]
913 1.12 christos * NB: posix impiles that we should enter insert mode, however
914 1.12 christos * this is against historical precedent...
915 1.12 christos */
916 1.12 christos protected el_action_t
917 1.12 christos /*ARGSUSED*/
918 1.12 christos vi_alias(EditLine *el, int c)
919 1.12 christos {
920 1.14 christos #ifdef __weak_extern
921 1.12 christos char alias_name[3];
922 1.12 christos char *alias_text;
923 1.14 christos extern char *get_alias_text(const char *);
924 1.16 dsl __weak_extern(get_alias_text);
925 1.12 christos
926 1.12 christos if (get_alias_text == 0) {
927 1.12 christos return CC_ERROR;
928 1.12 christos }
929 1.14 christos
930 1.12 christos alias_name[0] = '_';
931 1.12 christos alias_name[2] = 0;
932 1.12 christos if (el_getc(el, &alias_name[1]) != 1)
933 1.12 christos return CC_ERROR;
934 1.12 christos
935 1.12 christos alias_text = get_alias_text(alias_name);
936 1.12 christos if (alias_text != NULL)
937 1.12 christos el_push(el, alias_text);
938 1.12 christos return CC_NORM;
939 1.14 christos #else
940 1.14 christos return CC_ERROR;
941 1.14 christos #endif
942 1.12 christos }
943 1.12 christos
944 1.12 christos /* vi_to_history_line():
945 1.12 christos * Vi go to specified history file line.
946 1.12 christos * [G]
947 1.12 christos */
948 1.12 christos protected el_action_t
949 1.12 christos /*ARGSUSED*/
950 1.12 christos vi_to_history_line(EditLine *el, int c)
951 1.12 christos {
952 1.12 christos int sv_event_no = el->el_history.eventno;
953 1.12 christos el_action_t rval;
954 1.12 christos
955 1.12 christos
956 1.12 christos if (el->el_history.eventno == 0) {
957 1.12 christos (void) strncpy(el->el_history.buf, el->el_line.buffer,
958 1.12 christos EL_BUFSIZ);
959 1.12 christos el->el_history.last = el->el_history.buf +
960 1.12 christos (el->el_line.lastchar - el->el_line.buffer);
961 1.12 christos }
962 1.12 christos
963 1.12 christos /* Lack of a 'count' means oldest, not 1 */
964 1.12 christos if (!el->el_state.doingarg) {
965 1.12 christos el->el_history.eventno = 0x7fffffff;
966 1.12 christos hist_get(el);
967 1.12 christos } else {
968 1.12 christos /* This is brain dead, all the rest of this code counts
969 1.12 christos * upwards going into the past. Here we need count in the
970 1.12 christos * other direction (to match the output of fc -l).
971 1.12 christos * I could change the world, but this seems to suffice.
972 1.12 christos */
973 1.12 christos el->el_history.eventno = 1;
974 1.12 christos if (hist_get(el) == CC_ERROR)
975 1.12 christos return CC_ERROR;
976 1.12 christos el->el_history.eventno = 1 + el->el_history.ev.num
977 1.12 christos - el->el_state.argument;
978 1.12 christos if (el->el_history.eventno < 0) {
979 1.12 christos el->el_history.eventno = sv_event_no;
980 1.12 christos return CC_ERROR;
981 1.12 christos }
982 1.12 christos }
983 1.12 christos rval = hist_get(el);
984 1.12 christos if (rval == CC_ERROR)
985 1.12 christos el->el_history.eventno = sv_event_no;
986 1.12 christos return rval;
987 1.12 christos }
988 1.12 christos
989 1.12 christos /* vi_histedit():
990 1.12 christos * Vi edit history line with vi
991 1.12 christos * [v]
992 1.12 christos */
993 1.12 christos protected el_action_t
994 1.12 christos /*ARGSUSED*/
995 1.12 christos vi_histedit(EditLine *el, int c)
996 1.12 christos {
997 1.12 christos int fd;
998 1.12 christos pid_t pid;
999 1.12 christos int st;
1000 1.12 christos char tempfile[] = "/tmp/histedit.XXXXXXXXXX";
1001 1.12 christos char *cp;
1002 1.12 christos
1003 1.12 christos if (el->el_state.doingarg) {
1004 1.12 christos if (vi_to_history_line(el, 0) == CC_ERROR)
1005 1.12 christos return CC_ERROR;
1006 1.12 christos }
1007 1.12 christos
1008 1.12 christos fd = mkstemp(tempfile);
1009 1.12 christos if (fd < 0)
1010 1.12 christos return CC_ERROR;
1011 1.12 christos cp = el->el_line.buffer;
1012 1.12 christos write(fd, cp, el->el_line.lastchar - cp +0u);
1013 1.12 christos write(fd, "\n", 1);
1014 1.12 christos pid = fork();
1015 1.12 christos switch (pid) {
1016 1.12 christos case -1:
1017 1.12 christos close(fd);
1018 1.12 christos unlink(tempfile);
1019 1.12 christos return CC_ERROR;
1020 1.12 christos case 0:
1021 1.12 christos close(fd);
1022 1.12 christos execlp("vi", "vi", tempfile, 0);
1023 1.12 christos exit(0);
1024 1.12 christos /*NOTREACHED*/
1025 1.12 christos default:
1026 1.12 christos while (waitpid(pid, &st, 0) != pid)
1027 1.12 christos continue;
1028 1.12 christos lseek(fd, 0ll, SEEK_SET);
1029 1.12 christos st = read(fd, cp, el->el_line.limit - cp +0u);
1030 1.12 christos if (st > 0 && cp[st - 1] == '\n')
1031 1.12 christos st--;
1032 1.12 christos el->el_line.cursor = cp;
1033 1.12 christos el->el_line.lastchar = cp + st;
1034 1.12 christos break;
1035 1.12 christos }
1036 1.12 christos
1037 1.12 christos close(fd);
1038 1.12 christos unlink(tempfile);
1039 1.12 christos /* return CC_REFRESH; */
1040 1.12 christos return ed_newline(el, 0);
1041 1.12 christos }
1042 1.12 christos
1043 1.12 christos /* vi_history_word():
1044 1.12 christos * Vi append word from previous input line
1045 1.12 christos * [_]
1046 1.12 christos * Who knows where this one came from!
1047 1.12 christos * '_' in vi means 'entire current line', so 'cc' is a synonym for 'c_'
1048 1.12 christos */
1049 1.12 christos protected el_action_t
1050 1.12 christos /*ARGSUSED*/
1051 1.12 christos vi_history_word(EditLine *el, int c)
1052 1.12 christos {
1053 1.12 christos const char *wp = HIST_FIRST(el);
1054 1.12 christos const char *wep, *wsp;
1055 1.12 christos int len;
1056 1.12 christos char *cp;
1057 1.12 christos const char *lim;
1058 1.12 christos
1059 1.12 christos if (wp == NULL)
1060 1.12 christos return CC_ERROR;
1061 1.12 christos
1062 1.13 christos wep = wsp = 0;
1063 1.12 christos do {
1064 1.12 christos while (isspace((unsigned char)*wp))
1065 1.12 christos wp++;
1066 1.12 christos if (*wp == 0)
1067 1.12 christos break;
1068 1.12 christos wsp = wp;
1069 1.12 christos while (*wp && !isspace((unsigned char)*wp))
1070 1.12 christos wp++;
1071 1.12 christos wep = wp;
1072 1.12 christos } while ((!el->el_state.doingarg || --el->el_state.argument > 0) && *wp != 0);
1073 1.12 christos
1074 1.12 christos if (wsp == 0 || (el->el_state.doingarg && el->el_state.argument != 0))
1075 1.12 christos return CC_ERROR;
1076 1.12 christos
1077 1.12 christos cv_undo(el);
1078 1.12 christos len = wep - wsp;
1079 1.12 christos if (el->el_line.cursor < el->el_line.lastchar)
1080 1.12 christos el->el_line.cursor++;
1081 1.12 christos c_insert(el, len + 1);
1082 1.12 christos cp = el->el_line.cursor;
1083 1.12 christos lim = el->el_line.limit;
1084 1.12 christos if (cp < lim)
1085 1.12 christos *cp++ = ' ';
1086 1.12 christos while (wsp < wep && cp < lim)
1087 1.12 christos *cp++ = *wsp++;
1088 1.12 christos el->el_line.cursor = cp;
1089 1.12 christos
1090 1.12 christos el->el_map.current = el->el_map.key;
1091 1.12 christos return CC_REFRESH;
1092 1.12 christos }
1093 1.12 christos
1094 1.12 christos /* vi_redo():
1095 1.12 christos * Vi redo last non-motion command
1096 1.12 christos * [.]
1097 1.12 christos */
1098 1.12 christos protected el_action_t
1099 1.12 christos /*ARGSUSED*/
1100 1.12 christos vi_redo(EditLine *el, int c)
1101 1.12 christos {
1102 1.12 christos c_redo_t *r = &el->el_chared.c_redo;
1103 1.12 christos
1104 1.12 christos if (!el->el_state.doingarg && r->count) {
1105 1.12 christos el->el_state.doingarg = 1;
1106 1.12 christos el->el_state.argument = r->count;
1107 1.12 christos }
1108 1.12 christos
1109 1.12 christos el->el_chared.c_vcmd.pos = el->el_line.cursor;
1110 1.12 christos el->el_chared.c_vcmd.action = r->action;
1111 1.12 christos if (r->pos != r->buf) {
1112 1.12 christos if (r->pos + 1 > r->lim)
1113 1.12 christos /* sanity */
1114 1.12 christos r->pos = r->lim - 1;
1115 1.12 christos r->pos[0] = 0;
1116 1.12 christos el_push(el, r->buf);
1117 1.12 christos }
1118 1.12 christos
1119 1.12 christos el->el_state.thiscmd = r->cmd;
1120 1.12 christos el->el_state.thisch = r->ch;
1121 1.12 christos return (*el->el_map.func[r->cmd])(el, r->ch);
1122 1.1 cgd }
1123