mirror of
https://github.com/rfivet/uemacs.git
synced 2024-12-23 17:46:23 -05:00
Review execute keystroke handling logic.
This commit is contained in:
parent
ee667b25ed
commit
5c6aac1ae9
175
execute.c
175
execute.c
@ -205,102 +205,99 @@ static void fmatch( int ch) {
|
|||||||
* and arranges to move it to the "lastflag", so that the next command can
|
* and arranges to move it to the "lastflag", so that the next command can
|
||||||
* look at it. Return the status of command.
|
* look at it. Return the status of command.
|
||||||
*/
|
*/
|
||||||
int execute(int c, int f, int n)
|
int execute( int c, int f, int n) {
|
||||||
{
|
int status ;
|
||||||
int status;
|
fn_t execfunc ;
|
||||||
fn_t execfunc;
|
|
||||||
|
|
||||||
/* if the keystroke is a bound function...do it */
|
/* if the keystroke is a bound function...do it */
|
||||||
execfunc = getbind(c);
|
execfunc = getbind( c) ;
|
||||||
if (execfunc != NULL) {
|
if( execfunc != NULL) {
|
||||||
thisflag = 0;
|
thisflag = 0 ;
|
||||||
status = (*execfunc) (f, n);
|
status = execfunc( f, n) ;
|
||||||
lastflag = thisflag;
|
lastflag = thisflag ;
|
||||||
return status;
|
return status ;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* keystroke not bound => self insert, check if buffer is read only */
|
/* non insertable character can only be bound to function */
|
||||||
if (curbp->b_mode & MDVIEW)
|
if( c < 0x20
|
||||||
|
|| (c >= 0x7F && c < 0xA0)
|
||||||
|
|| c > 0x10FFFF) { /* last valid unicode */
|
||||||
|
lastflag = 0 ; /* Fake last flags. */
|
||||||
|
mloutfmt( "%B(Key not bound)") ; /* Complain */
|
||||||
|
return FALSE ;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* insertable character => self insert, check if buffer is read only */
|
||||||
|
if( curbp->b_mode & MDVIEW) {
|
||||||
|
lastflag = 0 ;
|
||||||
return rdonly() ;
|
return rdonly() ;
|
||||||
|
|
||||||
/*
|
|
||||||
* If a space was typed, fill column is defined, the argument is non-
|
|
||||||
* negative, wrap mode is enabled, and we are now past fill column,
|
|
||||||
* and we are not read-only, perform word wrap.
|
|
||||||
*/
|
|
||||||
if (c == ' ' && (curwp->w_bufp->b_mode & MDWRAP) && fillcol > 0 &&
|
|
||||||
n >= 0 && getccol(FALSE) > fillcol &&
|
|
||||||
(curwp->w_bufp->b_mode & MDVIEW) == FALSE)
|
|
||||||
execute(META | SPEC | 'W', FALSE, 1);
|
|
||||||
|
|
||||||
#if PKCODE
|
|
||||||
if ((c >= 0x20 && c <= 0x7E) /* Self inserting. */
|
|
||||||
#if IBMPC
|
|
||||||
|| (c >= 0x80 && c <= 0xFE)) {
|
|
||||||
#else
|
|
||||||
#if VMS || BSD || USG /* 8BIT P.K. */
|
|
||||||
|| (c >= 0xA0 && c <= 0x10FFFF)) {
|
|
||||||
#else
|
|
||||||
) {
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
#else
|
|
||||||
if ((c >= 0x20 && c <= 0xFF)) { /* Self inserting. */
|
|
||||||
#endif
|
|
||||||
if (n <= 0) { /* Fenceposts. */
|
|
||||||
lastflag = 0;
|
|
||||||
return n < 0 ? FALSE : TRUE;
|
|
||||||
}
|
|
||||||
thisflag = 0; /* For the future. */
|
|
||||||
|
|
||||||
/* if we are in overwrite mode, not at eol,
|
|
||||||
and next char is not a tab or we are at a tab stop,
|
|
||||||
delete a char forword */
|
|
||||||
if (curwp->w_bufp->b_mode & MDOVER &&
|
|
||||||
curwp->w_doto < curwp->w_dotp->l_used &&
|
|
||||||
(lgetc(curwp->w_dotp, curwp->w_doto) != '\t' ||
|
|
||||||
((curwp->w_doto) % tabwidth) == (tabwidth - 1)))
|
|
||||||
ldelchar(1, FALSE);
|
|
||||||
|
|
||||||
/* do the appropriate insertion */
|
|
||||||
switch( c) {
|
|
||||||
case '}':
|
|
||||||
case ']':
|
|
||||||
case ')':
|
|
||||||
case '#':
|
|
||||||
if( (curbp->b_mode & MDCMOD) != 0) {
|
|
||||||
if( c == '#')
|
|
||||||
status = inspound( n) ;
|
|
||||||
else {
|
|
||||||
status = insbrace( n, c) ;
|
|
||||||
#if CFENCE
|
|
||||||
if( status == TRUE)
|
|
||||||
fmatch( c) ; /* check for CMODE fence matching */
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
break ;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
status = linsert( n, c) ;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* check auto-save mode */
|
|
||||||
if (curbp->b_mode & MDASAVE)
|
|
||||||
if (--gacount == 0) {
|
|
||||||
/* and save the file if needed */
|
|
||||||
upscreen(FALSE, 0);
|
|
||||||
filesave(FALSE, 0);
|
|
||||||
gacount = gasave;
|
|
||||||
}
|
|
||||||
|
|
||||||
lastflag = thisflag;
|
|
||||||
return status;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
lastflag = 0 ; /* Fake last flags. */
|
/* check valid count */
|
||||||
mloutfmt( "%B(Key not bound)") ; /* Complain */
|
if( n <= 0) {
|
||||||
return FALSE ;
|
lastflag = 0 ;
|
||||||
|
return n < 0 ? FALSE : TRUE ;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* wrap on space after fill column in wrap mode */
|
||||||
|
if( c == ' '
|
||||||
|
&& (curwp->w_bufp->b_mode & MDWRAP)
|
||||||
|
&& fillcol > 0
|
||||||
|
&& getccol( FALSE) > fillcol) {
|
||||||
|
status = execute( META | SPEC | 'W', FALSE, 1) ; /* defaults to wrapword */
|
||||||
|
if( status != TRUE) {
|
||||||
|
lastflag = 0 ;
|
||||||
|
return status ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
thisflag = 0 ; /* For the future. */
|
||||||
|
|
||||||
|
/* following handling of overwrite is only valid when n == 1 */
|
||||||
|
/* if we are in overwrite mode, not at eol,
|
||||||
|
and next char is not a tab or we are at a tab stop,
|
||||||
|
delete a char forward */
|
||||||
|
if( curbp->b_mode & MDOVER
|
||||||
|
&& curwp->w_doto < curwp->w_dotp->l_used
|
||||||
|
&& (lgetc( curwp->w_dotp, curwp->w_doto) != '\t' ||
|
||||||
|
((curwp->w_doto) % tabwidth) == (tabwidth - 1)))
|
||||||
|
ldelchar( 1, FALSE) ;
|
||||||
|
|
||||||
|
/* do the appropriate insertion */
|
||||||
|
switch( c) {
|
||||||
|
case '}':
|
||||||
|
case ']':
|
||||||
|
case ')':
|
||||||
|
case '#':
|
||||||
|
if( (curbp->b_mode & MDCMOD) != 0) {
|
||||||
|
if( c == '#')
|
||||||
|
status = inspound( n) ;
|
||||||
|
else {
|
||||||
|
status = insbrace( n, c) ;
|
||||||
|
#if CFENCE
|
||||||
|
if( status == TRUE)
|
||||||
|
fmatch( c) ; /* check for CMODE fence matching */
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
break ;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
status = linsert( n, c) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* perform auto-save */
|
||||||
|
if( status == TRUE /* successful insertion */
|
||||||
|
&& (curbp->b_mode & MDASAVE) /* auto save is on */
|
||||||
|
&& (--gacount == 0)) { /* insertion count reached */
|
||||||
|
/* and save the file if needed */
|
||||||
|
upscreen( FALSE, 0) ;
|
||||||
|
filesave( FALSE, 0) ;
|
||||||
|
gacount = gasave ;
|
||||||
|
}
|
||||||
|
|
||||||
|
lastflag = thisflag ;
|
||||||
|
return status ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user