Mercurial > emacs
comparison lisp/locate.el @ 69501:c22f46390a8f
(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.
author | Luc Teirlinck <teirllm@auburn.edu> |
---|---|
date | Thu, 16 Mar 2006 01:43:59 +0000 |
parents | 3bd95f4f2941 |
children | 6958f9575abf e3bacb89536a |
comparison
equal
deleted
inserted
replaced
69500:9310e7b7380e | 69501:c22f46390a8f |
---|---|
120 "Interface to the locate command." | 120 "Interface to the locate command." |
121 :prefix "locate-" | 121 :prefix "locate-" |
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 |
129 (defvar locate-history-list nil | 148 (defvar locate-history-list nil |
130 "The history list used by the \\[locate] command.") | 149 "The history list used by the \\[locate] command.") |
131 | 150 |
132 (defvar locate-grep-history-list nil | 151 (defvar locate-grep-history-list nil |
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 |
155 ;;;###autoload | 186 ;;;###autoload |
156 (defcustom locate-ls-subdir-switches "-al" | 187 (defcustom locate-ls-subdir-switches "-al" |
159 :type 'string | 190 :type 'string |
160 :group 'locate | 191 :group 'locate |
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 |
173 ) | 204 ) |
174 | 205 |
189 (point))))) | 220 (point))))) |
190 | 221 |
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 |
198 (not locate-prompt-for-command)) | 244 (not locate-prompt-for-command)) |
199 (and (not current-prefix-arg) locate-prompt-for-command)) | 245 (and (not current-prefix-arg) locate-prompt-for-command)) |
253 ) | 299 ) |
254 ) | 300 ) |
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) |
265 (read-from-minibuffer "Filter: " nil nil | 318 (read-from-minibuffer "Filter: " nil nil |
266 nil 'locate-grep-history-list))) | 319 nil 'locate-grep-history-list))) |
267 (locate search-string filter)) | 320 (locate search-string filter)) |
268 | 321 |
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.") |
276 (if locate-mode-map | 329 (if locate-mode-map |
277 nil | 330 nil |
301 ;; the file name | 354 ;; the file name |
302 (defconst locate-filename-indentation 4 | 355 (defconst locate-filename-indentation 4 |
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))) |
309 (beginning-of-line) | 371 (beginning-of-line) |
310 | 372 |
318 (+ (count-lines (point-min) (point)) | 380 (+ (count-lines (point-min) (point)) |
319 (if (eq (current-column) 0) | 381 (if (eq (current-column) 0) |
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))) |
326 (and (not (eq lineno 1)) | 394 (and (not (eq lineno 1)) |
327 (not (eq lineno 2)) | 395 (not (eq lineno 2)) |
514 (message "This command only works inside main listing."))) | 582 (message "This command only works inside main listing."))) |
515 | 583 |
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) |
520 | 588 (find-file-other-window (locate-get-dirname)) |
589 (message "This command only works inside main listing."))) | |
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))) |
524 (if (setq file (buffer-substring (nth 0 filepos) (nth 1 filepos))) | 600 (if (setq file (buffer-substring (nth 0 filepos) (nth 1 filepos))) |
525 (progn | 601 (progn |