Skip to content

Commit

Permalink
Move compile-all-files to nfnl.api
Browse files Browse the repository at this point in the history
  • Loading branch information
Olical committed Nov 30, 2023
1 parent 979dbfc commit b8b1d2e
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 58 deletions.
49 changes: 31 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,24 +55,6 @@ You must commit the Lua into your configuration or plugin so that it can be
loaded by native Neovim Lua systems, with absolutely no knowledge of the Fennel
it originated from.

### Compiling all files

If you for whatever reason need to compile _all_ of your files to Lua at once
then you may do so by invoking the `compile-all-files` function like so.

```lua
require('nfnl')['compile-all-files']()
```

In the case where you're absolutely adamant that you need to `.gitignore` your
compiled Lua output, this can be used after you `git pull` to ensure everything
is compiled. I strongly advise committing your Lua for performance _and_
stability reasons however.

This project was designed around the principal of compiling early and then never
needing to compile again unless you make changes. I thought long and hard about
the tradeoffs so you don't have to.

## Configuration

nfnl is configured on a per directory basis using `.nfnl.fnl` files which also
Expand Down Expand Up @@ -331,6 +313,36 @@ just include this in your `.nfnl.fnl` configuration file for your project.
(default.fnl-path->lua-path (.. "some-other-dir/" rel-fnl-path))))}
```

### API

Although you can require any internal nfnl Lua module and call it's functions
([full index of internal modules and functions][apidoc]) there is a specific
module, `nfnl.api` ([documentation][api-module-doc]), that is designed to be
hooked up to your own functions, mappings and autocmds.

The functions within are designed to "do the right thing" with little to no
configuration. You shouldn't need them in normal use, but they may come in
useful when you need to fit nfnl into an interesting workflow or system.

As an example, here's how and why you'd use the `compile-all-files` function
from another Fennel file to, you guessed it, compile all of your files.

```fennel
(local nfnl (require :nfnl.api))
;; Takes an optional directory as an argument, defaults to (vim.fn.getcwd).
(nfnl.compile-all-files)
```

In the case where you're absolutely adamant that you need to `.gitignore` your
compiled Lua output, this can be used after you `git pull` to ensure everything
is compiled. However, I strongly advise committing your Lua for performance
_and_ stability.

This project was designed around the principal of compiling early and then never
needing to compile again unless you make changes. I thought long and hard about
the tradeoffs so you don't have to. These tools are here for when I'm wrong.

## Development

If you have nfnl installed in Neovim you should be able to just modify Fennel
Expand Down Expand Up @@ -409,3 +421,4 @@ experience.
[fd]: https://github.com/sharkdp/fd
[nfnl-plugin-example]: https://github.com/Olical/nfnl-plugin-example
[lua-in-git-justifications]: https://github.com/Olical/nfnl/issues/5#issuecomment-1655447175
[api-module-doc]: https://github.com/Olical/nfnl/blob/main/docs/api/nfnl/api.md
20 changes: 20 additions & 0 deletions docs/api/nfnl/api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Api.fnl

**Table of contents**

- [`compile-all-files`](#compile-all-files)

## `compile-all-files`
Function signature:

```
(compile-all-files dir)
```

Compiles all files in the given dir (optional), defaulting to the current working directory. Returns a sequential table with each of the files compilation result.

Will do nothing if you execute it on a directory that doesn't contain an nfnl configuration file.


<!-- Generated with Fenneldoc v1.0.1
https://gitlab.com/andreyorst/fenneldoc -->
10 changes: 0 additions & 10 deletions docs/api/nfnl/init.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,8 @@

**Table of contents**

- [`compile-all-files`](#compile-all-files)
- [`setup`](#setup)

## `compile-all-files`
Function signature:

```
(compile-all-files dir)
```

Compiles all files in the given directory, defaulting to the current working directory.

## `setup`
Function signature:

Expand Down
14 changes: 14 additions & 0 deletions fnl/nfnl/api.fnl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
(local {: autoload} (require :nfnl.module))
(local compile (autoload :nfnl.compile))
(local config (autoload :nfnl.config))

(fn compile-all-files [dir]
"Compiles all files in the given dir (optional), defaulting to the current working directory. Returns a sequential table with each of the files compilation result.
Will do nothing if you execute it on a directory that doesn't contain an nfnl configuration file."
(let [dir (or dir (vim.fn.getcwd))
{: config : root-dir : cfg} (config.find-and-load dir)]
(when config
(compile.all-files {: root-dir : cfg}))))

{: compile-all-files}
15 changes: 1 addition & 14 deletions fnl/nfnl/init.fnl
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
(local {: autoload} (require :nfnl.module))
(local compile (autoload :nfnl.compile))
(local config (autoload :nfnl.config))
(local notify (autoload :nfnl.notify))
(local callback (autoload :nfnl.callback))

(when vim
Expand All @@ -22,14 +19,4 @@
(fn setup []
"A noop for now, may be used one day. You just need to load this module for the plugin to initialise for now.")

(fn compile-all-files [dir]
"Compiles all files in the given directory, defaulting to the current working directory."

(local dir (or dir (vim.fn.getcwd)))
(let [{: config : root-dir : cfg} (config.find-and-load dir)]
(if config
(notify.info "Compilation complete.\n" (compile.all-files {: root-dir : cfg}))
(notify.warn "No .nfnl.fnl configuration found."))))

{: setup
: compile-all-files}
{: setup}
18 changes: 18 additions & 0 deletions lua/nfnl/api.lua

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 1 addition & 16 deletions lua/nfnl/init.lua

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b8b1d2e

Please sign in to comment.