From f11dea468fb0a27917de521589cf05a37daef826 Mon Sep 17 00:00:00 2001 From: Renaud Fivet Date: Fri, 20 May 2016 20:42:37 +0800 Subject: [PATCH] Insure transpose-characters works with UTF8. --- ebind.c | 2 +- names.c | 2 +- random.c | 45 +++++++++++++++++++++++++-------------------- random.h | 2 +- 4 files changed, 28 insertions(+), 23 deletions(-) diff --git a/ebind.c b/ebind.c index aba7853..c860cc4 100644 --- a/ebind.c +++ b/ebind.c @@ -73,7 +73,7 @@ struct key_tab keytab[NBINDS] = { , {CONTROL | 'S', forwsearch} , - {CONTROL | 'T', twiddle} + {CONTROL | 'T', (fn_t) twiddle} , {CONTROL | 'U', unarg} , diff --git a/names.c b/names.c index f44bfb7..0b69bdd 100644 --- a/names.c +++ b/names.c @@ -217,7 +217,7 @@ struct name_bind names[] = { #if BSD | __hpux | SVR4 {"suspend-emacs", bktoshell}, #endif - {"transpose-characters", twiddle}, + {"transpose-characters", (fn_t) twiddle}, #if AEDIT {"trim-line", trim}, #endif diff --git a/random.c b/random.c index c4e9506..25f1c2a 100644 --- a/random.c +++ b/random.c @@ -230,27 +230,32 @@ int setccol(int pos) * work. This fixes up a very common typo with a single stroke. Normally bound * to "C-T". This always works within a line, so "WFEDIT" is good enough. */ -int twiddle(int f, int n) -{ - struct line *dotp; - int doto; - int cl; - int cr; +boolean twiddle( int f, int n) { + unicode_t c ; + int len ; + boolean eof_f = FALSE ; - if (curbp->b_mode & MDVIEW) /* don't allow this command if */ - return rdonly(); /* we are in read only mode */ - dotp = curwp->w_dotp; - doto = curwp->w_doto; - if (doto == llength(dotp) && --doto < 0) - return FALSE; - cr = lgetc(dotp, doto); - if (--doto < 0) - return FALSE; - cl = lgetc(dotp, doto); - lputc(dotp, doto + 0, cr); - lputc(dotp, doto + 1, cl); - lchange(WFEDIT); - return TRUE; + if( curbp->b_mode & MDVIEW) /* don't allow this command if */ + return rdonly() ; /* we are in read only mode */ + + len = llength( curwp->w_dotp) ; + if( len < 2 || curwp->w_doto == 0) /* at least 2 chars & not bol */ + return FALSE ; + + if( curwp->w_doto == len) { /* at end of line */ + backchar( FALSE, 1) ; + eof_f = TRUE ; + } + + lgetchar( &c) ; + ldelchar( 1, FALSE) ; + backchar( FALSE, 1) ; + linsert( 1, c) ; + if( eof_f == TRUE) + forwchar( FALSE, 1) ; + + lchange( WFEDIT) ; + return TRUE ; } /* diff --git a/random.h b/random.h index f00e74c..b2d07c8 100644 --- a/random.h +++ b/random.h @@ -24,7 +24,7 @@ int showcpos( int f, int n) ; int getcline( void) ; int getccol( int bflg) ; int setccol( int pos) ; -int twiddle( int f, int n) ; +boolean twiddle( int f, int n) ; int quote( int f, int n) ; int insert_tab( int f, int n) ; #if AEDIT