Skip to content

[FEATURE] Make close_unsupported_windows more flexible #513

Description

@chancez

Is your feature request related to a problem? Please describe.

Background: #173 (comment)

Basically, I've implemented saving my quickfix window in auto-session, and I've also tried to "remember" if the window was open or closed when saving the session so that when I restore the session the quickfix window is in the same state (open or closed) as when I closed neovim. However, this doesn't work when close_unsupported_windows = true (the default) because it closes the quickfix window before my save_extra_cmds can run.

Describe the solution you'd like
Either make it possible to specify certain windows to not close close_unsupported_windows is true, or maybe change the order in which the save_extra_cmds runs so that it runs before windows are closed.

Describe alternatives you've considered
I've set close_unsupported_windows = false but then I have other windows (eg: AI input panels) that get restored on session restore that I don't want restored.

Additional context

Here's my save_extra_cmds logic. Note the qf_open checks which handles re-opening the quickfix when the session is restored, if it was open when the session was saved:

-- Save quickfix list and open it when restoring the session
save_extra_cmds = {
  function()
    local qflist = vim.fn.getqflist()
    -- return nil to clear any old qflist
    if #qflist == 0 then
      return nil
    end
    local qfinfo = vim.fn.getqflist({ title = 1 })

    for _, entry in ipairs(qflist) do
      -- use filename instead of bufnr so it can be reloaded
      entry.filename = vim.api.nvim_buf_get_name(entry.bufnr)
      entry.bufnr = nil
    end

    local setqflist = "call setqflist(" .. vim.fn.string(qflist) .. ")"
    local setqfinfo = 'call setqflist([], "a", ' .. vim.fn.string(qfinfo) .. ")"

    local cmds = { setqflist, setqfinfo }
    -- Check if the quickfix is open in the current tab, and add a command to open it if it was
    local qf_open = vim.iter(vim.api.nvim_tabpage_list_wins(vim.api.nvim_get_current_tabpage())):any(function(w)
      return vim.fn.win_gettype(w) == "quickfix"
    end)
    if qf_open then
      table.insert(cmds, "bot copen")
    end
    return cmds
  end,
},

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions