emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master b593ea1: Fix 'dired-diff' when backup file is in an


From: Eli Zaretskii
Subject: [Emacs-diffs] master b593ea1: Fix 'dired-diff' when backup file is in another directory
Date: Sat, 6 Aug 2016 10:15:36 +0000 (UTC)

branch: master
commit b593ea1f9b7068c03fe6527a3cb6d5e1b2cd9736
Author: Eli Zaretskii <address@hidden>
Commit: Eli Zaretskii <address@hidden>

    Fix 'dired-diff' when backup file is in another directory
    
    * lisp/dired-aux.el (dired-diff): Clarify the doc string wrt how
    the default for FILE is computed, especially when backup files
    are involved.  Support backup files in another directory.
    Don't suggest the default FILE if it doesn't exist.  (Bug#24089)
---
 lisp/dired-aux.el |   44 +++++++++++++++++++++++++++++++-------------
 1 file changed, 31 insertions(+), 13 deletions(-)

diff --git a/lisp/dired-aux.el b/lisp/dired-aux.el
index 83fcf48..ff1f14d 100644
--- a/lisp/dired-aux.el
+++ b/lisp/dired-aux.el
@@ -54,19 +54,23 @@ into this list; they also should call `dired-log' to log 
the errors.")
 
 ;;;###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.)
-
-FILE is the first file given to `diff'.  The file at point
-is the second file given to `diff'.
+  "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 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.
@@ -77,8 +81,20 @@ the string of command switches for the third argument of 
`diff'."
          (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))
@@ -87,7 +103,9 @@ the string of command switches for the third argument of 
`diff'."
                                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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]