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

Sharing gF with the world #1

Open
mightyiam opened this issue Nov 5, 2024 · 5 comments
Open

Sharing gF with the world #1

mightyiam opened this issue Nov 5, 2024 · 5 comments

Comments

@mightyiam
Copy link

{
key = "gF";
action = mkRaw ''
function()
local target_path = vim.fn.expand('<cfile>')
local path
if target_path:sub(1, 1) == "." then
local current_file = vim.fn.expand('%:p')
local cwd = vim.fn.fnamemodify(current_file, ':h')
local target_absolute = vim.fn.resolve(cwd .. '/' .. target_path)
path = vim.fn.fnamemodify(target_absolute, ':.')
else
path = target_path
end
vim.cmd('edit ' .. vim.fn.fnameescape(vim.fn.expand(path)))
end
'';
options.noremap = true;
}

Is there really no plugin that provides this kind of feature?

@jfly
Copy link
Owner

jfly commented Nov 5, 2024

I haven't found anything.

@mightyiam
Copy link
Author

neovim/neovim#31087

@mightyiam
Copy link
Author

Nvim don't want it. Do you think there's a potential plugin here?

@jfly
Copy link
Owner

jfly commented Nov 5, 2024

Sure! Either it's useful for people, or someone tells us about an existing plugin.

This piece of my config feels related:

{
desc = "When creating a new file in a Nix Flake, create it with --intent-to-add";
event = "BufWritePre";
callback = mkRaw ''
function(args)
local file = args.file
local function in_git_repo()
local cp = vim.system({'git', 'rev-parse', '--is-inside-work-tree'}):wait()
return cp.stdout == "true\n"
end
local is_new_file = vim.fn.filereadable(file) == 0
if is_new_file and in_git_repo() then
vim.fn.writefile({}, file)
local cmd = {'git', 'add', '--intent-to-add', file}
local cp = vim.system(cmd):wait()
if cp.code ~= 0 then
vim.notify("Failed to run: " .. table.concat(cmd, " "), vim.log.levels.ERROR)
else
vim.notify("Marked new file with git --intent-to-add", vim.log.levels.INFO)
end
end
end
'';
}
. I could imagine a version of it that would be reasonable to put in the same plugin (perhaps a configurable "should I git add --intent-to-add this file" predicate)?

@mightyiam
Copy link
Author

I imagine a 'better-gf.nvim' plugin, with scope limited to improving upon the default gf/gF action:

  • better path resolution
    • (does LSP offer module resolution API?)
    • support omitted extensions
  • open buffer and set path (I'm guessing that's a thing) if nonexistent
  • open file explorer thingy when path to directory (or even language specific, such as default.nix.

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