branch: master
commit 2ec499b799bf34b72fe703a43ca47bd996a7935d
Author: Basil L. Contovounesios <[email protected]>
Commit: Oleh Krehel <[email protected]>

    counsel.el (counsel-grep-or-swiper): Improve logic
    
    (counsel-grep-or-swiper): De Morgan.  Do not save result of
    jka-compr-build-file-regexp which is based on a defcustom.  Lookup
    compressed filenames dynamically via jka-compr-get-compression-info
    instead.
    (counsel-compressed-file-regex): Delete.
---
 counsel.el | 35 ++++++++++++-----------------------
 1 file changed, 12 insertions(+), 23 deletions(-)

diff --git a/counsel.el b/counsel.el
index e755760..b62ddc0 100644
--- a/counsel.el
+++ b/counsel.el
@@ -2383,33 +2383,22 @@ Note: don't use single quotes for either the regex or 
the file name."
   :type 'integer
   :group 'ivy)
 
-(defvar counsel-compressed-file-regex
-  (progn
-    (require 'jka-compr nil t)
-    (jka-compr-build-file-regexp))
-  "Store the regex for compressed file names.")
-
 ;;;###autoload
 (defun counsel-grep-or-swiper ()
   "Call `swiper' for small buffers and `counsel-grep' for large ones."
   (interactive)
-  (let ((fname (buffer-file-name)))
-    (if (and fname
-             (not (buffer-narrowed-p))
-             (not (ignore-errors
-                    (file-remote-p fname)))
-             (not (string-match
-                   counsel-compressed-file-regex
-                   fname))
-             (> (buffer-size)
-                (if (eq major-mode 'org-mode)
-                    (/ counsel-grep-swiper-limit 4)
-                  counsel-grep-swiper-limit)))
-        (progn
-          (when (file-writable-p fname)
-            (save-buffer))
-          (counsel-grep))
-      (swiper--ivy (swiper--candidates)))))
+  (if (or (not buffer-file-name)
+          (buffer-narrowed-p)
+          (ignore-errors
+            (file-remote-p buffer-file-name))
+          (jka-compr-get-compression-info buffer-file-name)
+          (<= (buffer-size)
+              (/ counsel-grep-swiper-limit
+                 (if (eq major-mode 'org-mode) 4 1))))
+      (swiper)
+    (when (file-writable-p buffer-file-name)
+      (save-buffer))
+    (counsel-grep)))
 
 ;;** `counsel-recoll'
 (defun counsel-recoll-function (string)

Reply via email to