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