From: Juri Linkov <juri@linkov.net>
To: martin rudalics <rudalics@gmx.at>
Cc: "Basil L. Contovounesios" <contovob@tcd.ie>,
Lars Ingebrigtsen <larsi@gnus.org>,
35385@debbugs.gnu.org
Subject: bug#35385: 27.0.50; Make dired-dwim-target aware of other frames
Date: Thu, 19 Sep 2019 23:43:37 +0300 [thread overview]
Message-ID: <87y2yknhja.fsf@mail.linkov.net> (raw)
In-Reply-To: <138859c1-a7e0-f40d-4623-635826decd90@gmx.at> (martin rudalics's message of "Thu, 19 Sep 2019 10:18:45 +0200")
[-- Attachment #1: Type: text/plain, Size: 659 bytes --]
>> BTW, while looking at windows walking functions, I noticed
>> an opportunity for simplification.
>>
>> Martin, could you please confirm if I'm not mistaken with this patch:
>
> Removing the
>
> (when (framep all-frames)
> (select-window (frame-first-window all-frames) 'norecord))
>
> LGTM. Whether we should remove the
>
> (save-selected-window
>
> envelope is another question. If FUN changes the selected window,
> we'd now have a side effect we didn't have so far.
So I left a comment explaining why save-selected-window is still needed.
Now I prepared a patch for dired-dwim-target to DWIM most recently used
windows from all frames:
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: dired-dwim-target-directories.patch --]
[-- Type: text/x-diff, Size: 3497 bytes --]
diff --git a/lisp/dired-aux.el b/lisp/dired-aux.el
index a321247b0b..7c477fa89d 100644
--- a/lisp/dired-aux.el
+++ b/lisp/dired-aux.el
@@ -1965,6 +1968,18 @@ dired-mark-read-file-name
#'read-file-name
(format prompt (dired-mark-prompt arg files)) dir default))
+(defun dired-dwim-target-directories ()
+ ;; Return directories from all visible windows with dired-mode buffers
+ ;; ordered by most-recently-used.
+ (mapcar #'cdr (sort (mapcan (lambda (w)
+ (with-current-buffer (window-buffer w)
+ (when (eq major-mode 'dired-mode)
+ (list (cons (window-use-time w)
+ (dired-current-directory))))))
+ (delq (selected-window)
+ (window-list-1 nil 'nomini 'visible)))
+ (lambda (a b) (> (car a) (car b))))))
+
(defun dired-dwim-target-directory ()
;; Try to guess which target directory the user may want.
;; If there is a dired buffer displayed in one of the next windows,
@@ -1973,15 +1988,7 @@ dired-dwim-target-directory
(dired-current-directory))))
;; non-dired buffer may want to profit from this function, e.g. vm-uudecode
(if dired-dwim-target
- (let* ((other-win (get-window-with-predicate
- (lambda (window)
- (with-current-buffer (window-buffer window)
- (eq major-mode 'dired-mode)))))
- (other-dir (and other-win
- (with-current-buffer (window-buffer other-win)
- (and (eq major-mode 'dired-mode)
- (dired-current-directory))))))
- (or other-dir this-dir))
+ (or (car (dired-dwim-target-directories)) this-dir)
this-dir)))
(defun dired-dwim-target-defaults (fn-list target-dir)
@@ -1999,15 +2006,11 @@ dired-dwim-target-defaults
(and (consp fn-list) (null (cdr fn-list)) (car fn-list)))
(current-dir (and (eq major-mode 'dired-mode)
(dired-current-directory)))
- dired-dirs)
- ;; Get a list of directories of visible buffers in dired-mode.
- (walk-windows (lambda (w)
- (with-current-buffer (window-buffer w)
- (and (eq major-mode 'dired-mode)
- (push (dired-current-directory) dired-dirs)))))
+ ;; Get a list of directories of visible buffers in dired-mode.
+ (dired-dirs (dired-dwim-target-directories)))
;; Force the current dir to be the first in the list.
(setq dired-dirs
- (delete-dups (delq nil (cons current-dir (nreverse dired-dirs)))))
+ (delete-dups (delq nil (cons current-dir dired-dirs))))
;; Remove the target dir (if specified) or the current dir from
;; default values, because it should be already in initial input.
(setq dired-dirs (delete (or target-dir current-dir) dired-dirs))
diff --git a/lisp/dired.el b/lisp/dired.el
index 854bc9f7d7..b0d40da57f 100644
--- a/lisp/dired.el
+++ b/lisp/dired.el
@@ -185,9 +185,9 @@ dired-keep-marker-symlink
(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 the next
-window, use its current directory, instead of this Dired buffer's
-current directory.
+This means: if there is a Dired buffer displayed in one of recently
+selected windows, use its current directory, instead of this Dired
+buffer's current directory.
The target is used in the prompt for file copy, rename etc."
:type 'boolean
next prev parent reply other threads:[~2019-09-19 20:43 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-22 21:47 bug#35385: 27.0.50; Make dired-dwim-target aware of other frames Basil L. Contovounesios
2019-04-22 22:11 ` Basil L. Contovounesios
2019-04-29 20:28 ` Juri Linkov
2019-06-23 17:28 ` Lars Ingebrigtsen
2019-09-16 21:11 ` Lars Ingebrigtsen
2019-09-16 21:39 ` Juri Linkov
2019-09-18 21:48 ` Juri Linkov
2019-09-19 8:18 ` martin rudalics
2019-09-19 20:43 ` Juri Linkov [this message]
2019-10-26 23:20 ` Juri Linkov
2019-11-04 19:01 ` Michael Heerdegen
2019-11-05 22:18 ` Juri Linkov
2019-11-08 19:13 ` Michael Heerdegen
2019-11-10 20:38 ` Juri Linkov
2019-11-12 21:21 ` Juri Linkov
2019-11-13 15:30 ` Michael Heerdegen
2019-11-13 21:41 ` Juri Linkov
2019-11-14 15:08 ` Michael Heerdegen
2019-11-14 23:10 ` Juri Linkov
2019-11-15 12:16 ` Michael Heerdegen
2019-11-16 22:06 ` Juri Linkov
2019-11-16 22:42 ` Michael Heerdegen
2020-08-10 11:36 ` Lars Ingebrigtsen
2019-11-14 10:13 ` Eli Zaretskii
2019-11-14 23:07 ` Juri Linkov
2019-09-19 1:51 ` Basil L. Contovounesios
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87y2yknhja.fsf@mail.linkov.net \
--to=juri@linkov.net \
--cc=35385@debbugs.gnu.org \
--cc=contovob@tcd.ie \
--cc=larsi@gnus.org \
--cc=rudalics@gmx.at \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).