Skip to content

Commit

Permalink
feat: support loading after directories (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcjkb authored Aug 23, 2024
1 parent c474b73 commit 5cb0cb7
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
7 changes: 7 additions & 0 deletions doc/rtp_nvim.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,11 @@ rtp_nvim.source_rtp_dir({dir}) *rtp_nvim.source_rtp_dir*
{dir} (string) The runtime directory to source


rtp_nvim.source_after_plugin_dir({dir}) *rtp_nvim.source_after_plugin_dir*
Source the `after` scripts

Parameters: ~
{dir} (string) The runtime directory to source


vim:tw=78:ts=8:noet:ft=help:norl:
12 changes: 12 additions & 0 deletions lua/rtp_nvim.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ local _sourced_ftdetect = {}
local RtpSourceDir = {
plugin = "plugin",
ftdetect = "ftdetect",
after_plugin = vim.fs.joinpath("after", "plugin"),
}

---Recursively iterate over a directory's children
Expand Down Expand Up @@ -77,11 +78,22 @@ local function source_ftdetect(dir)
end
end

---@param dir string
local function source_after_plugin(dir)
source(RtpSourceDir.after_plugin, dir)
end

---Source the `plugin` and `ftdetect` directories.
---@param dir string The runtime directory to source
function rtp_nvim.source_rtp_dir(dir)
source_plugin(dir)
source_ftdetect(dir)
end

---Source the `after` scripts
---@param dir string The runtime directory to source
function rtp_nvim.source_after_plugin_dir(dir)
source_after_plugin(dir)
end

return rtp_nvim
1 change: 1 addition & 0 deletions spec/fixtures/after/plugin/test_after_plugin.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
vim.g.test_after_plugin = (vim.g.test_after_plugin or 0) + 1
5 changes: 5 additions & 0 deletions spec/rtp_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@ describe("rtp_nvim", function()
it("sources plugin scripts multiple times and ftdetect scripts once", function()
assert.is_nil(vim.g.test_plugin)
assert.is_nil(vim.g.test_ftdetect)
assert.is_nil(vim.g.test_after_plugin)
rtp.source_rtp_dir(fixture_dir)
assert.same(1, vim.g.test_plugin)
assert.same(1, vim.g.test_ftdetect)
rtp.source_rtp_dir(fixture_dir)
assert.same(2, vim.g.test_plugin)
assert.same(1, vim.g.test_ftdetect)
rtp.source_after_plugin_dir(fixture_dir)
assert.same(1, vim.g.test_after_plugin)
rtp.source_after_plugin_dir(fixture_dir)
assert.same(2, vim.g.test_after_plugin)
end)
end)

0 comments on commit 5cb0cb7

Please sign in to comment.