@@ -444,17 +444,16 @@ M.load = function(name, opts)
444444 local bufnr = vim .fn .bufadd (buf .name )
445445 if buf .loaded then
446446 vim .fn .bufload (bufnr )
447+ vim .b [bufnr ]._resession_need_edit = true
447448 vim .api .nvim_create_autocmd (" BufEnter" , {
448449 desc = " Resession: complete setup of restored buffer" ,
449450 callback = function (args )
450451 pcall (vim .api .nvim_win_set_cursor , 0 , buf .last_pos )
451- -- We have to schedule :edit otherwise it recurses
452- vim .schedule (function ()
453- if vim .api .nvim_get_current_buf () == args .buf then
454- -- This triggers the autocmds that set filetype, syntax highlighting, and checks the swapfile
455- vim .cmd .edit ({ mods = { emsg_silent = true } })
456- end
457- end )
452+ -- This triggers the autocmds that set filetype, syntax highlighting, and checks the swapfile
453+ if vim .b ._resession_need_edit then
454+ vim .b ._resession_need_edit = nil
455+ vim .cmd .edit ({ mods = { emsg_silent = true } })
456+ end
458457 end ,
459458 buffer = bufnr ,
460459 once = true ,
@@ -524,6 +523,7 @@ M.load = function(name, opts)
524523 dispatch (" post_load" , name , opts )
525524
526525 -- In case the current buffer has a swapfile, make sure we trigger all the necessary autocmds
526+ vim .b ._resession_need_edit = nil
527527 vim .cmd .edit ({ mods = { emsg_silent = true } })
528528end
529529
0 commit comments