char-uppercase-p: New predicate

Return non-nil if its argument is an uppercase character.

Suggested in Bug#54804.

* lisp/subr.el (char-uppercase-p): New defun.
* etc/NEWS (Lisp Changes in Emacs 29.1): Announce it
* doc/lispref/display.texi (Size of Displayed Text): Document it.
* test/lisp/subr-tests.el (test-char-uppercase-p): Add a test.
This commit is contained in:
Tino Calancha 2022-05-11 18:01:11 +02:00
parent 4e7879f807
commit 7f2fb99211
4 changed files with 24 additions and 1 deletions

View file

@ -2010,6 +2010,11 @@ Tables}). The width of a tab character is usually @code{tab-width}
(@pxref{Usual Display}).
@end defun
@defun char-uppercase-p char
Return non-@code{nil} if @var{char} is an uppercase character
according to Unicode.
@end defun
@defun string-width string &optional from to
This function returns the width in columns of the string @var{string},
if it were displayed in the current buffer and the selected window.

View file

@ -1781,6 +1781,10 @@ functions.
* Lisp Changes in Emacs 29.1
+++
** New predicate 'char-uppercase-p'.
This returns non-nil if its argument its an uppercase character.
** Byte compilation
---
@ -1793,7 +1797,6 @@ I.e., double-quoting the 'bar', which is almost never the correct
value. The byte compiler will now issue a warning if it encounters
these forms.
+++
*** 'restore-buffer-modified-p' can now alter buffer auto-save state.
With a FLAG value of 'autosaved', it will mark the buffer as having

View file

@ -6054,6 +6054,14 @@ and KILLP is t if a prefix arg was specified."
;; Avoid warning about delete-backward-char
(with-no-warnings (delete-backward-char n killp))))
(defun char-uppercase-p (char)
"Return non-nil if CHAR is an upper-case character.
If the Unicode tables are not yet available, e.g. during bootstrap,
then gives correct answers only for ASCII characters."
(cond ((unicode-property-table-internal 'lowercase)
(characterp (get-char-code-property char 'lowercase)))
((and (>= char ?A) (<= char ?Z)))))
(defun zap-to-char (arg char)
"Kill up to and including ARGth occurrence of CHAR.
Case is ignored if `case-fold-search' is non-nil in the current buffer.

View file

@ -1074,5 +1074,12 @@ final or penultimate step during initialization."))
(should (= subr-test--local 2))
(should-not (boundp 'subr-test--unexist)))))
(ert-deftest test-char-uppercase-p ()
"Tests for `char-uppercase-p'."
(dolist (c (list ?R ?S ))
(should (char-uppercase-p c)))
(dolist (c (list ?a ?b ?α ))
(should-not (char-uppercase-p c))))
(provide 'subr-tests)
;;; subr-tests.el ends here