Moonscript plugin support for neovim
This plugin adds support for writing moonscript plugins in Neovim
Install via vim-plug by adding this to your init.vim.
Plug 'svermeulen/nvim-moonmaker'
Then all you need to do is place .moon
files in a 'moon' directory inside any plugin directory that is on the vim &runtimepath
and they will automatically compiled and available to be loaded.
This follows the same convention that Vim uses for other file types. For example, if you place Foo.py
inside a directory named 'python3' (underneath the root directory of your plugin) then it can be loaded by executing :python3 import Foo
.
And similar rules apply to lua (that is, they are expected to be placed underneath a 'lua' directory). However, despite early plans to do so, direct MoonScript was never added to Neovim (hence this plugin).
So all this plugin really does is keep the lua directory in sync with the corresponding moon directory for every plugin on the runtimepath.
Compilation occurs at Neovim startup or whenever manually executed by one of the methods below. Note that it will only compile the moon files that are out of date (ie. those moon files with a greater file modification time then the corresponding lua file).
You can then use the lua require()
method to lazily load and call your lua code from vim script or from other moonscript/lua files.
See here for an simple example.
After editting your moon files, you can update them manually by any of the following methods:
:MoonCompile
<plug>(MoonCompile)
(eg: nmap <leader>cm <plug>(MoonCompile)
)moonmaker#compile()
from VimLAfter manually calling one of these, if any .moon
files in any plugin directory are out of date, they will be compiled. The require cache for each updated lua file will also be cleared so that the next time you call require you will get the latest version.
More things to be aware of:
:Moon
command. For example: :Moon print('hello')
or :Moon require('Foo').doThing!
moonc
executable needs to be on the PATH.require("dir1.dir2.filename")
to use them from other moonscript filesg:MoonMakerDeleteOrphanedLuaFiles
to 1
.g:MoonCompiler
variable. Otherwise it will use moonc
which is assumed to exist on the PATH