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

[WIP][RFC] Open tmp window: handle case where tmp window is prev window #488

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions lua/orgmode/utils/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -536,10 +536,12 @@ end

function utils.open_tmp_org_window(height, split_mode, on_close)
local winnr = vim.api.nvim_get_current_win()
local bufnr = vim.api.nvim_get_current_buf()
utils.open_window(vim.fn.tempname(), height or 16, split_mode)
vim.cmd([[setf org]])
vim.cmd([[setlocal bufhidden=wipe nobuflisted nolist noswapfile nofoldenable]])
vim.api.nvim_buf_set_var(0, 'org_prev_window', winnr)
vim.api.nvim_buf_set_var(0, 'org_prev_buffer', bufnr)

if on_close then
vim.api.nvim_create_autocmd('BufWipeout', {
Expand All @@ -559,9 +561,16 @@ function utils.open_tmp_org_window(height, split_mode, on_close)
return function()
vim.api.nvim_create_augroup('OrgTmpWindow', { clear = true })
local prev_winnr = vim.api.nvim_buf_get_var(0, 'org_prev_window')
vim.api.nvim_win_close(0, true)
if prev_winnr and vim.api.nvim_win_is_valid(prev_winnr) then
vim.api.nvim_set_current_win(prev_winnr)
if prev_winnr ~= vim.api.nvim_get_current_win() then
vim.api.nvim_win_close(0, true)
if prev_winnr and vim.api.nvim_win_is_valid(prev_winnr) then
vim.api.nvim_set_current_win(prev_winnr)
end
else
local prev_bufnr = vim.api.nvim_buf_get_var(0, 'org_prev_buffer')
if prev_bufnr and vim.api.nvim_buf_is_valid(prev_bufnr) then
vim.api.nvim_set_current_buf(prev_bufnr)
end
end
end
end
Expand Down