[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: |
Wed, 11 May 2022 16:43:06 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) |
Eli Zaretskii <eliz@gnu.org> writes:
>> Is it the following implementation OK for such a function?
>
> Yes, thanks. But please call it char-uppercase-p ("upcase" has the
> meaning of making a character upper-case).
I'd like to add this `char-uppercase-p'.
Once merged, I will finish with the goal of the report.
I appreciate a hand with the documentation part.
--8<-----------------------------cut here---------------start------------->8---
commit aa270a4b8813ac226a61d8e6919f68e9e4ed0973
Author: Tino Calancha <tino.calancha@gmail.com>
Date: Wed May 11 16:34:33 2022 +0200
char-uppercase-p: New predicate
Return non-nil if its argument is an upper-case unicode 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.
diff --git a/doc/lispref/display.texi b/doc/lispref/display.texi
index 9650d22790..1c32458d62 100644
--- a/doc/lispref/display.texi
+++ b/doc/lispref/display.texi
@@ -2010,6 +2010,14 @@ Size of Displayed Text
(@pxref{Usual Display}).
@end defun
+@defun char-uppercase-p char
+This function returns non-nil if @var{char} is an uppercase unicode
+character. Be aware that if the Unicode tables are not yet available,
+e.g. during bootstrap, then this function gives the right answer only
+for @acronym{ASCII} characters; for other characters the function
+unconditionally returns @code{nil}.
+@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..57c254bce8 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1794,6 +1794,10 @@ value. The byte compiler will now issue a warning if it
encounters
these forms.
++++
+*** The new predicate 'char-uppercase-p' returns non-nil if its
+argument its an uppercase unicode character.
+
+++
*** '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..525e636ab6 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-uppercase-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..a25eb363b0 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-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
--8<-----------------------------cut here---------------end--------------->8---
- bug#54804: 29.0.50; zap-to-char: case sensitive for upper-case letter, Sean Whitton, 2022/05/09
- bug#54804: 29.0.50; zap-to-char: case sensitive for upper-case letter, Tino Calancha, 2022/05/10
- bug#54804: 29.0.50; zap-to-char: case sensitive for upper-case letter, Eli Zaretskii, 2022/05/11
- bug#54804: 29.0.50; zap-to-char: case sensitive for upper-case letter,
Tino Calancha <=
- bug#54804: 29.0.50; zap-to-char: case sensitive for upper-case letter, Lars Ingebrigtsen, 2022/05/11
- bug#54804: 29.0.50; zap-to-char: case sensitive for upper-case letter, Robert Pluim, 2022/05/11
- bug#54804: 29.0.50; zap-to-char: case sensitive for upper-case letter, Tino Calancha, 2022/05/11
- bug#54804: 29.0.50; zap-to-char: case sensitive for upper-case letter, Andreas Schwab, 2022/05/11
- bug#54804: 29.0.50; zap-to-char: case sensitive for upper-case letter, Tino Calancha, 2022/05/11
- bug#54804: 29.0.50; zap-to-char: case sensitive for upper-case letter, Andreas Schwab, 2022/05/11
- bug#54804: 29.0.50; zap-to-char: case sensitive for upper-case letter, Tino Calancha, 2022/05/11
- bug#54804: 29.0.50; zap-to-char: case sensitive for upper-case letter, Tino Calancha, 2022/05/12
- bug#54804: 29.0.50; zap-to-char: case sensitive for upper-case letter, Eli Zaretskii, 2022/05/13
- bug#54804: 29.0.50; zap-to-char: case sensitive for upper-case letter, Tino Calancha, 2022/05/17