]> git.eshelyaron.com Git - emacs.git/commitdiff
(encoded-kbd-self-insert-utf-8): Catch and recover from case when the bytes
authorStefan Monnier <monnier@iro.umontreal.ca>
Sun, 15 Jun 2008 04:43:35 +0000 (04:43 +0000)
committerStefan Monnier <monnier@iro.umontreal.ca>
Sun, 15 Jun 2008 04:43:35 +0000 (04:43 +0000)
we thought we were reading turn out to be something else entirely, such as
latin-1 chars from quail.  See bug#396.

lisp/ChangeLog
lisp/international/encoded-kb.el

index fd6246c59161843238cbbd2ce62ec393f9aba090..42b7c94c6aaad953bbfc85216b89ee5a45c43901 100644 (file)
@@ -1,3 +1,10 @@
+2008-06-15  Stefan Monnier  <monnier@iro.umontreal.ca>
+
+       * international/encoded-kb.el (encoded-kbd-self-insert-utf-8):
+       Catch and recover from case when the bytes we thought we were reading
+       turn out to be something else entirely, such as latin-1 chars from
+       quail.  See bug#396.
+
 2008-06-15  Dan Nicolaescu  <dann@ics.uci.edu>
 
        * vc.el (vc-deduce-fileset): Check if the buffer has a file.
index ec887659e9c598801693ff4087ff82bee0c2ef7e..4659b4991129938fb4f2d57d23c1cbef7f956f74 100644 (file)
@@ -219,8 +219,9 @@ The following key sequence may cause multilingual text insertion."
 
 (defun encoded-kbd-self-insert-utf-8 (arg)
   (interactive "p")
-  (let ((char (encoded-kbd-last-key))
-       len)
+  (let* ((lead (encoded-kbd-last-key))
+         (char lead)
+         len event)
     (cond ((< char #xE0)
           (setq len 1 char (logand char #x1F)))
          ((< char #xF0)
@@ -230,8 +231,22 @@ The following key sequence may cause multilingual text insertion."
          (t
           (setq len 4 char 0)))
     (while (> len 0)
-      (setq char (logior (lsh char 6) (logand (read-char-exclusive) #x3F))
-           len (1- len)))
+      (setq event (read-char-exclusive))
+      (if (and (>= event #x80) (< event #xc0))
+          ;; Valid utf-8 sequence.
+          (setq char (logior (lsh char 6) (- event #x80))
+                len (1- len))
+        ;; Invalid utf-8 sequence.  Might be because Quail got involved
+        ;; in-between and the bytes we thought we were reading were actually
+        ;; latin-1 chars.  Let's presume that `event' is the second "byte",
+        ;; i.e. there weren't any "apprently correct" between `lead' and
+        ;; `event': it's easy to recover in this case, and the more general
+        ;; case seems pretty unlikely.
+        ;; FIXME: We should really do encoded-kbd decoding before processing
+        ;; input-methods.
+        (push event unread-command-events)
+        (setq char lead)
+        (setq len 0)))
     (vector char)))
 
 (defun encoded-kbd-setup-keymap (keymap coding)