From caf5adfc0b7caf07dc74813242f9ecc664babc13 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Mon, 2 Nov 2015 14:01:18 +0000 Subject: [PATCH 3/3] * lisp/follow.el: Improve isearch compatibility (follow--search-function): New function. (follow-mode): Configure `isearch-lazy-highlight' and `isearch-search-fun-function'. --- lisp/follow.el | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/lisp/follow.el b/lisp/follow.el index 938c59e..0b80f04 100644 --- a/lisp/follow.el +++ b/lisp/follow.el @@ -419,6 +419,9 @@ follow-mode :keymap follow-mode-map (if follow-mode (progn + (setq-local isearch-search-fun-function #'follow--search-function) + (when isearch-lazy-highlight + (setq-local isearch-lazy-highlight 'all-windows)) (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)) @@ -434,6 +437,36 @@ follow-mode (remove-hook 'window-size-change-functions 'follow-window-size-change))) (remove-hook 'compilation-filter-hook 'follow-align-compilation-windows t))) +(defun follow--search-function () + "Return a function suitable for `isearch-search-fun-function'." + (lambda (string &optional bound noerror count) + (let* ((search-function (isearch-search-fun-default)) + (all-followers (follow-all-followers)) + ;; If bound at the edge of the window, extend it to the + ;; edges know by `follow-mode'. + (bound (cond ((equal bound (window-end)) + (window-end (car (last all-followers)))) + ((equal bound (window-start)) + (window-start (car all-followers))) + (t bound))) + (matched (funcall search-function string bound noerror count))) + ;; If this is a proper user-triggered search (and not just a + ;; lazy-highlight search), and if the search matched, and if the + ;; match is not visible on this window... + (when (and matched + (not isearch-lazy-highlight-ongoing-search) + (not (and (pos-visible-in-window-p (match-beginning 0)) + (pos-visible-in-window-p (match-end 0))))) + ;; ... see if the match is visible on another window. + (let ((win (seq-find (lambda (w) + (and (pos-visible-in-window-p (match-beginning 0) w) + (pos-visible-in-window-p (match-end 0) w))) + all-followers))) + ;; If so, select it. + (when win + (select-window win)))) + matched))) + (defun follow-find-file-hook () "Find-file hook for Follow mode. See the variable `follow-auto'." (if follow-auto (follow-mode 1))) -- 2.6.2