Subject: bug#52518: Log only vc-command-messages

From: Juri Linkov <[email-masked]>
Date: Wed, 15 Dec 2021 19:31:07 +0200

Tags: patch

It's useful to customize vc-command-messages to t
to be able to inspect the performed vc commands
in the *Messages* buffer.  When something goes wrong,
it's clearly visible what command caused the problem.

But displaying such all vc commands in the echo area
causes too much noise.  Here is an option to not
display such messages, only log in the *Messages* buffer:

diff --git a/lisp/vc/vc-dispatcher.el b/lisp/vc/vc-dispatcher.el
index 346974bdba..894ca060eb 100644
--- a/lisp/vc/vc-dispatcher.el
+++ b/lisp/vc/vc-dispatcher.el
@@ -127,8 +127,12 @@ vc-delete-logbuf-window
   :group 'vc)
 
 (defcustom vc-command-messages nil
-  "If non-nil, display run messages from back-end commands."
-  :type 'boolean
+  "If non-nil, log run messages from back-end commands.
+If `log', messages are logged to the *Messages* buffer, but not displayed.
+Other non-nil values also display run messages in the echo area."
+  :type '(choice (const :tag "No display and no log" nil)
+                 (const :tag "Display and log messages" t)
+                 (const :tag "Only log messages without displaying" log))
   :group 'vc)
 
 (defcustom vc-suppress-confirm nil
@@ -335,7 +339,9 @@ vc-do-command
 		       (apply #'start-file-process command (current-buffer)
                               command squeezed))))
 		(when vc-command-messages
-		  (let ((inhibit-message (eq (selected-window) (active-minibuffer-window))))
+		  (let ((inhibit-message
+			 (or (eq vc-command-messages 'log)
+			     (eq (selected-window) (active-minibuffer-window)))))
 		    (message "Running in background: %s" full-command)))
                 ;; Get rid of the default message insertion, in case we don't
                 ;; set a sentinel explicitly.
@@ -345,11 +351,15 @@ vc-do-command
 		(when vc-command-messages
 		  (vc-run-delayed
 		    (let ((message-truncate-lines t)
-			  (inhibit-message (eq (selected-window) (active-minibuffer-window))))
+			  (inhibit-message
+			   (or (eq vc-command-messages 'log)
+			       (eq (selected-window) (active-minibuffer-window)))))
 		      (message "Done in background: %s" full-command)))))
 	    ;; Run synchronously
 	    (when vc-command-messages
-	      (let ((inhibit-message (eq (selected-window) (active-minibuffer-window))))
+	      (let ((inhibit-message
+		     (or (eq vc-command-messages 'log)
+			 (eq (selected-window) (active-minibuffer-window)))))
 		(message "Running in foreground: %s" full-command)))
 	    (let ((buffer-undo-list t))
 	      (setq status (apply #'process-file command nil t nil squeezed)))
@@ -364,7 +374,9 @@ vc-do-command
 		     (if (integerp status) (format "status %d" status) status)
 		     full-command))
 	    (when vc-command-messages
-	      (let ((inhibit-message (eq (selected-window) (active-minibuffer-window))))
+	      (let ((inhibit-message
+		     (or (eq vc-command-messages 'log)
+			 (eq (selected-window) (active-minibuffer-window)))))
 		(message "Done (status=%d): %s" status full-command)))))
 	(vc-run-delayed
 	  (run-hook-with-args 'vc-post-command-functions