emacs.c File Reference

#include "config.h"
#include "el.h"

Include dependency graph for emacs.c:

Go to the source code of this file.

Functions

 __RCSID ("$NetBSD: emacs.c,v 1.10 2002/03/18 16:00:52 christos Exp $")
protected el_action_t em_capitol_case (EditLine *el, int c)
protected el_action_t em_copy_prev_word (EditLine *el, int c)
protected el_action_t em_copy_region (EditLine *el, int c)
protected el_action_t em_delete_next_word (EditLine *el, int c)
protected el_action_t em_delete_or_list (EditLine *el, int c)
protected el_action_t em_exchange_mark (EditLine *el, int c)
protected el_action_t em_gosmacs_traspose (EditLine *el, int c)
protected el_action_t em_inc_search_next (EditLine *el, int c)
protected el_action_t em_inc_search_prev (EditLine *el, int c)
protected el_action_t em_kill_line (EditLine *el, int c)
protected el_action_t em_kill_region (EditLine *el, int c)
protected el_action_t em_lower_case (EditLine *el, int c)
protected el_action_t em_meta_next (EditLine *el, int c)
protected el_action_t em_next_word (EditLine *el, int c)
protected el_action_t em_set_mark (EditLine *el, int c)
protected el_action_t em_toggle_overwrite (EditLine *el, int c)
protected el_action_t em_universal_argument (EditLine *el, int c)
protected el_action_t em_upper_case (EditLine *el, int c)
protected el_action_t em_yank (EditLine *el, int c)


Function Documentation

__RCSID ( "$NetBSD: emacs.  c,
v 1.10 2002/03/18 16:00:52 christos Exp $"   
)

protected el_action_t em_capitol_case ( EditLine el,
int  c 
)

Definition at line 312 of file emacs.c.

References el_state_t::argument, c__next_word(), CC_REFRESH, ce__isword(), el_line_t::cursor, editline::el_line, editline::el_state, and el_line_t::lastchar.

00313 {
00314    char *cp, *ep;
00315 
00316    ep = c__next_word(el->el_line.cursor, el->el_line.lastchar,
00317        el->el_state.argument, ce__isword);
00318 
00319    for (cp = el->el_line.cursor; cp < ep; cp++) {
00320       if (isalpha((unsigned char) *cp)) {
00321          if (islower((unsigned char) *cp))
00322             *cp = toupper(*cp);
00323          cp++;
00324          break;
00325       }
00326    }
00327    for (; cp < ep; cp++)
00328       if (isupper((unsigned char) *cp))
00329          *cp = tolower(*cp);
00330 
00331    el->el_line.cursor = ep;
00332    if (el->el_line.cursor > el->el_line.lastchar)
00333       el->el_line.cursor = el->el_line.lastchar;
00334    return (CC_REFRESH);
00335 }

protected el_action_t em_copy_prev_word ( EditLine el,
int  c 
)

Definition at line 443 of file emacs.c.

References el_state_t::argument, el_line_t::buffer, c__prev_word(), c_insert(), CC_ERROR, CC_REFRESH, ce__isword(), el_line_t::cursor, editline::el_line, editline::el_state, and el_line_t::lastchar.

00444 {
00445    char *cp, *oldc, *dp;
00446 
00447    if (el->el_line.cursor == el->el_line.buffer)
00448       return (CC_ERROR);
00449 
00450    oldc = el->el_line.cursor;
00451    /* does a bounds check */
00452    cp = c__prev_word(el->el_line.cursor, el->el_line.buffer,
00453        el->el_state.argument, ce__isword);
00454 
00455    c_insert(el, oldc - cp);
00456    for (dp = oldc; cp < oldc && dp < el->el_line.lastchar; cp++)
00457       *dp++ = *cp;
00458 
00459    el->el_line.cursor = dp;/* put cursor at end */
00460 
00461    return (CC_REFRESH);
00462 }

protected el_action_t em_copy_region ( EditLine el,
int  c 
)

Definition at line 214 of file emacs.c.

References c_kill_t::buf, el_chared_t::c_kill, CC_ERROR, CC_NORM, lineinfo::cursor, el_line_t::cursor, editline::el_chared, el_line(), editline::el_line, c_kill_t::last, and c_kill_t::mark.

00215 {
00216    char *kp, *cp;
00217 
00218    if (el->el_chared.c_kill.mark)
00219       return (CC_ERROR);
00220 
00221    if (el->el_chared.c_kill.mark > el->el_line.cursor) {
00222       cp = el->el_line.cursor;
00223       kp = el->el_chared.c_kill.buf;
00224       while (cp < el->el_chared.c_kill.mark)
00225          *kp++ = *cp++; /* copy it */
00226       el->el_chared.c_kill.last = kp;
00227    } else {
00228       cp = el->el_chared.c_kill.mark;
00229       kp = el->el_chared.c_kill.buf;
00230       while (cp < el->el_line.cursor)
00231          *kp++ = *cp++; /* copy it */
00232       el->el_chared.c_kill.last = kp;
00233    }
00234    return (CC_NORM);
00235 }

protected el_action_t em_delete_next_word ( EditLine el,
int  c 
)

Definition at line 93 of file emacs.c.

References el_state_t::argument, c_kill_t::buf, c__next_word(), c_delafter(), el_chared_t::c_kill, CC_ERROR, CC_REFRESH, ce__isword(), el_line_t::cursor, editline::el_chared, editline::el_line, editline::el_state, c_kill_t::last, and el_line_t::lastchar.

00094 {
00095    char *cp, *p, *kp;
00096 
00097    if (el->el_line.cursor == el->el_line.lastchar)
00098       return (CC_ERROR);
00099 
00100    cp = c__next_word(el->el_line.cursor, el->el_line.lastchar,
00101        el->el_state.argument, ce__isword);
00102 
00103    for (p = el->el_line.cursor, kp = el->el_chared.c_kill.buf; p < cp; p++)
00104             /* save the text */
00105       *kp++ = *p;
00106    el->el_chared.c_kill.last = kp;
00107 
00108    c_delafter(el, cp - el->el_line.cursor);  /* delete after dot */
00109    if (el->el_line.cursor > el->el_line.lastchar)
00110       el->el_line.cursor = el->el_line.lastchar;
00111             /* bounds check */
00112    return (CC_REFRESH);
00113 }

protected el_action_t em_delete_or_list ( EditLine el,
int  c 
)

Definition at line 59 of file emacs.c.

References el_state_t::argument, el_line_t::buffer, c_delafter(), CC_EOF, CC_ERROR, CC_REFRESH, el_line_t::cursor, editline::el_line, editline::el_state, el_line_t::lastchar, STReof, term__flush(), term_beep(), and term_overwrite().

00060 {
00061 
00062    if (el->el_line.cursor == el->el_line.lastchar) {
00063                /* if I'm at the end */
00064       if (el->el_line.cursor == el->el_line.buffer) {
00065                /* and the beginning */
00066          term_overwrite(el, STReof, 4);   /* then do a EOF */
00067          term__flush();
00068          return (CC_EOF);
00069       } else {
00070          /*
00071           * Here we could list completions, but it is an
00072           * error right now
00073           */
00074          term_beep(el);
00075          return (CC_ERROR);
00076       }
00077    } else {
00078       c_delafter(el, el->el_state.argument); /* delete after dot */
00079       if (el->el_line.cursor > el->el_line.lastchar)
00080          el->el_line.cursor = el->el_line.lastchar;
00081             /* bounds check */
00082       return (CC_REFRESH);
00083    }
00084 }

protected el_action_t em_exchange_mark ( EditLine el,
int  c 
)

Definition at line 382 of file emacs.c.

References el_chared_t::c_kill, CC_CURSOR, el_line_t::cursor, editline::el_chared, editline::el_line, and c_kill_t::mark.

00383 {
00384    char *cp;
00385 
00386    cp = el->el_line.cursor;
00387    el->el_line.cursor = el->el_chared.c_kill.mark;
00388    el->el_chared.c_kill.mark = cp;
00389    return (CC_CURSOR);
00390 }

protected el_action_t em_gosmacs_traspose ( EditLine el,
int  c 
)

Definition at line 243 of file emacs.c.

References el_line_t::buffer, CC_ERROR, CC_REFRESH, el_line_t::cursor, and editline::el_line.

00244 {
00245 
00246    if (el->el_line.cursor > &el->el_line.buffer[1]) {
00247       /* must have at least two chars entered */
00248       c = el->el_line.cursor[-2];
00249       el->el_line.cursor[-2] = el->el_line.cursor[-1];
00250       el->el_line.cursor[-1] = c;
00251       return (CC_REFRESH);
00252    } else
00253       return (CC_ERROR);
00254 }

protected el_action_t em_inc_search_next ( EditLine el,
int  c 
)

Definition at line 470 of file emacs.c.

References ce_inc_search(), editline::el_search, and el_search_t::patlen.

00471 {
00472 
00473    el->el_search.patlen = 0;
00474    return (ce_inc_search(el, ED_SEARCH_NEXT_HISTORY));
00475 }

protected el_action_t em_inc_search_prev ( EditLine el,
int  c 
)

Definition at line 483 of file emacs.c.

References ce_inc_search(), editline::el_search, and el_search_t::patlen.

00484 {
00485 
00486    el->el_search.patlen = 0;
00487    return (ce_inc_search(el, ED_SEARCH_PREV_HISTORY));
00488 }

protected el_action_t em_kill_line ( EditLine el,
int  c 
)

Definition at line 159 of file emacs.c.

References c_kill_t::buf, el_line_t::buffer, el_chared_t::c_kill, CC_REFRESH, el_line_t::cursor, editline::el_chared, el_line(), editline::el_line, c_kill_t::last, el_line_t::lastchar, and lineinfo::lastchar.

Referenced by vi_substitute_line().

00160 {
00161    char *kp, *cp;
00162 
00163    cp = el->el_line.buffer;
00164    kp = el->el_chared.c_kill.buf;
00165    while (cp < el->el_line.lastchar)
00166       *kp++ = *cp++; /* copy it */
00167    el->el_chared.c_kill.last = kp;
00168             /* zap! -- delete all of it */
00169    el->el_line.lastchar = el->el_line.buffer;
00170    el->el_line.cursor = el->el_line.buffer;
00171    return (CC_REFRESH);
00172 }

protected el_action_t em_kill_region ( EditLine el,
int  c 
)

Definition at line 181 of file emacs.c.

References c_kill_t::buf, c_delafter(), c_delbefore(), el_chared_t::c_kill, CC_ERROR, CC_REFRESH, lineinfo::cursor, el_line_t::cursor, editline::el_chared, el_line(), editline::el_line, c_kill_t::last, and c_kill_t::mark.

00182 {
00183    char *kp, *cp;
00184 
00185    if (!el->el_chared.c_kill.mark)
00186       return (CC_ERROR);
00187 
00188    if (el->el_chared.c_kill.mark > el->el_line.cursor) {
00189       cp = el->el_line.cursor;
00190       kp = el->el_chared.c_kill.buf;
00191       while (cp < el->el_chared.c_kill.mark)
00192          *kp++ = *cp++; /* copy it */
00193       el->el_chared.c_kill.last = kp;
00194       c_delafter(el, cp - el->el_line.cursor);
00195    } else {    /* mark is before cursor */
00196       cp = el->el_chared.c_kill.mark;
00197       kp = el->el_chared.c_kill.buf;
00198       while (cp < el->el_line.cursor)
00199          *kp++ = *cp++; /* copy it */
00200       el->el_chared.c_kill.last = kp;
00201       c_delbefore(el, cp - el->el_chared.c_kill.mark);
00202       el->el_line.cursor = el->el_chared.c_kill.mark;
00203    }
00204    return (CC_REFRESH);
00205 }

protected el_action_t em_lower_case ( EditLine el,
int  c 
)

Definition at line 344 of file emacs.c.

References el_state_t::argument, c__next_word(), CC_REFRESH, ce__isword(), el_line_t::cursor, editline::el_line, editline::el_state, and el_line_t::lastchar.

00345 {
00346    char *cp, *ep;
00347 
00348    ep = c__next_word(el->el_line.cursor, el->el_line.lastchar,
00349        el->el_state.argument, ce__isword);
00350 
00351    for (cp = el->el_line.cursor; cp < ep; cp++)
00352       if (isupper((unsigned char) *cp))
00353          *cp = tolower(*cp);
00354 
00355    el->el_line.cursor = ep;
00356    if (el->el_line.cursor > el->el_line.lastchar)
00357       el->el_line.cursor = el->el_line.lastchar;
00358    return (CC_REFRESH);
00359 }

protected el_action_t em_meta_next ( EditLine el,
int  c 
)

Definition at line 416 of file emacs.c.

References CC_ARGHACK, editline::el_state, and el_state_t::metanext.

00417 {
00418 
00419    el->el_state.metanext = 1;
00420    return (CC_ARGHACK);
00421 }

protected el_action_t em_next_word ( EditLine el,
int  c 
)

Definition at line 263 of file emacs.c.

References c_vcmd_t::action, el_state_t::argument, c__next_word(), el_chared_t::c_vcmd, CC_CURSOR, CC_ERROR, CC_REFRESH, ce__isword(), el_line_t::cursor, cv_delfini(), DELETE, editline::el_chared, editline::el_line, editline::el_map, editline::el_state, el_line_t::lastchar, MAP_VI, and el_map_t::type.

00264 {
00265    if (el->el_line.cursor == el->el_line.lastchar)
00266       return (CC_ERROR);
00267 
00268    el->el_line.cursor = c__next_word(el->el_line.cursor,
00269        el->el_line.lastchar,
00270        el->el_state.argument,
00271        ce__isword);
00272 
00273    if (el->el_map.type == MAP_VI)
00274       if (el->el_chared.c_vcmd.action & DELETE) {
00275          cv_delfini(el);
00276          return (CC_REFRESH);
00277       }
00278    return (CC_CURSOR);
00279 }

protected el_action_t em_set_mark ( EditLine el,
int  c 
)

Definition at line 368 of file emacs.c.

References el_chared_t::c_kill, CC_NORM, el_line_t::cursor, editline::el_chared, editline::el_line, and c_kill_t::mark.

00369 {
00370 
00371    el->el_chared.c_kill.mark = el->el_line.cursor;
00372    return (CC_NORM);
00373 }

protected el_action_t em_toggle_overwrite ( EditLine el,
int  c 
)

Definition at line 429 of file emacs.c.

References CC_NORM, editline::el_state, el_state_t::inputmode, MODE_INSERT, and MODE_REPLACE.

00430 {
00431 
00432    el->el_state.inputmode = (el->el_state.inputmode == MODE_INSERT) ?
00433        MODE_REPLACE : MODE_INSERT;
00434    return (CC_NORM);
00435 }

protected el_action_t em_universal_argument ( EditLine el,
int  c 
)

Definition at line 399 of file emacs.c.

References el_state_t::argument, CC_ARGHACK, CC_ERROR, el_state_t::doingarg, and editline::el_state.

00400 {           /* multiply current argument by 4 */
00401 
00402    if (el->el_state.argument > 1000000)
00403       return (CC_ERROR);
00404    el->el_state.doingarg = 1;
00405    el->el_state.argument *= 4;
00406    return (CC_ARGHACK);
00407 }

protected el_action_t em_upper_case ( EditLine el,
int  c 
)

Definition at line 288 of file emacs.c.

References el_state_t::argument, c__next_word(), CC_REFRESH, ce__isword(), el_line_t::cursor, editline::el_line, editline::el_state, and el_line_t::lastchar.

00289 {
00290    char *cp, *ep;
00291 
00292    ep = c__next_word(el->el_line.cursor, el->el_line.lastchar,
00293        el->el_state.argument, ce__isword);
00294 
00295    for (cp = el->el_line.cursor; cp < ep; cp++)
00296       if (islower((unsigned char) *cp))
00297          *cp = toupper(*cp);
00298 
00299    el->el_line.cursor = ep;
00300    if (el->el_line.cursor > el->el_line.lastchar)
00301       el->el_line.cursor = el->el_line.lastchar;
00302    return (CC_REFRESH);
00303 }

protected el_action_t em_yank ( EditLine el,
int  c 
)

Definition at line 122 of file emacs.c.

References el_state_t::argument, c_kill_t::buf, c_insert(), el_chared_t::c_kill, CC_ERROR, CC_REFRESH, ch_enlargebufs(), el_line_t::cursor, editline::el_chared, editline::el_line, editline::el_state, c_kill_t::last, el_line_t::lastchar, el_line_t::limit, and c_kill_t::mark.

00123 {
00124    char *kp, *cp;
00125 
00126    if (el->el_chared.c_kill.last == el->el_chared.c_kill.buf) {
00127       if (!ch_enlargebufs(el, 1))
00128          return (CC_ERROR);
00129    }
00130 
00131    if (el->el_line.lastchar +
00132        (el->el_chared.c_kill.last - el->el_chared.c_kill.buf) >=
00133        el->el_line.limit)
00134       return (CC_ERROR);
00135 
00136    el->el_chared.c_kill.mark = el->el_line.cursor;
00137    cp = el->el_line.cursor;
00138 
00139    /* open the space, */
00140    c_insert(el, el->el_chared.c_kill.last - el->el_chared.c_kill.buf);
00141    /* copy the chars */
00142    for (kp = el->el_chared.c_kill.buf; kp < el->el_chared.c_kill.last; kp++)
00143       *cp++ = *kp;
00144 
00145    /* if an arg, cursor at beginning else cursor at end */
00146    if (el->el_state.argument == 1)
00147       el->el_line.cursor = cp;
00148 
00149    return (CC_REFRESH);
00150 }


Generated on Thu Apr 16 06:30:50 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6