unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#35385: 27.0.50; Make dired-dwim-target aware of other frames
@ 2019-04-22 21:47 Basil L. Contovounesios
  2019-04-22 22:11 ` Basil L. Contovounesios
  2019-06-23 17:28 ` Lars Ingebrigtsen
  0 siblings, 2 replies; 26+ messages in thread
From: Basil L. Contovounesios @ 2019-04-22 21:47 UTC (permalink / raw)
  To: 35385

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





^ permalink raw reply	[flat|nested] 26+ messages in thread

* bug#35385: 27.0.50; Make dired-dwim-target aware of other frames
  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
  1 sibling, 1 reply; 26+ messages in thread
From: Basil L. Contovounesios @ 2019-04-22 22:11 UTC (permalink / raw)
  To: 35385

[-- Attachment #1: Type: text/plain, Size: 23 bytes --]

tags 35385 patch
quit


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Make-dired-dwim-target-aware-of-other-frames.patch --]
[-- Type: text/x-diff, Size: 7780 bytes --]

From 463ccbe8ba96aee0a2cdfd49342270a33e161db2 Mon Sep 17 00:00:00 2001
From: "Basil L. Contovounesios" <contovob@tcd.ie>
Date: Mon, 22 Apr 2019 14:33:38 +0100
Subject: [PATCH] Make dired-dwim-target aware of other frames

* lisp/dired.el (dired-dwim-target-frames): New user
option. (bug#35385)
(dired-dwim-target): Mention it in docstring.
* lisp/dired-aux.el (dired-dwim-target-directory): Use it.
* doc/emacs/dired.texi (Operating on Files): Document it.
* etc/NEWS: Announce it.  Merge duplicate Dired outlines.
* test/lisp/dired-tests.el: Remove unnecessary require and pacify
byte-compiler.
---
 doc/emacs/dired.texi     | 23 ++++++++++++++++++++---
 etc/NEWS                 | 16 +++++++++-------
 lisp/dired-aux.el        | 34 +++++++++++++++++-----------------
 lisp/dired.el            | 20 +++++++++++++++++---
 test/lisp/dired-tests.el |  3 +--
 5 files changed, 64 insertions(+), 32 deletions(-)

diff --git a/doc/emacs/dired.texi b/doc/emacs/dired.texi
index 9f454ea2ad..b8b1d73d8f 100644
--- a/doc/emacs/dired.texi
+++ b/doc/emacs/dired.texi
@@ -644,13 +644,30 @@ Operating on Files
 commands, use the same conventions to decide which files to work on.
 
 @vindex dired-dwim-target
+@vindex dired-dwim-target-frames
 @cindex two directories (in Dired)
   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 the
-next window, 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
+another window, that other buffer's directory is suggested instead.  The
+option @code{dired-dwim-target-frames} controls which windows to
+consider:
+
+@itemize @bullet
+@item @code{nil}
+means to consider windows on the selected frame.
+
+@item @code{t}
+means to consider windows on all existing frames.
+
+@item @code{visible}
+means to consider windows on all visible frames.
+
+@item 0
+means to consider windows on all frames on the current terminal.
+@end itemize
 
   Here are the file-manipulating Dired commands that operate on files.
 
diff --git a/etc/NEWS b/etc/NEWS
index b13ab47768..d1761c6415 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -507,6 +507,15 @@ remapped to these, respectively.
 +++
 *** New command 'dired-create-empty-file'.
 
++++
+*** The new user option 'dired-create-destination-dirs' controls whether
+'dired-do-copy' and 'dired-rename-file' should create non-existent
+directories in the destination.
+
++++
+*** New user option 'dired-dwim-target-frames'.
+This option controls which frames 'dired-dwim-target' applies to.
+
 ** Change Logs and VC
 
 *** Recording ChangeLog entries doesn't require an actual file.
@@ -857,13 +866,6 @@ unescaping text.
 The maximum level is used by default; customize
 'font-lock-maximum-decoration' to tone down the decoration.
 
-** Dired
-
-+++
-*** The new user option 'dired-create-destination-dirs' controls whether
-'dired-do-copy' and 'dired-rename-file' should create non-existent
-directories in the destination.
-
 ** Help
 
 ---
diff --git a/lisp/dired-aux.el b/lisp/dired-aux.el
index b81c0d1a4f..c3df5c982b 100644
--- a/lisp/dired-aux.el
+++ b/lisp/dired-aux.el
@@ -1937,23 +1937,21 @@ dired-mark-read-file-name
    (format prompt (dired-mark-prompt arg files)) dir default))
 
 (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,
-  ;; use its current subdir, else use current subdir of this dired buffer.
-  (let ((this-dir (and (eq major-mode 'dired-mode)
-		       (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))
-      this-dir)))
+  "Try to guess which target directory the user may want.
+If there is a Dired buffer displayed in another window (subject
+to `dired-dwim-target' and `dired-dwim-target-frames'), return
+its current subdirectory, otherwise return that of the current
+Dired buffer."
+  (let ((win (if dired-dwim-target
+                 (get-window-with-predicate
+                  (lambda (window)
+                    (with-current-buffer (window-buffer window)
+                      (eq major-mode 'dired-mode)))
+                  nil dired-dwim-target-frames (selected-window))
+               (selected-window))))
+    (with-current-buffer (window-buffer win)
+      (and (eq major-mode 'dired-mode)
+           (dired-current-directory)))))
 
 (defun dired-dwim-target-defaults (fn-list target-dir)
   ;; Return a list of default values for file-reading functions in Dired.
@@ -2839,6 +2837,8 @@ dired-do-isearch-regexp
   (multi-isearch-files-regexp
    (dired-get-marked-files nil nil 'dired-nondirectory-p nil t)))
 
+(declare-function fileloop-continue "fileloop" ())
+
 ;;;###autoload
 (defun dired-do-search (regexp)
   "Search through all marked files for a match for REGEXP.
diff --git a/lisp/dired.el b/lisp/dired.el
index 63082fe392..710fcfc0f4 100644
--- a/lisp/dired.el
+++ b/lisp/dired.el
@@ -185,14 +185,28 @@ 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 some window,
+use its current directory, instead of this Dired buffer's current
+directory.  See `dired-dwim-target-frames' for which frames to
+consider when looking for a target window.
 
 The target is used in the prompt for file copy, rename etc."
   :type 'boolean
   :group 'dired)
 
+(defcustom dired-dwim-target-frames nil
+  "Determines which frames to consider for `dired-dwim-target'.
+It has a similar meaning to the ALL-FRAMES argument of
+`next-window'.  nil means consider windows on only the selected
+frame; t on all existing frames; `visible' on all visible frames;
+and 0 on all frames on the current terminal."
+  :type '(choice (const :tag "Selected frame only" nil)
+                 (const :tag "All existing frames" t)
+                 (const :tag "All visible frames" visible)
+                 (const :tag "All frames on current terminal" 0))
+  :version "27.1"
+  :group 'dired)
+
 (defcustom dired-copy-preserve-time t
   "If non-nil, Dired preserves the last-modified time in a file copy.
 \(This works on only some systems.)"
diff --git a/test/lisp/dired-tests.el b/test/lisp/dired-tests.el
index 71ffcdd545..c4728e7a06 100644
--- a/test/lisp/dired-tests.el
+++ b/test/lisp/dired-tests.el
@@ -20,7 +20,6 @@
 ;;; Code:
 (require 'ert)
 (require 'dired)
-(require 'nadvice)
 
 (ert-deftest dired-autoload ()
   "Tests to see whether dired-x has been autoloaded"
@@ -54,7 +53,7 @@
         (when (buffer-live-p buf) (kill-buffer buf)))
       (delete-directory dir 'recursive))))
 
-(defvar dired-dwim-target)
+(defvar dired-query)
 (ert-deftest dired-test-bug25609 ()
   "Test for https://debbugs.gnu.org/25609 ."
   (let* ((from (make-temp-file "foo" 'dir))
-- 
2.20.1


[-- Attachment #3: Type: text/plain, Size: 133 bytes --]


"Basil L. Contovounesios" <contovob@tcd.ie> writes:

> Patch implementing this to follow.

Now attached.  WDYT?

Thanks,

-- 
Basil

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* bug#35385: 27.0.50; Make dired-dwim-target aware of other frames
  2019-04-22 22:11 ` Basil L. Contovounesios
@ 2019-04-29 20:28   ` Juri Linkov
  0 siblings, 0 replies; 26+ messages in thread
From: Juri Linkov @ 2019-04-29 20:28 UTC (permalink / raw)
  To: Basil L. Contovounesios; +Cc: 35385

> 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))





^ permalink raw reply	[flat|nested] 26+ messages in thread

* bug#35385: 27.0.50; Make dired-dwim-target aware of other frames
  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-06-23 17:28 ` Lars Ingebrigtsen
  2019-09-16 21:11   ` Lars Ingebrigtsen
  1 sibling, 1 reply; 26+ messages in thread
From: Lars Ingebrigtsen @ 2019-06-23 17:28 UTC (permalink / raw)
  To: Basil L. Contovounesios; +Cc: 35385

"Basil L. Contovounesios" <contovob@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





^ permalink raw reply	[flat|nested] 26+ messages in thread

* bug#35385: 27.0.50; Make dired-dwim-target aware of other frames
  2019-06-23 17:28 ` Lars Ingebrigtsen
@ 2019-09-16 21:11   ` Lars Ingebrigtsen
  2019-09-16 21:39     ` Juri Linkov
  2019-09-19  1:51     ` Basil L. Contovounesios
  0 siblings, 2 replies; 26+ messages in thread
From: Lars Ingebrigtsen @ 2019-09-16 21:11 UTC (permalink / raw)
  To: Basil L. Contovounesios; +Cc: 35385

Lars Ingebrigtsen <larsi@gnus.org> writes:

> "Basil L. Contovounesios" <contovob@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





^ permalink raw reply	[flat|nested] 26+ messages in thread

* bug#35385: 27.0.50; Make dired-dwim-target aware of other frames
  2019-09-16 21:11   ` Lars Ingebrigtsen
@ 2019-09-16 21:39     ` Juri Linkov
  2019-09-18 21:48       ` Juri Linkov
  2019-09-19  1:51     ` Basil L. Contovounesios
  1 sibling, 1 reply; 26+ messages in thread
From: Juri Linkov @ 2019-09-16 21:39 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: Basil L. Contovounesios, 35385

>>> 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.





^ permalink raw reply	[flat|nested] 26+ messages in thread

* bug#35385: 27.0.50; Make dired-dwim-target aware of other frames
  2019-09-16 21:39     ` Juri Linkov
@ 2019-09-18 21:48       ` Juri Linkov
  2019-09-19  8:18         ` martin rudalics
  0 siblings, 1 reply; 26+ messages in thread
From: Juri Linkov @ 2019-09-18 21:48 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: Basil L. Contovounesios, 35385

[-- Attachment #1: Type: text/plain, Size: 1061 bytes --]

> 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:


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: walk-windows-simplify.patch --]
[-- Type: text/x-diff, Size: 1357 bytes --]

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.

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* bug#35385: 27.0.50; Make dired-dwim-target aware of other frames
  2019-09-16 21:11   ` Lars Ingebrigtsen
  2019-09-16 21:39     ` Juri Linkov
@ 2019-09-19  1:51     ` Basil L. Contovounesios
  1 sibling, 0 replies; 26+ messages in thread
From: Basil L. Contovounesios @ 2019-09-19  1:51 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 35385

Lars Ingebrigtsen <larsi@gnus.org> writes:

> Lars Ingebrigtsen <larsi@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





^ permalink raw reply	[flat|nested] 26+ messages in thread

* bug#35385: 27.0.50; Make dired-dwim-target aware of other frames
  2019-09-18 21:48       ` Juri Linkov
@ 2019-09-19  8:18         ` martin rudalics
  2019-09-19 20:43           ` Juri Linkov
  0 siblings, 1 reply; 26+ messages in thread
From: martin rudalics @ 2019-09-19  8:18 UTC (permalink / raw)
  To: Juri Linkov, Lars Ingebrigtsen; +Cc: Basil L. Contovounesios, 35385

 > 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





^ permalink raw reply	[flat|nested] 26+ messages in thread

* bug#35385: 27.0.50; Make dired-dwim-target aware of other frames
  2019-09-19  8:18         ` martin rudalics
@ 2019-09-19 20:43           ` Juri Linkov
  2019-10-26 23:20             ` Juri Linkov
  0 siblings, 1 reply; 26+ messages in thread
From: Juri Linkov @ 2019-09-19 20:43 UTC (permalink / raw)
  To: martin rudalics; +Cc: Basil L. Contovounesios, Lars Ingebrigtsen, 35385

[-- 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

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* bug#35385: 27.0.50; Make dired-dwim-target aware of other frames
  2019-09-19 20:43           ` Juri Linkov
@ 2019-10-26 23:20             ` Juri Linkov
  2019-11-04 19:01               ` Michael Heerdegen
  0 siblings, 1 reply; 26+ messages in thread
From: Juri Linkov @ 2019-10-26 23:20 UTC (permalink / raw)
  To: 35385; +Cc: Basil L. Contovounesios, Lars Ingebrigtsen

> 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?





^ permalink raw reply	[flat|nested] 26+ messages in thread

* bug#35385: 27.0.50; Make dired-dwim-target aware of other frames
  2019-10-26 23:20             ` Juri Linkov
@ 2019-11-04 19:01               ` Michael Heerdegen
  2019-11-05 22:18                 ` Juri Linkov
  0 siblings, 1 reply; 26+ messages in thread
From: Michael Heerdegen @ 2019-11-04 19:01 UTC (permalink / raw)
  To: Juri Linkov; +Cc: Basil L. Contovounesios, Lars Ingebrigtsen, 35385

Juri Linkov <juri@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.





^ permalink raw reply	[flat|nested] 26+ messages in thread

* bug#35385: 27.0.50; Make dired-dwim-target aware of other frames
  2019-11-04 19:01               ` Michael Heerdegen
@ 2019-11-05 22:18                 ` Juri Linkov
  2019-11-08 19:13                   ` Michael Heerdegen
  0 siblings, 1 reply; 26+ messages in thread
From: Juri Linkov @ 2019-11-05 22:18 UTC (permalink / raw)
  To: Michael Heerdegen; +Cc: Basil L. Contovounesios, Lars Ingebrigtsen, 35385

> 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.





^ permalink raw reply	[flat|nested] 26+ messages in thread

* bug#35385: 27.0.50; Make dired-dwim-target aware of other frames
  2019-11-05 22:18                 ` Juri Linkov
@ 2019-11-08 19:13                   ` Michael Heerdegen
  2019-11-10 20:38                     ` Juri Linkov
  0 siblings, 1 reply; 26+ messages in thread
From: Michael Heerdegen @ 2019-11-08 19:13 UTC (permalink / raw)
  To: Juri Linkov; +Cc: Basil L. Contovounesios, Lars Ingebrigtsen, 35385

Juri Linkov <juri@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.





^ permalink raw reply	[flat|nested] 26+ messages in thread

* bug#35385: 27.0.50; Make dired-dwim-target aware of other frames
  2019-11-08 19:13                   ` Michael Heerdegen
@ 2019-11-10 20:38                     ` Juri Linkov
  2019-11-12 21:21                       ` Juri Linkov
  2019-11-14 10:13                       ` Eli Zaretskii
  0 siblings, 2 replies; 26+ messages in thread
From: Juri Linkov @ 2019-11-10 20:38 UTC (permalink / raw)
  To: Michael Heerdegen; +Cc: Basil L. Contovounesios, Lars Ingebrigtsen, 35385

[-- Attachment #1: Type: text/plain, Size: 332 bytes --]

>> 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:


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: dired-dwim-target-function.patch --]
[-- Type: text/x-diff, Size: 2190 bytes --]

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,

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* bug#35385: 27.0.50; Make dired-dwim-target aware of other frames
  2019-11-10 20:38                     ` Juri Linkov
@ 2019-11-12 21:21                       ` Juri Linkov
  2019-11-13 15:30                         ` Michael Heerdegen
  2019-11-14 10:13                       ` Eli Zaretskii
  1 sibling, 1 reply; 26+ messages in thread
From: Juri Linkov @ 2019-11-12 21:21 UTC (permalink / raw)
  To: Michael Heerdegen; +Cc: Basil L. Contovounesios, Lars Ingebrigtsen, 35385

>>> 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.





^ permalink raw reply	[flat|nested] 26+ messages in thread

* bug#35385: 27.0.50; Make dired-dwim-target aware of other frames
  2019-11-12 21:21                       ` Juri Linkov
@ 2019-11-13 15:30                         ` Michael Heerdegen
  2019-11-13 21:41                           ` Juri Linkov
  0 siblings, 1 reply; 26+ messages in thread
From: Michael Heerdegen @ 2019-11-13 15:30 UTC (permalink / raw)
  To: Juri Linkov; +Cc: Basil L. Contovounesios, Lars Ingebrigtsen, 35385

Juri Linkov <juri@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.





^ permalink raw reply	[flat|nested] 26+ messages in thread

* bug#35385: 27.0.50; Make dired-dwim-target aware of other frames
  2019-11-13 15:30                         ` Michael Heerdegen
@ 2019-11-13 21:41                           ` Juri Linkov
  2019-11-14 15:08                             ` Michael Heerdegen
  0 siblings, 1 reply; 26+ messages in thread
From: Juri Linkov @ 2019-11-13 21:41 UTC (permalink / raw)
  To: Michael Heerdegen; +Cc: Basil L. Contovounesios, Lars Ingebrigtsen, 35385

> 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





^ permalink raw reply related	[flat|nested] 26+ messages in thread

* bug#35385: 27.0.50; Make dired-dwim-target aware of other frames
  2019-11-10 20:38                     ` Juri Linkov
  2019-11-12 21:21                       ` Juri Linkov
@ 2019-11-14 10:13                       ` Eli Zaretskii
  2019-11-14 23:07                         ` Juri Linkov
  1 sibling, 1 reply; 26+ messages in thread
From: Eli Zaretskii @ 2019-11-14 10:13 UTC (permalink / raw)
  To: Juri Linkov; +Cc: michael_heerdegen, contovob, larsi, 35385

> From: Juri Linkov <juri@linkov.net>
> Date: Sun, 10 Nov 2019 22:38:38 +0200
> Cc: "Basil L. Contovounesios" <contovob@tcd.ie>,
>  Lars Ingebrigtsen <larsi@gnus.org>, 35385@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.





^ permalink raw reply	[flat|nested] 26+ messages in thread

* bug#35385: 27.0.50; Make dired-dwim-target aware of other frames
  2019-11-13 21:41                           ` Juri Linkov
@ 2019-11-14 15:08                             ` Michael Heerdegen
  2019-11-14 23:10                               ` Juri Linkov
  0 siblings, 1 reply; 26+ messages in thread
From: Michael Heerdegen @ 2019-11-14 15:08 UTC (permalink / raw)
  To: Juri Linkov; +Cc: Basil L. Contovounesios, Lars Ingebrigtsen, 35385

Juri Linkov <juri@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.





^ permalink raw reply	[flat|nested] 26+ messages in thread

* bug#35385: 27.0.50; Make dired-dwim-target aware of other frames
  2019-11-14 10:13                       ` Eli Zaretskii
@ 2019-11-14 23:07                         ` Juri Linkov
  0 siblings, 0 replies; 26+ messages in thread
From: Juri Linkov @ 2019-11-14 23:07 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: michael_heerdegen, contovob, larsi, 35385

>> 
>> +          (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.





^ permalink raw reply	[flat|nested] 26+ messages in thread

* bug#35385: 27.0.50; Make dired-dwim-target aware of other frames
  2019-11-14 15:08                             ` Michael Heerdegen
@ 2019-11-14 23:10                               ` Juri Linkov
  2019-11-15 12:16                                 ` Michael Heerdegen
  0 siblings, 1 reply; 26+ messages in thread
From: Juri Linkov @ 2019-11-14 23:10 UTC (permalink / raw)
  To: Michael Heerdegen; +Cc: Basil L. Contovounesios, Lars Ingebrigtsen, 35385

>> 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.





^ permalink raw reply	[flat|nested] 26+ messages in thread

* bug#35385: 27.0.50; Make dired-dwim-target aware of other frames
  2019-11-14 23:10                               ` Juri Linkov
@ 2019-11-15 12:16                                 ` Michael Heerdegen
  2019-11-16 22:06                                   ` Juri Linkov
  0 siblings, 1 reply; 26+ messages in thread
From: Michael Heerdegen @ 2019-11-15 12:16 UTC (permalink / raw)
  To: Juri Linkov; +Cc: Basil L. Contovounesios, Lars Ingebrigtsen, 35385

Juri Linkov <juri@linkov.net> writes:

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

That's what I thought, too.

Michael.





^ permalink raw reply	[flat|nested] 26+ messages in thread

* bug#35385: 27.0.50; Make dired-dwim-target aware of other frames
  2019-11-15 12:16                                 ` Michael Heerdegen
@ 2019-11-16 22:06                                   ` Juri Linkov
  2019-11-16 22:42                                     ` Michael Heerdegen
  0 siblings, 1 reply; 26+ messages in thread
From: Juri Linkov @ 2019-11-16 22:06 UTC (permalink / raw)
  To: Michael Heerdegen; +Cc: Basil L. Contovounesios, Lars Ingebrigtsen, 35385

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

Now this is implemented.





^ permalink raw reply	[flat|nested] 26+ messages in thread

* bug#35385: 27.0.50; Make dired-dwim-target aware of other frames
  2019-11-16 22:06                                   ` Juri Linkov
@ 2019-11-16 22:42                                     ` Michael Heerdegen
  2020-08-10 11:36                                       ` Lars Ingebrigtsen
  0 siblings, 1 reply; 26+ messages in thread
From: Michael Heerdegen @ 2019-11-16 22:42 UTC (permalink / raw)
  To: Juri Linkov; +Cc: Basil L. Contovounesios, Lars Ingebrigtsen, 35385

Juri Linkov <juri@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.





^ permalink raw reply	[flat|nested] 26+ messages in thread

* bug#35385: 27.0.50; Make dired-dwim-target aware of other frames
  2019-11-16 22:42                                     ` Michael Heerdegen
@ 2020-08-10 11:36                                       ` Lars Ingebrigtsen
  0 siblings, 0 replies; 26+ messages in thread
From: Lars Ingebrigtsen @ 2020-08-10 11:36 UTC (permalink / raw)
  To: Michael Heerdegen; +Cc: Basil L. Contovounesios, 35385, Juri Linkov

Michael Heerdegen <michael_heerdegen@web.de> writes:

> Juri Linkov <juri@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





^ permalink raw reply	[flat|nested] 26+ messages in thread

end of thread, other threads:[~2020-08-10 11:36 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
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

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).