[Top][All Lists]

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

Re: Simple isearch concerns

From: Juri Linkov
Subject: Re: Simple isearch concerns
Date: Tue, 27 Apr 2021 20:41:47 +0300
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (x86_64-pc-linux-gnu)

>>   (setq-local overriding-terminal-local-map isearch-mode-map)
>> fails with an error:
>>   Debugger entered--Lisp error: (error "Symbol overriding-terminal-local-map 
>> may not be buffer-local")
>>     make-local-variable(overriding-terminal-local-map)
>>     (set (make-local-variable 'overriding-terminal-local-map) 
>> isearch-mode-map)
>>     isearch-mode(t nil nil nil)
>>     isearch-forward(nil 1)
> Is this overriding map there just so that `isearch-mode-map' takes
> precedence over other minor mode maps?  If so, couldn't this be achieved
> by manipulating minor-mode-map-alist to put Isearch's map at the top?
> Maybe that can be done buffer-locally.

According to (info "(elisp) Searching Keymaps") the next keymap to try is
`overriding-local-map`.  It can be set buffer-locally.  And indeed,
with the following patch you can set a few commands to not exit isearch:

  (put 'other-window 'isearch-scroll t)
  (put 'eval-expression 'isearch-scroll t)

Then switching to another buffer with 'C-x o', or switching
to the minibuffer with 'M-:' leaves the local isearch active
in the original buffer.  After switching back to the original buffer,
or after exiting the minibuffer, isearch is still active
and can be used to continue searching.

Later this could be handled depending on a new option 'isearch-buffer-local':

diff --git a/lisp/isearch.el b/lisp/isearch.el
index 9f3cfd70fb..11c2798b76 100644
--- a/lisp/isearch.el
+++ b/lisp/isearch.el
@@ -1295,11 +1295,11 @@ isearch-mode
   (setq        isearch-mode " Isearch")  ;; forward? regexp?
-  (setq overriding-terminal-local-map isearch-mode-map)
+  (setq-local overriding-local-map isearch-mode-map)
   (run-hooks 'isearch-mode-hook)
   ;; Remember the initial map possibly modified
   ;; by external packages in isearch-mode-hook.  (Bug#16035)
-  (setq isearch--saved-overriding-local-map overriding-terminal-local-map)
+  (setq isearch--saved-overriding-local-map overriding-local-map)
   ;; Pushing the initial state used to be before running isearch-mode-hook,
   ;; but a hook might set `isearch-push-state-function' used in
@@ -1308,10 +1308,10 @@ isearch-mode
-  (add-hook 'pre-command-hook 'isearch-pre-command-hook)
-  (add-hook 'post-command-hook 'isearch-post-command-hook)
-  (add-hook 'mouse-leave-buffer-hook 'isearch-mouse-leave-buffer)
-  (add-hook 'kbd-macro-termination-hook 'isearch-done)
+  (add-hook 'pre-command-hook 'isearch-pre-command-hook nil t)
+  (add-hook 'post-command-hook 'isearch-post-command-hook nil t)
+  (add-hook 'mouse-leave-buffer-hook 'isearch-mouse-leave-buffer nil t)
+  (add-hook 'kbd-macro-termination-hook 'isearch-done nil t)
   ;; isearch-mode can be made modal (in the sense of not returning to
   ;; the calling function until searching is completed) by entering
@@ -1406,10 +1406,10 @@ isearch-done
-  (remove-hook 'pre-command-hook 'isearch-pre-command-hook)
-  (remove-hook 'post-command-hook 'isearch-post-command-hook)
-  (remove-hook 'mouse-leave-buffer-hook 'isearch-mouse-leave-buffer)
-  (remove-hook 'kbd-macro-termination-hook 'isearch-done)
+  (remove-hook 'pre-command-hook 'isearch-pre-command-hook t)
+  (remove-hook 'post-command-hook 'isearch-post-command-hook t)
+  (remove-hook 'mouse-leave-buffer-hook 'isearch-mouse-leave-buffer t)
+  (remove-hook 'kbd-macro-termination-hook 'isearch-done t)
   (when (buffer-live-p isearch--current-buffer)
     (with-current-buffer isearch--current-buffer
       (setq isearch--current-buffer nil)
@@ -1417,7 +1417,7 @@ isearch-done
   ;; Called by all commands that terminate isearch-mode.
   ;; If NOPUSH is non-nil, we don't push the string on the search ring.
-  (setq overriding-terminal-local-map nil)
+  (setq overriding-local-map nil)
   ;; (setq pre-command-hook isearch-old-pre-command-hook) ; for lemacs
   (setq minibuffer-message-timeout isearch-original-minibuffer-message-timeout)
@@ -2599,7 +2599,7 @@ isearch-mouse-2
 is bound to outside of Isearch."
   (interactive "e")
   (let ((w (posn-window (event-start click)))
-        (binding (let ((overriding-terminal-local-map nil)
+        (binding (let ((overriding-local-map nil)
                        ;; Key search depends on mode (bug#47755)
                        (isearch-mode nil))
                    (key-binding (this-command-keys-vector) t))))
@@ -3018,7 +3018,7 @@ isearch-pre-command-hook
      ;; Don't exit Isearch if we're in the middle of some
      ;; `set-transient-map' thingy like `universal-argument--mode'.
-     ((not (eq overriding-terminal-local-map 
+     ((not (eq overriding-local-map isearch--saved-overriding-local-map)))
      ;; Don't exit Isearch for isearch key bindings.
      ((or (commandp (lookup-key isearch-mode-map key nil))

reply via email to

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