-
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
feat: support starting plugin with Leet cmd #51
Conversation
97b9a68
to
e623ed9
Compare
c9553b8
to
a315ff0
Compare
Just to be sure, you are fine with having to launch a new instance of neovim when using You could just check during the execution of This should make for _, buf_id in pairs(vim.api.nvim_list_bufs()) do
local bufinfo = vim.fn.getbufinfo(buf_id)
if bufinfo.listed == 1 and #bufinfo.windows > 0
...
end
end |
Yes, that's totally fine by me! I think the current behavior should stay the same, I don't want to break anyone's config or introduce unexpected behavior.
I initially thought this as well, but I think it's useful to have when launching with the cmd so that users can easily close the menu and all questions and return the user to their previous buffer: 2024-01-22.21-55-49.mp4
Good idea! I'll make sure to check for unlisted buffers and avoid creating a new window, though creating a separate scratch buffer for the menu is still a good idea imo to avoid affecting buffers manged by other plugins. Edit: Actually I don't think this is needed, since we do a full teardown of all windows when initializing the UI. Where do you think it's needed? Initializing from Alpha works fine for me, though it can't be automatically returned to when exiting because it shuts itself down on BufLeave. |
0e5a85e
to
124a269
Compare
Ok, so I think we should settle on launch from dashboard plugins being the only option apart from I think the best way to achieve this would be to have initial function leetcode.setup(cfg)
config.apply(cfg or {})
vim.api.nvim_create_user_command("Leet", require("leetcode.command").start_with_cmd, {
bar = true,
bang = true,
desc = "Open leetcode.nvim",
})
local group_id = vim.api.nvim_create_augroup("leetcode_start", { clear = true })
vim.api.nvim_create_autocmd("VimEnter", {
group = group_id,
pattern = "*",
nested = true,
callback = function() leetcode.start(true) end,
})
end Then in
for _, buf_id in pairs(vim.api.nvim_list_bufs()) do
local bufinfo = vim.fn.getbufinfo(buf_id)[1]
if bufinfo and (bufinfo.listed == 1 and #bufinfo.windows > 0) then --
return true
end
end And based on what |
Basically as long as you don't open any file it should work. 2024-01-23.15-36-20.mp4 |
I don't use dashboard plugins regularly... I don't see why that should be a requirement. It just adds more steps that are required before the plugin starts. The only thing required to integrate into an existing session is to perform a full teardown when leetcode is initialized - it works exactly like normal from there except for the different exit behavior, which could be removed.
That's basically what part of this PR does. The menu command starts the plugin the first time if it wasn't already started, and after that it just opens / returns to the menu.
Can definitely do this, but again I'm not sure why adding another requirement is necessary. I don't use dashboard plugins, I have Alpha installed but I rarely open it and I feel like I shouldn't need to open it just to open Leetcode.nvim...
This plugin is already quite complex so I don't see much detriment to not locking users into a specific workflow for the sake of avoiding complexity. I understand if that's the route you want to take though, no worries! I am happy to close this and use my changes on my fork :)
It does not, but I also don't use it regularly. |
You could try creating a plugin inside |
Sorry I'm not quite sure why that would solve this problem, could you elaborate? It's not a standalone module like the leetcode.cn module... |
It would just ensure that the original code base stays the same and the non standalone approach is loaded only when the plugin is enabled. So commands like For example I've commited the solution from my video into So now you could create a plugin that overrides those functions and adds a third condition
Then if someone also wants to use that approach they can just enable it inside plugin config. |
to do that you would need to load plugins before |
Ah, I see. I'll look into implementing the changes that way. |
Something like this ea579df. What's left is the |
Cool, sounds good! |
Looking at that though, I still think the menu needs to create and mange its own buffer. It is not reasonable to hijack a pre-existing file buffer. I think this is good practice for any plugin so should be good for standalone mode as well. Since you've implemented most of this as a plugin, I'll remove the extra stuff from this PR but keep the menu changes, if that works? |
It doesn't hijack a pre-existing file buffer. If neovim contains any listed buffers it creates a new tabpage with empty buffer and mounts menu there, otherwise it also creates a new buffer and does the same thing if not on_vimenter then --
if buflisted then
vim.cmd.tabe()
else
vim.cmd.enew()
end
end |
Ah, I didn't see that that was added. Why not just create a new scratch buffer? Also, the menu cannot be reopened after it was closed. |
124a269
to
a42f5fe
Compare
You mean why create a separate tabpage rather than a new buffer in both cases? Because tab pages guarantee a clean start without any existing buffers, so leetcode.nvim menu won't open in a split or something like that.
If you close it with |
Unmounting still has to be changed because it doesn't remove questions from Other than that i think it's working well, but since it's a niche usecase of this plugin imo, I'm not in a rush to marge this |
Sounds good, I'll look into unmounting. No worries, I'm happy to use this branch for however long is needed. |
Any updates on this? Seems like a useful feature! |
Haven't looked at this in a few weeks, not sure when I'll get back to it tbh. I'll handle the merge conflicts today, but if someone else wants to finish this up, feel free :) |
I will look into merging this tomorrow |
Awesome, thanks! |
@willothy can you check if |
e72d0ae
to
dbb11e3
Compare
dbb11e3
to
7286a7f
Compare
d7d83d1
to
dc623d2
Compare
15d75a9
to
d0407cf
Compare
Sorry, haven't been on github much in the past few days. I'll test this today :) |
@kawre seems to be working well for me! |
Still testing this, there may be edge cases I haven't found yet, but it seems to be working well.
Changes:
:Leet
/:Leet menu
now start the plugin if it wasn't already initialized.:Leet exit
, which behaves exactly like the exit button in the menushould_skip
always returns false if the plugin was initialized by the:Leet
command.I have updated the readme but am unable to update the CN docs :)
closes #50