Changes between Version 1 and Version 2 of MuttGuide/Macros


Ignore:
Timestamp:
Oct 27, 2013 6:01:25 PM (4 years ago)
Author:
MichaelRay
Comment:

wikiml fixes

Legend:

Unmodified
Added
Removed
Modified
  • MuttGuide/Macros

    v1 v2  
    1 == Macros, what is it all about? ==
     1== Macros, what are they all about? ==
    22This is a short introduction to writing macros. As you will see they are very handy and easy to use.
    33They are ''no programming language'' though. (even if since version 1.5.12 mutt allows you to define your own variables)
     
    2929: Sequence is just a concatenation of functions and commands. Just use the function names in <> brackets.
    3030: You simply write down what you would type in interactively.
    31 : Though you can use the bound keys too, that is <b>not recommended</b>! Function names are way more portable and readable.
     31: Though you can use the bound keys too, that is '''not recommended'''! Function names are way more portable and readable.
    3232: For example:
    33 :<pre>
     33:{{{
    3434macro index,pager <f1> "<shell-escape>less /usr/local/doc/mutt/manual.txt<enter>" "Show Mutt documentation"
    35 </pre>
     35}}}
    3636: Nothing special yet. Note that you can define a macro for more than one menu (comma no space). \
    3737You need to quote sequence if it contains spaces.
    38 :<pre>
     38:{{{
    3939macro index,pager <f1> "<enter-command>unset wait_key<enter><shell-escape>less /usr/local/doc/mutt/manual.txt<enter><enter-command>set wait_key<enter>" "Show Mutt documentation"
    40 </pre>
     40}}}
    4141: So here is an example of a more complex macro. It first unsets $wait_key, then runs less and sets $wait_key again.
    4242: You can see how to use commands.
    43 :<pre>
     43:{{{
    4444macro index <tag-prefix-cond><save-message>=foo<enter> "Save tagged messages (if any) to =foo"
    45 </pre>
     45}}}
    4646: No space in sequence, no quotes needed. This is an example where you might want a \
    4747[ask user for input here] function. Unfortunately that does not exist.
     
    5050== Special usage: applying to several tagged entries ==
    5151If you define a macro to work with a single entry,
    52 then '''it can not be applied to tagged entries just by using <tt><tag-prefix></tt>macro-key'''!!!
     52then '''it can not be applied to tagged entries just by using '''<tag-prefix>'''macro-key'''!!!
    5353That's because you must remember that macros are just a series of key-strikes you'd do normally,
    54 '''not a real built-in''' <function>, but tagging only works with real built-in <function>s.
     54'''not a real built-in''' <function>, but tagging only works with a real built-in <function>.
    5555
    5656If you want to use a macro with multiple entries, then you must define your macro right from the start to do so.
    57 I.e. '''prepend all your functions''' in your macro that should operate on tagged entries with <tt>tag-prefix</tt>.
     57I.e. '''prepend all your functions''' in your macro that should operate on tagged entries with '''tag-prefix'''.
    5858For example
    5959 macro index ,g '<pipe-entry>shell-cmd...<delete>...'
     
    6161 macro index ,g '<tag-prefix><pipe-entry>shell-cmd...<tag-prefix><delete>...'
    6262Now, such a macro operates on tagged entries by typing just
    63 ",g" and '''not''' "<tt><tag-prefix></tt>,g", because <tt><tag-prefix></tt> is already
     63",g" and '''not''' "'''<tag-prefix>''',g", because '''<tag-prefix>''' is already
    6464present in the macro definition.
    6565
    66 '''Alternatively''', if you don't like to clutter your macro with <tt><tag-prefix></tt>,
    67 you could make a macro which sets and resets <tt>auto_tag</tt> before executing your original macro:
     66'''Alternatively''', if you don't like to clutter your macro with '''<tag-prefix>''',
     67you could make a macro which sets and resets '''auto_tag''' before executing your original macro:
    6868 macro index ,A '<enter-command>set auto_tag=yes<enter>'
    6969 macro index ,g '<pipe-entry>shell-cmd...<delete>...'
     
    7272
    7373Note: Both solutions do '''also''' operate on a single selected entry if there are no tags!!!
    74 The <tt>auto_tag</tt> solution will not stop when there are no tags, it will
     74The '''auto_tag''' solution will not stop when there are no tags, it will
    7575apply the macro on the current entry, since ",g" remains a simple
    7676direct macro. If you want to avoid single operation for macros intended only for tagged operation,
    77 then use <tt><tag-prefix-cond>...<end-cond></tt> around every <function> called which needs it.
     77then use '''<tag-prefix-cond>...<end-cond>''' around every <function> called which needs it.
    7878See also /Actions about tagging for further clues.
    7979
     
    8383
    8484With the self-defined variables in mutt-1.5.12 and later you can save variable states before you change them:
    85 <pre>
     85{{{
    8686macro index,pager <f1> '<enter-command>set my_wait_key=$wait_key<enter><enter-command>unset wait_key<enter><shell-escape>less /usr/local/doc/mutt/manual.txt<enter><enter-command>set wait_key=$my_wait_key<enter>'
    87 </pre>
     87}}}
    8888This way you can simply restore the previous state and don't have to set an assumed value.
    8989This is even more useful with nonbool vars think $index_format or $from.
    9090
    9191Here's another example how to use self-defined variables:
    92 <pre>
     92{{{
    9393## spell checker
    9494set my_ispell="/usr/bin/aspell -c --mode=email --lang=en_GB"
     
    100100# german aspell
    101101macro compose I '<enter-command>set ispell=$my_german_ispell<enter><ispell><enter-command>set ispell=$my_ispell<enter>'
    102 </pre>
     102}}}