using-macro-in-emacs.org
using-macro-in-emacs
Codes
Define macros
#+srcname: define-macros
#+begin_src emacs-lisp
;;; with-dir
(defmacro do-in-dir (DIR &rest FORMS)
"Execute FORMS in DIR."
(let ((orig-dir (gensym)))
`(prog2
(setq ,orig-dir default-directory)
(progn (cd ,DIR) ,@FORMS)
(cd ,orig-dir))))
#+end_src
#+RESULTS: define-macros
: do-in-dir
Run macros
#+srcname: run-macros
#+begin_src emacs-lisp
(macroexpand '(do-in-dir "~/.emacs.d"))
#+end_src
#+RESULTS: run-macros
| prog2 | (setq G1829 default-directory) | (progn (cd ~/.emacs.d)) | (cd G1829) |
Read other posts