3

The package straight.el requires the following bootstrapping code in your emacs config:

(defvar bootstrap-version)
(let ((bootstrap-file
       (expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory))
      (bootstrap-version 5))
  (unless (file-exists-p bootstrap-file)
    (with-current-buffer
        (url-retrieve-synchronously
         "https://raw.githubusercontent.com/raxod502/straight.el/develop/install.el"
         'silent 'inhibit-cookies)
      (goto-char (point-max))
      (eval-print-last-sexp)))
  (load bootstrap-file nil 'nomessage))

The use of defvar to initialize bootstrap-version was a little confusing to me, given that it's only used in a let statement that could have also just as easily initialized and defined it. However, it is invoked later in the install.el file that is retrieved into the buffer later. I'm not confident I fully understand the use of defvar, but is it the case that initializing bootstrap-version using a defvar statement makes it available to install.el? Would it not be accessible otherwise? If that's not the case, why is this variable initialized in this way instead of in the let expression?

1 Answer 1

3

The form (defvar bootstrap-version) doesn't set the value of bootstrap-version, and will not over-write the value of bootstrap-version if it was already set. It is also not necessary to make the variable "available" to straight.el or any of the files it includes.

The only thing the defvar accomplishes here is to declare bootstrap-version as "special", meaning that it is treated as a dynamic variable. straight.el uses lexical binding, so without this declaration bootstrap-version would be lexically bound.

To understand the difference, you might find Dynamic vs Lexical Binding helpful.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.