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