Mercurial > emacs
comparison lisp/progmodes/grep.el @ 75877:9ba96fd63815
(grep-files-aliases): Add tex and texi aliases.
(lgrep): Add DIR arg to start grep in specific directory, like rgrep.
(grep): Fix lgrep reference.
author | Kim F. Storm <storm@cua.dk> |
---|---|
date | Wed, 14 Feb 2007 11:54:12 +0000 |
parents | 81c369551691 |
children | dac34bd10d88 dd7c098af727 |
comparison
equal
deleted
inserted
replaced
75876:9a63c2e51e22 | 75877:9ba96fd63815 |
---|---|
148 ("c" . "*.c") | 148 ("c" . "*.c") |
149 ("h" . "*.h") | 149 ("h" . "*.h") |
150 ("asm" . "*.[sS]") | 150 ("asm" . "*.[sS]") |
151 ("m" . "[Mm]akefile*") | 151 ("m" . "[Mm]akefile*") |
152 ("l" . "[Cc]hange[Ll]og*") | 152 ("l" . "[Cc]hange[Ll]og*") |
153 ("tex" . "*.tex") | |
154 ("texi" . "*.texi") | |
153 ) | 155 ) |
154 "*Alist of aliases for the FILES argument to `lgrep' and `rgrep'." | 156 "*Alist of aliases for the FILES argument to `lgrep' and `rgrep'." |
155 :type 'alist | 157 :type 'alist |
156 :group 'grep) | 158 :group 'grep) |
157 | 159 |
530 or \\<grep-mode-map>\\[compile-goto-error] in the grep \ | 532 or \\<grep-mode-map>\\[compile-goto-error] in the grep \ |
531 output buffer, to go to the lines | 533 output buffer, to go to the lines |
532 where grep found matches. | 534 where grep found matches. |
533 | 535 |
534 For doing a recursive `grep', see the `rgrep' command. For running | 536 For doing a recursive `grep', see the `rgrep' command. For running |
535 `grep' in the current directory see `lgrep'. | 537 `grep' in a specific directory, see `lgrep'. |
536 | 538 |
537 This command uses a special history list for its COMMAND-ARGS, so you can | 539 This command uses a special history list for its COMMAND-ARGS, so you can |
538 easily repeat a grep command. | 540 easily repeat a grep command. |
539 | 541 |
540 A prefix argument says to default the argument based upon the current | 542 A prefix argument says to default the argument based upon the current |
655 (and files | 657 (and files |
656 (or (cdr (assoc files grep-files-aliases)) | 658 (or (cdr (assoc files grep-files-aliases)) |
657 files)))) | 659 files)))) |
658 | 660 |
659 ;;;###autoload | 661 ;;;###autoload |
660 (defun lgrep (regexp &optional files) | 662 (defun lgrep (regexp &optional files dir) |
661 "Run grep, searching for REGEXP in FILES in current directory. | 663 "Run grep, searching for REGEXP in FILES in directory DIR. |
662 The search is limited to file names matching shell pattern FILES. | 664 The search is limited to file names matching shell pattern FILES. |
663 FILES may use abbreviations defined in `grep-files-aliases', e.g. | 665 FILES may use abbreviations defined in `grep-files-aliases', e.g. |
664 entering `ch' is equivalent to `*.[ch]'. | 666 entering `ch' is equivalent to `*.[ch]'. |
665 | 667 |
666 With \\[universal-argument] prefix, you can edit the constructed shell command line | 668 With \\[universal-argument] prefix, you can edit the constructed shell command line |
682 nil)) | 684 nil)) |
683 ((not grep-template) | 685 ((not grep-template) |
684 (list nil | 686 (list nil |
685 (read-string "grep.el: No `grep-template' available. Press RET."))) | 687 (read-string "grep.el: No `grep-template' available. Press RET."))) |
686 (t (let* ((regexp (grep-read-regexp)) | 688 (t (let* ((regexp (grep-read-regexp)) |
687 (files (grep-read-files regexp))) | 689 (files (grep-read-files regexp)) |
688 (list regexp files)))))) | 690 (dir (read-directory-name "In directory: " |
691 nil default-directory t))) | |
692 (list regexp files dir)))))) | |
689 (when (and (stringp regexp) (> (length regexp) 0)) | 693 (when (and (stringp regexp) (> (length regexp) 0)) |
690 (let ((command regexp)) | 694 (let ((command regexp)) |
691 (if (null files) | 695 (if (null files) |
692 (if (string= command grep-command) | 696 (if (string= command grep-command) |
693 (setq command nil)) | 697 (setq command nil)) |
698 (setq dir (file-name-as-directory (expand-file-name dir))) | |
694 (setq command (grep-expand-template | 699 (setq command (grep-expand-template |
695 grep-template | 700 grep-template |
696 regexp | 701 regexp |
697 files)) | 702 files)) |
698 (when command | 703 (when command |
700 (setq command | 705 (setq command |
701 (read-from-minibuffer "Confirm: " | 706 (read-from-minibuffer "Confirm: " |
702 command nil nil 'grep-history)) | 707 command nil nil 'grep-history)) |
703 (add-to-history 'grep-history command)))) | 708 (add-to-history 'grep-history command)))) |
704 (when command | 709 (when command |
705 ;; Setting process-setup-function makes exit-message-function work | 710 (let ((default-directory dir)) |
706 ;; even when async processes aren't supported. | 711 ;; Setting process-setup-function makes exit-message-function work |
707 (compilation-start (if (and grep-use-null-device null-device) | 712 ;; even when async processes aren't supported. |
708 (concat command " " null-device) | 713 (compilation-start (if (and grep-use-null-device null-device) |
709 command) 'grep-mode))))) | 714 (concat command " " null-device) |
715 command) 'grep-mode)) | |
716 (if (eq next-error-last-buffer (current-buffer)) | |
717 (setq default-directory dir)))))) | |
718 | |
710 | 719 |
711 | 720 |
712 ;;;###autoload | 721 ;;;###autoload |
713 (defun rgrep (regexp &optional files dir) | 722 (defun rgrep (regexp &optional files dir) |
714 "Recursively grep for REGEXP in FILES in directory tree rooted at DIR. | 723 "Recursively grep for REGEXP in FILES in directory tree rooted at DIR. |