]> code.delx.au - gnu-emacs-elpa/commitdiff
counsel.el (counsel-grep-or-swiper): New command
authorOleh Krehel <ohwoeowho@gmail.com>
Fri, 15 Apr 2016 14:33:05 +0000 (16:33 +0200)
committerOleh Krehel <ohwoeowho@gmail.com>
Fri, 15 Apr 2016 14:33:28 +0000 (16:33 +0200)
* counsel.el (counsel-grep-swiper-limit): New defvar.

counsel.el

index a27bc684ca5a0b92e8d2379dec657db79d5462a3..7e9c2f74226939510083a37765d67f44dbc41575 100644 (file)
@@ -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."