Streamlined configuration with setup.el

This commit is contained in:
2026-01-03 18:08:55 +01:00
parent 7a075ccf9d
commit 996377775c
+131
View File
@@ -323,3 +323,134 @@ and =package-user-dir=.
(setq custom-safe-themes t)
(load-theme 'r2849)
#+end_src
* Streamlined configuration with setup.el
Use the excellent [[https://www.emacswiki.org/emacs/SetupEl][setup.el]] by [[https://ruzkuku.com][pkal]] as an alternative to =use-package=.
#+begin_src emacs-lisp
(straight-use-package
'(setup
:type git
:host nil
:repo "https://git.sr.ht/~pkal/setup"))
(require 'setup)
;; Uncomment this for debugging purposes
;; (defun dw/log-require (&rest args)
;; (with-current-buffer (get-buffer-create "*require-log*")
;; (insert (format "%s\n"
;; (file-name-nondirectory (car args))))))
;; (add-to-list 'after-load-functions #'dw/log-require)
#+end_src
** :straight
StraightEl (on GitHub) is a “next-generation, purely functional package manager
for the Emacs hacker,” according to its repo. I like using it is all I know.
Heres a :straight keyword for setup:
#+begin_src emacs-lisp
(setup-define :straight
(lambda (recipe)
`(unless (straight-use-package ',recipe)
,(setup-quit)))
:documentation
"Install RECIPE with `straight-use-package'.
This macro can be used as HEAD, and will replace itself with the
first RECIPE's package."
:repeatable t
:shorthand (lambda (sexp)
(let ((recipe (cadr sexp)))
(if (consp recipe)
(car recipe)
recipe))))
#+end_src
** :pkg
#+begin_src emacs-lisp
(defun mr/filter-straight-recipe (recipe)
(let* ((plist (cdr recipe))
(name (plist-get plist :straight)))
(cons (if (and name (not (equal name t)))
name
(car recipe))
(plist-put plist :straight nil))))
(setup-define :pkg
(lambda (&rest recipe)
`(straight-use-package ',(mr/filter-straight-recipe recipe)))
:documentation "Install RECIPE via Guix or straight.el"
:shorthand #'cadr)
#+end_src
** :delay
Delay the loading of a package until a certain amount of idle time has passed.
#+begin_src emacs-lisp
(setup-define :delay
(lambda (&rest time)
`(run-with-idle-timer ,(or time 1)
nil ;; Don't repeat
(lambda () (require ',(setup-get 'feature)))))
:documentation "Delay loading the feature until a certain amount of idle time has passed.")
#+end_src
** :disabled
Used to disable a package configuration, similar to =:disabled= in =use-package=.
#+begin_src emacs-lisp
(setup-define :disabled
(lambda ()
`,(setup-quit))
:documentation "Always stop evaluating the body.")
#+end_src
** :load-after
This keyword causes a body to be executed after other packages/features are loaded:
#+begin_src emacs-lisp
(setup-define :load-after
(lambda (features &rest body)
(let ((body `(progn
(require ',(setup-get 'feature))
,@body)))
(dolist (feature (if (listp features)
(nreverse features)
(list features)))
(setq body `(with-eval-after-load ',feature ,body)))
body))
:documentation "Load the current feature after FEATURES."
:indent 1)
#+end_src
** :face
Customizing faces.
#+begin_src emacs-lisp
(setup-define :face
(lambda (face spec)
`(custom-set-faces (quote (,face ,spec))))
:documentation "Customize FACE to SPEC."
:signature '(face spec ...)
:debug '(setup)
:repeatable t
:after-loaded t)
#+end_src