Skip to content

Commit

Permalink
[Fix #1078] For projectile-grep/ag use default value like grep/rgrep/ag
Browse files Browse the repository at this point in the history
  • Loading branch information
laz2 authored and bbatsov committed Dec 15, 2016
1 parent 78720e7 commit 7717fb8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
17 changes: 12 additions & 5 deletions projectile.el
Original file line number Diff line number Diff line change
Expand Up @@ -2340,6 +2340,15 @@ This is a subset of `grep-read-files', where either a matching entry from
"Return ignored file suffixes as a list of glob patterns."
(mapcar (lambda (pat) (concat "*" pat)) projectile-globally-ignored-file-suffixes))

(defun projectile--read-search-string-with-default (prefix-label)
(let* ((prefix-label (projectile-prepend-project-name prefix-label))
(default-value (projectile-symbol-or-selection-at-point))
(default-label (if (or (not default-value)
(string= default-value ""))
""
(format " (default %s)" default-value))))
(read-string (format "%s%s: " prefix-label default-label) nil nil default-value)))

;;;###autoload
(defun projectile-grep (&optional regexp arg)
"Perform rgrep in the project.
Expand All @@ -2353,8 +2362,7 @@ With REGEXP given, don't query the user for a regexp."
(require 'grep) ;; for `rgrep'
(let* ((roots (projectile-get-project-directories))
(search-regexp (or regexp
(read-string (projectile-prepend-project-name "Grep for: ")
(projectile-symbol-or-selection-at-point))))
(projectile--read-search-string-with-default "Grep for")))
(files (and arg (or (and (equal current-prefix-arg '-)
(projectile-grep-default-files))
(read-string (projectile-prepend-project-name "Grep in: ")
Expand Down Expand Up @@ -2388,9 +2396,8 @@ With REGEXP given, don't query the user for a regexp."
With an optional prefix argument ARG SEARCH-TERM is interpreted as a
regular expression."
(interactive
(list (read-from-minibuffer
(projectile-prepend-project-name (format "Ag %ssearch for: " (if current-prefix-arg "regexp " "")))
(projectile-symbol-or-selection-at-point))
(list (projectile--read-search-string-with-default
(format "Ag %ssearch for" (if current-prefix-arg "regexp " "")))
current-prefix-arg))
(if (require 'ag nil 'noerror)
(let ((ag-command (if arg 'ag-regexp 'ag))
Expand Down
4 changes: 2 additions & 2 deletions test/projectile-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -514,8 +514,8 @@
(current-prefix-arg '-)
(sym (cadr test)))
(noflet ((projectile-project-vcs () 'git)
(read-string (prompt initial &rest args)
(if (should (equal sym initial)) initial))
(read-string (prompt initial-input history default-value &rest args)
(if (should (equal sym default-value)) default-value))
(vc-git-grep (regexp files dir)
(progn (should (equal sym regexp))
(should (equal (car (last test)) files))
Expand Down

0 comments on commit 7717fb8

Please sign in to comment.