                             (plist-get state :recipe)
                             name)))
             (straight-use-package
-             recipe (or
-                     ;; Normalize value of `only-if-installed'.
-                     (and only-if-installed 'lazy)
-                     (unless (member context '(:byte-compile :ensure
-                                               :config :pre-ensure
-                                               :interactive))
-                       (lambda (package)
-                         ;; Value of NO-CLONE has a meaning that is
-                         ;; the opposite of ONLY-IF-INSTALLED.
-                         (not
-                          (y-or-n-p
-                           (format "Install package %S? " package))))))))))
+             recipe
+             (lambda (package available)
+               (cond
+                ;; When doing lazy installation, don't clone if not
+                ;; available.
+                (only-if-installed (not available))
+                ;; In cases where installation should be automatic, do
+                ;; it.
+                ((memq context '(:byte-compile :ensure
+                                 :config :pre-ensure
+                                 :interactive))
+                 nil)
+                ;; Otherwise, prompt the user.
+                (t
+                 ;; Value of NO-CLONE has a meaning that is the
+                 ;; opposite of ONLY-IF-INSTALLED.
+                 (not
+                  (y-or-n-p
+                   (format "Install package %S? " package))))))))))
 
       (defun straight-use-package-pre-ensure-function
           (name ensure state)

            (package local-repo)
          (unless local-repo
            (cl-return-from straight-use-package nil))
          (straight--transaction-exec
           (intern (format "use-package-%s" package))
           (lambda ()
             (let (;; Check if the package has been successfully
                   ;; built. If not, and this is an interactive call,
                   ;; we'll want to display a helpful hint message
                   ;; (see below).
                   (already-registered
                    (gethash package straight--success-cache))
                   ;; Remember that `no-build' can come both from the
                   ;; arguments to `straight-use-package' and from the
                   ;; actual recipe.
                   (recipe-no-build (plist-get recipe :no-build)))
               ;; We need to register the recipe before building the
               ;; package, since the ability of
               ;; `straight--convert-recipe' to deal properly with
               ;; dependencies versioned in the same repository of
               ;; their parent package will break unless the caches
               ;; are updated before we recur to the dependencies.
               (straight--register-recipe recipe)
               (let ((available
                      (straight--repository-is-available-p recipe)))
                 (unless available
                   (let ((no-clone
                          (if (and (functionp no-clone)
                                   ;; Make it so that if people define
                                   ;; functions with silly names, it
                                   ;; doesn't break invocations of
                                   ;; this function with the special
                                   ;; symbols `lazy' and `no-clone'.
                                   (not (memq no-clone '(lazy no-clone))))
                              (funcall no-clone package)
                            no-clone)))
                     (when (or no-clone
                               (and (eq no-clone 'lazy)
                                    (not available)))
                       ;; Package not installed. Return nil.
                       (cl-return-from straight-use-package nil)))
                   ;; We didn't decide to abort, and the repository
                   ;; still isn't available. Make it available.
                   (straight--clone-repository recipe cause))
                 (unless (or recipe-no-build
                             (if (and (functionp no-build)
                                      ;; Same reasoning as above.
                                      (not (eq no-build 'no-build)))
                                 (funcall no-build package)
                               no-build))
                   ;; Multi-file packages will need to be on the
                   ;; `load-path' in order to byte-compile properly.
                   (straight--add-package-to-load-path recipe)
                   (straight--transaction-exec
                    'build-cache
                    #'straight--load-build-cache
                    #'straight--save-build-cache)
                   (when
                       (or
                        (and
                         straight--packages-to-rebuild
                         (or (eq straight--packages-to-rebuild :all)
                             (gethash package straight--packages-to-rebuild))
                         (not (gethash
                               package straight--packages-not-to-rebuild))
                         ;; The following form returns non-nil, so it
                         ;; doesn't affect the `and' logic.
                         (puthash package t straight--packages-not-to-rebuild))
                        (straight--package-might-be-modified-p recipe))
                     (straight--build-package recipe cause))
                   ;; Here we are not actually trying to build the
                   ;; dependencies, but activate their autoloads. (See
                   ;; the comment in `straight--build-package' about
                   ;; this code.)
                   (dolist (dependency (straight--get-dependencies package))
                     ;; There are three interesting things here.
                     ;; Firstly, the recipe used is just the name of
                     ;; the dependency. This causes the default recipe
                     ;; to be looked up, unless one of the special
                     ;; cases in `straight--convert-recipe' pops up.
                     ;; Secondly, the values of `no-build' and
                     ;; `no-clone' are always nil. If the user has
                     ;; agreed to clone and build a package, we assume
                     ;; that they also want to clone and build all of
                     ;; its dependencies. Finally, we don't bother to
                     ;; update `cause', since we're not expecting any
                     ;; messages to be displayed here (all of the
                     ;; dependencies should have already been cloned
                     ;; [if necessary] and built back by
                     ;; `straight--build-package').
                     (straight-use-package (intern dependency) nil nil cause))
                   ;; Only make the package available after everything
                   ;; is kosher.
                   (straight--activate-package-autoloads recipe)
                   ;; In interactive use, tell the user how to install
                   ;; packages permanently.
                   (when (and interactive (not already-registered))
                     (message
                      (concat "If you want to keep %s, put "
                              "(straight-use-package %s%S) "
                              "in your init-file.")
                      package "'" (intern package))))
                 ;; The package was installed successfully.
                 (puthash package t straight--success-cache)
                 t)))))
      ;; Return non-nil for built-in packages.
      t)))

;;;###autoload
(defun straight-register-package (melpa-style-recipe)

This function is equivalent to calling `straight-use-package'
with symbol `lazy' for NO-CLONE. It is provided for convenience.
MELPA-STYLE-RECIPE is as for `straight-use-package'."
  (straight-use-package
   melpa-style-recipe
   ;; Don't clone the package if it's not available.
   (lambda (_package available)
     (not available))))

;;;###autoload
(defun straight-use-recipes (melpa-style-recipe)
