<<< Date Index >>>     <<< Thread Index >>>

Re: toggle button



On Tue, May 04, 2004 at 05:56:08PM +0300, Laas Toom wrote:
> I was thinking whether it is possible to implement the
> following with mutt's macros:
> 
>       if (sort == 'threads') then set sort = 'date'
>       else set sort='threads
> 
> That is get a single button to act different based on the
> current value of the sort variable (or any other variable).
> 
> I want this, because in some folders i need the date-order,
> but otherwise i prefer threaded view. So for now i just type
> in :set sort=<date|threads> when i need to switch, but i would
> like to make it more comfortable.

I just found your question in my last month's archive of the list,
therefore I'm late in answering :-)

Three is no 'real' way to do what you want, because
you can not 'really' make macros depend on values of
a variable (as far as I know).

BUT you *can* write a 'toggle' (or a 'loop' with many values)
by letting each macro-call redefine the key ti the next call
(with two this toggles, but there is no real limit :-)

E.g. I did a toggle between English and German 'ispell'
in the compose screen because I run mutt *permanently* but
reply in both languages (and have the same high rate of
typos in both :-):
-------------- piece of .muttrc ------------------------
#
# 'toggler' in 'compose' for ispell dictionaries
# Output of the current 'setting' by "set ?<variable>"
#
# 'Actions'
macro compose _AX0 ":set ?ispell^M"
macro compose _AX1 ":set ispell=\042ispell -d american\042^M"
macro compose _AX2 ":set ispell=\042ispell -d ngerman\042^M"
# 'Rotators'
macro compose _A00 ":macro compose \\260 \042:push 
\\042_A01\\042\\r\042^M_AX1_AX0"
macro compose _A01 ":macro compose \\260 \042:push 
\\042_A00\\042\\r\042^M_AX2_AX0"
#
# Default setting:
set ispell="ispell -d ngerman"
# startup ° rotating _A*
macro compose \260 ":push '_A00'^M"  "switch ispell language"
------------------------------------------------------------

First thing to know is, that I begin all the 'convoluted'
macros with an '_' underscore, and make them four chars long,
so I never hit them by accident.

The \260 is the little circle (degree '°'), which is above '^'
on my German Microsoft-Natural Keyboard.
To include a Doublequota in the Text of the macro I use \042.
And to include such a 'Definition by octal number' into the
Macro I have to double the Backslash.

To show the actual setting I 'appended' the extra macro '_AX0'

I already did the same thing for my 'index_format'
(about 10 different values) and a group of 12 'rotating' limits.

But those would need *very* long explanations to understand the
actual code-lines and are just logical extensions of the same idea.

The only extra idea was to create the 'default Action-Macro number _XX1'
by a folder hook, so the 'ring' of index-views can depend on the
actual folder mutt sees.

Hope that shows, what is possible with mutt, which has
no real 'programming' but ordinary textual macros.

Yours   Stucki

-- 
Christoph von Stuckrad     * * |nickname |<stucki@xxxxxxxxxxxxxxxxx>\
Freie Universitaet Berlin  |/_*|'stucki' |Tel(days):+49 30 838-75 459|
Fachbereich Mathematik, EDV|\ *|if online|Tel(else):+49 30 77 39 6600|
Arnimallee 2-6/14195 Berlin* * |on IRCnet|Fax(alle):+49 30 838-75454/