# Nested macro definitions in mutt

I wanted a customizable <save-entry> command in mutt, in order to easily store my students’ homework PDFs in the appropriate folder, under the appropriate filename.

To implement this, I resorted to a nested macro. A macro definition in muttrc can itself contain <enter-command>macro (...), which is a nice way to create macros with customizable functionality.

This particular version works as follows: when calling SPC W (I used Spacemacs for too long), the command to bind a macro to SPC w is pre-typed into the <enter-command> dialog. One need only complete the folder name, press enter, and then save files to the pre-selected directory using SPC w in the attach menu.

Quoting the commands to be typed into the definition of the lowest-level macro was a small puzzle, but it turns out that <quote-char> is sufficiently robust for the purpose.

macro index,pager,attach <space>W \
'<enter-command>macro attach <quote-char><space<quote-char>>w \
<save-entry><quote-char><kill-line<quote-char>>~/'