From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Artur Malabarba Newsgroups: gmane.emacs.devel Subject: Re: bug#17453: Isearch doesn't work properly with Follow Mode. Date: Sun, 1 Nov 2015 20:42:26 +0000 Message-ID: References: <20140509224458.GA4205@acm.acm> <20151029232302.GB3812@acm.fritz.box> <20151031233225.GD1853@acm.fritz.box> <20151101135253.GB2768@acm.fritz.box> <83k2q1y893.fsf@gnu.org> <20151101182733.GE2768@acm.fritz.box> Reply-To: bruce.connor.am@gmail.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: ger.gmane.org 1446410564 18452 80.91.229.3 (1 Nov 2015 20:42:44 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 1 Nov 2015 20:42:44 +0000 (UTC) Cc: Eli Zaretskii , emacs-devel To: Alan Mackenzie Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Nov 01 21:42:36 2015 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1ZszSW-0005cq-0Y for ged-emacs-devel@m.gmane.org; Sun, 01 Nov 2015 21:42:36 +0100 Original-Received: from localhost ([::1]:38815 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZszSV-0006S1-9R for ged-emacs-devel@m.gmane.org; Sun, 01 Nov 2015 15:42:35 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:39649) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZszSQ-0006OD-D2 for emacs-devel@gnu.org; Sun, 01 Nov 2015 15:42:31 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZszSP-0005wR-EV for emacs-devel@gnu.org; Sun, 01 Nov 2015 15:42:30 -0500 Original-Received: from mail-lb0-x22b.google.com ([2a00:1450:4010:c04::22b]:32860) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZszSN-0005v5-O8; Sun, 01 Nov 2015 15:42:27 -0500 Original-Received: by lbbec13 with SMTP id ec13so76994315lbb.0; Sun, 01 Nov 2015 12:42:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:reply-to:sender:in-reply-to:references:date:message-id :subject:from:to:cc:content-type; bh=9fESCtZtriXi4g3oTaHLcNSbY+94zI/QE7rQiQCDcRU=; b=W2/NS3D0yLiet28nkd2zIsT97s0RhmV5mgoIE+4hFAxJ9gVqBPPime9C/Hb/kP3rqz VNpgWCVoTXrhDxquXSkhIUIIwPDl6TVuTEj0+LLyFq2ew0P4uJZzDdLYuWeRAzIY4bXQ U5Gj77TDGYwiAXWouhSAyUfN1VihyeBg36HyFwCKIk27Llf5kkrbx4ttAP1j6MkMxRGP xobubT+FBMD6Ir0oUsWLbveU22Z8QAPeRsgNL5n0LPrD4US98Itf2YwShtUXZNuhz2ZM AF+yyX10KwWZ4QMxdXF/wAMlU8MoVJKxly7w11Bfp+NbBULqFydRlFsx7ALfNbWHZLvp mdig== X-Received: by 10.112.62.232 with SMTP id b8mr8249849lbs.27.1446410547018; Sun, 01 Nov 2015 12:42:27 -0800 (PST) Original-Received: by 10.112.63.71 with HTTP; Sun, 1 Nov 2015 12:42:26 -0800 (PST) In-Reply-To: X-Google-Sender-Auth: xm6HSxm1yDk8nk3yh4SY2KPlltI X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:4010:c04::22b X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:193082 Archived-At: 2015-11-01 19:46 GMT+00:00 Artur Malabarba : > The idiomatic Emacs way to do this is to add hooks to isearch, and run > them at useful places. Then packages like follow-mode can add stuff to > these hooks and do what they want (like, enable/disable itself). After playing around a bit, here's a quick solution that works for me. The patch adds 4 lines to isearch.el, and defines a function in follow-mode. I only tried it supperficially, so you might find issues with this solution that I couldn't --- lisp/follow.el | 14 ++++++++++++++ lisp/isearch.el | 4 ++++ 2 files changed, 18 insertions(+) diff --git a/lisp/follow.el b/lisp/follow.el index 938c59e..e9a60e5 100644 --- a/lisp/follow.el +++ b/lisp/follow.el @@ -203,6 +203,8 @@ (require 'easymenu) (eval-when-compile (require 'cl-lib)) +(require 'seq) +(require 'subr-x) ;;; Variables @@ -419,11 +421,13 @@ follow-mode :keymap follow-mode-map (if follow-mode (progn + (setq-local isearch-search-fun-function #'follow--search-function) (add-hook 'compilation-filter-hook 'follow-align-compilation-windows t t) (add-hook 'post-command-hook 'follow-post-command-hook t) (add-hook 'window-size-change-functions 'follow-window-size-change t)) ;; Remove globally-installed hook functions only if there is no ;; other Follow mode buffer. + (setq-local isearch-search-fun-function #'isearch-search-fun-default) (let ((buffers (buffer-list)) following) (while (and (not following) buffers) @@ -434,6 +438,16 @@ follow-mode (remove-hook 'window-size-change-functions 'follow-window-size-change))) (remove-hook 'compilation-filter-hook 'follow-align-compilation-windows t))) +(defvar isearch-lazy-highlight-ongoing-search) +(defun follow--search-function () + (lambda (&rest args) + (prog1 (apply (isearch-search-fun-default) args) + (unless (or isearch-lazy-highlight-ongoing-search + (pos-visible-in-window-p)) + (when-let ((win (seq-find (lambda (w) (pos-visible-in-window-p (point) w)) + (get-buffer-window-list)))) + (select-window win)))))) + (defun follow-find-file-hook () "Find-file hook for Follow mode. See the variable `follow-auto'." (if follow-auto (follow-mode 1))) diff --git a/lisp/isearch.el b/lisp/isearch.el index b762884..daecdb5 100644 --- a/lisp/isearch.el +++ b/lisp/isearch.el @@ -3075,11 +3075,15 @@ isearch-lazy-highlight-new-loop (run-with-idle-timer lazy-highlight-initial-delay nil 'isearch-lazy-highlight-update))))) +(defvar isearch-lazy-highlight-ongoing-search nil + "Bound to t while doing a lazy-highlight search.") + (defun isearch-lazy-highlight-search () "Search ahead for the next or previous match, for lazy highlighting. Attempt to do the search exactly the way the pending Isearch would." (condition-case nil (let ((case-fold-search isearch-lazy-highlight-case-fold-search) + (isearch-lazy-highlight-ongoing-search t) (isearch-regexp isearch-lazy-highlight-regexp) (isearch-regexp-function isearch-lazy-highlight-regexp-function) (isearch-lax-whitespace -- 2.5.3