bug-gnu-emacs
[Top][All Lists]
Advanced

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

bug#54804: 29.0.50; zap-to-char: case sensitive for upper-case letter


From: Tino Calancha
Subject: bug#54804: 29.0.50; zap-to-char: case sensitive for upper-case letter
Date: Tue, 10 May 2022 23:14:20 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)

Eli Zaretskii <eliz@gnu.org> writes:

> What I'd prefer is to have a single function (in subr.el) that
> determines whether a character is an upper- or lower-case

> it could instead use something like
>
>    (characterp (get-char-code-property CHAR 'uppercase))
>
> (But beware of the situation where the Unicode tables are not yet
> available during bootstrap -- in those cases the function should IMO
> punt and return nil no matter what the character is, or maybe support
> just the ASCII characters.  To test whether the 'uppercase table is
> available, see if unicode-property-table-internal returns non-nil.)

Is it the following implementation OK for such a function?

--8<-----------------------------cut here---------------start------------->8---
commit 74dd575d3ca8e5217a3c1457dbc011007ecc0800
Author: Tino Calancha <tino.calancha@gmail.com>
Date:   Tue May 10 23:01:34 2022 +0200

    Add char-upcase-p predicate

diff --git a/lisp/simple.el b/lisp/simple.el
index edcc226bfa..dc5e0f2ce8 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -6054,6 +6054,14 @@ backward-delete-char-untabify
     ;; Avoid warning about delete-backward-char
     (with-no-warnings (delete-backward-char n killp))))
 
+(defun char-upcase-p (char)
+  "Return non-nil if CHAR is an upper-case unicode character.
+If the Unicode tables are not yet available, e.g. during bootstrap,
+then the function restricts to the ASCII character set."
+  (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..8072cd9a61 100644
--- a/test/lisp/subr-tests.el
+++ b/test/lisp/subr-tests.el
@@ -1074,5 +1074,12 @@ test-local-set-state
       (should (= subr-test--local 2))
       (should-not (boundp 'subr-test--unexist)))))
 
+(ert-deftest test-char-upcase-p ()
+  "Tests for `char-upcase-p'."
+  (dolist (c (list ?R ?S ?Ω ?Ψ))
+    (should (char-upcase-p c)))
+  (dolist (c (list ?a ?b ?α ?β))
+    (should-not (char-upcase-p c))))
+
 (provide 'subr-tests)
 ;;; subr-tests.el ends here

--8<-----------------------------cut here---------------end--------------->8---





reply via email to

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