comparison lisp/international/mule-cmds.el @ 97151:db1329fe6a49

(read-char-by-name): Accept hash notation. Doc fix. (ucs-insert): Doc fix. Convert to number only when `arg' is a string. Use separate error message when `arg' is not an integer. Bind `ucs-insert' to `C-x 8 RET'.
author Juri Linkov <juri@jurta.org>
date Thu, 31 Jul 2008 16:51:45 +0000
parents fea0b97d4f6d
children a9b68f965d97
comparison
equal deleted inserted replaced
97150:9718b5cb3616 97151:db1329fe6a49
2856 (defvar ucs-completions (lazy-completion-table ucs-completions ucs-names) 2856 (defvar ucs-completions (lazy-completion-table ucs-completions ucs-names)
2857 "Lazy completion table for completing on Unicode character names.") 2857 "Lazy completion table for completing on Unicode character names.")
2858 2858
2859 (defun read-char-by-name (prompt) 2859 (defun read-char-by-name (prompt)
2860 "Read a character by its Unicode name or hex number string. 2860 "Read a character by its Unicode name or hex number string.
2861 Display PROMPT and read a string that represents a character 2861 Display PROMPT and read a string that represents a character by its
2862 by its Unicode property `name' or `old-name'. It also accepts 2862 Unicode property `name' or `old-name'. You can type a few of first
2863 a hexadecimal number of Unicode code point. Returns a character 2863 letters of the Unicode name and use completion. This function also
2864 as a number." 2864 accepts a hexadecimal number of Unicode code point or a number in
2865 hash notation, e.g. #o21430 for octal, #x2318 for hex, or #10r8984
2866 for decimal. Returns a character as a number."
2865 (let* ((completion-ignore-case t) 2867 (let* ((completion-ignore-case t)
2866 (input (completing-read prompt ucs-completions))) 2868 (input (completing-read prompt ucs-completions)))
2867 (or (and (string-match "^[0-9a-fA-F]+$" input) 2869 (cond
2868 (string-to-number input 16)) 2870 ((string-match "^[0-9a-fA-F]+$" input)
2869 (cdr (assoc input (ucs-names)))))) 2871 (string-to-number input 16))
2872 ((string-match "^#" input)
2873 (read input))
2874 (t
2875 (cdr (assoc input (ucs-names)))))))
2870 2876
2871 (defun ucs-insert (arg) 2877 (defun ucs-insert (arg)
2872 "Insert a character of the given Unicode code point. 2878 "Insert a character of the given Unicode code point.
2873 Interactively, prompts for a hex string giving the code." 2879 Interactively, prompts for a Unicode character name or a hex number
2880 using `read-char-by-name'."
2874 (interactive (list (read-char-by-name "Unicode (name or hex): "))) 2881 (interactive (list (read-char-by-name "Unicode (name or hex): ")))
2875 (or (integerp arg) 2882 (if (stringp arg)
2876 (setq arg (string-to-number arg 16))) 2883 (setq arg (string-to-number arg 16)))
2877 (if (or (< arg 0) (> arg #x10FFFF)) 2884 (cond
2878 (error "Not a Unicode character code: 0x%X" arg)) 2885 ((not (integerp arg))
2886 (error "Not a Unicode character code: %S" arg))
2887 ((or (< arg 0) (> arg #x10FFFF))
2888 (error "Not a Unicode character code: 0x%X" arg)))
2879 (insert-and-inherit arg)) 2889 (insert-and-inherit arg))
2880 2890
2891 (define-key ctl-x-map "8\r" 'ucs-insert)
2881 2892
2882 ;; arch-tag: b382c432-4b36-460e-bf4c-05efd0bb18dc 2893 ;; arch-tag: b382c432-4b36-460e-bf4c-05efd0bb18dc
2883 ;;; mule-cmds.el ends here 2894 ;;; mule-cmds.el ends here