[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 5268d10 06/12: Add an option to call the completion action
From: |
Oleh Krehel |
Subject: |
[elpa] master 5268d10 06/12: Add an option to call the completion action without exiting |
Date: |
Tue, 21 Apr 2015 12:09:21 +0000 |
branch: master
commit 5268d100fbb0ac28eee3d61cae040ed28566718c
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>
Add an option to call the completion action without exiting
* ivy.el (ivy--persistent-action): New defvar. This is a lambda that the
caller sets if the caller has a plan for persistent actions.
(ivy-next-line-and-call): Add and bind to "C-M-n". Identical to "C-n",
except calls `ivy--persistent-action' when it's not nil.
Add and bind to "C-M-p". Identical to "C-p",
except calls `ivy--persistent-action' when it's not nil.
(ivy-window): New defvar.
(ivy-read): Store `ivy-window'.
* counsel.el (counsel-git-grep): Use `ivy--persistent-action'.
For `counsel-git-grep', as an example, it's possible to move to the
matched place without exiting the completion with "C-M-n" and "C-M-p".
This is a nice advantage, since it gives a full context to each one-line
git grep match.
---
counsel.el | 14 ++++++++------
ivy.el | 27 +++++++++++++++++++++++++++
2 files changed, 35 insertions(+), 6 deletions(-)
diff --git a/counsel.el b/counsel.el
index 6bbc17b..c1cc347 100644
--- a/counsel.el
+++ b/counsel.el
@@ -211,15 +211,17 @@
(let* ((counsel--git-grep-count (counsel-git-grep-count ""))
(ivy--dynamic-function (when (> counsel--git-grep-count 20000)
'counsel-git-grep-function))
- (default-directory (locate-dominating-file
- default-directory ".git"))
+ (git-dir (locate-dominating-file
+ default-directory ".git"))
+ (ivy--persistent-action (lambda (x)
+ (setq lst (split-string x ":"))
+ (find-file (expand-file-name (car lst)
git-dir))
+ (goto-char (point-min))
+ (forward-line (1- (string-to-number (cadr
lst))))))
(val (ivy-read "pattern: " 'counsel-git-grep-function))
lst)
(when val
- (setq lst (split-string val ":"))
- (find-file (car lst))
- (goto-char (point-min))
- (forward-line (1- (string-to-number (cadr lst)))))))
+ (funcall ivy--persistent-action val))))
(defun counsel-locate-function (str &rest _u)
(if (< (length str) 3)
diff --git a/ivy.el b/ivy.el
index d25fbce..65b68d9 100644
--- a/ivy.el
+++ b/ivy.el
@@ -99,6 +99,8 @@ Only \"./\" and \"../\" apply here. They appear in reverse
order."
(define-key map (kbd "C-g") 'minibuffer-keyboard-quit)
(define-key map (kbd "C-v") 'ivy-scroll-up-command)
(define-key map (kbd "M-v") 'ivy-scroll-down-command)
+ (define-key map (kbd "C-M-n") 'ivy-next-line-and-call)
+ (define-key map (kbd "C-M-p") 'ivy-previous-line-and-call)
map)
"Keymap used in the minibuffer.")
@@ -120,6 +122,9 @@ of `history-length', which see.")
(defvar ivy-text ""
"Store the user's string as it is typed in.")
+(defvar ivy-window nil
+ "Store the window in which `ivy-read' was called.")
+
(defvar ivy--current ""
"Current candidate.")
@@ -133,6 +138,9 @@ Otherwise, store nil.")
(defvar ivy--action nil
"Store a function to call at the end of `ivy--read'.")
+(defvar ivy--persistent-action nil
+ "Store a function to call for current candidate without exiting.")
+
(defvar ivy--all-candidates nil
"Store the candidates passed to `ivy-read'.")
@@ -256,6 +264,24 @@ If the input is empty, select the previous history element
instead."
(ivy-previous-history-element 1))
(ivy-previous-line arg))
+(defun ivy-next-line-and-call (&optional arg)
+ "Move cursor vertically down ARG candidates."
+ (interactive "p")
+ (ivy-next-line arg)
+ (ivy--exhibit)
+ (when ivy--persistent-action
+ (with-selected-window ivy-window
+ (funcall ivy--persistent-action ivy--current))))
+
+(defun ivy-previous-line-and-call (&optional arg)
+ "Move cursor vertically down ARG candidates."
+ (interactive "p")
+ (ivy-previous-line arg)
+ (ivy--exhibit)
+ (when ivy--persistent-action
+ (with-selected-window ivy-window
+ (funcall ivy--persistent-action ivy--current))))
+
(defun ivy-previous-history-element (arg)
"Forward to `previous-history-element' with ARG."
(interactive "p")
@@ -367,6 +393,7 @@ UPDATE-FN is called each time the current candidate(s) is
changed.
When SORT is t, refer to `ivy-sort-functions-alist' for sorting."
(setq ivy--directory nil)
+ (setq ivy-window (selected-window))
(let (coll sort-fn)
(cond ((eq collection 'Info-read-node-name-1)
(if (equal Info-current-file "dir")
- [elpa] master updated (3d54459 -> e86b27e), Oleh Krehel, 2015/04/21
- [elpa] master 0d1fa17 01/12: ivy.el (ivy-done): Expand file name for empty text, Oleh Krehel, 2015/04/21
- [elpa] master 36b15f3 02/12: ivy.el (ivy--regex): Switch to non-greedy ".*?" joiner, Oleh Krehel, 2015/04/21
- [elpa] master 49638b4 04/12: ivy.el (ivy--sorted-files): Avoid returning an empty list, Oleh Krehel, 2015/04/21
- [elpa] master 2a5d3fc 05/12: Fix double-sorting for file names, Oleh Krehel, 2015/04/21
- [elpa] master bb89c9d 03/12: Allow to customize the sorting methods, Oleh Krehel, 2015/04/21
- [elpa] master 94c124d 07/12: ivy.el (ivy-done): Don't directory-expand glob filename, Oleh Krehel, 2015/04/21
- [elpa] master 5268d10 06/12: Add an option to call the completion action without exiting,
Oleh Krehel <=
- [elpa] master 9d5b60f 09/12: ivy.el (ivy--regex): Add optional greedy arg, Oleh Krehel, 2015/04/21
- [elpa] master be716a1 08/12: swiper.el (swiper--add-overlays): Update arglist, Oleh Krehel, 2015/04/21
- [elpa] master b724678 10/12: counsel.el: Add awesome swiper highlighting to git grep, Oleh Krehel, 2015/04/21
- [elpa] master 675bd5f 11/12: Fix describe-function / -variable "C-." interaction, Oleh Krehel, 2015/04/21
- [elpa] master e86b27e 12/12: Merge commit '675bd5ff97f75fb7d838e6056442ce71adf85e56' from swiper, Oleh Krehel, 2015/04/21