From: Tino Calancha <tino.calancha@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 54804@debbugs.gnu.org, uyennhi.qm@gmail.com,
Sean Whitton <spwhitton@spwhitton.name>
Subject: bug#54804: 29.0.50; zap-to-char: case sensitive for upper-case letter
Date: Tue, 10 May 2022 23:14:20 +0200 [thread overview]
Message-ID: <87ilqdnl8z.fsf@gmail.com> (raw)
In-Reply-To: <834k2t1cva.fsf@gnu.org> (Eli Zaretskii's message of "Sat, 16 Apr 2022 14:33:45 +0300")
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---
next prev parent reply other threads:[~2022-05-10 21:14 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-08 22:03 bug#54804: 29.0.50; zap-to-char: case sensitive for upper-case letter Tino Calancha
2022-04-09 6:03 ` Eli Zaretskii
2022-04-16 10:58 ` Tino Calancha
2022-04-16 11:33 ` Eli Zaretskii
2022-05-09 16:17 ` Sean Whitton
2022-05-10 21:14 ` Tino Calancha [this message]
2022-05-11 11:15 ` Eli Zaretskii
2022-05-11 14:43 ` Tino Calancha
2022-05-11 14:50 ` Lars Ingebrigtsen
2022-05-11 15:00 ` Robert Pluim
2022-05-11 15:19 ` Tino Calancha
2022-05-11 15:27 ` Andreas Schwab
2022-05-11 15:38 ` Tino Calancha
2022-05-11 16:11 ` Andreas Schwab
2022-05-11 16:18 ` Tino Calancha
2022-05-12 15:55 ` Tino Calancha
2022-05-13 6:48 ` Eli Zaretskii
2022-05-17 12:34 ` Tino Calancha
2022-05-17 12:41 ` Eli Zaretskii
2022-05-17 12:51 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-05-17 12:53 ` Tino Calancha
2022-05-17 13:38 ` Eli Zaretskii
2022-05-17 14:31 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-05-17 19:32 ` Juri Linkov
2022-05-18 7:25 ` Tino Calancha
2022-05-20 22:59 ` Sean Whitton
2022-05-21 5:38 ` Eli Zaretskii
2022-05-21 9:30 ` Tino Calancha
2022-05-21 18:53 ` Sean Whitton
2022-05-11 15:57 ` Eli Zaretskii
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87ilqdnl8z.fsf@gmail.com \
--to=tino.calancha@gmail.com \
--cc=54804@debbugs.gnu.org \
--cc=eliz@gnu.org \
--cc=spwhitton@spwhitton.name \
--cc=uyennhi.qm@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).