unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#60815: 28.2; Hard-coded M-sff key binding in dired-aux.el
@ 2023-01-14 16:44 Evgeni Pandurski
  2023-01-14 18:14 ` Eli Zaretskii
  2023-01-14 18:19 ` Juri Linkov
  0 siblings, 2 replies; 11+ messages in thread
From: Evgeni Pandurski @ 2023-01-14 16:44 UTC (permalink / raw)
  To: 60815

I have set "(dired-isearch-filenames t)", and have rebound "M-s" to
something that is not a keymap (other-window). The problem appears
when I try to "isearch" in a Dired buffer. Then the following code:

(defun dired-isearch-filenames-end ()
  "Clean up the Dired file name search after terminating isearch."
  (define-key isearch-mode-map "\M-sff" nil)
  (dired-isearch-filenames-mode -1)
  (remove-hook 'isearch-mode-end-hook #'dired-isearch-filenames-end t)
  (unless isearch-suspended
    (kill-local-variable 'dired-isearch-filenames)))

runs and fails, because it can not bind to "M-sff". It works when I
change "M-sff" to something that starts with a keymap-binding. This is
also a problem in Emacs 27.





^ permalink raw reply	[flat|nested] 11+ messages in thread

* bug#60815: 28.2; Hard-coded M-sff key binding in dired-aux.el
  2023-01-14 16:44 bug#60815: 28.2; Hard-coded M-sff key binding in dired-aux.el Evgeni Pandurski
@ 2023-01-14 18:14 ` Eli Zaretskii
       [not found]   ` <CA+MLsgOSFS0h45qMpDv3p8WFVpo3oju19uS49RvxfTMAmZRJ5Q@mail.gmail.com>
  2023-01-14 18:19 ` Juri Linkov
  1 sibling, 1 reply; 11+ messages in thread
From: Eli Zaretskii @ 2023-01-14 18:14 UTC (permalink / raw)
  To: Evgeni Pandurski; +Cc: 60815

> From: Evgeni Pandurski <epandurski@gmail.com>
> Date: Sat, 14 Jan 2023 18:44:06 +0200
> 
> I have set "(dired-isearch-filenames t)", and have rebound "M-s" to
> something that is not a keymap (other-window). The problem appears
> when I try to "isearch" in a Dired buffer. Then the following code:
> 
> (defun dired-isearch-filenames-end ()
>   "Clean up the Dired file name search after terminating isearch."
>   (define-key isearch-mode-map "\M-sff" nil)
>   (dired-isearch-filenames-mode -1)
>   (remove-hook 'isearch-mode-end-hook #'dired-isearch-filenames-end t)
>   (unless isearch-suspended
>     (kill-local-variable 'dired-isearch-filenames)))
> 
> runs and fails, because it can not bind to "M-sff". It works when I
> change "M-sff" to something that starts with a keymap-binding. This is
> also a problem in Emacs 27.

Please show how you rebound M-s to other-window.





^ permalink raw reply	[flat|nested] 11+ messages in thread

* bug#60815: 28.2; Hard-coded M-sff key binding in dired-aux.el
  2023-01-14 16:44 bug#60815: 28.2; Hard-coded M-sff key binding in dired-aux.el Evgeni Pandurski
  2023-01-14 18:14 ` Eli Zaretskii
@ 2023-01-14 18:19 ` Juri Linkov
  1 sibling, 0 replies; 11+ messages in thread
From: Juri Linkov @ 2023-01-14 18:19 UTC (permalink / raw)
  To: Evgeni Pandurski; +Cc: 60815

> I have set "(dired-isearch-filenames t)", and have rebound "M-s" to
> something that is not a keymap (other-window). The problem appears
> when I try to "isearch" in a Dired buffer. Then the following code:
>
> (defun dired-isearch-filenames-end ()
>   "Clean up the Dired file name search after terminating isearch."
>   (define-key isearch-mode-map "\M-sff" nil)
>   (dired-isearch-filenames-mode -1)
>   (remove-hook 'isearch-mode-end-hook #'dired-isearch-filenames-end t)
>   (unless isearch-suspended
>     (kill-local-variable 'dired-isearch-filenames)))
>
> runs and fails, because it can not bind to "M-sff". It works when I
> change "M-sff" to something that starts with a keymap-binding. This is
> also a problem in Emacs 27.

Maybe it should be configurable:

```
diff --git a/lisp/dired-aux.el b/lisp/dired-aux.el
index c390017e190..27ab35c04d2 100644
--- a/lisp/dired-aux.el
+++ b/lisp/dired-aux.el
@@ -3530,6 +3530,9 @@ dired-isearch-filenames-mode
     (setq isearch-success t isearch-adjusted t)
     (isearch-update)))
 
+(defvar dired-isearch-filenames-toggle-key "\M-sff"
+  "Key to toggle `dired-isearch-filenames-setup' in `isearch-mode'.")
+
 ;;;###autoload
 (defun dired-isearch-filenames-setup ()
   "Set up isearch to search in Dired file names.
@@ -3537,13 +3540,16 @@ dired-isearch-filenames-setup
   (when (or (eq dired-isearch-filenames t)
 	    (and (eq dired-isearch-filenames 'dwim)
 		 (get-text-property (point) 'dired-filename)))
-    (define-key isearch-mode-map "\M-sff" 'dired-isearch-filenames-mode)
+    (when dired-isearch-filenames-toggle-key
+      (define-key isearch-mode-map dired-isearch-filenames-toggle-key
+                  'dired-isearch-filenames-mode))
     (dired-isearch-filenames-mode 1)
     (add-hook 'isearch-mode-end-hook #'dired-isearch-filenames-end nil t)))
 
 (defun dired-isearch-filenames-end ()
   "Clean up the Dired file name search after terminating isearch."
-  (define-key isearch-mode-map "\M-sff" nil)
+  (when dired-isearch-filenames-toggle-key
+    (define-key isearch-mode-map dired-isearch-filenames-toggle-key nil))
   (dired-isearch-filenames-mode -1)
   (remove-hook 'isearch-mode-end-hook #'dired-isearch-filenames-end t)
   (unless isearch-suspended
```





^ permalink raw reply related	[flat|nested] 11+ messages in thread

* bug#60815: 28.2; Hard-coded M-sff key binding in dired-aux.el
       [not found]     ` <CA+MLsgOj1qyYT0xrM9kWfTHuo_qxQ6czhGtUtqoc=GYV9Hwf-g@mail.gmail.com>
@ 2023-01-14 18:52       ` Eli Zaretskii
  2023-01-17 17:24         ` Juri Linkov
  0 siblings, 1 reply; 11+ messages in thread
From: Eli Zaretskii @ 2023-01-14 18:52 UTC (permalink / raw)
  To: Evgeni Pandurski; +Cc: 60815

> From: Evgeni Pandurski <epandurski@gmail.com>
> Date: Sat, 14 Jan 2023 20:37:20 +0200
> 
> Oh, my bad! Actually, it is: (define-key isearch-mode-map (kbd "M-s")
> 'other-window)

And that is the problem: you should bind it in the global map, not in
isearch-mode-map.  The Isearch mode map has several key sequences
hard-coded that begin with the M-s key, so binding M-s in the Isearch
keymap is not recommended.





^ permalink raw reply	[flat|nested] 11+ messages in thread

* bug#60815: 28.2; Hard-coded M-sff key binding in dired-aux.el
  2023-01-14 18:52       ` Eli Zaretskii
@ 2023-01-17 17:24         ` Juri Linkov
  2023-01-17 18:30           ` Evgeni Pandurski
       [not found]           ` <CA+MLsgMSDroUBLYfkwcDxyf6=jMSZR0NxZExuWSvrg07+uDrHA@mail.gmail.com>
  0 siblings, 2 replies; 11+ messages in thread
From: Juri Linkov @ 2023-01-17 17:24 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Evgeni Pandurski, 60815-done

>> Oh, my bad! Actually, it is: (define-key isearch-mode-map (kbd "M-s")
>> 'other-window)
>
> And that is the problem: you should bind it in the global map, not in
> isearch-mode-map.  The Isearch mode map has several key sequences
> hard-coded that begin with the M-s key, so binding M-s in the Isearch
> keymap is not recommended.

Then I guess this report can be closed, done.





^ permalink raw reply	[flat|nested] 11+ messages in thread

* bug#60815: 28.2; Hard-coded M-sff key binding in dired-aux.el
  2023-01-17 17:24         ` Juri Linkov
@ 2023-01-17 18:30           ` Evgeni Pandurski
  2023-01-17 18:43             ` Eli Zaretskii
       [not found]           ` <CA+MLsgMSDroUBLYfkwcDxyf6=jMSZR0NxZExuWSvrg07+uDrHA@mail.gmail.com>
  1 sibling, 1 reply; 11+ messages in thread
From: Evgeni Pandurski @ 2023-01-17 18:30 UTC (permalink / raw)
  To: Juri Linkov; +Cc: Eli Zaretskii, 60815-done

Now I see that i have messed up this mail-thread, by not CC-ing to all
participants (easy to do from Gmail's web interface).

The point is that I found a way to re-bind M-s, which works well
enough for me (by monkey-patching some functions from dired-aux.el.
And I believe that, currently, re-binding M-s is unnecessarily hard,
which I consider as either a bug or a serious architectural problem in
Emacs.

On Tue, Jan 17, 2023 at 7:34 PM Juri Linkov <juri@linkov.net> wrote:
>
> >> Oh, my bad! Actually, it is: (define-key isearch-mode-map (kbd "M-s")
> >> 'other-window)
> >
> > And that is the problem: you should bind it in the global map, not in
> > isearch-mode-map.  The Isearch mode map has several key sequences
> > hard-coded that begin with the M-s key, so binding M-s in the Isearch
> > keymap is not recommended.
>
> Then I guess this report can be closed, done.





^ permalink raw reply	[flat|nested] 11+ messages in thread

* bug#60815: 28.2; Hard-coded M-sff key binding in dired-aux.el
  2023-01-17 18:30           ` Evgeni Pandurski
@ 2023-01-17 18:43             ` Eli Zaretskii
  0 siblings, 0 replies; 11+ messages in thread
From: Eli Zaretskii @ 2023-01-17 18:43 UTC (permalink / raw)
  To: Evgeni Pandurski; +Cc: 60815, juri

> From: Evgeni Pandurski <epandurski@gmail.com>
> Date: Tue, 17 Jan 2023 20:30:23 +0200
> Cc: Eli Zaretskii <eliz@gnu.org>, 60815-done@debbugs.gnu.org
> 
> Now I see that i have messed up this mail-thread, by not CC-ing to all
> participants (easy to do from Gmail's web interface).
> 
> The point is that I found a way to re-bind M-s, which works well
> enough for me (by monkey-patching some functions from dired-aux.el.
> And I believe that, currently, re-binding M-s is unnecessarily hard,
> which I consider as either a bug or a serious architectural problem in
> Emacs.

Once again, M-s in Isearch's local map is deliberately used for
Isearch-related commands.  You can bind M-s in the global map, and
then you will have no problems.

I don't agree that the fact we use M-x in Isearch is a bug.  Some key
bindings in Emacs are intentionally hard to rebind (for example, C-x),
and that's a feature from where I stand.





^ permalink raw reply	[flat|nested] 11+ messages in thread

* bug#60815: 28.2; Hard-coded M-sff key binding in dired-aux.el
       [not found]           ` <CA+MLsgMSDroUBLYfkwcDxyf6=jMSZR0NxZExuWSvrg07+uDrHA@mail.gmail.com>
@ 2023-01-17 18:47             ` Juri Linkov
  2023-01-17 19:01               ` Evgeni Pandurski
  0 siblings, 1 reply; 11+ messages in thread
From: Juri Linkov @ 2023-01-17 18:47 UTC (permalink / raw)
  To: Evgeni Pandurski; +Cc: 60815

[-- Attachment #1: Type: text/plain, Size: 1732 bytes --]

reopen 60815
thanks

>> Then I guess this report can be closed, done.
>
> I think so. Your patch would allow me to just change the value of
> dired-isearch-filenames-toggle-key, instead of monkey-patching the
> whole function in my .emacs.
>
> But it seems that some key-bindings are much harder to change than
> another. "M-s", is such an example, because many modes decide to
> override it in their keymaps. Just an idea: Wouldn't it be nice, if
> there were an configuration that defines what is the key sequence for
> "the M-s search" (M-s by default), and if major modes want to override
> the "M-s search commands", they would respect what the configuration
> says.

Indeed, there is already such variable: `search-map'.  So you can do:

  (define-key global-map [f6] search-map)

> For example, If I rebind "M-s" to say "M-6", then the
> dired-isearch-filenames-setup function would define the "M-6ff"
> binding, instead of "M-sff". I am not sure if this is a good idea, but
> this seems like a good approach to me.
>
> So basically, I propose, instead of the
> "dired-isearch-filenames-toggle-key" configuration ("M-sfff by
> default), to have, say "global-search-key-sequence" ("M-s" by
> default), which all major modes can use when building their local
> keymaps. This way, I would not need to fix this binding in every major
> mode which overrides it, wrongly believing that M-s is my "search
> prefix".

The problem is that isearch doesn't use the global "M-s" keymap,
but hard-codes "M-s" used in isearch-map.  The patch below adds
a new variable for the isearch's keymap "M-s" that you can
customize with e.g.:

  (define-key isearch-mode-map [f6] isearch-mode-search-map)

Needless to say this patch is for master.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: isearch-mode-search-map.patch --]
[-- Type: text/x-diff, Size: 3466 bytes --]

diff --git a/lisp/dired-aux.el b/lisp/dired-aux.el
index c390017e190..a840a027553 100644
--- a/lisp/dired-aux.el
+++ b/lisp/dired-aux.el
@@ -3537,13 +3537,13 @@ dired-isearch-filenames-setup
   (when (or (eq dired-isearch-filenames t)
 	    (and (eq dired-isearch-filenames 'dwim)
 		 (get-text-property (point) 'dired-filename)))
-    (define-key isearch-mode-map "\M-sff" 'dired-isearch-filenames-mode)
+    (define-key isearch-mode-search-map "ff" 'dired-isearch-filenames-mode)
     (dired-isearch-filenames-mode 1)
     (add-hook 'isearch-mode-end-hook #'dired-isearch-filenames-end nil t)))
 
 (defun dired-isearch-filenames-end ()
   "Clean up the Dired file name search after terminating isearch."
-  (define-key isearch-mode-map "\M-sff" nil)
+  (define-key isearch-mode-search-map "ff" nil)
   (dired-isearch-filenames-mode -1)
   (remove-hook 'isearch-mode-end-hook #'dired-isearch-filenames-end t)
   (unless isearch-suspended
diff --git a/lisp/isearch.el b/lisp/isearch.el
index 8efafd0a2d0..e2273ab7fb9 100644
--- a/lisp/isearch.el
+++ b/lisp/isearch.el
@@ -560,6 +560,21 @@ isearch-menu-bar-commands
   '(isearch-tmm-menubar tmm-menubar menu-bar-open mouse-minor-mode-menu)
   "List of commands that can open a menu during Isearch.")
 
+(defvar-keymap isearch-mode-search-map
+  :doc "Keymap for the M-s prefix keys used during Isearch."
+  ;; More toggles defined by `isearch-define-mode-toggle'.
+  "C-e" #'isearch-yank-line
+  "M-<" #'isearch-beginning-of-buffer
+  "M->" #'isearch-end-of-buffer
+  "e" #'isearch-edit-string
+  "o" #'isearch-occur
+  "h r" #'isearch-highlight-regexp
+  "h l" #'isearch-highlight-lines-matching-regexp)
+
+(put 'isearch-toggle-case-fold :advertised-binding "\M-sc")
+(put 'isearch-toggle-regexp    :advertised-binding "\M-sr")
+(put 'isearch-edit-string      :advertised-binding "\M-se")
+
 ;; Note: Before adding more key bindings to this map, please keep in
 ;; mind that any unbound key exits Isearch and runs the command bound
 ;; to it in the local or global map.  So in effect every key unbound
@@ -618,10 +633,6 @@ isearch-mode-map
     (define-key map "\M-\C-y" 'isearch-yank-char)
     (define-key map    "\C-y" 'isearch-yank-kill)
     (define-key map "\M-\C-z" 'isearch-yank-until-char)
-    (define-key map "\M-s\C-e" 'isearch-yank-line)
-
-    (define-key map "\M-s\M-<" 'isearch-beginning-of-buffer)
-    (define-key map "\M-s\M->" 'isearch-end-of-buffer)
 
     (define-key map (char-to-string help-char) isearch-help-map)
     (define-key map [help] isearch-help-map)
@@ -659,18 +670,10 @@ isearch-mode-map
     (define-key map "\M-r" 'isearch-toggle-regexp)
     (define-key map "\M-e" 'isearch-edit-string)
 
-    (put 'isearch-toggle-case-fold :advertised-binding "\M-sc")
-    (put 'isearch-toggle-regexp    :advertised-binding "\M-sr")
-    (put 'isearch-edit-string      :advertised-binding "\M-se")
-
-    (define-key map "\M-se" 'isearch-edit-string)
-    ;; More toggles defined by `isearch-define-mode-toggle'.
-
     (define-key map [?\M-%] 'isearch-query-replace)
     (define-key map [?\C-\M-%] 'isearch-query-replace-regexp)
-    (define-key map "\M-so" 'isearch-occur)
-    (define-key map "\M-shr" 'isearch-highlight-regexp)
-    (define-key map "\M-shl" 'isearch-highlight-lines-matching-regexp)
+
+    (define-key map "\M-s" isearch-mode-search-map)
 
     ;; The key translations defined in the C-x 8 prefix should add
     ;; characters to the search string.  See iso-transl.el.

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* bug#60815: 28.2; Hard-coded M-sff key binding in dired-aux.el
  2023-01-17 18:47             ` Juri Linkov
@ 2023-01-17 19:01               ` Evgeni Pandurski
  2023-01-17 19:27                 ` Juri Linkov
  0 siblings, 1 reply; 11+ messages in thread
From: Evgeni Pandurski @ 2023-01-17 19:01 UTC (permalink / raw)
  To: Juri Linkov; +Cc: 60815

Thanks.

The problem that remains is that I should do the equivalent of:

(define-key isearch-mode-map [f6] isearch-mode-search-map)
(define-key isearch-mode-map (kbd "M-s") other-window)

for several other minor (and probably some minor modes). To name a
few: minibuffer-local-map, Buffer-menu-mode-map, and dired-mode-map
all shadow my M-s redefinition, and I can not go to other window in
these modes. It would be very nice if those major modes are more
clever, clever when overriding global bindings.

On Tue, Jan 17, 2023 at 8:49 PM Juri Linkov <juri@linkov.net> wrote:
>
> reopen 60815
> thanks
>
> >> Then I guess this report can be closed, done.
> >
> > I think so. Your patch would allow me to just change the value of
> > dired-isearch-filenames-toggle-key, instead of monkey-patching the
> > whole function in my .emacs.
> >
> > But it seems that some key-bindings are much harder to change than
> > another. "M-s", is such an example, because many modes decide to
> > override it in their keymaps. Just an idea: Wouldn't it be nice, if
> > there were an configuration that defines what is the key sequence for
> > "the M-s search" (M-s by default), and if major modes want to override
> > the "M-s search commands", they would respect what the configuration
> > says.
>
> Indeed, there is already such variable: `search-map'.  So you can do:
>
>   (define-key global-map [f6] search-map)
>
> > For example, If I rebind "M-s" to say "M-6", then the
> > dired-isearch-filenames-setup function would define the "M-6ff"
> > binding, instead of "M-sff". I am not sure if this is a good idea, but
> > this seems like a good approach to me.
> >
> > So basically, I propose, instead of the
> > "dired-isearch-filenames-toggle-key" configuration ("M-sfff by
> > default), to have, say "global-search-key-sequence" ("M-s" by
> > default), which all major modes can use when building their local
> > keymaps. This way, I would not need to fix this binding in every major
> > mode which overrides it, wrongly believing that M-s is my "search
> > prefix".
>
> The problem is that isearch doesn't use the global "M-s" keymap,
> but hard-codes "M-s" used in isearch-map.  The patch below adds
> a new variable for the isearch's keymap "M-s" that you can
> customize with e.g.:
>
>   (define-key isearch-mode-map [f6] isearch-mode-search-map)
>
> Needless to say this patch is for master.
>





^ permalink raw reply	[flat|nested] 11+ messages in thread

* bug#60815: 28.2; Hard-coded M-sff key binding in dired-aux.el
  2023-01-17 19:01               ` Evgeni Pandurski
@ 2023-01-17 19:27                 ` Juri Linkov
  2023-01-17 19:44                   ` Evgeni Pandurski
  0 siblings, 1 reply; 11+ messages in thread
From: Juri Linkov @ 2023-01-17 19:27 UTC (permalink / raw)
  To: Evgeni Pandurski; +Cc: 60815

[-- Attachment #1: Type: text/plain, Size: 681 bytes --]

> The problem that remains is that I should do the equivalent of:
>
> (define-key isearch-mode-map [f6] isearch-mode-search-map)
> (define-key isearch-mode-map (kbd "M-s") other-window)
>
> for several other minor (and probably some minor modes). To name a
> few: minibuffer-local-map, Buffer-menu-mode-map, and dired-mode-map
> all shadow my M-s redefinition, and I can not go to other window in
> these modes. It would be very nice if those major modes are more
> clever, clever when overriding global bindings.

This is possible too where you can additionally use

  (setq search-prefix [f6])

If this works, then minibuffer-local-map could be made customizable
later as well:


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: search-prefix.patch --]
[-- Type: text/x-diff, Size: 6149 bytes --]

diff --git a/lisp/bindings.el b/lisp/bindings.el
index 99189d2e570..c8ce376e5d4 100644
--- a/lisp/bindings.el
+++ b/lisp/bindings.el
@@ -1139,7 +1139,8 @@ search-map
   "h u" #'unhighlight-regexp
   "h f" #'hi-lock-find-patterns
   "h w" #'hi-lock-write-interactive-patterns)
-(define-key esc-map "s" search-map)
+(defvar search-prefix "\M-s")
+(define-key global-map search-prefix search-map)
 
 (put 'highlight-regexp                   :advertised-binding [?\M-s ?h ?r])
 (put 'highlight-phrase                   :advertised-binding [?\M-s ?h ?p])
diff --git a/lisp/buff-menu.el b/lisp/buff-menu.el
index 29c981c1364..241c9d85e98 100644
--- a/lisp/buff-menu.el
+++ b/lisp/buff-menu.el
@@ -110,6 +110,12 @@ Buffer-menu-filter-predicate
 (defvar-local Buffer-menu-buffer-list nil
   "The current list of buffers or function to return buffers.")
 
+(defvar-keymap Buffer-menu-mode-search-map
+  :doc "Local keymap for search keys in `Buffer-menu-mode-map'."
+  "a C-s"   #'Buffer-menu-isearch-buffers
+  "a C-M-s" #'Buffer-menu-isearch-buffers-regexp
+  "a C-o"   #'Buffer-menu-multi-occur)
+
 (defvar-keymap Buffer-menu-mode-map
   :doc "Local keymap for `Buffer-menu-mode' buffers."
   :parent tabulated-list-mode-map
@@ -140,9 +146,7 @@ Buffer-menu-mode-map
   "V"           #'Buffer-menu-view
   "O"           #'Buffer-menu-view-other-window
   "T"           #'Buffer-menu-toggle-files-only
-  "M-s a C-s"   #'Buffer-menu-isearch-buffers
-  "M-s a C-M-s" #'Buffer-menu-isearch-buffers-regexp
-  "M-s a C-o"   #'Buffer-menu-multi-occur
+  (key-description search-prefix) Buffer-menu-mode-search-map
   "<mouse-2>"     #'Buffer-menu-mouse-select
   "<follow-link>" 'mouse-face)
 
diff --git a/lisp/dired-aux.el b/lisp/dired-aux.el
index c390017e190..a840a027553 100644
--- a/lisp/dired-aux.el
+++ b/lisp/dired-aux.el
@@ -3537,13 +3537,13 @@ dired-isearch-filenames-setup
   (when (or (eq dired-isearch-filenames t)
 	    (and (eq dired-isearch-filenames 'dwim)
 		 (get-text-property (point) 'dired-filename)))
-    (define-key isearch-mode-map "\M-sff" 'dired-isearch-filenames-mode)
+    (define-key isearch-mode-search-map "ff" 'dired-isearch-filenames-mode)
     (dired-isearch-filenames-mode 1)
     (add-hook 'isearch-mode-end-hook #'dired-isearch-filenames-end nil t)))
 
 (defun dired-isearch-filenames-end ()
   "Clean up the Dired file name search after terminating isearch."
-  (define-key isearch-mode-map "\M-sff" nil)
+  (define-key isearch-mode-search-map "ff" nil)
   (dired-isearch-filenames-mode -1)
   (remove-hook 'isearch-mode-end-hook #'dired-isearch-filenames-end t)
   (unless isearch-suspended
diff --git a/lisp/dired.el b/lisp/dired.el
index 1f7dca802fd..8986fd96bc5 100644
--- a/lisp/dired.el
+++ b/lisp/dired.el
@@ -2130,6 +2130,13 @@ dired-uncache
 \f
 ;;; Dired mode key bindings and menus
 
+(defvar-keymap dired-mode-search-map
+  :doc "Local keymap for search keys in `dired-mode-map'."
+  "a C-s"   #'dired-do-isearch
+  "a C-M-s" #'dired-do-isearch-regexp
+  "f C-s"   #'dired-isearch-filenames
+  "f C-M-s" #'dired-isearch-filenames-regexp)
+
 (defvar-keymap dired-mode-map
   :doc "Local keymap for Dired mode buffers."
   :full t
@@ -2248,10 +2255,7 @@ dired-mode-map
   "M-$"     #'dired-hide-all
   "("       #'dired-hide-details-mode
   ;; isearch
-  "M-s a C-s"   #'dired-do-isearch
-  "M-s a C-M-s" #'dired-do-isearch-regexp
-  "M-s f C-s"   #'dired-isearch-filenames
-  "M-s f C-M-s" #'dired-isearch-filenames-regexp
+  (key-description search-prefix) dired-mode-search-map
   ;; misc
   "<remap> <read-only-mode>"   #'dired-toggle-read-only
   "?"       #'dired-summary
diff --git a/lisp/isearch.el b/lisp/isearch.el
index bb46c89ae20..ef59e103a5c 100644
--- a/lisp/isearch.el
+++ b/lisp/isearch.el
@@ -560,6 +560,21 @@ isearch-menu-bar-commands
   '(isearch-tmm-menubar tmm-menubar menu-bar-open mouse-minor-mode-menu)
   "List of commands that can open a menu during Isearch.")
 
+(defvar-keymap isearch-mode-search-map
+  :doc "Keymap for the M-s prefix keys used during Isearch."
+  ;; More toggles defined by `isearch-define-mode-toggle'.
+  "C-e" #'isearch-yank-line
+  "M-<" #'isearch-beginning-of-buffer
+  "M->" #'isearch-end-of-buffer
+  "e" #'isearch-edit-string
+  "o" #'isearch-occur
+  "h r" #'isearch-highlight-regexp
+  "h l" #'isearch-highlight-lines-matching-regexp)
+
+(put 'isearch-toggle-case-fold :advertised-binding "\M-sc")
+(put 'isearch-toggle-regexp    :advertised-binding "\M-sr")
+(put 'isearch-edit-string      :advertised-binding "\M-se")
+
 ;; Note: Before adding more key bindings to this map, please keep in
 ;; mind that any unbound key exits Isearch and runs the command bound
 ;; to it in the local or global map.  So in effect every key unbound
@@ -618,10 +633,6 @@ isearch-mode-map
     (define-key map "\M-\C-y" 'isearch-yank-char)
     (define-key map    "\C-y" 'isearch-yank-kill)
     (define-key map "\M-\C-z" 'isearch-yank-until-char)
-    (define-key map "\M-s\C-e" 'isearch-yank-line)
-
-    (define-key map "\M-s\M-<" 'isearch-beginning-of-buffer)
-    (define-key map "\M-s\M->" 'isearch-end-of-buffer)
 
     (define-key map (char-to-string help-char) isearch-help-map)
     (define-key map [help] isearch-help-map)
@@ -659,18 +670,10 @@ isearch-mode-map
     (define-key map "\M-r" 'isearch-toggle-regexp)
     (define-key map "\M-e" 'isearch-edit-string)
 
-    (put 'isearch-toggle-case-fold :advertised-binding "\M-sc")
-    (put 'isearch-toggle-regexp    :advertised-binding "\M-sr")
-    (put 'isearch-edit-string      :advertised-binding "\M-se")
-
-    (define-key map "\M-se" 'isearch-edit-string)
-    ;; More toggles defined by `isearch-define-mode-toggle'.
-
     (define-key map [?\M-%] 'isearch-query-replace)
     (define-key map [?\C-\M-%] 'isearch-query-replace-regexp)
-    (define-key map "\M-so" 'isearch-occur)
-    (define-key map "\M-shr" 'isearch-highlight-regexp)
-    (define-key map "\M-shl" 'isearch-highlight-lines-matching-regexp)
+
+    (define-key map search-prefix isearch-mode-search-map)
 
     ;; The key translations defined in the C-x 8 prefix should add
     ;; characters to the search string.  See iso-transl.el.

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* bug#60815: 28.2; Hard-coded M-sff key binding in dired-aux.el
  2023-01-17 19:27                 ` Juri Linkov
@ 2023-01-17 19:44                   ` Evgeni Pandurski
  0 siblings, 0 replies; 11+ messages in thread
From: Evgeni Pandurski @ 2023-01-17 19:44 UTC (permalink / raw)
  To: Juri Linkov; +Cc: 60815

Great! Thanks.

I am not qualified to review your patch, but it seems that it does
exactly what I proposed. I hope what I proposed is not a terribly dumb
idea :)

Also, I am not sure that these are the only modes that "ruthlessly"
override the M-s global binding.

On Tue, Jan 17, 2023 at 9:28 PM Juri Linkov <juri@linkov.net> wrote:
>
> > The problem that remains is that I should do the equivalent of:
> >
> > (define-key isearch-mode-map [f6] isearch-mode-search-map)
> > (define-key isearch-mode-map (kbd "M-s") other-window)
> >
> > for several other minor (and probably some minor modes). To name a
> > few: minibuffer-local-map, Buffer-menu-mode-map, and dired-mode-map
> > all shadow my M-s redefinition, and I can not go to other window in
> > these modes. It would be very nice if those major modes are more
> > clever, clever when overriding global bindings.
>
> This is possible too where you can additionally use
>
>   (setq search-prefix [f6])
>
> If this works, then minibuffer-local-map could be made customizable
> later as well:
>





^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2023-01-17 19:44 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-14 16:44 bug#60815: 28.2; Hard-coded M-sff key binding in dired-aux.el Evgeni Pandurski
2023-01-14 18:14 ` Eli Zaretskii
     [not found]   ` <CA+MLsgOSFS0h45qMpDv3p8WFVpo3oju19uS49RvxfTMAmZRJ5Q@mail.gmail.com>
     [not found]     ` <CA+MLsgOj1qyYT0xrM9kWfTHuo_qxQ6czhGtUtqoc=GYV9Hwf-g@mail.gmail.com>
2023-01-14 18:52       ` Eli Zaretskii
2023-01-17 17:24         ` Juri Linkov
2023-01-17 18:30           ` Evgeni Pandurski
2023-01-17 18:43             ` Eli Zaretskii
     [not found]           ` <CA+MLsgMSDroUBLYfkwcDxyf6=jMSZR0NxZExuWSvrg07+uDrHA@mail.gmail.com>
2023-01-17 18:47             ` Juri Linkov
2023-01-17 19:01               ` Evgeni Pandurski
2023-01-17 19:27                 ` Juri Linkov
2023-01-17 19:44                   ` Evgeni Pandurski
2023-01-14 18:19 ` Juri Linkov

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).