emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: inputting characters by hexadigit


From: Juri Linkov
Subject: Re: inputting characters by hexadigit
Date: Sun, 20 Jul 2008 23:28:59 +0300
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (x86_64-pc-linux-gnu)

> The patch below now provides the following variants:
>
> C-q #x2323
> C-q #o21443
> C-q #b0010001100100011
> C-q #d8995
>
> However, I'm not sure about #d8995.  It is non-standard syntax where read
> fails with (invalid-read-syntax "#").  The standard syntax for decimal is
> without hash notation.  This suggests using `C-q 8995'.  But this means
> changing read-quoted-char-radix default to 10!
>
> Anyway, this patch also provides `C-q U2323' syntax that is mnemonic
> for everyone accustomed to U+ syntax.
>
> And another convenience is `C-q # RET' where after typing RET it reads a
> code point or Unicode name in the minibuffer.

It seems better to support all Emacs Lisp notations including both
leading characters `#' and `?':

      #b101100 => 44
      #o54 => 44
      #x2c => 44
      #24r1k => 44

      ?\012 => 10         ?\t => 9         ?\C-j => 10
      ?\101 => 65         ?A => 65         ?\v => 11
      ?\f => 12           ?\r => 13        ?\e => 27
      ?\s => 32           ?\\ => 92        ?\d => 127

      ?\uNNNN

The patch below simply uses `read' to read a character from the entered
string.  It also prepends `?' when the string begins with `\' thus allowing
to input Unicode code points using `C-q \uNNNN'.

Index: lisp/subr.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/subr.el,v
retrieving revision 1.601
diff -u -r1.601 subr.el
--- lisp/subr.el        27 Jun 2008 02:13:36 -0000      1.601
+++ lisp/subr.el        20 Jul 2008 20:28:29 -0000
@@ -1721,7 +1721,7 @@
 The optional argument PROMPT specifies a string to use to prompt the user.
 The variable `read-quoted-char-radix' controls which radix to use
 for numeric input."
-  (let ((message-log-max nil) done (first t) (code 0) char translated)
+  (let ((message-log-max nil) done (first t) (code 0) char translated string)
     (while (not done)
       (let ((inhibit-quit first)
            ;; Don't let C-h get the help message--only help function keys.
@@ -1753,6 +1753,19 @@
             ;; Turn a meta-character into a character with the 0200 bit set.
             (setq code (logior (logand translated (lognot ?\M-\^@)) 128)
                   done t))
+           ((and first (memq translated '(?# ?? ?\\)))
+            (setq string (char-to-string translated))
+            (and prompt (setq prompt (message "%s %c" prompt translated))))
+           (string
+            (if (eq translated ?\C-m)
+                (setq done t code
+                      (if (eq (length string) 1)
+                          (read-char-by-name "Unicode (hex or name): ")
+                        (setq code (read (if (eq (aref string 0) ?\\)
+                                             (concat "?" string)
+                                           string)))))
+              (setq string (concat string (char-to-string translated)))
+              (and prompt (setq prompt (message "%s %c" prompt translated)))))
            ((and (<= ?0 translated) (< translated (+ ?0 (min 10 
read-quoted-char-radix))))
             (setq code (+ (* code read-quoted-char-radix) (- translated ?0)))
             (and prompt (setq prompt (message "%s %c" prompt translated))))

-- 
Juri Linkov
http://www.jurta.org/emacs/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]