From: Artur Malabarba <bruce.connor.am@gmail.com>
To: Alan Mackenzie <acm@muc.de>
Cc: Eli Zaretskii <eliz@gnu.org>, emacs-devel <emacs-devel@gnu.org>
Subject: Re: bug#17453: Isearch doesn't work properly with Follow Mode.
Date: Sun, 1 Nov 2015 20:42:26 +0000 [thread overview]
Message-ID: <CAAdUY-JAnyiDQSYr-=NgutG7b=hAYfF_zFubSDTzTfyXx835Zw@mail.gmail.com> (raw)
In-Reply-To: <CAAdUY-KvTdLntFJ6ZJTeBcc2oQsW=x=OV2cLvsb+VAF2yWe5dA@mail.gmail.com>
2015-11-01 19:46 GMT+00:00 Artur Malabarba <bruce.connor.am@gmail.com>:
> 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
next prev parent reply other threads:[~2015-11-01 20:42 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20140509224458.GA4205@acm.acm>
[not found] ` <jwva9aqbcl9.fsf-monnier+emacsbugs@gnu.org>
2015-10-29 23:23 ` bug#17453: Isearch doesn't work properly with Follow Mode Alan Mackenzie
2015-10-31 22:35 ` John Wiegley
2015-10-31 23:25 ` Alan Mackenzie
2015-10-31 23:41 ` John Wiegley
2015-11-01 11:59 ` Alan Mackenzie
2015-11-01 0:17 ` Drew Adams
2015-10-31 23:13 ` Artur Malabarba
2015-10-31 23:32 ` Alan Mackenzie
2015-11-01 12:20 ` Artur Malabarba
2015-11-01 12:23 ` Artur Malabarba
2015-11-01 13:52 ` Alan Mackenzie
2015-11-01 16:50 ` Eli Zaretskii
2015-11-01 18:27 ` Alan Mackenzie
2015-11-01 19:46 ` Artur Malabarba
2015-11-01 20:15 ` Alan Mackenzie
2015-11-01 21:37 ` Artur Malabarba
2015-11-01 20:42 ` Artur Malabarba [this message]
2015-11-01 20:54 ` Eli Zaretskii
2015-11-01 22:19 ` Alan Mackenzie
2015-10-31 23:35 ` Juri Linkov
2015-10-31 23:56 ` Alan Mackenzie
2015-11-02 0:14 ` Juri Linkov
2015-11-02 3:35 ` Eli Zaretskii
2015-11-02 9:28 ` Alan Mackenzie
2015-11-02 11:53 ` Artur Malabarba
2015-11-02 12:14 ` Artur Malabarba
2015-11-02 12:39 ` Alan Mackenzie
2015-11-02 12:35 ` Alan Mackenzie
2015-11-02 13:10 ` Artur Malabarba
2015-11-02 14:18 ` Artur Malabarba
2015-11-02 15:44 ` Alan Mackenzie
2015-11-02 23:22 ` Juri Linkov
2015-11-03 12:31 ` Alan Mackenzie
2015-11-02 23:28 ` Juri Linkov
2015-11-02 23:33 ` Juri Linkov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAAdUY-JAnyiDQSYr-=NgutG7b=hAYfF_zFubSDTzTfyXx835Zw@mail.gmail.com' \
--to=bruce.connor.am@gmail.com \
--cc=acm@muc.de \
--cc=eliz@gnu.org \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).