1*d0ef721eSBaptiste Daroussin /* $NetBSD: emacs.c,v 1.36 2016/05/09 21:46:56 christos Exp $ */
2*d0ef721eSBaptiste Daroussin
3*d0ef721eSBaptiste Daroussin /*-
4*d0ef721eSBaptiste Daroussin * Copyright (c) 1992, 1993
5*d0ef721eSBaptiste Daroussin * The Regents of the University of California. All rights reserved.
6*d0ef721eSBaptiste Daroussin *
7*d0ef721eSBaptiste Daroussin * This code is derived from software contributed to Berkeley by
8*d0ef721eSBaptiste Daroussin * Christos Zoulas of Cornell University.
9*d0ef721eSBaptiste Daroussin *
10*d0ef721eSBaptiste Daroussin * Redistribution and use in source and binary forms, with or without
11*d0ef721eSBaptiste Daroussin * modification, are permitted provided that the following conditions
12*d0ef721eSBaptiste Daroussin * are met:
13*d0ef721eSBaptiste Daroussin * 1. Redistributions of source code must retain the above copyright
14*d0ef721eSBaptiste Daroussin * notice, this list of conditions and the following disclaimer.
15*d0ef721eSBaptiste Daroussin * 2. Redistributions in binary form must reproduce the above copyright
16*d0ef721eSBaptiste Daroussin * notice, this list of conditions and the following disclaimer in the
17*d0ef721eSBaptiste Daroussin * documentation and/or other materials provided with the distribution.
18*d0ef721eSBaptiste Daroussin * 3. Neither the name of the University nor the names of its contributors
19*d0ef721eSBaptiste Daroussin * may be used to endorse or promote products derived from this software
20*d0ef721eSBaptiste Daroussin * without specific prior written permission.
21*d0ef721eSBaptiste Daroussin *
22*d0ef721eSBaptiste Daroussin * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23*d0ef721eSBaptiste Daroussin * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24*d0ef721eSBaptiste Daroussin * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25*d0ef721eSBaptiste Daroussin * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26*d0ef721eSBaptiste Daroussin * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27*d0ef721eSBaptiste Daroussin * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28*d0ef721eSBaptiste Daroussin * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29*d0ef721eSBaptiste Daroussin * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30*d0ef721eSBaptiste Daroussin * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31*d0ef721eSBaptiste Daroussin * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32*d0ef721eSBaptiste Daroussin * SUCH DAMAGE.
33*d0ef721eSBaptiste Daroussin */
34*d0ef721eSBaptiste Daroussin
35*d0ef721eSBaptiste Daroussin #include "config.h"
36*d0ef721eSBaptiste Daroussin #if !defined(lint) && !defined(SCCSID)
37*d0ef721eSBaptiste Daroussin #if 0
38*d0ef721eSBaptiste Daroussin static char sccsid[] = "@(#)emacs.c 8.1 (Berkeley) 6/4/93";
39*d0ef721eSBaptiste Daroussin #else
40*d0ef721eSBaptiste Daroussin __RCSID("$NetBSD: emacs.c,v 1.36 2016/05/09 21:46:56 christos Exp $");
41*d0ef721eSBaptiste Daroussin #endif
42*d0ef721eSBaptiste Daroussin #endif /* not lint && not SCCSID */
43*d0ef721eSBaptiste Daroussin
44*d0ef721eSBaptiste Daroussin /*
45*d0ef721eSBaptiste Daroussin * emacs.c: Emacs functions
46*d0ef721eSBaptiste Daroussin */
47*d0ef721eSBaptiste Daroussin #include <ctype.h>
48*d0ef721eSBaptiste Daroussin
49*d0ef721eSBaptiste Daroussin #include "el.h"
50*d0ef721eSBaptiste Daroussin #include "emacs.h"
51*d0ef721eSBaptiste Daroussin #include "fcns.h"
52*d0ef721eSBaptiste Daroussin
53*d0ef721eSBaptiste Daroussin /* em_delete_or_list():
54*d0ef721eSBaptiste Daroussin * Delete character under cursor or list completions if at end of line
55*d0ef721eSBaptiste Daroussin * [^D]
56*d0ef721eSBaptiste Daroussin */
57*d0ef721eSBaptiste Daroussin libedit_private el_action_t
58*d0ef721eSBaptiste Daroussin /*ARGSUSED*/
em_delete_or_list(EditLine * el,wint_t c)59*d0ef721eSBaptiste Daroussin em_delete_or_list(EditLine *el, wint_t c)
60*d0ef721eSBaptiste Daroussin {
61*d0ef721eSBaptiste Daroussin
62*d0ef721eSBaptiste Daroussin if (el->el_line.cursor == el->el_line.lastchar) {
63*d0ef721eSBaptiste Daroussin /* if I'm at the end */
64*d0ef721eSBaptiste Daroussin if (el->el_line.cursor == el->el_line.buffer) {
65*d0ef721eSBaptiste Daroussin /* and the beginning */
66*d0ef721eSBaptiste Daroussin terminal_writec(el, c); /* then do an EOF */
67*d0ef721eSBaptiste Daroussin return CC_EOF;
68*d0ef721eSBaptiste Daroussin } else {
69*d0ef721eSBaptiste Daroussin /*
70*d0ef721eSBaptiste Daroussin * Here we could list completions, but it is an
71*d0ef721eSBaptiste Daroussin * error right now
72*d0ef721eSBaptiste Daroussin */
73*d0ef721eSBaptiste Daroussin terminal_beep(el);
74*d0ef721eSBaptiste Daroussin return CC_ERROR;
75*d0ef721eSBaptiste Daroussin }
76*d0ef721eSBaptiste Daroussin } else {
77*d0ef721eSBaptiste Daroussin if (el->el_state.doingarg)
78*d0ef721eSBaptiste Daroussin c_delafter(el, el->el_state.argument);
79*d0ef721eSBaptiste Daroussin else
80*d0ef721eSBaptiste Daroussin c_delafter1(el);
81*d0ef721eSBaptiste Daroussin if (el->el_line.cursor > el->el_line.lastchar)
82*d0ef721eSBaptiste Daroussin el->el_line.cursor = el->el_line.lastchar;
83*d0ef721eSBaptiste Daroussin /* bounds check */
84*d0ef721eSBaptiste Daroussin return CC_REFRESH;
85*d0ef721eSBaptiste Daroussin }
86*d0ef721eSBaptiste Daroussin }
87*d0ef721eSBaptiste Daroussin
88*d0ef721eSBaptiste Daroussin
89*d0ef721eSBaptiste Daroussin /* em_delete_next_word():
90*d0ef721eSBaptiste Daroussin * Cut from cursor to end of current word
91*d0ef721eSBaptiste Daroussin * [M-d]
92*d0ef721eSBaptiste Daroussin */
93*d0ef721eSBaptiste Daroussin libedit_private el_action_t
94*d0ef721eSBaptiste Daroussin /*ARGSUSED*/
em_delete_next_word(EditLine * el,wint_t c)95*d0ef721eSBaptiste Daroussin em_delete_next_word(EditLine *el, wint_t c __attribute__((__unused__)))
96*d0ef721eSBaptiste Daroussin {
97*d0ef721eSBaptiste Daroussin wchar_t *cp, *p, *kp;
98*d0ef721eSBaptiste Daroussin
99*d0ef721eSBaptiste Daroussin if (el->el_line.cursor == el->el_line.lastchar)
100*d0ef721eSBaptiste Daroussin return CC_ERROR;
101*d0ef721eSBaptiste Daroussin
102*d0ef721eSBaptiste Daroussin cp = c__next_word(el->el_line.cursor, el->el_line.lastchar,
103*d0ef721eSBaptiste Daroussin el->el_state.argument, ce__isword);
104*d0ef721eSBaptiste Daroussin
105*d0ef721eSBaptiste Daroussin for (p = el->el_line.cursor, kp = el->el_chared.c_kill.buf; p < cp; p++)
106*d0ef721eSBaptiste Daroussin /* save the text */
107*d0ef721eSBaptiste Daroussin *kp++ = *p;
108*d0ef721eSBaptiste Daroussin el->el_chared.c_kill.last = kp;
109*d0ef721eSBaptiste Daroussin
110*d0ef721eSBaptiste Daroussin c_delafter(el, (int)(cp - el->el_line.cursor)); /* delete after dot */
111*d0ef721eSBaptiste Daroussin if (el->el_line.cursor > el->el_line.lastchar)
112*d0ef721eSBaptiste Daroussin el->el_line.cursor = el->el_line.lastchar;
113*d0ef721eSBaptiste Daroussin /* bounds check */
114*d0ef721eSBaptiste Daroussin return CC_REFRESH;
115*d0ef721eSBaptiste Daroussin }
116*d0ef721eSBaptiste Daroussin
117*d0ef721eSBaptiste Daroussin
118*d0ef721eSBaptiste Daroussin /* em_yank():
119*d0ef721eSBaptiste Daroussin * Paste cut buffer at cursor position
120*d0ef721eSBaptiste Daroussin * [^Y]
121*d0ef721eSBaptiste Daroussin */
122*d0ef721eSBaptiste Daroussin libedit_private el_action_t
123*d0ef721eSBaptiste Daroussin /*ARGSUSED*/
em_yank(EditLine * el,wint_t c)124*d0ef721eSBaptiste Daroussin em_yank(EditLine *el, wint_t c __attribute__((__unused__)))
125*d0ef721eSBaptiste Daroussin {
126*d0ef721eSBaptiste Daroussin wchar_t *kp, *cp;
127*d0ef721eSBaptiste Daroussin
128*d0ef721eSBaptiste Daroussin if (el->el_chared.c_kill.last == el->el_chared.c_kill.buf)
129*d0ef721eSBaptiste Daroussin return CC_NORM;
130*d0ef721eSBaptiste Daroussin
131*d0ef721eSBaptiste Daroussin if (el->el_line.lastchar +
132*d0ef721eSBaptiste Daroussin (el->el_chared.c_kill.last - el->el_chared.c_kill.buf) >=
133*d0ef721eSBaptiste Daroussin el->el_line.limit)
134*d0ef721eSBaptiste Daroussin return CC_ERROR;
135*d0ef721eSBaptiste Daroussin
136*d0ef721eSBaptiste Daroussin el->el_chared.c_kill.mark = el->el_line.cursor;
137*d0ef721eSBaptiste Daroussin cp = el->el_line.cursor;
138*d0ef721eSBaptiste Daroussin
139*d0ef721eSBaptiste Daroussin /* open the space, */
140*d0ef721eSBaptiste Daroussin c_insert(el,
141*d0ef721eSBaptiste Daroussin (int)(el->el_chared.c_kill.last - el->el_chared.c_kill.buf));
142*d0ef721eSBaptiste Daroussin /* copy the chars */
143*d0ef721eSBaptiste Daroussin for (kp = el->el_chared.c_kill.buf; kp < el->el_chared.c_kill.last; kp++)
144*d0ef721eSBaptiste Daroussin *cp++ = *kp;
145*d0ef721eSBaptiste Daroussin
146*d0ef721eSBaptiste Daroussin /* if an arg, cursor at beginning else cursor at end */
147*d0ef721eSBaptiste Daroussin if (el->el_state.argument == 1)
148*d0ef721eSBaptiste Daroussin el->el_line.cursor = cp;
149*d0ef721eSBaptiste Daroussin
150*d0ef721eSBaptiste Daroussin return CC_REFRESH;
151*d0ef721eSBaptiste Daroussin }
152*d0ef721eSBaptiste Daroussin
153*d0ef721eSBaptiste Daroussin
154*d0ef721eSBaptiste Daroussin /* em_kill_line():
155*d0ef721eSBaptiste Daroussin * Cut the entire line and save in cut buffer
156*d0ef721eSBaptiste Daroussin * [^U]
157*d0ef721eSBaptiste Daroussin */
158*d0ef721eSBaptiste Daroussin libedit_private el_action_t
159*d0ef721eSBaptiste Daroussin /*ARGSUSED*/
em_kill_line(EditLine * el,wint_t c)160*d0ef721eSBaptiste Daroussin em_kill_line(EditLine *el, wint_t c __attribute__((__unused__)))
161*d0ef721eSBaptiste Daroussin {
162*d0ef721eSBaptiste Daroussin wchar_t *kp, *cp;
163*d0ef721eSBaptiste Daroussin
164*d0ef721eSBaptiste Daroussin cp = el->el_line.buffer;
165*d0ef721eSBaptiste Daroussin kp = el->el_chared.c_kill.buf;
166*d0ef721eSBaptiste Daroussin while (cp < el->el_line.lastchar)
167*d0ef721eSBaptiste Daroussin *kp++ = *cp++; /* copy it */
168*d0ef721eSBaptiste Daroussin el->el_chared.c_kill.last = kp;
169*d0ef721eSBaptiste Daroussin /* zap! -- delete all of it */
170*d0ef721eSBaptiste Daroussin el->el_line.lastchar = el->el_line.buffer;
171*d0ef721eSBaptiste Daroussin el->el_line.cursor = el->el_line.buffer;
172*d0ef721eSBaptiste Daroussin return CC_REFRESH;
173*d0ef721eSBaptiste Daroussin }
174*d0ef721eSBaptiste Daroussin
175*d0ef721eSBaptiste Daroussin
176*d0ef721eSBaptiste Daroussin /* em_kill_region():
177*d0ef721eSBaptiste Daroussin * Cut area between mark and cursor and save in cut buffer
178*d0ef721eSBaptiste Daroussin * [^W]
179*d0ef721eSBaptiste Daroussin */
180*d0ef721eSBaptiste Daroussin libedit_private el_action_t
181*d0ef721eSBaptiste Daroussin /*ARGSUSED*/
em_kill_region(EditLine * el,wint_t c)182*d0ef721eSBaptiste Daroussin em_kill_region(EditLine *el, wint_t c __attribute__((__unused__)))
183*d0ef721eSBaptiste Daroussin {
184*d0ef721eSBaptiste Daroussin wchar_t *kp, *cp;
185*d0ef721eSBaptiste Daroussin
186*d0ef721eSBaptiste Daroussin if (!el->el_chared.c_kill.mark)
187*d0ef721eSBaptiste Daroussin return CC_ERROR;
188*d0ef721eSBaptiste Daroussin
189*d0ef721eSBaptiste Daroussin if (el->el_chared.c_kill.mark > el->el_line.cursor) {
190*d0ef721eSBaptiste Daroussin cp = el->el_line.cursor;
191*d0ef721eSBaptiste Daroussin kp = el->el_chared.c_kill.buf;
192*d0ef721eSBaptiste Daroussin while (cp < el->el_chared.c_kill.mark)
193*d0ef721eSBaptiste Daroussin *kp++ = *cp++; /* copy it */
194*d0ef721eSBaptiste Daroussin el->el_chared.c_kill.last = kp;
195*d0ef721eSBaptiste Daroussin c_delafter(el, (int)(cp - el->el_line.cursor));
196*d0ef721eSBaptiste Daroussin } else { /* mark is before cursor */
197*d0ef721eSBaptiste Daroussin cp = el->el_chared.c_kill.mark;
198*d0ef721eSBaptiste Daroussin kp = el->el_chared.c_kill.buf;
199*d0ef721eSBaptiste Daroussin while (cp < el->el_line.cursor)
200*d0ef721eSBaptiste Daroussin *kp++ = *cp++; /* copy it */
201*d0ef721eSBaptiste Daroussin el->el_chared.c_kill.last = kp;
202*d0ef721eSBaptiste Daroussin c_delbefore(el, (int)(cp - el->el_chared.c_kill.mark));
203*d0ef721eSBaptiste Daroussin el->el_line.cursor = el->el_chared.c_kill.mark;
204*d0ef721eSBaptiste Daroussin }
205*d0ef721eSBaptiste Daroussin return CC_REFRESH;
206*d0ef721eSBaptiste Daroussin }
207*d0ef721eSBaptiste Daroussin
208*d0ef721eSBaptiste Daroussin
209*d0ef721eSBaptiste Daroussin /* em_copy_region():
210*d0ef721eSBaptiste Daroussin * Copy area between mark and cursor to cut buffer
211*d0ef721eSBaptiste Daroussin * [M-W]
212*d0ef721eSBaptiste Daroussin */
213*d0ef721eSBaptiste Daroussin libedit_private el_action_t
214*d0ef721eSBaptiste Daroussin /*ARGSUSED*/
em_copy_region(EditLine * el,wint_t c)215*d0ef721eSBaptiste Daroussin em_copy_region(EditLine *el, wint_t c __attribute__((__unused__)))
216*d0ef721eSBaptiste Daroussin {
217*d0ef721eSBaptiste Daroussin wchar_t *kp, *cp;
218*d0ef721eSBaptiste Daroussin
219*d0ef721eSBaptiste Daroussin if (!el->el_chared.c_kill.mark)
220*d0ef721eSBaptiste Daroussin return CC_ERROR;
221*d0ef721eSBaptiste Daroussin
222*d0ef721eSBaptiste Daroussin if (el->el_chared.c_kill.mark > el->el_line.cursor) {
223*d0ef721eSBaptiste Daroussin cp = el->el_line.cursor;
224*d0ef721eSBaptiste Daroussin kp = el->el_chared.c_kill.buf;
225*d0ef721eSBaptiste Daroussin while (cp < el->el_chared.c_kill.mark)
226*d0ef721eSBaptiste Daroussin *kp++ = *cp++; /* copy it */
227*d0ef721eSBaptiste Daroussin el->el_chared.c_kill.last = kp;
228*d0ef721eSBaptiste Daroussin } else {
229*d0ef721eSBaptiste Daroussin cp = el->el_chared.c_kill.mark;
230*d0ef721eSBaptiste Daroussin kp = el->el_chared.c_kill.buf;
231*d0ef721eSBaptiste Daroussin while (cp < el->el_line.cursor)
232*d0ef721eSBaptiste Daroussin *kp++ = *cp++; /* copy it */
233*d0ef721eSBaptiste Daroussin el->el_chared.c_kill.last = kp;
234*d0ef721eSBaptiste Daroussin }
235*d0ef721eSBaptiste Daroussin return CC_NORM;
236*d0ef721eSBaptiste Daroussin }
237*d0ef721eSBaptiste Daroussin
238*d0ef721eSBaptiste Daroussin
239*d0ef721eSBaptiste Daroussin /* em_gosmacs_transpose():
240*d0ef721eSBaptiste Daroussin * Exchange the two characters before the cursor
241*d0ef721eSBaptiste Daroussin * Gosling emacs transpose chars [^T]
242*d0ef721eSBaptiste Daroussin */
243*d0ef721eSBaptiste Daroussin libedit_private el_action_t
em_gosmacs_transpose(EditLine * el,wint_t c)244*d0ef721eSBaptiste Daroussin em_gosmacs_transpose(EditLine *el, wint_t c)
245*d0ef721eSBaptiste Daroussin {
246*d0ef721eSBaptiste Daroussin
247*d0ef721eSBaptiste Daroussin if (el->el_line.cursor > &el->el_line.buffer[1]) {
248*d0ef721eSBaptiste Daroussin /* must have at least two chars entered */
249*d0ef721eSBaptiste Daroussin c = el->el_line.cursor[-2];
250*d0ef721eSBaptiste Daroussin el->el_line.cursor[-2] = el->el_line.cursor[-1];
251*d0ef721eSBaptiste Daroussin el->el_line.cursor[-1] = c;
252*d0ef721eSBaptiste Daroussin return CC_REFRESH;
253*d0ef721eSBaptiste Daroussin } else
254*d0ef721eSBaptiste Daroussin return CC_ERROR;
255*d0ef721eSBaptiste Daroussin }
256*d0ef721eSBaptiste Daroussin
257*d0ef721eSBaptiste Daroussin
258*d0ef721eSBaptiste Daroussin /* em_next_word():
259*d0ef721eSBaptiste Daroussin * Move next to end of current word
260*d0ef721eSBaptiste Daroussin * [M-f]
261*d0ef721eSBaptiste Daroussin */
262*d0ef721eSBaptiste Daroussin libedit_private el_action_t
263*d0ef721eSBaptiste Daroussin /*ARGSUSED*/
em_next_word(EditLine * el,wint_t c)264*d0ef721eSBaptiste Daroussin em_next_word(EditLine *el, wint_t c __attribute__((__unused__)))
265*d0ef721eSBaptiste Daroussin {
266*d0ef721eSBaptiste Daroussin if (el->el_line.cursor == el->el_line.lastchar)
267*d0ef721eSBaptiste Daroussin return CC_ERROR;
268*d0ef721eSBaptiste Daroussin
269*d0ef721eSBaptiste Daroussin el->el_line.cursor = c__next_word(el->el_line.cursor,
270*d0ef721eSBaptiste Daroussin el->el_line.lastchar,
271*d0ef721eSBaptiste Daroussin el->el_state.argument,
272*d0ef721eSBaptiste Daroussin ce__isword);
273*d0ef721eSBaptiste Daroussin
274*d0ef721eSBaptiste Daroussin if (el->el_map.type == MAP_VI)
275*d0ef721eSBaptiste Daroussin if (el->el_chared.c_vcmd.action != NOP) {
276*d0ef721eSBaptiste Daroussin cv_delfini(el);
277*d0ef721eSBaptiste Daroussin return CC_REFRESH;
278*d0ef721eSBaptiste Daroussin }
279*d0ef721eSBaptiste Daroussin return CC_CURSOR;
280*d0ef721eSBaptiste Daroussin }
281*d0ef721eSBaptiste Daroussin
282*d0ef721eSBaptiste Daroussin
283*d0ef721eSBaptiste Daroussin /* em_upper_case():
284*d0ef721eSBaptiste Daroussin * Uppercase the characters from cursor to end of current word
285*d0ef721eSBaptiste Daroussin * [M-u]
286*d0ef721eSBaptiste Daroussin */
287*d0ef721eSBaptiste Daroussin libedit_private el_action_t
288*d0ef721eSBaptiste Daroussin /*ARGSUSED*/
em_upper_case(EditLine * el,wint_t c)289*d0ef721eSBaptiste Daroussin em_upper_case(EditLine *el, wint_t c __attribute__((__unused__)))
290*d0ef721eSBaptiste Daroussin {
291*d0ef721eSBaptiste Daroussin wchar_t *cp, *ep;
292*d0ef721eSBaptiste Daroussin
293*d0ef721eSBaptiste Daroussin ep = c__next_word(el->el_line.cursor, el->el_line.lastchar,
294*d0ef721eSBaptiste Daroussin el->el_state.argument, ce__isword);
295*d0ef721eSBaptiste Daroussin
296*d0ef721eSBaptiste Daroussin for (cp = el->el_line.cursor; cp < ep; cp++)
297*d0ef721eSBaptiste Daroussin if (iswlower(*cp))
298*d0ef721eSBaptiste Daroussin *cp = towupper(*cp);
299*d0ef721eSBaptiste Daroussin
300*d0ef721eSBaptiste Daroussin el->el_line.cursor = ep;
301*d0ef721eSBaptiste Daroussin if (el->el_line.cursor > el->el_line.lastchar)
302*d0ef721eSBaptiste Daroussin el->el_line.cursor = el->el_line.lastchar;
303*d0ef721eSBaptiste Daroussin return CC_REFRESH;
304*d0ef721eSBaptiste Daroussin }
305*d0ef721eSBaptiste Daroussin
306*d0ef721eSBaptiste Daroussin
307*d0ef721eSBaptiste Daroussin /* em_capitol_case():
308*d0ef721eSBaptiste Daroussin * Capitalize the characters from cursor to end of current word
309*d0ef721eSBaptiste Daroussin * [M-c]
310*d0ef721eSBaptiste Daroussin */
311*d0ef721eSBaptiste Daroussin libedit_private el_action_t
312*d0ef721eSBaptiste Daroussin /*ARGSUSED*/
em_capitol_case(EditLine * el,wint_t c)313*d0ef721eSBaptiste Daroussin em_capitol_case(EditLine *el, wint_t c __attribute__((__unused__)))
314*d0ef721eSBaptiste Daroussin {
315*d0ef721eSBaptiste Daroussin wchar_t *cp, *ep;
316*d0ef721eSBaptiste Daroussin
317*d0ef721eSBaptiste Daroussin ep = c__next_word(el->el_line.cursor, el->el_line.lastchar,
318*d0ef721eSBaptiste Daroussin el->el_state.argument, ce__isword);
319*d0ef721eSBaptiste Daroussin
320*d0ef721eSBaptiste Daroussin for (cp = el->el_line.cursor; cp < ep; cp++) {
321*d0ef721eSBaptiste Daroussin if (iswalpha(*cp)) {
322*d0ef721eSBaptiste Daroussin if (iswlower(*cp))
323*d0ef721eSBaptiste Daroussin *cp = towupper(*cp);
324*d0ef721eSBaptiste Daroussin cp++;
325*d0ef721eSBaptiste Daroussin break;
326*d0ef721eSBaptiste Daroussin }
327*d0ef721eSBaptiste Daroussin }
328*d0ef721eSBaptiste Daroussin for (; cp < ep; cp++)
329*d0ef721eSBaptiste Daroussin if (iswupper(*cp))
330*d0ef721eSBaptiste Daroussin *cp = towlower(*cp);
331*d0ef721eSBaptiste Daroussin
332*d0ef721eSBaptiste Daroussin el->el_line.cursor = ep;
333*d0ef721eSBaptiste Daroussin if (el->el_line.cursor > el->el_line.lastchar)
334*d0ef721eSBaptiste Daroussin el->el_line.cursor = el->el_line.lastchar;
335*d0ef721eSBaptiste Daroussin return CC_REFRESH;
336*d0ef721eSBaptiste Daroussin }
337*d0ef721eSBaptiste Daroussin
338*d0ef721eSBaptiste Daroussin
339*d0ef721eSBaptiste Daroussin /* em_lower_case():
340*d0ef721eSBaptiste Daroussin * Lowercase the characters from cursor to end of current word
341*d0ef721eSBaptiste Daroussin * [M-l]
342*d0ef721eSBaptiste Daroussin */
343*d0ef721eSBaptiste Daroussin libedit_private el_action_t
344*d0ef721eSBaptiste Daroussin /*ARGSUSED*/
em_lower_case(EditLine * el,wint_t c)345*d0ef721eSBaptiste Daroussin em_lower_case(EditLine *el, wint_t c __attribute__((__unused__)))
346*d0ef721eSBaptiste Daroussin {
347*d0ef721eSBaptiste Daroussin wchar_t *cp, *ep;
348*d0ef721eSBaptiste Daroussin
349*d0ef721eSBaptiste Daroussin ep = c__next_word(el->el_line.cursor, el->el_line.lastchar,
350*d0ef721eSBaptiste Daroussin el->el_state.argument, ce__isword);
351*d0ef721eSBaptiste Daroussin
352*d0ef721eSBaptiste Daroussin for (cp = el->el_line.cursor; cp < ep; cp++)
353*d0ef721eSBaptiste Daroussin if (iswupper(*cp))
354*d0ef721eSBaptiste Daroussin *cp = towlower(*cp);
355*d0ef721eSBaptiste Daroussin
356*d0ef721eSBaptiste Daroussin el->el_line.cursor = ep;
357*d0ef721eSBaptiste Daroussin if (el->el_line.cursor > el->el_line.lastchar)
358*d0ef721eSBaptiste Daroussin el->el_line.cursor = el->el_line.lastchar;
359*d0ef721eSBaptiste Daroussin return CC_REFRESH;
360*d0ef721eSBaptiste Daroussin }
361*d0ef721eSBaptiste Daroussin
362*d0ef721eSBaptiste Daroussin
363*d0ef721eSBaptiste Daroussin /* em_set_mark():
364*d0ef721eSBaptiste Daroussin * Set the mark at cursor
365*d0ef721eSBaptiste Daroussin * [^@]
366*d0ef721eSBaptiste Daroussin */
367*d0ef721eSBaptiste Daroussin libedit_private el_action_t
368*d0ef721eSBaptiste Daroussin /*ARGSUSED*/
em_set_mark(EditLine * el,wint_t c)369*d0ef721eSBaptiste Daroussin em_set_mark(EditLine *el, wint_t c __attribute__((__unused__)))
370*d0ef721eSBaptiste Daroussin {
371*d0ef721eSBaptiste Daroussin
372*d0ef721eSBaptiste Daroussin el->el_chared.c_kill.mark = el->el_line.cursor;
373*d0ef721eSBaptiste Daroussin return CC_NORM;
374*d0ef721eSBaptiste Daroussin }
375*d0ef721eSBaptiste Daroussin
376*d0ef721eSBaptiste Daroussin
377*d0ef721eSBaptiste Daroussin /* em_exchange_mark():
378*d0ef721eSBaptiste Daroussin * Exchange the cursor and mark
379*d0ef721eSBaptiste Daroussin * [^X^X]
380*d0ef721eSBaptiste Daroussin */
381*d0ef721eSBaptiste Daroussin libedit_private el_action_t
382*d0ef721eSBaptiste Daroussin /*ARGSUSED*/
em_exchange_mark(EditLine * el,wint_t c)383*d0ef721eSBaptiste Daroussin em_exchange_mark(EditLine *el, wint_t c __attribute__((__unused__)))
384*d0ef721eSBaptiste Daroussin {
385*d0ef721eSBaptiste Daroussin wchar_t *cp;
386*d0ef721eSBaptiste Daroussin
387*d0ef721eSBaptiste Daroussin cp = el->el_line.cursor;
388*d0ef721eSBaptiste Daroussin el->el_line.cursor = el->el_chared.c_kill.mark;
389*d0ef721eSBaptiste Daroussin el->el_chared.c_kill.mark = cp;
390*d0ef721eSBaptiste Daroussin return CC_CURSOR;
391*d0ef721eSBaptiste Daroussin }
392*d0ef721eSBaptiste Daroussin
393*d0ef721eSBaptiste Daroussin
394*d0ef721eSBaptiste Daroussin /* em_universal_argument():
395*d0ef721eSBaptiste Daroussin * Universal argument (argument times 4)
396*d0ef721eSBaptiste Daroussin * [^U]
397*d0ef721eSBaptiste Daroussin */
398*d0ef721eSBaptiste Daroussin libedit_private el_action_t
399*d0ef721eSBaptiste Daroussin /*ARGSUSED*/
em_universal_argument(EditLine * el,wint_t c)400*d0ef721eSBaptiste Daroussin em_universal_argument(EditLine *el, wint_t c __attribute__((__unused__)))
401*d0ef721eSBaptiste Daroussin { /* multiply current argument by 4 */
402*d0ef721eSBaptiste Daroussin
403*d0ef721eSBaptiste Daroussin if (el->el_state.argument > 1000000)
404*d0ef721eSBaptiste Daroussin return CC_ERROR;
405*d0ef721eSBaptiste Daroussin el->el_state.doingarg = 1;
406*d0ef721eSBaptiste Daroussin el->el_state.argument *= 4;
407*d0ef721eSBaptiste Daroussin return CC_ARGHACK;
408*d0ef721eSBaptiste Daroussin }
409*d0ef721eSBaptiste Daroussin
410*d0ef721eSBaptiste Daroussin
411*d0ef721eSBaptiste Daroussin /* em_meta_next():
412*d0ef721eSBaptiste Daroussin * Add 8th bit to next character typed
413*d0ef721eSBaptiste Daroussin * [<ESC>]
414*d0ef721eSBaptiste Daroussin */
415*d0ef721eSBaptiste Daroussin libedit_private el_action_t
416*d0ef721eSBaptiste Daroussin /*ARGSUSED*/
em_meta_next(EditLine * el,wint_t c)417*d0ef721eSBaptiste Daroussin em_meta_next(EditLine *el, wint_t c __attribute__((__unused__)))
418*d0ef721eSBaptiste Daroussin {
419*d0ef721eSBaptiste Daroussin
420*d0ef721eSBaptiste Daroussin el->el_state.metanext = 1;
421*d0ef721eSBaptiste Daroussin return CC_ARGHACK;
422*d0ef721eSBaptiste Daroussin }
423*d0ef721eSBaptiste Daroussin
424*d0ef721eSBaptiste Daroussin
425*d0ef721eSBaptiste Daroussin /* em_toggle_overwrite():
426*d0ef721eSBaptiste Daroussin * Switch from insert to overwrite mode or vice versa
427*d0ef721eSBaptiste Daroussin */
428*d0ef721eSBaptiste Daroussin libedit_private el_action_t
429*d0ef721eSBaptiste Daroussin /*ARGSUSED*/
em_toggle_overwrite(EditLine * el,wint_t c)430*d0ef721eSBaptiste Daroussin em_toggle_overwrite(EditLine *el, wint_t c __attribute__((__unused__)))
431*d0ef721eSBaptiste Daroussin {
432*d0ef721eSBaptiste Daroussin
433*d0ef721eSBaptiste Daroussin el->el_state.inputmode = (el->el_state.inputmode == MODE_INSERT) ?
434*d0ef721eSBaptiste Daroussin MODE_REPLACE : MODE_INSERT;
435*d0ef721eSBaptiste Daroussin return CC_NORM;
436*d0ef721eSBaptiste Daroussin }
437*d0ef721eSBaptiste Daroussin
438*d0ef721eSBaptiste Daroussin
439*d0ef721eSBaptiste Daroussin /* em_copy_prev_word():
440*d0ef721eSBaptiste Daroussin * Copy current word to cursor
441*d0ef721eSBaptiste Daroussin */
442*d0ef721eSBaptiste Daroussin libedit_private el_action_t
443*d0ef721eSBaptiste Daroussin /*ARGSUSED*/
em_copy_prev_word(EditLine * el,wint_t c)444*d0ef721eSBaptiste Daroussin em_copy_prev_word(EditLine *el, wint_t c __attribute__((__unused__)))
445*d0ef721eSBaptiste Daroussin {
446*d0ef721eSBaptiste Daroussin wchar_t *cp, *oldc, *dp;
447*d0ef721eSBaptiste Daroussin
448*d0ef721eSBaptiste Daroussin if (el->el_line.cursor == el->el_line.buffer)
449*d0ef721eSBaptiste Daroussin return CC_ERROR;
450*d0ef721eSBaptiste Daroussin
451*d0ef721eSBaptiste Daroussin oldc = el->el_line.cursor;
452*d0ef721eSBaptiste Daroussin /* does a bounds check */
453*d0ef721eSBaptiste Daroussin cp = c__prev_word(el->el_line.cursor, el->el_line.buffer,
454*d0ef721eSBaptiste Daroussin el->el_state.argument, ce__isword);
455*d0ef721eSBaptiste Daroussin
456*d0ef721eSBaptiste Daroussin c_insert(el, (int)(oldc - cp));
457*d0ef721eSBaptiste Daroussin for (dp = oldc; cp < oldc && dp < el->el_line.lastchar; cp++)
458*d0ef721eSBaptiste Daroussin *dp++ = *cp;
459*d0ef721eSBaptiste Daroussin
460*d0ef721eSBaptiste Daroussin el->el_line.cursor = dp;/* put cursor at end */
461*d0ef721eSBaptiste Daroussin
462*d0ef721eSBaptiste Daroussin return CC_REFRESH;
463*d0ef721eSBaptiste Daroussin }
464*d0ef721eSBaptiste Daroussin
465*d0ef721eSBaptiste Daroussin
466*d0ef721eSBaptiste Daroussin /* em_inc_search_next():
467*d0ef721eSBaptiste Daroussin * Emacs incremental next search
468*d0ef721eSBaptiste Daroussin */
469*d0ef721eSBaptiste Daroussin libedit_private el_action_t
470*d0ef721eSBaptiste Daroussin /*ARGSUSED*/
em_inc_search_next(EditLine * el,wint_t c)471*d0ef721eSBaptiste Daroussin em_inc_search_next(EditLine *el, wint_t c __attribute__((__unused__)))
472*d0ef721eSBaptiste Daroussin {
473*d0ef721eSBaptiste Daroussin
474*d0ef721eSBaptiste Daroussin el->el_search.patlen = 0;
475*d0ef721eSBaptiste Daroussin return ce_inc_search(el, ED_SEARCH_NEXT_HISTORY);
476*d0ef721eSBaptiste Daroussin }
477*d0ef721eSBaptiste Daroussin
478*d0ef721eSBaptiste Daroussin
479*d0ef721eSBaptiste Daroussin /* em_inc_search_prev():
480*d0ef721eSBaptiste Daroussin * Emacs incremental reverse search
481*d0ef721eSBaptiste Daroussin */
482*d0ef721eSBaptiste Daroussin libedit_private el_action_t
483*d0ef721eSBaptiste Daroussin /*ARGSUSED*/
em_inc_search_prev(EditLine * el,wint_t c)484*d0ef721eSBaptiste Daroussin em_inc_search_prev(EditLine *el, wint_t c __attribute__((__unused__)))
485*d0ef721eSBaptiste Daroussin {
486*d0ef721eSBaptiste Daroussin
487*d0ef721eSBaptiste Daroussin el->el_search.patlen = 0;
488*d0ef721eSBaptiste Daroussin return ce_inc_search(el, ED_SEARCH_PREV_HISTORY);
489*d0ef721eSBaptiste Daroussin }
490*d0ef721eSBaptiste Daroussin
491*d0ef721eSBaptiste Daroussin
492*d0ef721eSBaptiste Daroussin /* em_delete_prev_char():
493*d0ef721eSBaptiste Daroussin * Delete the character to the left of the cursor
494*d0ef721eSBaptiste Daroussin * [^?]
495*d0ef721eSBaptiste Daroussin */
496*d0ef721eSBaptiste Daroussin libedit_private el_action_t
497*d0ef721eSBaptiste Daroussin /*ARGSUSED*/
em_delete_prev_char(EditLine * el,wint_t c)498*d0ef721eSBaptiste Daroussin em_delete_prev_char(EditLine *el, wint_t c __attribute__((__unused__)))
499*d0ef721eSBaptiste Daroussin {
500*d0ef721eSBaptiste Daroussin
501*d0ef721eSBaptiste Daroussin if (el->el_line.cursor <= el->el_line.buffer)
502*d0ef721eSBaptiste Daroussin return CC_ERROR;
503*d0ef721eSBaptiste Daroussin
504*d0ef721eSBaptiste Daroussin if (el->el_state.doingarg)
505*d0ef721eSBaptiste Daroussin c_delbefore(el, el->el_state.argument);
506*d0ef721eSBaptiste Daroussin else
507*d0ef721eSBaptiste Daroussin c_delbefore1(el);
508*d0ef721eSBaptiste Daroussin el->el_line.cursor -= el->el_state.argument;
509*d0ef721eSBaptiste Daroussin if (el->el_line.cursor < el->el_line.buffer)
510*d0ef721eSBaptiste Daroussin el->el_line.cursor = el->el_line.buffer;
511*d0ef721eSBaptiste Daroussin return CC_REFRESH;
512*d0ef721eSBaptiste Daroussin }
513