From b3ea4f242d58ff9b903ece4b0e2513d6aed41578 Mon Sep 17 00:00:00 2001 From: Eric Danan Date: Wed, 26 Dec 2018 15:12:57 +0100 Subject: [PATCH] cp-grep: Simplify --- counsel-projectile.el | 25 ++++--------------------- 1 file changed, 4 insertions(+), 21 deletions(-) diff --git a/counsel-projectile.el b/counsel-projectile.el index 4a1eb19..2e69f53 100644 --- a/counsel-projectile.el +++ b/counsel-projectile.el @@ -647,9 +647,7 @@ construct the command.") "Grep for STRING in the current project." (or (counsel-more-chars) (let ((default-directory (ivy-state-directory ivy-last)) - (regex (counsel--elisp-to-pcre - (setq ivy--old-re - (ivy--regex string))))) + (regex (counsel--grep-regex string))) (counsel--async-command (format counsel-projectile-grep-command (shell-quote-argument regex))) nil))) @@ -671,24 +669,8 @@ construct the command.") (defun counsel-projectile-grep-occur () "Generate a custom occur buffer for `counsel-projectile-grep'." - ;; Copied from `counsel-grep-like-occur', except that we don't - ;; prepend "./" to the candidates since grep already does so. - (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))) + (counsel-grep-like-occur + counsel-projectile-grep-command)) ;;;###autoload (defun counsel-projectile-grep (&optional options-or-cmd) @@ -743,6 +725,7 @@ called with a prefix argument." (swiper--cleanup)) :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") (ivy-set-occur 'counsel-projectile-grep 'counsel-projectile-grep-occur) (ivy-set-display-transformer 'counsel-projectile-grep 'counsel-projectile-grep-transformer)