* bug#54804: 29.0.50; zap-to-char: case sensitive for upper-case letter
@ 2022-04-08 22:03 Tino Calancha
2022-04-09 6:03 ` Eli Zaretskii
0 siblings, 1 reply; 30+ messages in thread
From: Tino Calancha @ 2022-04-08 22:03 UTC (permalink / raw)
To: 54804; +Cc: uyennhi.qm
X-Debbugs-Cc: uyennhi.qm@gmail.com
Severity: wishlist
Tags: patch
A wishlist for the `zap-to-char' and `zap-up-to-char':
In interactive calls, when users input an upper-case letter then perform
a case-sensitive search.
This behavior is analog to what `isearch' does.
--8<-----------------------------cut here---------------start------------->8---
commit c55557d6eb83ac1fe3aa678cae080df979922f7c
Author: Tino Calancha <tino.calancha@gmail.com>
Date: Fri Apr 8 23:00:18 2022 +0200
zap-to-char: case sensitive for upper-case letter
In interactive calls, perform a case sensitive search when the given
char is an upper-case letter. Same for zap-up-to-char.
This is analog to what the user-level incremental search feature does.
* lisp/misc.el (zap-up-to-char): Delete it.
* lisp/simple.el (zap--to-char-region): Add helper function.
(zap-to-char, zap-up-to-char): Add the optional argument INTERACTIVE.
Do a case-sensitive search when CHAR is an upper-case letter and
INTERACTIVE is non-nil.
* etc/NEWS (Editing Changes in Emacs 29.1): Announce this change.
* test/lisp/misc-tests.el (misc-test-zap-up-to-char): Delete it.
* test/lisp/simple-tests.el (with-simple-test): Add helper macro.
(simple-tests-zap-to-char, simple-tests-zap-up-to-char): Add tests.
diff --git a/etc/NEWS b/etc/NEWS
index 2fac893cc5..5fb9f14366 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -501,6 +501,11 @@ are met. The conditions are given by the argument, which can be
* Editing Changes in Emacs 29.1
+---
+** 'zap-to-char' performs a case-sensitive search in interactive calls
+when the input character is an upper-case letter. Likewise, for
+'zap-up-to-char'.
+
---
** Indentation of 'cl-flet' and 'cl-labels' has changed.
These forms now indent like this:
diff --git a/lisp/misc.el b/lisp/misc.el
index d85f889ffd..389b1a6ef5 100644
--- a/lisp/misc.el
+++ b/lisp/misc.el
@@ -61,25 +61,6 @@ copy-from-above-command
(+ n (point)))))))
(insert string)))
-;; Variation of `zap-to-char'.
-
-;;;###autoload
-(defun zap-up-to-char (arg char)
- "Kill up to, but not including ARGth occurrence of CHAR.
-Case is ignored if `case-fold-search' is non-nil in the current buffer.
-Goes backward if ARG is negative; error if CHAR not found.
-Ignores CHAR at point."
- (interactive (list (prefix-numeric-value current-prefix-arg)
- (read-char-from-minibuffer "Zap up to char: "
- nil 'read-char-history)))
- (let ((direction (if (>= arg 0) 1 -1)))
- (kill-region (point)
- (progn
- (forward-char direction)
- (unwind-protect
- (search-forward (char-to-string char) nil nil arg)
- (backward-char direction))
- (point)))))
;; These were added with an eye to making possible a more CCA-compatible
;; command set; but that turned out not to be interesting.
diff --git a/lisp/simple.el b/lisp/simple.el
index eb65701803..50aed97680 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -6031,21 +6031,61 @@ backward-delete-char-untabify
;; Avoid warning about delete-backward-char
(with-no-warnings (delete-backward-char n killp))))
-(defun zap-to-char (arg char)
+(defun zap--to-char-region (arg char up-to interactive)
+ "Return the region to kill with `zap-to-char'.
+
+Helper function for `zap-to-char' and `zap-up-to-char'.
+If UP-TO is non-nil then implement the later, otherwise the former.
+The rest of the arguments are described in the commands."
+ (with-no-warnings
+ (when (char-table-p translation-table-for-input)
+ (setq char (or (aref translation-table-for-input char) char))))
+ (let* ((str (char-to-string char))
+ (upper-case (let (case-fold-search)
+ (string-match-p "[[:upper:]]" str)))
+ (case-fold-search (if (and interactive upper-case)
+ nil
+ case-fold-search)))
+ (list (point) (if up-to (let ((direction (if (>= arg 0) 1 -1)))
+ (forward-char direction)
+ (unwind-protect
+ (search-forward str nil nil arg)
+ (backward-char direction))
+ (point))
+ (search-forward str nil nil arg)
+ (point)))))
+
+(defun zap-to-char (arg char &optional interactive)
"Kill up to and including ARGth occurrence of CHAR.
+Optional argument INTERACTIVE tells the function to behave as when
+it's called interactively.
Case is ignored if `case-fold-search' is non-nil in the current buffer.
Goes backward if ARG is negative; error if CHAR not found.
+Called interactively, do a case sensitive search if the char is an
+upper case letter.
See also `zap-up-to-char'."
(interactive (list (prefix-numeric-value current-prefix-arg)
(read-char-from-minibuffer "Zap to char: "
- nil 'read-char-history)))
- ;; Avoid "obsolete" warnings for translation-table-for-input.
- (with-no-warnings
- (if (char-table-p translation-table-for-input)
- (setq char (or (aref translation-table-for-input char) char))))
- (kill-region (point) (progn
- (search-forward (char-to-string char) nil nil arg)
- (point))))
+ nil 'read-char-history)
+ t))
+ (pcase-let ((`(,start ,end) (zap--to-char-region arg char nil interactive)))
+ (kill-region start end)))
+
+(defun zap-up-to-char (arg char &optional interactive)
+ "Kill up to, but not including ARGth occurrence of CHAR.
+Optional argument INTERACTIVE tells the function to behave as when
+it's called interactively.
+Case is ignored if `case-fold-search' is non-nil in the current buffer.
+Goes backward if ARG is negative; error if CHAR not found.
+Called interactively, do a case sensitive search if the char is an
+upper case letter.
+Ignores CHAR at point."
+ (interactive (list (prefix-numeric-value current-prefix-arg)
+ (read-char-from-minibuffer "Zap up to char: "
+ nil 'read-char-history)
+ t))
+ (pcase-let ((`(,start ,end) (zap--to-char-region arg char 'up-to interactive)))
+ (kill-region start end)))
;; kill-line and its subroutines.
diff --git a/test/lisp/misc-tests.el b/test/lisp/misc-tests.el
index 36a8726b88..bec786c8c7 100644
--- a/test/lisp/misc-tests.el
+++ b/test/lisp/misc-tests.el
@@ -38,14 +38,6 @@ misc-test-copy-from-above-command
(with-misc-test "abc\n" "abc\nab"
(copy-from-above-command 2)))
-(ert-deftest misc-test-zap-up-to-char ()
- (with-misc-test "abcde" "cde"
- (goto-char (point-min))
- (zap-up-to-char 1 ?c))
- (with-misc-test "abcde abc123" "c123"
- (goto-char (point-min))
- (zap-up-to-char 2 ?c)))
-
(ert-deftest misc-test-upcase-char ()
(with-misc-test "abcde" "aBCDe"
(goto-char (1+ (point-min)))
diff --git a/test/lisp/simple-tests.el b/test/lisp/simple-tests.el
index 6350bebeee..b26a4e4b83 100644
--- a/test/lisp/simple-tests.el
+++ b/test/lisp/simple-tests.el
@@ -971,5 +971,43 @@ test-undo-region
;;(should (= (length (delq nil (undo-make-selective-list 5 9))) 0))
(should (= (length (delq nil (undo-make-selective-list 6 9))) 0))))
+(defmacro with-simple-test (original result &rest body)
+ (declare (indent 2) (debug (stringp stringp body)))
+ `(with-temp-buffer
+ (insert ,original)
+ ,@body
+ (should (equal (buffer-string) ,result))))
+
+(ert-deftest simple-tests-zap-to-char ()
+ (with-simple-test "abcde" "de"
+ (goto-char (point-min))
+ (zap-to-char 1 ?c))
+ (with-simple-test "abcde abc123" "123"
+ (goto-char (point-min))
+ (zap-to-char 2 ?c))
+ (let ((case-fold-search t))
+ (with-simple-test "abcdeCXYZ" "deCXYZ"
+ (goto-char (point-min))
+ (zap-to-char 1 ?C))
+ (with-simple-test "abcdeCXYZ" "XYZ"
+ (goto-char (point-min))
+ (zap-to-char 1 ?C 'interactive))))
+
+(ert-deftest simple-tests-zap-up-to-char ()
+ (with-simple-test "abcde" "cde"
+ (goto-char (point-min))
+ (zap-up-to-char 1 ?c))
+ (with-simple-test "abcde abc123" "c123"
+ (goto-char (point-min))
+ (zap-up-to-char 2 ?c))
+ (let ((case-fold-search t))
+ (with-simple-test "abcdeCXYZ" "cdeCXYZ"
+ (goto-char (point-min))
+ (zap-up-to-char 1 ?C))
+ (with-simple-test "abcdeCXYZ" "CXYZ"
+ (goto-char (point-min))
+ (zap-up-to-char 1 ?C 'interactive))))
+
+
(provide 'simple-test)
;;; simple-tests.el ends here
--8<-----------------------------cut here---------------end--------------->8---
In GNU Emacs 29.0.50 (build 1, x86_64-pc-linux-gnu, X toolkit, cairo version 1.16.0, Xaw scroll bars)
of 2022-04-08 built
Repository revision: 022a1f48a4e2005be7aa66b67eb2f17f8386c853
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version 11.0.12011000
System Description: Debian GNU/Linux 11 (bullseye)
^ permalink raw reply related [flat|nested] 30+ messages in thread
* bug#54804: 29.0.50; zap-to-char: case sensitive for upper-case letter
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
0 siblings, 1 reply; 30+ messages in thread
From: Eli Zaretskii @ 2022-04-09 6:03 UTC (permalink / raw)
To: Tino Calancha; +Cc: 54804, uyennhi.qm
> From: Tino Calancha <tino.calancha@gmail.com>
> Date: Sat, 09 Apr 2022 00:03:45 +0200
> Cc: uyennhi.qm@gmail.com
>
> A wishlist for the `zap-to-char' and `zap-up-to-char':
> In interactive calls, when users input an upper-case letter then perform
> a case-sensitive search.
>
> This behavior is analog to what `isearch' does.
Thanks, but why does the implementation have to be so complicated?
Isn't this just about turning off case-fold-search while searching for
the character? What am I missing?
^ permalink raw reply [flat|nested] 30+ messages in thread
* bug#54804: 29.0.50; zap-to-char: case sensitive for upper-case letter
2022-04-09 6:03 ` Eli Zaretskii
@ 2022-04-16 10:58 ` Tino Calancha
2022-04-16 11:33 ` Eli Zaretskii
0 siblings, 1 reply; 30+ messages in thread
From: Tino Calancha @ 2022-04-16 10:58 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: 54804, uyennhi.qm
Eli Zaretskii <eliz@gnu.org> writes:
>> A wishlist for the `zap-to-char' and `zap-up-to-char':
>> In interactive calls, when users input an upper-case letter then perform
>> a case-sensitive search.
>>
>> This behavior is analog to what `isearch' does.
>
> but why does the implementation have to be so complicated?
> Isn't this just about turning off case-fold-search while searching for
> the character? What am I missing?
The patch is moving the shared code in zap-to/zap-up-to in a
helper function. This has 2 motivations:
- reduce the code duplication.
- define these two related functions close each other.
- separate the logic of the function to calculate the region to kill.
If you prefer, we can keep the functions in their current
locations (simple.el/misc.el) with a patch like this one:
--8<-----------------------------cut here---------------start------------->8---
diff --git a/lisp/misc.el b/lisp/misc.el
index d85f889ffd..e771d2b315 100644
--- a/lisp/misc.el
+++ b/lisp/misc.el
@@ -64,20 +64,32 @@ copy-from-above-command
;; Variation of `zap-to-char'.
;;;###autoload
-(defun zap-up-to-char (arg char)
+(defun zap-up-to-char (arg char &optional interactive)
"Kill up to, but not including ARGth occurrence of CHAR.
Case is ignored if `case-fold-search' is non-nil in the current buffer.
Goes backward if ARG is negative; error if CHAR not found.
-Ignores CHAR at point."
+Ignores CHAR at point.
+Called interactively, do a case sensitive search if the char is an
+upper case letter."
(interactive (list (prefix-numeric-value current-prefix-arg)
(read-char-from-minibuffer "Zap up to char: "
- nil 'read-char-history)))
- (let ((direction (if (>= arg 0) 1 -1)))
+ nil 'read-char-history)
+ t))
+ ;; Avoid "obsolete" warnings for translation-table-for-input.
+ (with-no-warnings
+ (if (char-table-p translation-table-for-input)
+ (setq char (or (aref translation-table-for-input char) char))))
+ (let* ((direction (if (>= arg 0) 1 -1))
+ (str (char-to-string char))
+ (upper-case (let (case-fold-search) (string-match-p "[[:upper:]]" str)))
+ (case-fold-search (if (and interactive upper-case)
+ nil
+ case-fold-search)))
(kill-region (point)
(progn
(forward-char direction)
(unwind-protect
- (search-forward (char-to-string char) nil nil arg)
+ (search-forward str nil nil arg)
(backward-char direction))
(point)))))
diff --git a/lisp/simple.el b/lisp/simple.el
index eb65701803..2f3c43b9db 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -6031,21 +6031,27 @@ backward-delete-char-untabify
;; Avoid warning about delete-backward-char
(with-no-warnings (delete-backward-char n killp))))
-(defun zap-to-char (arg char)
+(defun zap-to-char (arg char &optional interactive)
"Kill up to and including ARGth occurrence of CHAR.
Case is ignored if `case-fold-search' is non-nil in the current buffer.
Goes backward if ARG is negative; error if CHAR not found.
-See also `zap-up-to-char'."
+See also `zap-up-to-char'.
+Called interactively, do a case sensitive search if the char is an
+upper case letter."
(interactive (list (prefix-numeric-value current-prefix-arg)
(read-char-from-minibuffer "Zap to char: "
- nil 'read-char-history)))
+ nil 'read-char-history))
+ t)
;; Avoid "obsolete" warnings for translation-table-for-input.
(with-no-warnings
(if (char-table-p translation-table-for-input)
(setq char (or (aref translation-table-for-input char) char))))
- (kill-region (point) (progn
- (search-forward (char-to-string char) nil nil arg)
- (point))))
+ (let* ((str (char-to-string char))
+ (upper-case (let (case-fold-search) (string-match-p "[[:upper:]]" str)))
+ (case-fold-search (if (and interactive upper-case)
+ nil
+ case-fold-search)))
+ (kill-region (point) (search-forward str nil nil arg))))
;; kill-line and its subroutines.
--8<-----------------------------cut here---------------end--------------->8---
^ permalink raw reply related [flat|nested] 30+ messages in thread
* bug#54804: 29.0.50; zap-to-char: case sensitive for upper-case letter
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
0 siblings, 2 replies; 30+ messages in thread
From: Eli Zaretskii @ 2022-04-16 11:33 UTC (permalink / raw)
To: Tino Calancha; +Cc: 54804, uyennhi.qm
> From: Tino Calancha <tino.calancha@gmail.com>
> Cc: 54804@debbugs.gnu.org, uyennhi.qm@gmail.com
> Date: Sat, 16 Apr 2022 12:58:06 +0200
>
> Eli Zaretskii <eliz@gnu.org> writes:
>
> > but why does the implementation have to be so complicated?
> > Isn't this just about turning off case-fold-search while searching for
> > the character? What am I missing?
>
> The patch is moving the shared code in zap-to/zap-up-to in a
> helper function. This has 2 motivations:
> - reduce the code duplication.
> - define these two related functions close each other.
> - separate the logic of the function to calculate the region to kill.
>
> If you prefer, we can keep the functions in their current
> locations (simple.el/misc.el) with a patch like this one:
What I'd prefer is to have a single function (in subr.el) that
determines whether a character is an upper- or lower-case, and then
use that function in a simple condition in these two commands.
The function to check whether a character is upper-case doesn't have
to make a string from the character and then use the "heavy artillery"
of string-match-p, 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.)
> + ;; Avoid "obsolete" warnings for translation-table-for-input.
> + (with-no-warnings
> + (if (char-table-p translation-table-for-input)
> + (setq char (or (aref translation-table-for-input char) char))))
translation-table-for-input is obsolete for a reason, so adding it to
a new function is not something we want to do. If anything, we should
remove it from the old function.
^ permalink raw reply [flat|nested] 30+ messages in thread
* bug#54804: 29.0.50; zap-to-char: case sensitive for upper-case letter
2022-04-16 11:33 ` Eli Zaretskii
@ 2022-05-09 16:17 ` Sean Whitton
2022-05-10 21:14 ` Tino Calancha
1 sibling, 0 replies; 30+ messages in thread
From: Sean Whitton @ 2022-05-09 16:17 UTC (permalink / raw)
To: Tino Calancha; +Cc: 54804, Eli Zaretskii, uyennhi.qm
Hello Tino,
Any progress on this? I would like this functionality. Thanks.
On Sat 16 Apr 2022 at 02:33pm +03, Eli Zaretskii wrote:
>> From: Tino Calancha <tino.calancha@gmail.com>
>> Cc: 54804@debbugs.gnu.org, uyennhi.qm@gmail.com
>> Date: Sat, 16 Apr 2022 12:58:06 +0200
>>
>> Eli Zaretskii <eliz@gnu.org> writes:
>>
>> > but why does the implementation have to be so complicated?
>> > Isn't this just about turning off case-fold-search while searching for
>> > the character? What am I missing?
>>
>> The patch is moving the shared code in zap-to/zap-up-to in a
>> helper function. This has 2 motivations:
>> - reduce the code duplication.
>> - define these two related functions close each other.
>> - separate the logic of the function to calculate the region to kill.
>>
>> If you prefer, we can keep the functions in their current
>> locations (simple.el/misc.el) with a patch like this one:
>
> What I'd prefer is to have a single function (in subr.el) that
> determines whether a character is an upper- or lower-case, and then
> use that function in a simple condition in these two commands.
>
> The function to check whether a character is upper-case doesn't have
> to make a string from the character and then use the "heavy artillery"
> of string-match-p, 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.)
>
>> + ;; Avoid "obsolete" warnings for translation-table-for-input.
>> + (with-no-warnings
>> + (if (char-table-p translation-table-for-input)
>> + (setq char (or (aref translation-table-for-input char) char))))
>
> translation-table-for-input is obsolete for a reason, so adding it to
> a new function is not something we want to do. If anything, we should
> remove it from the old function.
>
>
>
--
Sean Whitton
^ permalink raw reply [flat|nested] 30+ messages in thread
* bug#54804: 29.0.50; zap-to-char: case sensitive for upper-case letter
2022-04-16 11:33 ` Eli Zaretskii
2022-05-09 16:17 ` Sean Whitton
@ 2022-05-10 21:14 ` Tino Calancha
2022-05-11 11:15 ` Eli Zaretskii
1 sibling, 1 reply; 30+ messages in thread
From: Tino Calancha @ 2022-05-10 21:14 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: 54804, uyennhi.qm, Sean Whitton
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---
^ permalink raw reply related [flat|nested] 30+ messages in thread
* bug#54804: 29.0.50; zap-to-char: case sensitive for upper-case letter
2022-05-10 21:14 ` Tino Calancha
@ 2022-05-11 11:15 ` Eli Zaretskii
2022-05-11 14:43 ` Tino Calancha
0 siblings, 1 reply; 30+ messages in thread
From: Eli Zaretskii @ 2022-05-11 11:15 UTC (permalink / raw)
To: Tino Calancha; +Cc: 54804, uyennhi.qm, spwhitton
> From: Tino Calancha <tino.calancha@gmail.com>
> Cc: 54804@debbugs.gnu.org, uyennhi.qm@gmail.com, Sean Whitton
> <spwhitton@spwhitton.name>
> Date: Tue, 10 May 2022 23:14:20 +0200
>
> 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?
Yes, thanks. But please call it char-uppercase-p ("upcase" has the
meaning of making a character upper-case).
^ permalink raw reply [flat|nested] 30+ messages in thread
* bug#54804: 29.0.50; zap-to-char: case sensitive for upper-case letter
2022-05-11 11:15 ` Eli Zaretskii
@ 2022-05-11 14:43 ` Tino Calancha
2022-05-11 14:50 ` Lars Ingebrigtsen
` (2 more replies)
0 siblings, 3 replies; 30+ messages in thread
From: Tino Calancha @ 2022-05-11 14:43 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: 54804, uyennhi.qm, spwhitton
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---
^ permalink raw reply related [flat|nested] 30+ messages in thread
* bug#54804: 29.0.50; zap-to-char: case sensitive for upper-case letter
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:57 ` Eli Zaretskii
2 siblings, 0 replies; 30+ messages in thread
From: Lars Ingebrigtsen @ 2022-05-11 14:50 UTC (permalink / raw)
To: Tino Calancha; +Cc: Eli Zaretskii, spwhitton, 54804, uyennhi.qm
Tino Calancha <tino.calancha@gmail.com> writes:
> +This function returns non-nil if @var{char} is an uppercase unicode
> +character.
Do we need to say "Unicode characters" here? I think many will
interpret that to mean that it doesn't work on ASCII characters (which
it seems like it's doing).
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
^ permalink raw reply [flat|nested] 30+ messages in thread
* bug#54804: 29.0.50; zap-to-char: case sensitive for upper-case letter
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:57 ` Eli Zaretskii
2 siblings, 2 replies; 30+ messages in thread
From: Robert Pluim @ 2022-05-11 15:00 UTC (permalink / raw)
To: Tino Calancha; +Cc: Eli Zaretskii, spwhitton, 54804, uyennhi.qm
>>>>> On Wed, 11 May 2022 16:43:06 +0200, Tino Calancha <tino.calancha@gmail.com> said:
Tino> 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).
Tino> I'd like to add this `char-uppercase-p'.
Tino> Once merged, I will finish with the goal of the report.
Tino> I appreciate a hand with the documentation part.
Youʼre *asking* us to nit-pick? Youʼre a brave person ☺️
Tino> commit aa270a4b8813ac226a61d8e6919f68e9e4ed0973
Tino> Author: Tino Calancha <tino.calancha@gmail.com>
Tino> Date: Wed May 11 16:34:33 2022 +0200
Tino> char-uppercase-p: New predicate
Tino> Return non-nil if its argument is an upper-case unicode character.
Tino> Suggested in Bug#54804.
Tino> * lisp/subr.el (char-uppercase-p): New defun.
Tino> * etc/NEWS (Lisp Changes in Emacs 29.1): Announce it
Tino> * doc/lispref/display.texi (Size of Displayed Text): Document it.
Tino> * test/lisp/subr-tests.el (test-char-uppercase-p): Add a test.
Tino> diff --git a/doc/lispref/display.texi b/doc/lispref/display.texi
Tino> index 9650d22790..1c32458d62 100644
Tino> --- a/doc/lispref/display.texi
Tino> +++ b/doc/lispref/display.texi
Tino> @@ -2010,6 +2010,14 @@ Size of Displayed Text
Tino> (@pxref{Usual Display}).
Tino> @end defun
Tino> +@defun char-uppercase-p char
Tino> +This function returns non-nil if @var{char} is an uppercase unicode
Tino> +character. Be aware that if the Unicode tables are not yet available,
Tino> +e.g. during bootstrap, then this function gives the right answer only
Tino> +for @acronym{ASCII} characters; for other characters the function
Tino> +unconditionally returns @code{nil}.
Tino> +@end defun
Tino> +
Be active: 'Return non-nil if ...'. So:
Return non-@code{nil} if @var{char} is an uppercase character
according to Unicode. Be aware that if the Unicode tables are not yet
available, e.g. during bootstrap, this gives the correct answer only
for @acronym{ASCII} characters; for other characters it always returns
@code{nil}.
Tino> @defun string-width string &optional from to
Tino> This function returns the width in columns of the string @var{string},
Tino> if it were displayed in the current buffer and the selected window.
Tino> diff --git a/etc/NEWS b/etc/NEWS
Tino> index 991088a067..57c254bce8 100644
Tino> --- a/etc/NEWS
Tino> +++ b/etc/NEWS
Tino> @@ -1794,6 +1794,10 @@ value. The byte compiler will now issue a warning if it encounters
Tino> these forms.
Tino> ++++
Tino> +*** The new predicate 'char-uppercase-p' returns non-nil if its
Tino> +argument its an uppercase unicode character.
The header line should fit on one line. So
*** New predicate 'char-uppercase-p'.
This returns...
Tino> +
Tino> +++
Tino> *** 'restore-buffer-modified-p' can now alter buffer auto-save state.
Tino> With a FLAG value of 'autosaved', it will mark the buffer as having
Tino> diff --git a/lisp/simple.el b/lisp/simple.el
Tino> index 89fb0ea97e..525e636ab6 100644
Tino> --- a/lisp/simple.el
Tino> +++ b/lisp/simple.el
Tino> @@ -6054,6 +6054,14 @@ backward-delete-char-untabify
Tino> ;; Avoid warning about delete-backward-char
Tino> (with-no-warnings (delete-backward-char n killp))))
Tino> +(defun char-uppercase-p (char)
Tino> + "Return non-nil if CHAR is an upper-case unicode character.
Tino> +If the Unicode tables are not yet available, e.g. during bootstrap,
Tino> +then the function restricts to the ASCII character set."
Iʼd say 'gives correct answers only for ASCII characters'
Robert
--
^ permalink raw reply [flat|nested] 30+ messages in thread
* bug#54804: 29.0.50; zap-to-char: case sensitive for upper-case letter
2022-05-11 15:00 ` Robert Pluim
@ 2022-05-11 15:19 ` Tino Calancha
2022-05-11 15:27 ` Andreas Schwab
1 sibling, 0 replies; 30+ messages in thread
From: Tino Calancha @ 2022-05-11 15:19 UTC (permalink / raw)
To: Robert Pluim; +Cc: uyennhi.qm, Eli Zaretskii, 54804, spwhitton
Lars Ingebrigtsen <larsi@gnus.org> writes:
> Do we need to say "Unicode characters" here? I think many will
> interpret that to mean that it doesn't work on ASCII characters (which
> it seems like it's doing).
Good point. I have dropped Unicode.
Robert Pluim <rpluim@gmail.com> writes:
> Tino> I appreciate a hand with the documentation part.
>
> Youʼre *asking* us to nit-pick? Youʼre a brave person ☺️
You know, I've never had a native english speaker gf. Sniff, sniff.
Thanks for the great suggestions. All are in.
Now I am pushing these changes.
^ permalink raw reply [flat|nested] 30+ messages in thread
* bug#54804: 29.0.50; zap-to-char: case sensitive for upper-case letter
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
1 sibling, 1 reply; 30+ messages in thread
From: Andreas Schwab @ 2022-05-11 15:27 UTC (permalink / raw)
To: Robert Pluim; +Cc: uyennhi.qm, Eli Zaretskii, spwhitton, 54804, Tino Calancha
On Mai 11 2022, Robert Pluim wrote:
> Return non-@code{nil} if @var{char} is an uppercase character
> according to Unicode. Be aware that if the Unicode tables are not yet
> available, e.g. during bootstrap, this gives the correct answer only
> for @acronym{ASCII} characters; for other characters it always returns
> @code{nil}.
I don't think it is necessary to talk about bootstrapping in the manual.
--
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510 2552 DF73 E780 A9DA AEC1
"And now for something completely different."
^ permalink raw reply [flat|nested] 30+ messages in thread
* bug#54804: 29.0.50; zap-to-char: case sensitive for upper-case letter
2022-05-11 15:27 ` Andreas Schwab
@ 2022-05-11 15:38 ` Tino Calancha
2022-05-11 16:11 ` Andreas Schwab
0 siblings, 1 reply; 30+ messages in thread
From: Tino Calancha @ 2022-05-11 15:38 UTC (permalink / raw)
To: Andreas Schwab
Cc: 54804, Tino Calancha, Robert Pluim, Eli Zaretskii, uyennhi.qm,
spwhitton
On Wed, 11 May 2022, Andreas Schwab wrote:
> On Mai 11 2022, Robert Pluim wrote:
>
>> Return non-@code{nil} if @var{char} is an uppercase character
>> according to Unicode. Be aware that if the Unicode tables are not yet
>> available, e.g. during bootstrap, this gives the correct answer only
>> for @acronym{ASCII} characters; for other characters it always returns
>> @code{nil}.
>
> I don't think it is necessary to talk about bootstrapping in the manual.
Right... How about replacing?
"available, e.g. during bootstrap, this gives the correct answer only..."
with
"available, e.g. while compiling the Emac source code, this gives the
correct answer only..."
PD: I am having issues pushing: my password is not working.
If I am not able to make it work, then I will post here the final
patch so that someone else can push it.
^ permalink raw reply [flat|nested] 30+ messages in thread
* bug#54804: 29.0.50; zap-to-char: case sensitive for upper-case letter
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:57 ` Eli Zaretskii
2 siblings, 0 replies; 30+ messages in thread
From: Eli Zaretskii @ 2022-05-11 15:57 UTC (permalink / raw)
To: Tino Calancha; +Cc: 54804, uyennhi.qm, spwhitton
> From: Tino Calancha <tino.calancha@gmail.com>
> Cc: 54804@debbugs.gnu.org, uyennhi.qm@gmail.com, spwhitton@spwhitton.name
> Date: Wed, 11 May 2022 16:43:06 +0200
>
> +@defun char-uppercase-p char
> +This function returns non-nil if @var{char} is an uppercase unicode
^^^
@code{nil}
> +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}.
This manual is not for Emacs developers, it is for Lisp programmers.
Therefore, the last sentence should be removed.
> ++++
> +*** The new predicate 'char-uppercase-p' returns non-nil if its
> +argument its an uppercase unicode character.
The first line of a NEWS entry should be a complete sentence, and end
with a period.
> +(defun char-uppercase-p (char)
> + "Return non-nil if CHAR is an upper-case unicode character.
Just "upper-case character", no need to say "Unicode".
Thanks.
^ permalink raw reply [flat|nested] 30+ messages in thread
* bug#54804: 29.0.50; zap-to-char: case sensitive for upper-case letter
2022-05-11 15:38 ` Tino Calancha
@ 2022-05-11 16:11 ` Andreas Schwab
2022-05-11 16:18 ` Tino Calancha
0 siblings, 1 reply; 30+ messages in thread
From: Andreas Schwab @ 2022-05-11 16:11 UTC (permalink / raw)
To: Tino Calancha; +Cc: uyennhi.qm, Robert Pluim, 54804, Eli Zaretskii, spwhitton
On Mai 11 2022, Tino Calancha wrote:
> On Wed, 11 May 2022, Andreas Schwab wrote:
>
>> On Mai 11 2022, Robert Pluim wrote:
>>
>>> Return non-@code{nil} if @var{char} is an uppercase character
>>> according to Unicode. Be aware that if the Unicode tables are not yet
>>> available, e.g. during bootstrap, this gives the correct answer only
>>> for @acronym{ASCII} characters; for other characters it always returns
>>> @code{nil}.
>>
>> I don't think it is necessary to talk about bootstrapping in the manual.
> Right... How about replacing?
> "available, e.g. during bootstrap, this gives the correct answer only..."
>
> with
>
> "available, e.g. while compiling the Emac source code, this gives the
> correct answer only..."
I don't think there is a need for this at all in the manual. It could
be added as a comment in the source, though.
--
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510 2552 DF73 E780 A9DA AEC1
"And now for something completely different."
^ permalink raw reply [flat|nested] 30+ messages in thread
* bug#54804: 29.0.50; zap-to-char: case sensitive for upper-case letter
2022-05-11 16:11 ` Andreas Schwab
@ 2022-05-11 16:18 ` Tino Calancha
2022-05-12 15:55 ` Tino Calancha
0 siblings, 1 reply; 30+ messages in thread
From: Tino Calancha @ 2022-05-11 16:18 UTC (permalink / raw)
To: Andreas Schwab
Cc: 54804, Tino Calancha, Robert Pluim, Eli Zaretskii, uyennhi.qm,
spwhitton
On Wed, 11 May 2022, Andreas Schwab wrote:
>> "available, e.g. while compiling the Emac source code, this gives the
>> correct answer only..."
>
> I don't think there is a need for this at all in the manual. It could
> be added as a comment in the source, though.
I have removed completely that sentence and pushed
to the master branch.
Thank you Andreas.
^ permalink raw reply [flat|nested] 30+ messages in thread
* bug#54804: 29.0.50; zap-to-char: case sensitive for upper-case letter
2022-05-11 16:18 ` Tino Calancha
@ 2022-05-12 15:55 ` Tino Calancha
2022-05-13 6:48 ` Eli Zaretskii
2022-05-20 22:59 ` Sean Whitton
0 siblings, 2 replies; 30+ messages in thread
From: Tino Calancha @ 2022-05-12 15:55 UTC (permalink / raw)
To: Andreas Schwab; +Cc: 54804, spwhitton, Eli Zaretskii, Robert Pluim, uyennhi.qm
Tino Calancha <tino.calancha@gmail.com> writes:
> I have removed completely that sentence and pushed
> to the master branch.
The Empire Strikes Back
--8<-----------------------------cut here---------------start------------->8---
commit 86750ab021ea889766a717458ed28a54e6a40ad3
Author: Tino Calancha <tino.calancha@gmail.com>
Date: Thu May 12 17:48:09 2022 +0200
zap-to-char: case sensitive for upper-case characters
In interactive calls, behave case-sensitively if the given char
is an upper-case character. Same for zap-up-to-char.
This is analog to what the user-level incremental search feature does.
* lisp/misc.el (zap-up-to-char): Add an optional arg INTERACTIVE.
Perform a case-sensitive search when INTERACTIVE is non-nil and
CHAR is an upper-case character.
* lisp/simple.el (zap-to-char): Same.
* etc/NEWS (Editing Changes in Emacs 29.1): Announce this change.
* test/lisp/misc-tests.el ((misc-test-zap-up-to-char): Add test cases.
* test/lisp/simple-tests.el (with-simple-test): Add helper macro.
(simple-tests-zap-to-char): Add a test.
diff --git a/etc/NEWS b/etc/NEWS
index 3bdc497f18..d6493e77e5 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -672,6 +672,12 @@ recreate it anew next time 'imenu' is invoked.
* Editing Changes in Emacs 29.1
+---
+** 'zap-to-char' case sensitivity on interactive calls.
+The command now behaves as case-sensitive for interactive calls when is
+invoked with an uppercase argument, regardless of the
+`case-fold-search' value. Likewise, for 'zap-up-to-char'.
+
---
** 'scroll-other-window' and 'scroll-other-window-down' now respects remapping.
These commands (bound to 'C-M-v' and 'C-M-V') used to scroll the other
diff --git a/lisp/misc.el b/lisp/misc.el
index d85f889ffd..f92debf013 100644
--- a/lisp/misc.el
+++ b/lisp/misc.el
@@ -64,15 +64,21 @@ copy-from-above-command
;; Variation of `zap-to-char'.
;;;###autoload
-(defun zap-up-to-char (arg char)
+(defun zap-up-to-char (arg char &optional interactive)
"Kill up to, but not including ARGth occurrence of CHAR.
Case is ignored if `case-fold-search' is non-nil in the current buffer.
Goes backward if ARG is negative; error if CHAR not found.
-Ignores CHAR at point."
+Ignores CHAR at point.
+Called interactively, do a case sensitive search if CHAR
+is an upper-case character."
(interactive (list (prefix-numeric-value current-prefix-arg)
(read-char-from-minibuffer "Zap up to char: "
- nil 'read-char-history)))
- (let ((direction (if (>= arg 0) 1 -1)))
+ nil 'read-char-history)
+ t))
+ (let ((direction (if (>= arg 0) 1 -1))
+ (case-fold-search (if (and interactive (char-uppercase-p char))
+ nil
+ case-fold-search)))
(kill-region (point)
(progn
(forward-char direction)
diff --git a/lisp/simple.el b/lisp/simple.el
index 3812f6d8c6..7d6c55c190 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -6062,21 +6062,25 @@ char-uppercase-p
(characterp (get-char-code-property char 'lowercase)))
((and (>= char ?A) (<= char ?Z)))))
-(defun zap-to-char (arg char)
+(defun zap-to-char (arg char &optional interactive)
"Kill up to and including ARGth occurrence of CHAR.
Case is ignored if `case-fold-search' is non-nil in the current buffer.
Goes backward if ARG is negative; error if CHAR not found.
-See also `zap-up-to-char'."
+See also `zap-up-to-char'.
+Called interactively, do a case sensitive search if CHAR
+is an upper-case character."
(interactive (list (prefix-numeric-value current-prefix-arg)
(read-char-from-minibuffer "Zap to char: "
- nil 'read-char-history)))
+ nil 'read-char-history))
+ t)
;; Avoid "obsolete" warnings for translation-table-for-input.
(with-no-warnings
(if (char-table-p translation-table-for-input)
(setq char (or (aref translation-table-for-input char) char))))
- (kill-region (point) (progn
- (search-forward (char-to-string char) nil nil arg)
- (point))))
+ (let ((case-fold-search (if (and interactive (char-uppercase-p char))
+ nil
+ case-fold-search)))
+ (kill-region (point) (search-forward (char-to-string char) nil nil arg))))
;; kill-line and its subroutines.
diff --git a/test/lisp/misc-tests.el b/test/lisp/misc-tests.el
index 36a8726b88..236223ef49 100644
--- a/test/lisp/misc-tests.el
+++ b/test/lisp/misc-tests.el
@@ -44,7 +44,14 @@ misc-test-zap-up-to-char
(zap-up-to-char 1 ?c))
(with-misc-test "abcde abc123" "c123"
(goto-char (point-min))
- (zap-up-to-char 2 ?c)))
+ (zap-up-to-char 2 ?c))
+ (let ((case-fold-search t))
+ (with-misc-test "abcdeCXYZ" "cdeCXYZ"
+ (goto-char (point-min))
+ (zap-up-to-char 1 ?C))
+ (with-misc-test "abcdeCXYZ" "CXYZ"
+ (goto-char (point-min))
+ (zap-up-to-char 1 ?C 'interactive))))
(ert-deftest misc-test-upcase-char ()
(with-misc-test "abcde" "aBCDe"
diff --git a/test/lisp/simple-tests.el b/test/lisp/simple-tests.el
index dcab811bb5..2baf7124d7 100644
--- a/test/lisp/simple-tests.el
+++ b/test/lisp/simple-tests.el
@@ -971,5 +971,27 @@ test-undo-region
;;(should (= (length (delq nil (undo-make-selective-list 5 9))) 0))
(should (= (length (delq nil (undo-make-selective-list 6 9))) 0))))
+\f
+;;; Tests for `zap-to-char'
+
+(defmacro with-simple-test (original result &rest body)
+ (declare (indent 2) (debug (stringp stringp body)))
+ `(with-temp-buffer
+ (insert ,original)
+ (goto-char (point-min))
+ ,@body
+ (should (equal (buffer-string) ,result))))
+
+(ert-deftest simple-tests-zap-to-char ()
+ (with-simple-test "abcde" "de"
+ (zap-to-char 1 ?c))
+ (with-simple-test "abcde abc123" "123"
+ (zap-to-char 2 ?c))
+ (let ((case-fold-search t))
+ (with-simple-test "abcdeCXYZ" "deCXYZ"
+ (zap-to-char 1 ?C))
+ (with-simple-test "abcdeCXYZ" "XYZ"
+ (zap-to-char 1 ?C 'interactive))))
+
(provide 'simple-test)
;;; simple-tests.el ends here
--8<-----------------------------cut here---------------end--------------->8---
^ permalink raw reply related [flat|nested] 30+ messages in thread
* bug#54804: 29.0.50; zap-to-char: case sensitive for upper-case letter
2022-05-12 15:55 ` Tino Calancha
@ 2022-05-13 6:48 ` Eli Zaretskii
2022-05-17 12:34 ` Tino Calancha
2022-05-18 7:25 ` Tino Calancha
2022-05-20 22:59 ` Sean Whitton
1 sibling, 2 replies; 30+ messages in thread
From: Eli Zaretskii @ 2022-05-13 6:48 UTC (permalink / raw)
To: Tino Calancha; +Cc: 54804, spwhitton, schwab, rpluim, uyennhi.qm
> From: Tino Calancha <tino.calancha@gmail.com>
> Cc: 54804@debbugs.gnu.org, Robert Pluim <rpluim@gmail.com>, Eli Zaretskii
> <eliz@gnu.org>, uyennhi.qm@gmail.com, spwhitton@spwhitton.name
> Date: Thu, 12 May 2022 17:55:38 +0200
>
> * lisp/misc.el (zap-up-to-char): Add an optional arg INTERACTIVE.
> Perform a case-sensitive search when INTERACTIVE is non-nil and
> CHAR is an upper-case character.
I don't understand why the need for the new INTERACTIVE argument. It
is also undocumented in the doc strings.
> --- a/etc/NEWS
> +++ b/etc/NEWS
> @@ -672,6 +672,12 @@ recreate it anew next time 'imenu' is invoked.
>
> * Editing Changes in Emacs 29.1
>
> +---
> +** 'zap-to-char' case sensitivity on interactive calls.
NEWS is read in Outline mode, and its text should make sense when only
the headings are visible. The above heading doesn't have enough
information to be useful without the body, because it says almost
nothing about the change. Here's a better heading:
** 'zap-to-char' and 'zap-up-to-char' are case-sensitive for upper-case chars
> +The command now behaves as case-sensitive for interactive calls when is
> +invoked with an uppercase argument, regardless of the
> +`case-fold-search' value. Likewise, for 'zap-up-to-char'.
The body should describe both commands equally.
> -(defun zap-up-to-char (arg char)
> +(defun zap-up-to-char (arg char &optional interactive)
> "Kill up to, but not including ARGth occurrence of CHAR.
> Case is ignored if `case-fold-search' is non-nil in the current buffer.
> Goes backward if ARG is negative; error if CHAR not found.
> -Ignores CHAR at point."
> +Ignores CHAR at point.
> +Called interactively, do a case sensitive search if CHAR
"If called interactively, ..."
And, as mentioned above, I don't think I understand why we need to do
this only in interactive calls. Non-interactive invocations already
have a way to request case-sensitivity, by let-binding
case-fold-search, right?
> diff --git a/test/lisp/simple-tests.el b/test/lisp/simple-tests.el
> index dcab811bb5..2baf7124d7 100644
> --- a/test/lisp/simple-tests.el
> +++ b/test/lisp/simple-tests.el
> @@ -971,5 +971,27 @@ test-undo-region
> ;;(should (= (length (delq nil (undo-make-selective-list 5 9))) 0))
> (should (= (length (delq nil (undo-make-selective-list 6 9))) 0))))
>
> +\f
> +;;; Tests for `zap-to-char'
Should we have the tests for zap-* functions in one place, rather than
two?
> +(defmacro with-simple-test (original result &rest body)
> + (declare (indent 2) (debug (stringp stringp body)))
> + `(with-temp-buffer
> + (insert ,original)
> + (goto-char (point-min))
> + ,@body
> + (should (equal (buffer-string) ,result))))
This macro is specific to zap-* functions, I think. So its name
should reflect that fact.
Thanks.
^ permalink raw reply [flat|nested] 30+ messages in thread
* bug#54804: 29.0.50; zap-to-char: case sensitive for upper-case letter
2022-05-13 6:48 ` Eli Zaretskii
@ 2022-05-17 12:34 ` Tino Calancha
2022-05-17 12:41 ` Eli Zaretskii
2022-05-17 19:32 ` Juri Linkov
2022-05-18 7:25 ` Tino Calancha
1 sibling, 2 replies; 30+ messages in thread
From: Tino Calancha @ 2022-05-17 12:34 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: 54804, juri, uyennhi.qm, monnier, spwhitton
Eli Zaretskii <eliz@gnu.org> writes:
I have added Stefan, who suggests using the interactive arg (see
explanation below).
I have also added Juri, who is expert on isearch.
>> From: Tino Calancha <tino.calancha@gmail.com>
>> * lisp/misc.el (zap-up-to-char): Add an optional arg INTERACTIVE.
>> Perform a case-sensitive search when INTERACTIVE is non-nil and
>> CHAR is an upper-case character.
>
> I don't understand why the need for the new INTERACTIVE argument.
> And, as mentioned above, I don't think I understand why we need to do
> this only in interactive calls. Non-interactive invocations already
> have a way to request case-sensitivity, by let-binding
> case-fold-search, right?
I'll try to explain this.
This is what Emacs does for isearch/search.
If you go to the *scratch* buffer, and you do
C-s T C-s C-s
you only jump on 'T', that is, you skip the 't'. This is regardless
on the `case-fold-search' value.
Calling from Lisp:
(search-forward "T" nil t)
we'll also jump on the 't' if `case-fold-search' is non-nil.
I want the analog behavior for zap-to... commands: automatic
case sensitivity when the char is uppercase.
I want this behavior on interactive calls only, for instance when users
do `M-z'.
How to detect that the users are calling these commands interactively?
I got inspired from this comment found at the docstring of
`called-interactively-p' (Stefan wrote that):
"Instead of using this function, it is cleaner and more reliable to give your
function an extra optional argument whose ‘interactive’ spec specifies
non-nil unconditionally ("p" is a good way to do this), or via
(not (or executing-kbd-macro noninteractive))."
^ permalink raw reply [flat|nested] 30+ messages in thread
* bug#54804: 29.0.50; zap-to-char: case sensitive for upper-case letter
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 19:32 ` Juri Linkov
1 sibling, 1 reply; 30+ messages in thread
From: Eli Zaretskii @ 2022-05-17 12:41 UTC (permalink / raw)
To: Tino Calancha; +Cc: 54804, juri, uyennhi.qm, monnier, spwhitton
> From: Tino Calancha <tino.calancha@gmail.com>
> Cc: 54804@debbugs.gnu.org, spwhitton@spwhitton.name,uyennhi.qm@gmail.com,
> <monnier@iro.umontreal.ca>, juri@linkov.net
> Date: Tue, 17 May 2022 14:34:06 +0200
>
> Eli Zaretskii <eliz@gnu.org> writes:
>
> I have added Stefan, who suggests using the interactive arg (see
> explanation below).
> I have also added Juri, who is expert on isearch.
>
> >> From: Tino Calancha <tino.calancha@gmail.com>
> >> * lisp/misc.el (zap-up-to-char): Add an optional arg INTERACTIVE.
> >> Perform a case-sensitive search when INTERACTIVE is non-nil and
> >> CHAR is an upper-case character.
> >
> > I don't understand why the need for the new INTERACTIVE argument.
>
> > And, as mentioned above, I don't think I understand why we need to do
> > this only in interactive calls. Non-interactive invocations already
> > have a way to request case-sensitivity, by let-binding
> > case-fold-search, right?
>
> I'll try to explain this.
>
> This is what Emacs does for isearch/search.
Search is a much more complex set of features and commands in Emacs.
These two commands are much simpler, and I see no reason to try to be
compatible with search commands, since these two commands don't search
anything.
> I want the analog behavior for zap-to... commands: automatic
> case sensitivity when the char is uppercase.
> I want this behavior on interactive calls only, for instance when users
> do `M-z'.
As I said I disagree: these are DWIMish features that are best
reserved for interactive invocation. In calls from Lisp, it is
confusing to have the behavior change so drastically depending on the
letter-case of an argument.
^ permalink raw reply [flat|nested] 30+ messages in thread
* bug#54804: 29.0.50; zap-to-char: case sensitive for upper-case letter
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
0 siblings, 1 reply; 30+ messages in thread
From: Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2022-05-17 12:51 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: juri, 54804, spwhitton, uyennhi.qm, Tino Calancha
>> I want the analog behavior for zap-to... commands: automatic
>> case sensitivity when the char is uppercase.
>> I want this behavior on interactive calls only, for instance when users
>> do `M-z'.
>
> As I said I disagree: these are DWIMish features that are best
> reserved for interactive invocation. In calls from Lisp, it is
> confusing to have the behavior change so drastically depending on the
> letter-case of an argument.
Am I misunderstanding something or are you two violently agreeing?
Stefan
^ permalink raw reply [flat|nested] 30+ messages in thread
* bug#54804: 29.0.50; zap-to-char: case sensitive for upper-case letter
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
0 siblings, 1 reply; 30+ messages in thread
From: Tino Calancha @ 2022-05-17 12:53 UTC (permalink / raw)
To: Stefan Monnier
Cc: 54804, Tino Calancha, juri, Eli Zaretskii, uyennhi.qm, spwhitton
On Tue, 17 May 2022, Stefan Monnier wrote:
>>> I want the analog behavior for zap-to... commands: automatic
>>> case sensitivity when the char is uppercase.
>>> I want this behavior on interactive calls only, for instance when users
>>> do `M-z'.
>>
>> As I said I disagree: these are DWIMish features that are best
>> reserved for interactive invocation. In calls from Lisp, it is
>> confusing to have the behavior change so drastically depending on the
>> letter-case of an argument.
>
> Am I misunderstanding something or are you two violently agreeing?
We both agree with a sword in a hand.
I don't want to change the behavior on Lisp call!
Just let me know the nice way to detect that the call is interactive and
then I will inject the feature :-)
^ permalink raw reply [flat|nested] 30+ messages in thread
* bug#54804: 29.0.50; zap-to-char: case sensitive for upper-case letter
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
0 siblings, 1 reply; 30+ messages in thread
From: Eli Zaretskii @ 2022-05-17 13:38 UTC (permalink / raw)
To: Tino Calancha; +Cc: 54804, tino.calancha, juri, monnier, uyennhi.qm, spwhitton
> From: Tino Calancha <tino.calancha@gmail.com>
> Date: Tue, 17 May 2022 14:53:41 +0200 (CEST)
> cc: Eli Zaretskii <eliz@gnu.org>, Tino Calancha <tino.calancha@gmail.com>,
> 54804@debbugs.gnu.org, spwhitton@spwhitton.name, uyennhi.qm@gmail.com,
> juri@linkov.net
>
>
>
> On Tue, 17 May 2022, Stefan Monnier wrote:
>
> >>> I want the analog behavior for zap-to... commands: automatic
> >>> case sensitivity when the char is uppercase.
> >>> I want this behavior on interactive calls only, for instance when users
> >>> do `M-z'.
> >>
> >> As I said I disagree: these are DWIMish features that are best
> >> reserved for interactive invocation. In calls from Lisp, it is
> >> confusing to have the behavior change so drastically depending on the
> >> letter-case of an argument.
> >
> > Am I misunderstanding something or are you two violently agreeing?
>
> We both agree with a sword in a hand.
>
> I don't want to change the behavior on Lisp call!
> Just let me know the nice way to detect that the call is interactive and
> then I will inject the feature :-)
If you only make the search case-sensitive in the 'interactive' form,
that happens automagically.
^ permalink raw reply [flat|nested] 30+ messages in thread
* bug#54804: 29.0.50; zap-to-char: case sensitive for upper-case letter
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
0 siblings, 0 replies; 30+ messages in thread
From: Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2022-05-17 14:31 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: spwhitton, 54804, juri, uyennhi.qm, Tino Calancha
> If you only make the search case-sensitive in the 'interactive' form,
> that happens automagically.
I don't understand what you mean by that: the search doesn't take place
inside the interactive form, so he can't really control the
case-sensitivity from the interactive form, except (as he does) by using
the interactive form to pass extra info (in the form of the
`interactive` arg) to tell the search code that the call was made
interactively and should hence use the "fancier" form of
case sensitivity.
Stefan
^ permalink raw reply [flat|nested] 30+ messages in thread
* bug#54804: 29.0.50; zap-to-char: case sensitive for upper-case letter
2022-05-17 12:34 ` Tino Calancha
2022-05-17 12:41 ` Eli Zaretskii
@ 2022-05-17 19:32 ` Juri Linkov
1 sibling, 0 replies; 30+ messages in thread
From: Juri Linkov @ 2022-05-17 19:32 UTC (permalink / raw)
To: Tino Calancha; +Cc: uyennhi.qm, Eli Zaretskii, 54804, monnier, spwhitton
> This is what Emacs does for isearch/search.
>
> If you go to the *scratch* buffer, and you do
> C-s T C-s C-s
> you only jump on 'T', that is, you skip the 't'. This is regardless
> on the `case-fold-search' value.
Isearch has an additional option 'search-upper-case', although
I'm not sure if such complexity is worthy to add to zap-to.
Maybe only for interactive use.
^ permalink raw reply [flat|nested] 30+ messages in thread
* bug#54804: 29.0.50; zap-to-char: case sensitive for upper-case letter
2022-05-13 6:48 ` Eli Zaretskii
2022-05-17 12:34 ` Tino Calancha
@ 2022-05-18 7:25 ` Tino Calancha
1 sibling, 0 replies; 30+ messages in thread
From: Tino Calancha @ 2022-05-18 7:25 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: uyennhi.qm, 54804, schwab, rpluim, spwhitton
Eli Zaretskii <eliz@gnu.org> writes:
>> diff --git a/test/lisp/simple-tests.el b/test/lisp/simple-tests.el
>> index dcab811bb5..2baf7124d7 100644
>> --- a/test/lisp/simple-tests.el
>> +++ b/test/lisp/simple-tests.el
>> @@ -971,5 +971,27 @@ test-undo-region
>> ;;(should (= (length (delq nil (undo-make-selective-list 5 9))) 0))
>> (should (= (length (delq nil (undo-make-selective-list 6 9))) 0))))
>>
>> +\f
>> +;;; Tests for `zap-to-char'
>
> Should we have the tests for zap-* functions in one place, rather than
> two?
My understanding is that we only test in `foo-tests.el' functions
beloging to `foo.el'.
For historical reasons:
`zap-to-char' is defined in simple.el
`zap-up-to-char' is defined in misc.el
We can move the latter to simple.el, then test the functions in the same file.
Some people dislike that because it affects the Git history.
I am OK with whatever the people prefer here.
^ permalink raw reply [flat|nested] 30+ messages in thread
* bug#54804: 29.0.50; zap-to-char: case sensitive for upper-case letter
2022-05-12 15:55 ` Tino Calancha
2022-05-13 6:48 ` Eli Zaretskii
@ 2022-05-20 22:59 ` Sean Whitton
2022-05-21 5:38 ` Eli Zaretskii
1 sibling, 1 reply; 30+ messages in thread
From: Sean Whitton @ 2022-05-20 22:59 UTC (permalink / raw)
To: Tino Calancha, Andreas Schwab
Cc: 54804, Eli Zaretskii, Robert Pluim, uyennhi.qm
Hello Tino,
On Thu 12 May 2022 at 05:55pm +02, Tino Calancha wrote:
> commit 86750ab021ea889766a717458ed28a54e6a40ad3
> Author: Tino Calancha <tino.calancha@gmail.com>
> Date: Thu May 12 17:48:09 2022 +0200
>
> zap-to-char: case sensitive for upper-case characters
>
> In interactive calls, behave case-sensitively if the given char
> is an upper-case character. Same for zap-up-to-char.
>
> This is analog to what the user-level incremental search feature does.
Could we have a defcustom to always be case-sensitive, please?
I like the way C-s works by default but for zap-* I'd prefer case
sensitivity in every case.
Thanks.
--
Sean Whitton
^ permalink raw reply [flat|nested] 30+ messages in thread
* bug#54804: 29.0.50; zap-to-char: case sensitive for upper-case letter
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
0 siblings, 2 replies; 30+ messages in thread
From: Eli Zaretskii @ 2022-05-21 5:38 UTC (permalink / raw)
To: Sean Whitton; +Cc: uyennhi.qm, 54804, rpluim, tino.calancha
> From: Sean Whitton <spwhitton@spwhitton.name>
> Cc: 54804@debbugs.gnu.org, Robert Pluim <rpluim@gmail.com>, Eli Zaretskii
> <eliz@gnu.org>, uyennhi.qm@gmail.com
> Date: Fri, 20 May 2022 15:59:45 -0700
>
> > commit 86750ab021ea889766a717458ed28a54e6a40ad3
> > Author: Tino Calancha <tino.calancha@gmail.com>
> > Date: Thu May 12 17:48:09 2022 +0200
> >
> > zap-to-char: case sensitive for upper-case characters
> >
> > In interactive calls, behave case-sensitively if the given char
> > is an upper-case character. Same for zap-up-to-char.
> >
> > This is analog to what the user-level incremental search feature does.
>
> Could we have a defcustom to always be case-sensitive, please?
We already have: case-fold-search.
> I like the way C-s works by default but for zap-* I'd prefer case
> sensitivity in every case.
Why?
It is a slippery slope to have a separate case-sensitivity option for
each command or a couple of commands. If that is what you want, you
can always write your own one-line wrapper around each of these
commands, but I don't see any reason that Emacs should provide that
for everyone.
So I don't think we should provide such a defcustom for these two
commands.
^ permalink raw reply [flat|nested] 30+ messages in thread
* bug#54804: 29.0.50; zap-to-char: case sensitive for upper-case letter
2022-05-21 5:38 ` Eli Zaretskii
@ 2022-05-21 9:30 ` Tino Calancha
2022-05-21 18:53 ` Sean Whitton
1 sibling, 0 replies; 30+ messages in thread
From: Tino Calancha @ 2022-05-21 9:30 UTC (permalink / raw)
To: 54804-done; +Cc: uyennhi.qm
Eli Zaretskii <eliz@gnu.org> writes:
>> From: Sean Whitton <spwhitton@spwhitton.name>
>> Could we have a defcustom to always be case-sensitive, please?
>
> We already have: case-fold-search.
> So I don't think we should provide such a defcustom for these two
> commands.
I agree with Eli's point.
Pushed into master branch as commit:
zap-to-char: case sensitive for upper-case characters
(212aea97f9c9fdabdf7e8a47e64c8243953a7690)
^ permalink raw reply [flat|nested] 30+ messages in thread
* bug#54804: 29.0.50; zap-to-char: case sensitive for upper-case letter
2022-05-21 5:38 ` Eli Zaretskii
2022-05-21 9:30 ` Tino Calancha
@ 2022-05-21 18:53 ` Sean Whitton
1 sibling, 0 replies; 30+ messages in thread
From: Sean Whitton @ 2022-05-21 18:53 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: uyennhi.qm, 54804, rpluim, tino.calancha
Hello,
On Sat 21 May 2022 at 08:38am +03, Eli Zaretskii wrote:
>> Could we have a defcustom to always be case-sensitive, please?
>
> We already have: case-fold-search.
>
>> I like the way C-s works by default but for zap-* I'd prefer case
>> sensitivity in every case.
>
> Why?
Hard to say -- C-s never surprises me but when 'M-z a' jumps to an A it
does :)
> It is a slippery slope to have a separate case-sensitivity option for
> each command or a couple of commands. If that is what you want, you
> can always write your own one-line wrapper around each of these
> commands, but I don't see any reason that Emacs should provide that
> for everyone.
>
> So I don't think we should provide such a defcustom for these two
> commands.
I agree, adding a wrapper of my own is better.
Thanks for the commit, Tino, and to the reviewers.
--
Sean Whitton
^ permalink raw reply [flat|nested] 30+ messages in thread
end of thread, other threads:[~2022-05-21 18:53 UTC | newest]
Thread overview: 30+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.