Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for original rtp #145

Open
nanpcdev opened this issue Dec 27, 2024 · 2 comments
Open

Support for original rtp #145

nanpcdev opened this issue Dec 27, 2024 · 2 comments

Comments

@nanpcdev
Copy link

I'm just wondering, cause I've tried to configure tangerine plugin to do this, couldn't understand even how to with nfnl (aniseed v2) and I think I'm seeing the possibility better with hotpot, but haven't been able to implement it yet (sorry, a bit noob).

Why is not possible just to compile to default rtp? aka .local/share/nvim/site/...
Also, I would like to separate everything as in rtp standard way. My plugins added with or without plugin manager go into /pack, my configurations in /plugin and my shareable stuff that I need to be able to require in different places in /lua (/fnl in my config dir, /lua in rtp).

Maybe it's easier than I've been able to see with hotpot (git gud noob) but if anyone can help me gittin gud I'd appreciate it :)

I don't know, adding new dirs to rtp seems to me kinda dirty without trying this first.

Nice plugin!!! and thanks in advance just for the time reading this :3

@rktjmp
Copy link
Owner

rktjmp commented Dec 28, 2024

You can do what you want with a .hotpot.lua file.

-- ~/.config/nvim/init.lua
local path_package = vim.fn.stdpath('data') .. '/site/'
local function ensure_installed(plugin, branch)
  local user, repo = string.match(plugin, "(.+)/(.+)")
  local repo_path = path_package .. 'pack/deps/start/' .. repo
  if not (vim.uv or vim.loop).fs_stat(repo_path) then
    vim.notify("Installing " .. plugin .. " " .. branch)
    local repo_url = "https://github.com/" .. plugin
    local out = vim.fn.system({
      "git",
      "clone",
      "--filter=blob:none",
      "--branch=" .. branch,
      repo_url,
      repo_path
    })
    if vim.v.shell_error ~= 0 then
      vim.api.nvim_echo({
        { "Failed to clone " .. plugin .. ":\n", "ErrorMsg" },
        { out, "WarningMsg" },
        { "\nPress any key to exit..." },
      }, true, {})
      vim.fn.getchar()
      os.exit(1)
    end
    vim.cmd('packadd ' .. repo .. ' | helptags ALL')
    vim.cmd('echo "Installed `' .. repo ..'`" | redraw')
  end
end

ensure_installed("echasnovski/mini.nvim", "stable")
ensure_installed("rktjmp/hotpot.nvim", "v0.14.6")

require("hotpot") -- Optionally you may call require("hotpot").setup(...) here

require("mini.deps").setup({path = {package = path_package}})
MiniDeps.add({source = "echasnovski/mini.nvim", checkout = "stable"})
MiniDeps.add({source = "rktjmp/hotpot.nvim", checkout = "v0.14.6"})
-- ~/.config/nvim/.hotpot.lua
local data_dir = vim.fn.stdpath("data")
-- setting this to /site/plugin/my_config or something might make it simpler to clean up
local config_in_data_dir = data_dir .. "/site/plugin/my_config/"

-- Important, .hotpot.lua only runs as a "build step" when you save a fnl file
-- in a dir with a .hotpot.lua file somewhere in its parent paths.
-- (eg: its intended use is for shipping plugin lua code, etc)
--
-- It will *not* effect files that are only compiled to the cache dir "just in
-- time" as they're loaded via lua's `require('module')` system.

return {
  -- See build docs
  -- https://github.com/rktjmp/hotpot.nvim/blob/main/COOKBOOK.md#build
  build = {
    {verbose = true, atomic = true},
    {"fnl/**/*macro*.fnl", false}, -- important, do not compile any macro files
    {"fnl/**/*.fnl", function(abs_path)
      -- TODO: adjust prefix regex to your own dir
      local target_path = string.gsub(abs_path, "^/root/.config/nvim/fnl/", config_in_data_dir)
      return target_path
    end}
  },
  -- see docs, set to a glob path to search for unknown lua files
  -- note: be careful you don't remove lua files you make yourself or other
  -- systems have created.
  -- https://github.com/rktjmp/hotpot.nvim/blob/main/COOKBOOK.md#clean
  clean = {
    {config_in_data_dir .. "**/*.lua", true}
  }
}
;; ~/.config/nvim/fnl/hello.fnl
(print :hello)

Note you must edit and save fnl/hello.fnl to make hotpot notice the .hotpot.lua file and build to your target, which means any fresh install may require opening the file and saving it, if you're not shipping your site/... dir to new machines etc.

You'll see a message showing the source and target paths when verbose = true, as included in this example.

@rktjmp
Copy link
Owner

rktjmp commented Dec 28, 2024

The above will get your files where you want (you may have to adjust paths to fit your own system), but AFAICT, neovim wont see these files as "lua modules" and just directly loads the source and executes it? They never end up in luas package.loaded table. It may not behave how you want in the future. I also tried my_config/lua to the same result.

This isn't really an explicitly supported use case of hotpot because its pretty uncommon. IMO either treat the lua files as "inconsequential build artefacts" and let hotpot build them as they're required and put them in the cache dir, or build ahead of time to your (imo, more portable) .config/nvim/lua dir and let the regular lua module loader take over.

In terms of "modifying the RTP", hotpot adds one path, pointing to the cache dir, which I think is pretty inconsequential and is done for you.

The install instructions for Lazy require adding an additional path because of how Lazy works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants