mirror of
https://github.com/rfivet/uemacs.git
synced 2024-12-18 07:16:23 -05:00
bind: code review and minor refactoring.
basic: minor reformatting.
This commit is contained in:
parent
eaf516110f
commit
720603ac8e
1
basic.c
1
basic.c
@ -320,6 +320,7 @@ boolean setmark( int f, int n) {
|
|||||||
return TRUE ;
|
return TRUE ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Swap the values of "." and "mark" in the current window. If no mark as
|
/* Swap the values of "." and "mark" in the current window. If no mark as
|
||||||
been previously set, set it. Bound to C-X C-X exchange-point-and-mark.
|
been previously set, set it. Bound to C-X C-X exchange-point-and-mark.
|
||||||
*/
|
*/
|
||||||
|
389
bind.c
389
bind.c
@ -9,24 +9,22 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "estruct.h"
|
|
||||||
#include "bindable.h"
|
#include "bindable.h"
|
||||||
#include "buffer.h"
|
#include "buffer.h"
|
||||||
#include "display.h"
|
#include "display.h" /* upmode(), ostring() */
|
||||||
#include "exec.h"
|
#include "exec.h"
|
||||||
#include "file.h"
|
#include "file.h"
|
||||||
#include "flook.h"
|
#include "flook.h"
|
||||||
#include "input.h"
|
#include "input.h"
|
||||||
#include "line.h"
|
#include "line.h"
|
||||||
|
#include "mlout.h"
|
||||||
#include "names.h"
|
#include "names.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "window.h"
|
#include "window.h"
|
||||||
|
|
||||||
|
|
||||||
static int buildlist( char *mstring) ;
|
static int buildlist( char *mstring) ;
|
||||||
static char *cmdstr( unsigned c, char *seq) ;
|
static char *cmdstr( unsigned c, char *seq) ;
|
||||||
static unsigned int getckey( int mflag) ;
|
static unsigned int getckey( int mflag) ;
|
||||||
@ -34,124 +32,122 @@ static unsigned int stock( char *keyname) ;
|
|||||||
static const char *getfname( unsigned keycode, const char *failmsg) ;
|
static const char *getfname( unsigned keycode, const char *failmsg) ;
|
||||||
|
|
||||||
|
|
||||||
static boolean cmdfail( const char *msg) {
|
/* give me some help!!!! bring up a fake buffer and read the help file into
|
||||||
mlwrite( "%s", msg) ;
|
it with view mode
|
||||||
return FALSE ;
|
*/
|
||||||
}
|
|
||||||
|
|
||||||
BINDABLE( help) {
|
BINDABLE( help) {
|
||||||
/* give me some help!!!!
|
|
||||||
bring up a fake buffer and read the help file into it with view mode */
|
|
||||||
char *fname = NULL; /* ptr to file returned by flook() */
|
char *fname = NULL; /* ptr to file returned by flook() */
|
||||||
|
|
||||||
/* first check if we are already here */
|
/* first check if we are already here */
|
||||||
buffer_p bp = bfind( hlpfname, FALSE, BFINVS);
|
buffer_p bp = bfind( hlpfname, FALSE, BFINVS);
|
||||||
if( bp == curbp)
|
if( bp == curbp)
|
||||||
return TRUE ;
|
return TRUE ;
|
||||||
|
|
||||||
if( bp == NULL) {
|
if( bp == NULL) {
|
||||||
fname = flook( hlpfname, FALSE) ;
|
fname = flook( hlpfname, FALSE) ;
|
||||||
if( fname == NULL)
|
if( fname == NULL)
|
||||||
return cmdfail( "(Help file is not online)") ;
|
return mloutfail( "(Help file is not online)") ;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* split the current window to make room for the help stuff */
|
/* split the current window to make room for the help stuff */
|
||||||
if( wheadp->w_wndp == NULL /* One window */
|
if( wheadp->w_wndp == NULL /* One window */
|
||||||
&& splitwind( FALSE, 1) == FALSE) /* Split it */
|
&& splitwind( FALSE, 1) == FALSE) /* Split it */
|
||||||
return FALSE ;
|
return FALSE ;
|
||||||
|
|
||||||
if (bp == NULL) {
|
if( bp == NULL) {
|
||||||
/* and read the stuff in */
|
/* and read the stuff in */
|
||||||
if (getfile(fname, FALSE) == FALSE)
|
if( getfile( fname, FALSE) == FALSE)
|
||||||
return FALSE;
|
return FALSE ;
|
||||||
} else
|
} else
|
||||||
swbuffer( bp) ;
|
swbuffer( bp) ;
|
||||||
|
|
||||||
/* make this window in VIEW mode, update all mode lines */
|
/* make this window in VIEW mode, update all mode lines */
|
||||||
curwp->w_bufp->b_mode |= MDVIEW;
|
curwp->w_bufp->b_mode |= MDVIEW;
|
||||||
curwp->w_bufp->b_flag |= BFINVS;
|
curwp->w_bufp->b_flag |= BFINVS;
|
||||||
upmode() ;
|
upmode() ;
|
||||||
return TRUE;
|
return TRUE ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static boolean invalidkey( void) {
|
static boolean invalidkey( void) {
|
||||||
return cmdfail( "(Invalid key sequence)") ;
|
return mloutfail( "(Invalid key sequence)") ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* describe the command for a certain key */
|
/* describe the command for a certain key */
|
||||||
BINDABLE( deskey) {
|
BINDABLE( deskey) {
|
||||||
const char cmdname[] = "describe-key" ;
|
const char cmdname[] = "describe-key" ;
|
||||||
char outseq[ NSTRING] ; /* output buffer for command sequence */
|
char outseq[ 8] ; /* output buffer for keystroke sequence */
|
||||||
|
|
||||||
/* prompt the user to type a key to describe */
|
/* prompt the user to type a key to describe */
|
||||||
mlwrite( "%s: ", cmdname) ;
|
mloutfmt( "%s: ", cmdname) ;
|
||||||
|
|
||||||
/* get the command sequence to describe
|
/* get the command sequence to describe
|
||||||
* change it to something we can print as well */
|
* change it to something we can print as well */
|
||||||
unsigned keycode = getckey( FALSE) ;
|
unsigned keycode = getckey( FALSE) ;
|
||||||
if( keycode == (unsigned) ~0)
|
if( keycode == (unsigned) ~0)
|
||||||
return invalidkey() ;
|
return invalidkey() ;
|
||||||
|
|
||||||
/* output the command sequence */
|
/* output the command sequence */
|
||||||
mlwrite( "%s %s: 0x%x, %s", cmdname, cmdstr( keycode, outseq), keycode,
|
mloutfmt( "%s %s: 0x%x, %s", cmdname, cmdstr( keycode, outseq), keycode,
|
||||||
getfname( keycode, "Not Bound")) ;
|
getfname( keycode, "Not Bound")) ;
|
||||||
return TRUE ;
|
return TRUE ;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* bindtokey:
|
/* bindtokey:
|
||||||
* add a new key to the key binding table
|
* add a new key to the key binding table
|
||||||
*
|
*
|
||||||
* int f, n; command arguments [IGNORED]
|
* int f, n; command arguments [IGNORED]
|
||||||
*/
|
*/
|
||||||
BINDABLE( bindtokey) {
|
BINDABLE( bindtokey) {
|
||||||
kbind_p ktp ; /* pointer into the command table */
|
kbind_p ktp ; /* pointer into the command table */
|
||||||
char outseq[ 80] ; /* output buffer for keystroke sequence */
|
char outseq[ 8] ; /* output buffer for keystroke sequence */
|
||||||
|
|
||||||
/* prompt the user to type in a key to bind */
|
/* prompt the user to type in a key to bind */
|
||||||
mlwrite("bind-to-key: ");
|
mloutstr( "bind-to-key: ") ;
|
||||||
|
|
||||||
/* get the function name to bind it to */
|
/* get the function name to bind it to */
|
||||||
nbind_p nbp = getname() ;
|
nbind_p nbp = getname() ;
|
||||||
if( nbp == NULL) /* abort */
|
if( nbp == NULL) /* abort */
|
||||||
return FALSE ;
|
return FALSE ;
|
||||||
|
|
||||||
fnp_t kfunc = nbp->n_func ;
|
fnp_t kfunc = nbp->n_func ;
|
||||||
if( kfunc == NULL)
|
if( kfunc == NULL)
|
||||||
return cmdfail( "(No such function)") ;
|
return mloutfail( "(No such function)") ;
|
||||||
|
|
||||||
mlwrite( "bind-to-key %s: ", bind_name( nbp)) ;
|
mloutfmt( "bind-to-key %s: ", bind_name( nbp)) ;
|
||||||
|
|
||||||
/* get the command sequence to bind */
|
/* get the command sequence to bind */
|
||||||
boolean prefix_f = (kfunc == metafn) || (kfunc == cex) ||
|
boolean prefix_f = (kfunc == metafn) || (kfunc == cex) ||
|
||||||
(kfunc == unarg) || (kfunc == ctrlg) ;
|
(kfunc == unarg) || (kfunc == ctrlg) ;
|
||||||
int c = getckey( prefix_f) ;
|
int c = getckey( prefix_f) ;
|
||||||
if( c == ~0)
|
if( c == ~0)
|
||||||
return invalidkey() ;
|
return invalidkey() ;
|
||||||
|
|
||||||
/* change it to something we can print as well */
|
/* change it to something we can print as well */
|
||||||
/* and dump it out */
|
/* and dump it out */
|
||||||
ostring( cmdstr( c, outseq)) ;
|
ostring( cmdstr( c, outseq)) ;
|
||||||
|
|
||||||
/* key sequence can't be an active prefix key */
|
/* key sequence can't be an active prefix key */
|
||||||
if( c == metac || c == ctlxc || c == reptc || c == abortc) {
|
if( c == metac || c == ctlxc || c == reptc || c == abortc) {
|
||||||
if( (c == metac && kfunc == metafn)
|
if( (c == metac && kfunc == metafn)
|
||||||
|| (c == ctlxc && kfunc == cex)
|
|| (c == ctlxc && kfunc == cex)
|
||||||
|| (c == reptc && kfunc == unarg)
|
|| (c == reptc && kfunc == unarg)
|
||||||
|| (c == abortc && kfunc == ctrlg))
|
|| (c == abortc && kfunc == ctrlg))
|
||||||
return TRUE ;
|
return TRUE ; /* be silent if keep current */
|
||||||
|
|
||||||
return cmdfail( "(Can't bind to active prefix)") ;
|
return mloutfail( "(Can't bind to active prefix)") ;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* if the function is a prefix key */
|
/* if the function is a prefix key */
|
||||||
if( prefix_f) {
|
if( prefix_f) {
|
||||||
/* remove existing binding for the prefix */
|
/* remove existing binding for the prefix */
|
||||||
for( ktp = keytab ; ktp->k_code != 0 ; ktp++)
|
for( ktp = keytab ; ktp->k_code != 0 ; ktp++)
|
||||||
if( ktp->k_nbp == nbp) {
|
if( ktp->k_nbp == nbp) {
|
||||||
delkeybinding( ktp->k_code) ;
|
delkeybinding( ktp->k_code) ;
|
||||||
break ;
|
break ;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* set the appropriate global prefix variable */
|
/* set the appropriate global prefix variable */
|
||||||
if( kfunc == metafn)
|
if( kfunc == metafn)
|
||||||
@ -164,49 +160,47 @@ BINDABLE( bindtokey) {
|
|||||||
abortc = c ;
|
abortc = c ;
|
||||||
}
|
}
|
||||||
|
|
||||||
ktp = setkeybinding( c, nbp) ;
|
ktp = setkeybinding( c, nbp) ;
|
||||||
if( ktp->k_code == 0)
|
if( ktp->k_code == 0)
|
||||||
return cmdfail( "Binding table FULL!") ;
|
return mloutfail( "Binding table FULL!") ;
|
||||||
|
|
||||||
return TRUE ;
|
return TRUE ;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* unbindkey:
|
/* unbindkey:
|
||||||
* delete a key from the key binding table
|
* delete a key from the key binding table
|
||||||
*
|
*
|
||||||
* int f, n; command arguments [IGNORED]
|
* int f, n; command arguments [IGNORED]
|
||||||
*/
|
*/
|
||||||
BINDABLE( unbindkey) {
|
BINDABLE( unbindkey) {
|
||||||
char outseq[ 80] ; /* output buffer for keystroke sequence */
|
char outseq[ 8] ; /* output buffer for keystroke sequence */
|
||||||
|
|
||||||
/* prompt the user to type in a key to unbind */
|
/* prompt the user to type in a key to unbind */
|
||||||
mlwrite( "unbind-key: ") ;
|
mloutstr( "unbind-key: ") ;
|
||||||
|
|
||||||
/* get the command sequence to unbind */
|
/* get the command sequence to unbind */
|
||||||
int c = getckey( FALSE) ; /* get a command sequence */
|
int c = getckey( FALSE) ; /* get a command sequence */
|
||||||
if( c == ~0)
|
if( c == ~0)
|
||||||
return invalidkey() ;
|
return invalidkey() ;
|
||||||
|
|
||||||
/* change it to something we can print as well */
|
/* change it to something we can print as well */
|
||||||
/* and dump it out */
|
/* and dump it out */
|
||||||
ostring( cmdstr( c, outseq)) ;
|
ostring( cmdstr( c, outseq)) ;
|
||||||
|
|
||||||
/* prefix key sequence can't be undound, just redefined */
|
/* prefix key sequence can't be undound, just redefined */
|
||||||
if( c == reptc || c == abortc)
|
if( c == reptc || c == abortc)
|
||||||
return cmdfail( "(Can't unbind prefix)") ;
|
return mloutfail( "(Can't unbind prefix)") ;
|
||||||
|
|
||||||
/* if it isn't bound, bitch */
|
/* if it isn't bound, bitch */
|
||||||
if( delkeybinding( c) == FALSE) {
|
if( delkeybinding( c) == FALSE)
|
||||||
mlwrite( "(Key not bound)") ;
|
return mloutfail( "(Key not bound)") ;
|
||||||
return FALSE ;
|
|
||||||
}
|
|
||||||
|
|
||||||
return TRUE ;
|
return TRUE ;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* does source include sub?
|
/* does source include sub?
|
||||||
*
|
*
|
||||||
* char *source; string to search in
|
* char *source; string to search in
|
||||||
* char *sub; substring to look for
|
* char *sub; substring to look for
|
||||||
@ -214,8 +208,8 @@ BINDABLE( unbindkey) {
|
|||||||
static boolean strinc( const char *source, const char *sub) {
|
static boolean strinc( const char *source, const char *sub) {
|
||||||
/* for each character in the source string */
|
/* for each character in the source string */
|
||||||
for( ; *source ; source++) {
|
for( ; *source ; source++) {
|
||||||
const char *nxtsp ; /* next ptr into source */
|
const char *nxtsp ; /* next ptr into source */
|
||||||
const char *tp ; /* ptr into substring */
|
const char *tp ; /* ptr into substring */
|
||||||
|
|
||||||
nxtsp = source;
|
nxtsp = source;
|
||||||
|
|
||||||
@ -232,6 +226,7 @@ static boolean strinc( const char *source, const char *sub) {
|
|||||||
return FALSE ;
|
return FALSE ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* describe bindings
|
/* describe bindings
|
||||||
* bring up a fake buffer and list the key bindings
|
* bring up a fake buffer and list the key bindings
|
||||||
* into it with view mode
|
* into it with view mode
|
||||||
@ -240,168 +235,166 @@ BINDABLE( desbind) {
|
|||||||
return buildlist( "") ;
|
return buildlist( "") ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Apropos (List functions that match a substring) */
|
/* Apropos (List functions that match a substring) */
|
||||||
BINDABLE( apro) {
|
BINDABLE( apro) {
|
||||||
char *mstring ; /* string to match cmd names to */
|
char *mstring ; /* string to match cmd names to */
|
||||||
|
|
||||||
int status = newmlarg( &mstring, "apropos: ", 0) ;
|
int status = newmlarg( &mstring, "apropos: ", 0) ;
|
||||||
if( status == TRUE) {
|
if( status == TRUE) {
|
||||||
status = buildlist( mstring) ;
|
status = buildlist( mstring) ;
|
||||||
free( mstring) ;
|
free( mstring) ;
|
||||||
} else if( status == FALSE)
|
} else if( status == FALSE)
|
||||||
status = buildlist( "") ; /* build list of all commands */
|
status = buildlist( "") ; /* build list of all commands */
|
||||||
|
|
||||||
return status ;
|
return status ;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* build a binding list (limited or full)
|
/* build a binding list (limited or full)
|
||||||
*
|
*
|
||||||
* char *mstring; match string if a partial list, "" matches all
|
* char *mstring; match string if a partial list, "" matches all
|
||||||
*/
|
*/
|
||||||
static int buildlist( char *mstring) {
|
static int buildlist( char *mstring) {
|
||||||
struct window *wp; /* scanning pointer to windows */
|
#define PADDING 28
|
||||||
kbind_p ktp; /* pointer into the command table */
|
char outseq[ PADDING + 8] ; /* output buffer for command + keystroke */
|
||||||
nbind_p nptr;/* pointer into the name binding table */
|
|
||||||
struct buffer *bp; /* buffer to put binding list into */
|
|
||||||
char outseq[80]; /* output buffer for keystroke sequence */
|
|
||||||
|
|
||||||
/* split the current window to make room for the binding list */
|
/* split the current window to make room for the binding list */
|
||||||
if( wheadp->w_wndp == NULL /* One window */
|
if( wheadp->w_wndp == NULL /* One window */
|
||||||
&& splitwind( FALSE, 1) == FALSE) /* Split it */
|
&& splitwind( FALSE, 1) == FALSE) /* Split it */
|
||||||
return FALSE;
|
return FALSE ;
|
||||||
|
|
||||||
/* and get a buffer for it */
|
/* and get a buffer for it */
|
||||||
bp = bfind("*Binding list*", TRUE, 0);
|
buffer_p bp = bfind( "*Binding list*", TRUE, 0) ;
|
||||||
if( bp == NULL || bclear( bp) == FALSE)
|
if( bp == NULL || bclear( bp) == FALSE)
|
||||||
return cmdfail( "Can't display binding list") ;
|
return mloutfail( "Can't display binding list") ;
|
||||||
|
|
||||||
/* let us know this is in progress */
|
/* let us know this is in progress */
|
||||||
mlwrite("(Building binding list)");
|
mloutstr( "(Building binding list)") ;
|
||||||
|
|
||||||
/* disconnect the current buffer */
|
/* disconnect the current buffer */
|
||||||
if (--curbp->b_nwnd == 0) { /* Last use. */
|
if( --curbp->b_nwnd == 0) { /* Last use. */
|
||||||
curbp->b_dotp = curwp->w_dotp;
|
curbp->b_dotp = curwp->w_dotp ;
|
||||||
curbp->b_doto = curwp->w_doto;
|
curbp->b_doto = curwp->w_doto ;
|
||||||
curbp->b_markp = curwp->w_markp;
|
curbp->b_markp = curwp->w_markp ;
|
||||||
curbp->b_marko = curwp->w_marko;
|
curbp->b_marko = curwp->w_marko ;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* connect the current window to this buffer */
|
/* connect the current window to this buffer */
|
||||||
curbp = bp; /* make this buffer current in current window */
|
curbp = bp ; /* make this buffer current in current window */
|
||||||
bp->b_mode = 0; /* no modes active in binding list */
|
bp->b_mode = 0 ; /* no modes active in binding list */
|
||||||
bp->b_nwnd++; /* mark us as more in use */
|
bp->b_nwnd++ ; /* mark us as more in use */
|
||||||
wp = curwp;
|
window_p wp = curwp ;
|
||||||
wp->w_bufp = bp;
|
wp->w_bufp = bp ;
|
||||||
wp->w_linep = bp->b_linep;
|
wp->w_linep = bp->b_linep ;
|
||||||
wp->w_flag = WFHARD | WFFORCE;
|
wp->w_flag = WFHARD | WFFORCE ;
|
||||||
wp->w_dotp = bp->b_dotp;
|
wp->w_dotp = bp->b_dotp ;
|
||||||
wp->w_doto = bp->b_doto;
|
wp->w_doto = bp->b_doto ;
|
||||||
wp->w_markp = NULL;
|
wp->w_markp = NULL ;
|
||||||
wp->w_marko = 0;
|
wp->w_marko = 0 ;
|
||||||
|
|
||||||
/* build the contents of this window, inserting it line by line */
|
/* build the contents of this window, inserting it line by line */
|
||||||
for( nptr = names ; nptr->n_func != NULL ; nptr++) {
|
for( nbind_p nptr = names ; nptr->n_func != NULL ; nptr++) {
|
||||||
int cpos ; /* current position to use in outseq */
|
int cpos ; /* current position to use in outseq */
|
||||||
|
|
||||||
/* 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( bind_name( nptr), mstring) == FALSE)
|
if( *mstring && strinc( bind_name( nptr), mstring) == FALSE)
|
||||||
continue ;
|
continue ;
|
||||||
|
|
||||||
/* add in the command name */
|
/* add in the command name */
|
||||||
mystrscpy( outseq, bind_name( nptr), 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 */
|
||||||
for( ktp = keytab ; ktp->k_code != 0 ; ktp++) {
|
for( kbind_p ktp = keytab ; ktp->k_code != 0 ; ktp++) {
|
||||||
if( ktp->k_nbp == nptr) {
|
if( ktp->k_nbp == nptr) {
|
||||||
/* padd out some spaces */
|
/* padd out some spaces */
|
||||||
while (cpos < 28)
|
while( cpos < PADDING)
|
||||||
outseq[cpos++] = ' ';
|
outseq[ cpos++] = ' ' ;
|
||||||
|
|
||||||
/* add in the command sequence */
|
/* add in the command sequence */
|
||||||
cmdstr(ktp->k_code, &outseq[cpos]);
|
cmdstr( ktp->k_code, &outseq[ cpos]) ;
|
||||||
strcat(outseq, "\n");
|
strcat( outseq, "\n") ;
|
||||||
|
|
||||||
/* and add it as a line into the buffer */
|
/* and add it as a line into the buffer */
|
||||||
if (linstr(outseq) != TRUE)
|
if( linstr( outseq) != TRUE)
|
||||||
return FALSE;
|
return FALSE ;
|
||||||
|
|
||||||
cpos = 0; /* and clear the line */
|
cpos = 0 ; /* and clear the line */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* if no key was bound, we need to dump it anyway */
|
/* if no key was bound, we need to dump it anyway */
|
||||||
if (cpos > 0) {
|
if( cpos > 0) {
|
||||||
outseq[cpos++] = '\n';
|
outseq[ cpos++] = '\n';
|
||||||
outseq[cpos] = 0;
|
outseq[ cpos] = 0;
|
||||||
if (linstr(outseq) != TRUE)
|
if( linstr( outseq) != TRUE)
|
||||||
return FALSE;
|
return FALSE ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bp->b_mode |= MDVIEW; /* put this buffer view mode */
|
bp->b_mode |= MDVIEW ; /* put this buffer view mode */
|
||||||
bp->b_flag &= ~BFCHG; /* don't flag this as a change */
|
bp->b_flag &= ~BFCHG ; /* don't flag this as a change */
|
||||||
wp->w_dotp = lforw(bp->b_linep); /* back to the beginning */
|
wp->w_dotp = lforw( bp->b_linep) ; /* back to the beginning */
|
||||||
wp->w_doto = 0;
|
wp->w_doto = 0 ;
|
||||||
upmode() ; /* and update ALL mode lines */
|
upmode() ; /* and update ALL mode lines */
|
||||||
mlwrite(""); /* clear the mode line */
|
mloutstr( "") ; /* clear the mode line */
|
||||||
return TRUE;
|
return TRUE ;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* get a command key sequence from the keyboard
|
/* get a command key sequence from the keyboard
|
||||||
*
|
*
|
||||||
* int mflag; going for a meta sequence?
|
* int mflag; going for a meta sequence?
|
||||||
* returns ~0 on failure
|
* returns ~0 on failure
|
||||||
*/
|
*/
|
||||||
static unsigned int getckey( int mflag) {
|
static unsigned int getckey( int mflag) {
|
||||||
unsigned int c ; /* character fetched */
|
unsigned int c ; /* character fetched */
|
||||||
|
|
||||||
/* check to see if we are executing a command line */
|
/* check to see if we are executing a command line */
|
||||||
if( clexec) {
|
if( clexec) {
|
||||||
char *tok = getnewtokval() ; /* get the next token */
|
char *tok = getnewtokval() ; /* get the next token */
|
||||||
if( tok == NULL)
|
if( tok == NULL)
|
||||||
c = ~0 ; /* return invalid key on failure */
|
c = ~0 ; /* return invalid key on failure */
|
||||||
else {
|
else {
|
||||||
c = stock( tok) ;
|
c = stock( tok) ;
|
||||||
free( tok) ;
|
free( tok) ;
|
||||||
}
|
}
|
||||||
} else { /* or the normal way */
|
} else { /* or the normal way */
|
||||||
if( mflag)
|
if( mflag)
|
||||||
c = get1key() ;
|
c = get1key() ;
|
||||||
else
|
else
|
||||||
c = getcmd() ;
|
c = getcmd() ;
|
||||||
}
|
}
|
||||||
|
|
||||||
return c ;
|
return c ;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* execute the startup file
|
/* execute the startup file
|
||||||
*
|
*
|
||||||
* char *fname; name of startup file (null if default)
|
* char *fname; name of startup file (null if default)
|
||||||
*/
|
*/
|
||||||
int startup( const char *fname) {
|
int startup( const char *fname) {
|
||||||
if( !fname || *fname == 0) /* use default if empty parameter */
|
if( !fname || *fname == 0) /* use default if empty parameter */
|
||||||
fname = rcfname ;
|
fname = rcfname ;
|
||||||
|
|
||||||
fname = flook( fname, TRUE) ; /* look up the startup file */
|
fname = flook( fname, TRUE) ; /* look up the startup file */
|
||||||
if( fname == NULL) /* if it isn't around, don't sweat it */
|
if( fname == NULL) /* if it isn't around, don't sweat it */
|
||||||
return TRUE ;
|
return TRUE ;
|
||||||
|
|
||||||
return dofile( fname) ; /* otherwise, execute the sucker */
|
return dofile( fname) ; /* otherwise, execute the sucker */
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* change a key command to a string we can print out
|
/* change a key command to a string we can print out
|
||||||
*
|
*
|
||||||
* int c; sequence to translate
|
* int c; sequence to translate
|
||||||
* char *seq; destination string for sequence
|
* char *seq; destination string for sequence
|
||||||
*/
|
*/
|
||||||
static char *cmdstr( unsigned c, char *seq) {
|
static char *cmdstr( unsigned c, char *seq) {
|
||||||
char *ptr = seq ; /* pointer into current position in sequence */
|
char *ptr = seq ; /* pointer into current position in sequence */
|
||||||
|
|
||||||
/* apply meta sequence if needed */
|
/* apply meta sequence if needed */
|
||||||
if( c & META) {
|
if( c & META) {
|
||||||
@ -411,8 +404,8 @@ static char *cmdstr( unsigned c, char *seq) {
|
|||||||
|
|
||||||
/* apply ^X sequence if needed */
|
/* apply ^X sequence if needed */
|
||||||
if( c & CTLX) {
|
if( c & CTLX) {
|
||||||
if( ctlxc & CTRL)
|
if( ctlxc & CTRL)
|
||||||
*ptr++ = '^' ;
|
*ptr++ = '^' ;
|
||||||
|
|
||||||
*ptr++ = ctlxc & ~PRFXMASK ;
|
*ptr++ = ctlxc & ~PRFXMASK ;
|
||||||
}
|
}
|
||||||
@ -428,22 +421,24 @@ static char *cmdstr( unsigned c, char *seq) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* and output the final sequence */
|
/* and output the final sequence */
|
||||||
ptr += unicode_to_utf8( c & ~PRFXMASK, ptr) ;
|
ptr += unicode_to_utf8( c & ~PRFXMASK, ptr) ;
|
||||||
*ptr = 0 ; /* terminate the string */
|
*ptr = 0 ; /* terminate the string */
|
||||||
return seq ;
|
return seq ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static const char *getfname( unsigned keycode, const char *failmsg) {
|
static const char *getfname( unsigned keycode, const char *failmsg) {
|
||||||
/* takes a key code and gets the name of the function bound to it */
|
/* takes a key code and gets the name of the function bound to it */
|
||||||
kbind_p kbp = getkeybinding( keycode) ;
|
kbind_p kbp = getkeybinding( keycode) ;
|
||||||
if( kbp->k_code == 0)
|
if( kbp->k_code == 0)
|
||||||
return failmsg ;
|
return failmsg ;
|
||||||
|
|
||||||
const char *found = bind_name( kbp->k_nbp) ;
|
const char *found = bind_name( kbp->k_nbp) ;
|
||||||
assert( *found) ;
|
assert( *found) ;
|
||||||
return found ;
|
return found ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* stock:
|
/* stock:
|
||||||
* String key name TO Command Key
|
* String key name TO Command Key
|
||||||
*
|
*
|
||||||
@ -477,16 +472,16 @@ static unsigned int stock( char *keyname) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* only one character left to parse */
|
/* only one character left to parse */
|
||||||
if( !*keyname || keyname[1])
|
if( !*keyname || keyname[1])
|
||||||
return ~0 ;
|
return ~0 ;
|
||||||
|
|
||||||
/* only way to redefine ^X is by quoting binary value */
|
/* only way to redefine ^X is by quoting binary value */
|
||||||
if( *keyname < 32 || *keyname == 0x7F) {
|
if( *keyname < 32 || *keyname == 0x7F) {
|
||||||
c |= CTRL ;
|
c |= CTRL ;
|
||||||
*keyname ^= 0x40 ;
|
*keyname ^= 0x40 ;
|
||||||
} else if( c && !(c & SPEC)
|
} else if( c && !(c & SPEC)
|
||||||
&& *keyname >= 'a' && *keyname <= 'z')
|
&& *keyname >= 'a' && *keyname <= 'z')
|
||||||
/* make sure we are not lower case (not with function keys) */
|
/* make sure we are not lower case (not with function keys) */
|
||||||
*keyname -= 32 ;
|
*keyname -= 32 ;
|
||||||
|
|
||||||
/* the final sequence... */
|
/* the final sequence... */
|
||||||
@ -494,19 +489,19 @@ static unsigned int stock( char *keyname) {
|
|||||||
return c ;
|
return c ;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* string key name to binding name....
|
/* string key name to binding name....
|
||||||
*
|
*
|
||||||
* char *skey; name of key to get binding for
|
* char *skey; name of key to get binding for
|
||||||
*/
|
*/
|
||||||
const char *transbind( char *skey) {
|
const char *transbind( char *skey) {
|
||||||
static const char failmsg[] = "ERROR" ;
|
static const char failmsg[] = "ERROR" ;
|
||||||
|
|
||||||
unsigned c = stock( skey) ;
|
unsigned c = stock( skey) ;
|
||||||
if( c == (unsigned) ~0)
|
if( c == (unsigned) ~0)
|
||||||
return failmsg ;
|
return failmsg ;
|
||||||
else
|
else
|
||||||
return getfname( c, failmsg) ;
|
return getfname( c, failmsg) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* end of bind.c */
|
/* end of bind.c */
|
||||||
|
6
bind.h
6
bind.h
@ -1,3 +1,5 @@
|
|||||||
|
/* bind.h -- bindable functions dealing with name and key bindings */
|
||||||
|
|
||||||
#ifndef _BIND_H_
|
#ifndef _BIND_H_
|
||||||
#define _BIND_H_
|
#define _BIND_H_
|
||||||
|
|
||||||
@ -14,6 +16,8 @@ BINDABLE( unbindkey) ;
|
|||||||
int startup( const char *fname) ;
|
int startup( const char *fname) ;
|
||||||
|
|
||||||
/* find a key to function association in the key to function mapping table */
|
/* find a key to function association in the key to function mapping table */
|
||||||
const char *transbind( char *skey) ; /* by string representation of key */
|
const char *transbind( char *skey) ; /* by string representation of key */
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* end of bind.h */
|
||||||
|
Loading…
Reference in New Issue
Block a user