mirror of
https://github.com/neovim/neovim.git
synced 2025-10-05 17:36:29 +00:00
vim-patch:9.1.0207: No autocommand when writing session file (#28048)
Problem: No autocommand when writing session file
Solution: Add SessionWritePost autocommand
(Colin Kennedy)
fixes: vim/vim#14242
closes: vim/vim#14288
e5f2280381
Co-authored-by: Colin Kennedy <colinvfx@gmail.com>
This commit is contained in:
@@ -883,6 +883,9 @@ SafeState When nothing is pending, going to wait for the
|
|||||||
|
|
||||||
*SessionLoadPost*
|
*SessionLoadPost*
|
||||||
SessionLoadPost After loading the session file created using
|
SessionLoadPost After loading the session file created using
|
||||||
|
the |:mksession| command.
|
||||||
|
*SessionWritePost*
|
||||||
|
SessionWritePost After writing a session file by calling
|
||||||
the |:mksession| command.
|
the |:mksession| command.
|
||||||
*ShellCmdPost*
|
*ShellCmdPost*
|
||||||
ShellCmdPost After executing a shell command with |:!cmd|,
|
ShellCmdPost After executing a shell command with |:!cmd|,
|
||||||
|
@@ -88,6 +88,7 @@ return {
|
|||||||
'SafeState', -- going to wait for a character
|
'SafeState', -- going to wait for a character
|
||||||
'SearchWrapped', -- after the search wrapped around
|
'SearchWrapped', -- after the search wrapped around
|
||||||
'SessionLoadPost', -- after loading a session file
|
'SessionLoadPost', -- after loading a session file
|
||||||
|
'SessionWritePost', -- after writing a session file
|
||||||
'ShellCmdPost', -- after ":!cmd"
|
'ShellCmdPost', -- after ":!cmd"
|
||||||
'ShellFilterPost', -- after ":1,2!cmd", ":w !cmd", ":r !cmd".
|
'ShellFilterPost', -- after ":1,2!cmd", ":w !cmd", ":r !cmd".
|
||||||
'Signal', -- after nvim process received a signal
|
'Signal', -- after nvim process received a signal
|
||||||
|
@@ -12,6 +12,7 @@
|
|||||||
#include "nvim/arglist.h"
|
#include "nvim/arglist.h"
|
||||||
#include "nvim/arglist_defs.h"
|
#include "nvim/arglist_defs.h"
|
||||||
#include "nvim/ascii_defs.h"
|
#include "nvim/ascii_defs.h"
|
||||||
|
#include "nvim/autocmd.h"
|
||||||
#include "nvim/buffer.h"
|
#include "nvim/buffer.h"
|
||||||
#include "nvim/buffer_defs.h"
|
#include "nvim/buffer_defs.h"
|
||||||
#include "nvim/eval.h"
|
#include "nvim/eval.h"
|
||||||
@@ -1092,6 +1093,8 @@ void ex_mkrc(exarg_T *eap)
|
|||||||
}
|
}
|
||||||
|
|
||||||
xfree(viewFile);
|
xfree(viewFile);
|
||||||
|
|
||||||
|
apply_autocmds(EVENT_SESSIONWRITEPOST, NULL, NULL, false, curbuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @return the name of the view file for the current buffer.
|
/// @return the name of the view file for the current buffer.
|
||||||
|
@@ -3901,4 +3901,60 @@ func Test_autocmd_creates_new_buffer_on_bufleave()
|
|||||||
bw c.txt
|
bw c.txt
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
" Ensure `expected` was just recently written as a Vim session
|
||||||
|
func s:assert_session_path(expected)
|
||||||
|
call assert_equal(a:expected, v:this_session)
|
||||||
|
endfunc
|
||||||
|
|
||||||
|
" Check for `expected` after a session is written to-disk.
|
||||||
|
func s:watch_for_session_path(expected)
|
||||||
|
execute 'autocmd SessionWritePost * ++once execute "call s:assert_session_path(\"'
|
||||||
|
\ . a:expected
|
||||||
|
\ . '\")"'
|
||||||
|
endfunc
|
||||||
|
|
||||||
|
" Ensure v:this_session gets the full session path, if explicitly stated
|
||||||
|
func Test_explicit_session_absolute_path()
|
||||||
|
%bwipeout!
|
||||||
|
|
||||||
|
let directory = getcwd()
|
||||||
|
|
||||||
|
let v:this_session = ""
|
||||||
|
let name = "some_file.vim"
|
||||||
|
let expected = fnamemodify(name, ":p")
|
||||||
|
call s:watch_for_session_path(expected)
|
||||||
|
execute "mksession! " .. expected
|
||||||
|
|
||||||
|
call delete(expected)
|
||||||
|
endfunc
|
||||||
|
|
||||||
|
" Ensure v:this_session gets the full session path, if explicitly stated
|
||||||
|
func Test_explicit_session_relative_path()
|
||||||
|
%bwipeout!
|
||||||
|
|
||||||
|
let directory = getcwd()
|
||||||
|
|
||||||
|
let v:this_session = ""
|
||||||
|
let name = "some_file.vim"
|
||||||
|
let expected = fnamemodify(name, ":p")
|
||||||
|
call s:watch_for_session_path(expected)
|
||||||
|
execute "mksession! " .. name
|
||||||
|
|
||||||
|
call delete(expected)
|
||||||
|
endfunc
|
||||||
|
|
||||||
|
" Ensure v:this_session gets the full session path, if not specified
|
||||||
|
func Test_implicit_session()
|
||||||
|
%bwipeout!
|
||||||
|
|
||||||
|
let directory = getcwd()
|
||||||
|
|
||||||
|
let v:this_session = ""
|
||||||
|
let expected = fnamemodify("Session.vim", ":p")
|
||||||
|
call s:watch_for_session_path(expected)
|
||||||
|
mksession!
|
||||||
|
|
||||||
|
call delete(expected)
|
||||||
|
endfunc
|
||||||
|
|
||||||
" vim: shiftwidth=2 sts=2 expandtab
|
" vim: shiftwidth=2 sts=2 expandtab
|
||||||
|
Reference in New Issue
Block a user