From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Juri Linkov <juri@linkov.net> Newsgroups: gmane.emacs.bugs Subject: bug#29321: Isearch hit count Date: Sat, 27 Oct 2018 23:55:56 +0300 Organization: LINKOV.NET Message-ID: <87o9bfqfc3.fsf@mail.linkov.net> References: <m2ineavxaz.fsf@aurox.ch> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1540673773 11238 195.159.176.226 (27 Oct 2018 20:56:13 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 27 Oct 2018 20:56:13 +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 Sat Oct 27 22:56:08 2018 Return-path: <bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org> 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 <bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org>) id 1gGVcs-0002lo-AE for geb-bug-gnu-emacs@m.gmane.org; Sat, 27 Oct 2018 22:56:06 +0200 Original-Received: from localhost ([::1]:37786 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from <bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org>) id 1gGVey-00048B-4M for geb-bug-gnu-emacs@m.gmane.org; Sat, 27 Oct 2018 16:58:16 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:60327) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1gGVeq-000485-Lk for bug-gnu-emacs@gnu.org; Sat, 27 Oct 2018 16:58:09 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1gGVek-0007uT-92 for bug-gnu-emacs@gnu.org; Sat, 27 Oct 2018 16:58:08 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:41574) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1gGVej-0007uG-Vs for bug-gnu-emacs@gnu.org; Sat, 27 Oct 2018 16:58:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from <Debian-debbugs@debbugs.gnu.org>) id 1gGVej-00033b-SG for bug-gnu-emacs@gnu.org; Sat, 27 Oct 2018 16:58:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov <juri@linkov.net> Original-Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org> Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 27 Oct 2018 20:58:01 +0000 Resent-Message-ID: <handler.29321.B29321.154067384511709@debbugs.gnu.org> 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.154067384511709 (code B ref 29321); Sat, 27 Oct 2018 20:58:01 +0000 Original-Received: (at 29321) by debbugs.gnu.org; 27 Oct 2018 20:57:25 +0000 Original-Received: from localhost ([127.0.0.1]:45832 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces@debbugs.gnu.org>) id 1gGVe8-00032n-Ow for submit@debbugs.gnu.org; Sat, 27 Oct 2018 16:57:25 -0400 Original-Received: from common.maple.relay.mailchannels.net ([23.83.214.38]:38492) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <juri@linkov.net>) id 1gGVe6-00032e-Q5 for 29321@debbugs.gnu.org; Sat, 27 Oct 2018 16:57:23 -0400 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 F001168268D; Sat, 27 Oct 2018 20:57:20 +0000 (UTC) Original-Received: from pdx1-sub0-mail-a3.g.dreamhost.com (unknown [100.96.16.121]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id BBC8E681C7A; Sat, 27 Oct 2018 20:57:20 +0000 (UTC) X-Sender-Id: dreamhost|x-authsender|jurta@jurta.org Original-Received: from pdx1-sub0-mail-a3.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); Sat, 27 Oct 2018 20:57:20 +0000 X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|jurta@jurta.org X-MailChannels-Auth-Id: dreamhost X-Macabre-Keen: 595c8e7a666cd2bd_1540673840857_2620652219 X-MC-Loop-Signature: 1540673840857:1539443427 X-MC-Ingress-Time: 1540673840857 Original-Received: from pdx1-sub0-mail-a3.g.dreamhost.com (localhost [127.0.0.1]) by pdx1-sub0-mail-a3.g.dreamhost.com (Postfix) with ESMTP id 4B2867F69D; Sat, 27 Oct 2018 13:57:20 -0700 (PDT) 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=zKl2f9oSA6ZtPCocoMMZ0v5qpZI=; b= ZW8ohN+zITO8uruVaeOtsJu/hT2gquAAcoAf7n4N6zdNuDzo2VBco7mQuDax84T+ dq8MeUCL8P9xn/nqTe+18LXWxvAMZGr/e7rCgy+ot+Rwk9mK1V55m9i3sUuI6z/t Wl0u1MFZ+2XXDTVClQDR4AdN/ssexU/xhaMWdrNgU4Q= Original-Received: from mail.jurta.org (m91-129-105-154.cust.tele2.ee [91.129.105.154]) (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-a3.g.dreamhost.com (Postfix) with ESMTPSA id AA2947F69C; Sat, 27 Oct 2018 13:57:18 -0700 (PDT) X-DH-BACKEND: pdx1-sub0-mail-a3 In-Reply-To: <m2ineavxaz.fsf@aurox.ch> (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: gggruggvucftvghtrhhoucdtuddrgedtkedrheeggdduheelucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuggftfghnshhusghstghrihgsvgdpffftgfetoffjqffuvfenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvufhofhffjgfkfgggtgesmhdtreertdertdenucfhrhhomheplfhurhhiucfnihhnkhhovhcuoehjuhhriheslhhinhhkohhvrdhnvghtqeenucfkphepledurdduvdelrddutdehrdduheegnecurfgrrhgrmhepmhhouggvpehsmhhtphdphhgvlhhopehmrghilhdrjhhurhhtrgdrohhrghdpihhnvghtpeeluddruddvledruddthedrudehgedprhgvthhurhhnqdhprghthheplfhurhhiucfnihhnkhhovhcuoehjuhhriheslhhinhhkohhvrdhnvghtqedpmhgrihhlfhhrohhmpehjuhhriheslhhinhhkohhvrdhnvghtpdhnrhgtphhtthhopegthhgrrhhlvghssegruhhrohigrdgthhenucevlhhushhtvghrufhiiigvpedt 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" <bug-gnu-emacs.gnu.org> List-Unsubscribe: <https://lists.gnu.org/mailman/options/bug-gnu-emacs>, <mailto:bug-gnu-emacs-request@gnu.org?subject=unsubscribe> List-Archive: <http://lists.gnu.org/archive/html/bug-gnu-emacs/> List-Post: <mailto:bug-gnu-emacs@gnu.org> List-Help: <mailto:bug-gnu-emacs-request@gnu.org?subject=help> List-Subscribe: <https://lists.gnu.org/mailman/listinfo/bug-gnu-emacs>, <mailto:bug-gnu-emacs-request@gnu.org?subject=subscribe> Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" <bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org> Xref: news.gmane.org gmane.emacs.bugs:151709 Archived-At: <http://permalink.gmane.org/gmane.emacs.bugs/151709> --=-=-= 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. Thanks to Drew, now we have the full-buffer lazy-highlighting loop that can be reused for Isearch hit count. Here is a minimal patch that implements this feature: --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=isearch-lazy-count.1.diff diff --git a/lisp/isearch.el b/lisp/isearch.el index 580b3ac40a..8c264ab3ed 100644 --- a/lisp/isearch.el +++ b/lisp/isearch.el @@ -316,6 +316,13 @@ isearch-lazy-highlight :group 'lazy-highlight :group 'isearch) +(defcustom isearch-lazy-count nil + "Counts matches in the full buffer. +When non-nil, all matches in the full buffer are counted." + :type 'boolean + :group 'isearch + :version "27.1") + ;;; Lazy highlight customization. (defgroup lazy-highlight nil @@ -2794,7 +2801,15 @@ isearch-message-prefix (concat " [" current-input-method-title "]: ")) ": ") ))) - (propertize (concat (upcase (substring m 0 1)) (substring m 1)) + (propertize (concat (if (and isearch-lazy-count isearch-lazy-count-current) + (format "%d/%d " (if isearch-forward + isearch-lazy-count-current + (- isearch-lazy-count-total + isearch-lazy-count-current + -1)) + (or isearch-lazy-count-total "?")) + "") + (upcase (substring m 0 1)) (substring m 1)) 'face 'minibuffer-prompt))) (defun isearch-message-suffix (&optional c-q-hack) @@ -3212,6 +3227,10 @@ 'isearch-lazy-highlight-word (defvar isearch-lazy-highlight-regexp-function nil) (defvar isearch-lazy-highlight-forward nil) (defvar isearch-lazy-highlight-error nil) +(defvar isearch-lazy-count-current nil) +(defvar isearch-lazy-count-total nil) +(defvar isearch-lazy-count-start nil) +(defvar isearch-lazy-count-hash (make-hash-table)) (defun lazy-highlight-cleanup (&optional force procrastinate) "Stop lazy highlighting and remove extra highlighting from current buffer. @@ -3235,8 +3254,7 @@ isearch-lazy-highlight-new-loop This is called when `isearch-update' is invoked (which can cause the search string to change or the window to scroll). It is also used by other Emacs features." - (when (and (null executing-kbd-macro) - (sit-for 0) ;make sure (window-start) is credible + (setq isearch-lazy-count-start (or (not (equal isearch-string isearch-lazy-highlight-last-string)) (not (memq (selected-window) @@ -3251,17 +3269,20 @@ isearch-lazy-highlight-new-loop isearch-lax-whitespace)) (not (eq isearch-lazy-highlight-regexp-lax-whitespace isearch-regexp-lax-whitespace)) - (not (or lazy-highlight-buffer - (= (window-group-start) - isearch-lazy-highlight-window-start))) - (not (or lazy-highlight-buffer - (= (window-group-end) ; Window may have been split/joined. - isearch-lazy-highlight-window-end))) (not (eq isearch-forward isearch-lazy-highlight-forward)) ;; In case we are recovering from an error. (not (equal isearch-error isearch-lazy-highlight-error)))) + (when (and (null executing-kbd-macro) + (sit-for 0) ;make sure (window-start) is credible + (or isearch-lazy-count-start + (not (or lazy-highlight-buffer + (= (window-group-start) + isearch-lazy-highlight-window-start))) + (not (or lazy-highlight-buffer + (= (window-group-end) ; Window may have been split/joined. + isearch-lazy-highlight-window-end))))) ;; something important did indeed change (lazy-highlight-cleanup t (not (equal isearch-string ""))) ;stop old timer (setq isearch-lazy-highlight-error isearch-error) @@ -3303,9 +3324,18 @@ isearch-lazy-highlight-new-loop (1- (length isearch-lazy-highlight-last-string))) (point-min)))) (unless (equal isearch-string "") + (when (and isearch-lazy-count isearch-mode) + (when isearch-lazy-count-start + (clrhash isearch-lazy-count-hash) + (setq isearch-lazy-count-current nil + isearch-lazy-count-total nil))) (setq isearch-lazy-highlight-timer (run-with-idle-timer lazy-highlight-initial-delay nil - 'isearch-lazy-highlight-start))))) + 'isearch-lazy-highlight-start)))) + (when (and isearch-lazy-count isearch-mode) + (setq isearch-lazy-count-current + (gethash isearch-other-end isearch-lazy-count-hash)) + (funcall (or isearch-message-function #'isearch-message) nil t))) (defun isearch-lazy-highlight-search (string bound) "Search ahead for the next or previous match, for lazy highlighting. @@ -3426,7 +3456,8 @@ isearch-lazy-highlight-update (goto-char (min (or isearch-lazy-highlight-end-limit (point-max)) window-end))))))) (if nomore - (when isearch-lazy-highlight-buffer + (when (or isearch-lazy-highlight-buffer + isearch-lazy-count-start) (if isearch-lazy-highlight-forward (setq isearch-lazy-highlight-end (point-min)) (setq isearch-lazy-highlight-start (point-max))) @@ -3475,8 +3506,13 @@ isearch-lazy-highlight-buffer-update (if (= mb (point-min)) (setq found nil) (forward-char -1))) + (setq isearch-lazy-count-total (1+ (or isearch-lazy-count-total 0))) + (puthash (if isearch-lazy-highlight-forward mb me) + isearch-lazy-count-total + isearch-lazy-count-hash) ;; Already highlighted by isearch-lazy-highlight-update - (unless (and (>= mb window-start) (<= me window-end)) + (unless (or (and (>= mb window-start) (<= me window-end)) + (not isearch-lazy-highlight-buffer)) ;; non-zero-length match (isearch-lazy-highlight-match mb me))) ;; Remember the current position of point for @@ -3491,6 +3527,10 @@ isearch-lazy-highlight-buffer-update (setq looping nil nomore t)))) (unless nomore + (when (and isearch-lazy-count isearch-mode) + (setq isearch-lazy-count-current + (gethash isearch-other-end isearch-lazy-count-hash)) + (funcall (or isearch-message-function #'isearch-message) nil t)) (setq isearch-lazy-highlight-timer (run-at-time lazy-highlight-interval nil 'isearch-lazy-highlight-buffer-update))))))))) --=-=-=--