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: Wed, 30 Jul 2008 18:29:19 +0300
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (x86_64-pc-linux-gnu)

>>> I think we should improve `ucs-insert' to accept input in standard
>>> Emacs Lisp notations: #o... for octal and #x... for hex.
>>
>> Agreed.
>
> Sure, though it should be noted that this is an incompatible editing
> change: with standing Lisp notation, 123 would be decimal, not octal.

Hexadecimal numbers is the primary notation for Unicode code points
so it would be better to keep the current default.  In addition we can
support the hash notation that allows entering decimal numbers (though,
in less convenient way) as e.g. #10r182.  I propose the following patch
that keeps `ucs-insert' backward-compatible in regard of treating
numbers as hex by default, adds reading numbers with hash notations,
and improves error-handling of `ucs-insert'.

Index: lisp/international/mule-cmds.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/international/mule-cmds.el,v
retrieving revision 1.335
diff -c -r1.335 mule-cmds.el
*** lisp/international/mule-cmds.el     29 Jul 2008 14:45:50 -0000      1.335
--- lisp/international/mule-cmds.el     30 Jul 2008 15:29:11 -0000
***************
*** 2864,2883 ****
  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 (name or hex): ")))
!   (or (integerp arg)
        (setq arg (string-to-number arg 16)))
!   (if (or (< arg 0) (> arg #x10FFFF))
!       (error "Not a Unicode character code: 0x%X" arg))
    (insert-and-inherit arg))
  
  
  ;; arch-tag: b382c432-4b36-460e-bf4c-05efd0bb18dc
  ;;; mule-cmds.el ends here
--- 2864,2891 ----
  as a number."
    (let* ((completion-ignore-case t)
         (input (completing-read prompt ucs-completions)))
!     (cond
!      ((string-match "^[0-9a-fA-F]+$" input)
!       (string-to-number input 16))
!      ((string-match "^#" input)
!       (read input))
!      (t
!       (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 (name or hex): ")))
!   (if (stringp arg)
        (setq arg (string-to-number arg 16)))
!   (cond
!    ((not (integerp arg))
!     (error "Not a Unicode character code: %S" arg))
!    ((< arg 0) (> arg #x10FFFF)
!     (error "Not a Unicode character code: 0x%X" arg)))
    (insert-and-inherit arg))
  
+ (define-key ctl-x-map "8\r" 'ucs-insert)
  
  ;; arch-tag: b382c432-4b36-460e-bf4c-05efd0bb18dc
  ;;; mule-cmds.el ends here

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




reply via email to

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