[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: bug#17453: Isearch doesn't work properly with Follow Mode.

From: Artur Malabarba
Subject: Re: bug#17453: Isearch doesn't work properly with Follow Mode.
Date: Sun, 1 Nov 2015 20:42:26 +0000

2015-11-01 19:46 GMT+00:00 Artur Malabarba <address@hidden>:
> 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

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
+        (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))
       (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

+(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)

reply via email to

[Prev in Thread] Current Thread [Next in Thread]