summaryrefslogtreecommitdiff
path: root/lisp/international
diff options
context:
space:
mode:
authorRobert Pluim <rpluim@gmail.com>2022-09-01 17:59:10 +0200
committerRobert Pluim <rpluim@gmail.com>2022-09-02 10:56:59 +0200
commitb1c08a9581d2a0efcda3dae8d3bd90f5382d82d7 (patch)
tree0482c5152c97104ddfacb614d91db9b8496eef7e /lisp/international
parent6ffc091e1704f27c7d8f9caf497ea435f720c724 (diff)
downloademacs-b1c08a9581d2a0efcda3dae8d3bd90f5382d82d7.tar.gz
Allow easy entry of single chars in `read-char-by-name'
* lisp/international/mule-cmds.el (read-char-by-name): Add optional 'allow-single' argument, meaning to accept single chars as themselves.
Diffstat (limited to 'lisp/international')
-rw-r--r--lisp/international/mule-cmds.el10
1 files changed, 8 insertions, 2 deletions
diff --git a/lisp/international/mule-cmds.el b/lisp/international/mule-cmds.el
index 12896cc4b0e..41376425289 100644
--- a/lisp/international/mule-cmds.el
+++ b/lisp/international/mule-cmds.el
@@ -3195,7 +3195,7 @@ Defines the sorting order either by character names or their codepoints."
:group 'mule
:version "28.1")
-(defun read-char-by-name (prompt)
+(defun read-char-by-name (prompt &optional allow-single)
"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'.
@@ -3216,7 +3216,10 @@ Accept a name like \"CIRCULATION FUNCTION\", a hexadecimal
number like \"2A10\", or a number in hash notation (e.g.,
\"#x2a10\" for hex, \"10r10768\" for decimal, or \"#o25020\" for
octal). Treat otherwise-ambiguous strings like \"BED\" (U+1F6CF)
-as names, not numbers."
+as names, not numbers.
+
+Optional arg ALLOW-SINGLE non-nil means to additionally allow
+single characters to be treated as standing for themselves."
(let* ((enable-recursive-minibuffers t)
(completion-ignore-case t)
(completion-tab-width 4)
@@ -3239,6 +3242,9 @@ as names, not numbers."
(char
(cond
((char-from-name input t))
+ ((and allow-single
+ (string-match-p "\\`.\\'" input)
+ (ignore-errors (string-to-char input))))
((string-match-p "\\`[[:xdigit:]]+\\'" input)
(ignore-errors (string-to-number input 16)))
((string-match-p "\\`#\\([bBoOxX]\\|[0-9]+[rR]\\)[0-9a-zA-Z]+\\'"