From 847d582f89110f8c2f0e88c1533ced0606970fba Mon Sep 17 00:00:00 2001 From: Robert Pluim Date: Fri, 7 Jun 2024 12:05:34 +0200 Subject: [PATCH 1/3] Add 'char-to-name' convenience function To: emacs-devel@gnu.org * lisp/international/mule-cmds.el (char-to-name): New function. This is the inverse of 'char-from-name'. * doc/lispref/nonascii.texi (Character Codes): Document it. * etc/NEWS: Announce it. --- doc/lispref/nonascii.texi | 5 +++++ etc/NEWS | 4 ++++ lisp/international/mule-cmds.el | 7 +++++++ 3 files changed, 16 insertions(+) diff --git a/doc/lispref/nonascii.texi b/doc/lispref/nonascii.texi index b33082e2b24..195b818c0bd 100644 --- a/doc/lispref/nonascii.texi +++ b/doc/lispref/nonascii.texi @@ -435,6 +435,11 @@ Character Codes @end example @end defun +@defun char-to-name char +This function returns the Unicode name of @var{char}. Returns +@code{nil} if @var{char} is not a character or has no Unicode name. +@end defun + @defun get-byte &optional pos string This function returns the byte at character position @var{pos} in the current buffer. If the current buffer is unibyte, this is literally diff --git a/etc/NEWS b/etc/NEWS index 5fb1625a76c..c63e231f44f 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -2186,6 +2186,10 @@ it returns a short "unique" string that identifies the function. In either case, the string is propertized so clicking on it gives further details. +** New function 'char-to-name'. +This is a convenience function to return the Unicode name of a char (if +it has one). + ** New function 'cl-type-of'. This function is like 'type-of' except that it sometimes returns a more precise type. For example, for nil and t it returns 'null' diff --git a/lisp/international/mule-cmds.el b/lisp/international/mule-cmds.el index e80c42f523a..7d784ef3b1b 100644 --- a/lisp/international/mule-cmds.el +++ b/lisp/international/mule-cmds.el @@ -3183,6 +3183,13 @@ mule--ucs-names-group (script (and char (aref char-script-table char)))) (if script (symbol-name script) "ungrouped")))) +(defun char-to-name (char) + "Return the Unicode name for CHAR, if it has one, else nil. +Return nil if CHAR is not a character." + (and (characterp char) + (or (get-char-code-property char 'name) + (get-char-code-property char 'old-name)))) + (defun char-from-name (string &optional ignore-case) "Return a character as a number from its Unicode name STRING. If optional IGNORE-CASE is non-nil, ignore case in STRING. -- 2.39.2