[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 8c3bf21 36/90: ivy-toggle-calling: Toggle calling "RET" ac
From: |
Oleh Krehel |
Subject: |
[elpa] master 8c3bf21 36/90: ivy-toggle-calling: Toggle calling "RET" action for current candidate |
Date: |
Tue, 30 Jun 2015 07:28:19 +0000 |
branch: master
commit 8c3bf216171f6129317c2dc199380d96f9b4104a
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>
ivy-toggle-calling: Toggle calling "RET" action for current candidate
* ivy.el (ivy-calling): New defvar.
(ivy-set-index): New defun - a setter for `ivy--index' that can call the
current action when `ivy-calling' isn't nil.
(ivy-beginning-of-buffer):
(ivy-end-of-buffer):
(ivy-scroll-up-command):
(ivy-scroll-down-command):
(ivy-next-line):
(ivy-previous-line): Use `ivy-set-index' instead of a plain `setq'.
(ivy-toggle-calling): New defun - toggle `ivy-calling'.
(ivy-call): New defun - call the current action.
(ivy-next-line-and-call): Use `ivy-call'.
(ivy-previous-line-and-call): Use `ivy-call'.
(ivy-read): Reset `ivy-calling' to nil.
To make use of this functionality, bind `ivy-toggle-calling' in
`ivy-minibuffer-map'. After this, "C-n" will behave like "C-M-n" etc.
---
ivy.el | 65 ++++++++++++++++++++++++++++++++++++++++++---------------------
1 files changed, 43 insertions(+), 22 deletions(-)
diff --git a/ivy.el b/ivy.el
index 9faf6af..3216c4c 100644
--- a/ivy.el
+++ b/ivy.el
@@ -385,37 +385,48 @@ If the text hasn't changed as a result, forward to
`ivy-alt-done'."
:matcher (ivy-state-matcher ivy-last)
:dynamic-collection (ivy-state-dynamic-collection ivy-last)))
+(defvar ivy-calling nil
+ "When non-nil, call the current action when `ivy--index' changes.")
+
+(defun ivy-set-index (index)
+ "Set `ivy--index' to INDEX."
+ (setq ivy--index index)
+ (when ivy-calling
+ (ivy--exhibit)
+ (ivy-call)))
+
(defun ivy-beginning-of-buffer ()
"Select the first completion candidate."
(interactive)
- (setq ivy--index 0))
+ (ivy-set-index 0))
(defun ivy-end-of-buffer ()
"Select the last completion candidate."
(interactive)
- (setq ivy--index (1- ivy--length)))
+ (ivy-set-index (1- ivy--length)))
(defun ivy-scroll-up-command ()
"Scroll the candidates upward by the minibuffer height."
(interactive)
- (setq ivy--index (min (+ ivy--index ivy-height)
- (1- ivy--length))))
+ (ivy-set-index (min (+ ivy--index ivy-height)
+ (1- ivy--length))))
(defun ivy-scroll-down-command ()
"Scroll the candidates downward by the minibuffer height."
(interactive)
- (setq ivy--index (max (- ivy--index ivy-height)
- 0)))
+ (ivy-set-index (max (- ivy--index ivy-height)
+ 0)))
(defun ivy-next-line (&optional arg)
"Move cursor vertically down ARG candidates."
(interactive "p")
(setq arg (or arg 1))
- (cl-incf ivy--index arg)
- (when (> ivy--index (1- ivy--length))
- (if ivy-wrap
- (ivy-beginning-of-buffer)
- (setq ivy--index (1- ivy--length)))))
+ (let ((index (+ ivy--index arg)))
+ (if (> index (1- ivy--length))
+ (if ivy-wrap
+ (ivy-beginning-of-buffer)
+ (ivy-set-index (1- ivy--length)))
+ (ivy-set-index index))))
(defun ivy-next-line-or-history (&optional arg)
"Move cursor vertically down ARG candidates.
@@ -429,11 +440,12 @@ If the input is empty, select the previous history
element instead."
"Move cursor vertically up ARG candidates."
(interactive "p")
(setq arg (or arg 1))
- (cl-decf ivy--index arg)
- (when (< ivy--index 0)
- (if ivy-wrap
- (ivy-end-of-buffer)
- (setq ivy--index 0))))
+ (let ((index (- ivy--index arg)))
+ (if (< index 0)
+ (if ivy-wrap
+ (ivy-end-of-buffer)
+ (ivy-set-index 0))
+ (ivy-set-index index))))
(defun ivy-previous-line-or-history (arg)
"Move cursor vertically up ARG candidates.
@@ -443,15 +455,25 @@ If the input is empty, select the previous history
element instead."
(ivy-previous-history-element 1))
(ivy-previous-line arg))
+(defun ivy-toggle-calling ()
+ "Flip `ivy-calling'"
+ (interactive)
+ (when (setq ivy-calling (not ivy-calling))
+ (ivy-call)))
+
+(defun ivy-call ()
+ "Call the current action without exiting completion."
+ (when (ivy-state-action ivy-last)
+ (with-selected-window (ivy-state-window ivy-last)
+ (funcall (ivy-state-action ivy-last) ivy--current))))
+
(defun ivy-next-line-and-call (&optional arg)
"Move cursor vertically down ARG candidates.
Call the permanent action if possible."
(interactive "p")
(ivy-next-line arg)
(ivy--exhibit)
- (when (ivy-state-action ivy-last)
- (with-selected-window (ivy-state-window ivy-last)
- (funcall (ivy-state-action ivy-last) ivy--current))))
+ (ivy-call))
(defun ivy-previous-line-and-call (&optional arg)
"Move cursor vertically down ARG candidates.
@@ -459,9 +481,7 @@ Call the permanent action if possible."
(interactive "p")
(ivy-previous-line arg)
(ivy--exhibit)
- (when (ivy-state-action ivy-last)
- (with-selected-window (ivy-state-window ivy-last)
- (funcall (ivy-state-action ivy-last) ivy--current))))
+ (ivy-call))
(defun ivy-previous-history-element (arg)
"Forward to `previous-history-element' with ARG."
@@ -682,6 +702,7 @@ candidates with each input."
(setq ivy--regexp-quote 'regexp-quote)
(setq ivy--old-text "")
(setq ivy-text "")
+ (setq ivy-calling nil)
(let (coll sort-fn)
(cond ((eq collection 'Info-read-node-name-1)
(if (equal Info-current-file "dir")
- [elpa] master 3699897 26/90: counsel.el (counsel-symbol-at-point): Improve, (continued)
- [elpa] master 3699897 26/90: counsel.el (counsel-symbol-at-point): Improve, Oleh Krehel, 2015/06/30
- [elpa] master 03e7e70 27/90: counsel.el (counsel-M-x): New command, Oleh Krehel, 2015/06/30
- [elpa] master efa751b 28/90: counsel.el (counsel-M-x): Piggyback on smex for sorting, Oleh Krehel, 2015/06/30
- [elpa] master ebead12 29/90: Add fuzzy matching function, Oleh Krehel, 2015/06/30
- [elpa] master 84e20a3 30/90: Fixup ivy-resume for file completion, Oleh Krehel, 2015/06/30
- [elpa] master d24397b 32/90: counsel.el (counsel-M-x-initial-input): New defcustom, Oleh Krehel, 2015/06/30
- [elpa] master e016d48 31/90: Allow "TAB" to complete when input starts with "^", Oleh Krehel, 2015/06/30
- [elpa] master 7f2cc7c 33/90: counsel.el: Add a bunch of autoload cookies, Oleh Krehel, 2015/06/30
- [elpa] master 165c176 34/90: counsel.el (counsel-find-file-ignore-regexp): Default to nil, Oleh Krehel, 2015/06/30
- [elpa] master 72d4c76 35/90: Replace "C-x 6" with "<f2>" in counsel-M-x, Oleh Krehel, 2015/06/30
- [elpa] master 8c3bf21 36/90: ivy-toggle-calling: Toggle calling "RET" action for current candidate,
Oleh Krehel <=
- [elpa] master 39eb7ed 38/90: counsel.el (counsel-M-x): Call smex-initialize, Oleh Krehel, 2015/06/30
- [elpa] master 109e5b0 37/90: Bind "C-o" to hydra-ivy/body, Oleh Krehel, 2015/06/30
- [elpa] master 7dea8b7 39/90: ivy.el (hydra-ivy/body): Autoload, Oleh Krehel, 2015/06/30
- [elpa] master 9ceb7ee 42/90: Fix yank/undo bug, Oleh Krehel, 2015/06/30
- [elpa] master d8172a0 40/90: ivy.el (ivy--regex-fuzzy): Improve for "^" and "$", Oleh Krehel, 2015/06/30
- [elpa] master 02cedb7 43/90: ivy.el (ivy-insert-current): Add and bind to "M-i", Oleh Krehel, 2015/06/30
- [elpa] master 1a5b259 44/90: Fix the minibuffer being too small with enough candidates, Oleh Krehel, 2015/06/30
- [elpa] master e334a75 45/90: ivy.el (ivy-initial-inputs-alist): Add man and woman, Oleh Krehel, 2015/06/30
- [elpa] master ae05765 41/90: Allow to customize the initial input for all commands, Oleh Krehel, 2015/06/30
- [elpa] master 4d66758 47/90: Allow to toggle matching mode with "C-o m", Oleh Krehel, 2015/06/30