Skip to content

Commit

Permalink
Merge pull request #21 from QuantumVim/7-feat-runtime-path-modificati…
Browse files Browse the repository at this point in the history
…ons-and-user-config-after-directory

7 feat runtime path modifications and user config after directory
  • Loading branch information
quantumfate authored Aug 21, 2023
2 parents 8a63e6d + eb4980c commit 0267ff3
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
10 changes: 10 additions & 0 deletions init.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
local base_dir = vim.env.QUANTUMVIM_RTP_DIR
or (function()
local init_path = debug.getinfo(1, "S").source
return init_path:sub(2):match("(.*[/\\])"):sub(1, -2)
end)()

if not vim.tbl_contains(vim.opt.rtp:get(), base_dir) then
vim.opt.rtp:prepend(base_dir)
end

vim.loader.enable()

require("qvim.bootstrap"):init()
Expand Down
56 changes: 56 additions & 0 deletions lua/qvim/bootstrap.lua
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ function M:init()
install_path = self.lazy_install_dir,
})

vim.opt.rtp = self:bootstrap()

require("qvim.config"):init()

return self
Expand All @@ -145,6 +147,60 @@ function M:setup()
require("qvim.core.plugins.mason").bootstrap()
end

--Modifies the runtimepath by removing standard paths from `vim.call("stdpath", what)` with `vim.fn.stdpath(what)`
---@param stds string[]|nil @default: { "config", "data" }
---@param expands string[][]|nil @default: { {}, { "site", "after" }, { "site" }, { "after" } }
---@return vim.opt.runtimepath
function M:bootstrap(stds, expands)
stds = stds or { "config", "data" }
expands = expands or { {}, { "site", "after" }, { "site" }, { "after" } }
---@type vim.opt.runtimepath
local rtp_paths = vim.opt.rtp:get()
local rtp = vim.opt.rtp

for _, what in ipairs(stds) do
for _, expand in ipairs(expands) do
if #expand == 0 then
if vim.tbl_contains(rtp_paths, vim.call("stdpath", what)) then
-- remove
rtp:remove(vim.call("stdpath", what))
end
if not vim.tbl_contains(rtp_paths, vim.fn.stdpath(what)) then
-- add
rtp:prepend(vim.fn.stdpath(what))
end
else
if
-- remove
vim.tbl_contains(
rtp_paths,
_G.join_paths(
vim.call("stdpath", what),
unpack(expand)
)
)
then
rtp:remove(_G.join_paths(
vim.call("stdpath", what),
unpack(expand)
))
end
if
not vim.tbl_contains(
rtp_paths,
_G.join_paths(vim.fn.stdpath(what), unpack(expand))
)
then
-- add
rtp:prepend(
_G.join_paths(vim.fn.stdpath(what), unpack(expand))
)
end
end
end
end
return rtp
end
---Update qvimVim
---pulls the latest changes from github and, resets the startup cache
function M:update()
Expand Down

0 comments on commit 0267ff3

Please sign in to comment.