]> code.delx.au - gnu-emacs-elpa/blobdiff - counsel.el
ivy.el (ivy--format-minibuffer-line): Update
[gnu-emacs-elpa] / counsel.el
index 745d054b8c333a0fe4acf4717c49ca31ee59d347..81c9c2565305731b00872aed8639b316c3d571d0 100644 (file)
@@ -121,6 +121,8 @@ Or the time of the last minibuffer update.")
     (set-process-sentinel proc (or process-sentinel #'counsel--async-sentinel))
     (set-process-filter proc (or process-filter #'counsel--async-filter))))
 
+(defvar counsel-grep-last-line nil)
+
 (defun counsel--async-sentinel (process event)
   (let ((cands
          (cond ((string= event "finished\n")
@@ -141,8 +143,10 @@ Or the time of the last minibuffer update.")
            (ivy--set-candidates
             (ivy--sort-maybe
              cands))
-           (setq counsel--async-duration
-                 (time-to-seconds (time-since counsel--async-start)))
+           (setq counsel-grep-last-line nil)
+           (when counsel--async-start
+             (setq counsel--async-duration
+                   (time-to-seconds (time-since counsel--async-start))))
            (let ((re (funcall ivy--regex-function ivy-text)))
              (unless (stringp re)
                (setq re (caar re)))
@@ -1411,8 +1415,6 @@ the command."
        (format counsel-grep-base-command regex counsel--git-grep-dir))
       nil)))
 
-(defvar counsel-grep-last-line nil)
-
 (defun counsel-grep-action (x)
   (with-ivy-window
     (swiper--cleanup)
@@ -1495,6 +1497,29 @@ the command."
       (unless res
         (goto-char init-point)))))
 
+;;** `counsel-grep-or-swiper'
+(defcustom counsel-grep-swiper-limit 300000
+  "When the buffer is larger than this, use `counsel-grep' instead of `swiper'."
+  :type 'integer
+  :group 'ivy)
+
+;;;###autoload
+(defun counsel-grep-or-swiper ()
+  "Call `swiper' for small buffers and `counsel-grep' for large ones."
+  (interactive)
+  (if (and (buffer-file-name)
+           (not (buffer-narrowed-p))
+           (not (ignore-errors
+                  (file-remote-p (buffer-file-name))))
+           (> (buffer-size)
+              (if (eq major-mode 'org-mode)
+                  (/ counsel-grep-swiper-limit 4)
+                counsel-grep-swiper-limit)))
+      (progn
+        (save-buffer)
+        (counsel-grep))
+    (swiper--ivy (swiper--candidates))))
+
 ;;** `counsel-recoll'
 (defun counsel-recoll-function (string)
   "Grep in the current directory for STRING."