changeset 99811:e9cd9fee6fd7

(dired-isearch-filenames): Add new context-dependent option `dwim'. Change non-dwim option from `dired-filename' to `t'. Doc fix. (dired-isearch-filenames-setup): Run filename Isearch only when dired-isearch-filenames is t or dired-isearch-filenames is `dwim' and the text property `dired-filename' at point is non-nil. In this case also set isearch-message-prefix-add to "filename ". (dired-isearch-filenames-end): Set isearch-message-prefix-add to nil. (dired-isearch-filenames, dired-isearch-filenames-regexp): Don't let-bind isearch-message-prefix-add since this is done now in dired-isearch-filenames-setup.
author Juri Linkov <juri@jurta.org>
date Sat, 22 Nov 2008 20:40:28 +0000
parents e47f7a922e57
children fa8a56f094db
files lisp/dired-aux.el
diffstat 1 files changed, 13 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/dired-aux.el	Sat Nov 22 19:08:03 2008 +0000
+++ b/lisp/dired-aux.el	Sat Nov 22 20:40:28 2008 +0000
@@ -2304,9 +2304,13 @@
 ;; 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")
 
@@ -2329,7 +2333,10 @@
 (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-filter-predicate-orig
 	  (default-value 'isearch-filter-predicate))
@@ -2338,6 +2345,7 @@
 
 (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-filter-predicate dired-isearch-filter-predicate-orig)
   (remove-hook 'isearch-mode-end-hook 'dired-isearch-filenames-end t))
@@ -2354,16 +2362,14 @@
 (defun dired-isearch-filenames ()
   "Search for a string using Isearch only in file names in the Dired buffer."
   (interactive)
-  (let ((dired-isearch-filenames t)
-	(isearch-message-prefix-add "filename "))
+  (let ((dired-isearch-filenames t))
     (isearch-forward)))
 
 ;;;###autoload
 (defun dired-isearch-filenames-regexp ()
   "Search for a regexp using Isearch only in file names in the Dired buffer."
   (interactive)
-  (let ((dired-isearch-filenames t)
-	(isearch-message-prefix-add "filename "))
+  (let ((dired-isearch-filenames t))
     (isearch-forward-regexp)))