cp-grep: Simplify
This commit is contained in:
parent
5f554cdca7
commit
b3ea4f242d
1 changed files with 4 additions and 21 deletions
|
|
@ -647,9 +647,7 @@ construct the command.")
|
||||||
"Grep for STRING in the current project."
|
"Grep for STRING in the current project."
|
||||||
(or (counsel-more-chars)
|
(or (counsel-more-chars)
|
||||||
(let ((default-directory (ivy-state-directory ivy-last))
|
(let ((default-directory (ivy-state-directory ivy-last))
|
||||||
(regex (counsel--elisp-to-pcre
|
(regex (counsel--grep-regex string)))
|
||||||
(setq ivy--old-re
|
|
||||||
(ivy--regex string)))))
|
|
||||||
(counsel--async-command (format counsel-projectile-grep-command
|
(counsel--async-command (format counsel-projectile-grep-command
|
||||||
(shell-quote-argument regex)))
|
(shell-quote-argument regex)))
|
||||||
nil)))
|
nil)))
|
||||||
|
|
@ -671,24 +669,8 @@ construct the command.")
|
||||||
|
|
||||||
(defun counsel-projectile-grep-occur ()
|
(defun counsel-projectile-grep-occur ()
|
||||||
"Generate a custom occur buffer for `counsel-projectile-grep'."
|
"Generate a custom occur buffer for `counsel-projectile-grep'."
|
||||||
;; Copied from `counsel-grep-like-occur', except that we don't
|
(counsel-grep-like-occur
|
||||||
;; prepend "./" to the candidates since grep already does so.
|
counsel-projectile-grep-command))
|
||||||
(unless (eq major-mode 'ivy-occur-grep-mode)
|
|
||||||
(ivy-occur-grep-mode)
|
|
||||||
(setq default-directory (ivy-state-directory ivy-last)))
|
|
||||||
(setq ivy-text
|
|
||||||
(and (string-match "\"\\(.*\\)\"" (buffer-name))
|
|
||||||
(match-string 1 (buffer-name))))
|
|
||||||
(let* ((cmd (format counsel-projectile-grep-command
|
|
||||||
(shell-quote-argument
|
|
||||||
(counsel--elisp-to-pcre
|
|
||||||
(ivy--regex ivy-text)))))
|
|
||||||
(cands (split-string (shell-command-to-string cmd) "\n" t)))
|
|
||||||
;; Need precise number of header lines for `wgrep' to work.
|
|
||||||
(insert (format "-*- mode:grep; default-directory: %S -*-\n\n\n"
|
|
||||||
default-directory))
|
|
||||||
(insert (format "%d candidates:\n" (length cands)))
|
|
||||||
(ivy--occur-insert-lines cands)))
|
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun counsel-projectile-grep (&optional options-or-cmd)
|
(defun counsel-projectile-grep (&optional options-or-cmd)
|
||||||
|
|
@ -743,6 +725,7 @@ called with a prefix argument."
|
||||||
(swiper--cleanup))
|
(swiper--cleanup))
|
||||||
:caller 'counsel-projectile-grep)))))
|
:caller 'counsel-projectile-grep)))))
|
||||||
|
|
||||||
|
(cl-pushnew 'counsel-projectile-grep ivy-highlight-grep-commands)
|
||||||
(counsel-set-async-exit-code 'counsel-projectile-grep 1 "No matches found")
|
(counsel-set-async-exit-code 'counsel-projectile-grep 1 "No matches found")
|
||||||
(ivy-set-occur 'counsel-projectile-grep 'counsel-projectile-grep-occur)
|
(ivy-set-occur 'counsel-projectile-grep 'counsel-projectile-grep-occur)
|
||||||
(ivy-set-display-transformer 'counsel-projectile-grep 'counsel-projectile-grep-transformer)
|
(ivy-set-display-transformer 'counsel-projectile-grep 'counsel-projectile-grep-transformer)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue