Re: Muttlisp question
> Oh, I meant less efficient because the evaluation is done every time the key > is pressed when using the macro. Plus it's a macro executing a > which is evaluating MuttLisp. Oh, of course! You are right. What was I thinking? Maybe I should stop tweaking my mutt config and go to bed? :-) Thanks, Andy -- There is no kind of dishonesty into which otherwise good people more easily and frequently fall than that of defrauding the government. (Benjamin Franklin)
Re: Muttlisp question
On Tue, Dec 06, 2022 at 10:08:04PM +0100, Andy Spiegl wrote: Well, you could try putting the keybindings such as Sure, but weren't we talking about efficency, i.e. without Muttlisp? :-) Oh, I meant less efficient because the evaluation is done every time the key is pressed when using the macro. Plus it's a macro executing a which is evaluating MuttLisp. The bind cost is paid a single time, when toggling the sidebar, but not when pressing the key. -- Kevin J. McCarthy GPG Fingerprint: 8975 A9B3 3AA3 7910 385C 5308 ADEF 7684 8031 6BDA signature.asc Description: PGP signature
Re: Muttlisp question
> Sorry I wasn't clear enough. Now I understood it. Thank you very much! > Well, you could try putting the keybindings such as Sure, but weren't we talking about efficency, i.e. without Muttlisp? :-) Thanks, Andy -- The brain is a wonderful organ; it starts working the moment you get up in the morning, and does not stop until you get to work.
Re: Muttlisp question
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 'run (if (equal $sidebar_visible "yes") \ "exec sidebar-next" \ "exec next-undeleted")' 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 . The line: run (if (equal $sidebar_visible "yes") "exec sidebar-next" "exec next-undeleted") is then read and executed by the muttrc parser when 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 ^ "\ toggle sidebar_visible\ source ~/.mutt/sidebar-bindings\ " -- Kevin J. McCarthy GPG Fingerprint: 8975 A9B3 3AA3 7910 385C 5308 ADEF 7684 8031 6BDA signature.asc Description: PGP signature
Re: Muttlisp question
Kevin, thanks a lot! This was exactly what I was looking for. > 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 'run (if (equal $sidebar_visible "yes") \ > "exec sidebar-next" \ > "exec next-undeleted")' > 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? My first guess would have been like this: macro index ^ "\ toggle sidebar_visible\ bind index,pager j next-undeleted\< this line depends " \ "hide mutt sidebar and set key bindings" Thanks, Andy -- If it's true that we are here to help others, then what exactly are the OTHERS here for?
Re: Muttlisp question
On Mon, Dec 05, 2022 at 04:12:01PM -0800, Kevin J. McCarthy wrote: set muttlisp_inline_eval bind index j (if (equal $sidebar_visible "yes") \ 'sidebar-next' \ 'next-undeleted') I realized after I sent that you might be wanting to dynamically determine if the sidebar is visible. The above just affects what is bound to 'j' when evaluated. To do that, you could try a macro: macro index j 'run (if (equal $sidebar_visible "yes") \ "exec sidebar-next" \ "exec next-undeleted")' 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. -- Kevin J. McCarthy GPG Fingerprint: 8975 A9B3 3AA3 7910 385C 5308 ADEF 7684 8031 6BDA signature.asc Description: PGP signature
Re: Muttlisp question
On Tue, Dec 06, 2022 at 12:24:58AM +0100, Andy Spiegl wrote: I'm trying to bind the "j" key to the function "sidebar-next" if the sidebar is visible. The only doable way seems to be using muttlisp. I tried to follow the example in the mutt manual but I'm failing to write this tiny piece of lisp code. Could someone help me please to correct the follwing? Or maybe there is a better/easier way to do this? -- # sidebar visible --> bind index j next-undeleted # sidebar NOT visible --> bind index j sidebar-next bind index j '\ (or \ (if (not $sidebar_visible) 'next-undeleted') \ ('sidebar-next') \ ) \ ' Try something like: set muttlisp_inline_eval bind index j (if (equal $sidebar_visible "yes") \ 'sidebar-next' \ 'next-undeleted') The muttlisp can't be inside quotes, so I removed the outer single quotes. Also, boolean variables evaluate to "yes" or "no". I will add this to the documentation. Hope that helps. -- Kevin J. McCarthy GPG Fingerprint: 8975 A9B3 3AA3 7910 385C 5308 ADEF 7684 8031 6BDA signature.asc Description: PGP signature