GNU bug report logs - #35385
27.0.50; Make dired-dwim-target aware of other frames

Previous Next

Package: emacs;

Reported by: "Basil L. Contovounesios" <contovob <at> tcd.ie>

Date: Mon, 22 Apr 2019 22:04:01 UTC

Severity: wishlist

Tags: patch

Found in version 27.0.50

Done: Lars Ingebrigtsen <larsi <at> gnus.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 35385 in the body.
You can then email your comments to 35385 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#35385; Package emacs. (Mon, 22 Apr 2019 22:04:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to "Basil L. Contovounesios" <contovob <at> tcd.ie>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Mon, 22 Apr 2019 22:04:01 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: "Basil L. Contovounesios" <contovob <at> tcd.ie>
To: bug-gnu-emacs <at> gnu.org
Subject: 27.0.50; Make dired-dwim-target aware of other frames
Date: Mon, 22 Apr 2019 22:47:16 +0100
Severity: wishlist

Currently, the user option dired-dwim-target applies only to windows
displaying Dired buffers on the selected frame.  IWBNI this were
customisable, so that Dired buffers displayed on other frames were also
considered as default targets for file operations.  This would be useful
for users like me who enable pop-up-frames.

Patch implementing this to follow.

Thanks,

-- 
Basil




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#35385; Package emacs. (Mon, 22 Apr 2019 22:12:01 GMT) Full text and rfc822 format available.

Message #8 received at 35385 <at> debbugs.gnu.org (full text, mbox):

From: "Basil L. Contovounesios" <contovob <at> tcd.ie>
To: 35385 <at> debbugs.gnu.org
Subject: Re: bug#35385: 27.0.50; Make dired-dwim-target aware of other frames
Date: Mon, 22 Apr 2019 23:11:28 +0100
[Message part 1 (text/plain, inline)]
tags 35385 patch
quit

[0001-Make-dired-dwim-target-aware-of-other-frames.patch (text/x-diff, attachment)]
[Message part 3 (text/plain, inline)]
"Basil L. Contovounesios" <contovob <at> tcd.ie> writes:

> Patch implementing this to follow.

Now attached.  WDYT?

Thanks,

-- 
Basil

Added tag(s) patch. Request was from "Basil L. Contovounesios" <contovob <at> tcd.ie> to control <at> debbugs.gnu.org. (Mon, 22 Apr 2019 22:12:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#35385; Package emacs. (Mon, 29 Apr 2019 20:30:02 GMT) Full text and rfc822 format available.

Message #13 received at 35385 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: "Basil L. Contovounesios" <contovob <at> tcd.ie>
Cc: 35385 <at> debbugs.gnu.org
Subject: Re: bug#35385: 27.0.50; Make dired-dwim-target aware of other frames
Date: Mon, 29 Apr 2019 23:28:09 +0300
> Now attached.  WDYT?

>  @vindex dired-dwim-target
> +@vindex dired-dwim-target-frames

Should we also have dired-dwim-target-windows?
Because I have a problem when there are 3 or more
Dired windows on the same frame.  Often dired-dwim
chooses a wrong window.  Maybe it should use something
like implemented in compare-windows-get-recent-window:

  (or (get-mru-window 'visible t t)
      (get-mru-window 0 t t)
      (get-mru-window t t t))




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#35385; Package emacs. (Sun, 23 Jun 2019 17:29:02 GMT) Full text and rfc822 format available.

Message #16 received at 35385 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: "Basil L. Contovounesios" <contovob <at> tcd.ie>
Cc: 35385 <at> debbugs.gnu.org
Subject: Re: bug#35385: 27.0.50; Make dired-dwim-target aware of other frames
Date: Sun, 23 Jun 2019 19:28:06 +0200
"Basil L. Contovounesios" <contovob <at> tcd.ie> writes:

> Currently, the user option dired-dwim-target applies only to windows
> displaying Dired buffers on the selected frame.  IWBNI this were
> customisable, so that Dired buffers displayed on other frames were also
> considered as default targets for file operations.  This would be useful
> for users like me who enable pop-up-frames.
>
> Patch implementing this to follow.

This makes sense to me, and the code in the patch looked OK.  But what
did you think of Juri's comments about dired-dwim-target-windows?

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#35385; Package emacs. (Mon, 16 Sep 2019 21:12:03 GMT) Full text and rfc822 format available.

Message #19 received at 35385 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: "Basil L. Contovounesios" <contovob <at> tcd.ie>
Cc: 35385 <at> debbugs.gnu.org
Subject: Re: bug#35385: 27.0.50; Make dired-dwim-target aware of other frames
Date: Mon, 16 Sep 2019 23:11:15 +0200
Lars Ingebrigtsen <larsi <at> gnus.org> writes:

> "Basil L. Contovounesios" <contovob <at> tcd.ie> writes:
>
>> Currently, the user option dired-dwim-target applies only to windows
>> displaying Dired buffers on the selected frame.  IWBNI this were
>> customisable, so that Dired buffers displayed on other frames were also
>> considered as default targets for file operations.  This would be useful
>> for users like me who enable pop-up-frames.
>>
>> Patch implementing this to follow.
>
> This makes sense to me, and the code in the patch looked OK.  But what
> did you think of Juri's comments about dired-dwim-target-windows?

That was 12 weeks ago.  Basil, have you had an opportunity to look at
this?

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#35385; Package emacs. (Mon, 16 Sep 2019 21:43:02 GMT) Full text and rfc822 format available.

Message #22 received at 35385 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: Lars Ingebrigtsen <larsi <at> gnus.org>
Cc: "Basil L. Contovounesios" <contovob <at> tcd.ie>, 35385 <at> debbugs.gnu.org
Subject: Re: bug#35385: 27.0.50; Make dired-dwim-target aware of other frames
Date: Tue, 17 Sep 2019 00:39:13 +0300
>>> Currently, the user option dired-dwim-target applies only to windows
>>> displaying Dired buffers on the selected frame.  IWBNI this were
>>> customisable, so that Dired buffers displayed on other frames were also
>>> considered as default targets for file operations.  This would be useful
>>> for users like me who enable pop-up-frames.
>>>
>>> Patch implementing this to follow.
>>
>> This makes sense to me, and the code in the patch looked OK.  But what
>> did you think of Juri's comments about dired-dwim-target-windows?
>
> That was 12 weeks ago.  Basil, have you had an opportunity to look at
> this?

I'd like to elaborate on my comments: the thought was that instead of
extending the scope of the search for the first random Dired window
from the selected frame to all frames, would it be better to improve the
heuristic of finding the window that the user really meant to use
(remember that the user option name contains the word "DWIM").

The proposed heuristic was to use `get-mru-window' to get
the most recently used window from all frames, and even
better way is to traverse all windows ordered by their visiting
recency on all frames to find the window with Dired mode buffer.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#35385; Package emacs. (Wed, 18 Sep 2019 21:52:02 GMT) Full text and rfc822 format available.

Message #25 received at 35385 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: Lars Ingebrigtsen <larsi <at> gnus.org>
Cc: "Basil L. Contovounesios" <contovob <at> tcd.ie>,
 martin rudalics <rudalics <at> gmx.at>, 35385 <at> debbugs.gnu.org
Subject: Re: bug#35385: 27.0.50; Make dired-dwim-target aware of other frames
Date: Thu, 19 Sep 2019 00:48:30 +0300
[Message part 1 (text/plain, inline)]
> I'd like to elaborate on my comments: the thought was that instead of
> extending the scope of the search for the first random Dired window
> from the selected frame to all frames, would it be better to improve the
> heuristic of finding the window that the user really meant to use
> (remember that the user option name contains the word "DWIM").
>
> The proposed heuristic was to use `get-mru-window' to get
> the most recently used window from all frames, and even
> better way is to traverse all windows ordered by their visiting
> recency on all frames to find the window with Dired mode buffer.

I can't find an existing function that would sort windows by recency,
but fortunately the implementation is straightforward:

  (sort (window-list-1)
        (lambda (a b)
          (> (window-use-time a)
             (window-use-time b))))

using `>' gives the mru order, `<' - lru order.

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:

[walk-windows-simplify.patch (text/x-diff, inline)]
diff --git a/lisp/window.el b/lisp/window.el
index cf733153b8..aedebd9d46 100644
--- a/lisp/window.el
+++ b/lisp/window.el
@@ -2217,6 +2217,10 @@ walk-windows
 
 - A frame means consider all windows on that frame only.
 
+If ALL-FRAMES specifies a frame, the first window walked is the
+first window on that frame (the one returned by `frame-first-window'),
+not necessarily the selected window.
+
 Anything else means consider all windows on the selected frame
 and no others.
 
@@ -2226,14 +2230,11 @@ walk-windows
   ;; back to it.
   (when (window-minibuffer-p)
     (setq minibuf t))
-  ;; Make sure to not mess up the order of recently selected
-  ;; windows.  Use `save-selected-window' and `select-window'
-  ;; with second argument non-nil for this purpose.
-  (save-selected-window
-    (when (framep all-frames)
-      (select-window (frame-first-window all-frames) 'norecord))
-    (dolist (walk-windows-window (window-list-1 nil minibuf all-frames))
-      (funcall fun walk-windows-window))))
+  (dolist (walk-windows-window
+           (window-list-1 (and (framep all-frames)
+                               (frame-first-window all-frames))
+                          minibuf all-frames))
+      (funcall fun walk-windows-window)))
 
 (defun window-at-side-p (&optional window side)
   "Return t if WINDOW is at SIDE of its containing frame.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#35385; Package emacs. (Thu, 19 Sep 2019 01:52:01 GMT) Full text and rfc822 format available.

Message #28 received at 35385 <at> debbugs.gnu.org (full text, mbox):

From: "Basil L. Contovounesios" <contovob <at> tcd.ie>
To: Lars Ingebrigtsen <larsi <at> gnus.org>
Cc: 35385 <at> debbugs.gnu.org
Subject: Re: bug#35385: 27.0.50; Make dired-dwim-target aware of other frames
Date: Thu, 19 Sep 2019 02:51:16 +0100
Lars Ingebrigtsen <larsi <at> gnus.org> writes:

> Lars Ingebrigtsen <larsi <at> gnus.org> writes:
>
>> This makes sense to me, and the code in the patch looked OK.  But what
>> did you think of Juri's comments about dired-dwim-target-windows?
>
> That was 12 weeks ago.  Basil, have you had an opportunity to look at
> this?

Sorry, I haven't had a chance to catch up with this stuff since my
summer holidays.  I'll try to have a look within the next week if no-one
beats me to it.

Thanks,

-- 
Basil




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#35385; Package emacs. (Thu, 19 Sep 2019 08:20:02 GMT) Full text and rfc822 format available.

Message #31 received at 35385 <at> debbugs.gnu.org (full text, mbox):

From: martin rudalics <rudalics <at> gmx.at>
To: Juri Linkov <juri <at> linkov.net>, Lars Ingebrigtsen <larsi <at> gnus.org>
Cc: "Basil L. Contovounesios" <contovob <at> tcd.ie>, 35385 <at> debbugs.gnu.org
Subject: Re: bug#35385: 27.0.50; Make dired-dwim-target aware of other frames
Date: Thu, 19 Sep 2019 10:18:45 +0200
> 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.

Personally, I would always try to use 'walk-window-tree' instead of
'walk-windows' reserving the latter for operations that are allowed to
create or delete windows.

martin




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#35385; Package emacs. (Thu, 19 Sep 2019 20:50:02 GMT) Full text and rfc822 format available.

Message #34 received at 35385 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: martin rudalics <rudalics <at> gmx.at>
Cc: "Basil L. Contovounesios" <contovob <at> tcd.ie>,
 Lars Ingebrigtsen <larsi <at> gnus.org>, 35385 <at> debbugs.gnu.org
Subject: Re: bug#35385: 27.0.50; Make dired-dwim-target aware of other frames
Date: Thu, 19 Sep 2019 23:43:37 +0300
[Message part 1 (text/plain, inline)]
>> 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:

[dired-dwim-target-directories.patch (text/x-diff, inline)]
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

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#35385; Package emacs. (Sat, 26 Oct 2019 23:22:01 GMT) Full text and rfc822 format available.

Message #37 received at 35385 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: 35385 <at> debbugs.gnu.org
Cc: "Basil L. Contovounesios" <contovob <at> tcd.ie>,
 Lars Ingebrigtsen <larsi <at> gnus.org>
Subject: Re: bug#35385: 27.0.50; Make dired-dwim-target aware of other frames
Date: Sun, 27 Oct 2019 02:20:44 +0300
> Now I prepared a patch for dired-dwim-target to DWIM most recently used
> windows from all frames:

Pushed to master.  Can this be closed now?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#35385; Package emacs. (Mon, 04 Nov 2019 19:02:02 GMT) Full text and rfc822 format available.

Message #40 received at 35385 <at> debbugs.gnu.org (full text, mbox):

From: Michael Heerdegen <michael_heerdegen <at> web.de>
To: Juri Linkov <juri <at> linkov.net>
Cc: "Basil L. Contovounesios" <contovob <at> tcd.ie>,
 Lars Ingebrigtsen <larsi <at> gnus.org>, 35385 <at> debbugs.gnu.org
Subject: Re: bug#35385: 27.0.50; Make dired-dwim-target aware of other frames
Date: Mon, 04 Nov 2019 20:01:45 +0100
Juri Linkov <juri <at> linkov.net> writes:

> > Now I prepared a patch for dired-dwim-target to DWIM most recently
> > used windows from all frames:
>
> Pushed to master.  Can this be closed now?

I wished this could be made configurable somehow.  FWIW I liked the
former behavior more so I :override advice
`dired-dwim-target-directories'.  It would be good if the used function
would at least be bound to a new defvar.  A defcustom with some
reasonable choices would probably be even better (old behavior + new
behavior would already be a good start).

Michael.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#35385; Package emacs. (Tue, 05 Nov 2019 22:59:02 GMT) Full text and rfc822 format available.

Message #43 received at 35385 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: Michael Heerdegen <michael_heerdegen <at> web.de>
Cc: "Basil L. Contovounesios" <contovob <at> tcd.ie>,
 Lars Ingebrigtsen <larsi <at> gnus.org>, 35385 <at> debbugs.gnu.org
Subject: Re: bug#35385: 27.0.50; Make dired-dwim-target aware of other frames
Date: Wed, 06 Nov 2019 00:18:32 +0200
> I wished this could be made configurable somehow.  FWIW I liked the
> former behavior more so I :override advice
> `dired-dwim-target-directories'.  It would be good if the used function
> would at least be bound to a new defvar.  A defcustom with some
> reasonable choices would probably be even better (old behavior + new
> behavior would already be a good start).

The idea to use the recent buffer was borrowed from compare-windows
that for backward-compatibility has such defcustom:

  (defcustom compare-windows-get-window-function
    'compare-windows-get-recent-window
    "Function that provides the window to compare with."
    :type '(choice
            (function-item :tag "Most recently used window"
                           compare-windows-get-recent-window)
            (function-item :tag "Next window"
                           compare-windows-get-next-window)
            (function :tag "Your function"))
    :group 'compare-windows
    :version "25.1")

So dired-dwim-target could have a similar defcustom
with choices for recent/next window.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#35385; Package emacs. (Fri, 08 Nov 2019 19:14:01 GMT) Full text and rfc822 format available.

Message #46 received at 35385 <at> debbugs.gnu.org (full text, mbox):

From: Michael Heerdegen <michael_heerdegen <at> web.de>
To: Juri Linkov <juri <at> linkov.net>
Cc: "Basil L. Contovounesios" <contovob <at> tcd.ie>,
 Lars Ingebrigtsen <larsi <at> gnus.org>, 35385 <at> debbugs.gnu.org
Subject: Re: bug#35385: 27.0.50; Make dired-dwim-target aware of other frames
Date: Fri, 08 Nov 2019 20:13:41 +0100
Juri Linkov <juri <at> linkov.net> writes:

> So dired-dwim-target could have a similar defcustom
> with choices for recent/next window.

There are lots of imaginable user preferences, so I would prefer a
solution where one can specify a function.  Would you want to use
`dired-dwim-target' for that?


Michael.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#35385; Package emacs. (Sun, 10 Nov 2019 20:57:02 GMT) Full text and rfc822 format available.

Message #49 received at 35385 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: Michael Heerdegen <michael_heerdegen <at> web.de>
Cc: "Basil L. Contovounesios" <contovob <at> tcd.ie>,
 Lars Ingebrigtsen <larsi <at> gnus.org>, 35385 <at> debbugs.gnu.org
Subject: Re: bug#35385: 27.0.50; Make dired-dwim-target aware of other frames
Date: Sun, 10 Nov 2019 22:38:38 +0200
[Message part 1 (text/plain, inline)]
>> So dired-dwim-target could have a similar defcustom
>> with choices for recent/next window.
>
> There are lots of imaginable user preferences, so I would prefer a
> solution where one can specify a function.  Would you want to use
> `dired-dwim-target' for that?

This would be a natural choice, indeed.

Please try this patch:

[dired-dwim-target-function.patch (text/x-diff, inline)]
diff --git a/lisp/dired.el b/lisp/dired.el
index 05789a3516..cfee990a74 100644
--- a/lisp/dired.el
+++ b/lisp/dired.el
@@ -190,8 +190,16 @@ dired-dwim-target
 Dired buffer's current directory.
 
 The target is used in the prompt for file copy, rename etc."
-  :type 'boolean
-  :group 'dired)
+  :type '(choice
+          (const :tag "No guess" nil)
+          (function-item :tag "Prefer most recently used windows"
+                         dired-dwim-target-recent)
+          (function-item :tag "Prefer next windows"
+                         dired-dwim-target-next)
+          (function :tag "Your function")
+          (other :tag "Try to guess" t))
+  :group 'dired
+  :version "27.1")
 
 (defcustom dired-copy-preserve-time t
   "If non-nil, Dired preserves the last-modified time in a file copy.
diff --git a/lisp/dired-aux.el b/lisp/dired-aux.el
index 722d036e3f..a3d0ad61dd 100644
--- a/lisp/dired-aux.el
+++ b/lisp/dired-aux.el
@@ -1993,6 +1993,12 @@ dired-mark-read-file-name
    (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-recent))))
+
+(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)
@@ -2004,6 +2010,15 @@ dired-dwim-target-directories
                                     (window-list-1 nil 'nomini 'visible)))
                       (lambda (a b) (> (car a) (car b))))))
 
+(defun dired-dwim-target-next ()
+  (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-directory ()
   ;; Try to guess which target directory the user may want.
   ;; If there is a dired buffer displayed in one of the next windows,

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#35385; Package emacs. (Tue, 12 Nov 2019 21:23:02 GMT) Full text and rfc822 format available.

Message #52 received at 35385 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: Michael Heerdegen <michael_heerdegen <at> web.de>
Cc: "Basil L. Contovounesios" <contovob <at> tcd.ie>,
 Lars Ingebrigtsen <larsi <at> gnus.org>, 35385 <at> debbugs.gnu.org
Subject: Re: bug#35385: 27.0.50; Make dired-dwim-target aware of other frames
Date: Tue, 12 Nov 2019 23:21:28 +0200
>>> So dired-dwim-target could have a similar defcustom
>>> with choices for recent/next window.
>>
>> There are lots of imaginable user preferences, so I would prefer a
>> solution where one can specify a function.  Would you want to use
>> `dired-dwim-target' for that?
>
> This would be a natural choice, indeed.

Now pushed to master.  Please close if everything is alright.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#35385; Package emacs. (Wed, 13 Nov 2019 15:31:02 GMT) Full text and rfc822 format available.

Message #55 received at 35385 <at> debbugs.gnu.org (full text, mbox):

From: Michael Heerdegen <michael_heerdegen <at> web.de>
To: Juri Linkov <juri <at> linkov.net>
Cc: "Basil L. Contovounesios" <contovob <at> tcd.ie>,
 Lars Ingebrigtsen <larsi <at> gnus.org>, 35385 <at> debbugs.gnu.org
Subject: Re: bug#35385: 27.0.50; Make dired-dwim-target aware of other frames
Date: Wed, 13 Nov 2019 16:30:11 +0100
Juri Linkov <juri <at> linkov.net> writes:

> Now pushed to master.  Please close if everything is alright.

Thanks.  Works well for me.  But I'm not yet happy with the docstring of
the option `dired-dwim-target'.

I think we should add that the non-nil value can be a function, and that
in this case that function will be called with zero arguments and is
expected to return a list of directories which will be used as defaults
(i.e. default target and "future history") (though,
`dired-dwim-target-defaults' might modify it a bit).

The sentence "You can customize it to prefer either the next window with
a Dired buffer, or the most recently used window with a Dired buffer."
could get appended "or something else".

Michael.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#35385; Package emacs. (Wed, 13 Nov 2019 21:51:02 GMT) Full text and rfc822 format available.

Message #58 received at 35385 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: Michael Heerdegen <michael_heerdegen <at> web.de>
Cc: "Basil L. Contovounesios" <contovob <at> tcd.ie>,
 Lars Ingebrigtsen <larsi <at> gnus.org>, 35385 <at> debbugs.gnu.org
Subject: Re: bug#35385: 27.0.50; Make dired-dwim-target aware of other frames
Date: Wed, 13 Nov 2019 23:41:16 +0200
> I think we should add that the non-nil value can be a function, and that
> in this case that function will be called with zero arguments and is
> expected to return a list of directories which will be used as defaults
> (i.e. default target and "future history") (though,
> `dired-dwim-target-defaults' might modify it a bit).
>
> The sentence "You can customize it to prefer either the next window with
> a Dired buffer, or the most recently used window with a Dired buffer."
> could get appended "or something else".

Do you think this is good enough?

diff --git a/doc/emacs/dired.texi b/doc/emacs/dired.texi
index 8fab508dea..d1863510d4 100644
--- a/doc/emacs/dired.texi
+++ b/doc/emacs/dired.texi
@@ -659,7 +659,10 @@ Operating on Files
 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.
+a Dired buffer, or to use any other function.  When the value is
+a function, it will be called with no arguments and is expected to
+return a list of directories which will be used as defaults
+(i.e. default target and ``future history'').
 
   Here are the file-manipulating Dired commands that operate on files.
 
diff --git a/lisp/dired.el b/lisp/dired.el
index 009018fafe..15286cc9b0 100644
--- a/lisp/dired.el
+++ b/lisp/dired.el
@@ -190,7 +190,11 @@ dired-dwim-target
 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.
+or the most recently used window with a Dired buffer, or to use any other
+function.  When the value is a function, it will be called with no
+arguments and is expected to return a list of directories which will
+be used as defaults (i.e. default target and \"future history\")
+(though, `dired-dwim-target-defaults' might modify it a bit).
 
 The target is used in the prompt for file copy, rename etc."
   :type '(choice




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#35385; Package emacs. (Thu, 14 Nov 2019 10:14:02 GMT) Full text and rfc822 format available.

Message #61 received at 35385 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Juri Linkov <juri <at> linkov.net>
Cc: michael_heerdegen <at> web.de, contovob <at> tcd.ie, larsi <at> gnus.org,
 35385 <at> debbugs.gnu.org
Subject: Re: bug#35385: 27.0.50; Make dired-dwim-target aware of other frames
Date: Thu, 14 Nov 2019 12:13:13 +0200
> From: Juri Linkov <juri <at> linkov.net>
> Date: Sun, 10 Nov 2019 22:38:38 +0200
> Cc: "Basil L. Contovounesios" <contovob <at> tcd.ie>,
>  Lars Ingebrigtsen <larsi <at> gnus.org>, 35385 <at> debbugs.gnu.org
> 
> +          (function-item :tag "Prefer next windows"
> +                         dired-dwim-target-next)

This is confusing, IMO.  What does "next windows" allude to?

> +          (function :tag "Your function")

Instead of "Your" I'd say "Custom" here.

Note that dired-dwim-target is described in the user manual, so there
should be a corresponding change in the manual (and in NEWS).

Thanks.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#35385; Package emacs. (Thu, 14 Nov 2019 15:09:02 GMT) Full text and rfc822 format available.

Message #64 received at 35385 <at> debbugs.gnu.org (full text, mbox):

From: Michael Heerdegen <michael_heerdegen <at> web.de>
To: Juri Linkov <juri <at> linkov.net>
Cc: "Basil L. Contovounesios" <contovob <at> tcd.ie>,
 Lars Ingebrigtsen <larsi <at> gnus.org>, 35385 <at> debbugs.gnu.org
Subject: Re: bug#35385: 27.0.50; Make dired-dwim-target aware of other frames
Date: Thu, 14 Nov 2019 16:08:55 +0100
Juri Linkov <juri <at> linkov.net> writes:

> Do you think this is good enough?

Looks quite good so far.  An open question is what the behavior of a
non-nil and not functionp value is.

BTW, when configuring `dired-dwim-target' to `dired-dwim-target-next'
and when the current dired buffer's window is the only dired window in
the selected frame, then the default target is not the current buffer's
directory but the directory of some other frame's dired.  I don't like
that.  I would want that always all dired windows in the current frame
are considered, including the current one.  I mean, operating on files
in one dired buffer is a quite common need, so defaulting to a directory
of some dired buffer in some other frame can be quite confusing.  I'm
accustomed to the old behavior of course but...it made sense to me.


Michael.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#35385; Package emacs. (Thu, 14 Nov 2019 23:22:01 GMT) Full text and rfc822 format available.

Message #67 received at 35385 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: michael_heerdegen <at> web.de, contovob <at> tcd.ie, larsi <at> gnus.org,
 35385 <at> debbugs.gnu.org
Subject: Re: bug#35385: 27.0.50; Make dired-dwim-target aware of other frames
Date: Fri, 15 Nov 2019 01:07:30 +0200
>> 
>> +          (function-item :tag "Prefer next windows"
>> +                         dired-dwim-target-next)
>
> This is confusing, IMO.  What does "next windows" allude to?

This is what was in the previous version of the docstring:

  "Dired buffer displayed in the next window"

>> +          (function :tag "Your function")
>
> Instead of "Your" I'd say "Custom" here.

Ok, will change to "Custom function".

> Note that dired-dwim-target is described in the user manual, so there
> should be a corresponding change in the manual (and in NEWS).

This is already mentioned in the manual and in NEWS.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#35385; Package emacs. (Thu, 14 Nov 2019 23:22:04 GMT) Full text and rfc822 format available.

Message #70 received at 35385 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: Michael Heerdegen <michael_heerdegen <at> web.de>
Cc: "Basil L. Contovounesios" <contovob <at> tcd.ie>,
 Lars Ingebrigtsen <larsi <at> gnus.org>, 35385 <at> debbugs.gnu.org
Subject: Re: bug#35385: 27.0.50; Make dired-dwim-target aware of other frames
Date: Fri, 15 Nov 2019 01:10:12 +0200
>> Do you think this is good enough?
>
> Looks quite good so far.  An open question is what the behavior of a
> non-nil and not functionp value is.

Maybe it should default to its previous behavior (i.e. the next window
on the selected frame).

> BTW, when configuring `dired-dwim-target' to `dired-dwim-target-next'
> and when the current dired buffer's window is the only dired window in
> the selected frame, then the default target is not the current buffer's
> directory but the directory of some other frame's dired.  I don't like
> that.  I would want that always all dired windows in the current frame
> are considered, including the current one.  I mean, operating on files
> in one dired buffer is a quite common need, so defaulting to a directory
> of some dired buffer in some other frame can be quite confusing.  I'm
> accustomed to the old behavior of course but...it made sense to me.

Maybe the value 't' should use the old behavior.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#35385; Package emacs. (Fri, 15 Nov 2019 12:17:02 GMT) Full text and rfc822 format available.

Message #73 received at 35385 <at> debbugs.gnu.org (full text, mbox):

From: Michael Heerdegen <michael_heerdegen <at> web.de>
To: Juri Linkov <juri <at> linkov.net>
Cc: "Basil L. Contovounesios" <contovob <at> tcd.ie>,
 Lars Ingebrigtsen <larsi <at> gnus.org>, 35385 <at> debbugs.gnu.org
Subject: Re: bug#35385: 27.0.50; Make dired-dwim-target aware of other frames
Date: Fri, 15 Nov 2019 13:16:47 +0100
Juri Linkov <juri <at> linkov.net> writes:

> Maybe the value 't' should use the old behavior.

That's what I thought, too.

Michael.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#35385; Package emacs. (Sat, 16 Nov 2019 22:08:02 GMT) Full text and rfc822 format available.

Message #76 received at 35385 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: Michael Heerdegen <michael_heerdegen <at> web.de>
Cc: "Basil L. Contovounesios" <contovob <at> tcd.ie>,
 Lars Ingebrigtsen <larsi <at> gnus.org>, 35385 <at> debbugs.gnu.org
Subject: Re: bug#35385: 27.0.50; Make dired-dwim-target aware of other frames
Date: Sun, 17 Nov 2019 00:06:32 +0200
>> Maybe the value 't' should use the old behavior.
>
> That's what I thought, too.

Now this is implemented.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#35385; Package emacs. (Sat, 16 Nov 2019 22:43:02 GMT) Full text and rfc822 format available.

Message #79 received at 35385 <at> debbugs.gnu.org (full text, mbox):

From: Michael Heerdegen <michael_heerdegen <at> web.de>
To: Juri Linkov <juri <at> linkov.net>
Cc: "Basil L. Contovounesios" <contovob <at> tcd.ie>,
 Lars Ingebrigtsen <larsi <at> gnus.org>, 35385 <at> debbugs.gnu.org
Subject: Re: bug#35385: 27.0.50; Make dired-dwim-target aware of other frames
Date: Sat, 16 Nov 2019 23:42:13 +0100
Juri Linkov <juri <at> linkov.net> writes:

> >> Maybe the value 't' should use the old behavior.
> >
> > That's what I thought, too.
>
> Now this is implemented.

Tested quickly, seems to work well so far.  I'll continue to use it.

Thanks,

Michael.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#35385; Package emacs. (Mon, 10 Aug 2020 11:38:01 GMT) Full text and rfc822 format available.

Message #82 received at 35385 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Michael Heerdegen <michael_heerdegen <at> web.de>
Cc: "Basil L. Contovounesios" <contovob <at> tcd.ie>, 35385 <at> debbugs.gnu.org,
 Juri Linkov <juri <at> linkov.net>
Subject: Re: bug#35385: 27.0.50; Make dired-dwim-target aware of other frames
Date: Mon, 10 Aug 2020 13:36:53 +0200
Michael Heerdegen <michael_heerdegen <at> web.de> writes:

> Juri Linkov <juri <at> linkov.net> writes:
>
>> >> Maybe the value 't' should use the old behavior.
>> >
>> > That's what I thought, too.
>>
>> Now this is implemented.
>
> Tested quickly, seems to work well so far.  I'll continue to use it.

If I understand correctly, this was fixed by extending dired-dwim-target
with this:

          (function-item :tag "Prefer next windows on the same frame"
                         dired-dwim-target-next)
          (function-item :tag "Prefer next windows on visible frames"
                         dired-dwim-target-next-visible)

instead of adding a new variable, as the original patch proposed.  So
I'm closing this bug report; if there was anything further to fix here,
please reopen.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




bug closed, send any further explanations to 35385 <at> debbugs.gnu.org and "Basil L. Contovounesios" <contovob <at> tcd.ie> Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Mon, 10 Aug 2020 11:38:02 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Tue, 08 Sep 2020 11:24:12 GMT) Full text and rfc822 format available.

This bug report was last modified 3 years and 223 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.