use-package.org (1464B)
1 * Porting from ~custom-file~ 2 Some very dumb code to generate ~use-package~ declarations from Custom 3 settings. Entry point is ~c->us/port~. 4 #+begin_src elisp 5 (require 'help-fns) 6 (require 'radix-tree) 7 8 (defun c->us/get-custom-options () 9 (seq-map 10 (pcase-lambda (`(theme-value ,option user ,value)) 11 (list option value)) 12 (get 'user 'theme-settings))) 13 14 (defun c->us/get-option-file (option) 15 ;; Load packages first, otherwise symbol-file can return "loaddefs". 16 (pcase-dolist 17 (`(_ . ,files) 18 (radix-tree-prefixes (help-definition-prefixes) 19 (symbol-name option))) 20 (dolist (f files) 21 (load f 'noerror 'nomessage))) 22 (when-let ((file (symbol-file option))) 23 (file-name-base file))) 24 25 (defun c->us/write-declaration (lib pairs) 26 (insert (format "(use-package %s\n" lib)) 27 (insert " :custom") 28 (message "%s -> %s" lib pairs) 29 (pcase-dolist 30 (`(,option ,value) pairs) 31 (insert (format "\n (%s %s)" 32 option 33 (prin1-to-string value)))) 34 (insert ")\n\n")) 35 36 (defun c->us/symbols< (symlist1 symlist2) 37 (string< (car symlist1) (car symlist2))) 38 39 (defun c->us/port () 40 (seq-map 41 (pcase-lambda (`(,lib . ,pairs)) 42 (c->us/write-declaration lib pairs)) 43 (sort (seq-group-by 44 (pcase-lambda (`(,option _)) 45 (c->us/get-option-file option)) 46 (sort (c->us/get-custom-options) 'c->us/symbols<)) 47 'c->us/symbols<))) 48 #+end_src