emacs-devel
[Top][All Lists]
Advanced

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

Re: M-= in Dired


From: Juri Linkov
Subject: Re: M-= in Dired
Date: Sat, 15 Sep 2012 02:45:10 +0300
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2.50 (x86_64-pc-linux-gnu)

> I think it's possible to do this in dired-diff without throwing away
> useful functionality of using as default a marked file or a file in
> adjacent windows (dwim-target).  The top default value could be
> a backup file but remaining defaults could remain the same as before.

This patch keeps the new functionality of using the latest existing
backup file, and restores the original functionality of using the default
file with the mark on it and adding more defaults for dwim directories:

=== modified file 'lisp/dired-aux.el'
--- lisp/dired-aux.el   2012-09-13 23:42:39 +0000
+++ lisp/dired-aux.el   2012-09-14 23:45:05 +0000
@@ -62,17 +62,31 @@ (defun dired-diff (file &optional switch
 which is the string of command switches for `diff'."
   (interactive
    (let* ((current (dired-get-filename t))
-         (oldf (file-newest-backup current))
-         (dir (if oldf (file-name-directory oldf))))
-     (list (read-file-name
-           (format "Diff %s with%s: "
-                   (file-name-nondirectory current)
-                   (if oldf
-                       (concat " (default "
-                               (file-name-nondirectory oldf)
-                               ")")
-                     ""))
-           dir oldf 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))
+                                           (dired-get-filename t t))))
+         (default-file (or file-at-mark
+                           (and oldf (file-name-nondirectory oldf))))
+         ;; Use it as default if it's not the same as the current file.
+         (default (if (not (equal default-file current))
+                      default-file))
+         (defaults
+           (if (not (equal (dired-dwim-target-directory)
+                           (dired-current-directory)))
+               (dired-dwim-target-defaults (list current)
+                                           (dired-dwim-target-directory)))))
+     (list
+      (read-file-name
+       (format "Diff %s with%s: " current
+              (if default (format " (default %s)" default) ""))
+       (if default
+          (dired-current-directory)
+        (dired-dwim-target-directory))
+       (delq nil (append (list default) defaults))
+       t)
           (if current-prefix-arg
               (read-string "Options for diff: "
                            (if (stringp diff-switches)





reply via email to

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