From c4fab606d1b88605f1e479ec6564c6aac7e3a208 Mon Sep 17 00:00:00 2001 From: Renaud Fivet Date: Fri, 30 Jul 2021 16:24:52 +0800 Subject: [PATCH] Revise keycode encoding. Gather APROP and CFENCE conditional code. --- bind.c | 49 +++++------------- bind.h | 20 +++----- defines.h | 9 +--- estruct.h | 1 - execute.c | 96 ++++++++++++++++++++++++++++++++-- execute.h | 21 ++++++-- input.c | 38 +++++++------- names.c | 150 +++++++++++++++++++++++++++++------------------------- names.h | 10 ++++ random.c | 90 -------------------------------- random.h | 1 - 11 files changed, 242 insertions(+), 243 deletions(-) diff --git a/bind.c b/bind.c index 1821861..7a479b4 100644 --- a/bind.c +++ b/bind.c @@ -29,10 +29,7 @@ #include "window.h" -#if APROP static int buildlist( char *mstring) ; -#endif - static void cmdstr( int c, char *seq) ; static unsigned int getckey( int mflag) ; static unsigned int stock( char *keyname) ; @@ -208,7 +205,6 @@ BINDABLE( unbindkey) { return TRUE ; } -#if APROP /* * does source include sub? * @@ -235,23 +231,20 @@ static boolean strinc( const char *source, const char *sub) { return FALSE ; } -#endif /* describe bindings * bring up a fake buffer and list the key bindings * into it with view mode */ -int desbind( int f, int n) { -#if APROP +BINDABLE( desbind) { return buildlist( "") ; } /* Apropos (List functions that match a substring) */ -int apro( int f, int n) { +BINDABLE( apro) { char *mstring ; /* string to match cmd names to */ - int status ; /* status return */ - status = newmlarg( &mstring, "apropos: ", 0) ; + int status = newmlarg( &mstring, "apropos: ", 0) ; if( status == TRUE) { status = buildlist( mstring) ; free( mstring) ; @@ -267,7 +260,6 @@ int apro( int f, int n) { * char *mstring; match string if a partial list, "" matches all */ static int buildlist( char *mstring) { -#endif struct window *wp; /* scanning pointer to windows */ kbind_p ktp; /* pointer into the command table */ nbind_p nptr;/* pointer into the name binding table */ @@ -275,7 +267,8 @@ static int buildlist( char *mstring) { char outseq[80]; /* output buffer for keystroke sequence */ /* split the current window to make room for the binding list */ - if (splitwind(FALSE, 1) == FALSE) + if( wheadp->w_wndp == NULL /* One window */ + && splitwind( FALSE, 1) == FALSE) /* Split it */ return FALSE; /* and get a buffer for it */ @@ -288,7 +281,7 @@ static int buildlist( char *mstring) { /* let us know this is in progress */ mlwrite("(Building binding list)"); - /* disconect the current buffer */ + /* disconnect the current buffer */ if (--curbp->b_nwnd == 0) { /* Last use. */ curbp->b_dotp = curwp->w_dotp; curbp->b_doto = curwp->w_doto; @@ -313,12 +306,11 @@ static int buildlist( char *mstring) { for( nptr = names ; nptr->n_func != NULL ; nptr++) { int cpos ; /* current position to use in outseq */ -#if APROP /* if we are executing an apropos command..... */ - /* and current string doesn't include the search string */ + /* and current string doesn't include the search string */ if( *mstring && strinc( bind_name( nptr), mstring) == FALSE) continue ; -#endif + /* add in the command name */ mystrscpy( outseq, bind_name( nptr), sizeof outseq) ; cpos = strlen(outseq); @@ -424,7 +416,7 @@ static void cmdstr( int c, char *seq) { /* apply ^X sequence if needed */ if (c & CTLX) { - if( ctlxc & CONTROL) + if( ctlxc & CTRL) *ptr++ = '^' ; *ptr++ = ctlxc & 0x1FFFFF ; @@ -437,7 +429,7 @@ static void cmdstr( int c, char *seq) { } /* apply control sequence if needed */ - if (c & CONTROL) { + if (c & CTRL) { *ptr++ = '^'; } @@ -448,24 +440,9 @@ static void cmdstr( int c, char *seq) { *ptr = 0; /* terminate the string */ } -/* - * This function looks a key binding up in the binding table - * - * int c; key to find what is bound to it - */ -kbind_p getkeybind( unsigned c) { - kbind_p ktp ; - - for( ktp = keytab ; ktp->k_code != 0 ; ktp++) - if (ktp->k_code == c) - break ; - - return ktp ; -} - static const char *getfname( unsigned keycode, char *failmsg) { /* takes a key code and gets the name of the function bound to it */ - kbind_p kbp = getkeybind( keycode) ; + kbind_p kbp = getkeybinding( keycode) ; if( kbp->k_code == 0) return failmsg ; @@ -506,11 +483,11 @@ static unsigned int stock( char *keyname) { /* a control char? */ if (*keyname == '^' && *(keyname + 1) != 0) { - c |= CONTROL; + c |= CTRL; ++keyname; } if (*keyname < 32) { - c |= CONTROL; + c |= CTRL; *keyname += 'A'; } diff --git a/bind.h b/bind.h index bacba1e..dcb1ad6 100644 --- a/bind.h +++ b/bind.h @@ -3,23 +3,17 @@ #include "names.h" -#define APROP 1 /* Add code for Apropos command */ - -/* uEMACS functions */ -#if APROP -int apro( int f, int n) ; -#endif - -int help( int f, int n) ; -int deskey( int f, int n) ; -int bindtokey( int f, int n) ; -int unbindkey( int f, int n) ; -int desbind( int f, int n) ; +/* Bindable uEMACS functions */ +BINDABLE( apro) ; +BINDABLE( bindtokey) ; +BINDABLE( desbind) ; +BINDABLE( deskey) ; +BINDABLE( help) ; +BINDABLE( unbindkey) ; int startup( const char *fname) ; /* find a key to function association in the key to function mapping table */ -kbind_p getkeybind( unsigned keycode) ; /* by key code */ const char *transbind( char *skey) ; /* by string representation of key */ #endif diff --git a/defines.h b/defines.h index b6074ed..d62ac3a 100644 --- a/defines.h +++ b/defines.h @@ -5,7 +5,7 @@ /* Must define one of - USG | BSD + USG | BSD */ #define USG 1 @@ -13,12 +13,7 @@ #define SCROLLCODE 1 /* scrolling code P.K. */ #define ENVFUNC 1 -#define NSTRING 128 /* # of bytes, string buffers */ - -#define CONTROL 0x01000000 /* Control flag, or'ed in */ -#define META 0x02000000 /* Meta flag, or'ed in */ -#define CTLX 0x04000000 /* ^X flag, or'ed in */ -#define SPEC 0x08000000 /* special key (function keys) */ +#define NSTRING 128 /* # of bytes, string buffers */ #endif diff --git a/estruct.h b/estruct.h index 26abded..22d1e7b 100644 --- a/estruct.h +++ b/estruct.h @@ -93,7 +93,6 @@ /* Configuration options */ -#define CFENCE 1 /* fench matching in CMODE */ #define VISMAC 0 /* update display during keyboard macros */ #ifndef AUTOCONF diff --git a/execute.c b/execute.c index f0738a6..d96bcf3 100644 --- a/execute.c +++ b/execute.c @@ -8,7 +8,6 @@ #include #include "estruct.h" -#include "bind.h" #include "random.h" #include "display.h" #include "file.h" @@ -203,17 +202,106 @@ static void fmatch( int ch) { #endif +#if CFENCE +/* + * the cursor is moved to a matching fence + * + * int f, n; not used + */ +BINDABLE( getfence) { + struct line *oldlp; /* original line pointer */ + int oldoff; /* and offset */ + int sdir; /* direction of search (1/-1) */ + int count; /* current fence level count */ + char ch; /* fence type to match against */ + char ofence; /* open fence */ + char c; /* current character in scan */ + + /* save the original cursor position */ + oldlp = curwp->w_dotp; + oldoff = curwp->w_doto; + + /* get the current character */ + if (oldoff == llength(oldlp)) + ch = '\n'; + else + ch = lgetc(oldlp, oldoff); + + /* setup proper matching fence */ + switch (ch) { + case '(': + ofence = ')'; + sdir = FORWARD; + break; + case '{': + ofence = '}'; + sdir = FORWARD; + break; + case '[': + ofence = ']'; + sdir = FORWARD; + break; + case ')': + ofence = '('; + sdir = REVERSE; + break; + case '}': + ofence = '{'; + sdir = REVERSE; + break; + case ']': + ofence = '['; + sdir = REVERSE; + break; + default: + TTbeep(); + return FALSE; + } + + /* scan until we find a match, or reach the end of file */ + count = 1 ; + do { + if( boundry( curwp->w_dotp, curwp->w_doto, sdir)) { + /* at buffer limit, no match to be found */ + /* restore the current position */ + curwp->w_dotp = oldlp ; + curwp->w_doto = oldoff ; + TTbeep() ; + return FALSE ; + } + + if( sdir == FORWARD) + forwchar( FALSE, 1) ; + else + backchar( FALSE, 1) ; + + /* if no eol */ + if( curwp->w_doto != llength(curwp->w_dotp)) { + c = curwbyte() ; + if( c == ch) + ++count ; + else if( c == ofence) + --count ; + } + } while( count > 0) ; + + /* we have a match, move the sucker */ + curwp->w_flag |= WFMOVE ; + return TRUE ; +} +#endif + /* * This is the general command execution routine. It handles the fake binding * of all the keys to "self-insert". It also clears out the "thisflag" word, * and arranges to move it to the "lastflag", so that the next command can * look at it. Return the status of command. */ -int execute( int c, int f, int n) { +int execute( unsigned c, int f, int n) { int status ; /* if the keystroke is a bound function...do it */ - kbind_p ktp = getkeybind( c) ; + kbind_p ktp = getkeybinding( c) ; if( ktp->k_code != 0) { thisflag = 0 ; assert( ktp->k_nbp != NULL) ; @@ -342,7 +430,7 @@ void kbd_loop( void) { fnp_t execfunc ; if( c == newc - && (ktp = getkeybind( c))->k_code == c + && (ktp = getkeybinding( c))->k_code == c && (execfunc = ktp->k_nbp->k_func) != insert_newline && execfunc != insert_tab) newc = getcmd() ; diff --git a/execute.h b/execute.h index 35fa658..9949149 100644 --- a/execute.h +++ b/execute.h @@ -1,5 +1,20 @@ -extern int gasave ; /* global ASAVE size */ -extern int gacount ; /* count until next ASAVE */ +/* execute.h -- */ -int execute( int c, int f, int n) ; +#define CFENCE 1 /* fence matching in CMODE */ + + +#include "names.h" /* key code */ + + +extern int gasave ; /* global ASAVE size */ +extern int gacount ; /* count until next ASAVE */ + + +int execute( unsigned keycode, int f, int n) ; void kbd_loop( void) ; + +#if CFENCE +BINDABLE( getfence) ; +#endif + +/* end of execute.h */ diff --git a/input.c b/input.c index a095cc2..e67c197 100644 --- a/input.c +++ b/input.c @@ -41,12 +41,12 @@ kbdstate kbdmode = STOP ; /* current keyboard macro mode */ int lastkey = 0 ; /* last keystoke */ int kbdrep = 0 ; /* number of repetitions */ -int metac = CONTROL | '[' ; /* current meta character */ -int ctlxc = CONTROL | 'X' ; /* current control X prefix char */ -int reptc = CONTROL | 'U' ; /* current universal repeat char */ -int abortc = CONTROL | 'G' ; /* current abort command char */ +int metac = CTRL | '[' ; /* current meta character */ +int ctlxc = CTRL | 'X' ; /* current control X prefix char */ +int reptc = CTRL | 'U' ; /* current universal repeat char */ +int abortc = CTRL | 'G' ; /* current abort command char */ -const int nlc = CONTROL | 'J' ; /* end of input char */ +const int nlc = CTRL | 'J' ; /* end of input char */ void ue_system( const char *cmd) { @@ -145,11 +145,11 @@ int newmlargt( char **outbufref, const char *prompt, int size) { /* * ectoc: * expanded character to character - * collapse the CONTROL and SPEC flags back into an ascii code + * collapse the CTRL and SPEC flags back into an ascii code */ int ectoc( int c) { - if( c & CONTROL) - c ^= CONTROL | 0x40 ; + if( c & CTRL) + c ^= CTRL | 0x40 ; if( c & SPEC) c &= 255 ; @@ -325,7 +325,7 @@ int tgetc(void) } /* GET1KEY: Get one keystroke. The only prefixs legal here are the SPEC - and CONTROL prefixes. */ + and CTRL prefixes. */ int get1key( void) { int c ; @@ -333,7 +333,7 @@ int get1key( void) { c = tgetc(); if( (c >= 0x00 && c <= 0x1F) || c == 0x7F) /* C0 control -> C- */ - c ^= CONTROL | 0x40 ; + c ^= CTRL | 0x40 ; return c ; } @@ -377,7 +377,7 @@ int getcmd(void) if (c == 128+27) /* CSI */ goto handle_CSI; /* process META prefix */ - if (c == (CONTROL | '[')) { + if (c == (CTRL | '[')) { c = get1key(); #if VT220 if (c == '[' || c == 'O') { /* CSI P.K. */ @@ -416,7 +416,7 @@ handle_CSI: } #endif #if VT220 - if (c == (CONTROL | '[')) { + if (c == (CTRL | '[')) { cmask = META; goto proc_metac; } @@ -424,14 +424,14 @@ handle_CSI: if( islower( c)) /* Force to upper */ c = flipcase( c) ; else if( c >= 0x00 && c <= 0x1F) /* control key */ - c = CONTROL | (c + '@'); + c = CTRL | (c + '@'); return META | c; } #if PKCODE else if (c == metac) { c = get1key(); #if VT220 - if (c == (CONTROL | '[')) { + if (c == (CTRL | '[')) { cmask = META; goto proc_metac; } @@ -439,7 +439,7 @@ handle_CSI: if( islower( c)) /* Force to upper */ c = flipcase( c) ; else if( c >= 0x00 && c <= 0x1F) /* control key */ - c = CONTROL | (c + '@'); + c = CTRL | (c + '@'); return META | c; } #endif @@ -452,7 +452,7 @@ handle_CSI: if (c == ctlxc) { c = get1key(); #if VT220 - if (c == (CONTROL | '[')) { + if (c == (CTRL | '[')) { cmask = CTLX; goto proc_metac; } @@ -460,7 +460,7 @@ handle_CSI: if (c >= 'a' && c <= 'z') /* Force to upper */ c -= 0x20; if (c >= 0x00 && c <= 0x1F) /* control key */ - c = CONTROL | (c + '@'); + c = CTRL | (c + '@'); return CTLX | c; } @@ -554,8 +554,8 @@ int getstring( const char *prompt, char *buf, int nbuf, int eolchar) } /* If it is a , change it to a */ - if( c == (CONTROL | 'M')) - c = CONTROL | 0x40 | '\n' ; + if( c == (CTRL | 'M')) + c = CTRL | 0x40 | '\n' ; if( c == eolchar) { /* if they hit the line terminator, wrap it up */ diff --git a/names.c b/names.c index c6b93e2..13044eb 100644 --- a/names.c +++ b/names.c @@ -19,6 +19,7 @@ #include "display.h" #include "eval.h" #include "exec.h" +#include "execute.h" #include "file.h" #include "isearch.h" #include "line.h" @@ -31,58 +32,54 @@ #include "word.h" -#define CTL_ CONTROL - const name_bind names[] = { - {" abort-command", ctrlg, CTL_ | 'G'} , + {" abort-command", ctrlg, CTRL | 'G'} , {" add-global-mode", setgmode, META | 'M'} , {" add-mode", setemode, CTLX | 'M'} , -#if APROP {" apropos", apro, META | 'A'} , -#endif - {" backward-character", (fnp_t) backchar, CTL_ | 'B'} , + {" backward-character", (fnp_t) backchar, CTRL | 'B'} , {" begin-macro", ctlxlp, CTLX | '('} , {" beginning-of-file", (fnp_t) gotobob, META | '<'} , - {" beginning-of-line", (fnp_t) gotobol, CTL_ | 'A'} , + {" beginning-of-line", (fnp_t) gotobol, CTRL | 'A'} , {" bind-to-key", bindtokey, META | 'K'} , {" buffer-position", showcpos, CTLX | '='} , - {"!case-region-lower", lowerregion, CTLX | CTL_ | 'L'} , - {"!case-region-upper", upperregion, CTLX | CTL_ | 'U'} , + {"!case-region-lower", lowerregion, CTLX | CTRL | 'L'} , + {"!case-region-upper", upperregion, CTLX | CTRL | 'U'} , {"!case-word-capitalize", capword, META | 'C'} , {"!case-word-lower", lowerword, META | 'L'} , {"!case-word-upper", upperword, META | 'U'} , {" change-file-name", filename, CTLX | 'N'} , - {" change-screen-size", newsize, META | CTL_ | 'D'} , /* M^S */ - {" change-screen-width", newwidth, META | CTL_ | 'T'} , - {" clear-and-redraw", redraw, CTL_ | 'L'} , + {" change-screen-size", newsize, META | CTRL | 'D'} , /* M^S */ + {" change-screen-width", newwidth, META | CTRL | 'T'} , + {" clear-and-redraw", redraw, CTRL | 'L'} , {" clear-message-line", clrmes, 0} , {" copy-region", copyregion, META | 'W'} , #if WORDPRO - {" count-words", wordcount, META | CTL_ | 'C'} , + {" count-words", wordcount, META | CTRL | 'C'} , #endif - {" ctlx-prefix", cex, CTL_ | 'X'} , - {"!delete-blank-lines", deblank, CTLX | CTL_ | 'O'} , + {" ctlx-prefix", cex, CTRL | 'X'} , + {"!delete-blank-lines", deblank, CTLX | CTRL | 'O'} , {" delete-buffer", killbuffer, CTLX | 'K'} , - {" delete-global-mode", delgmode, META | CTL_ | 'M'} , - {" delete-mode", delmode, CTLX | CTL_ | 'M'} , - {"!delete-next-character", forwdel, CTL_ | 'D'} , + {" delete-global-mode", delgmode, META | CTRL | 'M'} , + {" delete-mode", delmode, CTLX | CTRL | 'M'} , + {"!delete-next-character", forwdel, CTRL | 'D'} , {"!delete-next-word", delfword, META | 'D'} , {" delete-other-windows", onlywind, CTLX | '1'} , - {"!delete-previous-character", backdel, CTL_ | 'H'} , /* ^? */ - {"!delete-previous-word", delbword, META | CTL_ | 'H'} , /* M^? */ + {"!delete-previous-character", backdel, CTRL | 'H'} , /* ^? */ + {"!delete-previous-word", delbword, META | CTRL | 'H'} , /* M^? */ {" delete-window", delwind, CTLX | '0'} , {" describe-bindings", desbind, 0} , {" describe-key", deskey, CTLX | '?'} , #if AEDIT - {"!detab-line", detab, CTLX | CTL_ | 'D'} , /* X^A */ + {"!detab-line", detab, CTLX | CTRL | 'D'} , /* X^A */ #endif {" end-macro", ctlxrp, CTLX | ')'} , {" end-of-file", (fnp_t) gotoeob, META | '>'} , - {" end-of-line", (fnp_t) gotoeol, CTL_ | 'E'} , + {" end-of-line", (fnp_t) gotoeol, CTRL | 'E'} , #if AEDIT - {"!entab-line", entab, CTLX | CTL_ | 'E'} , + {"!entab-line", entab, CTLX | CTRL | 'E'} , #endif - {" exchange-point-and-mark", (fnp_t) swapmark, CTLX | CTL_ | 'X'} , + {" exchange-point-and-mark", (fnp_t) swapmark, CTLX | CTRL | 'X'} , {" execute-buffer", execbuf, 0} , {" execute-command-line", execcmd, 0} , {" execute-file", execfile, 0} , @@ -129,22 +126,22 @@ const name_bind names[] = { {" execute-macro-9", cbuf9, 0} , {" execute-named-command", namedcmd, META | 'X'} , #if PROC - {" execute-procedure", execproc, META | CTL_ | 'E'} , + {" execute-procedure", execproc, META | CTRL | 'E'} , #endif {" execute-program", execprg, CTLX | '$'} , - {" exit-emacs", quit, CTLX | CTL_ | 'C'} , + {" exit-emacs", quit, CTLX | CTRL | 'C'} , #if WORDPRO {"!fill-paragraph", fillpara, META | 'Q'} , #endif {"!filter-buffer", filter_buffer, CTLX | '#'} , - {" find-file", filefind, CTLX | CTL_ | 'F'} , - {" forward-character", (fnp_t) forwchar, CTL_ | 'F'} , + {" find-file", filefind, CTLX | CTRL | 'F'} , + {" forward-character", (fnp_t) forwchar, CTRL | 'F'} , {" goto-line", gotoline, META | 'G'} , #if CFENCE - {" goto-matching-fence", getfence, META | CTL_ | 'F'} , + {" goto-matching-fence", getfence, META | CTRL | 'F'} , #endif {" grow-window", enlargewind, CTLX | 'Z'} , /* X^ */ - {"!handle-tab", insert_tab, CTL_ | 'I'} , + {"!handle-tab", insert_tab, CTRL | 'I'} , {" help", help, META | '?'} , {" hunt-backward", backhunt, 0} , {" hunt-forward", forwhunt, META | 'S'} , @@ -152,48 +149,48 @@ const name_bind names[] = { #if ISRCH {" incremental-search", fisearch, CTLX | 'S'} , #endif - {"!insert-file", insfile, CTLX | CTL_ | 'I'} , - {"!insert-space", insspace, CTL_ | 'C'} , + {"!insert-file", insfile, CTLX | CTRL | 'I'} , + {"!insert-space", insspace, CTRL | 'C'} , {"!insert-string", istring, 0} , #if WORDPRO #if PKCODE {"!justify-paragraph", justpara, META | 'J'} , #endif - {"!kill-paragraph", killpara, META | CTL_ | 'W'} , + {"!kill-paragraph", killpara, META | CTRL | 'W'} , #endif - {"!kill-region", killregion, CTL_ | 'W'} , - {"!kill-to-end-of-line", killtext, CTL_ | 'K'} , - {" list-buffers", listbuffers, CTLX | CTL_ | 'B'} , - {" meta-prefix", metafn, CTL_ | '['} , - {" move-window-down", mvdnwind, CTLX | CTL_ | 'N'} , - {" move-window-up", mvupwind, CTLX | CTL_ | 'P'} , - {" name-buffer", namebuffer, META | CTL_ | 'N'} , - {"!newline", insert_newline, CTL_ | 'M'} , - {"!newline-and-indent", indent, CTL_ | 'J'} , + {"!kill-region", killregion, CTRL | 'W'} , + {"!kill-to-end-of-line", killtext, CTRL | 'K'} , + {" list-buffers", listbuffers, CTLX | CTRL | 'B'} , + {" meta-prefix", metafn, CTRL | '['} , + {" move-window-down", mvdnwind, CTLX | CTRL | 'N'} , + {" move-window-up", mvupwind, CTLX | CTRL | 'P'} , + {" name-buffer", namebuffer, META | CTRL | 'N'} , + {"!newline", insert_newline, CTRL | 'M'} , + {"!newline-and-indent", indent, CTRL | 'J'} , {" next-buffer", nextbuffer, CTLX | 'X'} , - {" next-line", (fnp_t) forwline, CTL_ | 'N'} , - {" next-page", (fnp_t) forwpage, CTL_ | 'V'} , + {" next-line", (fnp_t) forwline, CTRL | 'N'} , + {" next-page", (fnp_t) forwpage, CTRL | 'V'} , #if WORDPRO {" next-paragraph", gotoeop, META | 'N'} , #endif {" next-window", nextwind, CTLX | 'O'} , {" next-word", forwword, META | 'F'} , {" nop", nullproc, SPEC | META | 'C'}, /* hook */ - {"!open-line", openline, CTL_ | 'O'} , + {"!open-line", openline, CTRL | 'O'} , {" overwrite-string", ovstring, 0} , {" pipe-command", pipecmd, CTLX | '@'} , - {" previous-line", (fnp_t) backline, CTL_ | 'P'} , - {" previous-page", (fnp_t) backpage, CTL_ | 'Z'} , /* MV */ + {" previous-line", (fnp_t) backline, CTRL | 'P'} , + {" previous-page", (fnp_t) backpage, CTRL | 'Z'} , /* MV */ #if WORDPRO {" previous-paragraph", gotobop, META | 'P'} , #endif {" previous-window", prevwind, CTLX | 'P'} , {" previous-word", backword, META | 'B'} , - {"!query-replace-string", qreplace, META | CTL_ | 'R'} , + {"!query-replace-string", qreplace, META | CTRL | 'R'} , {" quick-exit", quickexit, META | 'Z'} , - {"!quote-character", quote, CTL_ | 'Q'} , /* also XQ */ - {"!read-file", fileread, CTLX | CTL_ | 'R'} , - {" redraw-display", reposition, META | CTL_ | 'L'} , /* M! */ + {"!quote-character", quote, CTRL | 'Q'} , /* also XQ */ + {"!read-file", fileread, CTLX | CTRL | 'R'} , + {" redraw-display", reposition, META | CTRL | 'L'} , /* M! */ {"!replace-string", sreplace, META | 'R'} , {" resize-window", resize, CTLX | 'W'} , {" restore-window", restwnd, 0} , @@ -203,18 +200,18 @@ const name_bind names[] = { #if PROC {" run", execproc, 0} , // alias of execute-procedure #endif - {"!save-file", filesave, CTLX | CTL_ | 'S'} , /* also X^D */ + {"!save-file", filesave, CTLX | CTRL | 'S'} , /* also X^D */ {" save-window", savewnd, 0} , - {" scroll-next-down", scrnextdw, META | CTL_ | 'V'} , - {" scroll-next-up", scrnextup, META | CTL_ | 'Z'} , - {" search-forward", forwsearch, CTL_ | 'S'} , - {" search-reverse", backsearch, CTL_ | 'R'} , + {" scroll-next-down", scrnextdw, META | CTRL | 'V'} , + {" scroll-next-up", scrnextup, META | CTRL | 'Z'} , + {" search-forward", forwsearch, CTRL | 'S'} , + {" search-reverse", backsearch, CTRL | 'R'} , {" select-buffer", usebuffer, CTLX | 'B'} , {" set", setvar, CTLX | 'A'} , {" set-fill-column", setfillcol, CTLX | 'F'} , {" set-mark", (fnp_t) setmark, META | ' '} , /* M. */ {" shell-command", spawn, CTLX | '!'} , - {" shrink-window", shrinkwind, CTLX | CTL_ | 'Z'} , + {" shrink-window", shrinkwind, CTLX | CTRL | 'Z'} , {" split-current-window", splitwind, CTLX | '2'} , {" store-macro", storemac, 0} , #if PROC @@ -223,31 +220,31 @@ const name_bind names[] = { #if BSD | SVR4 {" suspend-emacs", bktoshell, CTLX | 'D'} , /* BSD MS */ #endif - {"!transpose-characters", (fnp_t) twiddle, CTL_ | 'T'} , + {"!transpose-characters", (fnp_t) twiddle, CTRL | 'T'} , #if AEDIT - {"!trim-line", trim, CTLX | CTL_ | 'T'} , + {"!trim-line", trim, CTLX | CTRL | 'T'} , #endif - {" unbind-key", unbindkey, META | CTL_ | 'K'} , - {" universal-argument", unarg, CTL_ | 'U'} , + {" unbind-key", unbindkey, META | CTRL | 'K'} , + {" universal-argument", unarg, CTRL | 'U'} , {" unmark-buffer", unmark, META | '~'} , {" update-screen", upscreen, 0} , - {" view-file", viewfile, CTLX | CTL_ | 'V'} , + {" view-file", viewfile, CTLX | CTRL | 'V'} , {"!wrap-word", wrapword, SPEC | META | 'W'} , /* hook */ - {" write-file", filewrite, CTLX | CTL_ | 'W'} , + {" write-file", filewrite, CTLX | CTRL | 'W'} , {" write-message", writemsg, 0} , - {"!yank", yank, CTL_ | 'Y'} , + {"!yank", yank, CTRL | 'Y'} , {" ", NULL, 0}, /* extra key mapping */ -// { NULL, newsize, META | CTL_ | 'S'}, - { NULL, backdel, CTL_ | '?'}, - { NULL, delbword, META | CTL_ | '?'}, - { NULL, detab, CTLX | CTL_ | 'A'}, +// { NULL, newsize, META | CTRL | 'S'}, + { NULL, backdel, CTRL | '?'}, + { NULL, delbword, META | CTRL | '?'}, + { NULL, detab, CTLX | CTRL | 'A'}, { NULL, enlargewind, CTLX | '^'}, { NULL, (fnp_t) backpage, META | 'V'}, { NULL, quote, CTLX | 'Q'}, { NULL, reposition, META | '!'}, -//detab { NULL, filesave, CTLX | CTL_ | 'D'}, +//detab { NULL, filesave, CTLX | CTRL | 'D'}, { NULL, (fnp_t) setmark, META | '.'}, // { NULL, bktoshell, META | 'S'}, @@ -390,6 +387,21 @@ boolean delkeybinding( unsigned key) { return FALSE ; } +/* + * This function looks a key binding up in the binding table + * + * int c; key to find what is bound to it + */ +kbind_p getkeybinding( unsigned c) { + kbind_p ktp ; + + for( ktp = keytab ; ktp->k_code != 0 ; ktp++) + if (ktp->k_code == c) + break ; + + return ktp ; +} + #define BINARY 1 nbind_p fncmatch( char *name) { diff --git a/names.h b/names.h index 64bf210..0d045f9 100644 --- a/names.h +++ b/names.h @@ -6,6 +6,12 @@ #include "retcode.h" +#define CTRL 0x01000000 /* Control flag, or'ed in */ +#define META 0x02000000 /* Meta flag, or'ed in */ +#define CTLX 0x04000000 /* ^X flag, or'ed in */ +#define SPEC 0x08000000 /* special key (function keys) */ + + /* Bindable uEMACS function pointer type and definition template */ #define BINDABLE( fname) int fname( int f, int n) @@ -39,8 +45,12 @@ extern kbind_p keytab ; /* key bind to functions table */ boolean init_bindings( void) ; kbind_p setkeybinding( unsigned key, nbind_p nbp) ; boolean delkeybinding( unsigned key) ; +kbind_p getkeybinding( unsigned key) ; /* look up by key code */ + +/* find a name to function association in the name to function mapping table */ nbind_p fncmatch( char *name) ; /* look up by name */ + /* bindable functions mapped to prefix keys and hooks */ BINDABLE( nullproc) ; BINDABLE( metafn) ; diff --git a/random.c b/random.c index 957a785..785c353 100644 --- a/random.c +++ b/random.c @@ -924,96 +924,6 @@ static int adjustmode( int kind, int global) { return FALSE; } -#if CFENCE -/* - * the cursor is moved to a matching fence - * - * int f, n; not used - */ -int getfence(int f, int n) -{ - struct line *oldlp; /* original line pointer */ - int oldoff; /* and offset */ - int sdir; /* direction of search (1/-1) */ - int count; /* current fence level count */ - char ch; /* fence type to match against */ - char ofence; /* open fence */ - char c; /* current character in scan */ - - /* save the original cursor position */ - oldlp = curwp->w_dotp; - oldoff = curwp->w_doto; - - /* get the current character */ - if (oldoff == llength(oldlp)) - ch = '\n'; - else - ch = lgetc(oldlp, oldoff); - - /* setup proper matching fence */ - switch (ch) { - case '(': - ofence = ')'; - sdir = FORWARD; - break; - case '{': - ofence = '}'; - sdir = FORWARD; - break; - case '[': - ofence = ']'; - sdir = FORWARD; - break; - case ')': - ofence = '('; - sdir = REVERSE; - break; - case '}': - ofence = '{'; - sdir = REVERSE; - break; - case ']': - ofence = '['; - sdir = REVERSE; - break; - default: - TTbeep(); - return FALSE; - } - - /* scan until we find a match, or reach the end of file */ - count = 1 ; - do { - if( boundry( curwp->w_dotp, curwp->w_doto, sdir)) { - /* at buffer limit, no match to be found */ - /* restore the current position */ - curwp->w_dotp = oldlp ; - curwp->w_doto = oldoff ; - TTbeep() ; - return FALSE ; - } - - if( sdir == FORWARD) - forwchar( FALSE, 1) ; - else - backchar( FALSE, 1) ; - - /* if no eol */ - if( curwp->w_doto != llength(curwp->w_dotp)) { - c = curwbyte() ; - if( c == ch) - ++count ; - else if( c == ofence) - --count ; - } - } while( count > 0) ; - - /* we have a match, move the sucker */ - curwp->w_flag |= WFMOVE ; - return TRUE ; -} -#endif - static int iovstring( int f, int n, const char *prompt, int (*fun)( char *)) { int status ; /* status return code */ diff --git a/random.h b/random.h index f666c4c..eb772d7 100644 --- a/random.h +++ b/random.h @@ -43,7 +43,6 @@ int setemode( int f, int n) ; int delmode( int f, int n) ; int setgmode( int f, int n) ; int delgmode( int f, int n) ; -int getfence( int f, int n) ; int istring( int f, int n) ; int ovstring( int f, int n) ;