emacs-diffs
[Top][All Lists]
Advanced

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

master d0351f4: * lisp/dired.el (dired-dwim-target): Add new choices (bu


From: Juri Linkov
Subject: master d0351f4: * lisp/dired.el (dired-dwim-target): Add new choices (bug#35385)
Date: Tue, 12 Nov 2019 16:21:20 -0500 (EST)

branch: master
commit d0351f4d2010e3e8f3ada04b045dede10f110d7f
Author: Juri Linkov <address@hidden>
Commit: Juri Linkov <address@hidden>

    * lisp/dired.el (dired-dwim-target): Add new choices (bug#35385)
    
    * lisp/dired.el (dired-dwim-target): Add choices
    dired-dwim-target-next and dired-dwim-target-recent.
    
    * lisp/dired-aux.el (dired-dwim-target-next)
    (dired-dwim-target-recent): New functions.
    (dired-dwim-target-directories): Call either of them.
    
    * doc/emacs/dired.texi (Operating on Files): Mention new
    preferences in dired-dwim-target.
---
 doc/emacs/dired.texi | 10 ++++++----
 etc/NEWS             |  4 ++--
 lisp/dired-aux.el    | 16 ++++++++++++++++
 lisp/dired.el        | 18 ++++++++++++++----
 4 files changed, 38 insertions(+), 10 deletions(-)

diff --git a/doc/emacs/dired.texi b/doc/emacs/dired.texi
index c32255a..8fab508 100644
--- a/doc/emacs/dired.texi
+++ b/doc/emacs/dired.texi
@@ -654,10 +654,12 @@ commands, use the same conventions to decide which files 
to work on.
   Commands which ask for a destination directory, such as those which
 copy and rename files or create links for them, try to guess the default
 target directory for the operation.  Normally, they suggest the Dired
-buffer's default directory, but if the variable @code{dired-dwim-target}
-is non-@code{nil}, and if there is another Dired buffer displayed in one
-of the most recently used windows, that other buffer's directory is
-suggested instead.
+buffer's default directory, but if the option @code{dired-dwim-target}
+is non-@code{nil}, and if there is another Dired buffer displayed in
+some window, that other buffer's directory is suggested instead.
+You can customize @code{dired-dwim-target} to prefer either the next
+window with a Dired buffer, or the most recently used window with
+a Dired buffer.
 
   Here are the file-manipulating Dired commands that operate on files.
 
diff --git a/etc/NEWS b/etc/NEWS
index 4134f7b..ff33449 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -852,8 +852,8 @@ pipes, block devices and character devices.
 directories in the destination.
 
 +++
-*** The non-nil value of 'dired-dwim-target' uses one of the most recently
-visited windows with a Dired buffer instead of the next window.
+*** 'dired-dwim-target' can be customized to prefer either the next window,
+or one of the most recently visited windows with a Dired buffer.
 
 *** When the new user option 'dired-vc-rename-file' is non-nil,
 Dired performs file renaming using underlying version control system.
diff --git a/lisp/dired-aux.el b/lisp/dired-aux.el
index 184b507..9f34b2a 100644
--- a/lisp/dired-aux.el
+++ b/lisp/dired-aux.el
@@ -1993,6 +1993,22 @@ Optional arg HOW-TO determines how to treat the target.
    (format prompt (dired-mark-prompt arg files)) dir default))
 
 (defun dired-dwim-target-directories ()
+  (cond ((functionp dired-dwim-target)
+         (funcall dired-dwim-target))
+        (dired-dwim-target
+         (dired-dwim-target-next))))
+
+(defun dired-dwim-target-next ()
+  ;; Return directories from all next visible windows with dired-mode buffers.
+  (mapcan (lambda (w)
+            (with-current-buffer (window-buffer w)
+              (when (eq major-mode 'dired-mode)
+                (list (dired-current-directory)))))
+          (delq (selected-window) (window-list-1
+                                   (next-window nil 'nomini 'visible)
+                                   'nomini 'visible))))
+
+(defun dired-dwim-target-recent ()
   ;; Return directories from all visible windows with dired-mode buffers
   ;; ordered by most-recently-used.
   (mapcar #'cdr (sort (mapcan (lambda (w)
diff --git a/lisp/dired.el b/lisp/dired.el
index 9d0b13e..009018f 100644
--- a/lisp/dired.el
+++ b/lisp/dired.el
@@ -185,12 +185,22 @@ If a character, new links are unconditionally marked with 
that character."
 
 (defcustom dired-dwim-target nil
   "If non-nil, Dired tries to guess a default target directory.
-This means: if there is a Dired buffer displayed in one of the most
-recently selected windows, use its current directory, instead of this
-Dired buffer's current directory.
+This means: if there is a Dired buffer displayed in some window,
+use its current directory, instead of this Dired buffer's
+current directory.
+
+You can customize it to prefer either the next window with a Dired buffer,
+or the most recently used window with a Dired buffer.
 
 The target is used in the prompt for file copy, rename etc."
-  :type 'boolean
+  :type '(choice
+          (const :tag "No guess" nil)
+          (function-item :tag "Prefer next windows"
+                         dired-dwim-target-next)
+          (function-item :tag "Prefer most recently used windows"
+                         dired-dwim-target-recent)
+          (function :tag "Your function")
+          (other :tag "Try to guess" t))
   :group 'dired)
 
 (defcustom dired-copy-preserve-time t



reply via email to

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