Subject: bug#75530: [PATCH 2/3] Remap read-only-mode for Occur modes

From: Liam Hupfer <[email-masked]>
Date: Sun, 12 Jan 2025 19:00:35 -0600

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        | 7 +++++++
 lisp/replace.el | 2 ++
 2 files changed, 9 insertions(+)

diff --git a/etc/NEWS b/etc/NEWS
index 220730c2cc0..ec9d8b058e1 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -946,6 +946,13 @@ destination window is chosen using 'display-buffer-alist'.  Example:
                                    display-buffer-use-some-window)
                                   (some-window . mru))))
 
+** Occur mode
+
+---
+*** Occur Edit entry and exit points remap 'read-only-mode'.
+Like Wdired, 'read-only-mode' is remapped in 'occur-mode-map' and
+'occur-edit-mode-map' to enter and exit 'occur-edit-mode', respectively.
+
 
 * New Modes and Packages in Emacs 31.1
 
diff --git a/lisp/replace.el b/lisp/replace.el
index cde3686dd12..4db069a1193 100644
--- a/lisp/replace.el
+++ b/lisp/replace.el
@@ -1304,6 +1304,7 @@ occur-mode-map
     (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 @@ occur-edit-mode-map
     (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)
     (bindings--define-key map [menu-bar occur] (cons "Occur" occur-menu-map))
-- 
2.47.1