omit netrw from saved sessions
This commit is contained in:
parent
4a721f051e
commit
bf39cd1ecd
4 changed files with 76 additions and 0 deletions
1
LOG.md
1
LOG.md
|
|
@ -220,6 +220,7 @@ Record every decision here with a short rationale. Append new entries; do not re
|
||||||
- 2026-10-28: Made netrw file previews intentionally plain after CSS and HTML exposed residual colour. The remaining decoration was Vim regex syntax plus indent-blankline extmarks, not diagnostics or Tree-sitter. Preview buffers now clear `syntax` and disable their buffer-local indent guides, then restore both recorded states on real edit.
|
- 2026-10-28: Made netrw file previews intentionally plain after CSS and HTML exposed residual colour. The remaining decoration was Vim regex syntax plus indent-blankline extmarks, not diagnostics or Tree-sitter. Preview buffers now clear `syntax` and disable their buffer-local indent guides, then restore both recorded states on real edit.
|
||||||
- 2026-10-28: Added buffer-local netrw `<M-j>` / `<M-k>` mappings to scroll the current preview with native `<C-e>` / `<C-y>` behavior while focus remains in the tree. The mappings accept Vim counts and quietly do nothing when no preview exists.
|
- 2026-10-28: Added buffer-local netrw `<M-j>` / `<M-k>` mappings to scroll the current preview with native `<C-e>` / `<C-y>` behavior while focus remains in the tree. The mappings accept Vim counts and quietly do nothing when no preview exists.
|
||||||
- 2026-10-28: Hardened preview scrolling after an interactive over-scroll surfaced a window-local error that did not reproduce headlessly. The temporary preview-window call is now protected, so stale-window and boundary failures are treated like native top/bottom clamping instead of reaching the command line.
|
- 2026-10-28: Hardened preview scrolling after an interactive over-scroll surfaced a window-local error that did not reproduce headlessly. The temporary preview-window call is now protected, so stale-window and boundary failures are treated like native top/bottom clamping instead of reaching the command line.
|
||||||
|
- 2026-10-28: Excluded netrw from automatic session persistence after `:mksession` serialized its generated `NetrwTreeListing` name and restored an empty explorer buffer. Before the existing exit-time save, preview windows and netrw windows are removed; a netrw-only tab is dropped, while the sole remaining netrw window is replaced with an ordinary file buffer or a blank fallback. Netrw is intentionally not rebuilt on load.
|
||||||
|
|
||||||
## Project-Local Configuration
|
## Project-Local Configuration
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -500,6 +500,7 @@ Source of truth for the step-by-step rebuild. Keep this concise and up to date.
|
||||||
## Phase 12.6 — Final polish
|
## Phase 12.6 — Final polish
|
||||||
- [x] Review all keymaps and ensure they're documented (README.md + :KeymapsGuide)
|
- [x] Review all keymaps and ensure they're documented (README.md + :KeymapsGuide)
|
||||||
- [x] Update LOG.md with final architecture and usage
|
- [x] Update LOG.md with final architecture and usage
|
||||||
|
- [x] Omit transient netrw and preview windows from automatic session saves
|
||||||
- [ ] Clean up any remaining debug code or temporary comments
|
- [ ] Clean up any remaining debug code or temporary comments
|
||||||
|
|
||||||
## Phase 13 — Controlled Neovim 0.12 Upgrade
|
## Phase 13 — Controlled Neovim 0.12 Upgrade
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ Session support is automatic but user-controlled:
|
||||||
**Auto-load/save** (via `lua/autocmds.lua`):
|
**Auto-load/save** (via `lua/autocmds.lua`):
|
||||||
- On startup: auto-loads `Session.vim` if it exists (unless files specified on command line)
|
- On startup: auto-loads `Session.vim` if it exists (unless files specified on command line)
|
||||||
- On exit: auto-saves to `Session.vim` if it already exists
|
- On exit: auto-saves to `Session.vim` if it already exists
|
||||||
|
- Netrw and its preview windows are omitted from the saved layout; generated `NetrwTreeListing` buffers are not restorable
|
||||||
- Sessions are per-directory and opt-in (just create one to start using)
|
- Sessions are per-directory and opt-in (just create one to start using)
|
||||||
|
|
||||||
**Stop using a session**:
|
**Stop using a session**:
|
||||||
|
|
|
||||||
|
|
@ -137,6 +137,78 @@ vim.api.nvim_create_autocmd("SessionLoadPost", {
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
local function is_netrw_session_buffer(buf)
|
||||||
|
return vim.api.nvim_buf_is_valid(buf)
|
||||||
|
and (vim.bo[buf].filetype == "netrw" or vim.api.nvim_buf_get_name(buf):match("NetrwTreeListing$") ~= nil)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function session_fallback_buffer()
|
||||||
|
for _, buf in ipairs(vim.api.nvim_list_bufs()) do
|
||||||
|
if
|
||||||
|
vim.api.nvim_buf_is_valid(buf)
|
||||||
|
and vim.bo[buf].buflisted
|
||||||
|
and vim.bo[buf].buftype == ""
|
||||||
|
and vim.api.nvim_buf_get_name(buf) ~= ""
|
||||||
|
and not is_netrw_session_buffer(buf)
|
||||||
|
then
|
||||||
|
return buf
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return vim.api.nvim_create_buf(true, false)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function close_session_tab(tab)
|
||||||
|
if vim.api.nvim_tabpage_close then
|
||||||
|
pcall(vim.api.nvim_tabpage_close, tab, true)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
pcall(function()
|
||||||
|
vim.api.nvim_set_current_tabpage(tab)
|
||||||
|
vim.cmd("tabclose!")
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function omit_netrw_from_session()
|
||||||
|
local tabs_with_netrw = {}
|
||||||
|
for _, tab in ipairs(vim.api.nvim_list_tabpages()) do
|
||||||
|
for _, win in ipairs(vim.api.nvim_tabpage_list_wins(tab)) do
|
||||||
|
if is_netrw_session_buffer(vim.api.nvim_win_get_buf(win)) then
|
||||||
|
tabs_with_netrw[tab] = true
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
for tab in pairs(tabs_with_netrw) do
|
||||||
|
if vim.api.nvim_tabpage_is_valid(tab) then
|
||||||
|
for _, win in ipairs(vim.api.nvim_tabpage_list_wins(tab)) do
|
||||||
|
if vim.api.nvim_win_is_valid(win) and vim.wo[win].previewwindow then
|
||||||
|
pcall(vim.api.nvim_win_close, win, true)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if vim.api.nvim_tabpage_is_valid(tab) then
|
||||||
|
for _, win in ipairs(vim.api.nvim_tabpage_list_wins(tab)) do
|
||||||
|
if
|
||||||
|
vim.api.nvim_win_is_valid(win)
|
||||||
|
and is_netrw_session_buffer(vim.api.nvim_win_get_buf(win))
|
||||||
|
then
|
||||||
|
if #vim.api.nvim_tabpage_list_wins(tab) > 1 then
|
||||||
|
pcall(vim.api.nvim_win_close, win, true)
|
||||||
|
elseif #vim.api.nvim_list_tabpages() > 1 then
|
||||||
|
close_session_tab(tab)
|
||||||
|
else
|
||||||
|
vim.api.nvim_win_set_buf(win, session_fallback_buffer())
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-- Auto-save session on exit, but ONLY if Session.vim already exists
|
-- Auto-save session on exit, but ONLY if Session.vim already exists
|
||||||
vim.api.nvim_create_autocmd("VimLeavePre", {
|
vim.api.nvim_create_autocmd("VimLeavePre", {
|
||||||
group = session_aug,
|
group = session_aug,
|
||||||
|
|
@ -144,6 +216,7 @@ vim.api.nvim_create_autocmd("VimLeavePre", {
|
||||||
callback = function()
|
callback = function()
|
||||||
-- Only save if Session.vim exists (user manually created it)
|
-- Only save if Session.vim exists (user manually created it)
|
||||||
if vim.fn.filereadable("Session.vim") == 1 then
|
if vim.fn.filereadable("Session.vim") == 1 then
|
||||||
|
omit_netrw_from_session()
|
||||||
vim.cmd("mksession! Session.vim")
|
vim.cmd("mksession! Session.vim")
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue