Skip to content

Commit

Permalink
Files under the macro(s) directory are macros now
Browse files Browse the repository at this point in the history
  • Loading branch information
Oliver Caldwell committed Jan 7, 2023
1 parent 4501db6 commit a7445c3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
13 changes: 7 additions & 6 deletions fnl/aniseed/fs.fnl
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@
(set newer? true)))
newer?)

(defn macro-file-path? [path]
"Check if the path is a specially treated Aniseed / Fennel macros file.
We preserve these and don't try to compile them to Lua since you can't
do that."
(a.string? (string.match path "macros?.fnl$")))

(def path-sep
;; https://github.com/nvim-lua/plenary.nvim/blob/8bae2c1fadc9ed5bfcfb5ecbd0c0c4d7d40cb974/lua/plenary/path.lua#L20-L31
(let [os (string.lower jit.os)]
Expand All @@ -38,3 +32,10 @@
(= :bsd os))
"/"
"\\")))

(defn macro-file-path? [path]
"Check if the path is a specially treated Aniseed / Fennel macros file.
We preserve these and don't try to compile them to Lua since you can't
do that."
(or (a.string? (string.match path "macros?.fnl$"))
(a.string? (string.match path (.. path-sep "macros?" path-sep)))))
8 changes: 4 additions & 4 deletions lua/aniseed/fs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ local function glob_dir_newer_3f(a_dir, b_dir, expr, b_dir_path_fn)
return newer_3f
end
_2amodule_2a["glob-dir-newer?"] = glob_dir_newer_3f
local function macro_file_path_3f(path)
return a["string?"](string.match(path, "macros?.fnl$"))
end
_2amodule_2a["macro-file-path?"] = macro_file_path_3f
local path_sep
do
local os = string.lower(jit.os)
Expand All @@ -55,4 +51,8 @@ do
end
end
_2amodule_2a["path-sep"] = path_sep
local function macro_file_path_3f(path)
return (a["string?"](string.match(path, "macros?.fnl$")) or a["string?"](string.match(path, (path_sep .. "macros?" .. path_sep))))
end
_2amodule_2a["macro-file-path?"] = macro_file_path_3f
return _2amodule_2a
6 changes: 5 additions & 1 deletion test/fnl/aniseed/fs-test.fnl
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,8 @@
(t.= true (fs.macro-file-path? "macro.fnl"))
(t.= false (fs.macro-file-path? "macron.fnl"))
(t.= false (fs.macro-file-path? "macro-thing.fnl"))
(t.= false (fs.macro-file-path? "macros-things.fnl")))
(t.= false (fs.macro-file-path? "macros-things.fnl"))

(t.= true (fs.macro-file-path? "foo/macros/bar.fnl"))
(t.= true (fs.macro-file-path? "foo/macro/bar.fnl"))
(t.= false (fs.macro-file-path? "foo/macroscopic/bar.fnl")))

0 comments on commit a7445c3

Please sign in to comment.