bug-gnu-emacs
[Top][All Lists]
Advanced

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

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


From: Juri Linkov
Subject: bug#60815: 28.2; Hard-coded M-sff key binding in dired-aux.el
Date: Tue, 17 Jan 2023 20:47:32 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/30.0.50 (x86_64-pc-linux-gnu)

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.

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.

reply via email to

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