From 2a139329997a71044593fb416367f5db4908cb81 Mon Sep 17 00:00:00 2001 From: Oleh Krehel Date: Fri, 15 Apr 2016 16:33:05 +0200 Subject: [PATCH] counsel.el (counsel-grep-or-swiper): New command * counsel.el (counsel-grep-swiper-limit): New defvar. --- counsel.el | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/counsel.el b/counsel.el index a27bc684c..7e9c2f742 100644 --- a/counsel.el +++ b/counsel.el @@ -1496,6 +1496,28 @@ 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 (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." -- 2.39.2