branch: externals/ivy-hydra
commit ea1e4f3c310cd03d911cf19b3e6c6ddaec6cf350
Author: Oleh Krehel <ohwoeo...@gmail.com>
Commit: Oleh Krehel <ohwoeo...@gmail.com>

    ivy.el (ivy-avy): Add a warning for M-x
    
    Fixes #2438
---
 ivy.el | 30 +++++++++++++++++-------------
 1 file changed, 17 insertions(+), 13 deletions(-)

diff --git a/ivy.el b/ivy.el
index 2bae71e..dbde39f 100644
--- a/ivy.el
+++ b/ivy.el
@@ -1834,19 +1834,23 @@ This string is inserted into the minibuffer."
 (defun ivy-avy ()
   "Jump to one of the current ivy candidates."
   (interactive)
-  (unless (require 'avy nil 'noerror)
-    (error "Package avy isn't installed"))
-  (let* ((avy-all-windows nil)
-         (avy-keys (or (cdr (assq 'ivy-avy avy-keys-alist))
-                       avy-keys))
-         (avy-style (or (cdr (assq 'ivy-avy avy-styles-alist))
-                        avy-style))
-         (avy-action #'identity)
-         (avy-handler-function #'ivy--avy-handler-function)
-         res)
-    (while (eq (setq res (avy-process (ivy--avy-candidates))) t))
-    (when res
-      (ivy--avy-action res))))
+  (cond ((not (require 'avy nil 'noerror))
+         (error "Package avy isn't installed"))
+        ((= (minibuffer-depth) 0)
+         (user-error
+          "This command is intended to be called with \"C-'\" from 
`ivy-read'."))
+        (t
+         (let* ((avy-all-windows nil)
+                (avy-keys (or (cdr (assq 'ivy-avy avy-keys-alist))
+                              avy-keys))
+                (avy-style (or (cdr (assq 'ivy-avy avy-styles-alist))
+                               avy-style))
+                (avy-action #'identity)
+                (avy-handler-function #'ivy--avy-handler-function)
+                res)
+           (while (eq (setq res (avy-process (ivy--avy-candidates))) t))
+           (when res
+             (ivy--avy-action res))))))
 
 (defun ivy-sort-file-function-default (x y)
   "Compare two files X and Y.

Reply via email to