SystemCrafters / crafted-emacs

A sensible base Emacs configuration.
MIT License
739 stars 117 forks source link

[craftedv2beta] Improve documentation for using straight.el #315

Closed monora closed 1 year ago

monora commented 1 year ago

I finally managed to setup craftedv2beta to use straight instead of the builtin package manager. The doc alone (info "(crafted-emacs)Using alternate package managers"') was not enough to get started. Here is my setup:

early-init.el:

(setq crafted-emacs-home "~/crafted-emacs-v2"
      crafted-bootstrap-directory (expand-file-name "bootstrap" crafted-emacs-home)
      crafted-config-path user-emacs-directory)
(load (expand-file-name "crafted-package" crafted-bootstrap-directory))
(setq crafted-package-system 'straight)
(crafted-package-bootstrap)

;; Adds crafted-emacs modules to the `load-path', sets up a module
;; writing template, sets the `crafted-emacs-home' variable, unless not already set.
;; We set it in `early-init' explicitly.
(load (expand-file-name "modules/crafted-init-config" crafted-emacs-home))

;; Now we can require this and configure `straight' as explained in `(info "(crafted-emacs)Using alternate package managers"'
(require 'crafted-package-config)

(setq crafted-package-installer #'straight-use-package)
(setq crafted-package-installed-predicate #'straight--installed-p)

;; Should we have an `crafted-early-init-straight-config' containing the code in this file ?
;; (load "~/crafted-emacs-v2/modules/crafted-early-init-config")

init.el:

;;; Initial phase.

;; Load the custom file if it exists.  Among other settings, this will
;; have the list `package-selected-packages', so we need to load that
;; before adding more packages.  The value of the `custom-file'
;; variable must be set appropriately, by default the value is nil.
;; This can be done here, or in the early-init.el file.
(setq custom-file (expand-file-name "custom.el" user-emacs-directory))
(when (and custom-file
           (file-exists-p custom-file))
  (load custom-file nil 'nomessage))

;; Adds crafted-emacs modules to the `load-path', sets up a module
;; writing template, sets the `crafted-emacs-home' variable.
;; (load (expand-file-name "modules/crafted-init-config" crafted-emacs-home))
;; already done in early-init.el, to configure package-system.

;;; Packages phase

;; Collect list of packages to install.
(require 'crafted-completion-packages)

;; Install the packages listed in the `package-selected-packages' list. CHANGE: Must use
;; `crafted-package-install-selected-packages' instead of
;; `package-install-selected-packages'
(crafted-package-install-selected-packages)

;; Rest same as in example init.el

Is this the intended way to use straight as package manager? If so, i would recommend to provide these two files as additional *init.el examples in the examples directory and refer to them in the docs.

jeffbowman commented 1 year ago

Thanks for examples!

This is close. The bootstrap folder is deprecated and should not be used with Crafted Emacs V2. Instead you should use the modules/crafted-package-config.el module which has similar properties.

Thus:

(load (expand-file-name "modules/crafted-package-config" crafted-emacs-home))

The rest looks good to me. with some caveats, which are mentioned below.

Regarding the documentation, would you be willing to submit a PR to update the documentation? (cc: @jvdydev )

Just as a positional statement on package managers, we only "officially" support package.el, but we recognize other package managers exist and users may prefer them over package.el. So we prefer to enable the user to provide their own configuration for handling packages. The reason for the separation between the *-packages and *-config modules is to facilitate this kind of configuration. Your example is sufficient as far as I can tell, however, it does appear to be missing the straight.el bootstrapping/installation code. Assuming that is provided somewhere near the top of your early-init.el file, I think this should work out of the box. Other package managers (borg, leaf, quelpa, etc) might need to have different configurations but, conceptually at least, those would be the "same" as straight.el.

Hope this helps answer your question(s), and I appreciate you raising the issue!

(Yes, the prior version of Crafted Emacs provided the appropriate code to initialize/setup/install straight.el, however as that code will be removed "soon" and as it makes several assumptions we no longer follow, that code will need to be provided explicitly by the user. The way your example is written would be sufficient if we intended to keep that code moving forward.)

monora commented 1 year ago

Instead you should use the modules/crafted-package-config.el module which has similar properties.

OK. It worked without the bootstrap dependend code. I only had to put the straight bootstrapping in early-init.

Regarding the documentation, would you be willing to submit a PR to update the documentation? (cc: @jvdydev )

I will try by providing an modules/crafted-early-init-straight-config.el which contains the straight bootstrap and an updated info node refering to it.

jeffbowman commented 1 year ago

I will try by providing an modules/crafted-early-init-straight-config.el which contains the straight bootstrap and an updated info node refering to it.

Would prefer this be an example rather than a module as we officially only support package.el, and adding this as a module would imply we officially support straight.el as well. We'll take a look at the info documentation on using different package managers in this context and see what can be updated so it is more clear how to approach using other package managers than package.el.

monora commented 1 year ago

Here is my current version located in the modules directory:

;;; Commentary:

;; Code to bootstrap straight package manager
;;
;; Should be loaded in early-init like this:

;; (setq crafted-emacs-home "~/crafted-emacs")
;; (load (expand-file-name "modules/crafted-early-init-straight-config" crafted-emacs-home))

;;; Code:

(load (expand-file-name "modules/crafted-package-config" crafted-emacs-home))

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

;; Configure crafted-emacs to use straight as package manager.
;; See `(info "(crafted-emacs)Using alternate package managers")'
(setq crafted-package-system 'straight)
(setq crafted-package-installer #'straight-use-package)
(setq crafted-package-installed-predicate #'straight--installed-p)

(provide 'crafted-early-init-straight-config)
;;; crafted-early-init-straight-config.el ends here

Shall I move it to the examples folder and refer to it in the docs? My personal use would be to put it in my custom-modules folder.

By the way: The v1 version did use crafted-config-path instead of user-emacs-directory and configured straight-base-dir to point to it. I guess crafted-config-path is no longer needed in v2, so I omited it to be closer to the straight defaults. Am I right?

jeffbowman commented 1 year ago

Shall I move it to the examples folder and refer to it in the docs?

Yes, please.

My personal use would be to put it in my custom-modules folder.

This would be a good approach. Keeping in mind, your configuration is yours wholly, you could just use this directly as your own version of the early-init.el file without actually needing to load it from your own custom-modules folder. Completely up to you though.

By the way: The v1 version did use crafted-config-path instead of user-emacs-directory and configured straight-base-dir to point to it. I guess crafted-config-path is no longer needed in v2, so I omited it to be closer to the straight defaults. Am I right?

Yes, that is correct. For v1, we kept those separate to avoid conflicts when Crafted Emacs was updated compared to when your updated your own personal configuration. With v2, we are assuming the user-emacs-directory is where you want to do all of your configuration, it simplifies how Crafted Emacs works, and then we just need to add the modules to the load-path in Emacs (which we do from the crafted-init-config.el file). The early-init.el file we leave to the user to configure to give the most flexibility for configuring package managers and UI elements (and anything else that can take advantage of being loaded or configured early in the Emacs startup process). Since we are no longer redirecting where the user configuration lives, we no longer need the crafted-config-path and other derived path variables (ala the etc and var versions of that path).

monora commented 1 year ago

we no longer need the crafted-config-path and other derived path variables (ala the etc and var versions of that path).

Did you notice my question #316 asking whether crafted-defaults--sensible-path was used to define etc and var directories. Do you plan something similar again in v2? Perhaps you could comment on this in #316.

jeffbowman commented 1 year ago

Thanks for pointing it out, I had not noticed. Answered there.