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

Review forwchar and backchar.

This commit is contained in:
Renaud 2016-05-19 21:27:26 +08:00
parent d4b2a4c1aa
commit 2b21a98e9c
5 changed files with 55 additions and 52 deletions

14
ebind.c
View File

@ -37,7 +37,7 @@
struct key_tab keytab[NBINDS] = {
{CONTROL | 'A', gotobol}
,
{CONTROL | 'B', backchar}
{CONTROL | 'B', (fn_t) backchar}
,
{CONTROL | 'C', insspace}
,
@ -45,7 +45,7 @@ struct key_tab keytab[NBINDS] = {
,
{CONTROL | 'E', gotoeol}
,
{CONTROL | 'F', forwchar}
{CONTROL | 'F', (fn_t) forwchar}
,
{CONTROL | 'G', ctrlg}
,
@ -329,9 +329,9 @@ struct key_tab keytab[NBINDS] = {
,
{SPEC | 73, backpage}
,
{SPEC | 75, backchar}
{SPEC | 75, (fn_t) backchar}
,
{SPEC | 77, forwchar}
{SPEC | 77, (fn_t) forwchar}
,
{SPEC | 79, gotoeol}
,
@ -406,13 +406,13 @@ struct key_tab keytab[NBINDS] = {
,
{SPEC | 'B', forwline}
,
{SPEC | 'C', forwchar}
{SPEC | 'C', (fn_t) forwchar}
,
{SPEC | 'D', backchar}
{SPEC | 'D', (fn_t) backchar}
,
{SPEC | 'c', metafn}
,
{SPEC | 'd', backchar}
{SPEC | 'd', (fn_t) backchar}
,
{SPEC | 'e', forwline}
,

61
line.c
View File

@ -91,32 +91,11 @@ char *getkill( void) {
* location. Error if you try and move out of the buffer. Set the flag if the
* line pointer for dot changes.
*/
int backchar( int f, int n) {
if( n < 0)
return forwchar( f, -n) ;
static unsigned utf8_revdelta( unsigned char *p, unsigned pos) {
unsigned delta = 0 ;
while( n--) {
if( curwp->w_doto == 0) {
struct line *lp ;
lp = lback( curwp->w_dotp) ;
if( lp == curbp->b_linep)
return FALSE ;
curwp->w_dotp = lp ;
curwp->w_doto = llength( lp) ;
curwp->w_flag |= WFMOVE ;
} else {
unsigned pos ;
pos = curwp->w_doto -= 1 ;
if( pos > 0) {
unsigned char *p ;
p = (unsigned char *) &( (curwp->w_dotp)->l_text[ pos]) ;
if( (*p & 0xC0) == 0x80) {
unsigned char c ;
int delta = 0 ;
c = *--p ;
if( (c & 0xE0) == 0xC0) /* valid 2 bytes unicode seq */
@ -129,10 +108,32 @@ int backchar( int f, int n) {
if( (p[ -1] & 0xF8) == 0xF0) /* valid 4 bytes unicode seq */
delta = 3 ;
}
}
curwp->w_doto -= delta ;
}
return delta ;
}
boolean backchar( int f, int n) {
if( n < 0)
return forwchar( f, -n) ;
while( n--) {
if( curwp->w_doto == 0) { /* at beginning of line */
line_p lp ;
lp = lback( curwp->w_dotp) ;
if( lp == curbp->b_linep) /* at beginning of buffer */
return FALSE ;
curwp->w_dotp = lp ;
curwp->w_doto = llength( lp) ;
curwp->w_flag |= WFMOVE ;
} else {
unsigned pos ;
pos = curwp->w_doto -= 1 ;
if( pos > 0)
curwp->w_doto -= utf8_revdelta( (unsigned char *) &( (curwp->w_dotp)->l_text[ pos]), pos) ;
}
}
@ -145,15 +146,16 @@ int backchar( int f, int n) {
* location, and move ".". Error if you try and move off the end of the
* buffer. Set the flag if the line pointer for dot changes.
*/
int forwchar(int f, int n)
{
boolean forwchar( int f, int n) {
if( n < 0)
return backchar( f, -n) ;
while( n--) {
int len = llength( curwp->w_dotp) ;
if (curwp->w_doto == len) {
if (curwp->w_dotp == curbp->b_linep)
if( curwp->w_doto == len) { /* at end of line */
if( curwp->w_dotp == curbp->b_linep) /* at end of buffer */
return FALSE ;
curwp->w_dotp = lforw( curwp->w_dotp) ;
curwp->w_doto = 0 ;
curwp->w_flag |= WFMOVE ;
@ -165,6 +167,7 @@ int forwchar(int f, int n)
curwp->w_doto += bytes ;
}
}
return TRUE ;
}

4
line.h
View File

@ -30,8 +30,8 @@ extern int tabwidth ; /* Map to $tab, default to 8, can be set to [1, .. */
char *getkill( void) ;
int backchar( int f, int n) ;
int forwchar( int f, int n) ;
boolean backchar( int f, int n) ;
boolean forwchar( int f, int n) ;
void lfree( line_p lp) ;
void lchange( int flag) ;

View File

@ -34,7 +34,7 @@ struct name_bind names[] = {
#if APROP
{"apropos", apro},
#endif
{"backward-character", backchar},
{"backward-character", (fn_t) backchar},
{"begin-macro", ctlxlp},
{"beginning-of-file", gotobob},
{"beginning-of-line", gotobol},
@ -132,7 +132,7 @@ struct name_bind names[] = {
#endif
{"filter-buffer", filter_buffer},
{"find-file", filefind},
{"forward-character", forwchar},
{"forward-character", (fn_t) forwchar},
{"goto-line", gotoline},
#if CFENCE
{"goto-matching-fence", getfence},

View File

@ -705,7 +705,7 @@ int backdel( int f, int n) {
thisflag |= CFKILL;
}
return (backchar( f, n) == TRUE) && ldelchar( n, f != FALSE) ;
return backchar( f, n) && ldelchar( n, f != FALSE) ;
}
/*