Function: dired-dwim-target-defaults

dired-dwim-target-defaults is a byte-compiled function defined in dired-aux.el.gz.

Signature

(dired-dwim-target-defaults FN-LIST TARGET-DIR)

Source Code

;; Defined in /usr/src/emacs/lisp/dired-aux.el.gz
(defun dired-dwim-target-defaults (fn-list target-dir)
  ;; Return a list of default values for file-reading functions in Dired.
  ;; This list may contain directories from Dired buffers in other windows.
  ;; `fn-list' is a list of file names used to build a list of defaults.
  ;; When nil or more than one element, a list of defaults will
  ;; contain only directory names.  `target-dir' is a directory name
  ;; to exclude from the returned list, for the case when this
  ;; directory name is already presented in initial input.
  ;; For Dired operations that support `dired-dwim-target',
  ;; the argument `target-dir' should have the value returned
  ;; from `dired-dwim-target-directory'.
  (let ((dired-one-file
	 (and (consp fn-list) (null (cdr fn-list)) (car fn-list)))
	(current-dir (and (eq major-mode 'dired-mode)
			  (dired-current-directory)))
	;; 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 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))
    ;; Return a list of default values.
    (if dired-one-file
	;; For one file operation, provide a list that contains
	;; other directories, other directories with the appended filename
	;; and the current directory with the appended filename, e.g.
	;; 1. /TARGET-DIR/
	;; 2. /TARGET-DIR/FILENAME
	;; 3. /CURRENT-DIR/FILENAME
	(append dired-dirs
		(mapcar (lambda (dir)
			  (expand-file-name
			   (file-name-nondirectory (car fn-list)) dir))
			(reverse dired-dirs))
		(list (expand-file-name
		       (file-name-nondirectory (car fn-list))
		       (or target-dir current-dir))))
      ;; For multi-file operation, return only a list of other directories.
      dired-dirs)))