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#29360: 26.0; Add full-buffer choice for `isearch-lazy-highlight' Date: Sun, 21 Oct 2018 22:06:48 +0300 Organization: LINKOV.NET Message-ID: <87woqbglvb.fsf@mail.linkov.net> References: <7ec3c778-ee77-48c9-ba10-f21202cac955@default> <87shd8lli4.fsf@mail.linkov.net> <36f5e57c-2eb3-45eb-ae43-3f8fdf7586dd@default> <60f1b355-7455-4bb9-ae3d-294e1494a9d9@default> <87va5yhpaq.fsf@mail.linkov.net> <875zxwjlke.fsf@mail.linkov.net> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1540150545 28708 195.159.176.226 (21 Oct 2018 19:35:45 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 21 Oct 2018 19:35:45 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (x86_64-pc-linux-gnu) Cc: 29360@debbugs.gnu.org To: Drew Adams Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Oct 21 21:35:41 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 1gEJVk-0007N7-CI for geb-bug-gnu-emacs@m.gmane.org; Sun, 21 Oct 2018 21:35:40 +0200 Original-Received: from localhost ([::1]:60017 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gEJXq-0007lX-Vh for geb-bug-gnu-emacs@m.gmane.org; Sun, 21 Oct 2018 15:37:50 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:60524) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gEJRA-0001nA-23 for bug-gnu-emacs@gnu.org; Sun, 21 Oct 2018 15:31:00 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gEJGc-0004o0-TC for bug-gnu-emacs@gnu.org; Sun, 21 Oct 2018 15:20:07 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:58563) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gEJGc-0004nn-OF for bug-gnu-emacs@gnu.org; Sun, 21 Oct 2018 15:20:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1gEJGc-0004IL-J4 for bug-gnu-emacs@gnu.org; Sun, 21 Oct 2018 15:20:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 21 Oct 2018 19:20:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 29360 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 29360-submit@debbugs.gnu.org id=B29360.154014955216445 (code B ref 29360); Sun, 21 Oct 2018 19:20:02 +0000 Original-Received: (at 29360) by debbugs.gnu.org; 21 Oct 2018 19:19:12 +0000 Original-Received: from localhost ([127.0.0.1]:34588 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gEJFo-0004HA-2g for submit@debbugs.gnu.org; Sun, 21 Oct 2018 15:19:12 -0400 Original-Received: from pop.dreamhost.com ([64.90.62.162]:57612 helo=pdx1-sub0-mail-a61.g.dreamhost.com) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gEJFl-0004H2-O6 for 29360@debbugs.gnu.org; Sun, 21 Oct 2018 15:19:10 -0400 Original-Received: from pdx1-sub0-mail-a61.g.dreamhost.com (localhost [127.0.0.1]) by pdx1-sub0-mail-a61.g.dreamhost.com (Postfix) with ESMTP id 4AE9D80005; Sun, 21 Oct 2018 12:19:09 -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=g8PyZoSAWbTeLV5IF42hTvUb8nA=; b= CvBovXE9y8iNRgqx1GnRLQECyahPl9HSJy4wQJw5U49R5JyYWXym/vUsV+2jMsEf PtssEU1x6qig0X3ehBievMDDPbQMEiDRWWKY2cltcAEojPGJ0eZGDLZKdzm0DUFi Svn1HjrPMWSaHy6tzP2FyzZShxpKZDdkXvFABpmYXPU= Original-Received: from mail.jurta.org (m91-129-96-249.cust.tele2.ee [91.129.96.249]) (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-a61.g.dreamhost.com (Postfix) with ESMTPSA id DAF1D7FFF8; Sun, 21 Oct 2018 12:19:07 -0700 (PDT) X-DH-BACKEND: pdx1-sub0-mail-a61 In-Reply-To: (Drew Adams's message of "Sat, 20 Oct 2018 16:09:29 -0700 (PDT)") X-VR-OUT-STATUS: OK X-VR-OUT-SCORE: -100 X-VR-OUT-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedtkedrgedtgddufeejucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuggftfghnshhusghstghrihgsvgdpffftgfetoffjqffuvfenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvufhofhffjgfkfgggtgesmhdtreertdertdenucfhrhhomheplfhurhhiucfnihhnkhhovhcuoehjuhhriheslhhinhhkohhvrdhnvghtqeenucfkphepledurdduvdelrdeliedrvdegleenucfrrghrrghmpehmohguvgepshhmthhppdhhvghlohepmhgrihhlrdhjuhhrthgrrdhorhhgpdhinhgvthepledurdduvdelrdeliedrvdegledprhgvthhurhhnqdhprghthheplfhurhhiucfnihhnkhhovhcuoehjuhhriheslhhinhhkohhvrdhnvghtqedpmhgrihhlfhhrohhmpehjuhhriheslhhinhhkohhvrdhnvghtpdhnrhgtphhtthhopegurhgvfidrrggurghmshesohhrrggtlhgvrdgtohhmnecuvehluhhsthgvrhfuihiivgeptd 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:151490 Archived-At: --=-=-= Content-Type: text/plain > In any case, yes, your suggestion of first doing what we do now > (highlight the immediate area, using the current algorith), and > then following that with highlighting the rest of the buffer, > could be a good idea. Dunno how much that might change > the existing code. In the patch attached below, a new function isearch-lazy-highlight-buffer-update is a copy of isearch-lazy-highlight-update with some changes specific to highlighting the full buffer. It seems making a duplicate function is necessary because adding more full-buffer specific conditions to the existing function isearch-lazy-highlight-update will make it unmaintainable. Only a part of the function (that highlights the match) is extracted into a new function isearch-lazy-highlight-match and shared among these aforementioned two functions. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=isearch-lazy-highlight-buffer.1.patch diff --git a/lisp/isearch.el b/lisp/isearch.el index 1e785a44c5..cb9e72526b 100644 --- a/lisp/isearch.el +++ b/lisp/isearch.el @@ -304,7 +304,7 @@ isearch-fail (defcustom isearch-lazy-highlight t "Controls the lazy-highlighting during incremental search. -When non-nil, all text in the buffer matching the current search +When non-nil, all text on the screen matching the current search string is highlighted lazily (see `lazy-highlight-initial-delay' and `lazy-highlight-interval'). @@ -316,6 +316,15 @@ isearch-lazy-highlight :group 'lazy-highlight :group 'isearch) +(defcustom isearch-lazy-highlight-buffer nil + "Controls the lazy-highlighting of the whole buffer. +When non-nil, all text in the buffer matching the current search +string is highlighted lazily (see `lazy-highlight-initial-delay', +`lazy-highlight-interval' and `lazy-highlight-buffer-max-at-a-time')." + :type 'boolean + :group 'lazy-highlight + :group 'isearch) + ;;; Lazy highlight customization. (defgroup lazy-highlight nil @@ -351,6 +360,15 @@ lazy-highlight-max-at-a-time (integer :tag "Some")) :group 'lazy-highlight) +(defcustom lazy-highlight-buffer-max-at-a-time 20 + "Maximum matches to highlight at a time (for `isearch-lazy-highlight-buffer'). +Larger values may reduce Isearch's responsiveness to user input; +smaller values make matches highlight slowly. +A value of nil means highlight all matches shown in the buffer." + :type '(choice (const :tag "All" nil) + (integer :tag "Some")) + :group 'lazy-highlight) + (defface lazy-highlight '((((class color) (min-colors 88) (background light)) (:background "paleturquoise")) @@ -3290,13 +3308,13 @@ isearch-lazy-highlight-search (+ isearch-lazy-highlight-start ;; Extend bound to match whole string at point (1- (length isearch-lazy-highlight-last-string))) - (window-group-end))) + (if isearch-lazy-highlight-buffer (point-max) (window-group-end)))) (max (or isearch-lazy-highlight-start-limit (point-min)) (if isearch-lazy-highlight-wrapped (- isearch-lazy-highlight-end ;; Extend bound to match whole string at point (1- (length isearch-lazy-highlight-last-string))) - (window-group-start)))))) + (if isearch-lazy-highlight-buffer (point-min) (window-group-start))))))) ;; Use a loop like in `isearch-search'. (while retry (setq success (isearch-search-string @@ -3317,6 +3335,20 @@ isearch-lazy-highlight-start (lazy-highlight-cleanup t) ;remove old overlays (isearch-lazy-highlight-update)) +(defvar isearch-lazy-highlight-match-function #'isearch-lazy-highlight-match + "Function that highlights the found match. +The function accepts two arguments: the beginning and the end of the match.") + +(defun isearch-lazy-highlight-match (mb me) + (let ((ov (make-overlay mb me))) + (push ov isearch-lazy-highlight-overlays) + ;; 1000 is higher than ediff's 100+, + ;; but lower than isearch main overlay's 1001 + (overlay-put ov 'priority 1000) + (overlay-put ov 'face 'lazy-highlight) + (unless (eq isearch-lazy-highlight 'all-windows) + (overlay-put ov 'window (selected-window))))) + (defun isearch-lazy-highlight-update () "Update highlighting of other matches for current search." (let ((max lazy-highlight-max-at-a-time) @@ -3353,16 +3385,8 @@ isearch-lazy-highlight-update (window-group-start))) (setq found nil) (forward-char -1))) - ;; non-zero-length match - (let ((ov (make-overlay mb me))) - (push ov isearch-lazy-highlight-overlays) - ;; 1000 is higher than ediff's 100+, - ;; but lower than isearch main overlay's 1001 - (overlay-put ov 'priority 1000) - (overlay-put ov 'face 'lazy-highlight) - (unless (eq isearch-lazy-highlight 'all-windows) - (overlay-put ov 'window (selected-window))))) + (funcall isearch-lazy-highlight-match-function mb me)) ;; Remember the current position of point for ;; the next call of `isearch-lazy-highlight-update' ;; when `lazy-highlight-max-at-a-time' is too small. @@ -3384,11 +3408,75 @@ isearch-lazy-highlight-update (setq isearch-lazy-highlight-start (window-group-end)) (goto-char (min (or isearch-lazy-highlight-end-limit (point-max)) (window-group-end)))))))) - (unless nomore + (if nomore + (when isearch-lazy-highlight-buffer + (setq isearch-lazy-highlight-start (window-group-start)) + (setq isearch-lazy-highlight-end (window-group-end)) + (setq isearch-lazy-highlight-wrapped nil) + (run-at-time lazy-highlight-interval nil + 'isearch-lazy-highlight-buffer-update)) (setq isearch-lazy-highlight-timer (run-at-time lazy-highlight-interval nil 'isearch-lazy-highlight-update))))))))) +(defun isearch-lazy-highlight-buffer-update () + "Update highlighting of other matches in the whole buffer." + (let ((max lazy-highlight-buffer-max-at-a-time) + (looping t) + nomore) + (with-local-quit + (save-excursion + (save-match-data + (goto-char (if isearch-lazy-highlight-forward + isearch-lazy-highlight-end + isearch-lazy-highlight-start)) + (while looping + (let ((found (isearch-lazy-highlight-search))) + (when max + (setq max (1- max)) + (if (<= max 0) + (setq looping nil))) + (if found + (let ((mb (match-beginning 0)) + (me (match-end 0))) + (if (= mb me) ;zero-length match + (if isearch-lazy-highlight-forward + (if (= mb (if isearch-lazy-highlight-wrapped + (window-group-start) + (point-max))) + (setq found nil) + (forward-char 1)) + (if (= mb (if isearch-lazy-highlight-wrapped + (window-group-end) + (point-min))) + (setq found nil) + (forward-char -1))) + ;; non-zero-length match + (funcall isearch-lazy-highlight-match-function mb me)) + ;; Remember the current position of point for + ;; the next call of `isearch-lazy-highlight-update' + ;; when `lazy-highlight-max-at-a-time' is too small. + (if isearch-lazy-highlight-forward + (setq isearch-lazy-highlight-end (point)) + (setq isearch-lazy-highlight-start (point))))) + ;; not found or zero-length match at the search bound + (if (not found) + (if isearch-lazy-highlight-wrapped + (setq looping nil + nomore t) + (setq isearch-lazy-highlight-wrapped t) + (if isearch-lazy-highlight-forward + (progn + (setq isearch-lazy-highlight-end (point-min)) + (goto-char (point-min))) + (setq isearch-lazy-highlight-start (point-max)) + (goto-char (point-max))))))) + (if nomore + (message "Finished lazy-highlighting the buffer") + (setq isearch-lazy-highlight-timer + (run-at-time lazy-highlight-interval nil + 'isearch-lazy-highlight-buffer-update)))))))) + (defun isearch-resume (string regexp word forward message case-fold) "Resume an incremental search. STRING is the string or regexp searched for. --=-=-=--