diff options
| author | Kévin Le Gouguec <kevin.legouguec@gmail.com> | 2025-01-14 22:48:35 +0100 |
|---|---|---|
| committer | Kévin Le Gouguec <kevin.legouguec@gmail.com> | 2025-01-14 23:26:44 +0100 |
| commit | cf8a3f15ee1c80b874be10cbdd34496b84560f59 (patch) | |
| tree | c7a77d6938c6d8d539a6ae1e72160732d440ccf5 /guides/applications/emacs/use-package.org | |
| parent | faf50994d58d2651a2ab1bb1ed94dce1feb246bd (diff) | |
| download | memory-leaks-cf8a3f15ee1c80b874be10cbdd34496b84560f59.tar.xz | |
Sort guides up a bit
Diffstat (limited to 'guides/applications/emacs/use-package.org')
| -rw-r--r-- | guides/applications/emacs/use-package.org | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/guides/applications/emacs/use-package.org b/guides/applications/emacs/use-package.org new file mode 100644 index 0000000..f6cd027 --- /dev/null +++ b/guides/applications/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 |
