# HG changeset patch # User Kim F. Storm # Date 1154127798 0 # Node ID bca9d3121eef426000549b075ae4ceb12e11cb73 # Parent e1280b2c4b2695b9b4fdfb5e5482a6cd1b856343 (grep-tag-default): New function. (grep-default-command, grep-read-regexp): Use it. diff -r e1280b2c4b26 -r bca9d3121eef lisp/progmodes/grep.el --- a/lisp/progmodes/grep.el Fri Jul 28 23:03:05 2006 +0000 +++ b/lisp/progmodes/grep.el Fri Jul 28 23:03:18 2006 +0000 @@ -455,13 +455,17 @@ (search-forward "--color" nil t)) t))))) +(defun grep-tag-default () + (or (and transient-mark-mode mark-active + (/= (point) (mark)) + (buffer-substring-no-properties (point) (mark))) + (funcall (or find-tag-default-function + (get major-mode 'find-tag-default-function) + 'find-tag-default)) + "")) + (defun grep-default-command () - (let ((tag-default - (shell-quote-argument - (or (funcall (or find-tag-default-function - (get major-mode 'find-tag-default-function) - 'find-tag-default)) - ""))) + (let ((tag-default (shell-quote-argument (grep-tag-default))) (sh-arg-re "\\(\\(?:\"\\(?:[^\"]\\|\\\\\"\\)+\"\\|'[^']+'\\|[^\"' \t\n]\\)+\\)") (grep-default (or (car grep-history) grep-command))) ;; Replace the thing matching for with that around cursor. @@ -590,15 +594,11 @@ (defun grep-read-regexp () "Read regexp arg for interactive grep." - (let ((default - (or (funcall (or find-tag-default-function - (get major-mode 'find-tag-default-function) - 'find-tag-default)) - ""))) + (let ((default (grep-tag-default))) (read-string (concat "Search for" (if (and default (> (length default) 0)) - (format " (default %s): " default) ": ")) + (format " (default \"%s\"): " default) ": ")) nil 'grep-regexp-history default))) (defun grep-read-files (regexp)