From f30ef38bc8c669944ee7a8fbd19a235cf1ddcc2a Mon Sep 17 00:00:00 2001 From: Renaud Fivet Date: Fri, 23 Jul 2021 10:47:58 +0800 Subject: [PATCH] Merge name to function and key code to function table initialization. --- bind.c | 5 +- bind.h | 4 +- ebind.c | 363 ------------------------------------------- ebind.h | 17 --- exec.c | 4 +- main.c | 1 + names.c | 465 +++++++++++++++++++++++++++++++++++--------------------- names.h | 24 ++- 8 files changed, 321 insertions(+), 562 deletions(-) delete mode 100644 ebind.c delete mode 100644 ebind.h diff --git a/bind.c b/bind.c index e1ba41a..ffe9010 100644 --- a/bind.c +++ b/bind.c @@ -19,7 +19,6 @@ #include "bindable.h" #include "buffer.h" #include "display.h" -#include "ebind.h" #include "exec.h" #include "file.h" #include "flook.h" @@ -308,7 +307,7 @@ int apro( int f, int n) { static int buildlist( char *mstring) { #endif struct window *wp; /* scanning pointer to windows */ - struct key_tab *ktp; /* pointer into the command table */ + key_tab *ktp; /* pointer into the command table */ const name_bind *nptr;/* pointer into the name binding table */ struct buffer *bp; /* buffer to put binding list into */ char outseq[80]; /* output buffer for keystroke sequence */ @@ -493,7 +492,7 @@ static void cmdstr( int c, char *seq) { * int c; key to find what is bound to it */ key_tab *getkeybind( unsigned c) { - struct key_tab *ktp ; + key_tab *ktp ; for( ktp = keytab ; ktp->k_fp != NULL ; ktp++) if (ktp->k_code == c) diff --git a/bind.h b/bind.h index 93200e0..8a4fe90 100644 --- a/bind.h +++ b/bind.h @@ -1,15 +1,15 @@ #ifndef _BIND_H_ #define _BIND_H_ -#include "ebind.h" +#include "names.h" #define APROP 1 /* Add code for Apropos command */ +/* uEMACS functions */ #if APROP int apro( int f, int n) ; #endif -/* uEMACS functions */ int help( int f, int n) ; int deskey( int f, int n) ; int bindtokey( int f, int n) ; diff --git a/ebind.c b/ebind.c deleted file mode 100644 index 7ee5ce7..0000000 --- a/ebind.c +++ /dev/null @@ -1,363 +0,0 @@ -/* ebind.c -- implements ebind.h */ -#include "ebind.h" - -/* ebind.c - * - * Initial default key to function bindings - * - * Modified by Petri Kutvonen - */ - -#include - - -#include "basic.h" -#include "bind.h" -#include "estruct.h" -#include "bindable.h" -#include "buffer.h" -#include "eval.h" -#include "exec.h" -#include "file.h" -#include "isearch.h" -#include "line.h" -#include "random.h" -#include "region.h" -#include "search.h" -#include "spawn.h" -#include "window.h" -#include "word.h" - -/* - * Command table. - * This table is *roughly* in ASCII order, left to right across the - * characters of the command. This explains the funny location of the - * control-X commands. - */ -key_tab keytab[ NBINDS] = { - {CONTROL | '?', backdel, NULL}, - {CONTROL | 'A', (fnp_t) gotobol, NULL} - , - {CONTROL | 'B', (fnp_t) backchar, NULL} - , - {CONTROL | 'C', insspace, NULL} - , - {CONTROL | 'D', forwdel, NULL} - , - {CONTROL | 'E', (fnp_t) gotoeol, NULL} - , - {CONTROL | 'F', (fnp_t) forwchar, NULL} - , - {CONTROL | 'G', ctrlg, NULL} - , - {CONTROL | 'H', backdel, NULL} - , - {CONTROL | 'I', insert_tab, NULL} - , - {CONTROL | 'J', indent, NULL} - , - {CONTROL | 'K', killtext, NULL} - , - {CONTROL | 'L', redraw, NULL} - , - {CONTROL | 'M', insert_newline, NULL} - , - {CONTROL | 'N', (fnp_t) forwline, NULL} - , - {CONTROL | 'O', openline, NULL} - , - {CONTROL | 'P', (fnp_t) backline, NULL} - , - {CONTROL | 'Q', quote, NULL} - , - {CONTROL | 'R', backsearch, NULL} - , - {CONTROL | 'S', forwsearch, NULL} - , - {CONTROL | 'T', (fnp_t) twiddle, NULL} - , - {CONTROL | 'U', unarg, NULL} - , - {CONTROL | 'V', (fnp_t) forwpage, NULL} - , - {CONTROL | 'W', killregion, NULL} - , - {CONTROL | 'X', cex, NULL} - , - {CONTROL | 'Y', yank, NULL} - , - {CONTROL | 'Z', (fnp_t) backpage, NULL} - , - {CONTROL | ']', metafn, NULL} - , - {CTLX | CONTROL | 'B', listbuffers, NULL} - , - {CTLX | CONTROL | 'C', quit, NULL} - , /* Hard quit. */ -#if PKCODE & AEDIT - {CTLX | CONTROL | 'A', detab, NULL} - , -#endif -#if PKCODE - {CTLX | CONTROL | 'D', filesave, NULL} - , /* alternative */ -#else -#if AEDIT - {CTLX | CONTROL | 'D', detab, NULL} - , -#endif -#endif -#if AEDIT - {CTLX | CONTROL | 'E', entab, NULL} - , -#endif - {CTLX | CONTROL | 'F', filefind, NULL} - , - {CTLX | CONTROL | 'I', insfile, NULL} - , - {CTLX | CONTROL | 'L', lowerregion, NULL} - , - {CTLX | CONTROL | 'M', delmode, NULL} - , - {CTLX | CONTROL | 'N', mvdnwind, NULL} - , - {CTLX | CONTROL | 'O', deblank, NULL} - , - {CTLX | CONTROL | 'P', mvupwind, NULL} - , - {CTLX | CONTROL | 'R', fileread, NULL} - , - {CTLX | CONTROL | 'S', filesave, NULL} - , -#if AEDIT - {CTLX | CONTROL | 'T', trim, NULL} - , -#endif - {CTLX | CONTROL | 'U', upperregion, NULL} - , - {CTLX | CONTROL | 'V', viewfile, NULL} - , - {CTLX | CONTROL | 'W', filewrite, NULL} - , - {CTLX | CONTROL | 'X', (fnp_t) swapmark, NULL} - , - {CTLX | CONTROL | 'Z', shrinkwind, NULL} - , - {CTLX | '?', deskey, NULL} - , - {CTLX | '!', spawn, NULL} - , - {CTLX | '@', pipecmd, NULL} - , - {CTLX | '#', filter_buffer, NULL} - , - {CTLX | '$', execprg, NULL} - , - {CTLX | '=', showcpos, NULL} - , - {CTLX | '(', ctlxlp, NULL} - , - {CTLX | ')', ctlxrp, NULL} - , - {CTLX | '^', enlargewind, NULL} - , - {CTLX | '0', delwind, NULL} - , - {CTLX | '1', onlywind, NULL} - , - {CTLX | '2', splitwind, NULL} - , - {CTLX | 'A', setvar, NULL} - , - {CTLX | 'B', usebuffer, NULL} - , - {CTLX | 'C', spawncli, NULL} - , -#if BSD | SVR4 - {CTLX | 'D', bktoshell, NULL} - , -#endif - {CTLX | 'E', ctlxe, NULL} - , - {CTLX | 'F', setfillcol, NULL} - , - {CTLX | 'K', killbuffer, NULL} - , - {CTLX | 'M', setemode, NULL} - , - {CTLX | 'N', filename, NULL} - , - {CTLX | 'O', nextwind, NULL} - , - {CTLX | 'P', prevwind, NULL} - , -#if PKCODE - {CTLX | 'Q', quote, NULL} - , /* alternative */ -#endif -#if ISRCH - {CTLX | 'R', risearch, NULL} - , - {CTLX | 'S', fisearch, NULL} - , -#endif - {CTLX | 'W', resize, NULL} - , - {CTLX | 'X', nextbuffer, NULL} - , - {CTLX | 'Z', enlargewind, NULL} - , - {META | CONTROL | '?', delbword, NULL}, -#if WORDPRO - {META | CONTROL | 'C', wordcount, NULL} - , -#endif -#if PKCODE - {META | CONTROL | 'D', newsize, NULL} - , -#endif -#if PROC - {META | CONTROL | 'E', execproc, NULL} - , -#endif -#if CFENCE - {META | CONTROL | 'F', getfence, NULL} - , -#endif - {META | CONTROL | 'H', delbword, NULL} - , - {META | CONTROL | 'K', unbindkey, NULL} - , - {META | CONTROL | 'L', reposition, NULL} - , - {META | CONTROL | 'M', delgmode, NULL} - , - {META | CONTROL | 'N', namebuffer, NULL} - , - {META | CONTROL | 'R', qreplace, NULL} - , - {META | CONTROL | 'S', newsize, NULL} - , - {META | CONTROL | 'T', newwidth, NULL} - , - {META | CONTROL | 'V', scrnextdw, NULL} - , -#if WORDPRO - {META | CONTROL | 'W', killpara, NULL} - , -#endif - {META | CONTROL | 'Z', scrnextup, NULL} - , - {META | ' ', (fnp_t) setmark, NULL} - , - {META | '?', help, NULL} - , - {META | '!', reposition, NULL} - , - {META | '.', (fnp_t) setmark, NULL} - , - {META | '>', (fnp_t) gotoeob, NULL} - , - {META | '<', (fnp_t) gotobob, NULL} - , - {META | '~', unmark, NULL} - , -#if APROP - {META | 'A', apro, NULL} - , -#endif - {META | 'B', backword, NULL} - , - {META | 'C', capword, NULL} - , - {META | 'D', delfword, NULL} - , - {META | 'F', forwword, NULL} - , - {META | 'G', gotoline, NULL} - , -#if PKCODE -#if WORDPRO - {META | 'J', justpara, NULL} - , -#endif -#endif - {META | 'K', bindtokey, NULL} - , - {META | 'L', lowerword, NULL} - , - {META | 'M', setgmode, NULL} - , -#if WORDPRO - {META | 'N', gotoeop, NULL} - , - {META | 'P', gotobop, NULL} - , - {META | 'Q', fillpara, NULL} - , -#endif - {META | 'R', sreplace, NULL} - , -#if PKCODE - {META | 'S', forwhunt, NULL} - , -#else -#if BSD - {META | 'S', bktoshell, NULL} - , -#endif -#endif - {META | 'U', upperword, NULL} - , - {META | 'V', (fnp_t) backpage, NULL} - , - {META | 'W', copyregion, NULL} - , - {META | 'X', namedcmd, NULL} - , - {META | 'Z', quickexit, NULL} - , - -#if VT220 - {SPEC | '1', (fnp_t) gotobob /* fisearch */, NULL} - , /* VT220 keys */ - {SPEC | '2', yank, NULL} - , - {SPEC | '3', forwdel /* killregion */, NULL} - , - {SPEC | '4', (fnp_t) gotoeob /* setmark */, NULL} - , - {SPEC | '5', (fnp_t) backpage, NULL} - , - {SPEC | '6', (fnp_t) forwpage, NULL} - , - {SPEC | 'A', (fnp_t) backline, NULL} - , - {SPEC | 'B', (fnp_t) forwline, NULL} - , - {SPEC | 'C', (fnp_t) forwchar, NULL} - , - {SPEC | 'D', (fnp_t) backchar, NULL} - , - {SPEC | 'c', metafn, NULL} - , - {SPEC | 'd', (fnp_t) backchar, NULL} - , - {SPEC | 'e', (fnp_t) forwline, NULL} - , - {SPEC | 'f', (fnp_t) gotobob, NULL} - , - {SPEC | 'h', help, NULL} - , - {SPEC | 'i', cex, NULL} - , -#endif - - /* special internal bindings */ - { SPEC | META | 'W', wrapword , NULL}, /* called on word wrap */ - { SPEC | META | 'C', nullproc , NULL}, /* every command input */ - { SPEC | META | 'R', nullproc , NULL}, /* on file read */ - { SPEC | META | 'X', nullproc , NULL}, /* on window change P.K. */ - - {0, NULL, NULL} -}; diff --git a/ebind.h b/ebind.h deleted file mode 100644 index 4ab490f..0000000 --- a/ebind.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef _EBIND_H_ -#define _EBIND_H_ - -#include "names.h" - -/* Structure for the key bindings table. */ -typedef struct key_tab { - unsigned k_code ; /* Key code */ - fnp_t k_fp ; /* Routine to handle it */ - const name_bind *k_nbp ; /* entry in name to function map table */ -} key_tab ; - -/* keycode to function mapping table */ -#define NBINDS 256 /* max # of bound keys */ -extern key_tab keytab[ NBINDS] ; /* key bind to functions table */ - -#endif diff --git a/exec.c b/exec.c index b8f86ad..0bbf488 100644 --- a/exec.c +++ b/exec.c @@ -87,7 +87,7 @@ static int macarg( char *tok, int toksz) ; */ int namedcmd( int f, int n) { /* prompt the user to type a named command */ - mlwrite(": execute-named-cmd "); + mlwrite("execute-named-cmd: "); /* and now get the function name to execute */ const name_bind *nbp = getname() ; @@ -121,7 +121,7 @@ int execcmd( int f, int n) { char *cmdstr ; /* string holding command to execute */ /* get the line wanted */ - status = newmlarg( &cmdstr, ": execute-command-line ", 0) ; + status = newmlarg( &cmdstr, "execute-command-line: ", 0) ; if( status != TRUE) return status ; diff --git a/main.c b/main.c index 50c1757..ec50fa9 100644 --- a/main.c +++ b/main.c @@ -165,6 +165,7 @@ int main(int argc, char **argv) } /* Initialize the editor. */ + init_bindings() ; /* initialize mapping of function to name and key */ vtinit(); /* Display */ mloutfmt = mlwrite ; edinit("main"); /* Buffers, windows */ diff --git a/names.c b/names.c index f50fd42..6494479 100644 --- a/names.c +++ b/names.c @@ -1,13 +1,18 @@ /* names.c -- implements names.h */ #include "names.h" +#define PARANOID 1 + /* Name to function binding table. * * This table gives the names of all the bindable functions and their C - * function address. These are used for the bind-to-key function and macro - * processing. + * function address. These are used for the bind-to-key function and + * command line parsing. */ +#ifdef PARANOID +#include +#endif #include #include "basic.h" @@ -28,216 +33,322 @@ #include "window.h" #include "word.h" + +#define CTL_ CONTROL + const name_bind names[] = { - {" abort-command", ctrlg} , - {" add-global-mode", setgmode} , - {" add-mode", setemode} , + {" abort-command", ctrlg, CTL_ | 'G'} , + {" add-global-mode", setgmode, META | 'M'} , + {" add-mode", setemode, CTLX | 'M'} , #if APROP - {" apropos", apro} , + {" apropos", apro, META | 'A'} , #endif - {" backward-character", (fnp_t) backchar} , - {" begin-macro", ctlxlp} , - {" beginning-of-file", (fnp_t) gotobob} , - {" beginning-of-line", (fnp_t) gotobol} , - {" bind-to-key", bindtokey} , - {" buffer-position", showcpos} , - {"!case-region-lower", lowerregion} , - {"!case-region-upper", upperregion} , - {"!case-word-capitalize", capword} , - {"!case-word-lower", lowerword} , - {"!case-word-upper", upperword} , - {" change-file-name", filename} , - {" change-screen-size", newsize} , - {" change-screen-width", newwidth} , - {" clear-and-redraw", redraw} , - {" clear-message-line", clrmes} , - {" copy-region", copyregion} , + {" backward-character", (fnp_t) backchar, CTL_ | 'B'} , + {" begin-macro", ctlxlp, CTLX | '('} , + {" beginning-of-file", (fnp_t) gotobob, META | '<'} , + {" beginning-of-line", (fnp_t) gotobol, CTL_ | '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-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'} , + {" clear-message-line", clrmes, 0} , + {" copy-region", copyregion, META | 'W'} , #if WORDPRO - {" count-words", wordcount} , + {" count-words", wordcount, META | CTL_ | 'C'} , #endif - {" ctlx-prefix", cex} , - {"!delete-blank-lines", deblank} , - {" delete-buffer", killbuffer} , - {" delete-global-mode", delgmode} , - {" delete-mode", delmode} , - {"!delete-next-character", forwdel} , - {"!delete-next-word", delfword} , - {" delete-other-windows", onlywind} , - {"!delete-previous-character", backdel} , - {"!delete-previous-word", delbword} , - {" delete-window", delwind} , - {" describe-bindings", desbind} , - {" describe-key", deskey} , + {" ctlx-prefix", cex, CTL_ | 'X'} , + {"!delete-blank-lines", deblank, CTLX | CTL_ | '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-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-window", delwind, CTLX | '0'} , + {" describe-bindings", desbind, 0} , + {" describe-key", deskey, CTLX | '?'} , #if AEDIT - {"!detab-line", detab} , + {"!detab-line", detab, CTLX | CTL_ | 'D'} , /* X^A */ #endif - {" end-macro", ctlxrp} , - {" end-of-file", (fnp_t) gotoeob} , - {" end-of-line", (fnp_t) gotoeol} , + {" end-macro", ctlxrp, CTLX | ')'} , + {" end-of-file", (fnp_t) gotoeob, META | '>'} , + {" end-of-line", (fnp_t) gotoeol, CTL_ | 'E'} , #if AEDIT - {"!entab-line", entab} , + {"!entab-line", entab, CTLX | CTL_ | 'E'} , #endif - {" exchange-point-and-mark", (fnp_t) swapmark} , - {" execute-buffer", execbuf} , - {" execute-command-line", execcmd} , - {" execute-file", execfile} , - {" execute-macro", ctlxe} , - {" execute-macro-1", cbuf1} , - {" execute-macro-10", cbuf10} , - {" execute-macro-11", cbuf11} , - {" execute-macro-12", cbuf12} , - {" execute-macro-13", cbuf13} , - {" execute-macro-14", cbuf14} , - {" execute-macro-15", cbuf15} , - {" execute-macro-16", cbuf16} , - {" execute-macro-17", cbuf17} , - {" execute-macro-18", cbuf18} , - {" execute-macro-19", cbuf19} , - {" execute-macro-2", cbuf2} , - {" execute-macro-20", cbuf20} , - {" execute-macro-21", cbuf21} , - {" execute-macro-22", cbuf22} , - {" execute-macro-23", cbuf23} , - {" execute-macro-24", cbuf24} , - {" execute-macro-25", cbuf25} , - {" execute-macro-26", cbuf26} , - {" execute-macro-27", cbuf27} , - {" execute-macro-28", cbuf28} , - {" execute-macro-29", cbuf29} , - {" execute-macro-3", cbuf3} , - {" execute-macro-30", cbuf30} , - {" execute-macro-31", cbuf31} , - {" execute-macro-32", cbuf32} , - {" execute-macro-33", cbuf33} , - {" execute-macro-34", cbuf34} , - {" execute-macro-35", cbuf35} , - {" execute-macro-36", cbuf36} , - {" execute-macro-37", cbuf37} , - {" execute-macro-38", cbuf38} , - {" execute-macro-39", cbuf39} , - {" execute-macro-4", cbuf4} , - {" execute-macro-40", cbuf40} , - {" execute-macro-5", cbuf5} , - {" execute-macro-6", cbuf6} , - {" execute-macro-7", cbuf7} , - {" execute-macro-8", cbuf8} , - {" execute-macro-9", cbuf9} , - {" execute-named-command", namedcmd} , + {" exchange-point-and-mark", (fnp_t) swapmark, CTLX | CTL_ | 'X'} , + {" execute-buffer", execbuf, 0} , + {" execute-command-line", execcmd, 0} , + {" execute-file", execfile, 0} , + {" execute-macro", ctlxe, CTLX | 'E'} , + {" execute-macro-1", cbuf1, 0} , + {" execute-macro-10", cbuf10, 0} , + {" execute-macro-11", cbuf11, 0} , + {" execute-macro-12", cbuf12, 0} , + {" execute-macro-13", cbuf13, 0} , + {" execute-macro-14", cbuf14, 0} , + {" execute-macro-15", cbuf15, 0} , + {" execute-macro-16", cbuf16, 0} , + {" execute-macro-17", cbuf17, 0} , + {" execute-macro-18", cbuf18, 0} , + {" execute-macro-19", cbuf19, 0} , + {" execute-macro-2", cbuf2, 0} , + {" execute-macro-20", cbuf20, 0} , + {" execute-macro-21", cbuf21, 0} , + {" execute-macro-22", cbuf22, 0} , + {" execute-macro-23", cbuf23, 0} , + {" execute-macro-24", cbuf24, 0} , + {" execute-macro-25", cbuf25, 0} , + {" execute-macro-26", cbuf26, 0} , + {" execute-macro-27", cbuf27, 0} , + {" execute-macro-28", cbuf28, 0} , + {" execute-macro-29", cbuf29, 0} , + {" execute-macro-3", cbuf3, 0} , + {" execute-macro-30", cbuf30, 0} , + {" execute-macro-31", cbuf31, 0} , + {" execute-macro-32", cbuf32, 0} , + {" execute-macro-33", cbuf33, 0} , + {" execute-macro-34", cbuf34, 0} , + {" execute-macro-35", cbuf35, 0} , + {" execute-macro-36", cbuf36, 0} , + {" execute-macro-37", cbuf37, 0} , + {" execute-macro-38", cbuf38, 0} , + {" execute-macro-39", cbuf39, 0} , + {" execute-macro-4", cbuf4, 0} , + {" execute-macro-40", cbuf40, 0} , + {" execute-macro-5", cbuf5, 0} , + {" execute-macro-6", cbuf6, 0} , + {" execute-macro-7", cbuf7, 0} , + {" execute-macro-8", cbuf8, 0} , + {" execute-macro-9", cbuf9, 0} , + {" execute-named-command", namedcmd, META | 'X'} , #if PROC - {" execute-procedure", execproc} , + {" execute-procedure", execproc, META | CTL_ | 'E'} , #endif - {" execute-program", execprg} , - {" exit-emacs", quit} , + {" execute-program", execprg, CTLX | '$'} , + {" exit-emacs", quit, CTLX | CTL_ | 'C'} , #if WORDPRO - {"!fill-paragraph", fillpara} , + {"!fill-paragraph", fillpara, META | 'Q'} , #endif - {"!filter-buffer", filter_buffer} , - {" find-file", filefind} , - {" forward-character", (fnp_t) forwchar} , - {" goto-line", gotoline} , + {"!filter-buffer", filter_buffer, CTLX | '#'} , + {" find-file", filefind, CTLX | CTL_ | 'F'} , + {" forward-character", (fnp_t) forwchar, CTL_ | 'F'} , + {" goto-line", gotoline, META | 'G'} , #if CFENCE - {" goto-matching-fence", getfence} , + {" goto-matching-fence", getfence, META | CTL_ | 'F'} , #endif - {" grow-window", enlargewind} , - {"!handle-tab", insert_tab} , - {" help", help} , - {" hunt-backward", backhunt} , - {" hunt-forward", forwhunt} , - {" i-shell", spawncli} , + {" grow-window", enlargewind, CTLX | 'Z'} , /* X^ */ + {"!handle-tab", insert_tab, CTL_ | 'I'} , + {" help", help, META | '?'} , + {" hunt-backward", backhunt, 0} , + {" hunt-forward", forwhunt, META | 'S'} , + {" i-shell", spawncli, CTLX | 'C'} , #if ISRCH - {" incremental-search", fisearch} , + {" incremental-search", fisearch, CTLX | 'S'} , #endif - {"!insert-file", insfile} , - {"!insert-space", insspace} , - {"!insert-string", istring} , + {"!insert-file", insfile, CTLX | CTL_ | 'I'} , + {"!insert-space", insspace, CTL_ | 'C'} , + {"!insert-string", istring, 0} , #if WORDPRO #if PKCODE - {"!justify-paragraph", justpara} , + {"!justify-paragraph", justpara, META | 'J'} , #endif - {"!kill-paragraph", killpara} , + {"!kill-paragraph", killpara, META | CTL_ | 'W'} , #endif - {"!kill-region", killregion} , - {"!kill-to-end-of-line", killtext} , - {" list-buffers", listbuffers} , - {" meta-prefix", metafn} , - {" move-window-down", mvdnwind} , - {" move-window-up", mvupwind} , - {" name-buffer", namebuffer} , - {"!newline", insert_newline} , - {"!newline-and-indent", indent} , - {" next-buffer", nextbuffer} , - {" next-line", (fnp_t) forwline} , - {" next-page", (fnp_t) forwpage} , + {"!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'} , + {" next-buffer", nextbuffer, CTLX | 'X'} , + {" next-line", (fnp_t) forwline, CTL_ | 'N'} , + {" next-page", (fnp_t) forwpage, CTL_ | 'V'} , #if WORDPRO - {" next-paragraph", gotoeop} , + {" next-paragraph", gotoeop, META | 'N'} , #endif - {" next-window", nextwind} , - {" next-word", forwword} , - {" nop", nullproc} , - {"!open-line", openline} , - {" overwrite-string", ovstring} , - {" pipe-command", pipecmd} , - {" previous-line", (fnp_t) backline} , - {" previous-page", (fnp_t) backpage} , + {" next-window", nextwind, CTLX | 'O'} , + {" next-word", forwword, META | 'F'} , + {" nop", nullproc, SPEC | META | 'C'}, /* hook */ + {"!open-line", openline, CTL_ | 'O'} , + {" overwrite-string", ovstring, 0} , + {" pipe-command", pipecmd, CTLX | '@'} , + {" previous-line", (fnp_t) backline, CTL_ | 'P'} , + {" previous-page", (fnp_t) backpage, CTL_ | 'Z'} , /* MV */ #if WORDPRO - {" previous-paragraph", gotobop} , + {" previous-paragraph", gotobop, META | 'P'} , #endif - {" previous-window", prevwind} , - {" previous-word", backword} , - {"!query-replace-string", qreplace} , - {" quick-exit", quickexit} , - {"!quote-character", quote} , - {"!read-file", fileread} , - {" redraw-display", reposition} , - {"!replace-string", sreplace} , - {" resize-window", resize} , - {" restore-window", restwnd} , + {" previous-window", prevwind, CTLX | 'P'} , + {" previous-word", backword, META | 'B'} , + {"!query-replace-string", qreplace, META | CTL_ | '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! */ + {"!replace-string", sreplace, META | 'R'} , + {" resize-window", resize, CTLX | 'W'} , + {" restore-window", restwnd, 0} , #if ISRCH - {" reverse-incremental-search", risearch} , + {" reverse-incremental-search", risearch, CTLX | 'R'} , #endif #if PROC - {" run", execproc} , + {" run", execproc, 0} , #endif - {"!save-file", filesave} , - {" save-window", savewnd} , - {" scroll-next-down", scrnextdw} , - {" scroll-next-up", scrnextup} , - {" search-forward", forwsearch} , - {" search-reverse", backsearch} , - {" select-buffer", usebuffer} , - {" set", setvar} , - {" set-fill-column", setfillcol} , - {" set-mark", (fnp_t) setmark} , - {" shell-command", spawn} , - {" shrink-window", shrinkwind} , - {" split-current-window", splitwind} , - {" store-macro", storemac} , + {"!save-file", filesave, CTLX | CTL_ | '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'} , + {" 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'} , + {" split-current-window", splitwind, CTLX | '2'} , + {" store-macro", storemac, 0} , #if PROC - {" store-procedure", storeproc} , + {" store-procedure", storeproc, 0} , #endif #if BSD | SVR4 - {" suspend-emacs", bktoshell} , + {" suspend-emacs", bktoshell, CTLX | 'D'} , /* BSD MS */ #endif - {"!transpose-characters", (fnp_t) twiddle} , + {"!transpose-characters", (fnp_t) twiddle, CTL_ | 'T'} , #if AEDIT - {"!trim-line", trim} , + {"!trim-line", trim, CTLX | CTL_ | 'T'} , #endif - {" unbind-key", unbindkey} , - {" universal-argument", unarg} , - {" unmark-buffer", unmark} , - {" update-screen", upscreen} , - {" view-file", viewfile} , - {" wrap-word", wrapword} , - {" write-file", filewrite} , - {" write-message", writemsg} , - {"!yank", yank} , + {" unbind-key", unbindkey, META | CTL_ | 'K'} , + {" universal-argument", unarg, CTL_ | 'U'} , + {" unmark-buffer", unmark, META | '~'} , + {" update-screen", upscreen, 0} , + {" view-file", viewfile, CTLX | CTL_ | 'V'} , + {"!wrap-word", wrapword, SPEC | META | 'W'} , /* hook */ + {" write-file", filewrite, CTLX | CTL_ | 'W'} , + {" write-message", writemsg, 0} , + {"!yank", yank, CTL_ | 'Y'} , - {" ", NULL} -}; + {" ", NULL, 0}, +/* extra key mapping */ +// { NULL, newsize, META | CTL_ | 'S'}, + { NULL, backdel, CTL_ | '?'}, + { NULL, delbword, META | CTL_ | '?'}, + { NULL, detab, CTLX | CTL_ | 'A'}, + { NULL, enlargewind, CTLX | '^'}, + { NULL, (fnp_t) backpage, META | 'V'}, + { NULL, quote, CTLX | 'Q'}, + { NULL, reposition, META | '!'}, +//detab { NULL, filesave, CTLX | CTL_ | 'D'}, + { NULL, (fnp_t) setmark, META | '.'}, +// { NULL, bktoshell, META | 'S'}, +#if VT220 + { NULL, yank, SPEC | '2'}, /* Insert */ + { NULL, forwdel /* killregion */, SPEC | '3'}, /* Delete */ + { NULL, (fnp_t) backpage, SPEC | '5'}, /* Page Up */ + { NULL, (fnp_t) forwpage, SPEC | '6'}, /* Page Down */ + { NULL, (fnp_t) backline, SPEC | 'A'}, /* Up */ + { NULL, (fnp_t) forwline, SPEC | 'B'}, /* Down */ + { NULL, (fnp_t) forwchar, SPEC | 'C'}, /* Right */ + { NULL, (fnp_t) backchar, SPEC | 'D'}, /* Left */ + { NULL, (fnp_t) gotoeob, SPEC | 'F'}, /* End */ + { NULL, (fnp_t) gotobob, SPEC | 'H'}, /* Home */ + { NULL, help, SPEC | 'P'}, /* F1 */ +#endif + +/* hooks */ + { NULL, nullproc, SPEC | META | 'R'}, /* hook */ + { NULL, nullproc, SPEC | META | 'X'}, /* hook */ + + { NULL, NULL, 0} +} ; + +static int lastidx = 0 ; + +key_tab keytab[ NBINDS] = { + {0, NULL, NULL} +} ; + + +void init_bindings( void) { +/* Add default key bindings */ + key_tab *ktp = keytab ; + const name_bind *nbp ; + for( nbp = names ; nbp->n_func != NULL ; nbp++) { +#ifdef PARANOID + /* Check entries and strict order */ + assert( (nbp->n_name != NULL) && + ((nbp == names) || + (0 > strcmp( bind_name( nbp - 1), bind_name( nbp))) + ) + ) ; +#endif + + /* Add key definition */ + if( nbp->n_keycode) { + ktp->k_code = nbp->n_keycode ; + ktp->k_fp = nbp->n_func ; + ktp->k_nbp = nbp ; + ktp += 1 ; + } + } + +/* memorize position after last valid function entry */ + lastidx = nbp - names ; + +/* Process extra key bindings if any */ + for( nbp++ ; nbp->n_func != NULL ; nbp++) { +#ifdef PARANOID + /* Check entry */ + assert( nbp->n_keycode && (nbp->n_name == NULL)) ; +#endif + + /* Look for corresponding function and add extra key binding */ + const name_bind *fnbp ; + for( fnbp = names ; fnbp->n_func != NULL ; fnbp++) + if( fnbp->n_func == nbp->n_func) { + ktp->k_code = nbp->n_keycode ; + ktp->k_fp = nbp->n_func ; + ktp->k_nbp = fnbp ; + ktp += 1 ; + break ; + } + +#ifdef PARANOID + /* Insure there is a name entry for the keycode and no double keycode */ + assert( fnbp->n_func != NULL) ; + int kcnt = 0 ; + for( key_tab *kktp = keytab ; kktp < ktp ; kktp++) + if( kktp->k_code == (ktp - 1)->k_code) + kcnt += 1 ; + + assert( kcnt == 1) ; +#endif + } + +/* Mark position after last valid key entry */ + ktp->k_code = 0 ; + ktp->k_fp = NULL ; + ktp->k_nbp = NULL ; +} + +#define BINARY 1 const name_bind *fncmatch( char *name) { - int found = ARRAY_SIZE( names) - 1 ; /* index of last entry/ catch all */ +#ifdef BINARY + int found = lastidx ; int low = 0 ; int high = found - 1 ; do { @@ -253,6 +364,14 @@ const name_bind *fncmatch( char *name) { } while( low <= high) ; return &names[ found] ; +#else + const name_bind *nbp ; + for( nbp = names ; nbp->n_func != NULL ; nbp++) + if( !strcmp( name, bind_name( nbp))) + break ; + + return nbp ; +#endif } /* end of names.c */ diff --git a/names.h b/names.h index ba763a4..3e7ce88 100644 --- a/names.h +++ b/names.h @@ -1,20 +1,40 @@ +/* names.h -- mapping of functions to names and keys */ + #ifndef _NAMES_H_ #define _NAMES_H_ /* Generic uEMACS function pointer type */ typedef int (*fnp_t)( int, int) ; + /* Structure for the name binding table. */ -typedef struct name_bind { +typedef struct { const char *n_name ; /* name starting with one tag character */ - fnp_t n_func ; /* function the name is bound to */ + fnp_t n_func ; /* function the name is bound to */ + unsigned n_keycode ; /* default key assignment, 0 when none */ } name_bind ; #define bind_name( p) (&(p)->n_name[ 1]) #define bind_tag( p) (p)->n_name[ 0] +/* Structure for the key bindings table. */ +typedef struct { + unsigned k_code ; /* Key code */ + fnp_t k_fp ; /* Routine to handle it */ + const name_bind *k_nbp ; /* entry in name to function map table */ +} key_tab ; + + extern const name_bind names[] ; /* name to function mapping table */ +/* keycode to function mapping table */ +#define NBINDS 256 /* max # of bound keys */ +extern key_tab keytab[ NBINDS] ; /* key bind to functions table */ + + +void init_bindings( void) ; const name_bind *fncmatch( char *name) ; /* look up by name */ #endif + +/* end of names.h */