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