A fully-featured macro system for the nano editor, powered by Luajit.
Expose git root to meta
Document default macros
meta.helpers.call should capture stderr

refs

master
browse log

clone

read-only
https://git.sr.ht/~shakna/nam
read/write
git@git.sr.ht:~shakna/nam

You can also use your local clone with git send-email.

nam (nanoArgMode)

A fully-featured macro system for the nano editor, powered by Luajit.


Basic Usage

nano -s ./nam YOURFILE

Supply the location of nam to the -s flag, and open your file/s like normal. (Or an empty buffer.)

Then, write the macro call you want directly into the buffer, on it's own line:

!:spell

And then call the spellchecker with ^T or whatever non-default binding you've added.


Limitations

The macro system can only effect the open buffer, it can't modify nano's default behaviours. It cannot move the active cursor.

This turns it into a text-manipulation system, rather than a self-modifying system like you might find in vim and emacs.

It is still reasonably powerful.


Issues

See the issue tracker.

You don't need a user to post.


Extending

Metadata

Metadata can be utilied by macros.

It can be set by placing a file called .namrc in the Current Working Directory, git repository root, and ~/.namrc.

This file represents the contents of a Lua key-value table.

e.g.

wat = "Hello?",

is equivalent to:

return {wat = "Hello?",}

Macros

Place a file named .nam in the Current Working Directory or root of a git repository (for just this project), or at ~/.nam/.nam (to apply everywhere).

This file is expected to:

  • Return a table that contains two further tables:

    • A table called 'file' for file-scoped macros

      • Each macro is expected to take four arguments: source, arguments, meta, macros
        • Source is a string.
        • Arguments is an array-style 1-index table.
        • meta is a key-value data structure
        • macros is the same structure as the table being returned.
      • The macro must return the modified source in its entirety and must be a string
    • A table called 'inline' for line-scoped macros

      • Each macro is expected to take four arguments: line, arguments, meta, macros
        • Line is a string
        • Arguments is an array-style 1-index table.
        • meta is a key-value data structure
        • macros is the same structure as the table being returned.
      • The macro must return a line in its entirety, and must be a string

Builtin Macros

spell

The spell macro, calls a file with either 'aspell -c' or a string set in .namrc to the key 'spellcheck'.

build

The build macro looks for the meta key 'build'. It calls it with any supplied arguments, and captures the output.

Upon completion, the output is opened in a new nano instance, which can be closed to resume processing.

lint

The lint macro looks for the meta key 'lint'. It calls it with any supplied arguments, and captures the output.

Upon completion, the output is opened in a new nano instance, which can be closed to resume processing.

replace

The replace macro takes two arguments: The first is a pattern to supply to Luajit's gsub, and the second is the replacement.


License

Copyright 2019 James Milne

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

  3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.