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

From: Liam Hupfer <[email-masked]>
Date: Sun, 2 Feb 2025 18:12:46 -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        | 8 ++++++++
 lisp/replace.el | 2 ++
 2 files changed, 10 insertions(+)

diff --git a/etc/NEWS b/etc/NEWS
index 188aaaf6e5b..f25e8b2fe87 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1058,6 +1058,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