From 6c602be33a5176fd1101e8cff45dd2a85b0e512e Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Wed, 31 Jan 2018 16:17:05 +0100 Subject: vim-patch:8.0.1445: cannot act on edits in the command line Problem: Cannot act on edits in the command line. Solution: Add the CmdlineChanged autocommand event. (xtal8, closes vim/vim#2603, closes vim/vim#2524) https://github.com/vim/vim/commit/153b704e20f9c269450a7d3ea8cafcf942579ab7 --- src/nvim/ex_getln.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 19a52c913a..447123e45d 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -1804,6 +1804,13 @@ static int empty_pattern(char_u *p) static int command_line_changed(CommandLineState *s) { + // Trigger CmdlineChanged autocommands. + char firstcbuf[2]; + firstcbuf[0] = s->firstc > 0 ? s->firstc : '-'; + firstcbuf[1] = 0; + apply_autocmds(EVENT_CMDLINECHANGED, (char_u *)firstcbuf, (char_u *)firstcbuf, + false, curbuf); + // 'incsearch' highlighting. if (p_is && !cmd_silent && (s->firstc == '/' || s->firstc == '?')) { pos_T end_pos; -- cgit From 5f82889be78856ee189c254110bf087dba918b23 Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Wed, 12 Dec 2018 11:01:46 +0100 Subject: cmdline: support v:event in CmdlineChanged --- src/nvim/ex_getln.c | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) (limited to 'src/nvim/ex_getln.c') diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index 447123e45d..bfc32887ca 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -1805,11 +1805,35 @@ static int empty_pattern(char_u *p) static int command_line_changed(CommandLineState *s) { // Trigger CmdlineChanged autocommands. - char firstcbuf[2]; - firstcbuf[0] = s->firstc > 0 ? s->firstc : '-'; - firstcbuf[1] = 0; - apply_autocmds(EVENT_CMDLINECHANGED, (char_u *)firstcbuf, (char_u *)firstcbuf, - false, curbuf); + if (has_event(EVENT_CMDLINECHANGED)) { + TryState tstate; + Error err = ERROR_INIT; + bool tl_ret = true; + dict_T *dict = get_vim_var_dict(VV_EVENT); + + char firstcbuf[2]; + firstcbuf[0] = s->firstc > 0 ? s->firstc : '-'; + firstcbuf[1] = 0; + + // 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); + tv_dict_set_keys_readonly(dict); + try_enter(&tstate); + + apply_autocmds(EVENT_CMDLINECHANGED, (char_u *)firstcbuf, + (char_u *)firstcbuf, false, curbuf); + tv_dict_clear(dict); + + tl_ret = try_leave(&tstate, &err); + if (!tl_ret && ERROR_SET(&err)) { + msg_putchar('\n'); + msg_printf_attr(HL_ATTR(HLF_E)|MSG_HIST, (char *)e_autocmd_err, err.msg); + api_clear_error(&err); + redrawcmd(); + } + tl_ret = true; + } // 'incsearch' highlighting. if (p_is && !cmd_silent && (s->firstc == '/' || s->firstc == '?')) { -- cgit