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

feat: toggle intergrations #388

Open
sand4rt opened this issue Sep 2, 2024 · 3 comments
Open

feat: toggle intergrations #388

sand4rt opened this issue Sep 2, 2024 · 3 comments
Labels
question Further information is requested

Comments

@sand4rt
Copy link

sand4rt commented Sep 2, 2024

Describe the problem

Would it be possible for NNP to automatically close an integration when another one is opened on the same left/right position?

Describe the solution

  1. Enable NNP
  2. Open Neotree (or another any other integration)
  3. Open Undotree (or another any other integration)
  4. Neotree should be closed en Undotree should take the space of Neotree
@shortcuts
Copy link
Owner

Hey, I guess it could but that's a bit out of scope of the plugin, I assume a simple autocmd would be enough to do it, yet nnp should still behave correctly

@shortcuts shortcuts added the question Further information is requested label Sep 3, 2024
@sand4rt
Copy link
Author

sand4rt commented Sep 7, 2024

that's a bit out of scope of the plugin

I thought it didn't make much sense to have two integrations open on the same side.

a simple autocmd would be enough to do it

Thanks for the pointer! I'll give it a try with an autocmd. Feel free to close if this does not belong in NNP.

@sand4rt
Copy link
Author

sand4rt commented Sep 7, 2024

Its quite a bit of code to implement in user land, but this is what i have now. If anyone has suggestions for improvements, please let me know:

vim.api.nvim_create_autocmd("FileType", {
    pattern = {
        "neo-tree",
        "undotree",
        "neotest-summary",
        "dbui",
        -- "dapui_*" TODO: turn when this is resolved: https://github.com/rcarriga/nvim-dap-ui/issues/329
        "dapui_scopes",
    },
    callback = function()
         if vim.bo.filetype == "neo-tree" then
            pcall(vim.cmd.UndotreeHide)
            pcall(vim.cmd.DBUIClose)
        elseif vim.bo.filetype == "undotree" then
            vim.cmd("Neotree close")
            pcall(vim.cmd.DBUIClose)
            -- fixes undotree width: https://github.com/mbbill/undotree/issues/143
            vim.api.nvim_win_set_width(vim.api.nvim_get_current_win(), vim.g.undotree_SplitWidth)
        elseif vim.bo.filetype == "dbui" then
            vim.cmd("Neotree close")
            pcall(vim.cmd.UndotreeHide)
            -- fixes dap ui width
            vim.api.nvim_win_set_width(vim.api.nvim_get_current_win(), vim.g.db_ui_winwidth)
        elseif string.find(vim.bo.filetype, "^dapui") then
            pcall(function()
                vim.cmd("Neotest summary close")
            end)
        elseif vim.bo.filetype == "neotest-summary" then
            -- TODO: this only works once because of https://github.com/rcarriga/nvim-dap-ui/issues/397
            require("dapui").close()
        end
    end,
})

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

No branches or pull requests

2 participants