1
0
mirror of https://github.com/rfivet/uemacs.git synced 2024-12-24 01:56:26 -05:00

Tag uEMACS functions using first character of name string.

This commit is contained in:
Renaud 2021-07-20 11:24:32 +08:00
parent 695b5d37da
commit 4f90e847f8
7 changed files with 213 additions and 231 deletions

6
bind.c
View File

@ -368,11 +368,11 @@ static int buildlist( char *mstring) {
#if APROP #if APROP
/* if we are executing an apropos command..... */ /* 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( nptr->n_name, mstring) == FALSE) if( *mstring && strinc( bind_name( nptr), mstring) == FALSE)
continue ; continue ;
#endif #endif
/* add in the command name */ /* add in the command name */
mystrscpy( outseq, nptr->n_name, sizeof outseq) ; mystrscpy( outseq, bind_name( nptr), sizeof outseq) ;
cpos = strlen(outseq); cpos = strlen(outseq);
/* search down any keys bound to this */ /* search down any keys bound to this */
@ -522,7 +522,7 @@ static const char *getfname( unsigned keycode, char *failmsg) {
if( func == NULL) if( func == NULL)
return failmsg ; return failmsg ;
const char *found = getnamebind( func)->n_name ; const char *found = getfncname( func) ;
return *found ? found : failmsg ; return *found ? found : failmsg ;
} }

4
exec.c
View File

@ -97,7 +97,7 @@ int namedcmd( int f, int n) {
return FALSE; return FALSE;
} }
if( nbp->tag && (curbp->b_mode & MDVIEW)) if( (bind_tag( nbp) & 1) && (curbp->b_mode & MDVIEW))
return rdonly() ; return rdonly() ;
/* and then execute the command */ /* and then execute the command */
@ -195,7 +195,7 @@ static int docmd( char *cline) {
return FALSE; return FALSE;
} }
if( nbp->tag && (curbp->b_mode & MDVIEW)) if( (bind_tag( nbp) & 1) && (curbp->b_mode & MDVIEW))
status = rdonly() ; status = rdonly() ;
else { else {
/* save the arguments and go execute the command */ /* save the arguments and go execute the command */

View File

@ -215,8 +215,8 @@ int execute( int c, int f, int n) {
fnp_t execfunc = getbind( c) ; fnp_t execfunc = getbind( c) ;
if( execfunc != NULL) { if( execfunc != NULL) {
thisflag = 0 ; thisflag = 0 ;
const name_bind *nbp = getnamebind( execfunc) ; const char *sp = getfncname( execfunc) ;
if( nbp->tag && curbp->b_mode & MDVIEW) if( (sp[ -1] & 1) && (curbp->b_mode & MDVIEW))
status = rdonly() ; status = rdonly() ;
else else
status = execfunc( f, n) ; status = execfunc( f, n) ;

72
input.c
View File

@ -168,14 +168,14 @@ const name_bind *fncmatch( char *fname) {
/* scan through the table, returning any match */ /* scan through the table, returning any match */
for( ffp = names ; ffp->n_func != NULL ; ffp++) for( ffp = names ; ffp->n_func != NULL ; ffp++)
if( strcmp( fname, ffp->n_name) == 0) if( strcmp( fname, bind_name( ffp)) == 0)
break ; break ;
return ffp ; 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 */ const name_bind *nptr ; /* pointer into the name binding table */
/* skim through the table, looking for a match */ /* skim through the table, looking for a match */
@ -183,7 +183,7 @@ const name_bind *getnamebind( fnp_t func) {
if (nptr->n_func == func) if (nptr->n_func == func)
break ; break ;
return nptr ; return bind_name( nptr) ;
} }
/* /*
@ -244,59 +244,40 @@ const name_bind *getname( void) {
} else if (c == ' ' || c == 0x1b || c == 0x09) { } else if (c == ' ' || c == 0x1b || c == 0x09) {
/* <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< */ /* <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< */
/* attempt a completion */ /* attempt a completion */
buf[cpos] = 0; /* terminate it for us */ buf[ cpos] = 0 ; /* terminate it for us */
ffp = names ; /* scan for matches */ int buflen = strlen( buf) ;
while (ffp->n_func != NULL) { /* scan for matches */
if (strncmp(buf, ffp->n_name, strlen(buf)) for( ffp = names ; ffp->n_func != NULL ; ffp++) {
== 0) { if( strncmp( buf, bind_name( ffp), buflen) == 0) {
/* a possible match! More than one? */ /* a possible match! More than one? */
if ((ffp + 1)->n_func == NULL || if( (ffp + 1)->n_func == NULL ||
(strncmp (strncmp( buf, bind_name( ffp + 1), buflen) != 0)) {
(buf, (ffp + 1)->n_name,
strlen(buf)) != 0)) {
/* no...we match, print it */ /* no...we match, print it */
echos( ffp->n_name + cpos) ; echos( &bind_name( ffp)[ cpos]) ;
TTflush(); TTflush() ;
return ffp ; return ffp ;
} else { } else {
/* << << << << << << << << << << << << << << << << << */ /* << << << << << << << << << << << << << << << << << */
/* try for a partial match against the list */ /* try for a partial match against the list */
/* first scan down until we no longer match the current input */ /* first scan down until we no longer match the
lffp = (ffp + 1); * current input */
while ((lffp + for( lffp = ffp + 1 ; (lffp + 1)->n_func != NULL ;
1)->n_func != lffp++)
NULL) { if( strncmp( buf, bind_name( lffp + 1),
if (strncmp buflen) != 0)
(buf, break ;
(lffp +
1)->n_name,
strlen(buf))
!= 0)
break;
++lffp;
}
/* 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) { while (TRUE) {
/* add the next char in */ /* add the next char in */
buf[cpos] = buf[ cpos] = bind_name( ffp)[ cpos] ;
ffp->
n_name[cpos];
/* scan through the candidates */ /* scan through the candidates */
cffp = ffp + 1; for( cffp = ffp + 1 ; cffp <= lffp ; cffp++)
while (cffp <= if( bind_name( cffp)[ cpos] != buf[ cpos])
lffp) { goto onward ;
if (cffp->
n_name
[cpos]
!=
buf
[cpos])
goto onward;
++cffp;
}
/* add the character */ /* add the character */
echoc( buf[ cpos++]) ; echoc( buf[ cpos++]) ;
@ -304,12 +285,11 @@ const name_bind *getname( void) {
/* << << << << << << << << << << << << << << << << << */ /* << << << << << << << << << << << << << << << << << */
} }
} }
++ffp;
} }
/* no match.....beep and onward */ /* no match.....beep and onward */
TTbeep(); TTbeep();
onward:; onward:
TTflush(); TTflush();
/* <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< */ /* <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< */
} else { } else {

View File

@ -30,7 +30,7 @@ int ectoc( int c) ;
/* Look up in names to function association table */ /* Look up in names to function association table */
const name_bind *fncmatch( char *) ; const name_bind *fncmatch( char *) ;
const name_bind *getname( void) ; const name_bind *getname( void) ;
const name_bind *getnamebind( fnp_t func) ; const char *getfncname( fnp_t func) ;
int tgetc( void) ; int tgetc( void) ;
int get1key( void) ; int get1key( void) ;

346
names.c
View File

@ -3,10 +3,10 @@
/* Name to function binding table. /* Name to function binding table.
* *
* This table gives the names of all the bindable functions * This table gives the names of all the bindable functions and their C
* and their C function address. These are used for the bind-to-key * function address. These are used for the bind-to-key function and macro
* function. * processing.
*/ */
#include "basic.h" #include "basic.h"
#include "bind.h" #include "bind.h"
@ -26,210 +26,210 @@
#include "word.h" #include "word.h"
const name_bind names[] = { const name_bind names[] = {
{"abort-command", ctrlg, 0} , {" abort-command", ctrlg} ,
{"add-mode", setemode, 0} , {" add-mode", setemode} ,
{"add-global-mode", setgmode, 0} , {" add-global-mode", setgmode} ,
#if APROP #if APROP
{"apropos", apro, 0} , {" apropos", apro} ,
#endif #endif
{"backward-character", (fnp_t) backchar, 0} , {" backward-character", (fnp_t) backchar} ,
{"begin-macro", ctlxlp, 0} , {" begin-macro", ctlxlp} ,
{"beginning-of-file", (fnp_t) gotobob, 0} , {" beginning-of-file", (fnp_t) gotobob} ,
{"beginning-of-line", (fnp_t) gotobol, 0} , {" beginning-of-line", (fnp_t) gotobol} ,
{"bind-to-key", bindtokey, 0} , {" bind-to-key", bindtokey} ,
{"buffer-position", showcpos, 0} , {" buffer-position", showcpos} ,
{"case-region-lower", lowerregion, 1} , {"!case-region-lower", lowerregion} ,
{"case-region-upper", upperregion, 1} , {"!case-region-upper", upperregion} ,
{"case-word-capitalize", capword, 1} , {"!case-word-capitalize", capword} ,
{"case-word-lower", lowerword, 1} , {"!case-word-lower", lowerword} ,
{"case-word-upper", upperword, 1} , {"!case-word-upper", upperword} ,
{"change-file-name", filename, 0} , {" change-file-name", filename} ,
{"change-screen-size", newsize, 0} , {" change-screen-size", newsize} ,
{"change-screen-width", newwidth, 0} , {" change-screen-width", newwidth} ,
{"clear-and-redraw", redraw, 0} , {" clear-and-redraw", redraw} ,
{"clear-message-line", clrmes, 0} , {" clear-message-line", clrmes} ,
{"copy-region", copyregion, 0} , {" copy-region", copyregion} ,
#if WORDPRO #if WORDPRO
{"count-words", wordcount, 0} , {" count-words", wordcount} ,
#endif #endif
{"ctlx-prefix", cex, 0} , {" ctlx-prefix", cex} ,
{"delete-blank-lines", deblank, 1} , {"!delete-blank-lines", deblank} ,
{"delete-buffer", killbuffer, 0} , {" delete-buffer", killbuffer} ,
{"delete-mode", delmode, 0} , {" delete-mode", delmode} ,
{"delete-global-mode", delgmode, 0} , {" delete-global-mode", delgmode} ,
{"delete-next-character", forwdel, 1} , {"!delete-next-character", forwdel} ,
{"delete-next-word", delfword, 1} , {"!delete-next-word", delfword} ,
{"delete-other-windows", onlywind, 0} , {" delete-other-windows", onlywind} ,
{"delete-previous-character", backdel, 1} , {"!delete-previous-character", backdel} ,
{"delete-previous-word", delbword, 1} , {"!delete-previous-word", delbword} ,
{"delete-window", delwind, 0} , {" delete-window", delwind} ,
{"describe-bindings", desbind, 0} , {" describe-bindings", desbind} ,
{"describe-key", deskey, 0} , {" describe-key", deskey} ,
#if AEDIT #if AEDIT
{"detab-line", detab, 1} , {"!detab-line", detab} ,
#endif #endif
{"end-macro", ctlxrp, 0} , {" end-macro", ctlxrp} ,
{"end-of-file", (fnp_t) gotoeob, 0} , {" end-of-file", (fnp_t) gotoeob} ,
{"end-of-line", (fnp_t) gotoeol, 0} , {" end-of-line", (fnp_t) gotoeol} ,
#if AEDIT #if AEDIT
{"entab-line", entab, 1} , {"!entab-line", entab} ,
#endif #endif
{"exchange-point-and-mark", (fnp_t) swapmark, 0} , {" exchange-point-and-mark", (fnp_t) swapmark} ,
{"execute-buffer", execbuf, 0} , {" execute-buffer", execbuf} ,
{"execute-command-line", execcmd, 0} , {" execute-command-line", execcmd} ,
{"execute-file", execfile, 0} , {" execute-file", execfile} ,
{"execute-macro", ctlxe, 0} , {" execute-macro", ctlxe} ,
{"execute-macro-1", cbuf1, 0} , {" execute-macro-1", cbuf1} ,
{"execute-macro-2", cbuf2, 0} , {" execute-macro-2", cbuf2} ,
{"execute-macro-3", cbuf3, 0} , {" execute-macro-3", cbuf3} ,
{"execute-macro-4", cbuf4, 0} , {" execute-macro-4", cbuf4} ,
{"execute-macro-5", cbuf5, 0} , {" execute-macro-5", cbuf5} ,
{"execute-macro-6", cbuf6, 0} , {" execute-macro-6", cbuf6} ,
{"execute-macro-7", cbuf7, 0} , {" execute-macro-7", cbuf7} ,
{"execute-macro-8", cbuf8, 0} , {" execute-macro-8", cbuf8} ,
{"execute-macro-9", cbuf9, 0} , {" execute-macro-9", cbuf9} ,
{"execute-macro-10", cbuf10, 0} , {" execute-macro-10", cbuf10} ,
{"execute-macro-11", cbuf11, 0} , {" execute-macro-11", cbuf11} ,
{"execute-macro-12", cbuf12, 0} , {" execute-macro-12", cbuf12} ,
{"execute-macro-13", cbuf13, 0} , {" execute-macro-13", cbuf13} ,
{"execute-macro-14", cbuf14, 0} , {" execute-macro-14", cbuf14} ,
{"execute-macro-15", cbuf15, 0} , {" execute-macro-15", cbuf15} ,
{"execute-macro-16", cbuf16, 0} , {" execute-macro-16", cbuf16} ,
{"execute-macro-17", cbuf17, 0} , {" execute-macro-17", cbuf17} ,
{"execute-macro-18", cbuf18, 0} , {" execute-macro-18", cbuf18} ,
{"execute-macro-19", cbuf19, 0} , {" execute-macro-19", cbuf19} ,
{"execute-macro-20", cbuf20, 0} , {" execute-macro-20", cbuf20} ,
{"execute-macro-21", cbuf21, 0} , {" execute-macro-21", cbuf21} ,
{"execute-macro-22", cbuf22, 0} , {" execute-macro-22", cbuf22} ,
{"execute-macro-23", cbuf23, 0} , {" execute-macro-23", cbuf23} ,
{"execute-macro-24", cbuf24, 0} , {" execute-macro-24", cbuf24} ,
{"execute-macro-25", cbuf25, 0} , {" execute-macro-25", cbuf25} ,
{"execute-macro-26", cbuf26, 0} , {" execute-macro-26", cbuf26} ,
{"execute-macro-27", cbuf27, 0} , {" execute-macro-27", cbuf27} ,
{"execute-macro-28", cbuf28, 0} , {" execute-macro-28", cbuf28} ,
{"execute-macro-29", cbuf29, 0} , {" execute-macro-29", cbuf29} ,
{"execute-macro-30", cbuf30, 0} , {" execute-macro-30", cbuf30} ,
{"execute-macro-31", cbuf31, 0} , {" execute-macro-31", cbuf31} ,
{"execute-macro-32", cbuf32, 0} , {" execute-macro-32", cbuf32} ,
{"execute-macro-33", cbuf33, 0} , {" execute-macro-33", cbuf33} ,
{"execute-macro-34", cbuf34, 0} , {" execute-macro-34", cbuf34} ,
{"execute-macro-35", cbuf35, 0} , {" execute-macro-35", cbuf35} ,
{"execute-macro-36", cbuf36, 0} , {" execute-macro-36", cbuf36} ,
{"execute-macro-37", cbuf37, 0} , {" execute-macro-37", cbuf37} ,
{"execute-macro-38", cbuf38, 0} , {" execute-macro-38", cbuf38} ,
{"execute-macro-39", cbuf39, 0} , {" execute-macro-39", cbuf39} ,
{"execute-macro-40", cbuf40, 0} , {" execute-macro-40", cbuf40} ,
{"execute-named-command", namedcmd, 0} , {" execute-named-command", namedcmd} ,
#if PROC #if PROC
{"execute-procedure", execproc, 0} , {" execute-procedure", execproc} ,
#endif #endif
{"execute-program", execprg, 0} , {" execute-program", execprg} ,
{"exit-emacs", quit, 0} , {" exit-emacs", quit} ,
#if WORDPRO #if WORDPRO
{"fill-paragraph", fillpara, 1} , {"!fill-paragraph", fillpara} ,
#endif #endif
{"filter-buffer", filter_buffer, 1} , {"!filter-buffer", filter_buffer} ,
{"find-file", filefind, 0} , {" find-file", filefind} ,
{"forward-character", (fnp_t) forwchar, 0} , {" forward-character", (fnp_t) forwchar} ,
{"goto-line", gotoline, 0} , {" goto-line", gotoline} ,
#if CFENCE #if CFENCE
{"goto-matching-fence", getfence, 0} , {" goto-matching-fence", getfence} ,
#endif #endif
{"grow-window", enlargewind, 0} , {" grow-window", enlargewind} ,
{"handle-tab", insert_tab, 0} , {"!handle-tab", insert_tab} ,
{"hunt-forward", forwhunt, 0} , {" hunt-forward", forwhunt} ,
{"hunt-backward", backhunt, 0} , {" hunt-backward", backhunt} ,
{"help", help, 0} , {" help", help} ,
{"i-shell", spawncli, 0} , {" i-shell", spawncli} ,
#if ISRCH #if ISRCH
{"incremental-search", fisearch, 0} , {" incremental-search", fisearch} ,
#endif #endif
{"insert-file", insfile, 1} , {"!insert-file", insfile} ,
{"insert-space", insspace, 1} , {"!insert-space", insspace} ,
{"insert-string", istring, 1} , {"!insert-string", istring} ,
#if WORDPRO #if WORDPRO
#if PKCODE #if PKCODE
{"justify-paragraph", justpara, 1} , {"!justify-paragraph", justpara} ,
#endif #endif
{"kill-paragraph", killpara, 1} , {"!kill-paragraph", killpara} ,
#endif #endif
{"kill-region", killregion, 1} , {"!kill-region", killregion} ,
{"kill-to-end-of-line", killtext, 1} , {"!kill-to-end-of-line", killtext} ,
{"list-buffers", listbuffers, 0} , {" list-buffers", listbuffers} ,
{"meta-prefix", metafn, 0} , {" meta-prefix", metafn} ,
{"move-window-down", mvdnwind, 0} , {" move-window-down", mvdnwind} ,
{"move-window-up", mvupwind, 0} , {" move-window-up", mvupwind} ,
{"name-buffer", namebuffer, 0} , {" name-buffer", namebuffer} ,
{"newline", insert_newline, 1} , {"!newline", insert_newline} ,
{"newline-and-indent", indent, 1} , {"!newline-and-indent", indent} ,
{"next-buffer", nextbuffer, 0} , {" next-buffer", nextbuffer} ,
{"next-line", (fnp_t) forwline, 0} , {" next-line", (fnp_t) forwline} ,
{"next-page", (fnp_t) forwpage, 0} , {" next-page", (fnp_t) forwpage} ,
#if WORDPRO #if WORDPRO
{"next-paragraph", gotoeop, 0} , {" next-paragraph", gotoeop} ,
#endif #endif
{"next-window", nextwind, 0} , {" next-window", nextwind} ,
{"next-word", forwword, 0} , {" next-word", forwword} ,
{"nop", nullproc, 0} , {" nop", nullproc} ,
{"open-line", openline, 1} , {"!open-line", openline} ,
{"overwrite-string", ovstring, 0} , {" overwrite-string", ovstring} ,
{"pipe-command", pipecmd, 0} , {" pipe-command", pipecmd} ,
{"previous-line", (fnp_t) backline, 0} , {" previous-line", (fnp_t) backline} ,
{"previous-page", (fnp_t) backpage, 0} , {" previous-page", (fnp_t) backpage} ,
#if WORDPRO #if WORDPRO
{"previous-paragraph", gotobop, 0} , {" previous-paragraph", gotobop} ,
#endif #endif
{"previous-window", prevwind, 0} , {" previous-window", prevwind} ,
{"previous-word", backword, 0} , {" previous-word", backword} ,
{"query-replace-string", qreplace, 1} , {"!query-replace-string", qreplace} ,
{"quick-exit", quickexit, 0} , {" quick-exit", quickexit} ,
{"quote-character", quote, 1} , {"!quote-character", quote} ,
{"read-file", fileread, 1} , {"!read-file", fileread} ,
{"redraw-display", reposition, 0} , {" redraw-display", reposition} ,
{"resize-window", resize, 0} , {" resize-window", resize} ,
{"restore-window", restwnd, 0} , {" restore-window", restwnd} ,
{"replace-string", sreplace, 1} , {"!replace-string", sreplace} ,
#if ISRCH #if ISRCH
{"reverse-incremental-search", risearch, 0} , {" reverse-incremental-search", risearch} ,
#endif #endif
#if PROC #if PROC
{"run", execproc, 0} , {" run", execproc} ,
#endif #endif
{"save-file", filesave, 1} , {"!save-file", filesave} ,
{"save-window", savewnd, 0} , {" save-window", savewnd} ,
{"scroll-next-up", scrnextup, 0} , {" scroll-next-up", scrnextup} ,
{"scroll-next-down", scrnextdw, 0} , {" scroll-next-down", scrnextdw} ,
{"search-forward", forwsearch, 0} , {" search-forward", forwsearch} ,
{"search-reverse", backsearch, 0} , {" search-reverse", backsearch} ,
{"select-buffer", usebuffer, 0} , {" select-buffer", usebuffer} ,
{"set", setvar, 0} , {" set", setvar} ,
{"set-fill-column", setfillcol, 0} , {" set-fill-column", setfillcol} ,
{"set-mark", (fnp_t) setmark, 0} , {" set-mark", (fnp_t) setmark} ,
{"shell-command", spawn, 0} , {" shell-command", spawn} ,
{"shrink-window", shrinkwind, 0} , {" shrink-window", shrinkwind} ,
{"split-current-window", splitwind, 0} , {" split-current-window", splitwind} ,
{"store-macro", storemac, 0} , {" store-macro", storemac} ,
#if PROC #if PROC
{"store-procedure", storeproc, 0} , {" store-procedure", storeproc} ,
#endif #endif
#if BSD | SVR4 #if BSD | SVR4
{"suspend-emacs", bktoshell, 0} , {" suspend-emacs", bktoshell} ,
#endif #endif
{"transpose-characters", (fnp_t) twiddle, 1} , {"!transpose-characters", (fnp_t) twiddle} ,
#if AEDIT #if AEDIT
{"trim-line", trim, 1} , {"!trim-line", trim} ,
#endif #endif
{"unbind-key", unbindkey, 0} , {" unbind-key", unbindkey} ,
{"universal-argument", unarg, 0} , {" universal-argument", unarg} ,
{"unmark-buffer", unmark, 0} , {" unmark-buffer", unmark} ,
{"update-screen", upscreen, 0} , {" update-screen", upscreen} ,
{"view-file", viewfile, 0} , {" view-file", viewfile} ,
{"wrap-word", wrapword, 0} , {" wrap-word", wrapword} ,
{"write-file", filewrite, 0} , {" write-file", filewrite} ,
{"write-message", writemsg, 0} , {" write-message", writemsg} ,
{"yank", yank, 1} , {"!yank", yank} ,
{"", NULL, 0} {" ", NULL}
}; };
/* end of names.c */ /* end of names.c */

View File

@ -5,11 +5,13 @@
/* Structure for the name binding table. */ /* Structure for the name binding table. */
typedef struct name_bind { typedef struct name_bind {
const char *n_name ; /* name of function key */ const char *n_name ; /* name starting with one tag character */
fnp_t n_func ; /* function name is bound to */ fnp_t n_func ; /* function the name is bound to */
char tag ; /* view mode compatibility tag */
} name_bind ; } 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 */ extern const name_bind names[] ; /* name to function table */
#endif #endif