Skip to content

Commit ab5823a

Browse files
committed
Add automatic execution of the orphan lua file check, config and docs
1 parent 983e3e3 commit ab5823a

File tree

7 files changed

+60
-43
lines changed

7 files changed

+60
-43
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ fine!) will default to these values that should work fine for most people.
7676
;; Intended for users who wish to write shebang comments at the top of their .lua for easier execution.
7777
:header-comment true
7878
79+
;; Automatically invoke :NfnlFindOrphans whenever you write to a .fnl file. This acts as a passive garbage collection check and will warn you about dangling .lua files left over from .fnl deletions or renames.
80+
;; If an orphan is found, you can use :NfnlDeleteOrphans to delete all of the files listed automatically. This command will NOT prompt you, so make sure you check the list first!
81+
:find-orphan-lua-files true
82+
7983
;; Passed to fennel.compileString when your code is compiled.
8084
;; See https://fennel-lang.org/api for more information.
8185
:compiler-options {;; Disables ansi escape sequences in compiler output.

fnl/nfnl/api.fnl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@
99

1010
(local M (define :nfnl.api))
1111

12-
(fn M.find-orphans []
13-
"Find orphan Lua files that were compiled from a Fennel file that no longer exists. Display them with notify."
12+
(fn M.find-orphans [opts]
13+
"Find orphan Lua files that were compiled from a Fennel file that no longer exists. Display them with notify. Set opts.passive? to true if you don't want it to tell you that there are no orphans."
1414
(let [dir (vim.fn.getcwd)
1515
{: config : root-dir : cfg} (config.find-and-load dir)]
1616
(if config
1717
(let [orphan-files (gc.find-orphan-lua-files {: root-dir : cfg})]
1818
(if (core.empty? orphan-files)
19-
(notify.info "No orphan files detected.")
19+
(when (not (core.get opts :passive?))
20+
(notify.info "No orphan files detected."))
2021
(notify.warn
2122
"Orphan files detected, delete them with :NfnlDeleteOrphans.\n"
2223
(->> orphan-files

fnl/nfnl/callback.fnl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
: cfg
2323
:path (fs.full-path (. ev :file))
2424
:source (nvim.get-buf-content-as-string (. ev :buf))})
25+
26+
(when (cfg [:find-orphan-lua-files])
27+
(api.find-orphans {:passive? true}))
28+
2529
nil))
2630

2731
(fn supported-path? [file-path]

fnl/nfnl/config.fnl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464

6565
{:verbose false
6666
:header-comment true
67+
:find-orphan-lua-files true
6768
:compiler-options {:error-pinpoint false}
6869

6970
:root-dir root-dir

lua/nfnl/api.lua

Lines changed: 24 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lua/nfnl/callback.lua

Lines changed: 22 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lua/nfnl/config.lua

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)