emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 7f2fb99211: char-uppercase-p: New predicate


From: Tino Calancha
Subject: master 7f2fb99211: char-uppercase-p: New predicate
Date: Wed, 11 May 2022 12:04:18 -0400 (EDT)

branch: master
commit 7f2fb992110a60a8b583db76fd3b3ee0f1c7efb9
Author: Tino Calancha <tino.calancha@gmail.com>
Commit: Tino Calancha <tino.calancha@gmail.com>

    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.
---
 doc/lispref/display.texi | 5 +++++
 etc/NEWS                 | 5 ++++-
 lisp/simple.el           | 8 ++++++++
 test/lisp/subr-tests.el  | 7 +++++++
 4 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/doc/lispref/display.texi b/doc/lispref/display.texi
index 0ab683d234..f428fb858b 100644
--- a/doc/lispref/display.texi
+++ b/doc/lispref/display.texi
@@ -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.
diff --git a/etc/NEWS b/etc/NEWS
index 991088a067..ddb83ce410 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -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
diff --git a/lisp/simple.el b/lisp/simple.el
index 89fb0ea97e..3812f6d8c6 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -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.
diff --git a/test/lisp/subr-tests.el b/test/lisp/subr-tests.el
index 89803e5ce2..a25eb363b0 100644
--- a/test/lisp/subr-tests.el
+++ b/test/lisp/subr-tests.el
@@ -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



reply via email to

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