From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Tino Calancha Newsgroups: gmane.emacs.bugs Subject: bug#54804: 29.0.50; zap-to-char: case sensitive for upper-case letter Date: Thu, 12 May 2022 17:55:38 +0200 Message-ID: <878rr6oidh.fsf@gmail.com> References: <87ee27fd1a.fsf@gmail.com> <83bkxaaj45.fsf@gnu.org> <878rs55m81.fsf@gmail.com> <834k2t1cva.fsf@gnu.org> <87ilqdnl8z.fsf@gmail.com> <83bkw4s4ln.fsf@gnu.org> <87fslgnn9h.fsf@gmail.com> <87lev85d36.fsf@gmail.com> <877d6sum2c.fsf@igel.home> <4548a66-c8f8-57de-58db-6241a1f16cc4@gmail.com> <8735hguk0u.fsf@igel.home> <218f952c-747d-c32-5bce-5ad078a51f41@gmail.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="16680"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) Cc: 54804@debbugs.gnu.org, spwhitton@spwhitton.name, Eli Zaretskii , Robert Pluim , uyennhi.qm@gmail.com To: Andreas Schwab Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu May 12 17:56:38 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1npBB8-0004Dz-0X for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 12 May 2022 17:56:38 +0200 Original-Received: from localhost ([::1]:43476 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1npBB6-0001hE-IS for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 12 May 2022 11:56:36 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:44652) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1npBAY-0000ZH-9M for bug-gnu-emacs@gnu.org; Thu, 12 May 2022 11:56:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:48098) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1npBAX-0007Fk-W3 for bug-gnu-emacs@gnu.org; Thu, 12 May 2022 11:56:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1npBAX-00071O-Qg for bug-gnu-emacs@gnu.org; Thu, 12 May 2022 11:56:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Tino Calancha Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 12 May 2022 15:56:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 54804 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 54804-submit@debbugs.gnu.org id=B54804.165237095026971 (code B ref 54804); Thu, 12 May 2022 15:56:01 +0000 Original-Received: (at 54804) by debbugs.gnu.org; 12 May 2022 15:55:50 +0000 Original-Received: from localhost ([127.0.0.1]:41995 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1npBAL-00070w-8V for submit@debbugs.gnu.org; Thu, 12 May 2022 11:55:49 -0400 Original-Received: from mail-ed1-f53.google.com ([209.85.208.53]:37451) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1npBAJ-00070h-6k for 54804@debbugs.gnu.org; Thu, 12 May 2022 11:55:47 -0400 Original-Received: by mail-ed1-f53.google.com with SMTP id k27so6793310edk.4 for <54804@debbugs.gnu.org>; Thu, 12 May 2022 08:55:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=GowL6mWu54tSm02jHWJuQ7SC6Fe5LmJpWtTBqHQLST4=; b=XgSgc5+IA+XswmOpNRVOkcSB8MHEFoUFUH1/OTvQ258lDWUV6CMEC2JnCoVAzRCE5o LlxUoSknU90xLWfpg+5Kn9+gWxs/uRoJsqNEh+ZNlXeFRrcYeyx8t8ElApXD6t93cpzt SIjm2S8maKK7pE6fT3tcKwGupyd2Njlq1X0O1gv437uZTlJlyrBZcyEiZHrw3XmlHPcl 2dDp+VlkYac/q3KgP2/zPMVc9Kg0T/Gj9W8QGZiihMTez0RsHaj61kk3VlBovGJySzDG j6KyY8IEhiFMGh8Yo6Hcsi+iy+WrzkqIyBWMmGuAyA18lTbeyv3XPI44OxbW9BvzEsgz ulQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=GowL6mWu54tSm02jHWJuQ7SC6Fe5LmJpWtTBqHQLST4=; b=ovxs/SjN4h1NKJY8DsB/kFIZy2vKFA0Htn8/OQqkXPVm7xo8AlDvP3sbNeu1Ij/NU2 L8/j6JuEaWzneIFZuDvt/iRwU7BSrNgPHxA6YbADk7jy/WnQuR9AXL8k4PKuFk5jm1xn jGe70vuQ0/7RVDz7wmOJ3GcZ6fCZ+IbOjMIKc0E2zyRmFy1hD00U0tCQaDfNaFxj3Fd+ exa/L/VwPoK4aNH8pq/MFk1Jgo4ydigYz66WpGNYZ9+aLU9omM6rD26yAXGPcHjwsSzk rvCGDvmdyHtvERt6Wzy6N7QJCpToOmn2AjTVHDamzLy251W/47HrA9IHllVgxgN8G0vH lVCg== X-Gm-Message-State: AOAM5322HgI4RUEB+Xehv465X17/EIxq7Ej++1L7QjfG7YepNBkQsdf1 58B9XGQr+T3tnPcflgD5nwM= X-Google-Smtp-Source: ABdhPJzjEp8Hrr8BuT0z0ldGny+e7KMZqCBTNYAosqhvaAtSja6sQqplGh9Qizl3mEYdU+/3mKo0Sg== X-Received: by 2002:a05:6402:11cd:b0:427:bda5:542f with SMTP id j13-20020a05640211cd00b00427bda5542fmr36264288edw.290.1652370941058; Thu, 12 May 2022 08:55:41 -0700 (PDT) Original-Received: from eprince ([193.118.249.171]) by smtp.gmail.com with ESMTPSA id l1-20020a50c101000000b0042617ba63c2sm2656533edf.76.2022.05.12.08.55.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 May 2022 08:55:40 -0700 (PDT) In-Reply-To: <218f952c-747d-c32-5bce-5ad078a51f41@gmail.com> (Tino Calancha's message of "Wed, 11 May 2022 18:18:55 +0200 (CEST)") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:232057 Archived-At: Tino Calancha 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 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)))) + +;;; 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---