Skip to content

Commit

Permalink
Extract config root from cwd instead of using scriptnames
Browse files Browse the repository at this point in the history
Breaking Change
  • Loading branch information
leiserfg committed Aug 16, 2022
1 parent 05e2e74 commit 0585c11
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions lua/luasnip/util/path.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,13 @@ function Path.read_file(path)
return buf
end

local MYCONFIG_ROOT = vim.env.MYVIMRC
-- if MYVIMRC is not set then it means nvim was called with -u
-- therefore the first script is the configuration
-- in case of calling -u NONE the plugin won't be loaded so we don't
-- have to handle that
local MYCONFIG_ROOT

if not MYCONFIG_ROOT then
MYCONFIG_ROOT = vim.fn.execute("scriptnames"):match("1: ([^\n]+)")
if vim.env.MYVIMRC then
MYCONFIG_ROOT = vim.fn.fnamemodify(vim.env.MYVIMRC, ":p:h")
else
MYCONFIG_ROOT = vim.fn.getcwd()
end
-- remove the filename of the script to optain where is it (most of the time it will be ~/.config/nvim/)

MYCONFIG_ROOT = MYCONFIG_ROOT:gsub(("%s[^%s]+$"):format(sep, sep), "")

function Path.expand(filepath)
local expanded =
Expand Down

10 comments on commit 0585c11

@bew
Copy link
Contributor

@bew bew commented on 0585c11 Aug 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So any use of multiple configs of neovim using nvim -u /path/to/config1.vim or nvim -u /path/to/config2.vim (not necessarily minimal configs, just 2 different ones, my main one could be one of them) will do what exactly?
What will stop working?

@L3MON4D3
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I've never seen this usage of -u, though @leiserfg tried to warn me, so that's on me 😬
We need the config-root for resolving ./ in paths passed to loaders.
If it's really necessary, we can probably figure out some way to still get accurate config-directories.

(not trying to diminish your point, just interested: What can multiple configs be used for?)

@bew
Copy link
Contributor

@bew bew commented on 0585c11 Aug 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have this usage currently but I'm considering it for my dev setup on NixOS, where I'd like:

  • keep an always-working config (could be minimal, or not, like pointing to an older revision of my configs), using nvim -u /path/to/old-configs/init.vim
  • have my current config using usual configs in ~/.config/nvim
  • and maybe have other configs like a 'my-next-gen-config' with stuff I'm working on (in a branch, pointing to some git worktree) but don't want to include in my normal config yet
  • and maybe some more dedicated alternative neovim configs for special workflows, that I may not want to include in usual config (for example, using neovim as a base for another tool)
  • (also, there is a Nix builder function to make on-the-fly nvim configuration that will AFAIK generate a binary that use nvim -u /path/to/generated/config.vim)

(I'm still thinking about uses, but that's the things I'm seeing as 'could be useful' 😃 )


note that I'm not impacted by the change for now, so take your time with fixing this if you want

@leiserfg
Copy link
Contributor Author

@leiserfg leiserfg commented on 0585c11 Aug 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I've never seen this usage of -u, though @leiserfg tried to warn me, so that's on me grimacing We need the config-root for resolving ./ in paths passed to loaders. If it's really necessary, we can probably figure out some way to still get accurate config-directories.

(not trying to diminish your point, just interested: What can multiple configs be used for?)

There is still a way to do it, but it's a bit more verbose:

env MYVIMRC=/tmp/config/init.lua  nvim -u $MYVIMRC

@bew
Copy link
Contributor

@bew bew commented on 0585c11 Aug 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

env MYVIMRC=/tmp/config/init.lua  nvim -u $MYVIMRC

That would work yeah, too bad there isn't a better way (or is there?)

@leiserfg
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only other way is to parse the args, that was my original pr.

@L3MON4D3
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have this usage currently but I'm considering it for my dev setup on NixOS, where I'd like:

  • keep an always-working config (could be minimal, or not, like pointing to an older revision of my configs), using nvim -u /path/to/old-configs/init.vim
  • have my current config using usual configs in ~/.config/nvim
  • and maybe have other configs like a 'my-next-gen-config' with stuff I'm working on (in a branch, pointing to some git worktree) but don't want to include in my normal config yet
  • and maybe some more dedicated alternative neovim configs for special workflows, that I may not want to include in usual config (for example, using neovim as a base for another tool)
  • (also, there is a Nix builder function to make on-the-fly nvim configuration that will AFAIK generate a binary that use nvim -u /path/to/generated/config.vim)

(I'm still thinking about uses, but that's the things I'm seeing as 'could be useful' smiley )

note that I'm not impacted by the change for now, so take your time with fixing this if you want

Good points 👍

I think setting $MYVIMRC manually is the correct approach as this directly makes up for nvim not setting $MYVIMRC when it's sourced via -u (which is a bit unexpected, but there's probably some reason for this not happening (or bug 🤷))

@leiserfg
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not initializing $MYVIMRC is intentional and documented, but I have no idea about the source of the intention.

@L3MON4D3
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yeah, ofc, my mind went to "that's a bug in the specification", but that doesn't make much sense xD

@leiserfg
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yeah, ofc, my mind went to "that's a bug in the specification", but that doesn't make much sense xD

Some friend of Bram Moolenaar is using it to heat his home.

Please sign in to comment.