diff options
| author | Luc Teirlinck | 2006-03-16 01:43:59 +0000 |
|---|---|---|
| committer | Luc Teirlinck | 2006-03-16 01:43:59 +0000 |
| commit | 18886d549ffc780c7b12166105f5cf00d0f24e8b (patch) | |
| tree | c4f643f6787d0f3feeff3a2e15f3a5a79bfb4ac3 | |
| parent | e6b7cc22ffa525e868e09b2dddf9303bbd7fef99 (diff) | |
| download | emacs-18886d549ffc780c7b12166105f5cf00d0f24e8b.tar.gz emacs-18886d549ffc780c7b12166105f5cf00d0f24e8b.zip | |
(locate-command, locate-make-command-line)
(locate-fcodes-file, locate-update-command)
(locate-prompt-for-command, locate, locate-with-filter)
(locate-get-file-positions): Doc fixes.
(locate-buffer-name, locate-header-face): Remove leading `*' in defcustom.
(locate-filter-output): Use `keep-lines' instead of its alias
`delete-non-matching-lines'.
(locate-get-filename, locate-get-dirname): Add introductory comment.
(locate-find-directory-other-window): Give appropriate error
message if used outside main listing.
| -rw-r--r-- | lisp/locate.el | 104 |
1 files changed, 90 insertions, 14 deletions
diff --git a/lisp/locate.el b/lisp/locate.el index bca53a32152..702ae98ecd6 100644 --- a/lisp/locate.el +++ b/lisp/locate.el | |||
| @@ -122,7 +122,26 @@ | |||
| 122 | :group 'external) | 122 | :group 'external) |
| 123 | 123 | ||
| 124 | (defcustom locate-command "locate" | 124 | (defcustom locate-command "locate" |
| 125 | "*The executable program used to search a database of files." | 125 | "Executable program for searching a database of files. |
| 126 | The Emacs commands `locate' and `locate-with-filter' use this. | ||
| 127 | The value should be a program that can be called from a shell | ||
| 128 | with one argument, SEARCH-STRING. The program determines which | ||
| 129 | database it searches. The output of the program should consist | ||
| 130 | of those file names in the database that match SEARCH-STRING, | ||
| 131 | listed one per line, possibly with leading or trailing | ||
| 132 | whitespace. If the output is in another form, you may have to | ||
| 133 | redefine the function `locate-get-file-positions'. | ||
| 134 | |||
| 135 | The program may interpret SEARCH-STRING as a literal string, a | ||
| 136 | shell pattern or a regular expression. The exact rules of what | ||
| 137 | constitutes a match may also depend on the program. | ||
| 138 | |||
| 139 | The standard value of this variable is \"locate\". | ||
| 140 | This program normally searches a database of all files on your | ||
| 141 | system, or of all files that you have access to. Consult the | ||
| 142 | documentation of that program for the details about how it determines | ||
| 143 | which file names match SEARCH-STRING. (Those details vary highly with | ||
| 144 | the version.)" | ||
| 126 | :type 'string | 145 | :type 'string |
| 127 | :group 'locate) | 146 | :group 'locate) |
| 128 | 147 | ||
| @@ -133,22 +152,34 @@ | |||
| 133 | "The history list used by the \\[locate-with-filter] command.") | 152 | "The history list used by the \\[locate-with-filter] command.") |
| 134 | 153 | ||
| 135 | (defcustom locate-make-command-line 'locate-default-make-command-line | 154 | (defcustom locate-make-command-line 'locate-default-make-command-line |
| 136 | "*Function used to create the locate command line." | 155 | "Function used to create the locate command line. |
| 156 | The Emacs commands `locate' and `locate-with-filter' use this. | ||
| 157 | This function should take one argument, a string (the name to find) | ||
| 158 | and return a list of strings. The first element of the list should be | ||
| 159 | the name of a command to be executed by a shell, the remaining elements | ||
| 160 | should be the arguments to that command (including the name to find)." | ||
| 137 | :type 'function | 161 | :type 'function |
| 138 | :group 'locate) | 162 | :group 'locate) |
| 139 | 163 | ||
| 140 | (defcustom locate-buffer-name "*Locate*" | 164 | (defcustom locate-buffer-name "*Locate*" |
| 141 | "*Name of the buffer to show results from the \\[locate] command." | 165 | "Name of the buffer to show results from the \\[locate] command." |
| 142 | :type 'string | 166 | :type 'string |
| 143 | :group 'locate) | 167 | :group 'locate) |
| 144 | 168 | ||
| 145 | (defcustom locate-fcodes-file nil | 169 | (defcustom locate-fcodes-file nil |
| 146 | "*File name for the database of file names." | 170 | "File name for the database of file names used by `locate'. |
| 171 | If non-nil, `locate' uses this name in the header of the `*Locate*' | ||
| 172 | buffer. If nil, it mentions no file name in that header. | ||
| 173 | |||
| 174 | Just setting this variable does not actually change the database | ||
| 175 | that `locate' searches. The executive program that the Emacs | ||
| 176 | function `locate' uses, as given by the variables `locate-command' | ||
| 177 | or `locate-make-command-line', determines the database." | ||
| 147 | :type '(choice (const :tag "None" nil) file) | 178 | :type '(choice (const :tag "None" nil) file) |
| 148 | :group 'locate) | 179 | :group 'locate) |
| 149 | 180 | ||
| 150 | (defcustom locate-header-face nil | 181 | (defcustom locate-header-face nil |
| 151 | "*Face used to highlight the locate header." | 182 | "Face used to highlight the locate header." |
| 152 | :type '(choice (const :tag "None" nil) face) | 183 | :type '(choice (const :tag "None" nil) face) |
| 153 | :group 'locate) | 184 | :group 'locate) |
| 154 | 185 | ||
| @@ -161,12 +192,12 @@ This should contain the \"-l\" switch, but not the \"-F\" or \"-b\" switches." | |||
| 161 | :version "22.1") | 192 | :version "22.1") |
| 162 | 193 | ||
| 163 | (defcustom locate-update-command "updatedb" | 194 | (defcustom locate-update-command "updatedb" |
| 164 | "The command used to update the locate database." | 195 | "The executable program used to update the locate database." |
| 165 | :type 'string | 196 | :type 'string |
| 166 | :group 'locate) | 197 | :group 'locate) |
| 167 | 198 | ||
| 168 | (defcustom locate-prompt-for-command nil | 199 | (defcustom locate-prompt-for-command nil |
| 169 | "If non-nil, the locate command prompts for a command to run. | 200 | "If non-nil, the `locate' command prompts for a command to run. |
| 170 | Otherwise, that behavior is invoked via a prefix argument." | 201 | Otherwise, that behavior is invoked via a prefix argument." |
| 171 | :group 'locate | 202 | :group 'locate |
| 172 | :type 'boolean | 203 | :type 'boolean |
| @@ -191,7 +222,22 @@ Otherwise, that behavior is invoked via a prefix argument." | |||
| 191 | ;;;###autoload | 222 | ;;;###autoload |
| 192 | (defun locate (search-string &optional filter) | 223 | (defun locate (search-string &optional filter) |
| 193 | "Run the program `locate', putting results in `*Locate*' buffer. | 224 | "Run the program `locate', putting results in `*Locate*' buffer. |
| 194 | With prefix arg, prompt for the locate command to run." | 225 | Pass it SEARCH-STRING as argument. Interactively, prompt for SEARCH-STRING. |
| 226 | With prefix arg, prompt for the exact shell command to run instead. | ||
| 227 | |||
| 228 | This program searches for those file names in a database that match | ||
| 229 | SEARCH-STRING and normally outputs all matching absolute file names, | ||
| 230 | one per line. The database normally consists of all files on your | ||
| 231 | system, or of all files that you have access to. Consult the | ||
| 232 | documentation of the program for the details about how it determines | ||
| 233 | which file names match SEARCH-STRING. (Those details vary highly with | ||
| 234 | the version.) | ||
| 235 | |||
| 236 | You can specify another program for this command to run by customizing | ||
| 237 | the variables `locate-command' or `locate-make-command-line'. | ||
| 238 | |||
| 239 | The main use of FILTER is to implement `locate-with-filter'. See | ||
| 240 | the docstring of that function for its meaning." | ||
| 195 | (interactive | 241 | (interactive |
| 196 | (list | 242 | (list |
| 197 | (if (or (and current-prefix-arg | 243 | (if (or (and current-prefix-arg |
| @@ -255,10 +301,17 @@ With prefix arg, prompt for the locate command to run." | |||
| 255 | 301 | ||
| 256 | ;;;###autoload | 302 | ;;;###autoload |
| 257 | (defun locate-with-filter (search-string filter) | 303 | (defun locate-with-filter (search-string filter) |
| 258 | "Run the locate command with a filter. | 304 | "Run the executable program `locate' with a filter. |
| 259 | 305 | This function is similar to the function `locate', which see. | |
| 260 | The filter is a regular expression. Only results matching the filter are | 306 | The difference is that, when invoked interactively, the present function |
| 261 | shown; this is often useful to constrain a big search." | 307 | prompts for both SEARCH-STRING and FILTER. It passes SEARCH-STRING |
| 308 | to the locate executable program. It produces a `*Locate*' buffer | ||
| 309 | that lists only those lines in the output of the locate program that | ||
| 310 | contain a match for the regular expression FILTER; this is often useful | ||
| 311 | to constrain a big search. | ||
| 312 | |||
| 313 | When called from Lisp, this function is identical with `locate', | ||
| 314 | except that FILTER is not optional." | ||
| 262 | (interactive | 315 | (interactive |
| 263 | (list (read-from-minibuffer "Locate: " nil nil | 316 | (list (read-from-minibuffer "Locate: " nil nil |
| 264 | nil 'locate-history-list) | 317 | nil 'locate-history-list) |
| @@ -269,7 +322,7 @@ shown; this is often useful to constrain a big search." | |||
| 269 | (defun locate-filter-output (filter) | 322 | (defun locate-filter-output (filter) |
| 270 | "Filter output from the locate command." | 323 | "Filter output from the locate command." |
| 271 | (goto-char (point-min)) | 324 | (goto-char (point-min)) |
| 272 | (delete-non-matching-lines filter)) | 325 | (keep-lines filter)) |
| 273 | 326 | ||
| 274 | (defvar locate-mode-map nil | 327 | (defvar locate-mode-map nil |
| 275 | "Local keymap for Locate mode buffers.") | 328 | "Local keymap for Locate mode buffers.") |
| @@ -303,6 +356,15 @@ shown; this is often useful to constrain a big search." | |||
| 303 | "The amount of indentation for each file.") | 356 | "The amount of indentation for each file.") |
| 304 | 357 | ||
| 305 | (defun locate-get-file-positions () | 358 | (defun locate-get-file-positions () |
| 359 | "Return list of start and end of the file name on the current line. | ||
| 360 | This is a list of two buffer positions. | ||
| 361 | |||
| 362 | You should only call this function on lines that contain a file name | ||
| 363 | listed by the locate program. Inside inserted subdirectories, or if | ||
| 364 | there is no file name on the current line, the return value is | ||
| 365 | meaningless. You can check whether the current line contains a file | ||
| 366 | listed by the locate program, using the function | ||
| 367 | `locate-main-listing-line-p'." | ||
| 306 | (save-excursion | 368 | (save-excursion |
| 307 | (end-of-line) | 369 | (end-of-line) |
| 308 | (let ((eol (point))) | 370 | (let ((eol (point))) |
| @@ -320,6 +382,12 @@ shown; this is often useful to constrain a big search." | |||
| 320 | 1 | 382 | 1 |
| 321 | 0))) | 383 | 0))) |
| 322 | 384 | ||
| 385 | ;; You should only call this function on lines that contain a file name | ||
| 386 | ;; listed by the locate program. Inside inserted subdirectories, or if | ||
| 387 | ;; there is no file name on the current line, the return value is | ||
| 388 | ;; meaningless. You can check whether the current line contains a file | ||
| 389 | ;; listed by the locate program, using the function | ||
| 390 | ;; `locate-main-listing-line-p'. | ||
| 323 | (defun locate-get-filename () | 391 | (defun locate-get-filename () |
| 324 | (let ((pos (locate-get-file-positions)) | 392 | (let ((pos (locate-get-file-positions)) |
| 325 | (lineno (locate-current-line-number))) | 393 | (lineno (locate-current-line-number))) |
| @@ -516,8 +584,16 @@ Database is updated using the shell command in `locate-update-command'." | |||
| 516 | (defun locate-find-directory-other-window () | 584 | (defun locate-find-directory-other-window () |
| 517 | "Visit the directory of the file named on this line in other window." | 585 | "Visit the directory of the file named on this line in other window." |
| 518 | (interactive) | 586 | (interactive) |
| 519 | (find-file-other-window (locate-get-dirname))) | 587 | (if (locate-main-listing-line-p) |
| 588 | (find-file-other-window (locate-get-dirname)) | ||
| 589 | (message "This command only works inside main listing."))) | ||
| 520 | 590 | ||
| 591 | ;; You should only call this function on lines that contain a file name | ||
| 592 | ;; listed by the locate program. Inside inserted subdirectories, or if | ||
| 593 | ;; there is no file name on the current line, the return value is | ||
| 594 | ;; meaningless. You can check whether the current line contains a file | ||
| 595 | ;; listed by the locate program, using the function | ||
| 596 | ;; `locate-main-listing-line-p'. | ||
| 521 | (defun locate-get-dirname () | 597 | (defun locate-get-dirname () |
| 522 | "Return the directory name of the file mentioned on this line." | 598 | "Return the directory name of the file mentioned on this line." |
| 523 | (let (file (filepos (locate-get-file-positions))) | 599 | (let (file (filepos (locate-get-file-positions))) |