;;; locate.el --- interface to the locate command
-;; Copyright (C) 1996, 1998 Free Software Foundation, Inc.
+;; Copyright (C) 1996, 1998, 2001 Free Software Foundation, Inc.
;; Author: Peter Breton <pbreton@cs.umb.edu>
+;; Keywords: unix files
;; This file is part of GNU Emacs.
(defun locate-default-make-command-line (search-string)
(list locate-command search-string))
+(defun locate-word-at-point ()
+ (let ((pt (point)))
+ (buffer-substring-no-properties
+ (save-excursion
+ (skip-chars-backward "-a-zA-Z0-9.")
+ (point))
+ (save-excursion
+ (skip-chars-forward "-a-zA-Z0-9.")
+ (skip-chars-backward "." pt)
+ (point)))))
+
;;;###autoload
-(defun locate (arg search-string &optional filter)
+(defun locate (search-string &optional filter)
"Run the program `locate', putting results in `*Locate*' buffer.
With prefix arg, prompt for the locate command to run."
(interactive
(list
- current-prefix-arg
- (if (or (and current-prefix-arg (not locate-prompt-for-command))
+ (if (or (and current-prefix-arg
+ (not locate-prompt-for-command))
(and (not current-prefix-arg) locate-prompt-for-command))
- (read-from-minibuffer "Run locate command: "
- nil nil nil 'locate-history-list)
- (read-from-minibuffer "Locate: " nil nil
- nil 'locate-history-list)
- )))
+ (let ((locate-cmd (funcall locate-make-command-line "")))
+ (read-from-minibuffer
+ "Run locate (like this): "
+ (cons
+ (concat (car locate-cmd) " "
+ (mapconcat 'identity (cdr locate-cmd) " "))
+ (+ 2 (length (car locate-cmd))))
+ nil nil 'locate-history-list))
+ (let* ((default (locate-word-at-point))
+ (input
+ (read-from-minibuffer
+ (if (> (length default) 0)
+ (format "Locate (default `%s'): " default)
+ (format "Locate: "))
+ nil nil nil 'locate-history-list default t)))
+ (and (equal input "") default
+ (setq input default))
+ input))))
+ (if (equal search-string "")
+ (error "Please specify a filename to search for"))
(let* ((locate-cmd-list (funcall locate-make-command-line search-string))
(locate-cmd (car locate-cmd-list))
(locate-cmd-args (cdr locate-cmd-list))
(run-locate-command
- (or (and arg (not locate-prompt-for-command))
- (and (not arg) locate-prompt-for-command)))
+ (or (and current-prefix-arg (not locate-prompt-for-command))
+ (and (not current-prefix-arg) locate-prompt-for-command)))
)
;; Find the Locate buffer
(and filter
(locate-filter-output filter))
- (locate-do-setup)
+ (locate-do-setup search-string)
)
(and (not (string-equal (buffer-name) locate-buffer-name))
(switch-to-buffer-other-window locate-buffer-name))
+ (run-hooks 'dired-mode-hook)
+ (dired-next-line 2) ;move to first matching file.
(run-hooks 'locate-post-command-hook)
)
)
nil 'locate-history-list)
(read-from-minibuffer "Filter: " nil nil
nil 'locate-grep-history-list)))
- (locate nil search-string filter))
+ (locate search-string filter))
(defun locate-filter-output (filter)
"Filter output from the locate command."
(setq revert-buffer-function 'locate-update)
(run-hooks 'locate-mode-hook))
-(defun locate-do-setup ()
- (let ((search-string (car locate-history-list)))
- (goto-char (point-min))
- (save-excursion
+(defun locate-do-setup (search-string)
+ (goto-char (point-min))
+ (save-excursion
- ;; Nothing returned from locate command?
- (and (eobp)
- (progn
- (kill-buffer locate-buffer-name)
- (if locate-current-filter
- (error "Locate: no match for %s in database using filter %s"
- search-string locate-current-filter)
- (error "Locate: no match for %s in database" search-string))))
+ ;; Nothing returned from locate command?
+ (and (eobp)
+ (progn
+ (kill-buffer locate-buffer-name)
+ (if locate-current-filter
+ (error "Locate: no match for %s in database using filter %s"
+ search-string locate-current-filter)
+ (error "Locate: no match for %s in database" search-string))))
- (locate-insert-header search-string)
+ (locate-insert-header search-string)
- (while (not (eobp))
- (insert-char ?\ locate-filename-indentation t)
- (locate-set-properties)
- (forward-line 1)))))
+ (while (not (eobp))
+ (insert-char ?\ locate-filename-indentation t)
+ (locate-set-properties)
+ (forward-line 1)))
+ (goto-char (point-min)))
(defun locate-set-properties ()
(save-excursion
(append (list locate-current-filter) locate-format-args)))
(setq locate-format-string
- (concat locate-format-string ": \n\n")
+ (concat locate-format-string ":\n\n")
locate-regexp-match
- (concat locate-regexp-match ": \n"))
+ (concat locate-regexp-match ":\n"))
(insert (apply 'format locate-format-string (reverse locate-format-args)))
(let ((str (car locate-history-list)))
(cond ((yes-or-no-p "Update locate database (may take a few seconds)? ")
(shell-command locate-update-command)
- (locate nil str)))))
+ (locate str)))))
;;; Modified three functions from `dired.el':
;;; dired-find-directory,
(list (concat "--database="
(expand-file-name database))
string))))))
- (locate nil search-string)))
+ (locate search-string)))
(provide 'locate)