From 3f4f0809de70703fc3706c541d3fc27c5fc49a11 Mon Sep 17 00:00:00 2001 From: Oleh Krehel Date: Mon, 4 Apr 2016 17:29:52 +0200 Subject: [PATCH] counsel-ag now works with ivy-occur-revert-buffer * ivy.el (ivy-occur-revert-buffer): Add `counsel-ag' to the list. * counsel.el (counsel-ag-occur): Don't call `ivy-occur-grep-mode' unless needed. > (string-match "\"\\(.*\\)\"" (buffer-name)) Is a hack to recover the old `ivy-text', since it's not a field in `ivy-last', and may have changed in the meantime. TODO: Fix this sort of hacks, all necessary session data should really be in `ivy-last'. --- counsel.el | 7 +++++-- ivy.el | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/counsel.el b/counsel.el index cce85dc27..54729699b 100644 --- a/counsel.el +++ b/counsel.el @@ -1337,11 +1337,14 @@ INITIAL-INPUT can be given as the initial minibuffer input." (defun counsel-ag-occur () "Generate a custom occur buffer for `counsel-ag'." - (ivy-occur-grep-mode) + (unless (eq major-mode 'ivy-occur-grep-mode) + (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)))) + (ivy--regex + (progn (string-match "\"\\(.*\\)\"" (buffer-name)) + (match-string 1 (buffer-name))))))) (cands (split-string (shell-command-to-string (format counsel-ag-base-command (shell-quote-argument regex))) diff --git a/ivy.el b/ivy.el index 5b23a4e3d..8d25e28f6 100644 --- a/ivy.el +++ b/ivy.el @@ -2853,7 +2853,7 @@ updated original buffer." (let ((inhibit-read-only t)) (erase-buffer) (funcall (plist-get ivy--occurs-list caller) t)))) - ((memq caller '(counsel-git-grep counsel-grep)) + ((memq caller '(counsel-git-grep counsel-grep counsel-ag)) (let ((inhibit-read-only t)) (erase-buffer) (funcall (plist-get ivy--occurs-list caller))))))) -- 2.39.2