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

Should preserve window-layout when closing non-floating terminal buffer window. #23

Closed
nyngwang opened this issue Mar 31, 2023 · 2 comments
Labels

Comments

@nyngwang
Copy link
Owner

nyngwang commented Mar 31, 2023

Migrated from: nyngwang/NeoZoom.lua#78, since the title has nothing to do with it after the breaking change.

current progress
vim.api.nvim_create_autocmd({ 'TermOpen' }, {
  group = curfile_augroup,
  callback = function ()
    local buf_term = vim.api.nvim_get_current_buf()
    local buf_enter = vim.fn.bufnr('#')
    vim.api.nvim_set_current_buf(buf_enter)
    local view_enter = vim.fn.winsaveview()
    vim.api.nvim_set_current_buf(buf_term)
    vim.api.nvim_create_autocmd({ 'WinClosed' }, {
      buffer = buf_term,
      group = curfile_augroup,
      callback = function (args)
        if -- it's another buffer/win being closed.
          vim.api.nvim_get_current_buf() ~= args.buf
          or vim.api.nvim_win_get_config(0).relative ~= ''
        then return end

        vim.cmd('split')
        if vim.api.nvim_buf_is_valid(buf_enter) then
          vim.api.nvim_set_current_buf(buf_enter)
          vim.fn.winrestview(view_enter)
        else
          vim.api.nvim_set_current_buf(vim.api.nvim_create_buf(true, false))
        end
      end,
    })
  end,
})
nyngwang added a commit that referenced this issue Mar 31, 2023
@nyngwang nyngwang pinned this issue Mar 31, 2023
@nyngwang
Copy link
Owner Author

nyngwang commented Mar 31, 2023

Can remove the hotfix autocmd in 5e33b29 as long as the upstream issue neovim/neovim#5176 would be resolved by someone. To remove it, simply comment out the following line:

create_hotfix_autocmds()

@nyngwang
Copy link
Owner Author

Note: this is pinned because it should be resolved upstream.

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

No branches or pull requests

1 participant