[Top][All Lists]
[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: |
Thu, 24 Jul 2008 01:35:38 +0300 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (x86_64-pc-linux-gnu) |
>> Can completions be cascaded somehow? The first tier would show all the
>> common first words, e.g. ... AEGEAN APL GREEK ... and then selecting
>> something from the first tier would cascade down to the second tier.
>
> The slow display should only happen when the list is really long,
> i.e. basically if you hit TAB with an empty minibuffer. So we could
> indeed easily use a different completion behavior in this case.
When I type TAB in the empty minibuffer, I really want to see all
completions even when the list is really long, to be able to use isearch
to find a completion candidate etc. Everyone who wants to narrow the
completion list can type the first word like "latin TAB", so I think the
current completion behavior is satisfactory.
I'm now trying to improve the performance of Unicode name completion.
To cache a list of (CHAR-NAME . CHAR-CODE) pairs I created a new
variable `ucs-names' and a function that returns its value or
creates a new list (time-consuming operation). The intention is
to fill this list only when the user tries to complete or enters
a string that doesn't look like a hex number.
I also tried to use `lazy-completion-table' but it seems slower
than giving a ready alist in the `collection' arg of `completing-read'
though I didn't make measurements. The current patch is below.
Can you see any problems with it?
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 23 Jul 2008 22:34:03 -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,2894 ----
(defvar nonascii-insert-offset 0 "This variable is obsolete.")
(defvar nonascii-translation-table nil "This variable is obsolete.")
+ (defvar ucs-names nil
+ "Alist of cached (CHAR-NAME . CHAR-CODE) pairs.")
+
+ (defun ucs-names ()
+ "Return alist of (CHAR-NAME . CHAR-CODE) pairs cached in `ucs-names'."
+ (or ucs-names
+ (setq ucs-names
+ (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)))))
+ names))))
+
+ (defvar ucs-completions (lazy-completion-table ucs-completions ucs-names)
+ "Lazy completion table for completing on Unicode character names.")
+
+ (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* ((completion-ignore-case t)
+ (input (completing-read prompt ucs-completions)))
+ (or (and (string-match "^[0-9a-fA-F]+$" input)
+ (string-to-number input 16))
+ (cdr (assoc input (ucs-names))))))
+
(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/
- RE: inputting characters by hexadigit, (continued)
- Re: inputting characters by hexadigit, Stefan Monnier, 2008/07/24
- RE: inputting characters by hexadigit, Drew Adams, 2008/07/24
- Re: inputting characters by hexadigit, Lennart Borgman (gmail), 2008/07/24
- Re: inputting characters by hexadigit, Lennart Borgman (gmail), 2008/07/24
- Re: inputting characters by hexadigit, Lennart Borgman (gmail), 2008/07/24
- Re: inputting characters by hexadigit, Ted Zlatanov, 2008/07/28
- Re: inputting characters by hexadigit,
Juri Linkov <=
- Re: inputting characters by hexadigit, Lennart Borgman (gmail), 2008/07/23
- Re: inputting characters by hexadigit, Stefan Monnier, 2008/07/23
- Re: inputting characters by hexadigit, Juri Linkov, 2008/07/24
- Re: inputting characters by hexadigit, Ted Zlatanov, 2008/07/24
- RE: inputting characters by hexadigit, Drew Adams, 2008/07/24
- Re: describe-char should display the character's Unicode name, Juri Linkov, 2008/07/18