emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] master 2e4f2fb 213/399: Fix grep-occur when using multi-pass re-b


From: Oleh Krehel
Subject: [elpa] master 2e4f2fb 213/399: Fix grep-occur when using multi-pass re-builders
Date: Sat, 20 Jul 2019 14:57:25 -0400 (EDT)

branch: master
commit 2e4f2fb589921a8e0748dc41094a987929555d12
Author: Troy Hinckley <address@hidden>
Commit: Oleh Krehel <address@hidden>

    Fix grep-occur when using multi-pass re-builders
    
    Fixes #2033
---
 counsel.el | 44 +++++++++++++++++++++++++-------------------
 1 file changed, 25 insertions(+), 19 deletions(-)

diff --git a/counsel.el b/counsel.el
index 5610334..0b6df50 100644
--- a/counsel.el
+++ b/counsel.el
@@ -2614,23 +2614,28 @@ NEEDLE is the search string."
          (funcall ivy--regex-function str))
    counsel--regex-look-around))
 
+(defun counsel--ag-extra-switches (regex)
+  "Get additional switches needed for look-arounds."
+  (and (stringp counsel--regex-look-around)
+       ;; using look-arounds
+       (string-match-p "\\`\\^(\\?[=!]" regex)
+       (concat " " counsel--regex-look-around " ")))
+
 (defun counsel-ag-function (string)
   "Grep in the current directory for STRING."
-  (let ((command-args (counsel--split-command-args string)))
-    (let ((switches (car command-args))
-          (search-term (cdr command-args)))
-      (or
-       (let ((ivy-text search-term))
-         (ivy-more-chars))
-       (let ((default-directory (ivy-state-directory ivy-last))
-             (regex (counsel--grep-regex search-term)))
-         (if (and (stringp counsel--regex-look-around)
-                  (string-match-p "\\`\\^(\\?[=!]" regex)) ;; using 
look-arounds
-             (setq switches (concat switches " " counsel--regex-look-around)))
-         (counsel--async-command (counsel--format-ag-command
-                                  switches
-                                  (shell-quote-argument regex)))
-         nil)))))
+  (let* ((command-args (counsel--split-command-args string))
+         (search-term (cdr command-args)))
+    (or
+     (let ((ivy-text search-term))
+       (ivy-more-chars))
+     (let* ((default-directory (ivy-state-directory ivy-last))
+            (regex (counsel--grep-regex search-term))
+            (switches (concat (car command-args)
+                              (counsel--ag-extra-switches regex))))
+       (counsel--async-command (counsel--format-ag-command
+                                switches
+                                (shell-quote-argument regex)))
+       nil))))
 
 ;;;###autoload
 (cl-defun counsel-ag (&optional initial-input initial-directory extra-ag-args 
ag-prompt
@@ -2692,12 +2697,13 @@ CALLER is passed to `ivy-read'."
         (and (string-match "\"\\(.*\\)\"" (buffer-name))
              (match-string 1 (buffer-name))))
   (let* ((command-args (counsel--split-command-args ivy-text))
+         (regex (counsel--grep-regex (cdr command-args)))
+         (switches (concat (car command-args)
+                           (counsel--ag-extra-switches regex)))
          (cmd (format cmd-template
                       (concat
-                       (car command-args)
-                       (shell-quote-argument
-                        (counsel--elisp-to-pcre
-                         (ivy--regex (cdr command-args)))))))
+                       switches
+                       (shell-quote-argument regex))))
          (cands (split-string (shell-command-to-string cmd)
                               counsel-async-split-string-re
                               t)))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]