From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.bugs Subject: bug#35385: 27.0.50; Make dired-dwim-target aware of other frames Date: Thu, 19 Sep 2019 23:43:37 +0300 Organization: LINKOV.NET Message-ID: <87y2yknhja.fsf@mail.linkov.net> References: <87k1fl3e6z.fsf@tcd.ie> <87zhj4osjw.fsf@gnus.org> <877e67x6ny.fsf@mail.linkov.net> <87impp1djl.fsf@mail.linkov.net> <138859c1-a7e0-f40d-4623-635826decd90@gmx.at> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="96925"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (x86_64-pc-linux-gnu) Cc: "Basil L. Contovounesios" , Lars Ingebrigtsen , 35385@debbugs.gnu.org To: martin rudalics Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Sep 19 22:55:54 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1iB3T0-000P7H-1y for geb-bug-gnu-emacs@m.gmane.org; Thu, 19 Sep 2019 22:55:54 +0200 Original-Received: from localhost ([::1]:48468 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iB3Sy-0007D9-RJ for geb-bug-gnu-emacs@m.gmane.org; Thu, 19 Sep 2019 16:55:52 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:49916) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iB3So-00073J-8t for bug-gnu-emacs@gnu.org; Thu, 19 Sep 2019 16:55:43 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iB3NL-0003A9-3o for bug-gnu-emacs@gnu.org; Thu, 19 Sep 2019 16:50:05 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:47676) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iB3NK-0003A3-SL for bug-gnu-emacs@gnu.org; Thu, 19 Sep 2019 16:50:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1iB3NK-0000AU-N0 for bug-gnu-emacs@gnu.org; Thu, 19 Sep 2019 16:50:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 19 Sep 2019 20:50:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 35385 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 35385-submit@debbugs.gnu.org id=B35385.1568926187619 (code B ref 35385); Thu, 19 Sep 2019 20:50:02 +0000 Original-Received: (at 35385) by debbugs.gnu.org; 19 Sep 2019 20:49:47 +0000 Original-Received: from localhost ([127.0.0.1]:56497 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1iB3N5-00009u-92 for submit@debbugs.gnu.org; Thu, 19 Sep 2019 16:49:47 -0400 Original-Received: from bonobo.elm.relay.mailchannels.net ([23.83.212.22]:64977) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1iB3N3-00009m-MI for 35385@debbugs.gnu.org; Thu, 19 Sep 2019 16:49:46 -0400 X-Sender-Id: dreamhost|x-authsender|jurta@jurta.org Original-Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id CA09B341F65; Thu, 19 Sep 2019 20:49:44 +0000 (UTC) Original-Received: from pdx1-sub0-mail-a17.g.dreamhost.com (100-96-169-125.trex.outbound.svc.cluster.local [100.96.169.125]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 44113342BD5; Thu, 19 Sep 2019 20:49:44 +0000 (UTC) X-Sender-Id: dreamhost|x-authsender|jurta@jurta.org Original-Received: from pdx1-sub0-mail-a17.g.dreamhost.com ([TEMPUNAVAIL]. [64.90.62.162]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384) by 0.0.0.0:2500 (trex/5.17.5); Thu, 19 Sep 2019 20:49:44 +0000 X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|jurta@jurta.org X-MailChannels-Auth-Id: dreamhost X-Plucky-Towering: 32df8e9a6033807d_1568926184543_181628879 X-MC-Loop-Signature: 1568926184543:3577326187 X-MC-Ingress-Time: 1568926184543 Original-Received: from pdx1-sub0-mail-a17.g.dreamhost.com (localhost [127.0.0.1]) by pdx1-sub0-mail-a17.g.dreamhost.com (Postfix) with ESMTP id EB0D1836B1; Thu, 19 Sep 2019 13:49:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=linkov.net; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type; s=linkov.net; bh=B2V6s2+LLG0twCoJkF/NppQsRro=; b= Wf1MPfmq5I4NZLPCsfC2fBfM2bSNnIpYqeEzR4OgZReHIwmf4uN+fd18f91Gp+QH xHwlcErrdATIV+MAsKUuzfeJQTMEftnUQqwHjmrV7d7TZ53A4FwXLtecI8zntt4T LeTo04FHqZv/bHrgKo5JIQA+ZWSFn5y06fEZdHa7itw= Original-Received: from mail.jurta.org (m91-129-107-243.cust.tele2.ee [91.129.107.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: jurta@jurta.org) by pdx1-sub0-mail-a17.g.dreamhost.com (Postfix) with ESMTPSA id 2530A836B7; Thu, 19 Sep 2019 13:49:37 -0700 (PDT) X-DH-BACKEND: pdx1-sub0-mail-a17 In-Reply-To: <138859c1-a7e0-f40d-4623-635826decd90@gmx.at> (martin rudalics's message of "Thu, 19 Sep 2019 10:18:45 +0200") X-VR-OUT-STATUS: OK X-VR-OUT-SCORE: -100 X-VR-OUT-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedufedrvddtgdduheehucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuggftfghnshhusghstghrihgsvgdpffftgfetoffjqffuvfenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvufhofhffjgfkfgggtgesmhdtreertdertdenucfhrhhomheplfhurhhiucfnihhnkhhovhcuoehjuhhriheslhhinhhkohhvrdhnvghtqeenucfkphepledurdduvdelrddutdejrddvgeefnecurfgrrhgrmhepmhhouggvpehsmhhtphdphhgvlhhopehmrghilhdrjhhurhhtrgdrohhrghdpihhnvghtpeeluddruddvledruddtjedrvdegfedprhgvthhurhhnqdhprghthheplfhurhhiucfnihhnkhhovhcuoehjuhhriheslhhinhhkohhvrdhnvghtqedpmhgrihhlfhhrohhmpehjuhhriheslhhinhhkohhvrdhnvghtpdhnrhgtphhtthhopehruhgurghlihgtshesghhmgidrrghtnecuvehluhhsthgvrhfuihiivgeptd X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:166733 Archived-At: --=-=-= Content-Type: text/plain >> 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: --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=dired-dwim-target-directories.patch 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 --=-=-=--