diff options
| author | Stefan Monnier | 2004-03-11 22:56:19 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2004-03-11 22:56:19 +0000 |
| commit | ab55f76f9ca670e3f41e4cfabeb35426f6b24fb6 (patch) | |
| tree | 809c3b62a3545d9173abe146e2c1c8880fb51832 | |
| parent | 2f0c11a15d15372775c19b9f900b3309e284ab9b (diff) | |
| download | emacs-ab55f76f9ca670e3f41e4cfabeb35426f6b24fb6.tar.gz emacs-ab55f76f9ca670e3f41e4cfabeb35426f6b24fb6.zip | |
(kill-grep): Move here from compile.el
(grep-error, grep-hit-face, grep-error-face)
(grep-mode-font-lock-keywords): New variables.
(grep-regexp-alist): Simplify regexp and add `binary' case.
(grep-mode): New mode.
(grep-process-setup): Simplify.
| -rw-r--r-- | lisp/progmodes/grep.el | 69 |
1 files changed, 47 insertions, 22 deletions
diff --git a/lisp/progmodes/grep.el b/lisp/progmodes/grep.el index 03f267cb133..94937ba1e87 100644 --- a/lisp/progmodes/grep.el +++ b/lisp/progmodes/grep.el | |||
| @@ -194,6 +194,8 @@ The following place holders should be present in the string: | |||
| 194 | "Keymap for grep buffers. | 194 | "Keymap for grep buffers. |
| 195 | `compilation-minor-mode-map' is a cdr of this.") | 195 | `compilation-minor-mode-map' is a cdr of this.") |
| 196 | 196 | ||
| 197 | (defalias 'kill-grep 'kill-compilation) | ||
| 198 | |||
| 197 | ;;;; TODO --- refine this!! | 199 | ;;;; TODO --- refine this!! |
| 198 | 200 | ||
| 199 | ;;; (defcustom grep-use-compilation-buffer t | 201 | ;;; (defcustom grep-use-compilation-buffer t |
| @@ -213,12 +215,39 @@ or when it is used with \\[grep-next-match]. | |||
| 213 | Notice that using \\[next-error] or \\[compile-goto-error] modifies | 215 | Notice that using \\[next-error] or \\[compile-goto-error] modifies |
| 214 | `complation-last-buffer' rather than `grep-last-buffer'.") | 216 | `complation-last-buffer' rather than `grep-last-buffer'.") |
| 215 | 217 | ||
| 216 | ;; Note: the character class after the optional drive letter does not | ||
| 217 | ;; include a space to support file names with blanks. | ||
| 218 | (defvar grep-regexp-alist | 218 | (defvar grep-regexp-alist |
| 219 | '(("\\([a-zA-Z]?:?.+?\\)[:( \t]+\\([0-9]+\\)[:) \t]" 1 2)) | 219 | '(("^\\(.+?\\)[:( \t]+\\([0-9]+\\)[:) \t]" 1 2) |
| 220 | ("^Binary file \\(.+\\) matches$" 1 nil nil 1)) | ||
| 220 | "Regexp used to match grep hits. See `compilation-error-regexp-alist'.") | 221 | "Regexp used to match grep hits. See `compilation-error-regexp-alist'.") |
| 221 | 222 | ||
| 223 | (defvar grep-error "grep hit" | ||
| 224 | "Message to print when no matches are found.") | ||
| 225 | |||
| 226 | ;; Reverse the colors because grep hits are not errors (though we jump there | ||
| 227 | ;; with `next-error'), and unreadable files can't be gone to. | ||
| 228 | (defvar grep-hit-face compilation-info-face | ||
| 229 | "Face name to use for grep hits.") | ||
| 230 | |||
| 231 | (defvar grep-error-face compilation-error-face | ||
| 232 | "Face name to use for grep error messages.") | ||
| 233 | |||
| 234 | (defvar grep-mode-font-lock-keywords | ||
| 235 | '(;; Command output lines. | ||
| 236 | ("^\\([A-Za-z_0-9/\.+-]+\\)[ \t]*:" 1 font-lock-function-name-face) | ||
| 237 | (": \\(.+\\): \\(?:Permission denied\\|No such \\(?:file or directory\\|device or address\\)\\)$" | ||
| 238 | 1 grep-error-face) | ||
| 239 | ;; remove match from grep-regexp-alist before fontifying | ||
| 240 | ("^Grep finished \\(?:(\\(matches found\\))\\|with \\(no matches found\\)\\).*" | ||
| 241 | (0 '(face nil message nil help-echo nil mouse-face nil) t) | ||
| 242 | (1 grep-hit-face nil t) | ||
| 243 | (2 grep-error-face nil t)) | ||
| 244 | ("^Grep \\(exited abnormally\\) with code \\([0-9]+\\).*" | ||
| 245 | (0 '(face nil message nil help-echo nil mouse-face nil) t) | ||
| 246 | (1 compilation-warning-face) | ||
| 247 | (2 compilation-line-face))) | ||
| 248 | "Additional things to highlight in grep output. | ||
| 249 | This gets tacked on the end of the generated expressions.") | ||
| 250 | |||
| 222 | (defvar grep-program | 251 | (defvar grep-program |
| 223 | ;; Currently zgrep has trouble. It runs egrep instead of grep, | 252 | ;; Currently zgrep has trouble. It runs egrep instead of grep, |
| 224 | ;; and it doesn't pass along long options right. | 253 | ;; and it doesn't pass along long options right. |
| @@ -251,9 +280,7 @@ This variable's value takes effect when `grep-compute-defaults' is called.") | |||
| 251 | 280 | ||
| 252 | (defun grep-process-setup () | 281 | (defun grep-process-setup () |
| 253 | "Setup compilation variables and buffer for `grep'. | 282 | "Setup compilation variables and buffer for `grep'. |
| 254 | Set up `compilation-exit-message-function' and `compilation-window-height'. | 283 | Set up `compilation-exit-message-function' and run `grep-setup-hook'." |
| 255 | Sets `grep-last-buffer' and runs `grep-setup-hook'." | ||
| 256 | (setq grep-last-buffer (current-buffer)) | ||
| 257 | (set (make-local-variable 'compilation-exit-message-function) | 284 | (set (make-local-variable 'compilation-exit-message-function) |
| 258 | (lambda (status code msg) | 285 | (lambda (status code msg) |
| 259 | (if (eq status 'exit) | 286 | (if (eq status 'exit) |
| @@ -264,13 +291,6 @@ Sets `grep-last-buffer' and runs `grep-setup-hook'." | |||
| 264 | (t | 291 | (t |
| 265 | (cons msg code))) | 292 | (cons msg code))) |
| 266 | (cons msg code)))) | 293 | (cons msg code)))) |
| 267 | (if grep-window-height | ||
| 268 | (set (make-local-variable 'compilation-window-height) | ||
| 269 | grep-window-height)) | ||
| 270 | (set (make-local-variable 'compile-auto-highlight) | ||
| 271 | grep-auto-highlight) | ||
| 272 | (set (make-local-variable 'compilation-scroll-output) | ||
| 273 | grep-scroll-output) | ||
| 274 | (run-hooks 'grep-setup-hook)) | 294 | (run-hooks 'grep-setup-hook)) |
| 275 | 295 | ||
| 276 | (defun grep-compute-defaults () | 296 | (defun grep-compute-defaults () |
| @@ -402,15 +422,20 @@ temporarily highlight in visited source lines." | |||
| 402 | 422 | ||
| 403 | ;; Setting process-setup-function makes exit-message-function work | 423 | ;; Setting process-setup-function makes exit-message-function work |
| 404 | ;; even when async processes aren't supported. | 424 | ;; even when async processes aren't supported. |
| 405 | (let* ((compilation-process-setup-function 'grep-process-setup) | 425 | (let ((compilation-process-setup-function 'grep-process-setup)) |
| 406 | (buf (compile-internal (if (and grep-use-null-device null-device) | 426 | (compilation-start (if (and grep-use-null-device null-device) |
| 407 | (concat command-args " " null-device) | 427 | (concat command-args " " null-device) |
| 408 | command-args) | 428 | command-args) |
| 409 | "No more grep hits" "grep" | 429 | 'grep-mode nil highlight-regexp))) |
| 410 | ;; Give it a simpler regexp to match. | 430 | |
| 411 | nil grep-regexp-alist | 431 | ;;;###autoload (autoload 'grep-mode "grep" nil t) |
| 412 | nil nil nil nil nil nil | 432 | (define-compilation-mode grep-mode "Grep" |
| 413 | highlight-regexp grep-mode-map))))) | 433 | "Sets `grep-last-buffer' and `compilation-window-height'." |
| 434 | (setq grep-last-buffer (current-buffer)) | ||
| 435 | (set (make-local-variable 'compilation-error-face) | ||
| 436 | grep-hit-face) | ||
| 437 | (set (make-local-variable 'compilation-error-regexp-alist) | ||
| 438 | grep-regexp-alist)) | ||
| 414 | 439 | ||
| 415 | ;; This is a copy of find-tag-default from etags.el. | 440 | ;; This is a copy of find-tag-default from etags.el. |
| 416 | (defun grep-tag-default () | 441 | (defun grep-tag-default () |