unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Tino Calancha <tino.calancha@gmail.com>
To: Andreas Schwab <schwab@linux-m68k.org>
Cc: 54804@debbugs.gnu.org, spwhitton@spwhitton.name,
	Eli Zaretskii <eliz@gnu.org>, Robert Pluim <rpluim@gmail.com>,
	uyennhi.qm@gmail.com
Subject: bug#54804: 29.0.50; zap-to-char: case sensitive for upper-case letter
Date: Thu, 12 May 2022 17:55:38 +0200	[thread overview]
Message-ID: <878rr6oidh.fsf@gmail.com> (raw)
In-Reply-To: <218f952c-747d-c32-5bce-5ad078a51f41@gmail.com> (Tino Calancha's message of "Wed, 11 May 2022 18:18:55 +0200 (CEST)")

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---





  reply	other threads:[~2022-05-12 15:55 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
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 [this message]
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=878rr6oidh.fsf@gmail.com \
    --to=tino.calancha@gmail.com \
    --cc=54804@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    --cc=rpluim@gmail.com \
    --cc=schwab@linux-m68k.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).