Subject: bug#57807: 29.0.50; Make vc-print-branch-log able to log multiple branches

From: Sean Whitton <[email-masked]>
Date: Mon, 26 Sep 2022 15:33:22 -0700

Hello,

On Sun 25 Sep 2022 at 10:29AM +03, Juri Linkov wrote:

>>>> I'm running into the problem that you pointed out in another thread.
>>>> How do we apply vc-filter-command-function to the final VC command
>>>> that's to be run without also applying it to intermediate VC commands,
>>>> e.g. in vc-read-revision?
>>>
>>> Maybe there is no problem to apply the editing filter to all commands,
>>> I don't know.  First need to try to see how it really works.
>>
>> Here's the WIP patch, hopefully it works well enough for testing.
>
> Thanks, I'm going to try it out.

It looks like I need to call (minibuffer-depth) like
display-buffer-override-next-command does.  Updated patch attached.

>> I think it's considerably worse than C-u C-x v b l tbh.
>
> Undoubtedly, it's worse.  But it solves the problem that
> all vc commands can't use C-u.

Just to be clear, the thing that I think is much worse is being prompted
for multiple intermediate commands, not the longer key sequence.

I realised that we could add an override inside vc-read-revision, and
potentially other places, which makes it considerably less annoying.
Done in the attached.

-- 
Sean Whitton
>From 7115ae59cf5f263dbc1b1a208fce974d790d8cae Mon Sep 17 00:00:00 2001
From: Sean Whitton <[email-masked]>
Date: Sat, 24 Sep 2022 16:17:56 -0700
Subject: [PATCH v2] WIP Add vc-edit-next-command.

---
 lisp/vc/vc-hooks.el |  3 ++-
 lisp/vc/vc.el       | 34 ++++++++++++++++++++++++++++++++--
 2 files changed, 34 insertions(+), 3 deletions(-)

diff --git a/lisp/vc/vc-hooks.el b/lisp/vc/vc-hooks.el
index 7f0d9e4d86..6ad26cfe67 100644
--- a/lisp/vc/vc-hooks.el
+++ b/lisp/vc/vc-hooks.el
@@ -882,7 +882,8 @@ vc-prefix-map
   "="   #'vc-diff
   "D"   #'vc-root-diff
   "~"   #'vc-revision-other-window
-  "x"   #'vc-delete-file)
+  "x"   #'vc-delete-file
+  "!"   #'vc-edit-next-command)
 (fset 'vc-prefix-map vc-prefix-map)
 (define-key ctl-x-map "v" 'vc-prefix-map)
 
diff --git a/lisp/vc/vc.el b/lisp/vc/vc.el
index 4950a1a32d..76554d2340 100644
--- a/lisp/vc/vc.el
+++ b/lisp/vc/vc.el
@@ -1918,8 +1918,11 @@ vc-read-revision
       (setq files (cadr vc-fileset))
       (setq backend (car vc-fileset))))
    ((null backend) (setq backend (vc-backend (car files)))))
-  (let ((completion-table
-         (vc-call-backend backend 'revision-completion-table files)))
+  ;; Override any `vc-filter-command-function' value, as user probably
+  ;; doesn't want to edit the command to get the completions.
+  (let* ((vc-filter-command-function #'list)
+         (completion-table
+          (vc-call-backend backend 'revision-completion-table files)))
     (if completion-table
         (completing-read prompt completion-table
                          nil nil initial-input 'vc-revision-history default)
@@ -3244,6 +3247,33 @@ vc-update-change-log
   (vc-call-backend (vc-responsible-backend default-directory)
                    'update-changelog args))
 
+(defvar vc-filter-command-function)
+
+;;;###autoload
+(defun vc-edit-next-command ()
+  "Request editing the next VC shell command before execution.
+This is a prefix command.  It affects only a VC command executed
+immediately after this one."
+  (interactive)
+  (letrec ((minibuffer-depth (minibuffer-depth))
+           (command this-command)
+           (keys (key-description (this-command-keys)))
+           (old vc-filter-command-function)
+           (echofun (lambda () keys))
+           (postfun
+            (lambda ()
+              (unless (or (eq this-command command)
+                          (> (minibuffer-depth) minibuffer-depth))
+                (remove-hook 'post-command-hook postfun)
+                (remove-hook 'prefix-command-echo-keystrokes-functions
+                             echofun)
+                (setq vc-filter-command-function old)))))
+    (add-hook 'post-command-hook postfun)
+    (add-hook 'prefix-command-echo-keystrokes-functions echofun)
+    (setq vc-filter-command-function
+          (lambda (&rest args)
+            (apply #'vc-user-edit-command (apply old args))))))
+
 (defun vc-default-responsible-p (_backend _file)
   "Indicate whether BACKEND is responsible for FILE.
 The default is to return nil always."
-- 
2.30.2