aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChong Yidong2007-04-23 14:54:04 +0000
committerChong Yidong2007-04-23 14:54:04 +0000
commit7861843e91d02d7225e9868044ea7eaae17d6818 (patch)
tree5af26019583ec6564217f5f0ec8af6cecd96a910
parent5c03c62821f17cf35869053fc25da18d52cec588 (diff)
downloademacs-7861843e91d02d7225e9868044ea7eaae17d6818.tar.gz
emacs-7861843e91d02d7225e9868044ea7eaae17d6818.zip
(locate-local-prompt): New var.
(locate-prompt-for-search-string): New function. (locate): Make locate-local-prompt buffer-local. Use locate-prompt-for-search-string. (locate-with-filter): New optional arg. Use locate-prompt-for-search-string. (locate-update): Bind locate-prompt-for-command.
-rw-r--r--lisp/locate.el85
1 files changed, 51 insertions, 34 deletions
diff --git a/lisp/locate.el b/lisp/locate.el
index 86f8c68cc8f..d0ef749281b 100644
--- a/lisp/locate.el
+++ b/lisp/locate.el
@@ -117,6 +117,7 @@
117(defvar locate-current-filter nil) 117(defvar locate-current-filter nil)
118(defvar locate-local-filter nil) 118(defvar locate-local-filter nil)
119(defvar locate-local-search nil) 119(defvar locate-local-search nil)
120(defvar locate-local-prompt nil)
120 121
121(defgroup locate nil 122(defgroup locate nil
122 "Interface to the locate command." 123 "Interface to the locate command."
@@ -221,7 +222,10 @@ option to \"/\"."
221 222
222(defcustom locate-prompt-for-command nil 223(defcustom locate-prompt-for-command nil
223 "If non-nil, the `locate' command prompts for a command to run. 224 "If non-nil, the `locate' command prompts for a command to run.
224Otherwise, that behavior is invoked via a prefix argument." 225Otherwise, that behavior is invoked via a prefix argument.
226
227Setting this option non-nil actually inverts the meaning of a prefix arg;
228that is, with a prefix arg, you get the default behavior."
225 :group 'locate 229 :group 'locate
226 :type 'boolean) 230 :type 'boolean)
227 231
@@ -241,8 +245,31 @@ Otherwise, that behavior is invoked via a prefix argument."
241 (skip-chars-backward "." pt) 245 (skip-chars-backward "." pt)
242 (point))))) 246 (point)))))
243 247
248(defun locate-prompt-for-search-string ()
249 (if (or (and current-prefix-arg
250 (not locate-prompt-for-command))
251 (and (not current-prefix-arg) locate-prompt-for-command))
252 (let ((locate-cmd (funcall locate-make-command-line "")))
253 (read-from-minibuffer
254 "Run locate (like this): "
255 (cons
256 (concat (car locate-cmd) " "
257 (mapconcat 'identity (cdr locate-cmd) " "))
258 (+ 2 (length (car locate-cmd))))
259 nil nil 'locate-history-list))
260 (let* ((default (locate-word-at-point))
261 (input
262 (read-from-minibuffer
263 (if (> (length default) 0)
264 (format "Locate (default %s): " default)
265 (format "Locate: "))
266 nil nil nil 'locate-history-list default t)))
267 (and (equal input "") default
268 (setq input default))
269 input)))
270
244;;;###autoload 271;;;###autoload
245(defun locate (search-string &optional filter) 272(defun locate (search-string &optional filter arg)
246 "Run the program `locate', putting results in `*Locate*' buffer. 273 "Run the program `locate', putting results in `*Locate*' buffer.
247Pass it SEARCH-STRING as argument. Interactively, prompt for SEARCH-STRING. 274Pass it SEARCH-STRING as argument. Interactively, prompt for SEARCH-STRING.
248With prefix arg, prompt for the exact shell command to run instead. 275With prefix arg, prompt for the exact shell command to run instead.
@@ -259,38 +286,23 @@ You can specify another program for this command to run by customizing
259the variables `locate-command' or `locate-make-command-line'. 286the variables `locate-command' or `locate-make-command-line'.
260 287
261The main use of FILTER is to implement `locate-with-filter'. See 288The main use of FILTER is to implement `locate-with-filter'. See
262the docstring of that function for its meaning." 289the docstring of that function for its meaning.
290
291ARG is the interactive prefix arg."
263 (interactive 292 (interactive
264 (list 293 (list
265 (if (or (and current-prefix-arg 294 (locate-prompt-for-search-string)
266 (not locate-prompt-for-command)) 295 nil
267 (and (not current-prefix-arg) locate-prompt-for-command)) 296 current-prefix-arg))
268 (let ((locate-cmd (funcall locate-make-command-line ""))) 297
269 (read-from-minibuffer
270 "Run locate (like this): "
271 (cons
272 (concat (car locate-cmd) " "
273 (mapconcat 'identity (cdr locate-cmd) " "))
274 (+ 2 (length (car locate-cmd))))
275 nil nil 'locate-history-list))
276 (let* ((default (locate-word-at-point))
277 (input
278 (read-from-minibuffer
279 (if (> (length default) 0)
280 (format "Locate (default %s): " default)
281 (format "Locate: "))
282 nil nil nil 'locate-history-list default t)))
283 (and (equal input "") default
284 (setq input default))
285 input))))
286 (if (equal search-string "") 298 (if (equal search-string "")
287 (error "Please specify a filename to search for")) 299 (error "Please specify a filename to search for"))
288 (let* ((locate-cmd-list (funcall locate-make-command-line search-string)) 300 (let* ((locate-cmd-list (funcall locate-make-command-line search-string))
289 (locate-cmd (car locate-cmd-list)) 301 (locate-cmd (car locate-cmd-list))
290 (locate-cmd-args (cdr locate-cmd-list)) 302 (locate-cmd-args (cdr locate-cmd-list))
291 (run-locate-command 303 (run-locate-command
292 (or (and current-prefix-arg (not locate-prompt-for-command)) 304 (or (and arg (not locate-prompt-for-command))
293 (and (not current-prefix-arg) locate-prompt-for-command))) 305 (and (not arg) locate-prompt-for-command)))
294 ) 306 )
295 307
296 ;; Find the Locate buffer 308 ;; Find the Locate buffer
@@ -304,6 +316,7 @@ the docstring of that function for its meaning."
304 (setq locate-current-filter filter) 316 (setq locate-current-filter filter)
305 (set (make-local-variable 'locate-local-search) search-string) 317 (set (make-local-variable 'locate-local-search) search-string)
306 (set (make-local-variable 'locate-local-filter) filter) 318 (set (make-local-variable 'locate-local-filter) filter)
319 (set (make-local-variable 'locate-local-prompt) run-locate-command)
307 320
308 (if run-locate-command 321 (if run-locate-command
309 (shell-command search-string locate-buffer-name) 322 (shell-command search-string locate-buffer-name)
@@ -324,7 +337,7 @@ the docstring of that function for its meaning."
324 ) 337 )
325 338
326;;;###autoload 339;;;###autoload
327(defun locate-with-filter (search-string filter) 340(defun locate-with-filter (search-string filter &optional arg)
328 "Run the executable program `locate' with a filter. 341 "Run the executable program `locate' with a filter.
329This function is similar to the function `locate', which see. 342This function is similar to the function `locate', which see.
330The difference is that, when invoked interactively, the present function 343The difference is that, when invoked interactively, the present function
@@ -334,14 +347,17 @@ that lists only those lines in the output of the locate program that
334contain a match for the regular expression FILTER; this is often useful 347contain a match for the regular expression FILTER; this is often useful
335to constrain a big search. 348to constrain a big search.
336 349
350ARG is the interactive prefix arg, which has the same effect as in `locate'.
351
337When called from Lisp, this function is identical with `locate', 352When called from Lisp, this function is identical with `locate',
338except that FILTER is not optional." 353except that FILTER is not optional."
339 (interactive 354 (interactive
340 (list (read-from-minibuffer "Locate: " nil nil 355 (list
341 nil 'locate-history-list) 356 (locate-prompt-for-search-string)
342 (read-from-minibuffer "Filter: " nil nil 357 (read-from-minibuffer "Filter: " nil nil
343 nil 'locate-grep-history-list))) 358 nil 'locate-grep-history-list)
344 (locate search-string filter)) 359 current-prefix-arg))
360 (locate search-string filter arg))
345 361
346(defun locate-filter-output (filter) 362(defun locate-filter-output (filter)
347 "Filter output from the locate command." 363 "Filter output from the locate command."
@@ -584,7 +600,8 @@ do not work in subdirectories.
584 "Revert the *Locate* buffer. 600 "Revert the *Locate* buffer.
585If `locate-update-when-revert' is non-nil, offer to update the 601If `locate-update-when-revert' is non-nil, offer to update the
586locate database using the shell command in `locate-update-command'." 602locate database using the shell command in `locate-update-command'."
587 (let ((locate-buffer-name (buffer-name))) 603 (let ((locate-buffer-name (buffer-name))
604 (locate-prompt-for-command locate-local-prompt))
588 (and locate-update-when-revert 605 (and locate-update-when-revert
589 (yes-or-no-p "Update locate database (may take a few seconds)? ") 606 (yes-or-no-p "Update locate database (may take a few seconds)? ")
590 ;; `expand-file-name' is used in order to autoload Tramp if 607 ;; `expand-file-name' is used in order to autoload Tramp if