diff options
| author | Juri Linkov | 2009-11-25 17:15:19 +0000 |
|---|---|---|
| committer | Juri Linkov | 2009-11-25 17:15:19 +0000 |
| commit | e237085f039fd84695c0ccd7ffba68b1d218b361 (patch) | |
| tree | 69f5ae86e98ccac8c64c01e423db373b99f86739 | |
| parent | 7d371eac644665cdc4afcac57e7a09560e010a31 (diff) | |
| download | emacs-e237085f039fd84695c0ccd7ffba68b1d218b361.tar.gz emacs-e237085f039fd84695c0ccd7ffba68b1d218b361.zip | |
Provide additional default values (directories at other Dired
windows) via M-n in the minibuffer of some Dired commands.
* dired-aux.el (dired-diff, dired-compare-directories)
(dired-do-create-files): Use `dired-dwim-target-defaults' to set
`minibuffer-default' in `minibuffer-with-setup-hook'.
(dired-dwim-target-directory): Find a window that displays Dired
buffer instead of failing when the next window is not Dired.
Use `get-window-with-predicate' to find for the next Dired window.
(dired-dwim-target-defaults): New function.
* ediff-util.el (ediff-read-file-name):
Use `dired-dwim-target-defaults' to set `minibuffer-default'
in `minibuffer-with-setup-hook'.
| -rw-r--r-- | etc/NEWS | 4 | ||||
| -rw-r--r-- | lisp/ChangeLog | 17 | ||||
| -rw-r--r-- | lisp/dired-aux.el | 133 | ||||
| -rw-r--r-- | lisp/ediff-util.el | 34 |
4 files changed, 135 insertions, 53 deletions
| @@ -152,7 +152,9 @@ when the value of the new variable `completions-format' is `vertical'. | |||
| 152 | 152 | ||
| 153 | ** M-n provides more default values in the minibuffer of commands that | 153 | ** M-n provides more default values in the minibuffer of commands that |
| 154 | read a file and directory name: a file name at point (when ffap is loaded | 154 | read a file and directory name: a file name at point (when ffap is loaded |
| 155 | without ffap-bindings), a file name on the current line in the Dired buffer. | 155 | without ffap-bindings), a file name on the current line in the Dired buffer, |
| 156 | a directory name of adjacent Dired windows for Dired commands that can | ||
| 157 | operate on several directories (copy, rename, diff). | ||
| 156 | 158 | ||
| 157 | ** M-r is bound to the new `move-to-window-line-top-bottom' | 159 | ** M-r is bound to the new `move-to-window-line-top-bottom' |
| 158 | to mirror the new behavior of C-l in Emacs-23.1. | 160 | to mirror the new behavior of C-l in Emacs-23.1. |
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 5c7d0a1e25d..4f1c86f6101 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,5 +1,22 @@ | |||
| 1 | 2009-11-25 Juri Linkov <juri@jurta.org> | 1 | 2009-11-25 Juri Linkov <juri@jurta.org> |
| 2 | 2 | ||
| 3 | Provide additional default values (directories at other Dired | ||
| 4 | windows) via M-n in the minibuffer of some Dired commands. | ||
| 5 | |||
| 6 | * dired-aux.el (dired-diff, dired-compare-directories) | ||
| 7 | (dired-do-create-files): Use `dired-dwim-target-defaults' to set | ||
| 8 | `minibuffer-default' in `minibuffer-with-setup-hook'. | ||
| 9 | (dired-dwim-target-directory): Find a window that displays Dired | ||
| 10 | buffer instead of failing when the next window is not Dired. | ||
| 11 | Use `get-window-with-predicate' to find for the next Dired window. | ||
| 12 | (dired-dwim-target-defaults): New function. | ||
| 13 | |||
| 14 | * ediff-util.el (ediff-read-file-name): | ||
| 15 | Use `dired-dwim-target-defaults' to set `minibuffer-default' | ||
| 16 | in `minibuffer-with-setup-hook'. | ||
| 17 | |||
| 18 | 2009-11-25 Juri Linkov <juri@jurta.org> | ||
| 19 | |||
| 3 | Provide additional default values (file name at point or at the | 20 | Provide additional default values (file name at point or at the |
| 4 | current Dired line) via M-n for file reading minibuffers. (Bug#5010) | 21 | current Dired line) via M-n for file reading minibuffers. (Bug#5010) |
| 5 | 22 | ||
diff --git a/lisp/dired-aux.el b/lisp/dired-aux.el index b45b625b1ba..4976d2cd683 100644 --- a/lisp/dired-aux.el +++ b/lisp/dired-aux.el | |||
| @@ -59,30 +59,27 @@ The prompted-for file is the first file given to `diff'. | |||
| 59 | With prefix arg, prompt for second argument SWITCHES, | 59 | With prefix arg, prompt for second argument SWITCHES, |
| 60 | which is options for `diff'." | 60 | which is options for `diff'." |
| 61 | (interactive | 61 | (interactive |
| 62 | (let ((current (dired-get-filename t)) | 62 | (let* ((current (dired-get-filename t)) |
| 63 | (default (if (mark t) | 63 | (target-dir (dired-dwim-target-directory)) |
| 64 | (save-excursion (goto-char (mark t)) | 64 | (marked (and (mark t) (save-excursion |
| 65 | (dired-get-filename t t))))) | 65 | (goto-char (mark t)) |
| 66 | (if (or (equal default current) | 66 | (dired-get-filename nil t)))) |
| 67 | (and (not (equal (dired-dwim-target-directory) | 67 | (defaults |
| 68 | (dired-current-directory))) | 68 | (append (dired-dwim-target-defaults nil target-dir) |
| 69 | (not mark-active))) | 69 | ;; Additional file with the mark. |
| 70 | (setq default nil)) | 70 | (and marked (list marked))))) |
| 71 | (require 'diff) | 71 | (require 'diff) |
| 72 | (list (read-file-name (format "Diff %s with%s: " | 72 | (list |
| 73 | current | 73 | (minibuffer-with-setup-hook |
| 74 | (if default | 74 | (lambda () |
| 75 | (concat " (default " default ")") | 75 | (set (make-local-variable 'minibuffer-default-add-function) nil) |
| 76 | "")) | 76 | (setq minibuffer-default defaults)) |
| 77 | (if default | 77 | (read-file-name (format "Diff %s with: " current) target-dir nil t)) |
| 78 | (dired-current-directory) | 78 | (if current-prefix-arg |
| 79 | (dired-dwim-target-directory)) | 79 | (read-string "Options for diff: " |
| 80 | default t) | 80 | (if (stringp diff-switches) |
| 81 | (if current-prefix-arg | 81 | diff-switches |
| 82 | (read-string "Options for diff: " | 82 | (mapconcat 'identity diff-switches " "))))))) |
| 83 | (if (stringp diff-switches) | ||
| 84 | diff-switches | ||
| 85 | (mapconcat 'identity diff-switches " "))))))) | ||
| 86 | (diff file (dired-get-filename t) switches)) | 83 | (diff file (dired-get-filename t) switches)) |
| 87 | 84 | ||
| 88 | ;;;###autoload | 85 | ;;;###autoload |
| @@ -128,11 +125,17 @@ Examples of PREDICATE: | |||
| 128 | (not (and (= (nth 2 fa1) (nth 2 fa2)) - mark files with different UID | 125 | (not (and (= (nth 2 fa1) (nth 2 fa2)) - mark files with different UID |
| 129 | (= (nth 3 fa1) (nth 3 fa2)))) and GID." | 126 | (= (nth 3 fa1) (nth 3 fa2)))) and GID." |
| 130 | (interactive | 127 | (interactive |
| 131 | (list (read-directory-name (format "Compare %s with: " | 128 | (list |
| 132 | (dired-current-directory)) | 129 | (let* ((target-dir (dired-dwim-target-directory)) |
| 133 | (dired-dwim-target-directory) | 130 | (defaults (dired-dwim-target-defaults nil target-dir))) |
| 134 | (dired-dwim-target-directory)) | 131 | (minibuffer-with-setup-hook |
| 135 | (read-from-minibuffer "Mark if (lisp expr or RET): " nil nil t nil "nil"))) | 132 | (lambda () |
| 133 | (set (make-local-variable 'minibuffer-default-add-function) nil) | ||
| 134 | (setq minibuffer-default defaults)) | ||
| 135 | (read-directory-name (format "Compare %s with: " | ||
| 136 | (dired-current-directory)) | ||
| 137 | target-dir target-dir t))) | ||
| 138 | (read-from-minibuffer "Mark if (lisp expr or RET): " nil nil t nil "nil"))) | ||
| 136 | (let* ((dir1 (dired-current-directory)) | 139 | (let* ((dir1 (dired-current-directory)) |
| 137 | (file-alist1 (dired-files-attributes dir1)) | 140 | (file-alist1 (dired-files-attributes dir1)) |
| 138 | (file-alist2 (dired-files-attributes dir2)) | 141 | (file-alist2 (dired-files-attributes dir2)) |
| @@ -1463,10 +1466,15 @@ Optional arg HOW-TO determiness how to treat the target. | |||
| 1463 | (default (and dired-one-file | 1466 | (default (and dired-one-file |
| 1464 | (expand-file-name (file-name-nondirectory (car fn-list)) | 1467 | (expand-file-name (file-name-nondirectory (car fn-list)) |
| 1465 | target-dir))) | 1468 | target-dir))) |
| 1469 | (defaults (dired-dwim-target-defaults fn-list target-dir)) | ||
| 1466 | (target (expand-file-name ; fluid variable inside dired-create-files | 1470 | (target (expand-file-name ; fluid variable inside dired-create-files |
| 1467 | (dired-mark-read-file-name | 1471 | (minibuffer-with-setup-hook |
| 1468 | (concat (if dired-one-file op1 operation) " %s to: ") | 1472 | (lambda () |
| 1469 | target-dir op-symbol arg rfn-list default))) | 1473 | (set (make-local-variable 'minibuffer-default-add-function) nil) |
| 1474 | (setq minibuffer-default defaults)) | ||
| 1475 | (dired-mark-read-file-name | ||
| 1476 | (concat (if dired-one-file op1 operation) " %s to: ") | ||
| 1477 | target-dir op-symbol arg rfn-list default)))) | ||
| 1470 | (into-dir (cond ((null how-to) | 1478 | (into-dir (cond ((null how-to) |
| 1471 | ;; Allow DOS/Windows users to change the letter | 1479 | ;; Allow DOS/Windows users to change the letter |
| 1472 | ;; case of a directory. If we don't test these | 1480 | ;; case of a directory. If we don't test these |
| @@ -1523,18 +1531,69 @@ Optional arg HOW-TO determiness how to treat the target. | |||
| 1523 | 1531 | ||
| 1524 | (defun dired-dwim-target-directory () | 1532 | (defun dired-dwim-target-directory () |
| 1525 | ;; Try to guess which target directory the user may want. | 1533 | ;; Try to guess which target directory the user may want. |
| 1526 | ;; If there is a dired buffer displayed in the next window, use | 1534 | ;; If there is a dired buffer displayed in one of the next windows, |
| 1527 | ;; its current subdir, else use current subdir of this dired buffer. | 1535 | ;; use its current subdir, else use current subdir of this dired buffer. |
| 1528 | (let ((this-dir (and (eq major-mode 'dired-mode) | 1536 | (let ((this-dir (and (eq major-mode 'dired-mode) |
| 1529 | (dired-current-directory)))) | 1537 | (dired-current-directory)))) |
| 1530 | ;; non-dired buffer may want to profit from this function, e.g. vm-uudecode | 1538 | ;; non-dired buffer may want to profit from this function, e.g. vm-uudecode |
| 1531 | (if dired-dwim-target | 1539 | (if dired-dwim-target |
| 1532 | (let* ((other-buf (window-buffer (next-window))) | 1540 | (let* ((other-win (get-window-with-predicate |
| 1533 | (other-dir (with-current-buffer other-buf | 1541 | (lambda (window) |
| 1534 | (and (eq major-mode 'dired-mode) | 1542 | (with-current-buffer (window-buffer window) |
| 1535 | (dired-current-directory))))) | 1543 | (eq major-mode 'dired-mode))))) |
| 1544 | (other-dir (and other-win | ||
| 1545 | (with-current-buffer (window-buffer other-win) | ||
| 1546 | (and (eq major-mode 'dired-mode) | ||
| 1547 | (dired-current-directory)))))) | ||
| 1536 | (or other-dir this-dir)) | 1548 | (or other-dir this-dir)) |
| 1537 | this-dir))) | 1549 | this-dir))) |
| 1550 | |||
| 1551 | (defun dired-dwim-target-defaults (fn-list target-dir) | ||
| 1552 | ;; Return a list of default values for file-reading functions in Dired. | ||
| 1553 | ;; This list may contain directories from Dired buffers in other windows. | ||
| 1554 | ;; `fn-list' is a list of file names used to build a list of defaults. | ||
| 1555 | ;; When nil or more than one element, a list of defaults will | ||
| 1556 | ;; contain only directory names. `target-dir' is a directory name | ||
| 1557 | ;; to exclude from the returned list, for the case when this | ||
| 1558 | ;; directory name is already presented in initial input. | ||
| 1559 | ;; For Dired operations that support `dired-dwim-target', | ||
| 1560 | ;; the argument `target-dir' should have the value returned | ||
| 1561 | ;; from `dired-dwim-target-directory'. | ||
| 1562 | (let ((dired-one-file | ||
| 1563 | (and (consp fn-list) (null (cdr fn-list)) (car fn-list))) | ||
| 1564 | (current-dir (and (eq major-mode 'dired-mode) | ||
| 1565 | (dired-current-directory))) | ||
| 1566 | dired-dirs) | ||
| 1567 | ;; Get a list of directories of visible buffers in dired-mode. | ||
| 1568 | (walk-windows (lambda (w) | ||
| 1569 | (with-current-buffer (window-buffer w) | ||
| 1570 | (and (eq major-mode 'dired-mode) | ||
| 1571 | (push (dired-current-directory) dired-dirs))))) | ||
| 1572 | ;; Force the current dir to be the first in the list. | ||
| 1573 | (setq dired-dirs | ||
| 1574 | (delete-dups (delq nil (cons current-dir (nreverse dired-dirs))))) | ||
| 1575 | ;; Remove the target dir (if specified) or the current dir from | ||
| 1576 | ;; default values, because it should be already in initial input. | ||
| 1577 | (setq dired-dirs (delete (or target-dir current-dir) dired-dirs)) | ||
| 1578 | ;; Return a list of default values. | ||
| 1579 | (if dired-one-file | ||
| 1580 | ;; For one file operation, provide a list that contains | ||
| 1581 | ;; other directories, other directories with the appended filename | ||
| 1582 | ;; and the current directory with the appended filename, e.g. | ||
| 1583 | ;; 1. /TARGET-DIR/ | ||
| 1584 | ;; 2. /TARGET-DIR/FILENAME | ||
| 1585 | ;; 3. /CURRENT-DIR/FILENAME | ||
| 1586 | (append dired-dirs | ||
| 1587 | (mapcar (lambda (dir) | ||
| 1588 | (expand-file-name | ||
| 1589 | (file-name-nondirectory (car fn-list)) dir)) | ||
| 1590 | (reverse dired-dirs)) | ||
| 1591 | (list (expand-file-name | ||
| 1592 | (file-name-nondirectory (car fn-list)) | ||
| 1593 | (or target-dir current-dir)))) | ||
| 1594 | ;; For multi-file operation, return only a list of other directories. | ||
| 1595 | dired-dirs))) | ||
| 1596 | |||
| 1538 | 1597 | ||
| 1539 | ;;;###autoload | 1598 | ;;;###autoload |
| 1540 | (defun dired-create-directory (directory) | 1599 | (defun dired-create-directory (directory) |
diff --git a/lisp/ediff-util.el b/lisp/ediff-util.el index ea12ef7532a..e8a171bf517 100644 --- a/lisp/ediff-util.el +++ b/lisp/ediff-util.el | |||
| @@ -3113,21 +3113,25 @@ Hit \\[ediff-recenter] to reset the windows afterward." | |||
| 3113 | (if (string= default-file "") | 3113 | (if (string= default-file "") |
| 3114 | (setq default-file nil)) | 3114 | (setq default-file nil)) |
| 3115 | 3115 | ||
| 3116 | (let (f) | 3116 | (let ((defaults (and (fboundp 'dired-dwim-target-defaults) |
| 3117 | (setq f (expand-file-name | 3117 | (dired-dwim-target-defaults |
| 3118 | (read-file-name | 3118 | (and default-file (list default-file)) |
| 3119 | (format "%s%s " | 3119 | default-dir))) |
| 3120 | prompt | 3120 | f) |
| 3121 | (cond (default-file | 3121 | (setq f (minibuffer-with-setup-hook |
| 3122 | (concat " (default " default-file "):")) | 3122 | (lambda () (when defaults |
| 3123 | (t (concat " (default " default-dir "):")))) | 3123 | (setq minibuffer-default defaults))) |
| 3124 | default-dir | 3124 | (read-file-name |
| 3125 | (or default-file default-dir) | 3125 | (format "%s%s " |
| 3126 | t ; must match, no-confirm | 3126 | prompt |
| 3127 | (if default-file (file-name-directory default-file)) | 3127 | (cond (default-file |
| 3128 | ) | 3128 | (concat " (default " default-file "):")) |
| 3129 | default-dir | 3129 | (t (concat " (default " default-dir "):")))) |
| 3130 | )) | 3130 | default-dir |
| 3131 | (or default-file default-dir) | ||
| 3132 | t ; must match, no-confirm | ||
| 3133 | (if default-file (file-name-directory default-file))))) | ||
| 3134 | (setq f (expand-file-name f default-dir)) | ||
| 3131 | ;; If user entered a directory name, expand the default file in that | 3135 | ;; If user entered a directory name, expand the default file in that |
| 3132 | ;; directory. This allows the user to enter a directory name for the | 3136 | ;; directory. This allows the user to enter a directory name for the |
| 3133 | ;; B-file and diff against the default-file in that directory instead | 3137 | ;; B-file and diff against the default-file in that directory instead |