[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/isearch-mb 1c16403 15/20: Keep advices only for the dur
From: |
Stefan Monnier |
Subject: |
[elpa] externals/isearch-mb 1c16403 15/20: Keep advices only for the duration of a search session |
Date: |
Sun, 16 May 2021 17:21:15 -0400 (EDT) |
branch: externals/isearch-mb
commit 1c1640301a696c730b38d5c8afcdac4a5fa9543e
Author: Augusto Stoffel <arstoffel@gmail.com>
Commit: Augusto Stoffel <arstoffel@gmail.com>
Keep advices only for the duration of a search session
Closes https://github.com/astoff/isearch-mb/issues/2
See also https://github.com/astoff/isearch-mb/pull/8
commit 65dcfc8e1c7102dc3312d29f68445a072c7420e8
Author: Augusto Stoffel <arstoffel@gmail.com>
Date: Sat May 15 16:22:01 2021 +0200
Pick some suggestions
Revert "Use remapping in minibuffer keymap"
This reverts commit eaa0d10a869cbf5d66f01a28c9a13cc161042d21.
commit c6054d037c2f5a1ba0b7e6b84f0105fa08e3bd9e
Author: Daniel Mendler <mail@daniel-mendler.de>
Date: Fri May 14 17:47:57 2021 +0200
todos
commit 138782231b462d30958f3d8821142c70b0ee0434
Author: Daniel Mendler <mail@daniel-mendler.de>
Date: Fri May 14 17:43:45 2021 +0200
Remove isearch-mb--session variable
commit 2115fccd8ab15715bd41626057d9f66a5da76b5a
Author: Daniel Mendler <mail@daniel-mendler.de>
Date: Fri May 14 17:29:19 2021 +0200
Add isearch-mb--no-search variable
commit 4aa36f115de243849896e3c2e0a0c9509f56cc6c
Author: Daniel Mendler <mail@daniel-mendler.de>
Date: Fri May 14 17:27:18 2021 +0200
Only install advices when mode is active
commit d6d6578f658dfdeebc613ba94c6e8d4935a3d5d2
Author: Daniel Mendler <mail@daniel-mendler.de>
Date: Fri May 14 17:18:24 2021 +0200
Use sharp symbols
commit eaa0d10a869cbf5d66f01a28c9a13cc161042d21
Author: Daniel Mendler <mail@daniel-mendler.de>
Date: Fri May 14 17:13:58 2021 +0200
Use remapping in minibuffer keymap
Additionally remap next/previous-line-or-history-element to
forward/backward
---
isearch-mb.el | 140 +++++++++++++++++++++++++++++++---------------------------
1 file changed, 74 insertions(+), 66 deletions(-)
diff --git a/isearch-mb.el b/isearch-mb.el
index 1b1a84c..5d0c380 100644
--- a/isearch-mb.el
+++ b/isearch-mb.el
@@ -41,8 +41,35 @@
(defvar isearch-mb--prompt-overlay nil
"Overlay for minibuffer prompt updates.")
-(defvar isearch-mb--session nil
- "Non-nil while reading the search string from the minibuffer.")
+(defvar isearch-mb--with-buffer
+ '(isearch-post-command-hook
+ isearch-beginning-of-buffer
+ isearch-end-of-buffer
+ isearch-occur
+ isearch-repeat-backward
+ isearch-repeat-forward
+ isearch-toggle-case-fold
+ isearch-toggle-char-fold
+ isearch-toggle-invisible
+ isearch-toggle-lax-whitespace
+ isearch-toggle-regexp
+ isearch-toggle-symbol
+ isearch-toggle-word
+ isearch-exit
+ isearch-delete-char)
+ "List of commands to execute in the search buffer.")
+
+(defvar isearch-mb--after-exit
+ '(isearch-query-replace
+ isearch-query-replace-regexp
+ isearch-highlight-regexp
+ isearch-highlight-lines-matching-regexp
+ isearch-abort)
+ "List of commands to execute after exiting the minibuffer.")
+
+(defvar isearch-mb--no-search
+ '(next-history-element previous-history-element)
+ "List of commands that shouldn't trigger a search.")
(defvar isearch-mb-minibuffer-map
(let ((map (make-sparse-keymap)))
@@ -77,12 +104,12 @@
;; Backtrack to barrier and search, unless `this-command' is
;; special or the search regexp is invalid.
(if (or (and (symbolp this-command)
- (get this-command 'isearch-mb--no-search))
+ (memq this-command isearch-mb--no-search))
(and isearch-regexp
(condition-case err
(prog1 nil (string-match-p isearch-string ""))
(invalid-regexp
- (prog1 t (isearch-mb--message (cadr err)))))))
+ (prog1 t (isearch-mb--momentary-message (cadr err)))))))
(isearch-update)
(goto-char isearch-barrier)
(setq isearch-adjusted t isearch-success t)
@@ -103,14 +130,13 @@
(point-max)
'(face isearch-fail)))
(when isearch-error
- (isearch-mb--message isearch-error))))
+ (isearch-mb--momentary-message isearch-error))))
-(defun isearch-mb--message (message)
+(defun isearch-mb--momentary-message (message)
"Display a momentary MESSAGE."
- (when isearch-mb--session
- (let ((message-log-max nil))
- (message (propertize (concat " [" message "]")
- 'face 'minibuffer-prompt)))))
+ (let ((message-log-max nil))
+ (message (propertize (concat " [" message "]")
+ 'face 'minibuffer-prompt))))
(defun isearch-mb--update-prompt (&rest _)
"Update the minibuffer prompt according to search status."
@@ -127,7 +153,7 @@
(defun isearch-mb--with-buffer (&rest args)
"Evaluate ARGS in the search buffer.
Intended as an advice for Isearch commands."
- (if (and isearch-mb--session (minibufferp))
+ (if (minibufferp)
(let ((enable-recursive-minibuffers t)
(inhibit-redisplay t))
(with-minibuffer-selected-window
@@ -140,17 +166,14 @@ Intended as an advice for Isearch commands."
"Evaluate ARGS, after quitting Isearch-Mb.
Intended as an advice for commands that quit Isearch and use the
minibuffer."
- (if isearch-mb--session
- (throw 'isearch-mb--continue args)
- (apply args)))
+ (throw 'isearch-mb--continue args))
(defun isearch-mb--session ()
"Read search string from the minibuffer."
(condition-case nil
(apply
(catch 'isearch-mb--continue
- (cl-letf ((isearch-mb--session t)
- ((cdr isearch-mode-map) nil)
+ (cl-letf (((cdr isearch-mode-map) nil)
;; We need to set `inhibit-redisplay' at certain points to
;; avoid flicker. As a side effect, window-start/end in
;; `isearch-lazy-highlight-update' will have incorrect
values,
@@ -158,25 +181,39 @@ minibuffer."
(lazy-highlight-buffer (not (null isearch-lazy-highlight))))
(minibuffer-with-setup-hook
(lambda ()
- (add-hook 'after-change-functions 'isearch-mb--after-change
nil 'local)
- (add-hook 'post-command-hook 'isearch-mb--post-command-hook
nil 'local)
+ (add-hook 'after-change-functions #'isearch-mb--after-change
nil 'local)
+ (add-hook 'post-command-hook #'isearch-mb--post-command-hook
nil 'local)
(setq-local tool-bar-map isearch-tool-bar-map)
(setq isearch-mb--prompt-overlay (make-overlay (point-min)
(point-min)
(current-buffer) t t))
(isearch-mb--update-prompt)
(isearch-mb--post-command-hook))
- (read-from-minibuffer
- "I-search: "
- nil
- isearch-mb-minibuffer-map
- nil
- (if isearch-regexp 'regexp-search-ring 'search-ring)
- (thread-last '(region url symbol sexp line) ;; TODO: make
customizable
- (mapcar 'thing-at-point)
- (delq nil)
- (delete-dups)
- (mapcar (if isearch-regexp 'regexp-quote 'identity)))
- t))
+ (unwind-protect
+ (progn
+ (dolist (fun isearch-mb--with-buffer)
+ (advice-add fun :around #'isearch-mb--with-buffer))
+ (dolist (fun isearch-mb--after-exit)
+ (advice-add fun :around #'isearch-mb--after-exit))
+ (advice-add #'isearch--momentary-message :override
#'isearch-mb--momentary-message)
+ (advice-add #'isearch-pre-command-hook :override #'ignore)
+ (read-from-minibuffer
+ "I-search: "
+ nil
+ isearch-mb-minibuffer-map
+ nil
+ (if isearch-regexp 'regexp-search-ring 'search-ring)
+ (thread-last '(region url symbol sexp line) ;; TODO: make
customizable
+ (mapcar #'thing-at-point)
+ (delq nil)
+ (delete-dups)
+ (mapcar (if isearch-regexp 'regexp-quote 'identity)))
+ t))
+ (dolist (fun isearch-mb--after-exit)
+ (advice-remove fun #'isearch-mb--after-exit))
+ (dolist (fun isearch-mb--with-buffer)
+ (advice-remove fun #'isearch-mb--with-buffer))
+ (advice-remove #'isearch--momentary-message
#'isearch-mb--momentary-message)
+ (advice-remove #'isearch-pre-command-hook #'ignore)))
(if isearch-mode '(isearch-done) '(ignore)))))
(quit (if isearch-mode (isearch-cancel) (signal 'quit nil)))))
@@ -187,36 +224,6 @@ minibuffer."
;; more than once, hence the test for `isearch-mode'.
(run-with-idle-timer 0 nil (lambda() (when isearch-mode
(isearch-mb--session))))))
-(put 'next-history-element 'isearch-mb--no-search t)
-(put 'previous-history-element 'isearch-mb--no-search t)
-
-(advice-add 'isearch--momentary-message :before-until 'isearch-mb--message)
-(advice-add 'isearch-pre-command-hook :before-until (lambda ()
isearch-mb--session))
-(advice-add 'isearch-post-command-hook :around 'isearch-mb--with-buffer)
-
-(advice-add 'isearch-beginning-of-buffer :around 'isearch-mb--with-buffer)
-(advice-add 'isearch-end-of-buffer :around 'isearch-mb--with-buffer)
-(advice-add 'isearch-occur :around 'isearch-mb--with-buffer)
-(advice-add 'isearch-repeat-backward :around 'isearch-mb--with-buffer)
-(advice-add 'isearch-repeat-forward :around 'isearch-mb--with-buffer)
-(advice-add 'isearch-toggle-case-fold :around 'isearch-mb--with-buffer)
-(advice-add 'isearch-toggle-char-fold :around 'isearch-mb--with-buffer)
-(advice-add 'isearch-toggle-invisible :around 'isearch-mb--with-buffer)
-(advice-add 'isearch-toggle-lax-whitespace :around 'isearch-mb--with-buffer)
-(advice-add 'isearch-toggle-regexp :around 'isearch-mb--with-buffer)
-(advice-add 'isearch-toggle-symbol :around 'isearch-mb--with-buffer)
-(advice-add 'isearch-toggle-word :around 'isearch-mb--with-buffer)
-
-(advice-add 'isearch-query-replace :around
'isearch-mb--after-exit)
-(advice-add 'isearch-query-replace-regexp :around
'isearch-mb--after-exit)
-(advice-add 'isearch-highlight-regexp :around
'isearch-mb--after-exit)
-(advice-add 'isearch-highlight-lines-matching-regexp :around
'isearch-mb--after-exit)
-
-;; For toolbar
-(advice-add 'isearch-exit :around 'isearch-mb--with-buffer)
-(advice-add 'isearch-delete-char :around 'isearch-mb--with-buffer)
-(advice-add 'isearch-abort :around 'isearch-mb--after-exit)
-
;;;###autoload
(define-minor-mode isearch-mb-mode
"Control Isearch from the minibuffer.
@@ -226,13 +233,14 @@ During an Isearch-Mb session, the following keys are
available:
:global t
(cond
(isearch-mb-mode
- ;; Setting `isearch-message-function' currently disables lazy count,
- ;; so we need this workaround.
- (advice-add 'isearch-message :override 'isearch-mb--update-prompt)
- (add-hook 'isearch-mode-hook 'isearch-mb--setup))
+ ;; Setting `isearch-message-function' currently disables lazy
+ ;; count, so we need this as a workaround. Setting it later
+ ;; causes flicker in the echo area when starting Isearch.
+ (advice-add #'isearch-message :override #'isearch-mb--update-prompt)
+ (add-hook 'isearch-mode-hook #'isearch-mb--setup))
(t
- (advice-remove 'isearch-message 'isearch-mb--update-prompt)
- (remove-hook 'isearch-mode-hook 'isearch-mb--setup))))
+ (advice-remove #'isearch-message #'isearch-mb--update-prompt)
+ (remove-hook 'isearch-mode-hook #'isearch-mb--setup))))
(provide 'isearch-mb)
;;; isearch-mb.el ends here
- [elpa] branch externals/isearch-mb created (now c270809), Stefan Monnier, 2021/05/16
- [elpa] externals/isearch-mb 1c16403 15/20: Keep advices only for the duration of a search session,
Stefan Monnier <=
- [elpa] externals/isearch-mb ce41e00 12/20: Add a Readme, Stefan Monnier, 2021/05/16
- [elpa] externals/isearch-mb c6fc566 18/20: Use remapping in minibuffer keymap, Stefan Monnier, 2021/05/16
- [elpa] externals/isearch-mb 5d5b0e9 17/20: Replace advices by let-bindings where possible, Stefan Monnier, 2021/05/16
- [elpa] externals/isearch-mb a663c22 16/20: Better place to check if Isearch is still active, Stefan Monnier, 2021/05/16
- [elpa] externals/isearch-mb dc603a9 03/20: Lazily highlight the whole buffer, to avoid missing overlays, Stefan Monnier, 2021/05/16
- [elpa] externals/isearch-mb 40add97 01/20: Initial commit, Stefan Monnier, 2021/05/16
- [elpa] externals/isearch-mb 8566108 02/20: Many changes, Stefan Monnier, 2021/05/16
- [elpa] externals/isearch-mb 223b1b9 04/20: Introduce a buffer-local minor mode, Stefan Monnier, 2021/05/16
- [elpa] externals/isearch-mb 5805f13 07/20: Add keybinding for newline, Stefan Monnier, 2021/05/16
- [elpa] externals/isearch-mb d075efe 06/20: Rename minor modes, move a test to the timer function, Stefan Monnier, 2021/05/16