summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--guides/emacs/use-package.org48
-rw-r--r--reviews/emacs/hype.org33
2 files changed, 67 insertions, 14 deletions
diff --git a/guides/emacs/use-package.org b/guides/emacs/use-package.org
new file mode 100644
index 0000000..f6cd027
--- /dev/null
+++ b/guides/emacs/use-package.org
@@ -0,0 +1,48 @@
+* Porting from ~custom-file~
+Some very dumb code to generate ~use-package~ declarations from Custom
+settings. Entry point is ~c->us/port~.
+#+begin_src elisp
+(require 'help-fns)
+(require 'radix-tree)
+
+(defun c->us/get-custom-options ()
+ (seq-map
+ (pcase-lambda (`(theme-value ,option user ,value))
+ (list option value))
+ (get 'user 'theme-settings)))
+
+(defun c->us/get-option-file (option)
+ ;; Load packages first, otherwise symbol-file can return "loaddefs".
+ (pcase-dolist
+ (`(_ . ,files)
+ (radix-tree-prefixes (help-definition-prefixes)
+ (symbol-name option)))
+ (dolist (f files)
+ (load f 'noerror 'nomessage)))
+ (when-let ((file (symbol-file option)))
+ (file-name-base file)))
+
+(defun c->us/write-declaration (lib pairs)
+ (insert (format "(use-package %s\n" lib))
+ (insert " :custom")
+ (message "%s -> %s" lib pairs)
+ (pcase-dolist
+ (`(,option ,value) pairs)
+ (insert (format "\n (%s %s)"
+ option
+ (prin1-to-string value))))
+ (insert ")\n\n"))
+
+(defun c->us/symbols< (symlist1 symlist2)
+ (string< (car symlist1) (car symlist2)))
+
+(defun c->us/port ()
+ (seq-map
+ (pcase-lambda (`(,lib . ,pairs))
+ (c->us/write-declaration lib pairs))
+ (sort (seq-group-by
+ (pcase-lambda (`(,option _))
+ (c->us/get-option-file option))
+ (sort (c->us/get-custom-options) 'c->us/symbols<))
+ 'c->us/symbols<)))
+#+end_src
diff --git a/reviews/emacs/hype.org b/reviews/emacs/hype.org
index 03a54cc..42e9b6a 100644
--- a/reviews/emacs/hype.org
+++ b/reviews/emacs/hype.org
@@ -5,20 +5,25 @@ the changes /I/ am excited about.
** =:core= promotions
A couple of ELPA packages have moved to emacs.git, making them
available out of the box.
-
-- eglot ("Emacs Polyglot") :: an LSP client that lets Emacs leverage
- language servers to boost completion-at-point, eldoc, flymake,
- imenu, project, xref.
-
-- use-package :: a utility macro for configuring packages that makes
- init-file management more pleasant (and efficient to boot):
- - OT1H, brings some amount of structure and order when compared to a
- fully free-form DYI =.emacs=,
- - OTOH, allows more leeway on how to organize things, when compared
- to Custom's rigid auto-generated forms (e.g. using regular code
- comments, computing option values),
- - takes care of setting up the ~eval-after-load~ wizardry to keep
- startup snappy.
+*** eglot ("Emacs Polyglot"): LSP client
+Lets Emacs leverage language servers to boost completion-at-point,
+eldoc, flymake, imenu, project, xref.
+*** use-package: init-file management
+A utility macro for configuring packages that makes init-file
+management more pleasant (and efficient to boot):
+
+- OT1H, brings some amount of structure and order when compared to a
+ fully free-form DYI =.emacs=,
+- OTOH, allows more leeway on how to organize things, when compared to
+ Custom's rigid auto-generated forms (e.g. using regular code
+ comments, computing option values, sorting options arbitrarily),
+- takes care of setting up the ~eval-after-load~ wizardry to keep
+ startup snappy.
+
+A tedious aspect of porting a ~custom-file~ to ~use-package~
+declarations is tracking down what package defines which variables,
+since not every variable is named after the package it belongs to.
+I wrote [[file:~/memory-leaks/guides/emacs/use-package.org::*Porting from ~custom-file~][some code to make the process faster]].
** ~global-text-scale-adjust~
~text-scale-adjust~ (bound to =C-x C-X= ∀ =X= ∈ =[=+-0]=) only scales
the font size in the current buffer; more often than not, one may want