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:27:47 +0300
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (x86_64-pc-linux-gnu)

>> > I think it is better to skip these ranges:
>> >   #x3400..#x4dbf   -- CJK Ideograph Extension A
>> >   #x4e00..#x9fff   -- CJK Ideograph
>> >   #xd800..#xfaFF   -- surroage-pair, private use, CJK COMPATIBILITY 
>> > IDEOGRAPH
>> >   #x20000..#x2ffff -- CJK Ideograph Extension B
>> > and end the loop at #xeffff (#xf0000.. are for private use)
>
>> Actually there are no Unicode names in these ranges in UnicodeData.txt.
>> It has only lines for the first and the last character in these ranges:
>
> Yes.  But, for CJK chars:
>
>    (get-char-code-property CHAR 'name)
>
> returns a valid name something like "CJK IDEOGRAPH-3400"(*)
> because get-char-code-property not only looks up
> UnicodeData.txt but also compute a proper value if
> necessary.

Thanks, I see now why it is necessary to skip these ranges.

Index: lisp/international/mule-cmds.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/international/mule-cmds.el,v
retrieving revision 1.333
diff -c -r1.333 mule-cmds.el
*** lisp/international/mule-cmds.el     15 Jul 2008 18:15:03 -0000      1.333
--- lisp/international/mule-cmds.el     20 Jul 2008 20:27:21 -0000
***************
*** 2846,2855 ****
  (defvar nonascii-insert-offset 0 "This variable is obsolete.")
  (defvar nonascii-translation-table nil "This variable is obsolete.")
  
  (defun ucs-insert (arg)
    "Insert a character of the given Unicode code point.
  Interactively, prompts for a hex string giving the code."
!   (interactive "sUnicode (hex): ")
    (or (integerp arg)
        (setq arg (string-to-number arg 16)))
    (if (or (< arg 0) (> arg #x10FFFF))
--- 2849,2879 ----
  (defvar nonascii-insert-offset 0 "This variable is obsolete.")
  (defvar nonascii-translation-table nil "This variable is obsolete.")
  
+ (defun read-char-by-name (prompt)
+   "Read a character by its Unicode name or hex number string.
+ Display PROMPT and read a string that represents a character
+ by its Unicode property `name' or `old-name'.  It also accepts
+ a hexadecimal number of Unicode code point.  Returns a character
+ as a number."
+   (let (name names)
+     (dotimes (c #xEFFFF)
+       (unless (or
+              (and (>= c #x3400 ) (<= c #x4dbf )) ; CJK Ideograph Extension A
+              (and (>= c #x4e00 ) (<= c #x9fff )) ; CJK Ideograph
+              (and (>= c #xd800 ) (<= c #xfaff )) ; Private/Surrogate
+              (and (>= c #x20000) (<= c #x2ffff)) ; CJK Ideograph Extension B
+              )
+       (if (setq name (get-char-code-property c 'name))
+           (setq names (cons (cons name c) names)))
+       (if (setq name (get-char-code-property c 'old-name))
+           (setq names (cons (cons name c) names)))))
+     (or (cdr (assoc (setq name (completing-read prompt names)) names))
+       (string-to-number name 16))))
+ 
  (defun ucs-insert (arg)
    "Insert a character of the given Unicode code point.
  Interactively, prompts for a hex string giving the code."
!   (interactive (list (read-char-by-name "Unicode (hex or name): ")))
    (or (integerp arg)
        (setq arg (string-to-number arg 16)))
    (if (or (< arg 0) (> arg #x10FFFF))

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




reply via email to

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