* 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