From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.bugs Subject: bug#41779: Fall back between vc-diff and diff-backup Date: Wed, 10 Jun 2020 02:35:48 +0300 Message-ID: <87mu5b24ob.fsf_-_@mail.linkov.net> References: <505E43E1.9090801@yandex.ru> <505E4A57.5020305@yandex.ru> <871rzer8t2.fsf@mail.linkov.net> <8d51a8c9-6200-84c9-cadb-09576b060fe1@yandex.ru> <87o92h7fv1.fsf@mail.linkov.net> <878stissii.fsf@mail.linkov.net> <87muhtzh8z.fsf@mail.linkov.net> <4538945a-4a47-e8a2-7c3b-485f229c0a98@yandex.ru> <871rz4qpni.fsf@mail.linkov.net> <87v9wdzc3g.fsf@mail.linkov.net> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="112650"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (x86_64-pc-linux-gnu) To: 41779@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Jun 10 01:40:20 2020 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jinqu-000TH6-LW for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 10 Jun 2020 01:40:20 +0200 Original-Received: from localhost ([::1]:50978 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jinqt-0000Sg-Lb for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 09 Jun 2020 19:40:19 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:56812) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jinqc-0000S4-SL for bug-gnu-emacs@gnu.org; Tue, 09 Jun 2020 19:40:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:49664) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jinqc-0001uO-Fx for bug-gnu-emacs@gnu.org; Tue, 09 Jun 2020 19:40:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1jinqc-0007cJ-Cx for bug-gnu-emacs@gnu.org; Tue, 09 Jun 2020 19:40:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 09 Jun 2020 23:40:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 41779 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.159174599729261 (code B ref -1); Tue, 09 Jun 2020 23:40:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 9 Jun 2020 23:39:57 +0000 Original-Received: from localhost ([127.0.0.1]:32977 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jinqW-0007bt-M5 for submit@debbugs.gnu.org; Tue, 09 Jun 2020 19:39:56 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:53208) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jinqV-0007bk-69 for submit@debbugs.gnu.org; Tue, 09 Jun 2020 19:39:55 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:56790) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jinqU-0000Ms-UU for bug-gnu-emacs@gnu.org; Tue, 09 Jun 2020 19:39:54 -0400 Original-Received: from relay9-d.mail.gandi.net ([217.70.183.199]:44721) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jinqT-0001t7-GO for bug-gnu-emacs@gnu.org; Tue, 09 Jun 2020 19:39:54 -0400 X-Originating-IP: 91.129.108.6 Original-Received: from mail.gandi.net (m91-129-108-6.cust.tele2.ee [91.129.108.6]) (Authenticated sender: juri@linkov.net) by relay9-d.mail.gandi.net (Postfix) with ESMTPSA id 4EAA9FF802 for ; Tue, 9 Jun 2020 23:39:48 +0000 (UTC) In-Reply-To: <87v9wdzc3g.fsf@mail.linkov.net> (Juri Linkov's message of "Mon, 08 Jul 2019 01:56:11 +0300") Received-SPF: pass client-ip=217.70.183.199; envelope-from=juri@linkov.net; helo=relay9-d.mail.gandi.net X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/09 19:39:50 X-ACL-Warn: Detected OS = Linux 3.11 and newer X-Spam_score_int: -35 X-Spam_score: -3.6 X-Spam_bar: --- X-Spam_report: (-3.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:181800 Archived-At: --=-=-= Content-Type: text/plain Tags: patch >> Which reminds me -- why doesn't `C-x v =' work on normal files that have >> backups? I think that would be pretty nice, natural and useful... > > I have the same problem of sometimes typing `C-x v =' instead of `M-=' > (dired-backup-diff) on backuped files in dired, and vice versa - `M-=' > instead of `C-x v =' on VC files. Now this annoyance finally got me - using these keys throws an error most of the time: when files are not yet registered in vc I use `M-=', but after registering them in vc, I continue typing the same key `M-=' and get that annoying error. The situation with `C-x v =' is not better: often after forgetting that a file is not yet under vc control, typing `C-x v =' raises the same error. Therefore, this patch to the rescue: --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=vc-diff-backup.patch diff --git a/lisp/vc/diff.el b/lisp/vc/diff.el index 9e7e771963..c94c442af8 100644 --- a/lisp/vc/diff.el +++ b/lisp/vc/diff.el @@ -230,10 +233,16 @@ diff-backup (if (backup-file-name-p file) (setq bak file ori (file-name-sans-versions file)) - (setq bak (or (diff-latest-backup-file file) - (error "No backup found for %s" file)) + (setq bak (diff-latest-backup-file file) ori file)) - (diff bak ori switches))) + (if bak + (diff bak ori switches) + ;; Fall back to vc-diff + (if (vc-backend file) + (let ((vc-diff-switches switches)) + (vc-diff-internal + t (list (vc-backend file) (list file)) nil nil t)) + (error "No backup found for %s" file))))) ;;;###autoload (defun diff-latest-backup-file (fn) diff --git a/lisp/vc/vc.el b/lisp/vc/vc.el index c640ba0420..a0363bd774 100644 --- a/lisp/vc/vc.el +++ b/lisp/vc/vc.el @@ -1888,11 +1890,15 @@ vc-diff The optional argument NOT-URGENT non-nil means it is ok to say no to saving the buffer." (interactive (list current-prefix-arg t)) - (if historic - (call-interactively 'vc-version-diff) - (when buffer-file-name (vc-buffer-sync not-urgent)) - (vc-diff-internal t (vc-deduce-fileset t) nil nil - (called-interactively-p 'interactive)))) + (if (vc-deduce-backend) + (if historic + (call-interactively 'vc-version-diff) + (when buffer-file-name (vc-buffer-sync not-urgent)) + (vc-diff-internal t (vc-deduce-fileset t) nil nil + (called-interactively-p 'interactive))) + ;; Fall back to non-vc diff-backup + (diff-backup (if (derived-mode-p 'dired-mode) (dired-get-filename) buffer-file-name) + vc-diff-switches))) ;;;###autoload (defun vc-diff-mergebase (_files rev1 rev2) --=-=-=--