Skip to content

Instantly share code, notes, and snippets.

@zk-phi
Created May 10, 2021 06:30
Show Gist options
  • Save zk-phi/a90af91109bf95754ccb1684db7e7cf4 to your computer and use it in GitHub Desktop.
Save zk-phi/a90af91109bf95754ccb1684db7e7cf4 to your computer and use it in GitHub Desktop.
macroexpand-file
(require 'macroexp)
(defun read-and-macroexpand-all (stream)
(ignore-errors
(cons (macroexpand-all (read stream))
(read-and-macroexpand-all stream))))
(defun macroexpand-file (src dest)
"ファイル SRC 内のすべてのフォームをマクロ展開して、ファイル DEST に保存する"
(let ((forms (with-temp-buffer
(insert-file-contents src)
(read-and-macroexpand-all (current-buffer)))))
(with-temp-buffer
(dolist (form forms)
(prin1 form (current-buffer))
(insert "\n\n"))
(write-file dest))))
;; (macroexpand-file "~/.emacs.d/init.el" "~/.emacs.d/init-expanded.el")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment