Subject: bug#43503: Patch: Improvements regarding commands like find-file-other-tab.

From: [email-masked]
Date: Fri, 18 Sep 2020 21:41:41 +0000

Hello.

This is what the patch does:

1. Document existing command `ffap-other-tab'.
2. Create `find-file-read-only-other-tab' and `ffap-read-only-other-tab'.
3. Bind "\C-r" to `find-file-read-only-other-tab', like how "\C-f" is
    bound to `find-file-other-tab'.
4. Document `ffap-read-only-other-tab' in misc.texi.

I don't really know the Texinfo format, so I just copied the mark-up used for 
other items.

Is there anything that should be changed?

Thank you.

From cb079bfa57694d529bee0fac0a38c68600c33a8e Mon Sep 17 00:00:00 2001
From: Earl <>
Date: Wed, 16 Sep 2020 17:07:58 -0400
Subject: [PATCH] Improvements regarding like find-file-other-tab.

1. Document existing command `ffap-other-tab'.
2. Create find-file-read-only-other-tab and ffap-read-only-other-tab.
3. Bind "\C-r" to find-file-read-only-other-tab, like how "\C-f" is
   bound to find-file-other-tab.
4. Document ffap-read-only-other-tab in misc.texi.
---
 doc/emacs/misc.texi |  5 +++++
 lisp/ffap.el        |  8 ++++++++
 lisp/tab-bar.el     | 15 +++++++++++++++
 3 files changed, 28 insertions(+)

diff --git a/doc/emacs/misc.texi b/doc/emacs/misc.texi
index c8b21e701c..4865ee1751 100644
--- a/doc/emacs/misc.texi
+++ b/doc/emacs/misc.texi
@@ -3028,6 +3028,11 @@ FFAP
 @code{find-file-read-only-other-frame}.
 @item C-x 5 d @var{directory} @key{RET}
 @code{ffap-dired-other-frame}, analogous to @code{dired-other-frame}.
+@kindex C-x t C-f @r{(FFAP)}
+@item C-x t C-f @var{filename} @key{return}
+@code{ffap-other-tab}, analogous to @code{find-file-other-tab}.
+@item C-x t C-r @var{filename} @key{return}
+@code{ffap-read-only-other-tab}, analogous to @code{find-file-read-only-other-tab}.
 @item M-x ffap-next
 Search buffer for next file name or URL, then find that file or URL.
 @item S-mouse-3
diff --git a/lisp/ffap.el b/lisp/ffap.el
index 3e65c687af..29883693a7 100644
--- a/lisp/ffap.el
+++ b/lisp/ffap.el
@@ -1926,6 +1926,14 @@ ffap-read-only-other-frame
     (ffap--toggle-read-only value)
     value))
 
+(defun ffap-read-only-other-tab (filename)
+  "Like `ffap', but put buffer in another tab and mark as read-only.
+Only intended for interactive use."
+  (interactive (list (ffap-prompter nil " other tab")))
+  (let ((value (window-buffer (ffap-other-tab filename))))
+    (ffap--toggle-read-only value)
+    value))
+
 (defun ffap-alternate-file (filename)
   "Like `ffap' and `find-alternate-file'.
 Only intended for interactive use."
diff --git a/lisp/tab-bar.el b/lisp/tab-bar.el
index d8f932e7a4..840c67d5cc 100644
--- a/lisp/tab-bar.el
+++ b/lisp/tab-bar.el
@@ -1567,6 +1567,20 @@ find-file-other-tab
           value)
       (switch-to-buffer-other-tab value))))
 
+(defun find-file-read-only-other-tab (filename &optional wildcards)
+  "Edit file FILENAME, in another tab, but don't allow changes.
+Like \\[find-file-other-frame] (which see), but creates a new tab.
+
+Like C-x t C-f, but marks buffer as read-only.
+Use C-x C-q to permit editing."
+  (interactive
+   (find-file-read-args "Find file read-only in other tab: "
+                        (confirm-nonexistent-file-or-buffer)))
+  (find-file--read-only (lambda (filename wildcards)
+                          (window-buffer
+                           (find-file-other-tab filename wildcards)))
+                        filename wildcards))
+
 (defun other-tab-prefix ()
   "Display the buffer of the next command in a new tab.
 The next buffer is the buffer displayed by the next command invoked
@@ -1596,6 +1610,7 @@ tab-prefix-map
 (define-key tab-prefix-map "b" 'switch-to-buffer-other-tab)
 (define-key tab-prefix-map "f" 'find-file-other-tab)
 (define-key tab-prefix-map "\C-f" 'find-file-other-tab)
+(define-key tab-prefix-map "\C-r" 'find-file-read-only-other-tab)
 (define-key tab-prefix-map "t" 'other-tab-prefix)
 
 
-- 
2.25.1