I'm currently getting into Literate Programming with org-mode in Emacs. One of the key features to make it tractable as a programming style is macros. I would like to be able to do something like this:

#+BEGIN_SRC emacs-lisp :tangle yes :noweb yes
<<set-name(name="John Doe",email="john.doe@gmail.com")>>

#+NAME: set-name
#+BEGIN_SRC emacs-lisp :tangle no :macro yes :var name="" :var email=""
(setq user-full-name name
      user-mail-address email)

And to have the tangled result be

(setq user-full-name "John Doe"
      user-mail-address "john.doe@gmail.com")

Currently this is possible in lisp languages like so:

#+NAME: set-name
#+BEGIN_SRC emacs-lisp :tangle no :var name="" :var email=""
`(setq user-full-name ,name
       user-mail-address ,email)

However, it doesn't appear that this is possible with other languages with lesser macro features, like Java for example.

Is there a pre-existing way to do this kind of variable-substitution-based macro expansion in org-mode? If not, where would be a good place to start with implementing it?

  • A potential solution which can be used in some cases is to simply wrap the using code in a variable declaration, like so: (let ((name "John Doe") (email "john.doe@gmail.com")) <<set-name>>) – Suskeyhose May 11 at 23:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.