emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/ivy-hydra 721a3b7 371/395: Make ivy-mode more careful w


From: Basil L. Contovounesios
Subject: [elpa] externals/ivy-hydra 721a3b7 371/395: Make ivy-mode more careful when setting globals
Date: Thu, 25 Feb 2021 08:32:41 -0500 (EST)

branch: externals/ivy-hydra
commit 721a3b7980897b6a8ade7b91a2daceefd3e04f8d
Author: Basil L. Contovounesios <contovob@tcd.ie>
Commit: Basil L. Contovounesios <contovob@tcd.ie>

    Make ivy-mode more careful when setting globals
    
    * ivy.el (ivy--old-crf, ivy--old-cirf): New variables.
    (ivy-mode): Modify completing-read-function and
    completion-in-region-function only if they contain the expected
    value beforehand.  Remember their previous value when enabling the
    mode so that it can conditionally be restored when disabling.
    
    Re: #2765.
---
 ivy.el | 24 ++++++++++++++++++++----
 1 file changed, 20 insertions(+), 4 deletions(-)

diff --git a/ivy.el b/ivy.el
index 72e6d8e..00b120d 100644
--- a/ivy.el
+++ b/ivy.el
@@ -2627,6 +2627,12 @@ See `ivy-set-prompt'."
   "When non-nil `ivy-mode' will set `completion-in-region-function'."
   :type 'boolean)
 
+(defvar ivy--old-crf nil
+  "Store previous value of `completing-read-function'.")
+
+(defvar ivy--old-cirf nil
+  "Store previous value of `completion-in-region-function'.")
+
 ;;;###autoload
 (define-minor-mode ivy-mode
   "Toggle Ivy mode on or off.
@@ -2645,11 +2651,21 @@ Minibuffer bindings:
   :lighter " ivy"
   (if ivy-mode
       (progn
-        (setq completing-read-function 'ivy-completing-read)
+        (unless (eq completing-read-function #'ivy-completing-read)
+          (setq ivy--old-crf completing-read-function)
+          (setq completing-read-function #'ivy-completing-read))
         (when ivy-do-completion-in-region
-          (setq completion-in-region-function 'ivy-completion-in-region)))
-    (setq completing-read-function 'completing-read-default)
-    (setq completion-in-region-function 'completion--in-region)))
+          (unless (eq completion-in-region-function #'ivy-completion-in-region)
+            (setq ivy--old-cirf completion-in-region-function)
+            (setq completion-in-region-function #'ivy-completion-in-region))))
+    (when (eq completing-read-function #'ivy-completing-read)
+      (setq completing-read-function (or ivy--old-crf
+                                         #'completing-read-default))
+      (setq ivy--old-crf nil))
+    (when (eq completion-in-region-function #'ivy-completion-in-region)
+      (setq completion-in-region-function (or ivy--old-cirf
+                                              #'completion--in-region))
+      (setq ivy--old-cirf nil))))
 
 (defun ivy--preselect-index (preselect candidates)
   "Return the index of PRESELECT in CANDIDATES."



reply via email to

[Prev in Thread] Current Thread [Next in Thread]