On Tue, Dec 06, 2022 at 08:47:27PM +0100, Andy Spiegl wrote:
The muttlisp can't be inside quotes, so I removed the outer single quotes.Is this only true for "bind" lines? Because in the macro the muttlisp code is inside quotes:macro index j '<enter-command>run (if (equal $sidebar_visible "yes") \ "exec sidebar-next" \ "exec next-undeleted")<enter>'
Sorry I wasn't clear enough. When a command is read and executed by the muttrc parser, a MuttLisp argument can't be surrounded by quotes. That is, the muttrc parser won't look inside a quoted argument for MuttLisp.
The above macro, when initially read in from your .muttrc, won't look for MuttLisp in the third argument.
However, when the macro is executed, by pressing 'j', it starts a command prompt, using <enter-command>. The line:
run (if (equal $sidebar_visible "yes") "exec sidebar-next" "exec next-undeleted")is then read and executed by the muttrc parser when <enter> is processed at the end of the macro. At that time, it will evaluate the first argument to the run command as MuttLisp because it is not surrounded by a quote.
Note that surrounding the macro with single quotes prevents the evaulation of $sidebar_visible when the muttrc is evaluated. So the MuttLisp above will look at the value of $sidebar_visible when it is executed.
It's a bit less efficient, so if that's a concern, you could just use a macro to toggle $sidebar_visible and at the same time source a file with the special "sidebar toggling" bind commands.Good idea but how would I set the key bindings depending on the visibility state of the sidebar? I'd need some kind of if-then-else because the toggle macro doesn't "know" the state. Or can you think of a smart method to do that?
Well, you could try putting the keybindings such as
bind index j (if (equal $sidebar_visible "yes") \
'sidebar-next' \
'next-undeleted')
bind index k (if (equal $sidebar_visible "yes") \
'sidebar-prev \
'previous-undeleted')
[...]
in a file '~/.mutt/sidebar-bindings' and then
macro index ^ "\
<enter-command>toggle sidebar_visible<enter>\
<enter-command>source ~/.mutt/sidebar-bindings<enter>\
"
--
Kevin J. McCarthy
GPG Fingerprint: 8975 A9B3 3AA3 7910 385C 5308 ADEF 7684 8031 6BDA
signature.asc
Description: PGP signature
