36 #if !defined(lint) && !defined(SCCSID)
38 static char sccsid[] =
"@(#)emacs.c 8.1 (Berkeley) 6/4/93";
54 em_delete_or_list(
EditLine *el, Int c)
57 if (el->el_line.cursor == el->el_line.lastchar) {
59 if (el->el_line.cursor == el->el_line.buffer) {
61 terminal_writec(el, c);
72 if (el->el_state.doingarg)
73 c_delafter(el, el->el_state.argument);
76 if (el->el_line.cursor > el->el_line.lastchar)
77 el->el_line.cursor = el->el_line.lastchar;
90 em_delete_next_word(
EditLine *el, Int c __attribute__((__unused__)))
94 if (el->el_line.cursor == el->el_line.lastchar)
97 cp = c__next_word(el->el_line.cursor, el->el_line.lastchar,
98 el->el_state.argument, ce__isword);
100 for (p = el->el_line.cursor, kp = el->el_chared.c_kill.buf; p < cp; p++)
103 el->el_chared.c_kill.last = kp;
105 c_delafter(el, (
int)(cp - el->el_line.cursor));
106 if (el->el_line.cursor > el->el_line.lastchar)
107 el->el_line.cursor = el->el_line.lastchar;
117 protected el_action_t
119 em_yank(
EditLine *el, Int c __attribute__((__unused__)))
123 if (el->el_chared.c_kill.last == el->el_chared.c_kill.buf)
126 if (el->el_line.lastchar +
127 (el->el_chared.c_kill.last - el->el_chared.c_kill.buf) >=
131 el->el_chared.c_kill.mark = el->el_line.cursor;
132 cp = el->el_line.cursor;
136 (
int)(el->el_chared.c_kill.last - el->el_chared.c_kill.buf));
138 for (kp = el->el_chared.c_kill.buf; kp < el->el_chared.c_kill.last; kp++)
142 if (el->el_state.argument == 1)
143 el->el_line.cursor = cp;
153 protected el_action_t
155 em_kill_line(
EditLine *el, Int c __attribute__((__unused__)))
159 cp = el->el_line.buffer;
160 kp = el->el_chared.c_kill.buf;
161 while (cp < el->el_line.lastchar)
163 el->el_chared.c_kill.last = kp;
165 el->el_line.lastchar = el->el_line.buffer;
166 el->el_line.cursor = el->el_line.buffer;
175 protected el_action_t
177 em_kill_region(
EditLine *el, Int c __attribute__((__unused__)))
181 if (!el->el_chared.c_kill.mark)
184 if (el->el_chared.c_kill.mark > el->el_line.cursor) {
185 cp = el->el_line.cursor;
186 kp = el->el_chared.c_kill.buf;
187 while (cp < el->el_chared.c_kill.mark)
189 el->el_chared.c_kill.last = kp;
190 c_delafter(el, (
int)(cp - el->el_line.cursor));
192 cp = el->el_chared.c_kill.mark;
193 kp = el->el_chared.c_kill.buf;
194 while (cp < el->el_line.cursor)
196 el->el_chared.c_kill.last = kp;
197 c_delbefore(el, (
int)(cp - el->el_chared.c_kill.mark));
198 el->el_line.cursor = el->el_chared.c_kill.mark;
208 protected el_action_t
210 em_copy_region(
EditLine *el, Int c __attribute__((__unused__)))
214 if (!el->el_chared.c_kill.mark)
217 if (el->el_chared.c_kill.mark > el->el_line.cursor) {
218 cp = el->el_line.cursor;
219 kp = el->el_chared.c_kill.buf;
220 while (cp < el->el_chared.c_kill.mark)
222 el->el_chared.c_kill.last = kp;
224 cp = el->el_chared.c_kill.mark;
225 kp = el->el_chared.c_kill.buf;
226 while (cp < el->el_line.cursor)
228 el->el_chared.c_kill.last = kp;
238 protected el_action_t
239 em_gosmacs_transpose(
EditLine *el, Int c)
242 if (el->el_line.cursor > &el->el_line.buffer[1]) {
244 c = el->el_line.cursor[-2];
245 el->el_line.cursor[-2] = el->el_line.cursor[-1];
246 el->el_line.cursor[-1] = c;
257 protected el_action_t
259 em_next_word(
EditLine *el, Int c __attribute__((__unused__)))
261 if (el->el_line.cursor == el->el_line.lastchar)
264 el->el_line.cursor = c__next_word(el->el_line.cursor,
265 el->el_line.lastchar,
266 el->el_state.argument,
269 if (el->el_map.type == MAP_VI)
270 if (el->el_chared.c_vcmd.action != NOP) {
282 protected el_action_t
284 em_upper_case(
EditLine *el, Int c __attribute__((__unused__)))
288 ep = c__next_word(el->el_line.cursor, el->el_line.lastchar,
289 el->el_state.argument, ce__isword);
291 for (cp = el->el_line.cursor; cp < ep; cp++)
295 el->el_line.cursor = ep;
296 if (el->el_line.cursor > el->el_line.lastchar)
297 el->el_line.cursor = el->el_line.lastchar;
306 protected el_action_t
308 em_capitol_case(
EditLine *el, Int c __attribute__((__unused__)))
312 ep = c__next_word(el->el_line.cursor, el->el_line.lastchar,
313 el->el_state.argument, ce__isword);
315 for (cp = el->el_line.cursor; cp < ep; cp++) {
323 for (; cp < ep; cp++)
327 el->el_line.cursor = ep;
328 if (el->el_line.cursor > el->el_line.lastchar)
329 el->el_line.cursor = el->el_line.lastchar;
338 protected el_action_t
340 em_lower_case(
EditLine *el, Int c __attribute__((__unused__)))
344 ep = c__next_word(el->el_line.cursor, el->el_line.lastchar,
345 el->el_state.argument, ce__isword);
347 for (cp = el->el_line.cursor; cp < ep; cp++)
351 el->el_line.cursor = ep;
352 if (el->el_line.cursor > el->el_line.lastchar)
353 el->el_line.cursor = el->el_line.lastchar;
362 protected el_action_t
364 em_set_mark(
EditLine *el, Int c __attribute__((__unused__)))
367 el->el_chared.c_kill.mark = el->el_line.cursor;
376 protected el_action_t
378 em_exchange_mark(
EditLine *el, Int c __attribute__((__unused__)))
382 cp = el->el_line.cursor;
383 el->el_line.cursor = el->el_chared.c_kill.mark;
384 el->el_chared.c_kill.mark = cp;
393 protected el_action_t
395 em_universal_argument(
EditLine *el, Int c __attribute__((__unused__)))
398 if (el->el_state.argument > 1000000)
400 el->el_state.doingarg = 1;
401 el->el_state.argument *= 4;
410 protected el_action_t
412 em_meta_next(
EditLine *el, Int c __attribute__((__unused__)))
415 el->el_state.metanext = 1;
423 protected el_action_t
425 em_toggle_overwrite(
EditLine *el, Int c __attribute__((__unused__)))
428 el->el_state.inputmode = (el->el_state.inputmode == MODE_INSERT) ?
429 MODE_REPLACE : MODE_INSERT;
437 protected el_action_t
439 em_copy_prev_word(
EditLine *el, Int c __attribute__((__unused__)))
441 Char *cp, *oldc, *dp;
443 if (el->el_line.cursor == el->el_line.buffer)
446 oldc = el->el_line.cursor;
448 cp = c__prev_word(el->el_line.cursor, el->el_line.buffer,
449 el->el_state.argument, ce__isword);
451 c_insert(el, (
int)(oldc - cp));
452 for (dp = oldc; cp < oldc && dp < el->el_line.lastchar; cp++)
455 el->el_line.cursor = dp;
464 protected el_action_t
466 em_inc_search_next(
EditLine *el, Int c __attribute__((__unused__)))
469 el->el_search.patlen = 0;
470 return ce_inc_search(el, ED_SEARCH_NEXT_HISTORY);
477 protected el_action_t
479 em_inc_search_prev(
EditLine *el, Int c __attribute__((__unused__)))
482 el->el_search.patlen = 0;
483 return ce_inc_search(el, ED_SEARCH_PREV_HISTORY);
491 protected el_action_t
493 em_delete_prev_char(
EditLine *el, Int c __attribute__((__unused__)))
496 if (el->el_line.cursor <= el->el_line.buffer)
499 if (el->el_state.doingarg)
500 c_delbefore(el, el->el_state.argument);
503 el->el_line.cursor -= el->el_state.argument;
504 if (el->el_line.cursor < el->el_line.buffer)
505 el->el_line.cursor = el->el_line.buffer;