• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /macosx-10.9.5/emacs-92/emacs/lisp/progmodes/

Lines Matching +defs:grep +defs:find

0 ;;; grep.el --- run Grep as inferior of Emacs, parse match messages
29 ;; This package provides the grep facilities documented in the Emacs
37 (defgroup grep nil
38 "Run grep as inferior of Emacs, parse error messages."
44 (defcustom grep-window-height nil
45 "*Number of lines in a grep window. If nil, use `compilation-window-height'."
49 :group 'grep)
51 (defcustom grep-highlight-matches 'auto-detect
52 "If t, use special markers to highlight grep matches.
54 Some grep programs are able to surround matches with special
55 markers in grep output. Such markers can be used to highlight
56 matches in grep mode.
60 option in front of any explicit grep options before starting
61 the grep.
63 The default value of this variable is set up by `grep-compute-defaults';
65 :type '(choice (const :tag "Do not highlight matches with grep markers" nil)
66 (const :tag "Highlight matches with grep markers" t)
69 :group 'grep)
71 (defcustom grep-scroll-output nil
72 "*Non-nil to scroll the *grep* buffer window as output appears.
74 Setting it causes the grep commands to put point at the end of their
79 :group 'grep)
82 (defcustom grep-command nil
83 "The default grep command for \\[grep].
84 If the grep program used supports an option to always include file names
85 in its output (such as the `-H' option to GNU grep), it's a good idea to
86 include it when specifying `grep-command'.
88 The default value of this variable is set up by `grep-compute-defaults';
92 :group 'grep)
94 (defcustom grep-template nil
96 The default value of this variable is set up by `grep-compute-defaults';
99 <C> - place to put -i if case insensitive grep.
106 :group 'grep)
108 (defcustom grep-use-null-device 'auto-detect
109 "If t, append the value of `null-device' to `grep' commands.
110 This is done to ensure that the output of grep includes the filename of
112 necessary if the grep program used supports the `-H' option.
114 The default value of this variable is set up by `grep-compute-defaults';
119 :group 'grep)
122 (defcustom grep-find-command nil
123 "The default find command for \\[grep-find].
124 The default value of this variable is set up by `grep-compute-defaults';
128 :group 'grep)
130 (defcustom grep-find-template nil
132 The default value of this variable is set up by `grep-compute-defaults';
135 <D> - base directory for find
136 <X> - find options to restrict or expand the directory list
137 <F> - find options to limit the files matched
138 <C> - place to put -i if case insensitive grep
143 :group 'grep)
145 (defcustom grep-files-aliases '(
158 :group 'grep)
160 (defcustom grep-find-ignored-directories '("CVS" ".svn" "{arch}" ".hg" "_darcs"
164 :group 'grep)
166 (defcustom grep-error-screen-columns nil
167 "*If non-nil, column numbers in grep hits are screen columns.
172 :group 'grep)
175 (defcustom grep-setup-hook nil
176 "List of hook functions run by `grep-process-setup' (see `run-hooks')."
178 :group 'grep)
180 (defvar grep-mode-map
195 (define-key map [menu-bar grep]
198 (define-key map [menu-bar grep compilation-kill-compilation]
200 (define-key map [menu-bar grep compilation-separator2]
202 (define-key map [menu-bar grep compilation-compile]
204 (define-key map [menu-bar grep compilation-grep]
205 '("Another grep..." . grep))
206 (define-key map [menu-bar grep compilation-grep-find]
207 '("Recursive grep..." . grep-find))
208 (define-key map [menu-bar grep compilation-recompile]
209 '("Repeat grep" . recompile))
210 (define-key map [menu-bar grep compilation-separator2]
212 (define-key map [menu-bar grep compilation-first-error]
214 (define-key map [menu-bar grep compilation-previous-error]
216 (define-key map [menu-bar grep compilation-next-error]
219 "Keymap for grep buffers.
222 (defalias 'kill-grep 'kill-compilation)
226 ;;; (defcustom grep-use-compilation-buffer t
227 ;;; "When non-nil, grep specific commands update `compilation-last-buffer'.
229 ;;; can be used to navigate between grep matches (the default).
230 ;;; Otherwise, the grep specific commands like \\[grep-next-match] must
231 ;;; be used to navigate between grep matches."
233 ;;; :group 'grep)
236 (defvar grep-last-buffer nil
237 "The most recent grep buffer.
238 A grep buffer becomes most recent when you select Grep mode in it.
240 `complation-last-buffer' rather than `grep-last-buffer'.")
243 (defvar grep-regexp-alist
246 ;; Rule to match column numbers is commented out since no known grep
253 ;; Calculate column positions (beg . end) of first grep match on a line
262 "Regexp used to match grep hits. See `compilation-error-regexp-alist'.")
264 (defvar grep-error "grep hit"
267 ;; Reverse the colors because grep hits are not errors (though we jump there
269 (defvar grep-hit-face compilation-info-face
270 "Face name to use for grep hits.")
272 (defvar grep-error-face 'compilation-error
273 "Face name to use for grep error messages.")
275 (defvar grep-match-face 'match
276 "Face name to use for grep matches.")
278 (defvar grep-context-face 'shadow
279 "Face name to use for grep context lines.")
281 (defvar grep-mode-font-lock-keywords
285 1 grep-error-face)
286 ;; remove match from grep-regexp-alist before fontifying
295 (1 grep-error-face)
296 (2 grep-error-face nil t))
297 ("^.+?-[0-9]+-.*\n" (0 grep-context-face))
298 ;; Highlight grep matches and delete markers
303 (2 (list 'face nil 'font-lock-face grep-match-face))
314 "Additional things to highlight in grep output.
318 (defvar grep-program "grep"
319 "The default grep program for `grep-command' and `grep-find-command'.
320 This variable's value takes effect when `grep-compute-defaults' is called.")
323 (defvar find-program "find"
324 "The default find program for `grep-find-command'.
325 This variable's value takes effect when `grep-compute-defaults' is called.")
328 (defvar grep-find-use-xargs nil
329 "Non-nil means that `grep-find' uses the `xargs' utility by default.
330 If `exec', use `find -exec'.
331 If `gnu', use `find -print0' and `xargs -0'.
332 Any other non-nil value means to use `find -print' and `xargs'.
334 This variable's value takes effect when `grep-compute-defaults' is called.")
336 ;; History of grep commands.
338 (defvar grep-history nil)
340 (defvar grep-find-history nil)
343 (defvar grep-regexp-history nil)
344 (defvar grep-files-history '("ch" "el"))
348 (defun grep-process-setup ()
349 "Setup compilation variables and buffer for `grep'.
350 Set up `compilation-exit-message-function' and run `grep-setup-hook'."
351 (unless (or (not grep-highlight-matches) (eq grep-highlight-matches t))
352 (grep-compute-defaults))
353 (when (eq grep-highlight-matches t)
356 ;; for GNU grep 2.5.1
358 ;; for GNU grep 2.5.1-cvs
370 (run-hooks 'grep-setup-hook))
372 (defun grep-probe (command args &optional func result)
379 (defun grep-compute-defaults ()
380 (unless (or (not grep-use-null-device) (eq grep-use-null-device t))
381 (setq grep-use-null-device
385 (and (if grep-command
386 ;; `grep-command' is already set, so
388 (grep-probe grep-command
391 ;; otherwise use `grep-program'
392 (grep-probe grep-program
399 (unless (and grep-command grep-find-command
400 grep-template grep-find-template)
401 (let ((grep-options
402 (concat (if grep-use-null-device "-n" "-nH")
403 (if (grep-probe grep-program
407 (unless grep-command
408 (setq grep-command
409 (format "%s %s " grep-program grep-options)))
410 (unless grep-template
411 (setq grep-template
412 (format "%s <C> %s <R> <F>" grep-program grep-options)))
413 (unless grep-find-use-xargs
414 (setq grep-find-use-xargs
417 (grep-probe find-program `(nil nil nil ,null-device "-print0"))
418 (grep-probe "xargs" `(nil nil nil "-0" "-e" "echo")))
422 (unless grep-find-command
423 (setq grep-find-command
424 (cond ((eq grep-find-use-xargs 'gnu)
426 find-program grep-command))
427 ((eq grep-find-use-xargs 'exec)
429 find-program grep-command)))
437 find-program grep-command)))))
438 (unless grep-find-template
439 (setq grep-find-template
441 grep-program grep-options)))
442 (cond ((eq grep-find-use-xargs 'gnu)
444 find-program gcmd))
445 ((eq grep-find-use-xargs 'exec)
447 find-program gcmd null-device
451 find-program gcmd))))))))
452 (unless (or (not grep-highlight-matches) (eq grep-highlight-matches t))
453 (setq grep-highlight-matches
455 (and (grep-probe grep-program '(nil t nil "--help"))
461 (defun grep-tag-default ()
465 (funcall (or find-tag-default-function
466 (get major-mode 'find-tag-default-function)
467 'find-tag-default))
470 (defun grep-default-command ()
471 "Compute the default grep command for C-u M-x grep to offer."
472 (let ((tag-default (shell-quote-argument (grep-tag-default)))
476 (grep-default (or (car grep-history) grep-command)))
477 ;; In the default command, find the arg that specifies the pattern.
481 grep-default)
483 (string-match "\\(\\)\\'" grep-default))
493 (match-string 3 grep-default)))
495 (setq grep-default (concat (substring grep-default
503 (replace-match tag-default t t grep-default 1))))
507 (define-compilation-mode grep-mode "Grep"
508 "Sets `grep-last-buffer' and `compilation-window-height'."
509 (setq grep-last-buffer (current-buffer))
511 grep-hit-face)
513 grep-regexp-alist)
515 'grep-process-setup)
520 (defun grep (command-args)
521 "Run grep, with user-specified args, and collect output in a buffer.
522 While grep runs asynchronously, you can use \\[next-error] (M-x next-error),
523 or \\<grep-mode-map>\\[compile-goto-error] in the grep \
525 where grep found matches.
527 For doing a recursive `grep', see the `rgrep' command. For running
528 `grep' in a specific directory, see `lgrep'.
531 easily repeat a grep command.
534 tag the cursor is over, substituting it into the last grep command
535 in the grep command history (or into `grep-command'
539 (grep-compute-defaults)
540 (let ((default (grep-default-command)))
541 (list (read-from-minibuffer "Run grep (like this): "
543 default grep-command)
544 nil nil 'grep-history
549 (compilation-start (if (and grep-use-null-device null-device)
552 'grep-mode))
556 (defun grep-find (command-args)
557 "Run grep via find, with user-specified args COMMAND-ARGS.
559 While find runs asynchronously, you can use the \\[next-error] command
560 to find the text that grep hits refer to.
563 easily repeat a find command."
566 (grep-compute-defaults)
567 (if grep-find-command
568 (list (read-from-minibuffer "Run find (like this): "
569 grep-find-command nil nil
570 'grep-find-history))
573 "compile.el: No `grep-find-command' command available. Press RET.")
576 (let ((null-device nil)) ; see grep
577 (grep command-args))))
580 (defalias 'find-grep 'grep-find)
585 (defconst grep-expand-keywords
592 "List of substitutions performed by `grep-expand-template'.
596 (defun grep-expand-template (template &optional regexp files dir excl)
597 "Patch grep COMMAND string replacing <C>, <D>, <F>, <R>, and <X>."
601 (dolist (kw grep-expand-keywords command)
611 (defun grep-read-regexp ()
612 "Read regexp arg for interactive grep."
613 (let ((default (grep-tag-default)))
618 nil 'grep-regexp-history default)))
620 (defun grep-read-files (regexp)
621 "Read files arg for interactive grep."
628 (let ((aliases grep-files-aliases)
640 (car grep-files-history)
641 (car (car grep-files-aliases))))
647 nil 'grep-files-history default)))
649 (or (cdr (assoc files grep-files-aliases))
654 "Run grep, searching for REGEXP in FILES in directory DIR.
656 FILES may use abbreviations defined in `grep-files-aliases', e.g.
661 With two \\[universal-argument] prefixes, directly edit and run `grep-command'.
663 Collect output in a buffer. While grep runs asynchronously, you
664 can use \\[next-error] (M-x next-error), or \\<grep-mode-map>\\[compile-goto-error]
665 in the grep output buffer, to go to the lines where grep found matches.
667 This command shares argument histories with \\[rgrep] and \\[grep]."
670 (grep-compute-defaults)
672 ((and grep-command (equal current-prefix-arg '(16)))
673 (list (read-from-minibuffer "Run: " grep-command
674 nil nil 'grep-history)
676 ((not grep-template)
678 (read-string "grep.el: No `grep-template' available. Press RET.")))
679 (t (let* ((regexp (grep-read-regexp))
680 (files (grep-read-files regexp))
687 (if (string= command grep-command)
690 (setq command (grep-expand-template
691 grep-template
698 command nil nil 'grep-history))
699 (add-to-history 'grep-history command))))
704 (compilation-start (if (and grep-use-null-device null-device)
706 command) 'grep-mode))
714 "Recursively grep for REGEXP in FILES in directory tree rooted at DIR.
716 FILES may use abbreviations defined in `grep-files-aliases', e.g.
721 With two \\[universal-argument] prefixes, directly edit and run `grep-find-command'.
723 Collect output in a buffer. While find runs asynchronously, you
724 can use \\[next-error] (M-x next-error), or \\<grep-mode-map>\\[compile-goto-error]
725 in the grep output buffer, to go to the lines where grep found matches.
727 This command shares argument histories with \\[lgrep] and \\[grep-find]."
730 (grep-compute-defaults)
732 ((and grep-find-command (equal current-prefix-arg '(16)))
733 (list (read-from-minibuffer "Run: " grep-find-command
734 nil nil 'grep-find-history)
736 ((not grep-find-template)
738 (read-string "grep.el: No `grep-find-template' available. Press RET.")))
739 (t (let* ((regexp (grep-read-regexp))
740 (files (grep-read-files regexp))
746 (if (not (string= regexp grep-find-command))
747 (compilation-start regexp 'grep-mode))
749 (let ((command (grep-expand-template
750 grep-find-template
760 (and grep-find-ignored-directories
767 grep-find-ignored-directories
776 command nil nil 'grep-find-history))
777 (add-to-history 'grep-find-history command))
779 (compilation-start command 'grep-mode))
780 ;; Set default-directory if we started rgrep in the *grep* buffer.
785 (provide 'grep)
788 ;;; grep.el ends here