From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.devel Subject: dired-dwim-target-directory (was: find-file-read-args) Date: Tue, 17 Nov 2009 19:42:33 +0200 Organization: JURTA Message-ID: <87einxayb2.fsf_-_@mail.jurta.org> References: <3b31caf90911051613w80af4cu61352a29ce5dcd77@mail.gmail.com> <87vdhoe73d.fsf@mail.jurta.org> <87y6mkb6qr.fsf@mail.jurta.org> <87bpjfiark.fsf@mail.jurta.org> <871vk8uo0q.fsf@mail.jurta.org> <87ocn8ayrw.fsf@mail.jurta.org> <4AFBE741.1040506@gmx.at> <87tyx05849.fsf@mail.jurta.org> <871vjz27lw.fsf@mail.jurta.org> <4B003A50.30601@gmx.at> <4B025430.1010204@gmx.at> <87my2ljxun.fsf@mail.jurta.org> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1258480765 22493 80.91.229.12 (17 Nov 2009 17:59:25 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 17 Nov 2009 17:59:25 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Nov 17 18:59:18 2009 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1NASKi-0000nx-Ab for ged-emacs-devel@m.gmane.org; Tue, 17 Nov 2009 18:59:16 +0100 Original-Received: from localhost ([127.0.0.1]:60950 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NASKh-00035N-VM for ged-emacs-devel@m.gmane.org; Tue, 17 Nov 2009 12:59:15 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NASKc-00034w-8j for emacs-devel@gnu.org; Tue, 17 Nov 2009 12:59:10 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NASKX-000313-Kb for emacs-devel@gnu.org; Tue, 17 Nov 2009 12:59:09 -0500 Original-Received: from [199.232.76.173] (port=53328 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NASKX-00030y-FS for emacs-devel@gnu.org; Tue, 17 Nov 2009 12:59:05 -0500 Original-Received: from smtp-out1.starman.ee ([85.253.0.3]:38760 helo=mx1.starman.ee) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NASKW-0007JX-Qy for emacs-devel@gnu.org; Tue, 17 Nov 2009 12:59:05 -0500 X-Virus-Scanned: by Amavisd-New at mx1.starman.ee Original-Received: from mail.starman.ee (82.131.30.92.cable.starman.ee [82.131.30.92]) by mx1.starman.ee (Postfix) with ESMTP id 2466F3F4122 for ; Tue, 17 Nov 2009 19:58:57 +0200 (EET) In-Reply-To: <87my2ljxun.fsf@mail.jurta.org> (Juri Linkov's message of "Tue, 17 Nov 2009 11:59:36 +0200") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1.50 (x86_64-pc-linux-gnu) X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:117110 Archived-At: There is one limitation of `dired-dwim-target-directory'. It tries to get a Dired buffer displayed in the next window, So when, for instance, there are two windows with Dired buffers on the same frame and one non-Dired window, it can fail. The following patch makes `dired-dwim-target-directory' more useful by allowing it to find the next window that displays a Dired buffer. Index: lisp/dired-aux.el =================================================================== RCS file: /sources/emacs/emacs/lisp/dired-aux.el,v retrieving revision 1.197 diff -c -r1.197 dired-aux.el *** lisp/dired-aux.el 13 Nov 2009 22:19:50 -0000 1.197 --- lisp/dired-aux.el 17 Nov 2009 17:42:07 -0000 *************** *** 1520,1537 **** (function 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 the next window, 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-buf (window-buffer (next-window))) ! (other-dir (with-current-buffer other-buf ! (and (eq major-mode 'dired-mode) ! (dired-current-directory))))) (or other-dir this-dir)) this-dir))) --- 1528,1546 ---- (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))) -- Juri Linkov http://www.jurta.org/emacs/