;;; dired-aux.el --- less commonly used parts of dired -*-byte-compile-dynamic: t;-*-
;; Copyright (C) 1985, 1986, 1992, 1994, 1998, 2000, 2001, 2002, 2003,
-;; 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+;; 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
;; Author: Sebastian Kremer <sk@thp.uni-koeln.de>.
;; Maintainer: FSF
;;; Copy, move/rename, making hard and symbolic links
(defcustom dired-backup-overwrite nil
- "*Non-nil if Dired should ask about making backups before overwriting files.
+ "Non-nil if Dired should ask about making backups before overwriting files.
Special value `always' suppresses confirmation."
:type '(choice (const :tag "off" nil)
(const :tag "suppress" always)
how-to)
"Create a new file for each marked file.
Prompts user for target, which is a directory in which to create
- the new files. Target may be a plain file if only one marked
+ the new files. Target may also be a plain file if only one marked
file exists. The way the default for the target directory is
computed depends on the value of `dired-dwim-target-directory'.
OP-SYMBOL is the symbol for the operation. Function `dired-mark-pop-up'
Optional arg MARKER-CHAR as in `dired-create-files'.
Optional arg OP1 is an alternate form for OPERATION if there is
only one file.
-Optional arg HOW-TO is used to set the value of the into-dir variable
- which determines how to treat target.
- If into-dir is set to nil then target is not regarded as a directory,
- there must be exactly one marked file, else error.
- Else if into-dir is set to a list, then target is a generalized
- directory (e.g. some sort of archive). The first element of into-dir
- must be a function with at least four arguments:
- operation as OPERATION above.
- rfn-list a list of the relative names for the marked files.
- fn-list a list of the absolute names for the marked files.
- target.
+Optional arg HOW-TO determiness how to treat the target.
+ If HOW-TO is nil, use `file-directory-p' to determine if the
+ target is a directory. If so, the marked file(s) are created
+ inside that directory. Otherwise, the target is a plain file;
+ an error is raised unless there is exactly one marked file.
+ If HOW-TO is t, target is always treated as a plain file.
+ Otherwise, HOW-TO should be a function of one argument, TARGET.
+ If its return value is nil, TARGET is regarded as a plain file.
+ If it return value is a list, TARGET is a generalized
+ directory (e.g. some sort of archive). The first element of
+ this list must be a function with at least four arguments:
+ operation - as OPERATION above.
+ rfn-list - list of the relative names for the marked files.
+ fn-list - list of the absolute names for the marked files.
+ target - the name of the target itself.
The rest of into-dir are optional arguments.
- Else into-dir is not a list. Target is a directory.
- The marked file(s) are created inside the target directory.
-
- If HOW-TO is not given (or nil), then into-dir is set to true if
- target is a directory and otherwise to nil.
- Else if HOW-TO is t, then into-dir is set to nil.
- Else HOW-TO is assumed to be a function of one argument, target,
- that looks at target and returns a value for the into-dir
- variable. The function `dired-into-dir-with-symlinks' is provided
- for the case (common when creating symlinks) that symbolic
- links to directories are not to be considered as directories
- (as `file-directory-p' would if HOW-TO had been nil)."
+ For any other return value, TARGET is treated as a directory."
(or op1 (setq op1 operation))
(let* ((fn-list (dired-get-marked-files nil arg))
(rfn-list (mapcar (function dired-make-relative) fn-list))
;; Search only in file names in the Dired buffer.
(defcustom dired-isearch-filenames nil
- "*If non-nil, Isearch in Dired matches only file names."
+ "Non-nil to Isearch in file names only.
+If t, Isearch in Dired always matches only file names.
+If `dwim', Isearch matches file names when initial point position is on
+a file name. Otherwise, it searches the whole buffer without restrictions."
:type '(choice (const :tag "No restrictions" nil)
- (const :tag "Isearch only in file names" dired-filename))
+ (const :tag "When point is on a file name initially, search file names" dwim)
+ (const :tag "Always search in file names" t))
:group 'dired
:version "23.1")
-(defvar dired-isearch-orig-success-function nil)
+(defvar dired-isearch-filter-predicate-orig nil)
(defun dired-isearch-filenames-toggle ()
"Toggle file names searching on or off.
-When on, Isearch checks the success of the current matching point
-using the function `dired-isearch-success-function' that matches only
-at file names. When off, it uses the default function
-`isearch-success-function-default'."
+When on, Isearch skips matches outside file names using the predicate
+`dired-isearch-filter-filenames' that matches only at file names.
+When off, it uses the original predicate."
(interactive)
- (setq isearch-success-function
- (if (eq isearch-success-function 'dired-isearch-success-function)
- 'isearch-success-function-default
- 'dired-isearch-success-function))
+ (setq isearch-filter-predicate
+ (if (eq isearch-filter-predicate 'dired-isearch-filter-filenames)
+ dired-isearch-filter-predicate-orig
+ 'dired-isearch-filter-filenames))
(setq isearch-success t isearch-adjusted t)
(isearch-update))
(defun dired-isearch-filenames-setup ()
"Set up isearch to search in Dired file names.
Intended to be added to `isearch-mode-hook'."
- (when dired-isearch-filenames
+ (when (or (eq dired-isearch-filenames t)
+ (and (eq dired-isearch-filenames 'dwim)
+ (get-text-property (point) 'dired-filename)))
+ (setq isearch-message-prefix-add "filename ")
(define-key isearch-mode-map "\M-sf" 'dired-isearch-filenames-toggle)
- (setq dired-isearch-orig-success-function
- (default-value 'isearch-success-function))
- (setq-default isearch-success-function 'dired-isearch-success-function)
+ (setq dired-isearch-filter-predicate-orig
+ (default-value 'isearch-filter-predicate))
+ (setq-default isearch-filter-predicate 'dired-isearch-filter-filenames)
(add-hook 'isearch-mode-end-hook 'dired-isearch-filenames-end nil t)))
(defun dired-isearch-filenames-end ()
"Clean up the Dired file name search after terminating isearch."
+ (setq isearch-message-prefix-add nil)
(define-key isearch-mode-map "\M-sf" nil)
- (setq-default isearch-success-function dired-isearch-orig-success-function)
+ (setq-default isearch-filter-predicate dired-isearch-filter-predicate-orig)
(remove-hook 'isearch-mode-end-hook 'dired-isearch-filenames-end t))
-(defun dired-isearch-success-function (beg end)
- "Match only at visible regions with the text property `dired-filename'."
- (and (isearch-success-function-default beg end)
+(defun dired-isearch-filter-filenames (beg end)
+ "Test whether the current search hit is a visible file name.
+Return non-nil if the text from BEG to END is part of a file
+name (has the text property `dired-filename') and is visible."
+ (and (isearch-filter-visible beg end)
(if dired-isearch-filenames
(text-property-not-all (min beg end) (max beg end)
'dired-filename nil)