1 ;;; dired-isearch.el --- isearch in Dired
3 ;; Copyright (C) 2006, 2007 William Xu
5 ;; Author: William Xu <william.xwl@gmail.com>
8 ;; This program is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation; either version 3, or (at your option)
13 ;; EMMS is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with EMMS; see the file COPYING. If not, write to the
20 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 ;; Boston, MA 02110-1301, USA.
25 ;; Do isearch in Dired but match only at file names.
27 ;; Recommended keybindings:
29 ;; (define-key dired-mode-map (kbd "C-s") 'dired-isearch-forward)
30 ;; (define-key dired-mode-map (kbd "C-r") 'dired-isearch-backward)
31 ;; (define-key dired-mode-map (kbd "ESC C-s") 'dired-isearch-forward-regexp)
32 ;; (define-key dired-mode-map (kbd "ESC C-r") 'dired-isearch-backward-regexp)
36 ;; - search string starting with a "^" causes some infinite loop
37 ;; - search string with ".*" matches at non-filenames
46 (defun dired-isearch-forward (&optional regexp-p no-recursive-edit
)
47 "In Dired, run `isearch-forward' but match only at file names."
49 (let ((isearch-search-fun-function 'dired-isearch-search-fun-function
))
50 (isearch-forward regexp-p no-recursive-edit
)))
53 (defun dired-isearch-backward (&optional regexp-p no-recursive-edit
)
54 "In Dired, run `isearch-backward' but match only at file names."
56 (let ((isearch-search-fun-function 'dired-isearch-search-fun-function
))
57 (isearch-backward regexp-p no-recursive-edit
)))
60 (defun dired-isearch-forward-regexp (&optional not-regexp no-recursive-edit
)
61 "In Dired, run `isearch-forward-regexp' but match only at file names."
63 (let ((isearch-search-fun-function 'dired-isearch-search-fun-function
))
64 (isearch-forward-regexp not-regexp no-recursive-edit
)))
67 (defun dired-isearch-backward-regexp (&optional not-regexp no-recursive-edit
)
68 "In Dired, run `isearch-backward-regexp' but match only at file names."
70 (let ((isearch-search-fun-function 'dired-isearch-search-fun-function
))
71 (isearch-backward-regexp not-regexp no-recursive-edit
)))
74 ;;; Low Level Functions
78 ;; (defun dired-isearch-search-fun-function () 'dired-isearch-search)
80 ;; (defun dired-isearch-search (&rest args)
81 ;; (let ((fun (let ((isearch-search-fun-function nil))
82 ;; (isearch-search-fun)))
84 ;; (while (and (setq point (apply fun args))
85 ;; ;; Use `help-echo' instead of `dired-filename' so as to
86 ;; ;; also work in Tramp dired buffers.
87 ;; (not (get-text-property (1- point) 'help-echo)))
88 ;; ;; (forward-char 1)
92 ;; (define-minor-mode dired-isearch-filenames-mode
93 ;; "Only match filenames in isearch."
95 ;; (if dired-isearch-filenames-mode
96 ;; (set (make-local-variable 'isearch-search-fun-function)
97 ;; 'dired-isearch-search-fun-function)
98 ;; (kill-local-variable 'isearch-search-fun-function)))
100 (defun dired-isearch-search-fun-function ()
101 "Return the isearch function in Dired."
104 (if isearch-forward
'dired-word-search-forward
'dired-word-search-backward
))
106 (if isearch-forward
'dired-re-search-forward
'dired-re-search-backward
))
108 (if isearch-forward
'dired-search-forward
'dired-search-backward
))))
110 (defun dired-search-forward (string &optional bound noerror count
)
111 "In Dired, run `search-forward' but match only at file names."
112 (let ((point (search-forward string bound noerror count
)))
113 ;; Use 'help-echo instead of 'dired-filename so as to also work
114 ;; in tramp dired buffers.
115 (while (and point
(not (get-text-property (1- point
) 'help-echo
)))
116 (setq point
(search-forward string bound noerror count
)))
119 (defun dired-search-backward (string &optional bound noerror count
)
120 "In Dired, run `search-backward' but match only at file names."
121 (let ((point (search-backward string bound noerror count
)))
122 (while (and point
(not (get-text-property point
'help-echo
)))
123 (setq point
(search-backward string bound noerror count
)))
126 (defun dired-re-search-forward (regexp &optional bound noerror count
)
127 "In Dired, run `re-search-forward' but match only at file names."
128 (let ((point (re-search-forward regexp bound noerror count
)))
129 (while (and point
(not (get-text-property (1- point
) 'help-echo
)))
130 (setq point
(re-search-forward regexp bound noerror count
)))
133 (defun dired-re-search-backward (regexp &optional bound noerror count
)
134 "In Dired, run `re-search-backward' but match only at file names."
135 (let ((point (re-search-backward regexp bound noerror count
)))
136 (while (and point
(not (get-text-property point
'help-echo
)))
137 (setq point
(re-search-backward regexp bound noerror count
)))
140 (defun dired-word-search-forward (string &optional bound noerror count
)
141 "In Dired, run `word-search-forward' but match only at file names."
142 (let ((point (word-search-forward string bound noerror count
)))
143 (while (and point
(not (get-text-property (1- point
) 'help-echo
)))
144 (setq point
(word-search-forward string bound noerror count
)))
147 (defun dired-word-search-backward (string &optional bound noerror count
)
148 "In Dired, run `word-search-backward' but match only at file names."
149 (let ((point (word-search-backward string bound noerror count
)))
150 (while (and point
(not (get-text-property point
'help-echo
)))
151 (setq point
(word-search-backward string bound noerror count
)))
154 (provide 'dired-isearch
)
156 ;;; dired-isearch.el ends here