From: Tino Calancha <tino.calancha@gmail.com>
To: 54804@debbugs.gnu.org
Cc: uyennhi.qm@gmail.com
Subject: bug#54804: 29.0.50; zap-to-char: case sensitive for upper-case letter
Date: Sat, 09 Apr 2022 00:03:45 +0200 [thread overview]
Message-ID: <87ee27fd1a.fsf@gmail.com> (raw)
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)
next reply other threads:[~2022-04-08 22:03 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-08 22:03 Tino Calancha [this message]
2022-04-09 6:03 ` bug#54804: 29.0.50; zap-to-char: case sensitive for upper-case letter 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
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=87ee27fd1a.fsf@gmail.com \
--to=tino.calancha@gmail.com \
--cc=54804@debbugs.gnu.org \
--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).