Skip to content

bug(terminal): TermClose Auto Command doesn't propagate #2944

Description

@RVxLab

Did you check docs and existing issues?

  • I have read all the snacks.nvim docs
  • I have updated the plugin to the latest version before submitting this issue
  • I have searched the existing issues of snacks.nvim
  • I have searched the existing issues of plugins related to this issue

Neovim version (nvim -v)

v0.12.5

Operating system/version

MacOS 26.5.2

Describe the bug

During beta testing of https://github.com/nvim-mini/mini.statuscolumn I found that when closing Lazygit, terminal and presumably other windows created through Snacks.win() with auto_close set to true causes the TermClose auto command being registered to eat other auto commands.

In case of mini.statuscolumn, it fails to reset the dimming when a buffer regains focus.

Echasnovski was able to reproduce it and pin-point it to a missing nested option in the registration of the TermClose auto command:

end, { buf = true })

He found that by adding nested = true to the options when registering the auto command the issue resolved. I was able to replicate that when creating the repro.lua for this report.

I can imagine that adding nested = true to the auto command could have some weird consequences for user configurations, so I would imagine the fix for this to be allowing auto_close to be of type boolean|table.

Not setting auto_close or a boolean would retain its current behaviour. Setting it to a table could pass it to the auto command as options, or perhaps a property on the table could be passed (e.g. auto_close.opts). I'm not sure how you envision this could be done.

See nvim-mini/mini.nvim#2542 (comment) and nvim-mini/mini.nvim#2542 (comment) for details.

Steps To Reproduce

Given mapleader = " "

In repro.lua I added 4 keymaps for reproduction:

<leader>g1: Standard Lazygit opening through Snacks
<leader>g2: Lazygit opening with auto_close set to false, manual TermClose auto command registration
<leader>g3: Lazygit opening with auto_close set to false, manual TermClose auto command registration and nested set to true in options
<leader>t: Standard Lazygit terminal opening

  1. Create a new, empty, local git repo
  2. Create a file in it, any empty file will do
  3. Open the file using the repro.lua provided
  4. Note that the status column is properly lit up
  5. Press <leader>g1, then q
  6. The status column is dimmed
  7. :restart
  8. Press <leader>g2, then q
  9. The status column is dimmed
  10. :restart
  11. Press <leader>g3, then q
  12. The status column regains its highlights
  13. :restart
  14. Press <leader>t, then <c-d>
  15. The status column is dimmed

Expected Behavior

When using the default Snacks.lazygit.open call, the status column should retain its highlight when a terminal is closed.

Repro

vim.g.mapleader = " "
vim.o.signcolumn = "yes"
vim.o.cursorline = true
vim.o.number = true

vim.env.LAZY_STDPATH = ".repro"
load(vim.fn.system("curl -s https://raw.githubusercontent.com/folke/lazy.nvim/main/bootstrap.lua"))()

require("lazy.minit").repro({
    spec = {
        {
            "folke/snacks.nvim",
            opts = {},
            keys = {
                {
                    "<leader>g1",
                    function()
                        require("snacks").lazygit.open()
                    end,
                },
                {
                    "<leader>g2",
                    function()
                        local terminal = require("snacks").lazygit.open({
                            auto_close = false,
                        })

                        terminal:on("TermClose", function()
                            terminal:close()
                            vim.cmd.checktime()
                        end, { buf = true })
                    end,
                },
                {
                    "<leader>g3",
                    function()
                        local terminal = require("snacks").lazygit.open({
                            auto_close = false,
                        })

                        terminal:on("TermClose", function()
                            terminal:close()
                            vim.cmd.checktime()
                        end, { buf = true, nested = true })
                    end,
                },
                {
                    "<leader>t",
                    function()
                        require("snacks").terminal.open()
                    end,
                },
            },
        },
        { "nvim-mini/mini.statuscolumn", opts = {} },
    },
})

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions