How to use the <mail> function inside a macro?

Philippe Meunier meunier at ccs.neu.edu
Thu Dec 10 09:23:16 UTC 2020


Hello,

I'm trying to write a macro that allows me to edit a new message in the
background using mutt's background_edit feature.  My intent is that new
messages are edited in the foreground by default when I use the regular "m"
binding in the index and pager menus, but new messages are edited in the
background when I use a new "M" binding to a macro that changes
$background_edit and $editor.  Something like this (assuming $editor is
something like vi by default):

macro index,pager M "\
<enter-command>set my_background_edit=\$background_edit<enter>\
<enter-command>set background_edit = yes<enter>\
<enter-command>set my_editor=\$editor<enter>\
<enter-command>set editor = \"xterm -e \$editor\"<enter>\
<mail>\
<enter-command>set background_edit=\$my_background_edit<enter>\
<enter-command>unset my_background_edit<enter>\
<enter-command>set editor=\$my_editor<enter>\
<enter-command>unset my_editor<enter>\
" "background edit new mail message"

Unfortunately this doesn't work because the <mail> function seems to use
the text of the rest of the macro as destination and subject for the new
message.

So I tried this:

macro index,pager M "\
<enter-command>set my_background_edit=\$background_edit<enter>\
<enter-command>set background_edit = yes<enter>\
<enter-command>set my_editor=\$editor<enter>\
<enter-command>set editor = \"xterm -e \$editor\"<enter>\
<mail>\
\"someone at somewhere\"<enter>\
\"some title\"<enter>\
<enter-command>set background_edit=\$my_background_edit<enter>\
<enter-command>unset my_background_edit<enter>\
<enter-command>set editor=\$my_editor<enter>\
<enter-command>unset my_editor<enter>\
" "background edit new mail message"

Which works somewhat better but:

1) Obviously I don't want someone at somewhere and "some title" to be hard
   coded in the macro.  Is there some kind of <ask-for-user-input-here>
   function that can be used there in the macro?

2) After the <mail> function has finished running and the message is sent,
   the rest of the macro doesn't seem to be executed so $background_edit
   and $editor are not set back to their original values as I had expected.
   I'm not sure why that is.

3) If I use this macro twice in succession to start two background edits
   that are then running at the same time, the second one then uses "xterm
   -e xterm -e $editor" as the editor.  I guess that's because $editor is
   essentially a global variable.  Is there some way to make the changes to
   $background_edit and $editor local to the macro?  Mutt's manual (section
   6.5) talks about taking "a snapshot of certain configuration variables
   and stores them with each editing session" that sounds a lot like local
   variables...

So how can I use the <mail> function inside such a macro?  Is it possible
at all?  Ideas are welcome...

Thanks a lot,

Philippe




More information about the Mutt-users mailing list