+;;; Modified three functions from `dired.el':
+;;; dired-find-directory,
+;;; dired-find-directory-other-window
+;;; dired-get-filename
+
+(defun locate-find-directory ()
+ "Visit the directory of the file mentioned on this line."
+ (interactive)
+ (if (locate-main-listing-line-p)
+ (let ((directory-name (locate-get-dirname)))
+ (if (file-directory-p directory-name)
+ (find-file directory-name)
+ (if (file-symlink-p directory-name)
+ (error "Directory is a symlink to a nonexistent target")
+ (error "Directory no longer exists; run `updatedb' to update database"))))
+ (message "This command only works inside main listing.")))
+
+(defun locate-find-directory-other-window ()
+ "Visit the directory of the file named on this line in other window."
+ (interactive)
+ (find-file-other-window (locate-get-dirname)))
+
+(defun locate-get-dirname ()
+ "Return the directory name of the file mentioned on this line."
+ (let (file (filepos (locate-get-file-positions)))
+ (if (setq file (buffer-substring (nth 0 filepos) (nth 1 filepos)))
+ (progn
+ ;; Get rid of the mouse-face property that file names have.
+ (set-text-properties 0 (length file) nil file)
+ (setq file (file-name-directory file))
+ ;; Unquote names quoted by ls or by dired-insert-directory.
+ ;; Using read to unquote is much faster than substituting
+ ;; \007 (4 chars) -> ^G (1 char) etc. in a lisp loop.
+ (setq file
+ (read
+ (concat "\""
+ ;; some ls -b don't escape quotes, argh!
+ ;; This is not needed for GNU ls, though.
+ (or (dired-string-replace-match
+ "\\([^\\]\\|\\`\\)\"" file "\\1\\\\\"" nil t)
+ file)
+ "\"")))))
+ (and file buffer-file-coding-system
+ (not file-name-coding-system)
+ (setq file (encode-coding-string file buffer-file-coding-system)))
+ file))
+
+;; Only for GNU locate
+(defun locate-in-alternate-database (search-string database)
+ "Run the GNU locate command, using an alternate database."
+ (interactive
+ (list
+ (progn
+ ;; (require 'locate)
+ (read-from-minibuffer "Locate: " nil nil
+ nil 'locate-history-list))
+ (read-file-name "Locate using Database: " )
+ ))
+ (or (file-exists-p database)
+ (error "Database file %s does not exist" database))
+ (let ((locate-make-command-line
+ (function (lambda (string)
+ (cons locate-command
+ (list (concat "--database="
+ (expand-file-name database))
+ string))))))
+ (locate search-string)))
+
+(defun locate-do-redisplay (&optional arg test-for-subdir)
+ "Like `dired-do-redisplay', but adapted for `*Locate*' buffers."
+ (interactive "P\np")
+ (if (string= (dired-current-directory) "/")
+ (message "This command only works in subdirectories.")
+ (let ((dired-actual-switches locate-ls-subdir-switches))
+ (dired-do-redisplay arg test-for-subdir))))
+