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, 16 Apr 2022 12:58:06 +0200 Message-ID: <878rs55m81.fsf@gmail.com> References: <87ee27fd1a.fsf@gmail.com> <83bkxaaj45.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="3583"; 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, uyennhi.qm@gmail.com To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Apr 16 12:59: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 1nfg8z-0000kN-EI for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 16 Apr 2022 12:59:09 +0200 Original-Received: from localhost ([::1]:46958 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nfg8y-0000mz-6P for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 16 Apr 2022 06:59:08 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:44232) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nfg8r-0000mp-Qf for bug-gnu-emacs@gnu.org; Sat, 16 Apr 2022 06:59:01 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:38653) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nfg8r-0002PE-Ic for bug-gnu-emacs@gnu.org; Sat, 16 Apr 2022 06:59:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nfg8r-0008Ag-I6 for bug-gnu-emacs@gnu.org; Sat, 16 Apr 2022 06:59: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: Sat, 16 Apr 2022 10:59: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.165010669731340 (code B ref 54804); Sat, 16 Apr 2022 10:59:01 +0000 Original-Received: (at 54804) by debbugs.gnu.org; 16 Apr 2022 10:58:17 +0000 Original-Received: from localhost ([127.0.0.1]:60777 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nfg88-00089Q-Pu for submit@debbugs.gnu.org; Sat, 16 Apr 2022 06:58:17 -0400 Original-Received: from mail-ed1-f45.google.com ([209.85.208.45]:37601) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nfg87-00089B-5k for 54804@debbugs.gnu.org; Sat, 16 Apr 2022 06:58:15 -0400 Original-Received: by mail-ed1-f45.google.com with SMTP id b15so12510557edn.4 for <54804@debbugs.gnu.org>; Sat, 16 Apr 2022 03:58:15 -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=fiT9z8EZrymA62AW+ynuqZ8MbsCfhtu9z8eUxeswenY=; b=XKvAuhj1mUQjhrmL007pkQGaAi342etXZ5tcUrykDFbY/8YpA7oQXPppDeAkYLOz0v G9YH6b+yEhtURvk65kwQ6d52u5qbCFaqpbQ88torzyAWyZfnVJXsfT0sG01bkcg38Hwt M0NAkj4SqUjy38lPxkrvejh3Lir7VZaTdeXhOsM5AXqrkQQQX4vvjtf3MYtWJEduN6ZC N1xC42S23UjxBo3eE8lhIvSF/xB3HsEnO9rudgJ6Pl7c5dy6uERK4VssTvyjpM7lIn+v 3h9OXo7+jg5dy4y6hub4Ar6XTngayd2FHxQAitBt21drLoIC+xp2hkbsjYq1+dtSwYA8 G/YQ== 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=fiT9z8EZrymA62AW+ynuqZ8MbsCfhtu9z8eUxeswenY=; b=alkZb610Zkf0TxXMzH91Buvz26UxDOwkDJhwYztKCcJ8cQA1TgCR872Kmu7jE2JMqu BIbXC/REK92RXkIOL5IqkiwBMb/qumQzvvnZNuy7Ivgt2yk75+T8L6CGfcnNydEfPb6K 8mtFNipFtHk8YfmWSwAZa+fh1dmTk6NHt/4FbKWCvFBisTuvswQWIEWW/vimaw/8t7NZ 7SdrncIJDpnoeh2cjOJd+Iq3ffbbJZ+eINpllpeEvOYgKJj48o7hdWhsq5tP7Y2LNKB9 zuoacmUodPru2Fn0J2P0biJLIvqIyZeBtcTH33xgNXmnpDtCE+97KU5PGFzVIvcHlene hZHQ== X-Gm-Message-State: AOAM5311uv9+lHuPQpI/XkRK+LKjeFgYAYpKXBEj04B9b0A3ygyB1cUs VamrpUcbbwY6nLSMKrPnH7s= X-Google-Smtp-Source: ABdhPJwUptTsLQqWb0py2GMmwWie5i5E4DuVa8JM+wQPhnJ5tLRq8HuhQGiydCD77LLB8BHYCrzceg== X-Received: by 2002:aa7:df92:0:b0:41d:84fd:5d92 with SMTP id b18-20020aa7df92000000b0041d84fd5d92mr3210936edy.337.1650106689127; Sat, 16 Apr 2022 03:58:09 -0700 (PDT) Original-Received: from eprince ([193.118.249.171]) by smtp.gmail.com with ESMTPSA id e22-20020a170906505600b006da7d71f25csm2568890ejk.41.2022.04.16.03.58.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Apr 2022 03:58:08 -0700 (PDT) In-Reply-To: <83bkxaaj45.fsf@gnu.org> (Eli Zaretskii's message of "Sat, 09 Apr 2022 09:03:38 +0300") 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:229972 Archived-At: Eli Zaretskii 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---