diff options
| author | Richard M. Stallman | 1997-03-24 23:59:44 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1997-03-24 23:59:44 +0000 |
| commit | 201bf3329c1699f641b8ee9218ab9e0c3660494b (patch) | |
| tree | 38debda7f8d4c2f930fdc7b44e48f0306779bdcb | |
| parent | debdd3caeaeb5c14cdfd5c3039aae773d4757c84 (diff) | |
| download | emacs-201bf3329c1699f641b8ee9218ab9e0c3660494b.tar.gz emacs-201bf3329c1699f641b8ee9218ab9e0c3660494b.zip | |
(grep-program): New variable.
(grep-command): Use it, and test whether it supports the -e
option; fix doc string (last command is stored in history variable).
(grep-null-device): Declare before grep-program and grep-command.
(grep-find-use-xargs, grep-find-command, grep-find-history):
New variables.
(grep-find): New command.
(grep): Only concatenate grep-null-device to COMMAND when it's
not nil (to support grep-find).
| -rw-r--r-- | lisp/progmodes/compile.el | 68 |
1 files changed, 65 insertions, 3 deletions
diff --git a/lisp/progmodes/compile.el b/lisp/progmodes/compile.el index 2d2bd775978..77330d2b66b 100644 --- a/lisp/progmodes/compile.el +++ b/lisp/progmodes/compile.el | |||
| @@ -256,8 +256,52 @@ Otherwise, it saves all modified buffers without asking.") | |||
| 256 | '(("^\\([a-zA-Z]?:?[^:( \t\n]+\\)[:( \t]+\\([0-9]+\\)[:) \t]" 1 2)) | 256 | '(("^\\([a-zA-Z]?:?[^:( \t\n]+\\)[:( \t]+\\([0-9]+\\)[:) \t]" 1 2)) |
| 257 | "Regexp used to match grep hits. See `compilation-error-regexp-alist'.") | 257 | "Regexp used to match grep hits. See `compilation-error-regexp-alist'.") |
| 258 | 258 | ||
| 259 | (defvar grep-command "grep -n " | 259 | ;; Use zgrep if available, to work nicely with compressed files. |
| 260 | "Last grep command used in \\[grep]; default for next grep.") | 260 | ;; Otherwise, use ordinary grep. |
| 261 | (defvar grep-program | ||
| 262 | (if (equal (condition-case nil ; in case "zgrep" isn't in exec-path | ||
| 263 | (call-process "zgrep" nil nil nil | ||
| 264 | "foo" grep-null-device) | ||
| 265 | (error nil)) | ||
| 266 | 1) | ||
| 267 | "zgrep" | ||
| 268 | "grep") | ||
| 269 | "The default grep program for `grep-command' and `grep-find-command'.") | ||
| 270 | |||
| 271 | ;; Use -e if grep supports it, | ||
| 272 | ;; because that avoids lossage if the pattern starts with `-'. | ||
| 273 | (defvar grep-command | ||
| 274 | (if (equal (condition-case nil ; in case "grep" isn't in exec-path | ||
| 275 | (call-process grep-program nil nil nil | ||
| 276 | "-e" "foo" grep-null-device) | ||
| 277 | (error nil)) | ||
| 278 | 1) | ||
| 279 | (format "%s -n -e " grep-program) | ||
| 280 | (format "%s -n " grep-program)) | ||
| 281 | "The default grep command for \\[grep].") | ||
| 282 | |||
| 283 | (defvar grep-find-use-xargs | ||
| 284 | (if (equal (call-process "find" nil nil nil | ||
| 285 | grep-null-device "-print0") | ||
| 286 | 0) | ||
| 287 | 'gnu) | ||
| 288 | "Whether \\[grep-find] uses the `xargs' utility by default. | ||
| 289 | |||
| 290 | If nil, it uses `grep -exec'; if `gnu', it uses `find -print0' and `xargs -0'; | ||
| 291 | if not nil and not `gnu', it uses `find -print' and `xargs'. | ||
| 292 | |||
| 293 | This variable's value takes effect when `compile.el' is loaded | ||
| 294 | by influencing the default value for the variable `grep-find-command'.") | ||
| 295 | |||
| 296 | (defvar grep-find-command | ||
| 297 | (cond ((eq grep-find-use-xargs 'gnu) | ||
| 298 | (format "find . -type f -print0 | xargs -0 -e %s" grep-command)) | ||
| 299 | (grep-find-use-xargs | ||
| 300 | (format "find . -type f -print | xargs %s" grep-command)) | ||
| 301 | (t (cons (format "find . -type f -exec %s {} /dev/null \\;" | ||
| 302 | grep-command) | ||
| 303 | (+ 22 (length grep-command))))) | ||
| 304 | "The default find command for \\[grep-find].") | ||
| 261 | 305 | ||
| 262 | ;;;###autoload | 306 | ;;;###autoload |
| 263 | (defvar compilation-search-path '(nil) | 307 | (defvar compilation-search-path '(nil) |
| @@ -308,6 +352,7 @@ write into the compilation buffer, and to put in its mode line.") | |||
| 308 | (defvar compile-history nil) | 352 | (defvar compile-history nil) |
| 309 | ;; History of grep commands. | 353 | ;; History of grep commands. |
| 310 | (defvar grep-history nil) | 354 | (defvar grep-history nil) |
| 355 | (defvar grep-find-history nil) | ||
| 311 | 356 | ||
| 312 | (defun compilation-mode-font-lock-keywords () | 357 | (defun compilation-mode-font-lock-keywords () |
| 313 | "Return expressions to highlight in Compilation mode." | 358 | "Return expressions to highlight in Compilation mode." |
| @@ -392,11 +437,28 @@ easily repeat a grep command." | |||
| 392 | ;; Setting process-setup-function makes exit-message-function work | 437 | ;; Setting process-setup-function makes exit-message-function work |
| 393 | ;; even when async processes aren't supported. | 438 | ;; even when async processes aren't supported. |
| 394 | (let* ((compilation-process-setup-function 'grep-process-setup) | 439 | (let* ((compilation-process-setup-function 'grep-process-setup) |
| 395 | (buf (compile-internal (concat command-args " " grep-null-device) | 440 | (buf (compile-internal (if grep-null-device |
| 441 | (concat command-args " " grep-null-device) | ||
| 442 | command-args) | ||
| 396 | "No more grep hits" "grep" | 443 | "No more grep hits" "grep" |
| 397 | ;; Give it a simpler regexp to match. | 444 | ;; Give it a simpler regexp to match. |
| 398 | nil grep-regexp-alist))))) | 445 | nil grep-regexp-alist))))) |
| 399 | 446 | ||
| 447 | |||
| 448 | ;;;###autoload | ||
| 449 | (defun grep-find (command-args) | ||
| 450 | "Run grep via find, with user-specified args, and collect output in a buffer. | ||
| 451 | While find runs asynchronously, you can use the \\[next-error] command | ||
| 452 | to find the text that grep hits refer to. | ||
| 453 | |||
| 454 | This command uses a special history list for its arguments, so you can | ||
| 455 | easily repeat a find command." | ||
| 456 | (interactive | ||
| 457 | (list (read-from-minibuffer "Run find (like this): " | ||
| 458 | grep-find-command nil nil 'grep-find-history))) | ||
| 459 | (let ((grep-null-device nil)) ; see grep | ||
| 460 | (grep command-args))) | ||
| 461 | |||
| 400 | (defun compile-internal (command error-message | 462 | (defun compile-internal (command error-message |
| 401 | &optional name-of-mode parser regexp-alist | 463 | &optional name-of-mode parser regexp-alist |
| 402 | name-function) | 464 | name-function) |