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

Untint forcibly closed windows #41

Closed
wants to merge 2 commits into from

Conversation

levouh
Copy link
Owner

@levouh levouh commented Mar 3, 2023

Fix #38

@akinsho
Copy link
Contributor

akinsho commented Mar 3, 2023

@levouh just gave this a try and don't think it made a difference as far as I can tell 🤔

@levouh
Copy link
Owner Author

levouh commented Mar 3, 2023

Sounds good @akinsho, I will do some actual testing later when I can. I imagine it is an issue with the second commit, but I'll double check.

@levouh
Copy link
Owner Author

levouh commented Mar 3, 2023

@akinsho it fails for me on master, and works for me on this branch with:

local opts = { plugins = true, dir = "/tmp/nvim-test" }

vim.opt.runtimepath:remove(vim.fn.stdpath("config"))
vim.opt.packpath:remove(vim.fn.stdpath("data") .. "/site")
vim.opt.runtimepath:append(vim.fn.expand(opts.dir))
vim.opt.packpath:append(vim.fn.expand(opts.dir))
vim.opt.termguicolors = true

local function install_packer()
  local install_path = opts.dir .. "/pack/packer/start/packer.nvim"
  if vim.fn.empty(vim.fn.glob(install_path)) > 0 then
    vim.cmd("!git clone https://github.com/wbthomason/packer.nvim " .. install_path)
    vim.cmd("packadd packer.nvim")
  end

  local packer = require("packer")

  packer.init({
    package_root = opts.dir .. "/pack",
    compile_path = opts.dir .. "/plugin/packer_compiled.lua",
  })

  return packer
end

local function chain(funcs, delay)
  delay = delay or 1500

  local defer = delay
  for _, func in ipairs(funcs) do
    vim.defer_fn(func, defer)
    defer = defer + delay
  end
end

local function init()
  chain({
    function()
      vim.cmd("top new | wincmd o")
    end,
    function()
      vim.cmd("Neotree")
    end,
    function()
      vim.api.nvim_feedkeys("q", "m", true)
    end,
  })
end

local function setup_plugins(packer)
  packer.startup(function(use)
    use("wbthomason/packer.nvim")

    use("MunifTanjim/nui.nvim")
    use("nvim-lua/plenary.nvim")
    use("nvim-tree/nvim-web-devicons")

    use({
      "levouh/tint.nvim",
      -- branch = "untint-forcibly-closed-windows",
      config = function()
        require("tint").setup({})
      end,
    })

    use({
      "nvim-neo-tree/neo-tree.nvim",
      cmd = { "Neotree" },
      config = function()
        require("neo-tree").setup({})
      end,
    })

    vim.api.nvim_create_autocmd({ "User" }, {
      pattern = { "PackerComplete" },
      callback = function()
        init()
      end,
    })

    packer.sync()
  end)
end

local function main()
  if opts.plugins then
    setup_plugins(install_packer())
  end
end

main()

Can you try with the "minimal reproduction" configuration above and verify? Hard to accommodate for anything outside of the minimal case in terms of fixing stuff, unless the culprit is something else obvious.

The way the above is setup, it will just operate in /tmp/nvim-test. You can nuke that directory when you are done, and everything is gone so it should be relatively "non-committal".

@akinsho
Copy link
Contributor

akinsho commented Mar 4, 2023

@levouh so I tried out the minimal init as well as my local config and could confirm that the PR works. The reason I couldn't get it to work in the first place with my config is that I use a window_ignore_function to try to ignore tinting windows based on their filetype rather than highlight groups (since then I have to depend on a long list of highlight names from a plugin rather than just saying never tint neo-tree because I always want to be able to see my file explorer).

The function looks like

      window_ignore_function = function(win_id)
        local win, buf = vim.wo[win_id], vim.bo[vim.api.nvim_win_get_buf(win_id)]
        if win.diff or not as.empty(fn.win_gettype(win_id)) then return true end
        local ignore_bt = { terminal = true, prompt = true, nofile = true }
        local ignore_ft = {
          ['neo-tree'] = true,
          ['toggleterm'] = true,
          ['qf'] = true,
        }
        local has_bt, has_ft = ignore_bt[buf.buftype], ignore_ft[buf.filetype]
        return has_bt or has_ft
      end,

I'm not sure when this window ignore function runs or how it works but it seems to stop tinting from being cancelled when leaving the neo-tree window as well as the original bug

@williamboman
Copy link
Contributor

I'm experiencing the same with neotest. FWIW I'm not sure this is something tint.nvim should try to work around, but instead these plugins should be closing windows "properly". I was able to locate the issue with neotest, it seems to boil down to the fact that they force delete the floating buffer in a WinEnter autocmd, which I guess causes WinLeave to never fire because the floating window gets disposed at the same time.

I believe the better option would be to utilize the 'bufhidden' option (setting it to wipe). I'll submit a PR to them 🤷‍♂️

@levouh
Copy link
Owner Author

levouh commented Aug 25, 2023

@akinsho @williamboman many months later - 😄

You guy see any reason to not merge this (beyond needing to fix some formatting/linting stuff)? I'm not sure if you guys actively use this branch (or even plugin anymore), but I have not run into any issues with this branch as my primary.

I agree generally about plugins needing to fix how they are closing windows, but I imagine it is largely just easier to try to handle things "appropriately" (within reason) here.

@williamboman
Copy link
Contributor

@levouh I do still run into a lot of issues with window remaining tinted, I've sort of gotten used to it now. I think it makes sense to patch it here as much as it's possible. I've only tested this branch just now but it already fixes one of the most occurring issues I'm having, so that's nice 👍

@levouh
Copy link
Owner Author

levouh commented Aug 28, 2023

Closing this, see #48 for an updated version.

@levouh levouh closed this Aug 28, 2023
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

Successfully merging this pull request may close these issues.

issue when using with neo-tree float window
3 participants