* net/tramp-sh.el (tramp-sh-handle-copy-directory):
[bpt/emacs.git] / lisp / locate.el
index bc2dce9..99a9985 100644 (file)
@@ -1,17 +1,16 @@
 ;;; locate.el --- interface to the locate command
 
 ;;; locate.el --- interface to the locate command
 
-;; Copyright (C) 1996, 1998, 2001, 2002, 2003, 2004,
-;;   2005, 2006, 2007 Free Software Foundation, Inc.
+;; Copyright (C) 1996, 1998, 2001-2013 Free Software Foundation, Inc.
 
 ;; Author: Peter Breton <pbreton@cs.umb.edu>
 ;; Keywords: unix files
 
 ;; This file is part of GNU Emacs.
 
 
 ;; Author: Peter Breton <pbreton@cs.umb.edu>
 ;; Keywords: unix files
 
 ;; This file is part of GNU Emacs.
 
-;; GNU Emacs is free software; you can redistribute it and/or modify
+;; GNU Emacs is free software: you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
 ;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 3, or (at your option)
-;; any later version.
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
 
 ;; GNU Emacs is distributed in the hope that it will be useful,
 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
 
 ;; GNU Emacs is distributed in the hope that it will be useful,
 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -19,9 +18,7 @@
 ;; GNU General Public License for more details.
 
 ;; You should have received a copy of the GNU General Public License
 ;; GNU General Public License for more details.
 
 ;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs; see the file COPYING.  If not, write to the
-;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-;; Boston, MA 02110-1301, USA.
+;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
 
 ;;; Commentary:
 
 
 ;;; Commentary:
 
@@ -37,7 +34,7 @@
 ;;
 ;;   SHELLPROGRAM  Name-to-find
 ;;
 ;;
 ;;   SHELLPROGRAM  Name-to-find
 ;;
-;; set the variable `locate-command' in your .emacs file.
+;; set the variable `locate-command' in your init file.
 ;;
 ;;   To use a more complicated expression, create a function which
 ;; takes a string (the name to find) as input and returns a list.
 ;;
 ;;   To use a more complicated expression, create a function which
 ;; takes a string (the name to find) as input and returns a list.
@@ -98,8 +95,8 @@
 ;;
 ;; (defadvice dired-make-relative (before set-no-error activate)
 ;;   "For locate mode and Windows, don't return errors"
 ;;
 ;; (defadvice dired-make-relative (before set-no-error activate)
 ;;   "For locate mode and Windows, don't return errors"
-;;   (if (and (eq   major-mode  'locate-mode)
-;;        (memq system-type (list 'windows-nt 'ms-dos)))
+;;   (if (and (derived-mode-p 'locate-mode)
+;;        (memq system-type '(windows-nt ms-dos)))
 ;;       (ad-set-arg 2 t)
 ;;     ))
 ;;
 ;;       (ad-set-arg 2 t)
 ;;     ))
 ;;
 \f
 ;;; Code:
 
 \f
 ;;; Code:
 
-(eval-when-compile
-  (require 'dired))
+(require 'dired)
 
 ;; Variables
 
 
 ;; Variables
 
@@ -148,6 +144,11 @@ the version.)"
   :type 'string
   :group 'locate)
 
   :type 'string
   :group 'locate)
 
+(defcustom locate-post-command-hook nil
+  "List of hook functions run after `locate' (see `run-hooks')."
+  :type  'hook
+  :group 'locate)
+
 (defvar locate-history-list nil
   "The history list used by the \\[locate] command.")
 
 (defvar locate-history-list nil
   "The history list used by the \\[locate] command.")
 
@@ -187,7 +188,7 @@ or `locate-make-command-line', determines the database."
   :group 'locate)
 
 ;;;###autoload
   :group 'locate)
 
 ;;;###autoload
-(defcustom locate-ls-subdir-switches "-al"
+(defcustom locate-ls-subdir-switches (purecopy "-al")
   "`ls' switches for inserting subdirectories in `*Locate*' buffers.
 This should contain the \"-l\" switch, but not the \"-F\" or \"-b\" switches."
   :type 'string
   "`ls' switches for inserting subdirectories in `*Locate*' buffers.
 This should contain the \"-l\" switch, but not the \"-F\" or \"-b\" switches."
   :type 'string
@@ -229,6 +230,11 @@ that is, with a prefix arg, you get the default behavior."
   :group 'locate
   :type 'boolean)
 
   :group 'locate
   :type 'boolean)
 
+(defcustom locate-mode-hook nil
+  "List of hook functions run by `locate-mode' (see `run-mode-hooks')."
+  :type  'hook
+  :group 'locate)
+
 ;; Functions
 
 (defun locate-default-make-command-line (search-string)
 ;; Functions
 
 (defun locate-default-make-command-line (search-string)
@@ -273,7 +279,7 @@ that is, with a prefix arg, you get the default behavior."
 (defun locate (search-string &optional filter arg)
   "Run the program `locate', putting results in `*Locate*' buffer.
 Pass it SEARCH-STRING as argument.  Interactively, prompt for SEARCH-STRING.
 (defun locate (search-string &optional filter arg)
   "Run the program `locate', putting results in `*Locate*' buffer.
 Pass it SEARCH-STRING as argument.  Interactively, prompt for SEARCH-STRING.
-With prefix arg, prompt for the exact shell command to run instead.
+With prefix arg ARG, prompt for the exact shell command to run instead.
 
 This program searches for those file names in a database that match
 SEARCH-STRING and normally outputs all matching absolute file names,
 
 This program searches for those file names in a database that match
 SEARCH-STRING and normally outputs all matching absolute file names,
@@ -289,7 +295,8 @@ the variables `locate-command' or `locate-make-command-line'.
 The main use of FILTER is to implement `locate-with-filter'.  See
 the docstring of that function for its meaning.
 
 The main use of FILTER is to implement `locate-with-filter'.  See
 the docstring of that function for its meaning.
 
-ARG is the interactive prefix arg."
+After preparing the results buffer, this runs `dired-mode-hook' and
+then `locate-post-command-hook'."
   (interactive
    (list
     (locate-prompt-for-search-string)
   (interactive
    (list
     (locate-prompt-for-search-string)
@@ -303,8 +310,7 @@ ARG is the interactive prefix arg."
         (locate-cmd-args (cdr locate-cmd-list))
         (run-locate-command
          (or (and arg (not locate-prompt-for-command))
         (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)))
-        )
+             (and (not arg) locate-prompt-for-command))))
 
     ;; Find the Locate buffer
     (save-window-excursion
 
     ;; Find the Locate buffer
     (save-window-excursion
@@ -326,16 +332,13 @@ ARG is the interactive prefix arg."
        (and filter
             (locate-filter-output filter))
 
        (and filter
             (locate-filter-output filter))
 
-       (locate-do-setup search-string)
-       ))
+       (locate-do-setup search-string)))
     (and (not (string-equal (buffer-name) locate-buffer-name))
     (and (not (string-equal (buffer-name) locate-buffer-name))
-       (switch-to-buffer-other-window locate-buffer-name))
+       (pop-to-buffer locate-buffer-name))
 
     (run-hooks 'dired-mode-hook)
     (dired-next-line 3)                        ;move to first matching file.
 
     (run-hooks 'dired-mode-hook)
     (dired-next-line 3)                        ;move to first matching file.
-    (run-hooks 'locate-post-command-hook)
-    )
-  )
+    (run-hooks 'locate-post-command-hook)))
 
 ;;;###autoload
 (defun locate-with-filter (search-string filter &optional arg)
 
 ;;;###autoload
 (defun locate-with-filter (search-string filter &optional arg)
@@ -365,31 +368,22 @@ except that FILTER is not optional."
   (goto-char (point-min))
   (keep-lines filter))
 
   (goto-char (point-min))
   (keep-lines filter))
 
-(defvar locate-mode-map nil
+(defvar locate-mode-map
+  (let ((map (copy-keymap dired-mode-map)))
+    ;; Undefine Useless Dired Menu bars
+    (define-key map [menu-bar Dired]   'undefined)
+    (define-key map [menu-bar subdir]  'undefined)
+    (define-key map [menu-bar mark executables] 'undefined)
+    (define-key map [menu-bar mark directory]   'undefined)
+    (define-key map [menu-bar mark directories] 'undefined)
+    (define-key map [menu-bar mark symlinks]    'undefined)
+    (define-key map [M-mouse-2] 'locate-mouse-view-file)
+    (define-key map "\C-c\C-t"  'locate-tags)
+    (define-key map "l"       'locate-do-redisplay)
+    (define-key map "U"       'dired-unmark-all-files)
+    (define-key map "V"       'locate-find-directory)
+    map)
   "Local keymap for Locate mode buffers.")
   "Local keymap for Locate mode buffers.")
-(if locate-mode-map
-    nil
-
-   (require 'dired)
-
-   (setq locate-mode-map (copy-keymap dired-mode-map))
-
-   ;; Undefine Useless Dired Menu bars
-   (define-key locate-mode-map [menu-bar Dired]   'undefined)
-   (define-key locate-mode-map [menu-bar subdir]  'undefined)
-
-   (define-key locate-mode-map [menu-bar mark executables] 'undefined)
-   (define-key locate-mode-map [menu-bar mark directory]   'undefined)
-   (define-key locate-mode-map [menu-bar mark directories] 'undefined)
-   (define-key locate-mode-map [menu-bar mark symlinks]    'undefined)
-
-   (define-key locate-mode-map [M-mouse-2] 'locate-mouse-view-file)
-   (define-key locate-mode-map "\C-c\C-t"  'locate-tags)
-
-   (define-key locate-mode-map "l"       'locate-do-redisplay)
-   (define-key locate-mode-map "U"       'dired-unmark-all-files)
-   (define-key locate-mode-map "V"       'locate-find-directory)
-)
 
 ;; This variable is used to indent the lines and then to search for
 ;; the file name
 
 ;; This variable is used to indent the lines and then to search for
 ;; the file name
@@ -454,11 +448,12 @@ file name or is inside a subdirectory."
 ;; Define a mode for locate
 ;; Default directory is set to "/" so that dired commands, which
 ;; expect to be in a tree, will work properly
 ;; Define a mode for locate
 ;; Default directory is set to "/" so that dired commands, which
 ;; expect to be in a tree, will work properly
-(defun locate-mode ()
+(define-derived-mode locate-mode special-mode "Locate"
   "Major mode for the `*Locate*' buffer made by \\[locate].
 \\<locate-mode-map>\
 In that buffer, you can use almost all the usual dired bindings.
 \\[locate-find-directory] visits the directory of the file on the current line.
   "Major mode for the `*Locate*' buffer made by \\[locate].
 \\<locate-mode-map>\
 In that buffer, you can use almost all the usual dired bindings.
 \\[locate-find-directory] visits the directory of the file on the current line.
+This function runs `locate-mode-hook' before returning.
 
 Operating on listed files works, but does not always
 automatically update the buffer as in ordinary Dired.
 
 Operating on listed files works, but does not always
 automatically update the buffer as in ordinary Dired.
@@ -468,39 +463,32 @@ Specific `locate-mode' commands, such as \\[locate-find-directory],
 do not work in subdirectories.
 
 \\{locate-mode-map}"
 do not work in subdirectories.
 
 \\{locate-mode-map}"
-  ;; Not to be called interactively.
-  (kill-all-local-variables)
   ;; Avoid clobbering this variable
   (make-local-variable 'dired-subdir-alist)
   ;; Avoid clobbering this variable
   (make-local-variable 'dired-subdir-alist)
-  (use-local-map             locate-mode-map)
-  (setq major-mode          'locate-mode
-        mode-name           "Locate"
-        default-directory   "/"
+  (setq default-directory   "/"
        buffer-read-only    t
        selective-display   t)
   (dired-alist-add-1 default-directory (point-min-marker))
   (set (make-local-variable 'dired-directory) "/")
   (set (make-local-variable 'dired-subdir-switches) locate-ls-subdir-switches)
   (setq dired-switches-alist nil)
        buffer-read-only    t
        selective-display   t)
   (dired-alist-add-1 default-directory (point-min-marker))
   (set (make-local-variable 'dired-directory) "/")
   (set (make-local-variable 'dired-subdir-switches) locate-ls-subdir-switches)
   (setq dired-switches-alist nil)
-  (make-local-variable 'directory-listing-before-filename-regexp)
   ;; This should support both Unix and Windoze style names
   ;; This should support both Unix and Windoze style names
-  (setq directory-listing-before-filename-regexp
-       (concat "^."
-               (make-string (1- locate-filename-indentation) ?\s)
-               "\\(/\\|[A-Za-z]:\\)\\|"
-               (default-value 'directory-listing-before-filename-regexp)))
-  (make-local-variable 'dired-actual-switches)
-  (setq dired-actual-switches "")
-  (make-local-variable 'dired-permission-flags-regexp)
-  (setq dired-permission-flags-regexp
-       (concat "^.\\("
-               (make-string (1- locate-filename-indentation) ?\s)
-               "\\)\\|"
-               (default-value 'dired-permission-flags-regexp)))
-  (make-local-variable 'revert-buffer-function)
-  (setq revert-buffer-function 'locate-update)
-  (set (make-local-variable 'page-delimiter) "\n\n")
-  (run-mode-hooks 'locate-mode-hook))
+  (setq-local directory-listing-before-filename-regexp
+              (concat "^.\\("
+                      (make-string (1- locate-filename-indentation) ?\s)
+                      "\\)\\|"
+                      (default-value
+                        'directory-listing-before-filename-regexp)))
+  (setq-local dired-actual-switches "")
+  (setq-local dired-permission-flags-regexp
+              (concat "^.\\("
+                      (make-string (1- locate-filename-indentation) ?\s)
+                      "\\)\\|"
+                      (default-value 'dired-permission-flags-regexp)))
+
+  (setq-local revert-buffer-function #'locate-update)
+  (setq-local page-delimiter "\n\n"))
+(put 'locate-mode 'derived-mode-parent 'dired-mode)
 
 (defun locate-do-setup (search-string)
   (goto-char (point-min))
 
 (defun locate-do-setup (search-string)
   (goto-char (point-min))
@@ -593,7 +581,7 @@ do not work in subdirectories.
     (message "This command only works inside main listing.")))
 
 ;; From Stephen Eglen <stephen@cns.ed.ac.uk>
     (message "This command only works inside main listing.")))
 
 ;; From Stephen Eglen <stephen@cns.ed.ac.uk>
-(defun locate-update (ignore1 ignore2)
+(defun locate-update (_ignore1 _ignore2)
   "Revert the *Locate* buffer.
 If `locate-update-when-revert' is non-nil, offer to update the
 locate database using the shell command in `locate-update-command'."
   "Revert the *Locate* buffer.
 If `locate-update-when-revert' is non-nil, offer to update the
 locate database using the shell command in `locate-update-command'."
@@ -699,5 +687,4 @@ the database on the command line."
 
 (provide 'locate)
 
 
 (provide 'locate)
 
-;;; arch-tag: 60c4d098-b5d5-4b3c-a3e0-51a2e9f43898
 ;;; locate.el ends here
 ;;; locate.el ends here