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: Sat, 09 Apr 2022 00:03:45 +0200 Message-ID: <87ee27fd1a.fsf@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="32637"; mail-complaints-to="usenet@ciao.gmane.io" Cc: uyennhi.qm@gmail.com To: 54804@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Apr 09 00:05:11 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 1ncwj8-0008G2-Op for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 09 Apr 2022 00:05:10 +0200 Original-Received: from localhost ([::1]:47886 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ncwj7-0008VG-O8 for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 08 Apr 2022 18:05:09 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:55916) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ncwj0-0008Ut-DW for bug-gnu-emacs@gnu.org; Fri, 08 Apr 2022 18:05:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:42355) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ncwj0-00029Z-4M for bug-gnu-emacs@gnu.org; Fri, 08 Apr 2022 18:05:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ncwiz-00035i-Vl; Fri, 08 Apr 2022 18:05:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Tino Calancha Original-Sender: "Debbugs-submit" Resent-CC: uyennhi.qm@gmail.com, bug-gnu-emacs@gnu.org Resent-Date: Fri, 08 Apr 2022 22:05:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 54804 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org X-Debbugs-Original-Xcc: uyennhi.qm@gmail.com Original-Received: via spool by submit@debbugs.gnu.org id=B.164945545911825 (code B ref -1); Fri, 08 Apr 2022 22:05:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 8 Apr 2022 22:04:19 +0000 Original-Received: from localhost ([127.0.0.1]:36252 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ncwiI-00034e-Dn for submit@debbugs.gnu.org; Fri, 08 Apr 2022 18:04:18 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:35368) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ncwiG-00034W-Qs for submit@debbugs.gnu.org; Fri, 08 Apr 2022 18:04:17 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:55812) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ncwiG-0008JI-N0 for bug-gnu-emacs@gnu.org; Fri, 08 Apr 2022 18:04:16 -0400 Original-Received: from mail-wm1-x330.google.com ([2a00:1450:4864:20::330]:34567) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ncwiE-00025e-2d for bug-gnu-emacs@gnu.org; Fri, 08 Apr 2022 18:04:15 -0400 Original-Received: by mail-wm1-x330.google.com with SMTP id j5-20020a05600c1c0500b0038ea8b53580so1387415wms.1 for ; Fri, 08 Apr 2022 15:04:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:mime-version; bh=OsYQQSZbo+a4mc8SezBAOTbsIWdzqSXUtEdYyFzkz7s=; b=TIzOrijl5zPGIpsotwu8QLif4AIq9u1Qn87cbDM8noabEpvLfGAZV3CA6EUAywCLFx OSu5ecUSqkMZ7DYVu/JbsdkrR0jXOKfCfF4M65NcQmR4JG2HRyMeGxrtEJVxH3IwIU1x yAWFfQlMTMVvFKuBPeBCPKmXnFg4Qe99RwjiuUeHgWWakkpGAWpOtSyRwOt11xGlvzyP so4EQaWgYpWgRJ7q9rx1rUVvqFswp6qY9GOesnSZKh00bCRQwF1hE+sdBZz/HJGAVikB Gk1FuW7UDrxa2jJOWOVs4Ltf/7OS8N3wKtmKr0UJC0QbTTK1XbtVzPDNhyfHqmww83cT dsJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:mime-version; bh=OsYQQSZbo+a4mc8SezBAOTbsIWdzqSXUtEdYyFzkz7s=; b=Walyn9yhatqU8l4xMAIinRJmsvlVBfEu7eQkQjRW7ruWZo3kGU4m8zjaFOtOj4HJUI R/TcZ+0db7F3ofMI9xwjw448EHk7aGfBX3TeOnmJknT/T6yNJiu0Gk2aBUfEGeEjuQX6 zG9Y/IQVvNjEGjkzagnSPo5gPm0+w7AiqmwLPZYvfr1zLRB6PIPFrOI9FbqKaLqEabsC YnU1B7wVTP30cUFAvK6QEZ8wIZjLRD6p6XREfhzWLsVabK8yAd3dHRKoOkDsvEUpluAu ruwqfiWHmpQuDa4JdrPzPit1pin9TyI17aku79jGqmEa3kDzB/XjlXL1lpaWqEIKfFG/ kP2A== X-Gm-Message-State: AOAM530hH/KrVHi7CZNjqILA4I4+6oqTQ4b5rCRm4tyBRLnLZv5XrMIc FwSCLBXHN9rLuUYXxlcbOl5VWDsxYQk= X-Google-Smtp-Source: ABdhPJxyFzzosC70XxU+oCcUjzv5tTwu+pH1vKXZQ7xby8RAqqeUKV3B1rPo5JU6P6zRIjGrrnWYUA== X-Received: by 2002:a7b:c013:0:b0:38e:9edd:a44c with SMTP id c19-20020a7bc013000000b0038e9edda44cmr5242393wmb.122.1649455450609; Fri, 08 Apr 2022 15:04:10 -0700 (PDT) Original-Received: from eprince ([193.118.249.171]) by smtp.gmail.com with ESMTPSA id f13-20020a05600c4e8d00b0038c949ef0d5sm13620745wmq.8.2022.04.08.15.04.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Apr 2022 15:04:09 -0700 (PDT) Received-SPF: pass client-ip=2a00:1450:4864:20::330; envelope-from=tino.calancha@gmail.com; helo=mail-wm1-x330.google.com X-Spam_score_int: 12 X-Spam_score: 1.2 X-Spam_bar: + X-Spam_report: (1.2 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action 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:229593 Archived-At: 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 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)