Hi,

here are two very simple fixes for ksh(1) emacs input mode.

The first hunk lets you insert non-ASCII UTF-8 characters without
screwing up the display.  Specifically, after inserting a continuation
byte, it backs up to the start byte and starts re-printing there.

The second hunk fixes forward movement which i didn't get quite
right in my previous commit (backward movement is already fine).
Always advance to a start byte, never to a final continuation byte.
Without it, if you move forward onto a multi-byte character and
then insert something, the something splits the UTF-8 character
in the middle.  Ooops.

OK?
  Ingo


Index: emacs.c
===================================================================
RCS file: /cvs/src/bin/ksh/emacs.c,v
retrieving revision 1.61
diff -u -p -r1.61 emacs.c
--- emacs.c     10 Dec 2015 10:00:14 -0000      1.61
+++ emacs.c     5 Jan 2016 18:25:26 -0000
@@ -681,6 +681,11 @@ x_zots(char *str)
 {
        int     adj = x_adj_done;
 
+       if (str > xbuf && isu8cont(*str)) {
+               while (str > xbuf && isu8cont(*str))
+                       str--;
+               x_e_putc('\b');
+       }
        x_lastcp();
        while (*str && str < xlp && adj == x_adj_done)
                x_zotc(*str++);
@@ -727,7 +732,7 @@ x_mv_forw(int c)
        }
        if (x_arg > nleft)
                x_arg = nleft;
-       while (x_arg < nleft && isu8cont(xcp[x_arg + 1]))
+       while (x_arg < nleft && isu8cont(xcp[x_arg]))
                x_arg++;
        x_goto(xcp + x_arg);
        return KSTD;

Reply via email to