Subject: Re: bug#41779: Fall back between vc-diff and diff-backup

From: Juri Linkov <[email-masked]>
Date: Thu, 25 Jun 2020 02:32:32 +0300

tags 41779 wontfix
close 41779 28.0.50
quit

>> But I don't insist on this feature, I can handle this in my init file.
>> I proposed it as a patch only because Lars mentioned the same problem.
>
> I think my suggestion is not significantly worse or more awkward to use.

It seems my request was too specific, so I retract it.
It's easy to achieve this fallback in the init file with:

(advice-add 'diff-backup :around
            (lambda (orig-fun file &optional switches)
              (condition-case err
                  (funcall orig-fun file switches)
                (error
                 ;; Fall back to vc-diff
                 (if (vc-backend file)
                     (let ((vc-diff-switches switches))
                       (require 'vc)
                       (vc-diff-internal
                        t (list (vc-backend file) (list file)) nil nil t))
                   (error (cadr err))))))
            '((name . diff-backup-fallback-to-vc-diff)))

(advice-add 'vc-diff :around
            (lambda (orig-fun &rest args)
              (if (vc-deduce-backend)
                  (apply orig-fun args)
                ;; Fall back to non-vc diff-backup
                (diff-backup (if (derived-mode-p 'dired-mode)
                                 (dired-get-filename)
                               buffer-file-name)
                             vc-diff-switches)))
            '((name . vc-diff-fallback-to-diff-backup)))