all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Tino Calancha <tino.calancha@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 54804@debbugs.gnu.org, uyennhi.qm@gmail.com
Subject: bug#54804: 29.0.50; zap-to-char: case sensitive for upper-case letter
Date: Sat, 16 Apr 2022 12:58:06 +0200	[thread overview]
Message-ID: <878rs55m81.fsf@gmail.com> (raw)
In-Reply-To: <83bkxaaj45.fsf@gnu.org> (Eli Zaretskii's message of "Sat, 09 Apr 2022 09:03:38 +0300")

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





  reply	other threads:[~2022-04-16 10:58 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 [this message]
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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=878rs55m81.fsf@gmail.com \
    --to=tino.calancha@gmail.com \
    --cc=54804@debbugs.gnu.org \
    --cc=eliz@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 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.