[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 2bd9118 44/63: counsel.el (counsel-ag): New command
From: |
Oleh Krehel |
Subject: |
[elpa] master 2bd9118 44/63: counsel.el (counsel-ag): New command |
Date: |
Fri, 21 Aug 2015 12:08:43 +0000 |
branch: master
commit 2bd91185243b5aae569be655a17fa0ffadd2aaa1
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>
counsel.el (counsel-ag): New command
* counsel.el (counsel-ag-function): New defun.
(counsel-git-grep): Update prompt.
Going from sync to async now is as simple as:
- add :dynamic-collection t
- replace `shell-command-to-string' with `counsel--async-command'
---
counsel.el | 27 ++++++++++++++++++++++++++-
1 files changed, 26 insertions(+), 1 deletions(-)
diff --git a/counsel.el b/counsel.el
index 161d789..cb87e8a 100644
--- a/counsel.el
+++ b/counsel.el
@@ -332,7 +332,7 @@ INITIAL-INPUT can be given as the initial minibuffer input."
(if (null counsel--git-grep-dir)
(error "Not in a git repository")
(setq counsel--git-grep-count (counsel--gg-count "" t))
- (ivy-read "pattern: " 'counsel-git-grep-function
+ (ivy-read "git grep: " 'counsel-git-grep-function
:initial-input initial-input
:matcher #'counsel-git-grep-matcher
:dynamic-collection (> counsel--git-grep-count 20000)
@@ -826,6 +826,31 @@ Usable with `ivy-resume', `ivy-next-line-and-call' and
:history 'org-tags-history
:action 'counsel-org-tag-action)))
+(defun counsel-ag-function (string &optional _pred &rest _unused)
+ "Grep in the current directory for STRING."
+ (if (< (length string) 3)
+ (counsel-more-chars 3)
+ (let ((regex (replace-regexp-in-string
+ "\\\\)" ")"
+ (replace-regexp-in-string
+ "\\\\(" "("
+ (ivy--regex string)))))
+ (counsel--async-command
+ (format "ag --noheading --nocolor %S" regex))
+ nil)))
+
+(defun counsel-ag (&optional initial-input)
+ "Grep for a string in the current directory using ag.
+INITIAL-INPUT can be given as the initial minibuffer input."
+ (interactive)
+ (setq counsel--git-grep-dir default-directory)
+ (ivy-read "ag: " 'counsel-ag-function
+ :initial-input initial-input
+ :dynamic-collection t
+ :history 'counsel-git-grep-history
+ :action #'counsel-git-grep-action
+ :unwind #'swiper--cleanup))
+
(provide 'counsel)
;;; counsel.el ends here
- [elpa] master 08bd5b4 25/63: counsel.el (counsel-variable-list): Add, (continued)
- [elpa] master 08bd5b4 25/63: counsel.el (counsel-variable-list): Add, Oleh Krehel, 2015/08/21
- [elpa] master ae77d93 36/63: counsel.el (counsel-org-tag): Replace org-set-tags, Oleh Krehel, 2015/08/21
- [elpa] master 1e483c5 37/63: Fixup counsel-org-tag, Oleh Krehel, 2015/08/21
- [elpa] master a9ff1f1 38/63: counsel.el (counsel-org-change-tags): Improve removing tags, Oleh Krehel, 2015/08/21
- [elpa] master 5ae677c 41/63: Simplify counsel-git-grep logic, Oleh Krehel, 2015/08/21
- [elpa] master c1b9f5a 39/63: Allow "M-o j" to switch to virtual buffers in other window, Oleh Krehel, 2015/08/21
- [elpa] master f71a562 40/63: Fix "DEL" generating a "Quit" sometimes for counsel-git-grep, Oleh Krehel, 2015/08/21
- [elpa] master 36e8fe3 46/63: counsel.el (counsel-org-tag): No need to be at heading, Oleh Krehel, 2015/08/21
- [elpa] master acf4485 42/63: ivy.el (ivy--exhibit): Check if in post-command-hook, Oleh Krehel, 2015/08/21
- [elpa] master 8a06271 43/63: Update :dynamic-collection to be a boolean, Oleh Krehel, 2015/08/21
- [elpa] master 2bd9118 44/63: counsel.el (counsel-ag): New command,
Oleh Krehel <=
- [elpa] master 8152577 45/63: counsel.el (counsel-recoll): New command, Oleh Krehel, 2015/08/21
- [elpa] master 6ab519f 48/63: counsel.el (counsel-org-tag): Delete dups, Oleh Krehel, 2015/08/21
- [elpa] master e7d778b 47/63: counsel.el (counsel-recoll): Simplify, Oleh Krehel, 2015/08/21
- [elpa] master 5b61577 49/63: Use recoll -t instead of recollq, Oleh Krehel, 2015/08/21
- [elpa] master 8d82b98 51/63: swiper.el (swiper-from-isearch): New command, Oleh Krehel, 2015/08/21
- [elpa] master dba4e47 50/63: counsel.el (org-bound-and-true-p): Update declare, Oleh Krehel, 2015/08/21
- [elpa] master 1f0c79b 52/63: counsel.el (org-setting-tags): Declare dynamic var, Oleh Krehel, 2015/08/21
- [elpa] master 40c17b4 54/63: Add a few more Org declarations, Oleh Krehel, 2015/08/21
- [elpa] master 13d0c50 56/63: counsel.el (counsel-org-tag-agenda): New command, Oleh Krehel, 2015/08/21
- [elpa] master b8b951b 59/63: Allow ivy-count-format to be set as nil, Oleh Krehel, 2015/08/21