From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.bugs Subject: bug#29321: Isearch hit count Date: Thu, 15 Nov 2018 00:36:37 +0200 Organization: LINKOV.NET Message-ID: <87va4zmglm.fsf@mail.linkov.net> References: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1542235096 12053 195.159.176.226 (14 Nov 2018 22:38:16 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 14 Nov 2018 22:38:16 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (x86_64-pc-linux-gnu) Cc: 29321@debbugs.gnu.org To: charles@aurox.ch (Charles A. Roelli) Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Nov 14 23:38:11 2018 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gN3nW-000318-6E for geb-bug-gnu-emacs@m.gmane.org; Wed, 14 Nov 2018 23:38:10 +0100 Original-Received: from localhost ([::1]:34461 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gN3pc-0005jW-P6 for geb-bug-gnu-emacs@m.gmane.org; Wed, 14 Nov 2018 17:40:20 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:59972) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gN3pN-0005hU-Nk for bug-gnu-emacs@gnu.org; Wed, 14 Nov 2018 17:40:06 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gN3pK-0006rQ-Ij for bug-gnu-emacs@gnu.org; Wed, 14 Nov 2018 17:40:05 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:48445) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gN3pK-0006rI-Cv for bug-gnu-emacs@gnu.org; Wed, 14 Nov 2018 17:40:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1gN3pK-0007C1-5o for bug-gnu-emacs@gnu.org; Wed, 14 Nov 2018 17:40:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 14 Nov 2018 22:40:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 29321 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 29321-submit@debbugs.gnu.org id=B29321.154223517627613 (code B ref 29321); Wed, 14 Nov 2018 22:40:02 +0000 Original-Received: (at 29321) by debbugs.gnu.org; 14 Nov 2018 22:39:36 +0000 Original-Received: from localhost ([127.0.0.1]:52702 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gN3ot-0007BJ-T5 for submit@debbugs.gnu.org; Wed, 14 Nov 2018 17:39:36 -0500 Original-Received: from insect.birch.relay.mailchannels.net ([23.83.209.93]:43147) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gN3or-0007B9-4T for 29321@debbugs.gnu.org; Wed, 14 Nov 2018 17:39:34 -0500 X-Sender-Id: dreamhost|x-authsender|jurta@jurta.org Original-Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id AD9031245F5; Wed, 14 Nov 2018 22:39:31 +0000 (UTC) Original-Received: from pdx1-sub0-mail-a77.g.dreamhost.com (unknown [100.96.36.160]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 6B70F1245C4; Wed, 14 Nov 2018 22:39:31 +0000 (UTC) X-Sender-Id: dreamhost|x-authsender|jurta@jurta.org Original-Received: from pdx1-sub0-mail-a77.g.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384) by 0.0.0.0:2500 (trex/5.16.2); Wed, 14 Nov 2018 22:39:31 +0000 X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|jurta@jurta.org X-MailChannels-Auth-Id: dreamhost X-Lettuce-Grain: 22855d1b68b2273e_1542235171532_3964087060 X-MC-Loop-Signature: 1542235171531:2071076287 X-MC-Ingress-Time: 1542235171531 Original-Received: from pdx1-sub0-mail-a77.g.dreamhost.com (localhost [127.0.0.1]) by pdx1-sub0-mail-a77.g.dreamhost.com (Postfix) with ESMTP id 20700815E5; Wed, 14 Nov 2018 14:39:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=linkov.net; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type; s=linkov.net; bh=MfQrTxpxqNdnxheYXuhrKLv5rDw=; b= WPf2xKDckJqBxvHySw1ObSHAzlpQw3mppsBNoNuDsdEhqop1xMz2TZL75w32p3iR agPC2k+aGFCKNU1JnPtEYg/6eWrL1yLihJsGbcDScBb2Lm0L8StyQ0+YUuel/EMt u25bG42B/+SNhNpZdYE9TIHiSt9cfLwHrLWluKQXG6w= Original-Received: from mail.jurta.org (m91-129-107-244.cust.tele2.ee [91.129.107.244]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: jurta@jurta.org) by pdx1-sub0-mail-a77.g.dreamhost.com (Postfix) with ESMTPSA id A594A815E4; Wed, 14 Nov 2018 14:39:18 -0800 (PST) X-DH-BACKEND: pdx1-sub0-mail-a77 In-Reply-To: (Charles A. Roelli's message of "Thu, 16 Nov 2017 20:27:32 +0100") X-VR-OUT-STATUS: OK X-VR-OUT-SCORE: -100 X-VR-OUT-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedtkedrleeggddtvdcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucggtfgfnhhsuhgsshgtrhhisggvpdfftffgtefojffquffvnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvffuohhfffgjkfgfgggtsehmtderredtredtnecuhfhrohhmpefluhhrihcunfhinhhkohhvuceojhhurhhisehlihhnkhhovhdrnhgvtheqnecuffhomhgrihhnpehgnhhurdhorhhgnecukfhppeeluddruddvledruddtjedrvdeggeenucfrrghrrghmpehmohguvgepshhmthhppdhhvghlohepmhgrihhlrdhjuhhrthgrrdhorhhgpdhinhgvthepledurdduvdelrddutdejrddvgeegpdhrvghtuhhrnhdqphgrthhhpefluhhrihcunfhinhhkohhvuceojhhurhhisehlihhnkhhovhdrnhgvtheqpdhmrghilhhfrhhomhepjhhurhhisehlihhnkhhovhdrnhgvthdpnhhrtghpthhtoheptghhrghrlhgvshesrghurhhogidrtghhnecuvehluhhsthgvrhfuihiivgeptd X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 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.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:152399 Archived-At: --=-=-= Content-Type: text/plain > Isearch could show in the mode line how many matches follow or precede > the currently highlighted one (or we could write "3 of 4 matches", as, > e.g., Firefox does). For big files, it could be helpful to calculate > this information either lazily or in another thread. Lazy-counting is now pushed to master. > If we had this, it would also be convenient to say "go forward n > matches", so that typing "M-3 C-s" during a search would be the > equivalent of typing C-s three times. To do this we could add numeric > prefix arg handling to C-s/C-r/C-M-s/C-M-r, if that isn't already > taken for some other behavior. Adding a numeric prefix arg to C-s/C-r is implemented in https://debbugs.gnu.org/29321#86 But this implementation causes flicker because it updates isearch highlighting on every search hit while traversing all found matches COUNT times until it reaches COUNT-th match. Attached is a better approach that adds the COUNT arg to isearch functions down to the lowest-level isearch function, thus making it compatible with the COUNT arg of re-search-forward: --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=isearch-repeat-count.2.patch diff --git a/lisp/isearch.el b/lisp/isearch.el index 035ff69327..3e6e696a74 100644 --- a/lisp/isearch.el +++ b/lisp/isearch.el @@ -1547,7 +1547,7 @@ isearch-abort (isearch-pop-state)) (isearch-update))) -(defun isearch-repeat (direction) +(defun isearch-repeat (direction &optional count) ;; Utility for isearch-repeat-forward and -backward. (if (eq isearch-forward (eq direction 'forward)) ;; C-s in forward or C-r in reverse. @@ -1590,21 +1590,29 @@ isearch-repeat (setq isearch-success nil) (ding)) (forward-char (if isearch-forward 1 -1)) - (isearch-search)) - (isearch-search))) + (isearch-search count)) + (isearch-search count))) (isearch-push-state) (isearch-update)) -(defun isearch-repeat-forward () - "Repeat incremental search forwards." - (interactive) - (isearch-repeat 'forward)) - -(defun isearch-repeat-backward () - "Repeat incremental search backwards." - (interactive) - (isearch-repeat 'backward)) +(defun isearch-repeat-forward (&optional arg) + "Repeat incremental search forwards. +With a prefix argument, repeat a search ARG times." + (interactive "P") + (let ((count (and arg (abs (prefix-numeric-value arg))))) + ;; Take into account one search iteration to reverse direction. + (when (and count (not isearch-forward)) (setq count (1+ count))) + (isearch-repeat 'forward count))) + +(defun isearch-repeat-backward (&optional arg) + "Repeat incremental search backwards. +With a prefix argument, repeat a search ARG times." + (interactive "P") + (let ((count (and arg (abs (prefix-numeric-value arg))))) + ;; Take into account one search iteration to reverse direction. + (when (and count isearch-forward) (setq count (1+ count))) + (isearch-repeat 'backward count))) ;;; Toggles for `isearch-regexp-function' and `search-default-mode'. @@ -2910,7 +2918,7 @@ isearch-search-fun-default (t (regexp-quote string))) bound noerror count)))) -(defun isearch-search-string (string bound noerror) +(defun isearch-search-string (string bound noerror &optional count) "Search for the first occurrence of STRING or its translation. STRING's characters are translated using `translation-table-for-input' if that is non-nil. @@ -2921,7 +2929,10 @@ isearch-search-string Optional third argument, if t, means if fail just return nil (no error). If not nil and not t, move to limit of search and return nil." (let* ((func (isearch-search-fun)) - (pos1 (save-excursion (funcall func string bound noerror))) + (pos1 (save-excursion (if count + (funcall func string bound noerror count) + ;; Backward-compatibility for functions that don't support count arg + (funcall func string bound noerror)))) pos2) (when (and ;; Avoid "obsolete" warnings for translation-table-for-input. @@ -2960,7 +2971,7 @@ isearch-search-string (goto-char pos1) pos1))) -(defun isearch-search () +(defun isearch-search (&optional count) ;; Do the search with the current search string. (if (and (eq isearch-case-fold-search t) search-upper-case) (setq isearch-case-fold-search @@ -2974,7 +2985,7 @@ isearch-search (setq isearch-error nil) (while retry (setq isearch-success - (isearch-search-string isearch-string nil t)) + (isearch-search-string isearch-string nil t count)) ;; Clear RETRY unless the search predicate says ;; to skip this search hit. (if (or (not isearch-success) --=-=-=--