From: Robert Pluim Date: Fri, 7 Jun 2024 10:05:34 +0000 (+0200) Subject: Add 'char-to-name' convenience function X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=63f10871c7fac9caafbd865ec9fdf6b4116e4ab8;p=emacs.git Add 'char-to-name' convenience function * 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. (cherry picked from commit 3a4cf1aa1efb79b52c0aca18281593ba0e8175ca) --- diff --git a/doc/lispref/nonascii.texi b/doc/lispref/nonascii.texi index 1482becb9f5..d9fb9e306f0 100644 --- a/doc/lispref/nonascii.texi +++ b/doc/lispref/nonascii.texi @@ -435,6 +435,11 @@ This function returns @code{nil} if @var{string} does not name a character. @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 a6fdd3e138a..d9352f25212 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -2360,6 +2360,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 d33a9ac2771..8f7d9715f36 100644 --- a/lisp/international/mule-cmds.el +++ b/lisp/international/mule-cmds.el @@ -3242,6 +3242,13 @@ returns excludes categories that you specify instead." (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.