branch: master
commit dc223ac4b6e2bc49589885f29a482ab58beada50
Author: Ryan C. Thompson <[email protected]>
Commit: Ryan C. Thompson <[email protected]>

    Prevent infinite recursion when handlers call ivy
    
    Previously, if a function in ivy-completing-read-handlers-alist called
    ivy-completing-read, this would result in infinite recursion. However,
    now if ivy-completing-read is called recursively without incrementing
    "(minibuffer-depth)", it ignores all handlers on the second call,
    breaking the recursion.
    
    The result of all this is that functions in
    ivy-completing-read-handlers-alist can now safely call
    ivy-completing-read.
---
 ivy.el | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/ivy.el b/ivy.el
index 521a9a5..d128a20 100644
--- a/ivy.el
+++ b/ivy.el
@@ -202,6 +202,12 @@ See 
https://github.com/abo-abo/swiper/wiki/ivy-display-function.";
   "An alist of handlers to replace `completing-read' in `ivy-mode'."
   :type '(alist :key-type function :value-type function))
 
+(defvar ivy-completing-read-ignore-handlers-depth -1
+  "Used to avoid infinite recursion.
+
+If `(minibuffer-depth)' equals this, `ivy-completing-read' will
+act as if `ivy-completing-read-handlers-alist' is empty.")
+
 (defvar ivy--actions-list nil
   "A list of extra actions per command.")
 
@@ -1842,9 +1848,12 @@ INITIAL-INPUT is a string inserted into the minibuffer 
initially.
 HISTORY is a list of previously selected inputs.
 DEF is the default value.
 INHERIT-INPUT-METHOD is currently ignored."
-  (let ((handler (assoc this-command ivy-completing-read-handlers-alist)))
+  (let ((handler
+         (when (< ivy-completing-read-ignore-handlers-depth (minibuffer-depth))
+           (assoc this-command ivy-completing-read-handlers-alist))))
     (if handler
-        (let ((completion-in-region-function #'completion--in-region))
+        (let ((completion-in-region-function #'completion--in-region)
+              (ivy-completing-read-ignore-handlers-depth (1+ 
(minibuffer-depth))))
           (funcall (cdr handler)
                    prompt collection
                    predicate require-match

Reply via email to