[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/ivy-hydra 657e6b4 062/395: ivy-test.el (ivy-inhibit-act
From: |
Basil L. Contovounesios |
Subject: |
[elpa] externals/ivy-hydra 657e6b4 062/395: ivy-test.el (ivy-inhibit-action): Better behavior with an alist collection |
Date: |
Thu, 25 Feb 2021 08:31:32 -0500 (EST) |
branch: externals/ivy-hydra
commit 657e6b4d3f2d9783dc87389f460e1145ce26fa70
Author: Oleh Krehel <ohwoeowho@gmail.com>
Commit: Oleh Krehel <ohwoeowho@gmail.com>
ivy-test.el (ivy-inhibit-action): Better behavior with an alist collection
Make it easily to extract the full cons cell.
* ivy.el (ivy-call): In case `ivy-inhibit-action' is bound, the return
result is the application of action on the current item.
(ivy-read): Simplify by returning the return result of `ivy-call'.
---
ivy-test.el | 12 +++++++
ivy.el | 115 +++++++++++++++++++++++++++++++-----------------------------
2 files changed, 72 insertions(+), 55 deletions(-)
diff --git a/ivy-test.el b/ivy-test.el
index 6054e3b..f5868a7 100644
--- a/ivy-test.el
+++ b/ivy-test.el
@@ -1436,6 +1436,18 @@ a buffer visiting a file."
(ivy--handle-directory "/sudo::"))
"/sudo::/tmp/")))
+(ert-deftest ivy-inhibit-action ()
+ (should (equal (ivy-with
+ '(let ((ivy-inhibit-action #'identity))
+ (ivy-read "pattern: " '(("a" . 1) ("b" . 2))))
+ "C-m")
+ '("a" . 1)))
+ (should (equal (ivy-with
+ '(let ((ivy-inhibit-action #'cdr))
+ (ivy-read "pattern: " '(("a" . 1) ("b" . 2))))
+ "C-n C-m")
+ 2)))
+
(defun ivy-test-run-tests ()
(let ((test-sets
'(
diff --git a/ivy.el b/ivy.el
index d885515..d8e4083 100644
--- a/ivy.el
+++ b/ivy.el
@@ -1419,54 +1419,63 @@ will be called for each element of this list.")
ivy-alt-done
ivy-dispatching-done))
(setq ivy-current-prefix-arg current-prefix-arg))
- (let ((action
- (if (functionp ivy-inhibit-action)
- ivy-inhibit-action
- (and (not ivy-inhibit-action)
- (ivy--get-action ivy-last)))))
- (when action
- (let* ((collection (ivy-state-collection ivy-last))
- (current (ivy-state-current ivy-last))
- (x (cond
- ;; Alist type.
- ((and (consp (car-safe collection))
- ;; Previously, the cdr of the selected
- ;; candidate would be returned. Now, the
- ;; whole candidate is returned.
- (let ((idx (get-text-property 0 'idx current)))
- (if idx
- (nth idx collection)
- (assoc current collection)))))
- (ivy--directory
- (expand-file-name current ivy--directory))
- ((equal current "")
- ivy-text)
- (t
- current))))
- (if (eq action #'identity)
- (prog1 x
- (ivy-recursive-restore))
- (select-window (ivy--get-window ivy-last))
- (set-buffer (ivy-state-buffer ivy-last))
- (prog1 (unwind-protect
- (if ivy-marked-candidates
- (let ((prefix-len (length ivy-mark-prefix)))
- (setq ivy-marked-candidates
- (mapcar (lambda (s) (substring s prefix-len))
- ivy-marked-candidates))
- (if (ivy-state-multi-action ivy-last)
- (funcall
- (ivy-state-multi-action ivy-last)
- ivy-marked-candidates)
- (dolist (c ivy-marked-candidates)
- (let ((default-directory (ivy-state-directory
ivy-last)))
- (funcall action c)))))
- (funcall action x))
- (ivy-recursive-restore))
- (unless (or (eq ivy-exit 'done)
- (minibuffer-window-active-p (selected-window))
- (null (active-minibuffer-window)))
- (select-window (active-minibuffer-window)))))))))
+ (let* ((action
+ (if (functionp ivy-inhibit-action)
+ ivy-inhibit-action
+ (and (not ivy-inhibit-action)
+ (ivy--get-action ivy-last))))
+ (collection (ivy-state-collection ivy-last))
+ (current (ivy-state-current ivy-last))
+ (x (cond
+ ;; Alist type.
+ ((and (consp (car-safe collection))
+ ;; Previously, the cdr of the selected
+ ;; candidate would be returned. Now, the
+ ;; whole candidate is returned.
+ (let ((idx (get-text-property 0 'idx current)))
+ (if idx
+ (progn
+ (ivy--remove-props current 'idx)
+ (nth idx collection))
+ (assoc current collection)))))
+ (ivy--directory
+ (expand-file-name current ivy--directory))
+ ((equal current "")
+ ivy-text)
+ (t
+ current)))
+ (res
+ (cond
+ ((null action)
+ current)
+ ((eq action #'identity)
+ (prog1 x
+ (ivy-recursive-restore)))
+ (t
+ (select-window (ivy--get-window ivy-last))
+ (set-buffer (ivy-state-buffer ivy-last))
+ (prog1 (unwind-protect
+ (if ivy-marked-candidates
+ (let ((prefix-len (length ivy-mark-prefix)))
+ (setq ivy-marked-candidates
+ (mapcar (lambda (s) (substring s
prefix-len))
+ ivy-marked-candidates))
+ (if (ivy-state-multi-action ivy-last)
+ (funcall
+ (ivy-state-multi-action ivy-last)
+ ivy-marked-candidates)
+ (dolist (c ivy-marked-candidates)
+ (let ((default-directory
(ivy-state-directory ivy-last)))
+ (funcall action c)))))
+ (funcall action x))
+ (ivy-recursive-restore))
+ (unless (or (eq ivy-exit 'done)
+ (minibuffer-window-active-p (selected-window))
+ (null (active-minibuffer-window)))
+ (select-window (active-minibuffer-window))))))))
+ (if ivy-inhibit-action
+ res
+ current)))
(defun ivy-call-and-recenter ()
"Call action and recenter window according to the selected candidate."
@@ -2085,8 +2094,7 @@ customizations apply to the current completion session."
(ivy--display-function
(when (or ivy-recursive-last
(not (window-minibuffer-p)))
- (ivy-alist-setting ivy-display-functions-alist caller)))
- result)
+ (ivy-alist-setting ivy-display-functions-alist caller))))
(setq update-fn (or update-fn (ivy-alist-setting ivy-update-fns-alist
caller)))
(setq unwind (or unwind (ivy-alist-setting ivy-unwind-fns-alist caller)))
(setq ivy-last
@@ -2149,12 +2157,9 @@ customizations apply to the current completion session."
hist)
(pop (symbol-value hist)))
(when (eq ivy-exit 'done)
- (ivy--update-history hist))
- (setq result (ivy-state-current ivy-last))))
+ (ivy--update-history hist))))
(ivy--cleanup))
- (ivy-call)
- (ivy--remove-props (ivy-state-current ivy-last) 'idx)
- result))
+ (ivy-call)))
(defun ivy--update-history (hist)
(let ((item (if ivy--directory
- [elpa] externals/ivy-hydra abfb283 054/395: ivy-overlay.el (ivy-display-function-overlay): Fix for org-current-level, (continued)
- [elpa] externals/ivy-hydra abfb283 054/395: ivy-overlay.el (ivy-display-function-overlay): Fix for org-current-level, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra 06886f1 055/395: ivy.el (ivy--tramp-prefix-p): Extract, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra d2052ba 017/395: counsel.el (counsel--company-display-transformer): Add, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra 1020a77 026/395: swiper.el (swiper-query-replace): Show matched groups in preview, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra c0b61ea 028/395: swiper.el (swiper--query-replace-setup): Highlight at eobp, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra 412266f 038/395: swiper.el (swiper--line-at-point): Don't error on empty string, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra e598b04 042/395: ivy.el (ivy--regex): Improve handling of capture groups, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra f42723e 046/395: ivy.el (ivy-done): Let it go through the rest of conditions if confirmation is not required., Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra 6abc3de 050/395: .travis.yml: Use 2 xenial recipes, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra ecb098d 049/395: counsel.el (counsel-imenu): Add counsel-imenu-history., Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra 657e6b4 062/395: ivy-test.el (ivy-inhibit-action): Better behavior with an alist collection,
Basil L. Contovounesios <=
- [elpa] externals/ivy-hydra 4ba0944 064/395: counsel.el (counsel-set-variable): Save expr to the kill ring, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra 40978ec 063/395: counsel.el (counsel-ag-base-command): Set default to --vimgrep, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra e7146dc 066/395: counsel.el (counsel--compilation-errors-buffer): Simplify, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra 148f84e 074/395: counsel.el (counsel-git): Work with utf-8 characters, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra bfefd69 075/395: counsel.el (counsel-git-occur): Fixup, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra b4d9286 080/395: ivy-test.el (ivy-read-sort-def): Add test, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra 41bd988 082/395: ivy.el (ivy-alt-done): In an empty directory with no input return this directory, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra 0f57db8 079/395: ivy.el (ivy--reset-state): Ensure default values are prepended, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra f8eb450 077/395: counsel.el (counsel-register): Fix for file registers in Emacs 27, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra 7d94e67 087/395: Use the current prompt for shell history initial input, Basil L. Contovounesios, 2021/02/25