Skip to content

Commit

Permalink
perf: disable most autocmds when saving/loading a session
Browse files Browse the repository at this point in the history
  • Loading branch information
stevearc-stripe committed Apr 22, 2023
1 parent c57ff6f commit 10ce835
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lua/resession/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ local function save(name, opts, target_tabpage)
local util = require("resession.util")
local filename = util.get_session_file(name, opts.dir)
dispatch("pre_save", name, opts, target_tabpage)
local eventignore = vim.o.eventignore
vim.o.eventignore = "all"
local data = {
buffers = {},
tabs = {},
Expand Down Expand Up @@ -227,6 +229,7 @@ local function save(name, opts, target_tabpage)
dir = opts.dir,
}
end
vim.o.eventignore = eventignore
dispatch("post_save", name, opts, target_tabpage)
end

Expand Down Expand Up @@ -422,6 +425,8 @@ M.load = function(name, opts)
else
open_clean_tab()
end
local eventignore = vim.o.eventignore
vim.o.eventignore = "all"
if not data.tab_scoped then
-- Set the options immediately
util.restore_global_options(data.global.options)
Expand Down Expand Up @@ -504,6 +509,7 @@ M.load = function(name, opts)
dir = opts.dir,
}
end
vim.o.eventignore = eventignore
_is_loading = false
dispatch("post_load", name, opts)
end
Expand Down
5 changes: 5 additions & 0 deletions lua/resession/layout.lua
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,10 @@ local function set_winlayout_data(layout, scale_factor, visit_data)
if win.extension then
local ext = util.get_extension(win.extension)
if ext then
-- Re-enable autocmds so if the extensions rely on BufReadCmd it works
vim.o.eventignore = ""
local ok, new_winid = pcall(ext.load_win, win.winid, win.extension_data)
vim.o.eventignore = "all"
if ok then
win.winid = new_winid or win.winid
else
Expand All @@ -135,7 +138,9 @@ local function set_winlayout_data(layout, scale_factor, visit_data)
local bufnr = vim.fn.bufadd(win.bufname)
vim.api.nvim_win_set_buf(win.winid, bufnr)
-- After setting the buffer into the window, manually set the filetype to trigger syntax highlighting
vim.o.eventignore = ""
vim.api.nvim_buf_set_option(bufnr, "filetype", vim.api.nvim_buf_get_option(bufnr, "filetype"))
vim.o.eventignore = "all"
end
pcall(vim.api.nvim_win_set_cursor, win.winid, win.cursor)
util.restore_win_options(win.winid, win.options)
Expand Down

0 comments on commit 10ce835

Please sign in to comment.