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