aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEli Zaretskii2016-08-06 13:13:57 +0300
committerEli Zaretskii2016-08-06 13:13:57 +0300
commitb593ea1f9b7068c03fe6527a3cb6d5e1b2cd9736 (patch)
tree21c990c3d144d90a512ac0a314bb26a0f924931d
parent0a327afe2e416777e09b24c18292f854536bdb23 (diff)
downloademacs-b593ea1f9b7068c03fe6527a3cb6d5e1b2cd9736.tar.gz
emacs-b593ea1f9b7068c03fe6527a3cb6d5e1b2cd9736.zip
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)
-rw-r--r--lisp/dired-aux.el44
1 files changed, 31 insertions, 13 deletions
diff --git a/lisp/dired-aux.el b/lisp/dired-aux.el
index 83fcf480b74..ff1f14d7a65 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.")
54 54
55;;;###autoload 55;;;###autoload
56(defun dired-diff (file &optional switches) 56(defun dired-diff (file &optional switches)
57 "Compare file at point with file FILE using `diff'. 57 "Compare file at point with FILE using `diff'.
58If called interactively, prompt for FILE. If the file at point 58If called interactively, prompt for FILE.
59has a backup file, use that as the default. If the file at point 59If the mark is active in Transient Mark mode, use the file at the mark
60is a backup file, use its original. If the mark is active 60as the default for FILE. (That's the mark set by \\[set-mark-command],
61in Transient Mark mode, use the file at the mark as the default. 61not by Dired's \\[dired-mark] command.)
62\(That's the mark set by \\[set-mark-command], not by Dired's 62If the file at point has a backup file, use that as the default FILE.
63\\[dired-mark] command.) 63If the file at point is a backup file, use its original, if that exists
64 64and can be found. Note that customizations of `backup-directory-alist'
65FILE is the first file given to `diff'. The file at point 65and `make-backup-file-name-function' change where this function searches
66is the second file given to `diff'. 66for the backup file, and affect its ability to find the original of a
67backup file.
68
69FILE is the first argument given to the `diff' function. The file at
70point is the second argument given to `diff'.
67 71
68With prefix arg, prompt for second argument SWITCHES, which is 72With prefix arg, prompt for second argument SWITCHES, which is
69the string of command switches for the third argument of `diff'." 73the string of command switches used as the third argument of `diff'."
70 (interactive 74 (interactive
71 (let* ((current (dired-get-filename t)) 75 (let* ((current (dired-get-filename t))
72 ;; Get the latest existing backup file or its original. 76 ;; Get the latest existing backup file or its original.
@@ -77,8 +81,20 @@ the string of command switches for the third argument of `diff'."
77 (file-at-mark (if (and transient-mark-mode mark-active) 81 (file-at-mark (if (and transient-mark-mode mark-active)
78 (save-excursion (goto-char (mark t)) 82 (save-excursion (goto-char (mark t))
79 (dired-get-filename t t)))) 83 (dired-get-filename t t))))
84 (separate-dir (and oldf
85 (not (equal (file-name-directory oldf)
86 (dired-current-directory)))))
80 (default-file (or file-at-mark 87 (default-file (or file-at-mark
81 (and oldf (file-name-nondirectory oldf)))) 88 ;; If the file with which to compare
89 ;; doesn't exist, or we cannot intuit it,
90 ;; we forget that name and don't show it
91 ;; as the default, as an indication to the
92 ;; user that she should type the file
93 ;; name.
94 (and (if (and oldf (file-readable-p oldf)) oldf)
95 (if separate-dir
96 oldf
97 (file-name-nondirectory oldf)))))
82 ;; Use it as default if it's not the same as the current file, 98 ;; Use it as default if it's not the same as the current file,
83 ;; and the target dir is current or there is a default file. 99 ;; and the target dir is current or there is a default file.
84 (default (if (and (not (equal default-file current)) 100 (default (if (and (not (equal default-file current))
@@ -87,7 +103,9 @@ the string of command switches for the third argument of `diff'."
87 default-file)) 103 default-file))
88 default-file)) 104 default-file))
89 (target-dir (if default 105 (target-dir (if default
90 (dired-current-directory) 106 (if separate-dir
107 (file-name-directory default)
108 (dired-current-directory))
91 (dired-dwim-target-directory))) 109 (dired-dwim-target-directory)))
92 (defaults (dired-dwim-target-defaults (list current) target-dir))) 110 (defaults (dired-dwim-target-defaults (list current) target-dir)))
93 (list 111 (list