[neomutt-users] Neomutt: now featuring Lua scripting!

Guyzmo z+mutt+neomutt at m0g.net
Fri Apr 28 13:26:06 CEST 2017

On Fri, Apr 28, 2017 at 03:31:12AM +0200, Floyd Anderson wrote:
> On Fr, 28 Apr Guyzmo <z+mutt+neomutt at m0g.net> wrote:
> I have a question about this. Will it be mandatory to mixing ‘normal’
> {,Neo}mutt configuration directives with Lua code or can both be placed
> in separated files and sourced from there? That probably would prevent (new)
> user from getting confused, I think.

well yes! as said in the first post of this thread you can either call Lua
commands from Neomuttrc (or the `enter-command` line) by prefixing Lua code
with the Neomuttrc `lua` command…

Or you can source a lua script, within the context of Neomutt's Lua
runtime using the `lua-source path/to/source-file.lua` command.

The way I see this is that you can write some algorithms to modify your
configuration dynamically in a Lua source file, source it, and then you
can bind it using a macro.

function do_stuff(thing);
    mutt.message("doing stuff with " .. thing .. " ;) " ) ;

lua-source sourcefile.lua
lua do_stuff("a muttrc command at startup")
macro generic z :lua do_stuff("a macro bound to the key z")

> The reason behind this is, as I came to Lua due to my former favourite
> editor SciTE [1], I was glad to separate normal statically (treated as
> default) configuration from Lua scripting and to know which is which by
> using a simple startup script declaration [2].

Also, to make it a bit more comfortable to mix Muttrc and lua code, I'd
like to add to the Neomuttrc parser a syntax (inspired by vim's) like:

lua << EOS
function fubar()
  mutt.message("This is some multiline lua code")

macro generic z :lua fubar()

> This way it was also possible to implement a global table (as a normal user)
> which realised a pseudo object-oriented programming syntax within
> additionally Lua scripts due to the require() statement. And using the
> several exposed events from SciTE — that was fun pure.

require statements are supported, if you look at the resources link I
attached, I'm using a luarocks library (busted) to run integration tests
on the API wrote in Lua, testing the Lua API.

> I’m sure I will when I found the way how to compile, install and testing
> Neomutt without influencing my existing ‘old dog’. ;-)

that's easy:

wget https://github.com/neomutt/neomutt/archive/neomutt-20170421.tar.gz
tar xvzf neomutt-20170421.tar.gz
cd neomutt-neomutt-20170421
# I like to keep the compilation output in a separate directory
mkdir build
# build all stable features, plus lua, and skip all doc and i18n
../configure --enable-everything --enable-lua --disable-doc --disable-po --disable-full-doc



More information about the neomutt-users mailing list