Subject: Re: bug#13772: 24.3.50; dired-diff does not replace dired-backup-diff

From: Juri Linkov <[email-masked]>
Date: Thu, 28 Feb 2013 01:57:50 +0200

> The M-= binding for dired-backup-diff was deleted,
> supposedly because dired-diff now replaces it.
> However, it does not.  If you type it on a backup file,
> it does not present the current file as the default argument.
> The default argument gives an error.
>
> And if you specify the current file as the argument, you get a diff
> between the right two files, but it is in reverse order.

The following patch copies the relevant logic from `diff-backup'
to `dired-diff', so that typing it on a backup file should present
its original as the default argument and run a diff in correct order.

=== modified file 'lisp/dired-aux.el'
*** lisp/dired-aux.el	2013-01-01 09:11:05 +0000
--- lisp/dired-aux.el	2013-02-27 23:56:03 +0000
*************** (defconst dired-quark-subst-regexp "\\(^
*** 55,61 ****
  (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 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.)
--- 55,62 ----
  (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.)
*************** (defun dired-diff (file &optional switch
*** 67,74 ****
  the string of command switches for the third argument of `diff'."
    (interactive
     (let* ((current (dired-get-filename t))
! 	  ;; Get the latest existing backup file.
! 	  (oldf (diff-latest-backup-file current))
  	  ;; Get the file at the mark.
  	  (file-at-mark (if (and transient-mark-mode mark-active)
  			    (save-excursion (goto-char (mark t))
--- 68,77 ----
  the string of command switches for the third argument of `diff'."
    (interactive
     (let* ((current (dired-get-filename t))
! 	  ;; Get the latest existing backup file or its original.
! 	  (oldf (if (backup-file-name-p current)
! 		    (file-name-sans-versions current)
! 		  (diff-latest-backup-file current)))
  	  ;; Get the file at the mark.
  	  (file-at-mark (if (and transient-mark-mode mark-active)
  			    (save-excursion (goto-char (mark t))
*************** (defun dired-diff (file &optional switch
*** 107,113 ****
  		   (equal (expand-file-name current file)
  			  (expand-file-name current))))
        (error "Attempt to compare the file to itself"))
!     (diff file current switches)))
  
  ;;;###autoload
  (defun dired-backup-diff (&optional switches)
--- 110,119 ----
  		   (equal (expand-file-name current file)
  			  (expand-file-name current))))
        (error "Attempt to compare the file to itself"))
!     (if (and (backup-file-name-p current)
! 	     (not (backup-file-name-p file)))
! 	(diff current file switches)
!       (diff file current switches))))
  
  ;;;###autoload
  (defun dired-backup-diff (&optional switches)