[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 6757030 225/272: counsel-grep now works with ivy-occur-rev
From: |
Oleh Krehel |
Subject: |
[elpa] master 6757030 225/272: counsel-grep now works with ivy-occur-revert-buffer |
Date: |
Mon, 25 Apr 2016 10:13:27 +0000 |
branch: master
commit 6757030a5b1c7b2fa80863ae08c06a73d88ad1e9
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>
counsel-grep now works with ivy-occur-revert-buffer
Press "g" in a *ivy-occur counsel-grep ...* buffer to refresh the list
of matches, due to possible changes in the file.
* counsel.el (counsel-grep-base-command): New defcustom.
(counsel-grep-occur): New defun.
(counsel-set-async-exit-code 'counsel-grep): Make it look more like swiper.
---
counsel.el | 36 +++++++++++++++++++++++++++++++++++-
1 file changed, 35 insertions(+), 1 deletion(-)
diff --git a/counsel.el b/counsel.el
index 16cc297..cce85dc 100644
--- a/counsel.el
+++ b/counsel.el
@@ -1373,6 +1373,12 @@ This uses `counsel-ag' with `counsel-pt-base-command'
replacing
(call-interactively 'counsel-ag)))
;;** `counsel-grep'
+(defcustom counsel-grep-base-command "grep -nE --ignore-case \"%s\" %s"
+ "Format string to use in `cousel-grep-function' to construct
+the command."
+ :type 'string
+ :group 'ivy)
+
(defun counsel-grep-function (string)
"Grep in the current directory for STRING."
(if (< (length string) 2)
@@ -1381,7 +1387,7 @@ This uses `counsel-ag' with `counsel-pt-base-command'
replacing
(setq ivy--old-re
(ivy--regex string)))))
(counsel--async-command
- (format "grep -nE --ignore-case \"%s\" %s" regex counsel--git-grep-dir))
+ (format counsel-grep-base-command regex counsel--git-grep-dir))
nil)))
(defun counsel-grep-action (x)
@@ -1401,6 +1407,34 @@ This uses `counsel-ag' with `counsel-pt-base-command'
replacing
(line-end-position))
(swiper--add-overlays (ivy--regex ivy-text))))))))
+(defun counsel-grep-occur ()
+ "Generate a custom occur buffer for `counsel-grep'."
+ (unless (eq major-mode 'ivy-occur-grep-mode)
+ (ivy-occur-grep-mode))
+ (let ((cands
+ (split-string
+ (shell-command-to-string
+ (format counsel-grep-base-command
+ (counsel-unquote-regex-parens
+ (setq ivy--old-re
+ (ivy--regex
+ (progn (string-match "\"\\(.*\\)\"" (buffer-name))
+ (match-string 1 (buffer-name))) t)))
+ counsel--git-grep-dir))
+ "\n" t))
+ (file (file-name-nondirectory counsel--git-grep-dir)))
+ ;; 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 "./" file ":" cand))
+ cands))))
+
+(ivy-set-occur 'counsel-grep 'counsel-grep-occur)
+(counsel-set-async-exit-code 'counsel-grep 1 "")
+
;;;###autoload
(defun counsel-grep ()
"Grep for a string in the current file."
- [elpa] master 00f08f7 073/272: Improve Ivy documentation UI, (continued)
- [elpa] master 00f08f7 073/272: Improve Ivy documentation UI, Oleh Krehel, 2016/04/25
- [elpa] master 8f527d7 149/272: ivy.el (ivy-next-history-element): No "\\_<" for dynamic-collection, Oleh Krehel, 2016/04/25
- [elpa] master 265bf49 251/272: counsel.el: Fix compile warning, Oleh Krehel, 2016/04/25
- [elpa] master 7cf13a7 186/272: counsel.el (counsel-linux-app): New command, Oleh Krehel, 2016/04/25
- [elpa] master 31a2f86 238/272: counsel.el (counsel-expression-history): enable-recursive-minibuffers, Oleh Krehel, 2016/04/25
- [elpa] master 5299c0a 099/272: doc/ivy.texi: Re-export from previous commit, Oleh Krehel, 2016/04/25
- [elpa] master a50f668 111/272: counsel.el (counsel-locate-options): Make obsolete, Oleh Krehel, 2016/04/25
- [elpa] master 327b85a 239/272: counsel.el (counsel-expression-history): Add docstring, Oleh Krehel, 2016/04/25
- [elpa] master b6f3e45 271/272: Rename swiper -> ivy, Oleh Krehel, 2016/04/25
- [elpa] master 9aa1f5c 156/272: counsel.el (counsel-mode-map): Add counsel-M-x, Oleh Krehel, 2016/04/25
- [elpa] master 6757030 225/272: counsel-grep now works with ivy-occur-revert-buffer,
Oleh Krehel <=
- [elpa] master 6026caf 174/272: counsel.el (counsel-locate-cmd-es): Add, Oleh Krehel, 2016/04/25
- [elpa] master 7ed5b06 119/272: ivy.el (ivy--preselect-index): Don't use regexp-quote, Oleh Krehel, 2016/04/25
- [elpa] master dcf4957 123/272: counsel.el (counsel--async-command): Add sentinel and filter args, Oleh Krehel, 2016/04/25
- [elpa] master 53ca6ed 065/272: ivy.el (ivy-do-completion-in-region): New defcustom, Oleh Krehel, 2016/04/25
- [elpa] master ca2b47f 240/272: Add timing information to async commands, Oleh Krehel, 2016/04/25
- [elpa] master d544427 093/272: swiper.el (swiper--re-builder): Replace \t with 4 spaces, Oleh Krehel, 2016/04/25
- [elpa] master 1f3ea7d 095/272: ivy.el (ivy-next-history-element): Handle "M-n M-n" better, Oleh Krehel, 2016/04/25
- [elpa] master ab3ad4e 085/272: doc/ivy.org: Add more CUSTOM_ID, Oleh Krehel, 2016/04/25
- [elpa] master 725e19a 170/272: counsel.el (counsel-ag-occur): Add, Oleh Krehel, 2016/04/25
- [elpa] master ccbf9ef 204/272: Improve counsel-async initial anchoring, Oleh Krehel, 2016/04/25