|
| 1 | +--- |
| 2 | +title: Lua |
| 3 | +description: Embedded Lua Scripting |
| 4 | +since: 2017-04-14 |
| 5 | +status: devel |
| 6 | +--- |
| 7 | +{% raw %} |
| 8 | +<div class="chapter"> |
| 9 | + <div class="titlepage"> |
| 10 | + <div> |
| 11 | + <div> |
| 12 | + <h1 class="title"> |
| 13 | + <a id="feature/lua"></a>Lua</h1> |
| 14 | + </div> |
| 15 | + <div> |
| 16 | + <h3 class="subtitle"> |
| 17 | + <em>Embedded Lua Scripting</em> |
| 18 | + </h3> |
| 19 | + </div> |
| 20 | + </div> |
| 21 | + </div> |
| 22 | + <div class="sect1"> |
| 23 | + <div class="titlepage"> |
| 24 | + <div> |
| 25 | + <div> |
| 26 | + <h2 class="title" style="clear: both"> |
| 27 | + <a id="support"></a>1. Support</h2> |
| 28 | + </div> |
| 29 | + </div> |
| 30 | + </div> |
| 31 | + <p> |
| 32 | + <span class="bold"> |
| 33 | + <strong>Since:</strong> |
| 34 | + </span>NeoMutt 2017-04-14</p> |
| 35 | + <p> |
| 36 | + <span class="bold"> |
| 37 | + <strong>Dependencies:</strong> |
| 38 | + </span>None</p> |
| 39 | + </div> |
| 40 | + <div class="sect1"> |
| 41 | + <div class="titlepage"> |
| 42 | + <div> |
| 43 | + <div> |
| 44 | + <h2 class="title" style="clear: both"> |
| 45 | + <a id="intro"></a>2. Introduction</h2> |
| 46 | + </div> |
| 47 | + </div> |
| 48 | + </div> |
| 49 | + <p>Lua is a simple scripting language that's frequently embedded into other programs, such as NeoVim. It allows users to cusotomise the behaviour of the host program.</p> |
| 50 | + <p>In NeoMutt, Lua can used to get/set config options and run commands.</p> |
| 51 | + </div> |
| 52 | + <div class="sect1"> |
| 53 | + <div class="titlepage"> |
| 54 | + <div> |
| 55 | + <div> |
| 56 | + <h2 class="title" style="clear: both"> |
| 57 | + <a id="commands"></a>3. Commands</h2> |
| 58 | + </div> |
| 59 | + </div> |
| 60 | + </div> |
| 61 | + <div class="cmdsynopsis"> |
| 62 | + <p> |
| 63 | + <code class="command">lua</code> |
| 64 | + <em class="replaceable"> |
| 65 | + <code>"lua-commands"</code> |
| 66 | + </em> |
| 67 | + </p> |
| 68 | + </div> |
| 69 | + <div class="cmdsynopsis"> |
| 70 | + <p> |
| 71 | + <code class="command">lua-source</code> |
| 72 | + <em class="replaceable"> |
| 73 | + <code>filename</code> |
| 74 | + </em> |
| 75 | + </p> |
| 76 | + </div> |
| 77 | + </div> |
| 78 | + <div class="sect1"> |
| 79 | + <div class="titlepage"> |
| 80 | + <div> |
| 81 | + <div> |
| 82 | + <h2 class="title" style="clear: both"> |
| 83 | + <a id="usage"></a>4. Usage</h2> |
| 84 | + </div> |
| 85 | + </div> |
| 86 | + </div> |
| 87 | + <p>A simple example of running some Lua commands in NeoMutt.</p> |
| 88 | + <pre class="screen"> |
| 89 | +<span class="comment"># In NeoMutt, make the Sidebar wider</span> |
| 90 | +:lua "local x = mutt.get('sidebar_width'); x = x + 5; mutt.set('sidebar_width', x)" |
| 91 | +</pre> |
| 92 | + <p>Next, create a script for easier reuse.</p> |
| 93 | + <p>Create a local Lua script, |
| 94 | + <code class="literal">sw.lua</code></p> |
| 95 | + <pre class="screen"> |
| 96 | +<span class="comment">-- Make the sidebar wider</span> |
| 97 | +function sw() |
| 98 | + local width = mutt.get('sidebar_width') |
| 99 | + width = width + 5 |
| 100 | + mutt.set('sidebar_width', width) |
| 101 | +end |
| 102 | +</pre> |
| 103 | + <p>Alter your NeoMutt config to add:</p> |
| 104 | + <pre class="screen"> |
| 105 | +<span class="comment"># Load the script once</span> |
| 106 | +lua-source "sw.lua" |
| 107 | + |
| 108 | +<span class="comment"># Create a binding to run the function in the script</span> |
| 109 | +macro index <F1> "<enter-command>lua 'sw()'<enter> |
| 110 | +</pre> |
| 111 | + </div> |
| 112 | + <div class="sect1"> |
| 113 | + <div class="titlepage"> |
| 114 | + <div> |
| 115 | + <div> |
| 116 | + <h2 class="title" style="clear: both"> |
| 117 | + <a id="limitations"></a>5. Limitations</h2> |
| 118 | + </div> |
| 119 | + </div> |
| 120 | + </div> |
| 121 | + <p>Currently, the Lua Scripting is very limited. It doesn't have any way to interact with the objects within NeoMutt: the Mailboxes, the Emails, etc. Beyond that, there's almost zero documentation.</p> |
| 122 | + <p>This state is changing. There is some new work coming to NeoMutt that exposes the Accounts, Mailboxes and Emails to Lua. This would allow the user to perform meaningful actions.</p> |
| 123 | + <p>See: |
| 124 | + <a class="ulink" href="https://github.com/neomutt/neomutt/pull/4707" target="_top">https://github.com/neomutt/neomutt/pull/4707</a></p> |
| 125 | + </div> |
| 126 | + <div class="sect1"> |
| 127 | + <div class="titlepage"> |
| 128 | + <div> |
| 129 | + <div> |
| 130 | + <h2 class="title" style="clear: both"> |
| 131 | + <a id="credits"></a>6. Credits</h2> |
| 132 | + </div> |
| 133 | + </div> |
| 134 | + </div> |
| 135 | + <p>Richard Russon, Bernard Pratz, Rayford Shireman, Darshit Shah</p> |
| 136 | + </div> |
| 137 | +</div> |
| 138 | +{% endraw %} |
0 commit comments