Mercurial > emacs
comparison lisp/progmodes/grep.el @ 90573:858cb33ae39d
Merge from emacs--devo--0
Patches applied:
* emacs--devo--0 (patch 357-381)
- Merge from gnus--rel--5.10
- Update from CVS
- Merge from erc--emacs--21
* gnus--rel--5.10 (patch 116-122)
- Update from CVS
- Merge from emacs--devo--0
Revision: emacs@sv.gnu.org/emacs--unicode--0--patch-98
author | Miles Bader <miles@gnu.org> |
---|---|
date | Thu, 03 Aug 2006 11:45:23 +0000 |
parents | 8a8e69664178 691a901b4418 |
children | 6823a91487f2 |
comparison
equal
deleted
inserted
replaced
90572:ab9b8d043c39 | 90573:858cb33ae39d |
---|---|
153 ) | 153 ) |
154 "*Alist of aliases for the FILES argument to `lgrep' and `rgrep'." | 154 "*Alist of aliases for the FILES argument to `lgrep' and `rgrep'." |
155 :type 'alist | 155 :type 'alist |
156 :group 'grep) | 156 :group 'grep) |
157 | 157 |
158 (defcustom grep-find-ignored-directories '("CVS" ".hg" "{arch}") | 158 (defcustom grep-find-ignored-directories '("CVS" ".svn" "{arch}" ".hg" "_darcs") |
159 "*List of names of sub-directories which `rgrep' shall not recurse into." | 159 "*List of names of sub-directories which `rgrep' shall not recurse into." |
160 :type '(repeat string) | 160 :type '(repeat string) |
161 :group 'grep) | 161 :group 'grep) |
162 | 162 |
163 (defcustom grep-error-screen-columns nil | 163 (defcustom grep-error-screen-columns nil |
453 (progn | 453 (progn |
454 (goto-char (point-min)) | 454 (goto-char (point-min)) |
455 (search-forward "--color" nil t)) | 455 (search-forward "--color" nil t)) |
456 t))))) | 456 t))))) |
457 | 457 |
458 (defun grep-tag-default () | |
459 (or (and transient-mark-mode mark-active | |
460 (/= (point) (mark)) | |
461 (buffer-substring-no-properties (point) (mark))) | |
462 (funcall (or find-tag-default-function | |
463 (get major-mode 'find-tag-default-function) | |
464 'find-tag-default)) | |
465 "")) | |
466 | |
458 (defun grep-default-command () | 467 (defun grep-default-command () |
459 (let ((tag-default | 468 "Compute the default grep command for C-u M-x grep to offer." |
460 (shell-quote-argument | 469 (let ((tag-default (shell-quote-argument (grep-tag-default))) |
461 (or (funcall (or find-tag-default-function | 470 ;; This a regexp to match single shell arguments. |
462 (get major-mode 'find-tag-default-function) | 471 ;; Could someone please add comments explaining it? |
463 'find-tag-default)) | |
464 ""))) | |
465 (sh-arg-re "\\(\\(?:\"\\(?:[^\"]\\|\\\\\"\\)+\"\\|'[^']+'\\|[^\"' \t\n]\\)+\\)") | 472 (sh-arg-re "\\(\\(?:\"\\(?:[^\"]\\|\\\\\"\\)+\"\\|'[^']+'\\|[^\"' \t\n]\\)+\\)") |
466 (grep-default (or (car grep-history) grep-command))) | 473 (grep-default (or (car grep-history) grep-command))) |
467 ;; Replace the thing matching for with that around cursor. | 474 ;; In the default command, find the arg that specifies the pattern. |
468 (when (or (string-match | 475 (when (or (string-match |
469 (concat "[^ ]+\\s +\\(?:-[^ ]+\\s +\\)*" | 476 (concat "[^ ]+\\s +\\(?:-[^ ]+\\s +\\)*" |
470 sh-arg-re "\\(\\s +\\(\\S +\\)\\)?") | 477 sh-arg-re "\\(\\s +\\(\\S +\\)\\)?") |
471 grep-default) | 478 grep-default) |
472 ;; If the string is not yet complete. | 479 ;; If the string is not yet complete. |
473 (string-match "\\(\\)\\'" grep-default)) | 480 (string-match "\\(\\)\\'" grep-default)) |
474 (unless (or (not (stringp buffer-file-name)) | 481 ;; Maybe we will replace the pattern with the default tag. |
475 (when (match-beginning 2) | 482 ;; But first, maybe replace the file name pattern. |
476 (save-match-data | 483 (condition-case nil |
477 (string-match | 484 (unless (or (not (stringp buffer-file-name)) |
478 (wildcard-to-regexp | 485 (when (match-beginning 2) |
479 (file-name-nondirectory | 486 (save-match-data |
480 (match-string 3 grep-default))) | 487 (string-match |
481 (file-name-nondirectory buffer-file-name))))) | 488 (wildcard-to-regexp |
482 (setq grep-default (concat (substring grep-default | 489 (file-name-nondirectory |
483 0 (match-beginning 2)) | 490 (match-string 3 grep-default))) |
484 " *." | 491 (file-name-nondirectory buffer-file-name))))) |
485 (file-name-extension buffer-file-name)))) | 492 (setq grep-default (concat (substring grep-default |
493 0 (match-beginning 2)) | |
494 " *." | |
495 (file-name-extension buffer-file-name)))) | |
496 ;; In case wildcard-to-regexp gets an error | |
497 ;; from invalid data. | |
498 (error nil)) | |
499 ;; Now replace the pattern with the default tag. | |
486 (replace-match tag-default t t grep-default 1)))) | 500 (replace-match tag-default t t grep-default 1)))) |
487 | 501 |
488 | 502 |
489 ;;;###autoload | 503 ;;;###autoload |
490 (define-compilation-mode grep-mode "Grep" | 504 (define-compilation-mode grep-mode "Grep" |
588 "") | 602 "") |
589 t t command)))))) | 603 t t command)))))) |
590 | 604 |
591 (defun grep-read-regexp () | 605 (defun grep-read-regexp () |
592 "Read regexp arg for interactive grep." | 606 "Read regexp arg for interactive grep." |
593 (let ((default | 607 (let ((default (grep-tag-default))) |
594 (or (funcall (or find-tag-default-function | |
595 (get major-mode 'find-tag-default-function) | |
596 'find-tag-default)) | |
597 ""))) | |
598 (read-string | 608 (read-string |
599 (concat "Search for" | 609 (concat "Search for" |
600 (if (and default (> (length default) 0)) | 610 (if (and default (> (length default) 0)) |
601 (format " (default %s): " default) ": ")) | 611 (format " (default \"%s\"): " default) ": ")) |
602 nil 'grep-regexp-history default))) | 612 nil 'grep-regexp-history default))) |
603 | 613 |
604 (defun grep-read-files (regexp) | 614 (defun grep-read-files (regexp) |
605 "Read files arg for interactive grep." | 615 "Read files arg for interactive grep." |
606 (let* ((bn (or (buffer-file-name) (buffer-name))) | 616 (let* ((bn (or (buffer-file-name) (buffer-name))) |
618 (setq aliases nil) | 628 (setq aliases nil) |
619 (setq alias nil))) | 629 (setq alias nil))) |
620 (cdr alias))) | 630 (cdr alias))) |
621 (and fn | 631 (and fn |
622 (let ((ext (file-name-extension fn))) | 632 (let ((ext (file-name-extension fn))) |
623 (and ext (concat "*." ext)))))) | 633 (and ext (concat "*." ext)))) |
634 (car grep-files-history) | |
635 (car (car grep-files-aliases)))) | |
624 (files (read-string | 636 (files (read-string |
625 (concat "Search for \"" regexp | 637 (concat "Search for \"" regexp |
626 "\" in files" | 638 "\" in files" |
627 (if default (concat " (default " default ")")) | 639 (if default (concat " (default " default ")")) |
628 ": ") | 640 ": ") |