mirror of
https://github.com/rfivet/uemacs.git
synced 2024-11-17 18:16:22 -05:00
Review forwchar and backchar.
This commit is contained in:
parent
d4b2a4c1aa
commit
2b21a98e9c
14
ebind.c
14
ebind.c
@ -37,7 +37,7 @@
|
|||||||
struct key_tab keytab[NBINDS] = {
|
struct key_tab keytab[NBINDS] = {
|
||||||
{CONTROL | 'A', gotobol}
|
{CONTROL | 'A', gotobol}
|
||||||
,
|
,
|
||||||
{CONTROL | 'B', backchar}
|
{CONTROL | 'B', (fn_t) backchar}
|
||||||
,
|
,
|
||||||
{CONTROL | 'C', insspace}
|
{CONTROL | 'C', insspace}
|
||||||
,
|
,
|
||||||
@ -45,7 +45,7 @@ struct key_tab keytab[NBINDS] = {
|
|||||||
,
|
,
|
||||||
{CONTROL | 'E', gotoeol}
|
{CONTROL | 'E', gotoeol}
|
||||||
,
|
,
|
||||||
{CONTROL | 'F', forwchar}
|
{CONTROL | 'F', (fn_t) forwchar}
|
||||||
,
|
,
|
||||||
{CONTROL | 'G', ctrlg}
|
{CONTROL | 'G', ctrlg}
|
||||||
,
|
,
|
||||||
@ -329,9 +329,9 @@ struct key_tab keytab[NBINDS] = {
|
|||||||
,
|
,
|
||||||
{SPEC | 73, backpage}
|
{SPEC | 73, backpage}
|
||||||
,
|
,
|
||||||
{SPEC | 75, backchar}
|
{SPEC | 75, (fn_t) backchar}
|
||||||
,
|
,
|
||||||
{SPEC | 77, forwchar}
|
{SPEC | 77, (fn_t) forwchar}
|
||||||
,
|
,
|
||||||
{SPEC | 79, gotoeol}
|
{SPEC | 79, gotoeol}
|
||||||
,
|
,
|
||||||
@ -406,13 +406,13 @@ struct key_tab keytab[NBINDS] = {
|
|||||||
,
|
,
|
||||||
{SPEC | 'B', forwline}
|
{SPEC | 'B', forwline}
|
||||||
,
|
,
|
||||||
{SPEC | 'C', forwchar}
|
{SPEC | 'C', (fn_t) forwchar}
|
||||||
,
|
,
|
||||||
{SPEC | 'D', backchar}
|
{SPEC | 'D', (fn_t) backchar}
|
||||||
,
|
,
|
||||||
{SPEC | 'c', metafn}
|
{SPEC | 'c', metafn}
|
||||||
,
|
,
|
||||||
{SPEC | 'd', backchar}
|
{SPEC | 'd', (fn_t) backchar}
|
||||||
,
|
,
|
||||||
{SPEC | 'e', forwline}
|
{SPEC | 'e', forwline}
|
||||||
,
|
,
|
||||||
|
61
line.c
61
line.c
@ -91,32 +91,11 @@ char *getkill( void) {
|
|||||||
* location. Error if you try and move out of the buffer. Set the flag if the
|
* location. Error if you try and move out of the buffer. Set the flag if the
|
||||||
* line pointer for dot changes.
|
* line pointer for dot changes.
|
||||||
*/
|
*/
|
||||||
int backchar( int f, int n) {
|
static unsigned utf8_revdelta( unsigned char *p, unsigned pos) {
|
||||||
if( n < 0)
|
unsigned delta = 0 ;
|
||||||
return forwchar( f, -n) ;
|
|
||||||
|
|
||||||
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) {
|
if( (*p & 0xC0) == 0x80) {
|
||||||
unsigned char c ;
|
unsigned char c ;
|
||||||
int delta = 0 ;
|
|
||||||
|
|
||||||
c = *--p ;
|
c = *--p ;
|
||||||
if( (c & 0xE0) == 0xC0) /* valid 2 bytes unicode seq */
|
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 */
|
if( (p[ -1] & 0xF8) == 0xF0) /* valid 4 bytes unicode seq */
|
||||||
delta = 3 ;
|
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
|
* 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.
|
* 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)
|
if( n < 0)
|
||||||
return backchar( f, -n) ;
|
return backchar( f, -n) ;
|
||||||
|
|
||||||
while( n--) {
|
while( n--) {
|
||||||
int len = llength( curwp->w_dotp) ;
|
int len = llength( curwp->w_dotp) ;
|
||||||
if (curwp->w_doto == len) {
|
if( curwp->w_doto == len) { /* at end of line */
|
||||||
if (curwp->w_dotp == curbp->b_linep)
|
if( curwp->w_dotp == curbp->b_linep) /* at end of buffer */
|
||||||
return FALSE ;
|
return FALSE ;
|
||||||
|
|
||||||
curwp->w_dotp = lforw( curwp->w_dotp) ;
|
curwp->w_dotp = lforw( curwp->w_dotp) ;
|
||||||
curwp->w_doto = 0 ;
|
curwp->w_doto = 0 ;
|
||||||
curwp->w_flag |= WFMOVE ;
|
curwp->w_flag |= WFMOVE ;
|
||||||
@ -165,6 +167,7 @@ int forwchar(int f, int n)
|
|||||||
curwp->w_doto += bytes ;
|
curwp->w_doto += bytes ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return TRUE ;
|
return TRUE ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
4
line.h
4
line.h
@ -30,8 +30,8 @@ extern int tabwidth ; /* Map to $tab, default to 8, can be set to [1, .. */
|
|||||||
|
|
||||||
char *getkill( void) ;
|
char *getkill( void) ;
|
||||||
|
|
||||||
int backchar( int f, int n) ;
|
boolean backchar( int f, int n) ;
|
||||||
int forwchar( int f, int n) ;
|
boolean forwchar( int f, int n) ;
|
||||||
|
|
||||||
void lfree( line_p lp) ;
|
void lfree( line_p lp) ;
|
||||||
void lchange( int flag) ;
|
void lchange( int flag) ;
|
||||||
|
4
names.c
4
names.c
@ -34,7 +34,7 @@ struct name_bind names[] = {
|
|||||||
#if APROP
|
#if APROP
|
||||||
{"apropos", apro},
|
{"apropos", apro},
|
||||||
#endif
|
#endif
|
||||||
{"backward-character", backchar},
|
{"backward-character", (fn_t) backchar},
|
||||||
{"begin-macro", ctlxlp},
|
{"begin-macro", ctlxlp},
|
||||||
{"beginning-of-file", gotobob},
|
{"beginning-of-file", gotobob},
|
||||||
{"beginning-of-line", gotobol},
|
{"beginning-of-line", gotobol},
|
||||||
@ -132,7 +132,7 @@ struct name_bind names[] = {
|
|||||||
#endif
|
#endif
|
||||||
{"filter-buffer", filter_buffer},
|
{"filter-buffer", filter_buffer},
|
||||||
{"find-file", filefind},
|
{"find-file", filefind},
|
||||||
{"forward-character", forwchar},
|
{"forward-character", (fn_t) forwchar},
|
||||||
{"goto-line", gotoline},
|
{"goto-line", gotoline},
|
||||||
#if CFENCE
|
#if CFENCE
|
||||||
{"goto-matching-fence", getfence},
|
{"goto-matching-fence", getfence},
|
||||||
|
Loading…
Reference in New Issue
Block a user