patch 9.2.0061: Not possible to know when a session will be loaded
Commit:
https://github.com/vim/vim/commit/1c0d468d72e0220d4cb25936043ac35439a981b5
Author: Colin Kennedy <[email protected]>
Date: Wed Feb 25 21:08:15 2026 +0000
patch 9.2.0061: Not possible to know when a session will be loaded
Problem: Not possible to know when a session will be loaded.
Solution: Add the SessionLoadPre autocommand (Colin Kennedy).
fixes: #19084
closes: #19306
Signed-off-by: Colin Kennedy <[email protected]>
Signed-off-by: Christian Brabandt <[email protected]>
diff --git a/runtime/doc/autocmd.txt b/runtime/doc/autocmd.txt
index 23d604a32..eba6e4354 100644
--- a/runtime/doc/autocmd.txt
+++ b/runtime/doc/autocmd.txt
@@ -1,4 +1,4 @@
-*autocmd.txt* For Vim version 9.2. Last change: 2026 Feb 14
+*autocmd.txt* For Vim version 9.2. Last change: 2026 Feb 25
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -435,6 +435,7 @@ Name triggered by ~
|QuickFixCmdPre| before a quickfix command is run
|QuickFixCmdPost| after a quickfix command is run
+|SessionLoadPre| before loading a session file
|SessionLoadPost| after loading a session file
|SessionWritePost| after writing the session file using
@@ -1182,6 +1183,9 @@ SafeStateAgain Like SafeState but
after processing any
triggered often, don't do something that takes
time.
+ *SessionLoadPre*
+SessionLoadPre Before loading the session file created using
+ the |:mksession| command.
*SessionLoadPost*
SessionLoadPost After loading the session file created
using
the |:mksession| command.
diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt
index a26412782..47948bdf7 100644
--- a/runtime/doc/options.txt
+++ b/runtime/doc/options.txt
@@ -1,4 +1,4 @@
-*options.txt* For Vim version 9.2. Last change: 2026 Feb 24
+*options.txt* For Vim version 9.2. Last change: 2026 Feb 25
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -3595,6 +3595,7 @@ A jump table for the options with a short description can
be found at |Q_op|.
|SafeState|,
|SafeStateAgain|,
|SessionLoadPost|,
+ |SessionLoadPre|,
|SessionWritePost|,
|ShellCmdPost|,
|SigUSR1|,
diff --git a/runtime/doc/starting.txt b/runtime/doc/starting.txt
index 4d828a1c3..8aa6241d5 100644
--- a/runtime/doc/starting.txt
+++ b/runtime/doc/starting.txt
@@ -1,4 +1,4 @@
-*starting.txt* For Vim version 9.2. Last change: 2026 Feb 18
+*starting.txt* For Vim version 9.2. Last change: 2026 Feb 25
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -1468,8 +1468,8 @@ This saves the current Session, and starts off the
command to load another.
A session includes all tab pages, unless "tabpages" was removed from
'sessionoptions'. |tab-page|
-The |SessionLoadPost| autocmd event is triggered after a session file is
-loaded/sourced.
+The |SessionLoadPre| autocmd event is triggered before a session file is
+loaded/sourced and |SessionLoadPost| autocmd event is triggered after.
*SessionLoad-variable*
While the session file is loading, the SessionLoad global variable is set to
1. Plugins can use this to postpone some work until the SessionLoadPost event
diff --git a/runtime/doc/tags b/runtime/doc/tags
index f86fe37eb..017362863 100644
--- a/runtime/doc/tags
+++ b/runtime/doc/tags
@@ -5896,6 +5896,7 @@ Select-mode-mapping visual.txt
/*Select-mode-mapping*
Session starting.txt /*Session*
SessionLoad-variable starting.txt /*SessionLoad-variable*
SessionLoadPost autocmd.txt /*SessionLoadPost*
+SessionLoadPre autocmd.txt /*SessionLoadPre*
SessionWritePost autocmd.txt /*SessionWritePost*
ShellCmdPost autocmd.txt /*ShellCmdPost*
ShellFilterPost autocmd.txt /*ShellFilterPost*
diff --git a/runtime/doc/version9.txt b/runtime/doc/version9.txt
index 17535bdbd..8261c32ef 100644
--- a/runtime/doc/version9.txt
+++ b/runtime/doc/version9.txt
@@ -52601,6 +52601,11 @@ Changed~
*added-9.3*
Added ~
-----
+Various syntax, indent and other plugins were added.
+
+Autocommands: ~
+
+|SessionLoadPre| before loading a |Session| file
==============================================================================
PATCHES *patches-9.3*
*bug-fixes-9.3*
diff --git a/src/autocmd.c b/src/autocmd.c
index acf7bb140..e6b6ecbe0 100644
--- a/src/autocmd.c
+++ b/src/autocmd.c
@@ -168,6 +168,7 @@ static keyvalue_T event_tab[NUM_EVENTS] = {
KEYVALUE_ENTRY(EVENT_SAFESTATE, "SafeState"),
KEYVALUE_ENTRY(EVENT_SAFESTATEAGAIN, "SafeStateAgain"),
KEYVALUE_ENTRY(EVENT_SESSIONLOADPOST, "SessionLoadPost"),
+ KEYVALUE_ENTRY(EVENT_SESSIONLOADPRE, "SessionLoadPre"),
KEYVALUE_ENTRY(EVENT_SESSIONWRITEPOST, "SessionWritePost"),
KEYVALUE_ENTRY(EVENT_SHELLCMDPOST, "ShellCmdPost"),
KEYVALUE_ENTRY(-EVENT_SHELLFILTERPOST, "ShellFilterPost"),
diff --git a/src/session.c b/src/session.c
index 80d4ffb70..31a021b22 100644
--- a/src/session.c
+++ b/src/session.c
@@ -640,6 +640,10 @@ makeopens(
# ifdef FEAT_EVAL
if (put_line(fd, "let v:this_session=expand(\"<sfile>:p\")") == FAIL)
goto fail;
+
+ if (put_line(fd, "doautoall SessionLoadPre") == FAIL)
+ goto fail;
+
if (ssop_flags & SSOP_GLOBALS)
if (store_session_globals(fd) == FAIL)
goto fail;
diff --git a/src/testdir/test_autocmd.vim b/src/testdir/test_autocmd.vim
index 74b1aabdf..084dd7a5a 100644
--- a/src/testdir/test_autocmd.vim
+++ b/src/testdir/test_autocmd.vim
@@ -1131,6 +1131,71 @@ func Test_BufEnter()
only
endfunc
+func Test_autocmd_SessLoadPre()
+ tabnew
+ set noswapfile
+ mksession! Session.vim
+
+ call assert_false(exists('g:session_loaded_var'))
+
+ let content =<< trim [CODE]
+ set nocp noswapfile
+
+ func! Assert(cond, msg)
+ if !a:cond
+ echomsg "ASSERT_FAIL: " .. a:msg
+ else
+ echomsg "ASSERT_OK: " .. a:msg
+ endif
+ endfunc
+
+ func! OnSessionLoadPre()
+ call Assert(!exists('g:session_loaded_var'),
+ \ 'SessionLoadPre: var NOT set')
+ endfunc
+ au SessionLoadPre * call OnSessionLoadPre()
+
+ func! OnSessionLoadPost()
+ call Assert(exists('g:session_loaded_var'),
+ \ 'SessionLoadPost: var IS set')
+ echomsg "SessionLoadPost DONE"
+ endfunc
+ au SessionLoadPost * call OnSessionLoadPost()
+
+ func! WriteErrors()
+ call writefile([execute("messages")], "XerrorsPost")
+ endfunc
+ au VimLeave * call WriteErrors()
+ [CODE]
+
+ call writefile(content, 'Xvimrc', 'D')
+
+ call writefile(
+ \ ['let g:session_loaded_var = 1'],
+ \ 'Sessionx.vim',
+ \ 'b'
+ \ )
+
+ " --- Run child Vim ---
+ call system(
+ \ GetVimCommand('Xvimrc')
+ \ .. ' --not-a-term --noplugins -S Session.vim -c cq'
+ \ )
+
+ call WaitForAssert({-> assert_true(filereadable('XerrorsPost'))})
+
+ let errors = join(readfile('XerrorsPost'), "
")
+ call assert_notmatch('ASSERT_FAIL', errors)
+ call assert_match('ASSERT_OK: SessionLoadPre: var NOT set', errors)
+ call assert_match('ASSERT_OK: SessionLoadPost: var IS set', errors)
+ call assert_match('SessionLoadPost DONE', errors)
+
+ set swapfile
+ for file in ['Session.vim', 'Sessionx.vim', 'XerrorsPost']
+ call delete(file)
+ endfor
+endfunc
+
" Closing a window might cause an endless loop
" E814 for older Vims
func Test_autocmd_bufwipe_in_SessLoadPost()
diff --git a/src/version.c b/src/version.c
index 55cfca20d..08e7ee2c9 100644
--- a/src/version.c
+++ b/src/version.c
@@ -734,6 +734,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 61,
/**/
60,
/**/
diff --git a/src/vim.h b/src/vim.h
index 3d375f099..02e02c332 100644
--- a/src/vim.h
+++ b/src/vim.h
@@ -1470,6 +1470,7 @@ enum auto_event
EVENT_SAFESTATE, // going to wait for a character
EVENT_SAFESTATEAGAIN, // still waiting for a character
EVENT_SESSIONLOADPOST, // after loading a session file
+ EVENT_SESSIONLOADPRE, // before loading a session file
EVENT_SESSIONWRITEPOST, // after writing a session file
EVENT_SHELLCMDPOST, // after ":!cmd"
EVENT_SHELLFILTERPOST, // after ":1,2!cmd", ":w !cmd", ":r !cmd".
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/vim_dev/E1vvMDn-00CzGi-OD%40256bit.org.