Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(events): save v:event for cmdline autocommands separately #21316

Merged
merged 1 commit into from
Dec 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix(events): save v:event for cmdline autocommands separately
  • Loading branch information
zeertzjq committed Dec 7, 2022
commit 4ef6efe927895ea43f32c7110c9b6e4de37e4ef8
8 changes: 6 additions & 2 deletions src/nvim/ex_getln.c
Original file line number Diff line number Diff line change
Expand Up @@ -738,13 +738,14 @@ static uint8_t *command_line_enter(int firstc, long count, int indent, bool init
TryState tstate;
Error err = ERROR_INIT;
bool tl_ret = true;
save_v_event_T save_v_event;
dict_T *dict = get_v_event(&save_v_event);
char firstcbuf[2];
firstcbuf[0] = (char)(firstc > 0 ? firstc : '-');
firstcbuf[1] = 0;

if (has_event(EVENT_CMDLINEENTER)) {
save_v_event_T save_v_event;
dict_T *dict = get_v_event(&save_v_event);

// set v:event to a dictionary with information about the commandline
tv_dict_add_str(dict, S_LEN("cmdtype"), firstcbuf);
tv_dict_add_nr(dict, S_LEN("cmdlevel"), ccline.level);
Expand Down Expand Up @@ -806,6 +807,9 @@ static uint8_t *command_line_enter(int firstc, long count, int indent, bool init
state_enter(&s->state);

if (has_event(EVENT_CMDLINELEAVE)) {
save_v_event_T save_v_event;
dict_T *dict = get_v_event(&save_v_event);

tv_dict_add_str(dict, S_LEN("cmdtype"), firstcbuf);
tv_dict_add_nr(dict, S_LEN("cmdlevel"), ccline.level);
tv_dict_set_keys_readonly(dict);
Expand Down
8 changes: 8 additions & 0 deletions test/functional/autocmd/cmdline_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,14 @@ describe('cmdline autocommands', function()
eq({'notification', 'CmdlineLeave', {{cmdtype='=', cmdlevel=2, abort=false}}}, next_msg())
end)

it('no crash with recursive use of v:event #19484', function()
command('autocmd CmdlineEnter * normal :')
feed(':')
eq({'notification', 'CmdlineEnter', {{cmdtype=':', cmdlevel=1}}}, next_msg())
feed('<CR>')
eq({'notification', 'CmdlineLeave', {{cmdtype=':', cmdlevel=1, abort=false}}}, next_msg())
end)

it('supports CmdlineChanged' ,function()
command("autocmd CmdlineChanged * call rpcnotify(g:channel, 'CmdlineChanged', v:event, getcmdline())")
feed(':')
Expand Down