From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#24089: 25.1; Dired: diff error on = if the file has a backup inside .~/ Date: Sun, 31 Jul 2016 18:08:40 +0300 Message-ID: <838twhq1zb.fsf@gnu.org> References: <1469644946.16323.9.camel@gmail.com> <83popxrefr.fsf@gnu.org> <1469792610.16323.47.camel@gmail.com> <83bn1gqzco.fsf@gnu.org> <1469809763.28832.14.camel@gmail.com> Reply-To: Eli Zaretskii NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: blaine.gmane.org 1469977774 28805 80.91.229.8 (31 Jul 2016 15:09:34 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 31 Jul 2016 15:09:34 +0000 (UTC) Cc: 24089@debbugs.gnu.org To: Jorge Peixoto de Morais Neto Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Jul 31 17:09:20 2016 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bTsMh-0007R7-NS for geb-bug-gnu-emacs@m.gmane.org; Sun, 31 Jul 2016 17:09:19 +0200 Original-Received: from localhost ([::1]:39875 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bTsMd-0001vG-Qt for geb-bug-gnu-emacs@m.gmane.org; Sun, 31 Jul 2016 11:09:15 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:34850) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bTsMS-0001sE-4U for bug-gnu-emacs@gnu.org; Sun, 31 Jul 2016 11:09:09 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bTsMQ-0006t6-E6 for bug-gnu-emacs@gnu.org; Sun, 31 Jul 2016 11:09:03 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:54994) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bTsMQ-0006t2-Ai for bug-gnu-emacs@gnu.org; Sun, 31 Jul 2016 11:09:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1bTsMQ-0003B4-5K for bug-gnu-emacs@gnu.org; Sun, 31 Jul 2016 11:09:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 31 Jul 2016 15:09:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 24089 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 24089-submit@debbugs.gnu.org id=B24089.146997773512201 (code B ref 24089); Sun, 31 Jul 2016 15:09:02 +0000 Original-Received: (at 24089) by debbugs.gnu.org; 31 Jul 2016 15:08:55 +0000 Original-Received: from localhost ([127.0.0.1]:52291 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bTsMI-0003Ai-OT for submit@debbugs.gnu.org; Sun, 31 Jul 2016 11:08:55 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:43822) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bTsMH-0003AW-5I for 24089@debbugs.gnu.org; Sun, 31 Jul 2016 11:08:53 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bTsM6-0006qv-W6 for 24089@debbugs.gnu.org; Sun, 31 Jul 2016 11:08:47 -0400 Original-Received: from fencepost.gnu.org ([2001:4830:134:3::e]:58639) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bTsM6-0006qn-SB; Sun, 31 Jul 2016 11:08:42 -0400 Original-Received: from 84.94.185.246.cable.012.net.il ([84.94.185.246]:3453 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_128_CBC_SHA1:128) (Exim 4.82) (envelope-from ) id 1bTsM4-0003kN-L4; Sun, 31 Jul 2016 11:08:41 -0400 In-reply-to: <1469809763.28832.14.camel@gmail.com> (message from Jorge Peixoto de Morais Neto on Fri, 29 Jul 2016 13:29:23 -0300) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 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.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:121745 Archived-At: > From: Jorge Peixoto de Morais Neto > Cc: 24089@debbugs.gnu.org > Date: Fri, 29 Jul 2016 13:29:23 -0300 > > On Fri, 2016-07-29 at 17:43 +0300, Eli Zaretskii wrote: > > I'm not sure why you expect that case to work.  How can Emacs > > reverse-engineer backup-directory-alist, to figure out which of its > > elements was in effect when the original file was backed up?  In your > > example, there's only one element in the alist, but in general there > > could be several. > > > > It sounds like in this case the users cannot just press RET, they > > should actually type a file name.  Am I missing something? > I understood the intended behavior that way because of the dired-diff > docstring: >     If the file at point is a backup file, use its original. > > Perhaps the docstring could be clarified? > > Also dired-diff could be tweaked so that, when it is is invoked on a backup > file, the default would be empty.  This would avoid the diff error on = . >  I am not sure though. > > Another possibility (which can be combined with the previous) is to tweak > dired-diff to reverse-engineer backup-directory-alist at least for a few > important easy particular cases, such as the following two: > 1. (("." . ".~")) > 2. (("." . "/ABSOLUTE/PATH")) > and possibly others. How about the alternative patch below? It fixes the doc string, and makes the prompt be without the default in the second case. Is that good enough, in your opinion? --- lisp/dired-aux.el~0 2016-05-08 07:05:52.000000000 +0300 +++ lisp/dired-aux.el 2016-07-31 17:50:35.792144200 +0300 @@ -55,19 +55,23 @@ ;;;###autoload (defun dired-diff (file &optional switches) - "Compare file at point with file FILE using `diff'. -If called interactively, prompt for FILE. If the file at point -has a backup file, use that as the default. If the file at point -is a backup file, use its original. If the mark is active -in Transient Mark mode, use the file at the mark as the default. -\(That's the mark set by \\[set-mark-command], not by Dired's -\\[dired-mark] command.) + "Compare file at point with FILE using `diff'. +If called interactively, prompt for FILE. +If the mark is active in Transient Mark mode, use the file at the mark +as the default for FILE. (That's the mark set by \\[set-mark-command], +not by Dired's \\[dired-mark] command.) +If the file at point has a backup file, use that as the default FILE. +If the file at point is a backup file, use its original, if that exists +and can be found. Note that customizations of `backup-directory-alist' +and `make-backup-file-name-function' change where this function searches +for the backup file, and affect its ability to find the original of a +backup file. -FILE is the first file given to `diff'. The file at point -is the second file given to `diff'. +FILE is the first argument given to the `diff' function. The file at +point is the second argument given to `diff'. With prefix arg, prompt for second argument SWITCHES, which is -the string of command switches for the third argument of `diff'." +the string of command switches used as the third argument of `diff'." (interactive (let* ((current (dired-get-filename t)) ;; Get the latest existing backup file or its original. @@ -78,8 +82,20 @@ (file-at-mark (if (and transient-mark-mode mark-active) (save-excursion (goto-char (mark t)) (dired-get-filename t t)))) + (separate-dir (and oldf + (not (equal (file-name-directory oldf) + (dired-current-directory))))) (default-file (or file-at-mark - (and oldf (file-name-nondirectory oldf)))) + ;; If the file with which to compare + ;; doesn't exist, or we cannot intuit it, + ;; we forget that name and don't show it + ;; as the default, as an indication to the + ;; user that she should type the file + ;; name. + (and (if (and oldf (file-readable-p oldf)) oldf) + (if separate-dir + oldf + (file-name-nondirectory oldf))))) ;; Use it as default if it's not the same as the current file, ;; and the target dir is current or there is a default file. (default (if (and (not (equal default-file current)) @@ -88,7 +104,9 @@ default-file)) default-file)) (target-dir (if default - (dired-current-directory) + (if separate-dir + (file-name-directory default) + (dired-current-directory)) (dired-dwim-target-directory))) (defaults (dired-dwim-target-defaults (list current) target-dir))) (list