branch: master
commit ca12f22ae19c5b5018654e5d5e579f5803b3f0e5
Author: Oleh Krehel <[email protected]>
Commit: Oleh Krehel <[email protected]>
counsel.el (counsel-imenu-map): New defvar
* counsel.el (counsel-imenu): Update.
* ivy.el (ivy-call-and-recenter): Rename/extract from
`counsel-git-grep-recenter'.
Fixes #1180
---
counsel.el | 17 ++++++++---------
ivy.el | 7 +++++++
2 files changed, 15 insertions(+), 9 deletions(-)
diff --git a/counsel.el b/counsel.el
index 7181c86..3eca04f 100644
--- a/counsel.el
+++ b/counsel.el
@@ -1037,7 +1037,7 @@ INITIAL-INPUT can be given as the initial minibuffer
input."
;;** `counsel-git-grep'
(defvar counsel-git-grep-map
(let ((map (make-sparse-keymap)))
- (define-key map (kbd "C-l") 'counsel-git-grep-recenter)
+ (define-key map (kbd "C-l") 'ivy-call-and-recenter)
(define-key map (kbd "M-q") 'counsel-git-grep-query-replace)
(define-key map (kbd "C-c C-m") 'counsel-git-grep-switch-cmd)
map))
@@ -1377,13 +1377,6 @@ When REVERT is non-nil, regenerate the current
*ivy-occur* buffer."
(goto-char (point-min)))
(perform-replace from to t t nil)))))))))))
-(defun counsel-git-grep-recenter ()
- "Recenter window according to the selected candidate."
- (interactive)
- (counsel-git-grep-action (ivy-state-current ivy-last))
- (with-ivy-window
- (recenter-top-bottom)))
-
;;** `counsel-git-stash'
(defun counsel-git-stash-kill-action (x)
"Add git stash command to kill ring.
@@ -1921,7 +1914,7 @@ It applies no filtering to ivy--all-candidates."
;;** `counsel-ag'
(defvar counsel-ag-map
(let ((map (make-sparse-keymap)))
- (define-key map (kbd "C-l") 'counsel-git-grep-recenter)
+ (define-key map (kbd "C-l") 'ivy-call-and-recenter)
(define-key map (kbd "M-q") 'counsel-git-grep-query-replace)
map))
@@ -2845,6 +2838,11 @@ PREFIX is used to create the key."
(cdr elm))))))))
alist))
+(defvar counsel-imenu-map
+ (let ((map (make-sparse-keymap)))
+ (define-key map (kbd "C-l") 'ivy-call-and-recenter)
+ map))
+
;;;###autoload
(defun counsel-imenu ()
"Jump to a buffer position indexed by imenu."
@@ -2865,6 +2863,7 @@ PREFIX is used to create the key."
;; In org-mode, (imenu candidate) will expand child
node
;; after jump to the candidate position
(imenu (cdr candidate))))
+ :keymap counsel-imenu-map
:caller 'counsel-imenu)))
;;** `counsel-list-processes'
diff --git a/ivy.el b/ivy.el
index 00c7886..c82dbf5 100644
--- a/ivy.el
+++ b/ivy.el
@@ -1112,6 +1112,13 @@ See variable `ivy-recursive-restore' for further
information."
(null (active-minibuffer-window)))
(select-window (active-minibuffer-window))))))))))
+(defun ivy-call-and-recenter ()
+ "Call action and recenter window according to the selected candidate."
+ (interactive)
+ (ivy-call)
+ (with-ivy-window
+ (recenter-top-bottom)))
+
(defun ivy-next-line-and-call (&optional arg)
"Move cursor vertically down ARG candidates.
Call the permanent action if possible."