Subject: bug#75530: [PATCH v2.1 0/3] Consistently remap read-only-mode for special edit modes

From: Liam Hupfer <[email-masked]>
Date: Mon, 3 Feb 2025 22:10:03 -0600

v2.1 is v2 but in a single email per Eli’s preference. Apparently
git-send-email(1) doesn’t expose a way to create a single email with
multiple patches as MIME attachments, but the --output and --no-thread
options are sufficient to generate one long message that applies cleanly
with ‘git am --empty=drop’.

Thanks!

Liam Hupfer (3):
  Remap read-only-mode in wdired-mode-map (bug#75530)
  Remap read-only-mode for Occur modes (bug#75530)
  Remap read-only-mode for Grep Edit (bug#75530)

 etc/NEWS               | 23 +++++++++++++++++++----
 lisp/progmodes/grep.el |  6 ++++--
 lisp/replace.el        |  2 ++
 lisp/wdired.el         |  2 +-
 4 files changed, 26 insertions(+), 7 deletions(-)

base-commit: c4a67a405072601b9d7dd95dc94c0b402e1e0ae6
-- 
2.47.1

>From 551fcce44e2ea235cdae8da3d9afefe5e7a0a9b5 Mon Sep 17 00:00:00 2001
From: Liam Hupfer <[email-masked]>
Date: Sun, 12 Jan 2025 12:24:38 -0600
Subject: [PATCH v2.1 1/3] Remap read-only-mode in wdired-mode-map (bug#75530)

dired-mode-map already remaps read-only-mode to dired-toggle-read-only.
Make wdired-mode-map remap as well, instead of hardcoding the default
C-x C-q.

* lisp/wdired.el (wdired-mode-map): Remap read-only-mode to wdired-exit.
* etc/NEWS (Dired): Document remap.
---
 etc/NEWS       | 6 ++++++
 lisp/wdired.el | 2 +-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/etc/NEWS b/etc/NEWS
index 8cf86d1375d..6893d71268a 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -892,6 +892,12 @@ Without 'dired-hide-details-hide-absolute-location':
 When 'dired-make-directory-clickable' is non-nil, clicking on the base
 name of the directory now reverts the Dired buffer.
 
+---
+*** 'wdired-exit' binding now respects user 'read-only-mode' bindings.
+If you add or change bindings for 'read-only-mode', 'wdired-exit' will
+respect those bindings.  Previously, it used a fixed 'C-x C-q' binding
+regardless of 'read-only-mode' bindings.
+
 ** Grep
 
 +++
diff --git a/lisp/wdired.el b/lisp/wdired.el
index c7409446b19..78d0c7e0716 100644
--- a/lisp/wdired.el
+++ b/lisp/wdired.el
@@ -160,7 +160,7 @@ nonexistent directory will fail."
   "C-c C-c" #'wdired-finish-edit
   "C-c C-k" #'wdired-abort-changes
   "C-c C-[" #'wdired-abort-changes
-  "C-x C-q" #'wdired-exit
+  "<remap> <read-only-mode>" #'wdired-exit
   "RET"     #'undefined
   "C-j"     #'undefined
   "C-o"     #'undefined
-- 
2.47.1

>From 5fe91fc4cb5deebc38d8fca3d4ebda935cfe9e58 Mon Sep 17 00:00:00 2001
From: Liam Hupfer <[email-masked]>
Date: Sun, 12 Jan 2025 12:31:17 -0600
Subject: [PATCH v2.1 2/3] Remap read-only-mode for Occur modes (bug#75530)

occur-edit-mode behaves similarly to wdired-mode.  Dired remaps
read-only-mode to toggle wdired, so set up similar remaps for
occur-mode-map and occur-edit-mode-map.

* lisp/replace.el (occur-mode-map): Remap read-only-mode to
occur-edit-mode.
(occur-edit-mode-map): Remap read-only-mode to occur-cease-edit.
* etc/NEWS (Occur mode): Document Occur Edit entry/exit remaps.
---
 etc/NEWS        | 8 ++++++++
 lisp/replace.el | 2 ++
 2 files changed, 10 insertions(+)

diff --git a/etc/NEWS b/etc/NEWS
index 6893d71268a..ce78759849c 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1082,6 +1082,14 @@ destination window is chosen using 'display-buffer-alist'.  Example:
                                    display-buffer-use-some-window)
                                   (some-window . mru))))
 
+** Occur mode
+
+---
+*** New Occur Edit entry and exit based on 'read-only-mode' bindings.
+In addition to entering 'occur-edit-mode' with 'e' and exiting with 'C-c
+C-c', you can now use 'C-x C-q' (or anywhere you bind 'read-only-mode')
+for entry and exit.
+
 
 * New Modes and Packages in Emacs 31.1
 
diff --git a/lisp/replace.el b/lisp/replace.el
index 3bd803ce347..724e54f256b 100644
--- a/lisp/replace.el
+++ b/lisp/replace.el
@@ -1304,6 +1304,7 @@ a previously found match."
     (define-key map [mouse-2] 'occur-mode-mouse-goto)
     (define-key map "\C-c\C-c" 'occur-mode-goto-occurrence)
     (define-key map "e" 'occur-edit-mode)
+    (define-key map [remap read-only-mode] 'occur-edit-mode)
     (define-key map "\C-m" 'occur-mode-goto-occurrence)
     (define-key map "o" 'occur-mode-goto-occurrence-other-window)
     (define-key map "\C-o" 'occur-mode-display-occurrence)
@@ -1366,6 +1367,7 @@ Alternatively, click \\[occur-mode-mouse-goto] on an item to go to it.
     (set-keymap-parent map text-mode-map)
     (define-key map [mouse-2] 'occur-mode-mouse-goto)
     (define-key map "\C-c\C-c" 'occur-cease-edit)
+    (define-key map [remap read-only-mode] 'occur-cease-edit)
     (define-key map "\C-o" 'occur-mode-display-occurrence)
     (define-key map "\C-c\C-f" 'next-error-follow-minor-mode)
     (define-key map [menu-bar occur] (cons "Occur" occur-menu-map))
-- 
2.47.1

>From b1b4dc4816acb7a8727129c74fd1c9ce3538fa89 Mon Sep 17 00:00:00 2001
From: Liam Hupfer <[email-masked]>
Date: Sun, 12 Jan 2025 17:16:13 -0600
Subject: [PATCH v2.1 3/3] Remap read-only-mode for Grep Edit (bug#75530)

Like Dired and Occur, Grep buffers now remap read-only-mode to a useful
editing mode.

* lisp/progmodes/grep.el (grep-mode-map): Remap read-only-mode to
grep-change-to-grep-edit-mode.
(grep-edit-mode-map): Remap read-only-mode to grep-edit-save-changes.
* etc/NEWS (Grep): Document remaps.
---
 etc/NEWS               | 9 +++++----
 lisp/progmodes/grep.el | 6 ++++--
 2 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index ce78759849c..45fff54f433 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -902,10 +902,11 @@ regardless of 'read-only-mode' bindings.
 
 +++
 *** Grep results can be edited to reflect changes in the originating file.
-Like Occur Edit mode, typing 'e' in the "*grep*" buffer will now make
-the 'grep' results editable.  The edits will be reflected in the buffer
-visiting the originating file.  Typing 'C-c C-c' will leave the Grep
-Edit mode.
+Like Occur Edit mode, typing 'e' or 'C-x C-q' (or your own
+'read-only-mode' binding) in the "*grep*" buffer will now make the
+'grep' results editable.  The edits will be reflected in the buffer
+visiting the originating file.  Typing 'C-c C-c' or 'C-x C-q' (or your
+own 'read-only-mode' binding) will leave the Grep Edit mode.
 
 ** time-stamp
 
diff --git a/lisp/progmodes/grep.el b/lisp/progmodes/grep.el
index d04e9945b0d..b29f56c9ed4 100644
--- a/lisp/progmodes/grep.el
+++ b/lisp/progmodes/grep.el
@@ -312,7 +312,8 @@ This keymap inherits from `compilation-minor-mode-map'."
   "TAB"       #'compilation-next-error
   "<backtab>" #'compilation-previous-error
 
-  "e"         #'grep-change-to-grep-edit-mode)
+  "e"         #'grep-change-to-grep-edit-mode
+  "<remap> <read-only-mode>" #'grep-change-to-grep-edit-mode)
 
 (easy-menu-define grep-menu-map grep-mode-map
   "Menu for grep buffers."
@@ -1083,7 +1084,8 @@ list is empty)."
 (defvar-keymap grep-edit-mode-map
   :doc "Keymap for `grep-edit-mode'."
   :parent text-mode-map
-  "C-c C-c" #'grep-edit-save-changes)
+  "C-c C-c" #'grep-edit-save-changes
+  "<remap> <read-only-mode>" #'grep-edit-save-changes)
 
 (defvar grep-edit-mode-hook nil
   "Hooks run when changing to Grep-Edit mode.")
-- 
2.47.1