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: Sat, 10 Nov 2018 22:45:35 +0200 Organization: LINKOV.NET Message-ID: <87d0rcu5gc.fsf@mail.linkov.net> References: <87o9bfqfc3.fsf@mail.linkov.net> <988284b2-58af-428d-9c6f-da56db0c6565@default> <874ld5elxb.fsf@mail.linkov.net> <3e52e081-ad81-41a6-a0d6-295790db82d4@default> <877ei049f6.fsf@mail.linkov.net> <2231d642-cb4a-4114-9896-be995e4c6460@default> <87r2g7kp8u.fsf@mail.linkov.net> <8629624d-6118-4b6b-b626-77801112326a@default> <76796f6d-4d0d-47d6-bea7-0944cf53cb18@default> <877ehx7qj9.fsf@mail.linkov.net> <2dca8e1b-2949-4b07-8467-27f873dd0f3d@default> <87a7msl9oz.fsf@mail.linkov.net> <75dd449d-2239-4e22-85da-a079f10e759e@default> <877ehse9fb.fsf@mail.linkov.net> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1541887037 4701 195.159.176.226 (10 Nov 2018 21:57:17 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 10 Nov 2018 21:57:17 +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 Nov 10 22:57:13 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 1gLbFg-00016p-7F for geb-bug-gnu-emacs@m.gmane.org; Sat, 10 Nov 2018 22:57:12 +0100 Original-Received: from localhost ([::1]:40096 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gLbHm-0006LO-M0 for geb-bug-gnu-emacs@m.gmane.org; Sat, 10 Nov 2018 16:59:22 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:38503) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gLbHY-0006Ku-0i for bug-gnu-emacs@gnu.org; Sat, 10 Nov 2018 16:59:12 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gLbHS-00054d-VO for bug-gnu-emacs@gnu.org; Sat, 10 Nov 2018 16:59:07 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:40840) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gLbHS-00052R-NF for bug-gnu-emacs@gnu.org; Sat, 10 Nov 2018 16:59:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1gLbHS-0004qL-KR for bug-gnu-emacs@gnu.org; Sat, 10 Nov 2018 16:59: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: Sat, 10 Nov 2018 21:59: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.154188714118608 (code B ref 29321); Sat, 10 Nov 2018 21:59:02 +0000 Original-Received: (at 29321) by debbugs.gnu.org; 10 Nov 2018 21:59:01 +0000 Original-Received: from localhost ([127.0.0.1]:45097 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gLbHR-0004pz-6Z for submit@debbugs.gnu.org; Sat, 10 Nov 2018 16:59:01 -0500 Original-Received: from palegreen.birch.relay.mailchannels.net ([23.83.209.140]:36353) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gLbHP-0004pj-Kz for 29321@debbugs.gnu.org; Sat, 10 Nov 2018 16:59:00 -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 6384A681F25; Sat, 10 Nov 2018 21:58:57 +0000 (UTC) Original-Received: from pdx1-sub0-mail-a77.g.dreamhost.com (unknown [100.96.29.126]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 328BB68229C; Sat, 10 Nov 2018 21:58:57 +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); Sat, 10 Nov 2018 21:58:57 +0000 X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|jurta@jurta.org X-MailChannels-Auth-Id: dreamhost X-Absorbed-Madly: 26750f34317e9a4a_1541887137313_969306650 X-MC-Loop-Signature: 1541887137313:1358029222 X-MC-Ingress-Time: 1541887137313 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 E92BB8091E; Sat, 10 Nov 2018 13:58:56 -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=xBhpafL+Z+u0s9wEzzmuhfUune8=; b= QW7fFMRQvbHODlxIJtrDr0FQiJDqIOsAiDWbcHrpii2dsxupDqFahYcK9D8IbCM4 5dtojjCffXouVMoZZIYeOk3eeWM6vrYIXSZ6+o/RhjW3xBE+JRSLJFDNQ57Lafz9 fdTONwhrYDtvBIg7m4Wy3MB5lYRgMnBZ2TO2tCJ68Pc= 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 C51AE7F44E; Sat, 10 Nov 2018 13:58:54 -0800 (PST) X-DH-BACKEND: pdx1-sub0-mail-a77 In-Reply-To: (Charles A. Roelli's message of "Sat, 10 Nov 2018 15:27:10 +0100") X-VR-OUT-STATUS: OK X-VR-OUT-SCORE: -100 X-VR-OUT-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedtkedrkeehgdduheeiucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuggftfghnshhusghstghrihgsvgdpffftgfetoffjqffuvfenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvufhofhffjgfkfgggtgesmhdtreertdertdenucfhrhhomheplfhurhhiucfnihhnkhhovhcuoehjuhhriheslhhinhhkohhvrdhnvghtqeenucfkphepledurdduvdelrddutdejrddvgeegnecurfgrrhgrmhepmhhouggvpehsmhhtphdphhgvlhhopehmrghilhdrjhhurhhtrgdrohhrghdpihhnvghtpeeluddruddvledruddtjedrvdeggedprhgvthhurhhnqdhprghthheplfhurhhiucfnihhnkhhovhcuoehjuhhriheslhhinhhkohhvrdhnvghtqedpmhgrihhlfhhrohhmpehjuhhriheslhhinhhkohhvrdhnvghtpdhnrhgtphhtthhopegthhgrrhhlvghssegruhhrohigrdgthhenucevlhhushhtvghrufhiiigvpedt 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:152275 Archived-At: --=-=-= Content-Type: text/plain > Could we prevent the "0/0" count from showing when searching for an > incomplete regexp? For example, typing characters after C-M-s [ > results in the isearch prompt shifting when the "0/0" count is > displayed lazily after each keypress. > > Also, the count is shown in the prompt even for "M-e". For example, > C-s buf M-e shows "1/2 I-search:" as the (static) prompt, which is not > necessary (and it may be outdated as soon as the user changes the text > in the minibuffer). I agree on both accounts, and fixed this in a new patch that also includes two new customizable variables lazy-count-prefix-format and lazy-count-suffix-format: --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=isearch.count.7.patch diff --git a/lisp/isearch.el b/lisp/isearch.el index 42b3aa42ba..5f75e90387 100644 --- a/lisp/isearch.el +++ b/lisp/isearch.el @@ -316,6 +316,29 @@ isearch-lazy-highlight :group 'lazy-highlight :group 'isearch) +(defcustom isearch-lazy-count nil + "Show match number in the Isearch prompt. +When both this option and `isearch-lazy-highlight' are non-nil, +show the current match number and the total number of matches +in the buffer (or its restriction)." + :type 'boolean + :group 'isearch + :version "27.1") + +(defcustom lazy-count-prefix-format "%s/%s " + "Format of the current/total number of matches for message prefix." + :type '(choice (const :tag "No prefix" nil) + (string :tag "Prefix format string" "%s/%s ")) + :group 'isearch + :version "27.1") + +(defcustom lazy-count-suffix-format nil + "Format of the current/total number of matches for message suffix." + :type '(choice (const :tag "No suffix" nil) + (string :tag "Suffix format string" " [%s of %s]")) + :group 'isearch + :version "27.1") + ;;; Lazy highlight customization. (defgroup lazy-highlight nil @@ -2794,7 +2821,8 @@ isearch-message-prefix (concat " [" current-input-method-title "]: ")) ": ") ))) - (propertize (concat (upcase (substring m 0 1)) (substring m 1)) + (propertize (concat (isearch-lazy-count-format) + (upcase (substring m 0 1)) (substring m 1)) 'face 'minibuffer-prompt))) (defun isearch-message-suffix (&optional c-q-hack) @@ -2802,9 +2830,33 @@ isearch-message-suffix (if isearch-error (concat " [" isearch-error "]") "") + (isearch-lazy-count-format 'suffix) (or isearch-message-suffix-add "")) 'face 'minibuffer-prompt)) +(defun isearch-lazy-count-format (&optional suffix-p) + "Format the current match number and the total number of matches. +When SUFFIX-P is non-nil, the returned string is indended for +isearch-message-suffix. Otherwise, for isearch-message-prefix." + (let ((format-string (if suffix-p + lazy-count-suffix-format + lazy-count-prefix-format))) + (if (and format-string + isearch-lazy-count + isearch-lazy-count-current + (not isearch-error) + (not isearch-suspended)) + (format format-string + (if isearch-forward + isearch-lazy-count-current + (if (eq isearch-lazy-count-current 0) + 0 + (- isearch-lazy-count-total + isearch-lazy-count-current + -1))) + (or isearch-lazy-count-total "?")) + ""))) + ;; Searching @@ -3202,6 +3254,8 @@ isearch-lazy-highlight-window (defvar isearch-lazy-highlight-window-group nil) (defvar isearch-lazy-highlight-window-start nil) (defvar isearch-lazy-highlight-window-end nil) +(defvar isearch-lazy-highlight-window-start-changed nil) +(defvar isearch-lazy-highlight-window-end-changed nil) (defvar isearch-lazy-highlight-point-min nil) (defvar isearch-lazy-highlight-point-max nil) (defvar isearch-lazy-highlight-buffer nil) @@ -3214,6 +3268,9 @@ '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-hash (make-hash-table)) (defun lazy-highlight-cleanup (&optional force procrastinate) "Stop lazy highlighting and remove extra highlighting from current buffer. @@ -3258,18 +3315,36 @@ isearch-lazy-highlight-new-loop ;; In case we are recovering from an error. (not (equal isearch-error isearch-lazy-highlight-error)) - (not (if lazy-highlight-buffer - (= (point-min) - isearch-lazy-highlight-point-min) - (= (window-group-start) - isearch-lazy-highlight-window-start))) - (not (if lazy-highlight-buffer - (= (point-max) - isearch-lazy-highlight-point-max) - (= (window-group-end) ; Window may have been split/joined. - isearch-lazy-highlight-window-end))))) + (if lazy-highlight-buffer + (not (= (point-min) + isearch-lazy-highlight-point-min)) + (setq isearch-lazy-highlight-window-start-changed + (not (= (window-group-start) + isearch-lazy-highlight-window-start)))) + (if lazy-highlight-buffer + (not (= (point-max) + isearch-lazy-highlight-point-max)) + (setq isearch-lazy-highlight-window-end-changed + (not (= (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 + (when (and isearch-lazy-count isearch-mode) + (when (or (equal isearch-string "") + (and (not isearch-lazy-highlight-window-start-changed) + (not isearch-lazy-highlight-window-end-changed)) + (not (= (point-min) + isearch-lazy-highlight-point-min)) + (not (= (point-max) + isearch-lazy-highlight-point-max))) + ;; Reset old counter before going to count new numbers + (clrhash isearch-lazy-count-hash) + (setq isearch-lazy-count-current nil + isearch-lazy-count-total nil) + (when (null isearch-message-function) + (isearch-message nil t)))) + (setq isearch-lazy-highlight-window-start-changed nil) + (setq isearch-lazy-highlight-window-end-changed nil) (setq isearch-lazy-highlight-error isearch-error) ;; It used to check for `(not isearch-error)' here, but actually ;; lazy-highlighting might find matches to highlight even when @@ -3313,7 +3388,14 @@ isearch-lazy-highlight-new-loop (unless (equal isearch-string "") (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 (null isearch-message-function)) + ;; Update isearch-lazy-count-current only when it was already set + ;; at the end of isearch-lazy-highlight-buffer-update + (when isearch-lazy-count-current + (setq isearch-lazy-count-current + (or (gethash (point) isearch-lazy-count-hash) 0)) + (isearch-message nil t)))) (defun isearch-lazy-highlight-search (string bound) "Search ahead for the next or previous match, for lazy highlighting. @@ -3434,7 +3516,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 + (and isearch-lazy-count (null isearch-lazy-count-current))) (if isearch-lazy-highlight-forward (setq isearch-lazy-highlight-end (point-min)) (setq isearch-lazy-highlight-start (point-max))) @@ -3448,7 +3531,8 @@ isearch-lazy-highlight-buffer-update "Update highlighting of other matches in the full buffer." (let ((max lazy-highlight-buffer-max-at-a-time) (looping t) - nomore window-start window-end) + nomore window-start window-end + (opoint (point))) (with-local-quit (save-selected-window (if (and (window-live-p isearch-lazy-highlight-window) @@ -3483,8 +3567,14 @@ isearch-lazy-highlight-buffer-update (if (= mb (point-min)) (setq found nil) (forward-char -1))) + (when isearch-lazy-count + (setq isearch-lazy-count-total (1+ (or isearch-lazy-count-total 0))) + (puthash (if isearch-lazy-highlight-forward me mb) + 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 (not isearch-lazy-highlight-buffer) + (and (>= mb window-start) (<= me window-end))) ;; non-zero-length match (isearch-lazy-highlight-match mb me))) ;; Remember the current position of point for @@ -3498,7 +3588,13 @@ isearch-lazy-highlight-buffer-update (if (not found) (setq looping nil nomore t)))) - (unless nomore + (if nomore + (when (and isearch-lazy-count isearch-mode (null isearch-message-function)) + (unless isearch-lazy-count-total + (setq isearch-lazy-count-total 0)) + (setq isearch-lazy-count-current + (or (gethash opoint isearch-lazy-count-hash) 0)) + (isearch-message nil t)) (setq isearch-lazy-highlight-timer (run-at-time lazy-highlight-interval nil 'isearch-lazy-highlight-buffer-update))))))))) --=-=-=--