Show
Ignore:
Timestamp:
08/10/06 11:19:54 (2 years ago)
Author:
miyoshi
Message:

Sync up with Emacs CVS HEAD.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lisp/progmodes/grep.el

    r4131 r4140  
    456456                 t))))) 
    457457 
     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 
    458467(defun grep-default-command () 
    459   (let ((tag-default 
    460          (shell-quote-argument 
    461           (or (funcall (or find-tag-default-function 
    462                            (get major-mode 'find-tag-default-function) 
    463                            'find-tag-default)) 
    464               ""))) 
     468  "Compute the default grep command for C-u M-x grep to offer." 
     469  (let ((tag-default (shell-quote-argument (grep-tag-default))) 
     470        ;; This a regexp to match single shell arguments. 
     471        ;; Could someone please add comments explaining it? 
    465472        (sh-arg-re "\\(\\(?:\"\\(?:[^\"]\\|\\\\\"\\)+\"\\|'[^']+'\\|[^\"' \t\n]\\)+\\)") 
    466473        (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
    468475    (when (or (string-match 
    469476               (concat "[^ ]+\\s +\\(?:-[^ ]+\\s +\\)*" 
     
    472479              ;; If the string is not yet complete. 
    473480              (string-match "\\(\\)\\'" grep-default)) 
    474       (unless (or (not (stringp buffer-file-name)) 
    475                   (when (match-beginning 2) 
    476                     (save-match-data 
    477                       (string-match 
    478                        (wildcard-to-regexp 
    479                         (file-name-nondirectory 
    480                          (match-string 3 grep-default))) 
    481                        (file-name-nondirectory buffer-file-name))))) 
    482         (setq grep-default (concat (substring grep-default 
    483                                               0 (match-beginning 2)) 
    484                                    " *." 
    485                                    (file-name-extension buffer-file-name)))) 
     481      ;; Maybe we will replace the pattern with the default tag. 
     482      ;; But first, maybe replace the file name pattern. 
     483      (condition-case nil 
     484          (unless (or (not (stringp buffer-file-name)) 
     485                      (when (match-beginning 2) 
     486                        (save-match-data 
     487                          (string-match 
     488                           (wildcard-to-regexp 
     489                            (file-name-nondirectory 
     490                             (match-string 3 grep-default))) 
     491                           (file-name-nondirectory 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. 
    486500      (replace-match tag-default t t grep-default 1)))) 
    487501 
     
    591605(defun grep-read-regexp () 
    592606  "Read regexp arg for interactive grep." 
    593   (let ((default 
    594           (or (funcall (or find-tag-default-function 
    595                            (get major-mode 'find-tag-default-function) 
    596                            'find-tag-default)) 
    597               ""))) 
     607  (let ((default (grep-tag-default))) 
    598608    (read-string 
    599609     (concat "Search for" 
    600610             (if (and default (> (length default) 0)) 
    601                  (format " (default %s): " default) ": ")) 
     611                 (format " (default \"%s\"): " default) ": ")) 
    602612     nil 'grep-regexp-history default))) 
    603613 
     
    621631               (and fn 
    622632                    (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)))) 
    624636         (files (read-string 
    625637                 (concat "Search for \"" regexp