grep.el 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104
  1. ;;; grep.el --- run `grep' and display the results
  2. ;; Copyright (C) 1985-1987, 1993-1999, 2001-2012
  3. ;; Free Software Foundation, Inc.
  4. ;; Author: Roland McGrath <roland@gnu.org>
  5. ;; Maintainer: FSF
  6. ;; Keywords: tools, processes
  7. ;; This file is part of GNU Emacs.
  8. ;; GNU Emacs is free software: you can redistribute it and/or modify
  9. ;; it under the terms of the GNU General Public License as published by
  10. ;; the Free Software Foundation, either version 3 of the License, or
  11. ;; (at your option) any later version.
  12. ;; GNU Emacs is distributed in the hope that it will be useful,
  13. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. ;; GNU General Public License for more details.
  16. ;; You should have received a copy of the GNU General Public License
  17. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  18. ;;; Commentary:
  19. ;; This package provides the grep facilities documented in the Emacs
  20. ;; user's manual.
  21. ;;; Code:
  22. (require 'compile)
  23. (defgroup grep nil
  24. "Run `grep' and display the results."
  25. :group 'tools
  26. :group 'processes)
  27. (defvar grep-host-defaults-alist nil
  28. "Default values depending on target host.
  29. `grep-compute-defaults' returns default values for every local or
  30. remote host `grep' runs. These values can differ from host to
  31. host. Once computed, the default values are kept here in order
  32. to avoid computing them again.")
  33. (defun grep-apply-setting (symbol value)
  34. "Set SYMBOL to VALUE, and update `grep-host-defaults-alist'.
  35. SYMBOL should be one of `grep-command', `grep-template',
  36. `grep-use-null-device', `grep-find-command',
  37. `grep-find-template', `grep-find-use-xargs', or
  38. `grep-highlight-matches'."
  39. (when grep-host-defaults-alist
  40. (let* ((host-id
  41. (intern (or (file-remote-p default-directory) "localhost")))
  42. (host-defaults (assq host-id grep-host-defaults-alist))
  43. (defaults (assq nil grep-host-defaults-alist)))
  44. (setcar (cdr (assq symbol host-defaults)) value)
  45. (setcar (cdr (assq symbol defaults)) value)))
  46. (set-default symbol value))
  47. ;;;###autoload
  48. (defcustom grep-window-height nil
  49. "*Number of lines in a grep window. If nil, use `compilation-window-height'."
  50. :type '(choice (const :tag "Default" nil)
  51. integer)
  52. :version "22.1"
  53. :group 'grep)
  54. (defcustom grep-highlight-matches 'auto-detect
  55. "Use special markers to highlight grep matches.
  56. Some grep programs are able to surround matches with special
  57. markers in grep output. Such markers can be used to highlight
  58. matches in grep mode. This requires `font-lock-mode' to be active
  59. in grep buffers, so if you have globally disabled font-lock-mode,
  60. you will not get highlighting.
  61. This option sets the environment variable GREP_COLORS to specify
  62. markers for highlighting and GREP_OPTIONS to add the --color
  63. option in front of any explicit grep options before starting
  64. the grep.
  65. When this option is `auto', grep uses `--color=auto' to highlight
  66. matches only when it outputs to a terminal (when `grep' is the last
  67. command in the pipe), thus avoiding the use of any potentially-harmful
  68. escape sequences when standard output goes to a file or pipe.
  69. To make grep highlight matches even into a pipe, you need the option
  70. `always' that forces grep to use `--color=always' to unconditionally
  71. output escape sequences.
  72. In interactive usage, the actual value of this variable is set up
  73. by `grep-compute-defaults' when the default value is `auto-detect'.
  74. To change the default value, use Customize or call the function
  75. `grep-apply-setting'."
  76. :type '(choice (const :tag "Do not highlight matches with grep markers" nil)
  77. (const :tag "Highlight matches with grep markers" t)
  78. (const :tag "Use --color=always" always)
  79. (const :tag "Use --color=auto" auto)
  80. (other :tag "Not Set" auto-detect))
  81. :set 'grep-apply-setting
  82. :version "22.1"
  83. :group 'grep)
  84. (defcustom grep-scroll-output nil
  85. "*Non-nil to scroll the *grep* buffer window as output appears.
  86. Setting it causes the grep commands to put point at the end of their
  87. output window so that the end of the output is always visible rather
  88. than the beginning."
  89. :type 'boolean
  90. :version "22.1"
  91. :group 'grep)
  92. ;;;###autoload
  93. (defcustom grep-command nil
  94. "The default grep command for \\[grep].
  95. If the grep program used supports an option to always include file names
  96. in its output (such as the `-H' option to GNU grep), it's a good idea to
  97. include it when specifying `grep-command'.
  98. In interactive usage, the actual value of this variable is set up
  99. by `grep-compute-defaults'; to change the default value, use
  100. Customize or call the function `grep-apply-setting'."
  101. :type '(choice string
  102. (const :tag "Not Set" nil))
  103. :set 'grep-apply-setting
  104. :group 'grep)
  105. (defcustom grep-template nil
  106. "The default command to run for \\[lgrep].
  107. The following place holders should be present in the string:
  108. <C> - place to put -i if case insensitive grep.
  109. <F> - file names and wildcards to search.
  110. <X> - file names and wildcards to exclude.
  111. <R> - the regular expression searched for.
  112. <N> - place to insert null-device.
  113. In interactive usage, the actual value of this variable is set up
  114. by `grep-compute-defaults'; to change the default value, use
  115. Customize or call the function `grep-apply-setting'."
  116. :type '(choice string
  117. (const :tag "Not Set" nil))
  118. :set 'grep-apply-setting
  119. :version "22.1"
  120. :group 'grep)
  121. (defcustom grep-use-null-device 'auto-detect
  122. "If t, append the value of `null-device' to `grep' commands.
  123. This is done to ensure that the output of grep includes the filename of
  124. any match in the case where only a single file is searched, and is not
  125. necessary if the grep program used supports the `-H' option.
  126. In interactive usage, the actual value of this variable is set up
  127. by `grep-compute-defaults'; to change the default value, use
  128. Customize or call the function `grep-apply-setting'."
  129. :type '(choice (const :tag "Do Not Append Null Device" nil)
  130. (const :tag "Append Null Device" t)
  131. (other :tag "Not Set" auto-detect))
  132. :set 'grep-apply-setting
  133. :group 'grep)
  134. ;;;###autoload
  135. (defcustom grep-find-command nil
  136. "The default find command for \\[grep-find].
  137. In interactive usage, the actual value of this variable is set up
  138. by `grep-compute-defaults'; to change the default value, use
  139. Customize or call the function `grep-apply-setting'."
  140. :type '(choice string
  141. (const :tag "Not Set" nil))
  142. :set 'grep-apply-setting
  143. :group 'grep)
  144. (defcustom grep-find-template nil
  145. "The default command to run for \\[rgrep].
  146. The following place holders should be present in the string:
  147. <D> - base directory for find
  148. <X> - find options to restrict or expand the directory list
  149. <F> - find options to limit the files matched
  150. <C> - place to put -i if case insensitive grep
  151. <R> - the regular expression searched for.
  152. In interactive usage, the actual value of this variable is set up
  153. by `grep-compute-defaults'; to change the default value, use
  154. Customize or call the function `grep-apply-setting'."
  155. :type '(choice string
  156. (const :tag "Not Set" nil))
  157. :set 'grep-apply-setting
  158. :version "22.1"
  159. :group 'grep)
  160. (defcustom grep-files-aliases
  161. '(("all" . "* .*")
  162. ("el" . "*.el")
  163. ("ch" . "*.[ch]")
  164. ("c" . "*.c")
  165. ("cc" . "*.cc *.cxx *.cpp *.C *.CC *.c++")
  166. ("cchh" . "*.cc *.[ch]xx *.[ch]pp *.[CHh] *.CC *.HH *.[ch]++")
  167. ("hh" . "*.hxx *.hpp *.[Hh] *.HH *.h++")
  168. ("h" . "*.h")
  169. ("l" . "[Cc]hange[Ll]og*")
  170. ("m" . "[Mm]akefile*")
  171. ("tex" . "*.tex")
  172. ("texi" . "*.texi")
  173. ("asm" . "*.[sS]"))
  174. "*Alist of aliases for the FILES argument to `lgrep' and `rgrep'."
  175. :type 'alist
  176. :group 'grep)
  177. (defcustom grep-find-ignored-directories
  178. vc-directory-exclusion-list
  179. "*List of names of sub-directories which `rgrep' shall not recurse into.
  180. If an element is a cons cell, the car is called on the search directory
  181. to determine whether cdr should not be recursed into."
  182. :type '(choice (repeat :tag "Ignored directories" string)
  183. (const :tag "No ignored directories" nil))
  184. :group 'grep)
  185. (defcustom grep-find-ignored-files
  186. (cons ".#*" (delq nil (mapcar (lambda (s)
  187. (unless (string-match-p "/\\'" s)
  188. (concat "*" s)))
  189. completion-ignored-extensions)))
  190. "*List of file names which `rgrep' and `lgrep' shall exclude.
  191. If an element is a cons cell, the car is called on the search directory
  192. to determine whether cdr should not be excluded."
  193. :type '(choice (repeat :tag "Ignored file" string)
  194. (const :tag "No ignored files" nil))
  195. :group 'grep)
  196. (defcustom grep-error-screen-columns nil
  197. "*If non-nil, column numbers in grep hits are screen columns.
  198. See `compilation-error-screen-columns'"
  199. :type '(choice (const :tag "Default" nil)
  200. integer)
  201. :version "22.1"
  202. :group 'grep)
  203. ;;;###autoload
  204. (defcustom grep-setup-hook nil
  205. "List of hook functions run by `grep-process-setup' (see `run-hooks')."
  206. :type 'hook
  207. :group 'grep)
  208. (defvar grep-mode-map
  209. (let ((map (make-sparse-keymap)))
  210. (set-keymap-parent map compilation-minor-mode-map)
  211. (define-key map " " 'scroll-up-command)
  212. (define-key map "\^?" 'scroll-down-command)
  213. (define-key map "\C-c\C-f" 'next-error-follow-minor-mode)
  214. (define-key map "\r" 'compile-goto-error) ;; ?
  215. (define-key map "n" 'next-error-no-select)
  216. (define-key map "p" 'previous-error-no-select)
  217. (define-key map "{" 'compilation-previous-file)
  218. (define-key map "}" 'compilation-next-file)
  219. (define-key map "\t" 'compilation-next-error)
  220. (define-key map [backtab] 'compilation-previous-error)
  221. ;; Set up the menu-bar
  222. (define-key map [menu-bar grep]
  223. (cons "Grep" (make-sparse-keymap "Grep")))
  224. (define-key map [menu-bar grep compilation-kill-compilation]
  225. '(menu-item "Kill Grep" kill-compilation
  226. :help "Kill the currently running grep process"))
  227. (define-key map [menu-bar grep compilation-separator2] '("----"))
  228. (define-key map [menu-bar grep compilation-compile]
  229. '(menu-item "Compile..." compile
  230. :help "Compile the program including the current buffer. Default: run `make'"))
  231. (define-key map [menu-bar grep compilation-rgrep]
  232. '(menu-item "Recursive grep..." rgrep
  233. :help "User-friendly recursive grep in directory tree"))
  234. (define-key map [menu-bar grep compilation-lgrep]
  235. '(menu-item "Local grep..." lgrep
  236. :help "User-friendly grep in a directory"))
  237. (define-key map [menu-bar grep compilation-grep-find]
  238. '(menu-item "Grep via Find..." grep-find
  239. :help "Run grep via find, with user-specified args"))
  240. (define-key map [menu-bar grep compilation-grep]
  241. '(menu-item "Another grep..." grep
  242. :help "Run grep, with user-specified args, and collect output in a buffer."))
  243. (define-key map [menu-bar grep compilation-recompile]
  244. '(menu-item "Repeat grep" recompile
  245. :help "Run grep again"))
  246. (define-key map [menu-bar grep compilation-separator2] '("----"))
  247. (define-key map [menu-bar grep compilation-first-error]
  248. '(menu-item "First Match" first-error
  249. :help "Restart at the first match, visit corresponding location"))
  250. (define-key map [menu-bar grep compilation-previous-error]
  251. '(menu-item "Previous Match" previous-error
  252. :help "Visit the previous match and corresponding location"))
  253. (define-key map [menu-bar grep compilation-next-error]
  254. '(menu-item "Next Match" next-error
  255. :help "Visit the next match and corresponding location"))
  256. map)
  257. "Keymap for grep buffers.
  258. `compilation-minor-mode-map' is a cdr of this.")
  259. (defvar grep-mode-tool-bar-map
  260. ;; When bootstrapping, tool-bar-map is not properly initialized yet,
  261. ;; so don't do anything.
  262. (when (keymapp (butlast tool-bar-map))
  263. (let ((map (butlast (copy-keymap tool-bar-map)))
  264. (help (last tool-bar-map))) ;; Keep Help last in tool bar
  265. (tool-bar-local-item
  266. "left-arrow" 'previous-error-no-select 'previous-error-no-select map
  267. :rtl "right-arrow"
  268. :help "Goto previous match")
  269. (tool-bar-local-item
  270. "right-arrow" 'next-error-no-select 'next-error-no-select map
  271. :rtl "left-arrow"
  272. :help "Goto next match")
  273. (tool-bar-local-item
  274. "cancel" 'kill-compilation 'kill-compilation map
  275. :enable '(let ((buffer (compilation-find-buffer)))
  276. (get-buffer-process buffer))
  277. :help "Stop grep")
  278. (tool-bar-local-item
  279. "refresh" 'recompile 'recompile map
  280. :help "Restart grep")
  281. (append map help))))
  282. (defalias 'kill-grep 'kill-compilation)
  283. ;;;; TODO --- refine this!!
  284. ;; (defcustom grep-use-compilation-buffer t
  285. ;; "When non-nil, grep specific commands update `compilation-last-buffer'.
  286. ;; This means that standard compile commands like \\[next-error] and \\[compile-goto-error]
  287. ;; can be used to navigate between grep matches (the default).
  288. ;; Otherwise, the grep specific commands like \\[grep-next-match] must
  289. ;; be used to navigate between grep matches."
  290. ;; :type 'boolean
  291. ;; :group 'grep)
  292. ;; override compilation-last-buffer
  293. (defvar grep-last-buffer nil
  294. "The most recent grep buffer.
  295. A grep buffer becomes most recent when you select Grep mode in it.
  296. Notice that using \\[next-error] or \\[compile-goto-error] modifies
  297. `compilation-last-buffer' rather than `grep-last-buffer'.")
  298. ;;;###autoload
  299. (defconst grep-regexp-alist
  300. '(
  301. ;; Rule to match column numbers is commented out since no known grep
  302. ;; produces them
  303. ;; ("^\\(.+?\\)\\(:[ \t]*\\)\\([1-9][0-9]*\\)\\2\\(?:\\([1-9][0-9]*\\)\\(?:-\\([1-9][0-9]*\\)\\)?\\2\\)?"
  304. ;; 1 3 (4 . 5))
  305. ;; Note that we want to use as tight a regexp as we can to try and
  306. ;; handle weird file names (with colons in them) as well as possible.
  307. ;; E.g. we use [1-9][0-9]* rather than [0-9]+ so as to accept ":034:"
  308. ;; in file names.
  309. ("^\\(.+?\\)\\(:[ \t]*\\)\\([1-9][0-9]*\\)\\2"
  310. 1 3
  311. ;; Calculate column positions (col . end-col) of first grep match on a line
  312. ((lambda ()
  313. (when grep-highlight-matches
  314. (let* ((beg (match-end 0))
  315. (end (save-excursion (goto-char beg) (line-end-position)))
  316. (mbeg (text-property-any beg end 'font-lock-face 'match)))
  317. (when mbeg
  318. (- mbeg beg)))))
  319. .
  320. (lambda ()
  321. (when grep-highlight-matches
  322. (let* ((beg (match-end 0))
  323. (end (save-excursion (goto-char beg) (line-end-position)))
  324. (mbeg (text-property-any beg end 'font-lock-face 'match))
  325. (mend (and mbeg (next-single-property-change mbeg 'font-lock-face nil end))))
  326. (when mend
  327. (- mend beg)))))))
  328. ("^Binary file \\(.+\\) matches$" 1 nil nil 0 1))
  329. "Regexp used to match grep hits. See `compilation-error-regexp-alist'.")
  330. (defvar grep-first-column 0 ; bug#10594
  331. "Value to use for `compilation-first-column' in grep buffers.")
  332. (defvar grep-error "grep hit"
  333. "Message to print when no matches are found.")
  334. ;; Reverse the colors because grep hits are not errors (though we jump there
  335. ;; with `next-error'), and unreadable files can't be gone to.
  336. (defvar grep-hit-face compilation-info-face
  337. "Face name to use for grep hits.")
  338. (defvar grep-error-face 'compilation-error
  339. "Face name to use for grep error messages.")
  340. (defvar grep-match-face 'match
  341. "Face name to use for grep matches.")
  342. (defvar grep-context-face 'shadow
  343. "Face name to use for grep context lines.")
  344. (defvar grep-mode-font-lock-keywords
  345. '(;; Command output lines.
  346. (": \\(.+\\): \\(?:Permission denied\\|No such \\(?:file or directory\\|device or address\\)\\)$"
  347. 1 grep-error-face)
  348. ;; remove match from grep-regexp-alist before fontifying
  349. ("^Grep[/a-zA-z]* started.*"
  350. (0 '(face nil compilation-message nil help-echo nil mouse-face nil) t))
  351. ("^Grep[/a-zA-z]* finished \\(?:(\\(matches found\\))\\|with \\(no matches found\\)\\).*"
  352. (0 '(face nil compilation-message nil help-echo nil mouse-face nil) t)
  353. (1 compilation-info-face nil t)
  354. (2 compilation-warning-face nil t))
  355. ("^Grep[/a-zA-z]* \\(exited abnormally\\|interrupt\\|killed\\|terminated\\)\\(?:.*with code \\([0-9]+\\)\\)?.*"
  356. (0 '(face nil compilation-message nil help-echo nil mouse-face nil) t)
  357. (1 grep-error-face)
  358. (2 grep-error-face nil t))
  359. ("^.+?-[0-9]+-.*\n" (0 grep-context-face)))
  360. "Additional things to highlight in grep output.
  361. This gets tacked on the end of the generated expressions.")
  362. ;;;###autoload
  363. (defvar grep-program (purecopy "grep")
  364. "The default grep program for `grep-command' and `grep-find-command'.
  365. This variable's value takes effect when `grep-compute-defaults' is called.")
  366. ;;;###autoload
  367. (defvar find-program (purecopy "find")
  368. "The default find program for `grep-find-command'.
  369. This variable's value takes effect when `grep-compute-defaults' is called.")
  370. ;;;###autoload
  371. (defvar xargs-program (purecopy "xargs")
  372. "The default xargs program for `grep-find-command'.
  373. See `grep-find-use-xargs'.
  374. This variable's value takes effect when `grep-compute-defaults' is called.")
  375. ;;;###autoload
  376. (defvar grep-find-use-xargs nil
  377. "How to invoke find and grep.
  378. If `exec', use `find -exec {} ;'.
  379. If `exec-plus' use `find -exec {} +'.
  380. If `gnu', use `find -print0' and `xargs -0'.
  381. Any other value means to use `find -print' and `xargs'.
  382. This variable's value takes effect when `grep-compute-defaults' is called.")
  383. ;; History of grep commands.
  384. ;;;###autoload
  385. (defvar grep-history nil "History list for grep.")
  386. ;;;###autoload
  387. (defvar grep-find-history nil "History list for grep-find.")
  388. ;; History of lgrep and rgrep regexp and files args.
  389. (defvar grep-regexp-history nil)
  390. (defvar grep-files-history nil)
  391. ;;;###autoload
  392. (defun grep-process-setup ()
  393. "Setup compilation variables and buffer for `grep'.
  394. Set up `compilation-exit-message-function' and run `grep-setup-hook'."
  395. (when (eq grep-highlight-matches 'auto-detect)
  396. (grep-compute-defaults))
  397. (unless (or (eq grep-highlight-matches 'auto-detect)
  398. (null grep-highlight-matches)
  399. ;; Don't output color escapes if they can't be
  400. ;; highlighted with `font-lock-face' by `grep-filter'.
  401. (null font-lock-mode))
  402. ;; `setenv' modifies `process-environment' let-bound in `compilation-start'
  403. ;; Any TERM except "dumb" allows GNU grep to use `--color=auto'
  404. (setenv "TERM" "emacs-grep")
  405. (setenv "GREP_OPTIONS"
  406. (concat (getenv "GREP_OPTIONS")
  407. " --color=" (if (eq grep-highlight-matches 'always)
  408. "always" "auto")))
  409. ;; GREP_COLOR is used in GNU grep 2.5.1, but deprecated in later versions
  410. (setenv "GREP_COLOR" "01;31")
  411. ;; GREP_COLORS is used in GNU grep 2.5.2 and later versions
  412. (setenv "GREP_COLORS" "mt=01;31:fn=:ln=:bn=:se=:sl=:cx=:ne"))
  413. (set (make-local-variable 'compilation-exit-message-function)
  414. (lambda (status code msg)
  415. (if (eq status 'exit)
  416. ;; This relies on the fact that `compilation-start'
  417. ;; sets buffer-modified to nil before running the command,
  418. ;; so the buffer is still unmodified if there is no output.
  419. (cond ((and (zerop code) (buffer-modified-p))
  420. '("finished (matches found)\n" . "matched"))
  421. ((not (buffer-modified-p))
  422. '("finished with no matches found\n" . "no match"))
  423. (t
  424. (cons msg code)))
  425. (cons msg code))))
  426. (run-hooks 'grep-setup-hook))
  427. (defun grep-filter ()
  428. "Handle match highlighting escape sequences inserted by the grep process.
  429. This function is called from `compilation-filter-hook'."
  430. (save-excursion
  431. (forward-line 0)
  432. (let ((end (point)) beg)
  433. (goto-char compilation-filter-start)
  434. (forward-line 0)
  435. (setq beg (point))
  436. ;; Only operate on whole lines so we don't get caught with part of an
  437. ;; escape sequence in one chunk and the rest in another.
  438. (when (< (point) end)
  439. (setq end (copy-marker end))
  440. ;; Highlight grep matches and delete marking sequences.
  441. (while (re-search-forward "\033\\[0?1;31m\\(.*?\\)\033\\[[0-9]*m" end 1)
  442. (replace-match (propertize (match-string 1)
  443. 'face nil 'font-lock-face grep-match-face)
  444. t t))
  445. ;; Delete all remaining escape sequences
  446. (goto-char beg)
  447. (while (re-search-forward "\033\\[[0-9;]*[mK]" end 1)
  448. (replace-match "" t t))))))
  449. (defun grep-probe (command args &optional func result)
  450. (let (process-file-side-effects)
  451. (equal (condition-case nil
  452. (apply (or func 'process-file) command args)
  453. (error nil))
  454. (or result 0))))
  455. ;;;###autoload
  456. (defun grep-compute-defaults ()
  457. ;; Keep default values.
  458. (unless grep-host-defaults-alist
  459. (add-to-list
  460. 'grep-host-defaults-alist
  461. (cons nil
  462. `((grep-command ,grep-command)
  463. (grep-template ,grep-template)
  464. (grep-use-null-device ,grep-use-null-device)
  465. (grep-find-command ,grep-find-command)
  466. (grep-find-template ,grep-find-template)
  467. (grep-find-use-xargs ,grep-find-use-xargs)
  468. (grep-highlight-matches ,grep-highlight-matches)))))
  469. (let* ((host-id
  470. (intern (or (file-remote-p default-directory) "localhost")))
  471. (host-defaults (assq host-id grep-host-defaults-alist))
  472. (defaults (assq nil grep-host-defaults-alist)))
  473. ;; There are different defaults on different hosts. They must be
  474. ;; computed for every host once.
  475. (dolist (setting '(grep-command grep-template
  476. grep-use-null-device grep-find-command
  477. grep-find-template grep-find-use-xargs
  478. grep-highlight-matches))
  479. (set setting
  480. (cadr (or (assq setting host-defaults)
  481. (assq setting defaults)))))
  482. (unless (or (not grep-use-null-device) (eq grep-use-null-device t))
  483. (setq grep-use-null-device
  484. (with-temp-buffer
  485. (let ((hello-file (expand-file-name "HELLO" data-directory)))
  486. (not
  487. (and (if grep-command
  488. ;; `grep-command' is already set, so
  489. ;; use that for testing.
  490. (grep-probe grep-command
  491. `(nil t nil "^English" ,hello-file)
  492. #'call-process-shell-command)
  493. ;; otherwise use `grep-program'
  494. (grep-probe grep-program
  495. `(nil t nil "-nH" "^English" ,hello-file)))
  496. (progn
  497. (goto-char (point-min))
  498. (looking-at
  499. (concat (regexp-quote hello-file)
  500. ":[0-9]+:English")))))))))
  501. (unless (and grep-command grep-find-command
  502. grep-template grep-find-template)
  503. (let ((grep-options
  504. (concat (if grep-use-null-device "-n" "-nH")
  505. (if (grep-probe grep-program
  506. `(nil nil nil "-e" "foo" ,null-device)
  507. nil 1)
  508. " -e"))))
  509. (unless grep-command
  510. (setq grep-command
  511. (format "%s %s " grep-program grep-options)))
  512. (unless grep-template
  513. (setq grep-template
  514. (format "%s <X> <C> %s <R> <F>" grep-program grep-options)))
  515. (unless grep-find-use-xargs
  516. (setq grep-find-use-xargs
  517. (cond
  518. ((grep-probe find-program
  519. `(nil nil nil ,null-device "-exec" "echo"
  520. "{}" "+"))
  521. 'exec-plus)
  522. ((and
  523. (grep-probe find-program `(nil nil nil ,null-device "-print0"))
  524. (grep-probe xargs-program `(nil nil nil "-0" "-e" "echo")))
  525. 'gnu)
  526. (t
  527. 'exec))))
  528. (unless grep-find-command
  529. (setq grep-find-command
  530. (cond ((eq grep-find-use-xargs 'gnu)
  531. ;; Windows shells need the program file name
  532. ;; after the pipe symbol be quoted if they use
  533. ;; forward slashes as directory separators.
  534. (format "%s . -type f -print0 | \"%s\" -0 -e %s"
  535. find-program xargs-program grep-command))
  536. ((memq grep-find-use-xargs '(exec exec-plus))
  537. (let ((cmd0 (format "%s . -type f -exec %s"
  538. find-program grep-command))
  539. (null (if grep-use-null-device
  540. (format "%s " null-device)
  541. "")))
  542. (cons
  543. (if (eq grep-find-use-xargs 'exec-plus)
  544. (format "%s %s{} +" cmd0 null)
  545. (format "%s {} %s%s" cmd0 null
  546. (shell-quote-argument ";")))
  547. (1+ (length cmd0)))))
  548. (t
  549. (format "%s . -type f -print | \"%s\" %s"
  550. find-program xargs-program grep-command)))))
  551. (unless grep-find-template
  552. (setq grep-find-template
  553. (let ((gcmd (format "%s <C> %s <R>"
  554. grep-program grep-options))
  555. (null (if grep-use-null-device
  556. (format "%s " null-device)
  557. "")))
  558. (cond ((eq grep-find-use-xargs 'gnu)
  559. (format "%s . <X> -type f <F> -print0 | \"%s\" -0 -e %s"
  560. find-program xargs-program gcmd))
  561. ((eq grep-find-use-xargs 'exec)
  562. (format "%s . <X> -type f <F> -exec %s {} %s%s"
  563. find-program gcmd null
  564. (shell-quote-argument ";")))
  565. ((eq grep-find-use-xargs 'exec-plus)
  566. (format "%s . <X> -type f <F> -exec %s %s{} +"
  567. find-program gcmd null))
  568. (t
  569. (format "%s . <X> -type f <F> -print | \"%s\" %s"
  570. find-program xargs-program gcmd))))))))
  571. (when (eq grep-highlight-matches 'auto-detect)
  572. (setq grep-highlight-matches
  573. (with-temp-buffer
  574. (and (grep-probe grep-program '(nil t nil "--help"))
  575. (progn
  576. (goto-char (point-min))
  577. (search-forward "--color" nil t))
  578. ;; Windows and DOS pipes fail `isatty' detection in Grep.
  579. (if (memq system-type '(windows-nt ms-dos))
  580. 'always 'auto)))))
  581. ;; Save defaults for this host.
  582. (setq grep-host-defaults-alist
  583. (delete (assq host-id grep-host-defaults-alist)
  584. grep-host-defaults-alist))
  585. (add-to-list
  586. 'grep-host-defaults-alist
  587. (cons host-id
  588. `((grep-command ,grep-command)
  589. (grep-template ,grep-template)
  590. (grep-use-null-device ,grep-use-null-device)
  591. (grep-find-command ,grep-find-command)
  592. (grep-find-template ,grep-find-template)
  593. (grep-find-use-xargs ,grep-find-use-xargs)
  594. (grep-highlight-matches ,grep-highlight-matches))))))
  595. (defun grep-tag-default ()
  596. (or (and transient-mark-mode mark-active
  597. (/= (point) (mark))
  598. (buffer-substring-no-properties (point) (mark)))
  599. (funcall (or find-tag-default-function
  600. (get major-mode 'find-tag-default-function)
  601. 'find-tag-default))
  602. ""))
  603. (defun grep-default-command ()
  604. "Compute the default grep command for \\[universal-argument] \\[grep] to offer."
  605. (let ((tag-default (shell-quote-argument (grep-tag-default)))
  606. ;; This a regexp to match single shell arguments.
  607. ;; Could someone please add comments explaining it?
  608. (sh-arg-re "\\(\\(?:\"\\(?:[^\"]\\|\\\\\"\\)+\"\\|'[^']+'\\|[^\"' \t\n]\\)+\\)")
  609. (grep-default (or (car grep-history) grep-command)))
  610. ;; In the default command, find the arg that specifies the pattern.
  611. (when (or (string-match
  612. (concat "[^ ]+\\s +\\(?:-[^ ]+\\s +\\)*"
  613. sh-arg-re "\\(\\s +\\(\\S +\\)\\)?")
  614. grep-default)
  615. ;; If the string is not yet complete.
  616. (string-match "\\(\\)\\'" grep-default))
  617. ;; Maybe we will replace the pattern with the default tag.
  618. ;; But first, maybe replace the file name pattern.
  619. (condition-case nil
  620. (unless (or (not (stringp buffer-file-name))
  621. (when (match-beginning 2)
  622. (save-match-data
  623. (string-match
  624. (wildcard-to-regexp
  625. (file-name-nondirectory
  626. (match-string 3 grep-default)))
  627. (file-name-nondirectory buffer-file-name)))))
  628. (setq grep-default (concat (substring grep-default
  629. 0 (match-beginning 2))
  630. " *."
  631. (file-name-extension buffer-file-name))))
  632. ;; In case wildcard-to-regexp gets an error
  633. ;; from invalid data.
  634. (error nil))
  635. ;; Now replace the pattern with the default tag.
  636. (replace-match tag-default t t grep-default 1))))
  637. ;;;###autoload
  638. (define-compilation-mode grep-mode "Grep"
  639. "Sets `grep-last-buffer' and `compilation-window-height'."
  640. (setq grep-last-buffer (current-buffer))
  641. (set (make-local-variable 'tool-bar-map) grep-mode-tool-bar-map)
  642. (set (make-local-variable 'compilation-error-face)
  643. grep-hit-face)
  644. (set (make-local-variable 'compilation-error-regexp-alist)
  645. grep-regexp-alist)
  646. ;; compilation-directory-matcher can't be nil, so we set it to a regexp that
  647. ;; can never match.
  648. (set (make-local-variable 'compilation-directory-matcher) '("\\`a\\`"))
  649. (set (make-local-variable 'compilation-process-setup-function)
  650. 'grep-process-setup)
  651. (set (make-local-variable 'compilation-disable-input) t)
  652. (set (make-local-variable 'compilation-error-screen-columns)
  653. grep-error-screen-columns)
  654. (add-hook 'compilation-filter-hook 'grep-filter nil t))
  655. ;;;###autoload
  656. (defun grep (command-args)
  657. "Run grep, with user-specified args, and collect output in a buffer.
  658. While grep runs asynchronously, you can use \\[next-error] (M-x next-error),
  659. or \\<grep-mode-map>\\[compile-goto-error] in the *grep* \
  660. buffer, to go to the lines where grep found
  661. matches. To kill the grep job before it finishes, type \\[kill-compilation].
  662. For doing a recursive `grep', see the `rgrep' command. For running
  663. `grep' in a specific directory, see `lgrep'.
  664. This command uses a special history list for its COMMAND-ARGS, so you
  665. can easily repeat a grep command.
  666. A prefix argument says to default the argument based upon the current
  667. tag the cursor is over, substituting it into the last grep command
  668. in the grep command history (or into `grep-command' if that history
  669. list is empty)."
  670. (interactive
  671. (progn
  672. (grep-compute-defaults)
  673. (let ((default (grep-default-command)))
  674. (list (read-shell-command "Run grep (like this): "
  675. (if current-prefix-arg default grep-command)
  676. 'grep-history
  677. (if current-prefix-arg nil default))))))
  678. ;; Setting process-setup-function makes exit-message-function work
  679. ;; even when async processes aren't supported.
  680. (compilation-start (if (and grep-use-null-device null-device)
  681. (concat command-args " " null-device)
  682. command-args)
  683. 'grep-mode))
  684. ;;;###autoload
  685. (defun grep-find (command-args)
  686. "Run grep via find, with user-specified args COMMAND-ARGS.
  687. Collect output in a buffer.
  688. While find runs asynchronously, you can use the \\[next-error] command
  689. to find the text that grep hits refer to.
  690. This command uses a special history list for its arguments, so you can
  691. easily repeat a find command."
  692. (interactive
  693. (progn
  694. (grep-compute-defaults)
  695. (if grep-find-command
  696. (list (read-shell-command "Run find (like this): "
  697. grep-find-command 'grep-find-history))
  698. ;; No default was set
  699. (read-string
  700. "compile.el: No `grep-find-command' command available. Press RET.")
  701. (list nil))))
  702. (when command-args
  703. (let ((null-device nil)) ; see grep
  704. (grep command-args))))
  705. ;;;###autoload
  706. (defalias 'find-grep 'grep-find)
  707. ;; User-friendly interactive API.
  708. (defconst grep-expand-keywords
  709. '(("<C>" . (and cf (isearch-no-upper-case-p regexp t) "-i"))
  710. ("<D>" . dir)
  711. ("<F>" . files)
  712. ("<N>" . null-device)
  713. ("<X>" . excl)
  714. ("<R>" . (shell-quote-argument (or regexp ""))))
  715. "List of substitutions performed by `grep-expand-template'.
  716. If car of an element matches, the cdr is evalled in to get the
  717. substitution string. Note dynamic scoping of variables.")
  718. (defun grep-expand-template (template &optional regexp files dir excl)
  719. "Patch grep COMMAND string replacing <C>, <D>, <F>, <R>, and <X>."
  720. (let ((command template)
  721. (cf case-fold-search)
  722. (case-fold-search nil))
  723. (dolist (kw grep-expand-keywords command)
  724. (if (string-match (car kw) command)
  725. (setq command
  726. (replace-match
  727. (or (if (symbolp (cdr kw))
  728. (symbol-value (cdr kw))
  729. (save-match-data (eval (cdr kw))))
  730. "")
  731. t t command))))))
  732. (defun grep-read-regexp ()
  733. "Read regexp arg for interactive grep."
  734. (let ((default (grep-tag-default)))
  735. (read-string
  736. (concat "Search for"
  737. (if (and default (> (length default) 0))
  738. (format " (default \"%s\"): " default) ": "))
  739. nil 'grep-regexp-history default)))
  740. (defun grep-read-files (regexp)
  741. "Read files arg for interactive grep."
  742. (let* ((bn (or (buffer-file-name)
  743. (replace-regexp-in-string "<[0-9]+>\\'" "" (buffer-name))))
  744. (fn (and bn
  745. (stringp bn)
  746. (file-name-nondirectory bn)))
  747. (default-alias
  748. (and fn
  749. (let ((aliases (remove (assoc "all" grep-files-aliases)
  750. grep-files-aliases))
  751. alias)
  752. (while aliases
  753. (setq alias (car aliases)
  754. aliases (cdr aliases))
  755. (if (string-match (mapconcat
  756. 'wildcard-to-regexp
  757. (split-string (cdr alias) nil t)
  758. "\\|")
  759. fn)
  760. (setq aliases nil)
  761. (setq alias nil)))
  762. (cdr alias))))
  763. (default-extension
  764. (and fn
  765. (let ((ext (file-name-extension fn)))
  766. (and ext (concat "*." ext)))))
  767. (default
  768. (or default-alias
  769. default-extension
  770. (car grep-files-history)
  771. (car (car grep-files-aliases))))
  772. (files (completing-read
  773. (concat "Search for \"" regexp
  774. "\" in files"
  775. (if default (concat " (default " default ")"))
  776. ": ")
  777. 'read-file-name-internal
  778. nil nil nil 'grep-files-history
  779. (delete-dups
  780. (delq nil (append (list default default-alias default-extension)
  781. (mapcar 'car grep-files-aliases)))))))
  782. (and files
  783. (or (cdr (assoc files grep-files-aliases))
  784. files))))
  785. ;;;###autoload
  786. (defun lgrep (regexp &optional files dir confirm)
  787. "Run grep, searching for REGEXP in FILES in directory DIR.
  788. The search is limited to file names matching shell pattern FILES.
  789. FILES may use abbreviations defined in `grep-files-aliases', e.g.
  790. entering `ch' is equivalent to `*.[ch]'.
  791. With \\[universal-argument] prefix, you can edit the constructed shell command line
  792. before it is executed.
  793. With two \\[universal-argument] prefixes, directly edit and run `grep-command'.
  794. Collect output in a buffer. While grep runs asynchronously, you
  795. can use \\[next-error] (M-x next-error), or \\<grep-mode-map>\\[compile-goto-error] \
  796. in the grep output buffer,
  797. to go to the lines where grep found matches.
  798. This command shares argument histories with \\[rgrep] and \\[grep]."
  799. (interactive
  800. (progn
  801. (grep-compute-defaults)
  802. (cond
  803. ((and grep-command (equal current-prefix-arg '(16)))
  804. (list (read-from-minibuffer "Run: " grep-command
  805. nil nil 'grep-history)))
  806. ((not grep-template)
  807. (error "grep.el: No `grep-template' available"))
  808. (t (let* ((regexp (grep-read-regexp))
  809. (files (grep-read-files regexp))
  810. (dir (read-directory-name "In directory: "
  811. nil default-directory t))
  812. (confirm (equal current-prefix-arg '(4))))
  813. (list regexp files dir confirm))))))
  814. (when (and (stringp regexp) (> (length regexp) 0))
  815. (unless (and dir (file-directory-p dir) (file-readable-p dir))
  816. (setq dir default-directory))
  817. (let ((command regexp))
  818. (if (null files)
  819. (if (string= command grep-command)
  820. (setq command nil))
  821. (setq dir (file-name-as-directory (expand-file-name dir)))
  822. (setq command (grep-expand-template
  823. grep-template
  824. regexp
  825. files
  826. nil
  827. (and grep-find-ignored-files
  828. (concat " --exclude="
  829. (mapconcat
  830. #'(lambda (ignore)
  831. (cond ((stringp ignore)
  832. (shell-quote-argument ignore))
  833. ((consp ignore)
  834. (and (funcall (car ignore) dir)
  835. (shell-quote-argument
  836. (cdr ignore))))))
  837. grep-find-ignored-files
  838. " --exclude=")))))
  839. (when command
  840. (if confirm
  841. (setq command
  842. (read-from-minibuffer "Confirm: "
  843. command nil nil 'grep-history))
  844. (add-to-history 'grep-history command))))
  845. (when command
  846. (let ((default-directory dir))
  847. ;; Setting process-setup-function makes exit-message-function work
  848. ;; even when async processes aren't supported.
  849. (compilation-start (if (and grep-use-null-device null-device)
  850. (concat command " " null-device)
  851. command)
  852. 'grep-mode))
  853. (if (eq next-error-last-buffer (current-buffer))
  854. (setq default-directory dir))))))
  855. (defvar find-name-arg) ; not autoloaded but defined in find-dired
  856. ;;;###autoload
  857. (defun rgrep (regexp &optional files dir confirm)
  858. "Recursively grep for REGEXP in FILES in directory tree rooted at DIR.
  859. The search is limited to file names matching shell pattern FILES.
  860. FILES may use abbreviations defined in `grep-files-aliases', e.g.
  861. entering `ch' is equivalent to `*.[ch]'.
  862. With \\[universal-argument] prefix, you can edit the constructed shell command line
  863. before it is executed.
  864. With two \\[universal-argument] prefixes, directly edit and run `grep-find-command'.
  865. Collect output in a buffer. While the recursive grep is running,
  866. you can use \\[next-error] (M-x next-error), or \\<grep-mode-map>\\[compile-goto-error] \
  867. in the grep output buffer,
  868. to visit the lines where matches were found. To kill the job
  869. before it finishes, type \\[kill-compilation].
  870. This command shares argument histories with \\[lgrep] and \\[grep-find].
  871. When called programmatically and FILES is nil, REGEXP is expected
  872. to specify a command to run."
  873. (interactive
  874. (progn
  875. (grep-compute-defaults)
  876. (cond
  877. ((and grep-find-command (equal current-prefix-arg '(16)))
  878. (list (read-from-minibuffer "Run: " grep-find-command
  879. nil nil 'grep-find-history)))
  880. ((not grep-find-template)
  881. (error "grep.el: No `grep-find-template' available"))
  882. (t (let* ((regexp (grep-read-regexp))
  883. (files (grep-read-files regexp))
  884. (dir (read-directory-name "Base directory: "
  885. nil default-directory t))
  886. (confirm (equal current-prefix-arg '(4))))
  887. (list regexp files dir confirm))))))
  888. (when (and (stringp regexp) (> (length regexp) 0))
  889. (unless (and dir (file-directory-p dir) (file-readable-p dir))
  890. (setq dir default-directory))
  891. (if (null files)
  892. (if (not (string= regexp (if (consp grep-find-command)
  893. (car grep-find-command)
  894. grep-find-command)))
  895. (compilation-start regexp 'grep-mode))
  896. (setq dir (file-name-as-directory (expand-file-name dir)))
  897. (require 'find-dired) ; for `find-name-arg'
  898. (let ((command (grep-expand-template
  899. grep-find-template
  900. regexp
  901. (concat (shell-quote-argument "(")
  902. " " find-name-arg " "
  903. (mapconcat #'shell-quote-argument
  904. (split-string files)
  905. (concat " -o " find-name-arg " "))
  906. " "
  907. (shell-quote-argument ")"))
  908. dir
  909. (concat
  910. (and grep-find-ignored-directories
  911. (concat "-type d "
  912. (shell-quote-argument "(")
  913. ;; we should use shell-quote-argument here
  914. " -path "
  915. (mapconcat
  916. #'(lambda (ignore)
  917. (cond ((stringp ignore)
  918. (shell-quote-argument
  919. (concat "*/" ignore)))
  920. ((consp ignore)
  921. (and (funcall (car ignore) dir)
  922. (shell-quote-argument
  923. (concat "*/"
  924. (cdr ignore)))))))
  925. grep-find-ignored-directories
  926. " -o -path ")
  927. " "
  928. (shell-quote-argument ")")
  929. " -prune -o "))
  930. (and grep-find-ignored-files
  931. (concat (shell-quote-argument "(")
  932. ;; we should use shell-quote-argument here
  933. " -name "
  934. (mapconcat
  935. #'(lambda (ignore)
  936. (cond ((stringp ignore)
  937. (shell-quote-argument ignore))
  938. ((consp ignore)
  939. (and (funcall (car ignore) dir)
  940. (shell-quote-argument
  941. (cdr ignore))))))
  942. grep-find-ignored-files
  943. " -o -name ")
  944. " "
  945. (shell-quote-argument ")")
  946. " -prune -o "))))))
  947. (when command
  948. (if confirm
  949. (setq command
  950. (read-from-minibuffer "Confirm: "
  951. command nil nil 'grep-find-history))
  952. (add-to-history 'grep-find-history command))
  953. (let ((default-directory dir))
  954. (compilation-start command 'grep-mode))
  955. ;; Set default-directory if we started rgrep in the *grep* buffer.
  956. (if (eq next-error-last-buffer (current-buffer))
  957. (setq default-directory dir)))))))
  958. ;;;###autoload
  959. (defun zrgrep (regexp &optional files dir confirm grep-find-template)
  960. "Recursively grep for REGEXP in gzipped FILES in tree rooted at DIR.
  961. Like `rgrep' but uses `zgrep' for `grep-program', sets the default
  962. file name to `*.gz', and sets `grep-highlight-matches' to `always'."
  963. (interactive
  964. (progn
  965. ;; Compute standard default values.
  966. (grep-compute-defaults)
  967. ;; Compute the default zrgrep command by running `grep-compute-defaults'
  968. ;; for grep program "zgrep", but not changing global values.
  969. (let ((grep-program "zgrep")
  970. ;; Don't change global values for variables computed
  971. ;; by `grep-compute-defaults'.
  972. (grep-find-template nil)
  973. (grep-find-command nil)
  974. (grep-host-defaults-alist nil)
  975. ;; Use for `grep-read-files'
  976. (grep-files-aliases '(("all" . "* .*")
  977. ("gz" . "*.gz"))))
  978. ;; Recompute defaults using let-bound values above.
  979. (grep-compute-defaults)
  980. (cond
  981. ((and grep-find-command (equal current-prefix-arg '(16)))
  982. (list (read-from-minibuffer "Run: " grep-find-command
  983. nil nil 'grep-find-history)))
  984. ((not grep-find-template)
  985. (error "grep.el: No `grep-find-template' available"))
  986. (t (let* ((regexp (grep-read-regexp))
  987. (files (grep-read-files regexp))
  988. (dir (read-directory-name "Base directory: "
  989. nil default-directory t))
  990. (confirm (equal current-prefix-arg '(4))))
  991. (list regexp files dir confirm grep-find-template)))))))
  992. ;; Set `grep-highlight-matches' to `always'
  993. ;; since `zgrep' puts filters in the grep output.
  994. (let ((grep-highlight-matches 'always))
  995. ;; `rgrep' uses the dynamically bound value `grep-find-template'
  996. ;; from the argument `grep-find-template' whose value is computed
  997. ;; in the `interactive' spec.
  998. (rgrep regexp files dir confirm)))
  999. ;;;###autoload
  1000. (defalias 'rzgrep 'zrgrep)
  1001. (provide 'grep)
  1002. ;;; grep.el ends here