Subject: bug#65387: [PATCH] New user option 'submit-emacs-patch-display-help'

From: Eshel Yaron <[email-masked]>
Date: Sun, 20 Aug 2023 13:35:56 +0200

Daniel Martín <[email-masked]> writes:

> Instead of just a toggle, we could make the new option a tristate:
>
> - `nil`: Only displays the buffer to compose the email (what is proposed in
>   this bug report).
> - `help`: Displays instructions on how to send the patch (current
>   behavior).  
> - `patch`: Displays the patch that you want to submit in the split
>   window.

Good idea, thanks.  I've added something like that in the following
updated patch:

>From 10c943cbf340255d0577a03fe4b3d74af840a9e2 Mon Sep 17 00:00:00 2001
From: Eshel Yaron <[email-masked]>
Date: Sat, 19 Aug 2023 21:24:34 +0200
Subject: [PATCH v2] New user option 'submit-emacs-patch-display-help'

This lets users prevent 'submit-emacs-patch' from displaying a buffer
with instructions about submitting patches when they no longer need it.

* lisp/mail/emacsbug.el (submit-emacs-patch-display-help): New user
option.
(submit-emacs-patch): Use it.
* doc/emacs/trouble.texi (Sending Patches): Document it.
* etc/NEWS: Announce it.
---
 doc/emacs/trouble.texi |  9 +++++++
 etc/NEWS               |  7 ++++++
 lisp/mail/emacsbug.el  | 54 ++++++++++++++++++++++++++----------------
 3 files changed, 50 insertions(+), 20 deletions(-)

diff --git a/doc/emacs/trouble.texi b/doc/emacs/trouble.texi
index d2e8ac3452a..042637ed8fc 100644
--- a/doc/emacs/trouble.texi
+++ b/doc/emacs/trouble.texi
@@ -1336,6 +1336,15 @@ Sending Patches
 form that is clearly safe to install.
 @end itemize
 
+@vindex submit-emacs-patch-display-help
+By default, @kbd{M-x submit-emacs-patch} displays a buffer with some
+instructions alongside the Message mode buffer.  If you're already
+familiar with these instructions after submitting a patch or two, you
+can disable this help by customizing the user option
+@code{submit-emacs-patch-display-help} to @code{nil}.  If you set this
+option to @code{patch}, Emacs displays the patch you're about to
+submit instead of the instructions buffer.
+
 @node Contributing
 @section Contributing to Emacs Development
 @cindex contributing to Emacs
diff --git a/etc/NEWS b/etc/NEWS
index 6588299c532..5ea8a204522 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -99,6 +99,13 @@ This allows the user to customize the prompt that is appended by
 'yes-or-no-p' when asking questions.  The default value is
 "(yes or no) ".
 
++++
+** New user option 'submit-emacs-patch-display-help'.
+You can set this user option to nil to prevent 'submit-emacs-patch'
+from displaying a help buffer with instructions for submitting
+patches.  If you set this option to 'patch', Emacs displays the patch
+you're about to submit instead of the instructions buffer.
+
 ---
 ** New face 'display-time-date-and-time'.
 This is used for displaying the time and date components of
diff --git a/lisp/mail/emacsbug.el b/lisp/mail/emacsbug.el
index bebaad720db..b93aed47bac 100644
--- a/lisp/mail/emacsbug.el
+++ b/lisp/mail/emacsbug.el
@@ -50,6 +50,17 @@ report-emacs-bug-no-explanations
   "If non-nil, suppress the explanations given for the sake of novice users."
   :type 'boolean)
 
+(defcustom submit-emacs-patch-display-help t
+  "Whether `submit-emacs-patch' displays help in another buffer.
+
+If nil, display only the message buffer without additional help.  If this is
+the symbol `patch', display the patch you are submitting in another buffer.
+Any other value says to display a buffer with instructions for submitting
+patches (this is the default for the sake of novice users)."
+  :type '(choice (const :tag "Do not display help" nil)
+		 (const :tag "Display instructions" t)
+		 (const :tag "Display patch" patch)))
+
 ;; User options end here.
 
 (defvar report-emacs-bug-orig-text nil
@@ -509,26 +520,29 @@ submit-emacs-patch
      (list (read-string (format-prompt "This patch is about" guess)
                         nil nil guess)
            file)))
-  (switch-to-buffer "*Patch Help*")
-  (let ((inhibit-read-only t))
-    (erase-buffer)
-    (insert "Thank you for considering submitting a patch to the Emacs project.\n\n"
-            "Please describe what the patch fixes (or, if it's a new feature, what it\n"
-            "implements) in the mail buffer below.  When done, use the "
-            (substitute-command-keys "\\<message-mode-map>\\[message-send-and-exit] command\n")
-            "to send the patch as an email to the Emacs issue tracker.\n\n"
-            "If this is the first time you're submitting an Emacs patch, please\n"
-            "read the ")
-    (insert-text-button
-     "CONTRIBUTE"
-     'action (lambda (_)
-               (view-buffer
-                (find-file-noselect
-                 (expand-file-name "CONTRIBUTE" installation-directory)))))
-    (insert " file first.\n")
-    (goto-char (point-min))
-    (view-mode 1)
-    (button-mode 1))
+  (pcase submit-emacs-patch-display-help
+    ('patch (find-file file))
+    ((pred (not null))
+     (switch-to-buffer "*Patch Help*")
+     (let ((inhibit-read-only t))
+       (erase-buffer)
+       (insert "Thank you for considering submitting a patch to the Emacs project.\n\n"
+               "Please describe what the patch fixes (or, if it's a new feature, what it\n"
+               "implements) in the mail buffer below.  When done, use the "
+               (substitute-command-keys "\\<message-mode-map>\\[message-send-and-exit] command\n")
+               "to send the patch as an email to the Emacs issue tracker.\n\n"
+               "If this is the first time you're submitting an Emacs patch, please\n"
+               "read the ")
+       (insert-text-button
+        "CONTRIBUTE"
+        'action (lambda (_)
+                  (view-buffer
+                   (find-file-noselect
+                    (expand-file-name "CONTRIBUTE" installation-directory)))))
+       (insert " file first.\n")
+       (goto-char (point-min))
+       (view-mode 1)
+       (button-mode 1))))
   (compose-mail-other-window report-emacs-bug-address subject)
   (message-goto-body)
   (insert "\n\n\n")
-- 
2.41.0