diff options
| author | Juri Linkov | 2019-10-27 02:20:15 +0300 |
|---|---|---|
| committer | Juri Linkov | 2019-10-27 02:20:15 +0300 |
| commit | c6667cc6a958e06fd43fb1ee0e80753adfefa49d (patch) | |
| tree | 601b9860dbd0d6cc90e4ca809050c4bd511c575f | |
| parent | 1660f5875c6022ba4f342a53efadfc4d2deb150a (diff) | |
| download | emacs-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.
| -rw-r--r-- | doc/emacs/dired.texi | 5 | ||||
| -rw-r--r-- | etc/NEWS | 16 | ||||
| -rw-r--r-- | lisp/dired-aux.el | 32 | ||||
| -rw-r--r-- | lisp/dired.el | 6 | ||||
| -rw-r--r-- | test/lisp/dired-tests.el | 3 |
5 files changed, 32 insertions, 30 deletions
diff --git a/doc/emacs/dired.texi b/doc/emacs/dired.texi index 4ada2a8df4f..c32255a86db 100644 --- a/doc/emacs/dired.texi +++ b/doc/emacs/dired.texi | |||
| @@ -655,8 +655,9 @@ commands, use the same conventions to decide which files to work on. | |||
| 655 | copy and rename files or create links for them, try to guess the default | 655 | copy and rename files or create links for them, try to guess the default |
| 656 | target directory for the operation. Normally, they suggest the Dired | 656 | target directory for the operation. Normally, they suggest the Dired |
| 657 | buffer's default directory, but if the variable @code{dired-dwim-target} | 657 | buffer's default directory, but if the variable @code{dired-dwim-target} |
| 658 | is non-@code{nil}, and if there is another Dired buffer displayed in the | 658 | is non-@code{nil}, and if there is another Dired buffer displayed in one |
| 659 | next window, that other buffer's directory is suggested instead. | 659 | of the most recently used windows, that other buffer's directory is |
| 660 | suggested instead. | ||
| 660 | 661 | ||
| 661 | Here are the file-manipulating Dired commands that operate on files. | 662 | Here are the file-manipulating Dired commands that operate on files. |
| 662 | 663 | ||
| @@ -810,6 +810,15 @@ command itself, not how many files are marked in total. | |||
| 810 | *** A new face, 'dired-special', is used to highlight sockets, named | 810 | *** A new face, 'dired-special', is used to highlight sockets, named |
| 811 | pipes, block devices and character devices. | 811 | pipes, block devices and character devices. |
| 812 | 812 | ||
| 813 | +++ | ||
| 814 | *** The new user option 'dired-create-destination-dirs' controls whether | ||
| 815 | 'dired-do-copy' and 'dired-rename-file' should create non-existent | ||
| 816 | directories in the destination. | ||
| 817 | |||
| 818 | +++ | ||
| 819 | *** The non-nil value of 'dired-dwim-target' uses one of the most recently | ||
| 820 | visited windows with a Dired buffer instead of the next window. | ||
| 821 | |||
| 813 | ** Find-Dired | 822 | ** Find-Dired |
| 814 | 823 | ||
| 815 | *** New user option 'find-dired-refine-function'. | 824 | *** New user option 'find-dired-refine-function'. |
| @@ -1367,13 +1376,6 @@ unescaping text. | |||
| 1367 | The maximum level is used by default; customize | 1376 | The maximum level is used by default; customize |
| 1368 | 'font-lock-maximum-decoration' to tone down the decoration. | 1377 | 'font-lock-maximum-decoration' to tone down the decoration. |
| 1369 | 1378 | ||
| 1370 | ** Dired | ||
| 1371 | |||
| 1372 | +++ | ||
| 1373 | *** The new user option 'dired-create-destination-dirs' controls whether | ||
| 1374 | 'dired-do-copy' and 'dired-rename-file' should create non-existent | ||
| 1375 | directories in the destination. | ||
| 1376 | |||
| 1377 | ** Help | 1379 | ** Help |
| 1378 | 1380 | ||
| 1379 | --- | 1381 | --- |
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. |
| 188 | This means: if there is a Dired buffer displayed in the next | 188 | This means: if there is a Dired buffer displayed in one of the most |
| 189 | window, use its current directory, instead of this Dired buffer's | 189 | recently selected windows, use its current directory, instead of this |
| 190 | current directory. | 190 | Dired buffer's current directory. |
| 191 | 191 | ||
| 192 | The target is used in the prompt for file copy, rename etc." | 192 | The target is used in the prompt for file copy, rename etc." |
| 193 | :type 'boolean | 193 | :type 'boolean |
diff --git a/test/lisp/dired-tests.el b/test/lisp/dired-tests.el index 71ffcdd5458..c4728e7a067 100644 --- a/test/lisp/dired-tests.el +++ b/test/lisp/dired-tests.el | |||
| @@ -20,7 +20,6 @@ | |||
| 20 | ;;; Code: | 20 | ;;; Code: |
| 21 | (require 'ert) | 21 | (require 'ert) |
| 22 | (require 'dired) | 22 | (require 'dired) |
| 23 | (require 'nadvice) | ||
| 24 | 23 | ||
| 25 | (ert-deftest dired-autoload () | 24 | (ert-deftest dired-autoload () |
| 26 | "Tests to see whether dired-x has been autoloaded" | 25 | "Tests to see whether dired-x has been autoloaded" |
| @@ -54,7 +53,7 @@ | |||
| 54 | (when (buffer-live-p buf) (kill-buffer buf))) | 53 | (when (buffer-live-p buf) (kill-buffer buf))) |
| 55 | (delete-directory dir 'recursive)))) | 54 | (delete-directory dir 'recursive)))) |
| 56 | 55 | ||
| 57 | (defvar dired-dwim-target) | 56 | (defvar dired-query) |
| 58 | (ert-deftest dired-test-bug25609 () | 57 | (ert-deftest dired-test-bug25609 () |
| 59 | "Test for https://debbugs.gnu.org/25609 ." | 58 | "Test for https://debbugs.gnu.org/25609 ." |
| 60 | (let* ((from (make-temp-file "foo" 'dir)) | 59 | (let* ((from (make-temp-file "foo" 'dir)) |