1
0
mirror of https://github.com/rfivet/uemacs.git synced 2024-12-18 07:16:23 -05:00

Review insbrace, getfence and fmatch.

Adjust timing to pause when highlighting matching brace.
$tpause <= 0 disable matching brace highlight.
This commit is contained in:
Renaud 2016-02-29 21:23:43 +08:00
parent 663fc2e554
commit 14ef4f50ab

122
random.c
View File

@ -14,6 +14,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <unistd.h>
#include "basic.h" #include "basic.h"
#include "buffer.h" #include "buffer.h"
@ -637,15 +638,16 @@ int insbrace(int n, int c)
oldlp = curwp->w_dotp; oldlp = curwp->w_dotp;
oldoff = curwp->w_doto; oldoff = curwp->w_doto;
count = 1; count = 1 ;
do { do {
if( boundry( curwp->w_dotp, curwp->w_doto, REVERSE)) { if( boundry( curwp->w_dotp, curwp->w_doto, REVERSE)) {
/* at beginning of buffer, no match to be found */ /* at beginning of buffer, no match to be found */
curwp->w_dotp = oldlp ; curwp->w_dotp = oldlp ;
curwp->w_doto = oldoff ; curwp->w_doto = oldoff ;
return linsert( n, c) ; return linsert( n, c) ;
} else }
backchar( FALSE, 1) ;
backchar( FALSE, 1) ;
/* if not eol */ /* if not eol */
if( curwp->w_doto != llength( curwp->w_dotp)) { if( curwp->w_doto != llength( curwp->w_dotp)) {
@ -1079,46 +1081,36 @@ int getfence(int f, int n)
return FALSE; return FALSE;
} }
/* set up for scan */ /* scan until we find a match, or reach the end of file */
count = 1; count = 1 ;
if (sdir == REVERSE) do {
backchar(FALSE, 1); if( boundry( curwp->w_dotp, curwp->w_doto, sdir)) {
else /* at buffer limit, no match to be found */
forwchar(FALSE, 1); /* restore the current position */
curwp->w_dotp = oldlp ;
curwp->w_doto = oldoff ;
TTbeep() ;
return FALSE ;
}
/* scan until we find it, or reach the end of file */ if( sdir == FORWARD)
while (count > 0) { forwchar( FALSE, 1) ;
if (curwp->w_doto == llength(curwp->w_dotp))
c = '\n';
else else
c = lgetc(curwp->w_dotp, curwp->w_doto); backchar( FALSE, 1) ;
if (c == ch)
++count;
if (c == ofence)
--count;
if (sdir == FORWARD)
forwchar(FALSE, 1);
else
backchar(FALSE, 1);
if (boundry(curwp->w_dotp, curwp->w_doto, sdir))
break;
}
/* if count is zero, we have a match, move the sucker */ /* if no eol */
if (count == 0) { if( curwp->w_doto != llength(curwp->w_dotp)) {
if (sdir == FORWARD) c = lgetc( curwp->w_dotp, curwp->w_doto) ;
backchar(FALSE, 1); if( c == ch)
else ++count ;
forwchar(FALSE, 1); else if( c == ofence)
curwp->w_flag |= WFMOVE; --count ;
return TRUE; }
} } while( count > 0) ;
/* restore the current position */ /* we have a match, move the sucker */
curwp->w_dotp = oldlp; curwp->w_flag |= WFMOVE ;
curwp->w_doto = oldoff; return TRUE ;
TTbeep();
return FALSE;
} }
#endif #endif
@ -1138,6 +1130,10 @@ int fmatch(int ch)
char c; /* current character in scan */ char c; /* current character in scan */
int i; int i;
/* $tpause <= 0 disable fmatch */
if( term.t_pause <= 0)
return TRUE ;
/* first get the display update out there */ /* first get the display update out there */
update(FALSE); update(FALSE);
@ -1155,32 +1151,36 @@ int fmatch(int ch)
/* find the top line and set up for scan */ /* find the top line and set up for scan */
toplp = curwp->w_linep->l_bp; toplp = curwp->w_linep->l_bp;
count = 1; backchar( FALSE, 1) ; /* . was after the }, move back */
backchar(FALSE, 2);
/* scan back until we find it, or reach past the top of the window */ /* scan back until we find it, or reach past the top of the window */
while (count > 0 && curwp->w_dotp != toplp) { count = 1 ;
if (curwp->w_doto == llength(curwp->w_dotp)) do {
c = '\n'; /* At beginning of window or buffer, no match to be found */
else if( curwp->w_dotp == toplp
c = lgetc(curwp->w_dotp, curwp->w_doto); || boundry( curwp->w_dotp, curwp->w_doto, REVERSE))
if (c == ch) break ;
++count;
if (c == opench) backchar( FALSE, 1) ;
--count;
backchar(FALSE, 1); /* if not eol */
if (curwp->w_dotp == curwp->w_bufp->b_linep->l_fp && if( curwp->w_doto != llength(curwp->w_dotp)) {
curwp->w_doto == 0) c = lgetc( curwp->w_dotp, curwp->w_doto) ;
break; if( c == ch)
} ++count ;
else if( c == opench)
--count ;
}
} while( count > 0) ;
/* if count is zero, we have a match, display the sucker */ /* if count is zero, we have a match, display the sucker */
/* there is a real machine dependant timing problem here we have if( count == 0) {
yet to solve......... */ /* there is a real machine dependant timing problem here we have
if (count == 0) { yet to solve......... */
forwchar(FALSE, 1); for( i = 0 ; i < term.t_pause ; i++) {
for (i = 0; i < term.t_pause; i++) update( FALSE) ;
update(FALSE); usleep( 10000L) ;
}
} }
/* restore the current position */ /* restore the current position */