diff --git a/bind.c b/bind.c index 7227b7d..839dc8c 100644 --- a/bind.c +++ b/bind.c @@ -368,11 +368,11 @@ static int buildlist( char *mstring) { #if APROP /* if we are executing an apropos command..... */ /* and current string doesn't include the search string */ - if( *mstring && strinc( nptr->n_name, mstring) == FALSE) + if( *mstring && strinc( bind_name( nptr), mstring) == FALSE) continue ; #endif /* add in the command name */ - mystrscpy( outseq, nptr->n_name, sizeof outseq) ; + mystrscpy( outseq, bind_name( nptr), sizeof outseq) ; cpos = strlen(outseq); /* search down any keys bound to this */ @@ -522,7 +522,7 @@ static const char *getfname( unsigned keycode, char *failmsg) { if( func == NULL) return failmsg ; - const char *found = getnamebind( func)->n_name ; + const char *found = getfncname( func) ; return *found ? found : failmsg ; } diff --git a/exec.c b/exec.c index db51781..3681c67 100644 --- a/exec.c +++ b/exec.c @@ -97,7 +97,7 @@ int namedcmd( int f, int n) { return FALSE; } - if( nbp->tag && (curbp->b_mode & MDVIEW)) + if( (bind_tag( nbp) & 1) && (curbp->b_mode & MDVIEW)) return rdonly() ; /* and then execute the command */ @@ -195,7 +195,7 @@ static int docmd( char *cline) { return FALSE; } - if( nbp->tag && (curbp->b_mode & MDVIEW)) + if( (bind_tag( nbp) & 1) && (curbp->b_mode & MDVIEW)) status = rdonly() ; else { /* save the arguments and go execute the command */ diff --git a/execute.c b/execute.c index 365860f..efe84b0 100644 --- a/execute.c +++ b/execute.c @@ -215,8 +215,8 @@ int execute( int c, int f, int n) { fnp_t execfunc = getbind( c) ; if( execfunc != NULL) { thisflag = 0 ; - const name_bind *nbp = getnamebind( execfunc) ; - if( nbp->tag && curbp->b_mode & MDVIEW) + const char *sp = getfncname( execfunc) ; + if( (sp[ -1] & 1) && (curbp->b_mode & MDVIEW)) status = rdonly() ; else status = execfunc( f, n) ; diff --git a/input.c b/input.c index ec5f05e..e0ecb01 100644 --- a/input.c +++ b/input.c @@ -168,14 +168,14 @@ const name_bind *fncmatch( char *fname) { /* scan through the table, returning any match */ for( ffp = names ; ffp->n_func != NULL ; ffp++) - if( strcmp( fname, ffp->n_name) == 0) + if( strcmp( fname, bind_name( ffp)) == 0) break ; return ffp ; } -const name_bind *getnamebind( fnp_t func) { +const char *getfncname( fnp_t func) { const name_bind *nptr ; /* pointer into the name binding table */ /* skim through the table, looking for a match */ @@ -183,7 +183,7 @@ const name_bind *getnamebind( fnp_t func) { if (nptr->n_func == func) break ; - return nptr ; + return bind_name( nptr) ; } /* @@ -243,60 +243,41 @@ const name_bind *getname( void) { } else if (c == ' ' || c == 0x1b || c == 0x09) { /* <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< */ - /* attempt a completion */ - buf[cpos] = 0; /* terminate it for us */ - ffp = names ; /* scan for matches */ - while (ffp->n_func != NULL) { - if (strncmp(buf, ffp->n_name, strlen(buf)) - == 0) { + /* attempt a completion */ + buf[ cpos] = 0 ; /* terminate it for us */ + int buflen = strlen( buf) ; + /* scan for matches */ + for( ffp = names ; ffp->n_func != NULL ; ffp++) { + if( strncmp( buf, bind_name( ffp), buflen) == 0) { /* a possible match! More than one? */ - if ((ffp + 1)->n_func == NULL || - (strncmp - (buf, (ffp + 1)->n_name, - strlen(buf)) != 0)) { + if( (ffp + 1)->n_func == NULL || + (strncmp( buf, bind_name( ffp + 1), buflen) != 0)) { /* no...we match, print it */ - echos( ffp->n_name + cpos) ; - TTflush(); + echos( &bind_name( ffp)[ cpos]) ; + TTflush() ; return ffp ; } else { /* << << << << << << << << << << << << << << << << << */ /* try for a partial match against the list */ - /* first scan down until we no longer match the current input */ - lffp = (ffp + 1); - while ((lffp + - 1)->n_func != - NULL) { - if (strncmp - (buf, - (lffp + - 1)->n_name, - strlen(buf)) - != 0) - break; - ++lffp; - } + /* first scan down until we no longer match the + * current input */ + for( lffp = ffp + 1 ; (lffp + 1)->n_func != NULL ; + lffp++) + if( strncmp( buf, bind_name( lffp + 1), + buflen) != 0) + break ; - /* and now, attempt to partial complete the string, char at a time */ + /* and now, attempt to partial complete the string, + * one char at a time */ while (TRUE) { /* add the next char in */ - buf[cpos] = - ffp-> - n_name[cpos]; + buf[ cpos] = bind_name( ffp)[ cpos] ; /* scan through the candidates */ - cffp = ffp + 1; - while (cffp <= - lffp) { - if (cffp-> - n_name - [cpos] - != - buf - [cpos]) - goto onward; - ++cffp; - } + for( cffp = ffp + 1 ; cffp <= lffp ; cffp++) + if( bind_name( cffp)[ cpos] != buf[ cpos]) + goto onward ; /* add the character */ echoc( buf[ cpos++]) ; @@ -304,12 +285,11 @@ const name_bind *getname( void) { /* << << << << << << << << << << << << << << << << << */ } } - ++ffp; } /* no match.....beep and onward */ TTbeep(); - onward:; + onward: TTflush(); /* <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< */ } else { diff --git a/input.h b/input.h index 2bc53de..041b306 100644 --- a/input.h +++ b/input.h @@ -30,7 +30,7 @@ int ectoc( int c) ; /* Look up in names to function association table */ const name_bind *fncmatch( char *) ; const name_bind *getname( void) ; -const name_bind *getnamebind( fnp_t func) ; +const char *getfncname( fnp_t func) ; int tgetc( void) ; int get1key( void) ; diff --git a/names.c b/names.c index 85d7ffe..f341e38 100644 --- a/names.c +++ b/names.c @@ -3,10 +3,10 @@ /* 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. -*/ + * 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. + */ #include "basic.h" #include "bind.h" @@ -26,210 +26,210 @@ #include "word.h" const name_bind names[] = { - {"abort-command", ctrlg, 0} , - {"add-mode", setemode, 0} , - {"add-global-mode", setgmode, 0} , + {" abort-command", ctrlg} , + {" add-mode", setemode} , + {" add-global-mode", setgmode} , #if APROP - {"apropos", apro, 0} , + {" apropos", apro} , #endif - {"backward-character", (fnp_t) backchar, 0} , - {"begin-macro", ctlxlp, 0} , - {"beginning-of-file", (fnp_t) gotobob, 0} , - {"beginning-of-line", (fnp_t) gotobol, 0} , - {"bind-to-key", bindtokey, 0} , - {"buffer-position", showcpos, 0} , - {"case-region-lower", lowerregion, 1} , - {"case-region-upper", upperregion, 1} , - {"case-word-capitalize", capword, 1} , - {"case-word-lower", lowerword, 1} , - {"case-word-upper", upperword, 1} , - {"change-file-name", filename, 0} , - {"change-screen-size", newsize, 0} , - {"change-screen-width", newwidth, 0} , - {"clear-and-redraw", redraw, 0} , - {"clear-message-line", clrmes, 0} , - {"copy-region", copyregion, 0} , + {" 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} , #if WORDPRO - {"count-words", wordcount, 0} , + {" count-words", wordcount} , #endif - {"ctlx-prefix", cex, 0} , - {"delete-blank-lines", deblank, 1} , - {"delete-buffer", killbuffer, 0} , - {"delete-mode", delmode, 0} , - {"delete-global-mode", delgmode, 0} , - {"delete-next-character", forwdel, 1} , - {"delete-next-word", delfword, 1} , - {"delete-other-windows", onlywind, 0} , - {"delete-previous-character", backdel, 1} , - {"delete-previous-word", delbword, 1} , - {"delete-window", delwind, 0} , - {"describe-bindings", desbind, 0} , - {"describe-key", deskey, 0} , + {" ctlx-prefix", cex} , + {"!delete-blank-lines", deblank} , + {" delete-buffer", killbuffer} , + {" delete-mode", delmode} , + {" delete-global-mode", delgmode} , + {"!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} , #if AEDIT - {"detab-line", detab, 1} , + {"!detab-line", detab} , #endif - {"end-macro", ctlxrp, 0} , - {"end-of-file", (fnp_t) gotoeob, 0} , - {"end-of-line", (fnp_t) gotoeol, 0} , + {" end-macro", ctlxrp} , + {" end-of-file", (fnp_t) gotoeob} , + {" end-of-line", (fnp_t) gotoeol} , #if AEDIT - {"entab-line", entab, 1} , + {"!entab-line", entab} , #endif - {"exchange-point-and-mark", (fnp_t) swapmark, 0} , - {"execute-buffer", execbuf, 0} , - {"execute-command-line", execcmd, 0} , - {"execute-file", execfile, 0} , - {"execute-macro", ctlxe, 0} , - {"execute-macro-1", cbuf1, 0} , - {"execute-macro-2", cbuf2, 0} , - {"execute-macro-3", cbuf3, 0} , - {"execute-macro-4", cbuf4, 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-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-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-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-40", cbuf40, 0} , - {"execute-named-command", namedcmd, 0} , + {" 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-2", cbuf2} , + {" execute-macro-3", cbuf3} , + {" execute-macro-4", cbuf4} , + {" execute-macro-5", cbuf5} , + {" execute-macro-6", cbuf6} , + {" execute-macro-7", cbuf7} , + {" execute-macro-8", cbuf8} , + {" execute-macro-9", cbuf9} , + {" 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-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-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-40", cbuf40} , + {" execute-named-command", namedcmd} , #if PROC - {"execute-procedure", execproc, 0} , + {" execute-procedure", execproc} , #endif - {"execute-program", execprg, 0} , - {"exit-emacs", quit, 0} , + {" execute-program", execprg} , + {" exit-emacs", quit} , #if WORDPRO - {"fill-paragraph", fillpara, 1} , + {"!fill-paragraph", fillpara} , #endif - {"filter-buffer", filter_buffer, 1} , - {"find-file", filefind, 0} , - {"forward-character", (fnp_t) forwchar, 0} , - {"goto-line", gotoline, 0} , + {"!filter-buffer", filter_buffer} , + {" find-file", filefind} , + {" forward-character", (fnp_t) forwchar} , + {" goto-line", gotoline} , #if CFENCE - {"goto-matching-fence", getfence, 0} , + {" goto-matching-fence", getfence} , #endif - {"grow-window", enlargewind, 0} , - {"handle-tab", insert_tab, 0} , - {"hunt-forward", forwhunt, 0} , - {"hunt-backward", backhunt, 0} , - {"help", help, 0} , - {"i-shell", spawncli, 0} , + {" grow-window", enlargewind} , + {"!handle-tab", insert_tab} , + {" hunt-forward", forwhunt} , + {" hunt-backward", backhunt} , + {" help", help} , + {" i-shell", spawncli} , #if ISRCH - {"incremental-search", fisearch, 0} , + {" incremental-search", fisearch} , #endif - {"insert-file", insfile, 1} , - {"insert-space", insspace, 1} , - {"insert-string", istring, 1} , + {"!insert-file", insfile} , + {"!insert-space", insspace} , + {"!insert-string", istring} , #if WORDPRO #if PKCODE - {"justify-paragraph", justpara, 1} , + {"!justify-paragraph", justpara} , #endif - {"kill-paragraph", killpara, 1} , + {"!kill-paragraph", killpara} , #endif - {"kill-region", killregion, 1} , - {"kill-to-end-of-line", killtext, 1} , - {"list-buffers", listbuffers, 0} , - {"meta-prefix", metafn, 0} , - {"move-window-down", mvdnwind, 0} , - {"move-window-up", mvupwind, 0} , - {"name-buffer", namebuffer, 0} , - {"newline", insert_newline, 1} , - {"newline-and-indent", indent, 1} , - {"next-buffer", nextbuffer, 0} , - {"next-line", (fnp_t) forwline, 0} , - {"next-page", (fnp_t) forwpage, 0} , + {"!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} , #if WORDPRO - {"next-paragraph", gotoeop, 0} , + {" next-paragraph", gotoeop} , #endif - {"next-window", nextwind, 0} , - {"next-word", forwword, 0} , - {"nop", nullproc, 0} , - {"open-line", openline, 1} , - {"overwrite-string", ovstring, 0} , - {"pipe-command", pipecmd, 0} , - {"previous-line", (fnp_t) backline, 0} , - {"previous-page", (fnp_t) backpage, 0} , + {" 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} , #if WORDPRO - {"previous-paragraph", gotobop, 0} , + {" previous-paragraph", gotobop} , #endif - {"previous-window", prevwind, 0} , - {"previous-word", backword, 0} , - {"query-replace-string", qreplace, 1} , - {"quick-exit", quickexit, 0} , - {"quote-character", quote, 1} , - {"read-file", fileread, 1} , - {"redraw-display", reposition, 0} , - {"resize-window", resize, 0} , - {"restore-window", restwnd, 0} , - {"replace-string", sreplace, 1} , + {" previous-window", prevwind} , + {" previous-word", backword} , + {"!query-replace-string", qreplace} , + {" quick-exit", quickexit} , + {"!quote-character", quote} , + {"!read-file", fileread} , + {" redraw-display", reposition} , + {" resize-window", resize} , + {" restore-window", restwnd} , + {"!replace-string", sreplace} , #if ISRCH - {"reverse-incremental-search", risearch, 0} , + {" reverse-incremental-search", risearch} , #endif #if PROC - {"run", execproc, 0} , + {" run", execproc} , #endif - {"save-file", filesave, 1} , - {"save-window", savewnd, 0} , - {"scroll-next-up", scrnextup, 0} , - {"scroll-next-down", scrnextdw, 0} , - {"search-forward", forwsearch, 0} , - {"search-reverse", backsearch, 0} , - {"select-buffer", usebuffer, 0} , - {"set", setvar, 0} , - {"set-fill-column", setfillcol, 0} , - {"set-mark", (fnp_t) setmark, 0} , - {"shell-command", spawn, 0} , - {"shrink-window", shrinkwind, 0} , - {"split-current-window", splitwind, 0} , - {"store-macro", storemac, 0} , + {"!save-file", filesave} , + {" save-window", savewnd} , + {" scroll-next-up", scrnextup} , + {" scroll-next-down", scrnextdw} , + {" 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} , #if PROC - {"store-procedure", storeproc, 0} , + {" store-procedure", storeproc} , #endif #if BSD | SVR4 - {"suspend-emacs", bktoshell, 0} , + {" suspend-emacs", bktoshell} , #endif - {"transpose-characters", (fnp_t) twiddle, 1} , + {"!transpose-characters", (fnp_t) twiddle} , #if AEDIT - {"trim-line", trim, 1} , + {"!trim-line", trim} , #endif - {"unbind-key", unbindkey, 0} , - {"universal-argument", unarg, 0} , - {"unmark-buffer", unmark, 0} , - {"update-screen", upscreen, 0} , - {"view-file", viewfile, 0} , - {"wrap-word", wrapword, 0} , - {"write-file", filewrite, 0} , - {"write-message", writemsg, 0} , - {"yank", yank, 1} , + {" 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} , - {"", NULL, 0} + {" ", NULL} }; /* end of names.c */ diff --git a/names.h b/names.h index 6bc1944..9355ca3 100644 --- a/names.h +++ b/names.h @@ -5,11 +5,13 @@ /* Structure for the name binding table. */ typedef struct name_bind { - const char *n_name ; /* name of function key */ - fnp_t n_func ; /* function name is bound to */ - char tag ; /* view mode compatibility tag */ + const char *n_name ; /* name starting with one tag character */ + fnp_t n_func ; /* function the name is bound to */ } name_bind ; +#define bind_name( p) (&(p)->n_name[ 1]) +#define bind_tag( p) (p)->n_name[ 0] + extern const name_bind names[] ; /* name to function table */ #endif