GNU bug report logs - #60815
28.2; Hard-coded M-sff key binding in dired-aux.el

Previous Next

Package: emacs;

Reported by: Evgeni Pandurski <epandurski <at> gmail.com>

Date: Sat, 14 Jan 2023 17:38:02 UTC

Severity: normal

Found in version 28.2

Done: Evgeni Pandurski <epandurski <at> gmail.com>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 60815 in the body.
You can then email your comments to 60815 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#60815; Package emacs. (Sat, 14 Jan 2023 17:38:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Evgeni Pandurski <epandurski <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Sat, 14 Jan 2023 17:38:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Evgeni Pandurski <epandurski <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 28.2; Hard-coded M-sff key binding in dired-aux.el
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.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#60815; Package emacs. (Sat, 14 Jan 2023 18:15:02 GMT) Full text and rfc822 format available.

Message #8 received at 60815 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Evgeni Pandurski <epandurski <at> gmail.com>
Cc: 60815 <at> debbugs.gnu.org
Subject: Re: bug#60815: 28.2; Hard-coded M-sff key binding in dired-aux.el
Date: Sat, 14 Jan 2023 20:14:40 +0200
> From: Evgeni Pandurski <epandurski <at> 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.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#60815; Package emacs. (Sat, 14 Jan 2023 18:22:01 GMT) Full text and rfc822 format available.

Message #11 received at 60815 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: Evgeni Pandurski <epandurski <at> gmail.com>
Cc: 60815 <at> debbugs.gnu.org
Subject: Re: bug#60815: 28.2; Hard-coded M-sff key binding in dired-aux.el
Date: Sat, 14 Jan 2023 20:19:57 +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.

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
```




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#60815; Package emacs. (Sat, 14 Jan 2023 18:53:02 GMT) Full text and rfc822 format available.

Message #14 received at 60815 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Evgeni Pandurski <epandurski <at> gmail.com>
Cc: 60815 <at> debbugs.gnu.org
Subject: Re: bug#60815: 28.2; Hard-coded M-sff key binding in dired-aux.el
Date: Sat, 14 Jan 2023 20:52:06 +0200
> From: Evgeni Pandurski <epandurski <at> 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.




Reply sent to Juri Linkov <juri <at> linkov.net>:
You have taken responsibility. (Tue, 17 Jan 2023 17:35:04 GMT) Full text and rfc822 format available.

Notification sent to Evgeni Pandurski <epandurski <at> gmail.com>:
bug acknowledged by developer. (Tue, 17 Jan 2023 17:35:04 GMT) Full text and rfc822 format available.

Message #19 received at 60815-done <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: Evgeni Pandurski <epandurski <at> gmail.com>, 60815-done <at> debbugs.gnu.org
Subject: Re: bug#60815: 28.2; Hard-coded M-sff key binding in dired-aux.el
Date: Tue, 17 Jan 2023 19:24:10 +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.

Then I guess this report can be closed, done.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#60815; Package emacs. (Tue, 17 Jan 2023 18:44:02 GMT) Full text and rfc822 format available.

Message #22 received at 60815 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Evgeni Pandurski <epandurski <at> gmail.com>
Cc: 60815 <at> debbugs.gnu.org, juri <at> linkov.net
Subject: Re: bug#60815: 28.2; Hard-coded M-sff key binding in dired-aux.el
Date: Tue, 17 Jan 2023 20:43:57 +0200
> From: Evgeni Pandurski <epandurski <at> gmail.com>
> Date: Tue, 17 Jan 2023 20:30:23 +0200
> Cc: Eli Zaretskii <eliz <at> gnu.org>, 60815-done <at> 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.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#60815; Package emacs. (Tue, 17 Jan 2023 18:50:02 GMT) Full text and rfc822 format available.

Message #25 received at 60815 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: Evgeni Pandurski <epandurski <at> gmail.com>
Cc: 60815 <at> debbugs.gnu.org
Subject: Re: bug#60815: 28.2; Hard-coded M-sff key binding in dired-aux.el
Date: Tue, 17 Jan 2023 20:47:32 +0200
[Message part 1 (text/plain, inline)]
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.

[isearch-mode-search-map.patch (text/x-diff, inline)]
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.

Did not alter fixed versions and reopened. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Tue, 17 Jan 2023 18:50:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#60815; Package emacs. (Tue, 17 Jan 2023 19:29:02 GMT) Full text and rfc822 format available.

Message #30 received at 60815 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: Evgeni Pandurski <epandurski <at> gmail.com>
Cc: 60815 <at> debbugs.gnu.org
Subject: Re: bug#60815: 28.2; Hard-coded M-sff key binding in dired-aux.el
Date: Tue, 17 Jan 2023 21:27:15 +0200
[Message part 1 (text/plain, inline)]
> 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:

[search-prefix.patch (text/x-diff, inline)]
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
 
 ;;; 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.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#60815; Package emacs. (Wed, 18 Jan 2023 01:48:02 GMT) Full text and rfc822 format available.

Message #33 received at 60815 <at> debbugs.gnu.org (full text, mbox):

From: Evgeni Pandurski <epandurski <at> gmail.com>
To: Juri Linkov <juri <at> linkov.net>
Cc: 60815 <at> debbugs.gnu.org
Subject: Re: bug#60815: 28.2; Hard-coded M-sff key binding in dired-aux.el
Date: Tue, 17 Jan 2023 21:01:43 +0200
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 <at> 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.
>




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#60815; Package emacs. (Wed, 18 Jan 2023 01:48:02 GMT) Full text and rfc822 format available.

Message #36 received at 60815 <at> debbugs.gnu.org (full text, mbox):

From: Evgeni Pandurski <epandurski <at> gmail.com>
To: Juri Linkov <juri <at> linkov.net>
Cc: 60815 <at> debbugs.gnu.org
Subject: Re: bug#60815: 28.2; Hard-coded M-sff key binding in dired-aux.el
Date: Tue, 17 Jan 2023 21:44:01 +0200
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 <at> 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:
>




Reply sent to Evgeni Pandurski <epandurski <at> gmail.com>:
You have taken responsibility. (Wed, 18 Jan 2023 01:48:03 GMT) Full text and rfc822 format available.

Notification sent to Evgeni Pandurski <epandurski <at> gmail.com>:
bug acknowledged by developer. (Wed, 18 Jan 2023 01:48:03 GMT) Full text and rfc822 format available.

Message #41 received at 60815-done <at> debbugs.gnu.org (full text, mbox):

From: Evgeni Pandurski <epandurski <at> gmail.com>
To: Juri Linkov <juri <at> linkov.net>
Cc: Eli Zaretskii <eliz <at> gnu.org>, 60815-done <at> debbugs.gnu.org
Subject: Re: bug#60815: 28.2; Hard-coded M-sff key binding in dired-aux.el
Date: Tue, 17 Jan 2023 20:30:23 +0200
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 <at> 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.




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Wed, 15 Feb 2023 12:24:06 GMT) Full text and rfc822 format available.

This bug report was last modified 1 year and 64 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.