-
Notifications
You must be signed in to change notification settings - Fork 34
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
FR: Allow ability to update existing named instances with prefills #165
Comments
i am guessing if we kill the instance with that name and recreate it, that would achieve the desired effect.
By trigger I assume you mean toggle_instance call, correct? |
Yep, killing and re-creating will work, should you will loose other prefills, but thats ok for my use case.
Correct toggle_instance is great, but options like focus_instance, close_instance, update_instance would be really cool as well. |
@choovick FYI, still needs unit tests, but I've added some API in #172
I did a quick test similar to what you have where each re-trigger increases a count that gets filled in and it seems to work: local count = 1
vim.keymap.set('n', '<leader>so', function()
local prefills = { search = 'something ' .. count }
if not grugFar.has_instance('far') then
grugFar.grug_far({
instanceName = 'far',
prefills = prefills,
})
else
grugFar.open_instance('far')
grugFar.update_instance_prefills('far', prefills, true)
end
count = count + 1
end) You can try the branch if you have time and let me know if you find any issue 😄 . I'll try to get to the tests soon... |
api looks good, i'll play around with it now and will report. |
Recording.at.2024-07-30.00.23.40.mp4vim.keymap.set("n", "z", function()
local node = lib.get_node_at_cursor()
local grugFar = require("grug-far")
if node then
-- get directory of current file if it's a file
local path
if node.type == "directory" then
-- Keep the full path for directories
path = node.absolute_path
else
-- Get the directory of the file
path = vim.fn.fnamemodify(node.absolute_path, ":h")
end
local prefills = {
paths = path,
}
if not grugFar.has_instance("tree") then
grugFar.grug_far({
instanceName = "tree",
prefills = prefills,
staticTitle = "Find and Replace from Tree",
})
else
grugFar.open_instance("tree")
-- updating the prefills without clearing the search
grugFar.update_instance_prefills("tree", prefills, false)
end
end
end, opts("Search in directory")) works like a charm! You need to slow down btw. Its not acceptable to have a repo with all issues addressed. |
great! Thanks for trying it out! |
it's merged now 😄 . local count = 1
local gfInstance
vim.keymap.set('n', '<leader>so', function()
local prefills = { search = 'something ' .. count }
if not grugFar.has_instance(gfInstance) then
gfInstance = grugFar.grug_far({ prefills = prefills })
else
grugFar.open_instance(gfInstance)
grugFar.update_instance_prefills(gfInstance, prefills, true)
end
count = count + 1
end) Anyways, just one small request if you get a chance, could you create a PR to add a prettified example of your more advanced usage to the Cookbook section of the README.md? |
@choovick btw, one last note, if you want to support paths with spaces in their names you need to do this in your code snippet above: path:sub(“ “, “\\ “) |
Yep, found that out pretty quickly! I will make PR for the README.md with my use case |
awesome, thanks! ❤️ |
Maybe pushing it but here it goes.
Use case: I would like to have a persistent single instance of grug-far, but I would like to change scope of the search from nvim-tree re-opening or re-triggering it updating prefills
Example:
Current behaviour:
on
grug_far
: A grug-far instance with instanceName="far" already exists!on
trigger
: Just triggers, but prefills are not updatedDesired:
on
grug_far
: buffer with instance name located, non empty prefills updated (this is basically a focus option as well)on
trigger
: tiggers, with prefills updatedThe text was updated successfully, but these errors were encountered: