aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorJuri Linkov2019-10-27 02:20:15 +0300
committerJuri Linkov2019-10-27 02:20:15 +0300
commitc6667cc6a958e06fd43fb1ee0e80753adfefa49d (patch)
tree601b9860dbd0d6cc90e4ca809050c4bd511c575f /lisp
parent1660f5875c6022ba4f342a53efadfc4d2deb150a (diff)
downloademacs-c6667cc6a958e06fd43fb1ee0e80753adfefa49d.tar.gz
emacs-c6667cc6a958e06fd43fb1ee0e80753adfefa49d.zip
dired-dwim-target uses most recently visited window instead of next window.
* doc/emacs/dired.texi (Operating on Files): Document behavior change. * lisp/dired-aux.el (dired-dwim-target-directories): New function. (dired-dwim-target-directory, dired-dwim-target-defaults): Use it to get the most recently used window instead of the next window (bug#35385). * lisp/dired.el (dired-dwim-target): Doc fix. * test/lisp/dired-tests.el: Remove unnecessary require and pacify byte-compiler.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/dired-aux.el32
-rw-r--r--lisp/dired.el6
2 files changed, 19 insertions, 19 deletions
diff --git a/lisp/dired-aux.el b/lisp/dired-aux.el
index b3ff2443626..b1521ecf018 100644
--- a/lisp/dired-aux.el
+++ b/lisp/dired-aux.el
@@ -1977,6 +1977,18 @@ Optional arg HOW-TO determines how to treat the target.
1977 #'read-file-name 1977 #'read-file-name
1978 (format prompt (dired-mark-prompt arg files)) dir default)) 1978 (format prompt (dired-mark-prompt arg files)) dir default))
1979 1979
1980(defun dired-dwim-target-directories ()
1981 ;; Return directories from all visible windows with dired-mode buffers
1982 ;; ordered by most-recently-used.
1983 (mapcar #'cdr (sort (mapcan (lambda (w)
1984 (with-current-buffer (window-buffer w)
1985 (when (eq major-mode 'dired-mode)
1986 (list (cons (window-use-time w)
1987 (dired-current-directory))))))
1988 (delq (selected-window)
1989 (window-list-1 nil 'nomini 'visible)))
1990 (lambda (a b) (> (car a) (car b))))))
1991
1980(defun dired-dwim-target-directory () 1992(defun dired-dwim-target-directory ()
1981 ;; Try to guess which target directory the user may want. 1993 ;; Try to guess which target directory the user may want.
1982 ;; If there is a dired buffer displayed in one of the next windows, 1994 ;; If there is a dired buffer displayed in one of the next windows,
@@ -1985,15 +1997,7 @@ Optional arg HOW-TO determines how to treat the target.
1985 (dired-current-directory)))) 1997 (dired-current-directory))))
1986 ;; non-dired buffer may want to profit from this function, e.g. vm-uudecode 1998 ;; non-dired buffer may want to profit from this function, e.g. vm-uudecode
1987 (if dired-dwim-target 1999 (if dired-dwim-target
1988 (let* ((other-win (get-window-with-predicate 2000 (or (car (dired-dwim-target-directories)) this-dir)
1989 (lambda (window)
1990 (with-current-buffer (window-buffer window)
1991 (eq major-mode 'dired-mode)))))
1992 (other-dir (and other-win
1993 (with-current-buffer (window-buffer other-win)
1994 (and (eq major-mode 'dired-mode)
1995 (dired-current-directory))))))
1996 (or other-dir this-dir))
1997 this-dir))) 2001 this-dir)))
1998 2002
1999(defun dired-dwim-target-defaults (fn-list target-dir) 2003(defun dired-dwim-target-defaults (fn-list target-dir)
@@ -2011,15 +2015,11 @@ Optional arg HOW-TO determines how to treat the target.
2011 (and (consp fn-list) (null (cdr fn-list)) (car fn-list))) 2015 (and (consp fn-list) (null (cdr fn-list)) (car fn-list)))
2012 (current-dir (and (eq major-mode 'dired-mode) 2016 (current-dir (and (eq major-mode 'dired-mode)
2013 (dired-current-directory))) 2017 (dired-current-directory)))
2014 dired-dirs) 2018 ;; Get a list of directories of visible buffers in dired-mode.
2015 ;; Get a list of directories of visible buffers in dired-mode. 2019 (dired-dirs (dired-dwim-target-directories)))
2016 (walk-windows (lambda (w)
2017 (with-current-buffer (window-buffer w)
2018 (and (eq major-mode 'dired-mode)
2019 (push (dired-current-directory) dired-dirs)))))
2020 ;; Force the current dir to be the first in the list. 2020 ;; Force the current dir to be the first in the list.
2021 (setq dired-dirs 2021 (setq dired-dirs
2022 (delete-dups (delq nil (cons current-dir (nreverse dired-dirs))))) 2022 (delete-dups (delq nil (cons current-dir dired-dirs))))
2023 ;; Remove the target dir (if specified) or the current dir from 2023 ;; Remove the target dir (if specified) or the current dir from
2024 ;; default values, because it should be already in initial input. 2024 ;; default values, because it should be already in initial input.
2025 (setq dired-dirs (delete (or target-dir current-dir) dired-dirs)) 2025 (setq dired-dirs (delete (or target-dir current-dir) dired-dirs))
diff --git a/lisp/dired.el b/lisp/dired.el
index 1d085e010f6..e50108fdb9e 100644
--- a/lisp/dired.el
+++ b/lisp/dired.el
@@ -185,9 +185,9 @@ If a character, new links are unconditionally marked with that character."
185 185
186(defcustom dired-dwim-target nil 186(defcustom dired-dwim-target nil
187 "If non-nil, Dired tries to guess a default target directory. 187 "If non-nil, Dired tries to guess a default target directory.
188This means: if there is a Dired buffer displayed in the next 188This means: if there is a Dired buffer displayed in one of the most
189window, use its current directory, instead of this Dired buffer's 189recently selected windows, use its current directory, instead of this
190current directory. 190Dired buffer's current directory.
191 191
192The target is used in the prompt for file copy, rename etc." 192The target is used in the prompt for file copy, rename etc."
193 :type 'boolean 193 :type 'boolean