]> code.delx.au - gnu-emacs-elpa/commitdiff
counsel.el (counsel-ag-occur): Add
authorOleh Krehel <ohwoeowho@gmail.com>
Wed, 9 Mar 2016 15:28:13 +0000 (16:28 +0100)
committerOleh Krehel <ohwoeowho@gmail.com>
Wed, 9 Mar 2016 15:28:13 +0000 (16:28 +0100)
Re #423

counsel.el

index 53da8893503abf075394e4a5786df841efb4d04d..2c0c480ef999bc5799c6f25488e0a0760b00ae3e 100644 (file)
@@ -1229,6 +1229,7 @@ command. %S will be replaced by the regex string. The default is
   :group 'ivy)
 
 (counsel-set-async-exit-code 'counsel-ag 1 "No matches found")
+(ivy-set-occur 'counsel-ag 'counsel-ag-occur)
 
 (defun counsel-ag-function (string)
   "Grep in the current directory for STRING."
@@ -1258,6 +1259,27 @@ INITIAL-INPUT can be given as the initial minibuffer input."
                       (swiper--cleanup))
             :caller 'counsel-ag))
 
+(defun counsel-ag-occur ()
+  "Generate a custom occur buffer for `counsel-ag'."
+  (ivy-occur-grep-mode)
+  (setq default-directory counsel--git-grep-dir)
+  (let* ((regex (counsel-unquote-regex-parens
+                 (setq ivy--old-re
+                       (ivy--regex ivy-text))))
+         (cands (split-string
+                 (shell-command-to-string
+                  (format counsel-ag-base-command (shell-quote-argument regex)))
+                 "\n"
+                 t)))
+    ;; Need precise number of header lines for `wgrep' to work.
+    (insert (format "-*- mode:grep; default-directory: %S -*-\n\n\n"
+                    default-directory))
+    (insert (format "%d candidates:\n" (length cands)))
+    (ivy--occur-insert-lines
+     (mapcar
+      (lambda (cand) (concat "./" cand))
+      cands))))
+
 ;;** `counsel-grep'
 (defun counsel-grep-function (string)
   "Grep in the current directory for STRING."