diff options
| -rw-r--r-- | lisp/dired-aux.el | 44 |
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'. |
| 58 | If called interactively, prompt for FILE. If the file at point | 58 | If called interactively, prompt for FILE. |
| 59 | has a backup file, use that as the default. If the file at point | 59 | If the mark is active in Transient Mark mode, use the file at the mark |
| 60 | is a backup file, use its original. If the mark is active | 60 | as the default for FILE. (That's the mark set by \\[set-mark-command], |
| 61 | in Transient Mark mode, use the file at the mark as the default. | 61 | not by Dired's \\[dired-mark] command.) |
| 62 | \(That's the mark set by \\[set-mark-command], not by Dired's | 62 | If the file at point has a backup file, use that as the default FILE. |
| 63 | \\[dired-mark] command.) | 63 | If the file at point is a backup file, use its original, if that exists |
| 64 | 64 | and can be found. Note that customizations of `backup-directory-alist' | |
| 65 | FILE is the first file given to `diff'. The file at point | 65 | and `make-backup-file-name-function' change where this function searches |
| 66 | is the second file given to `diff'. | 66 | for the backup file, and affect its ability to find the original of a |
| 67 | backup file. | ||
| 68 | |||
| 69 | FILE is the first argument given to the `diff' function. The file at | ||
| 70 | point is the second argument given to `diff'. | ||
| 67 | 71 | ||
| 68 | With prefix arg, prompt for second argument SWITCHES, which is | 72 | With prefix arg, prompt for second argument SWITCHES, which is |
| 69 | the string of command switches for the third argument of `diff'." | 73 | the 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 |