emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

dired-dwim-target-directory (was: find-file-read-args)


From: Juri Linkov
Subject: dired-dwim-target-directory (was: find-file-read-args)
Date: Tue, 17 Nov 2009 19:42:33 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1.50 (x86_64-pc-linux-gnu)

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/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]