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/auevents.lua | 1 + src/nvim/ex_getln.c | 7 +++++++ src/nvim/testdir/test_autocmd.vim | 12 ++++++++++++ 3 files changed, 20 insertions(+) (limited to 'src') diff --git a/src/nvim/auevents.lua b/src/nvim/auevents.lua index ab92e84799..3cffd66dee 100644 --- a/src/nvim/auevents.lua +++ b/src/nvim/auevents.lua @@ -21,6 +21,7 @@ return { 'BufWritePre', -- before writing a buffer 'ChanInfo', -- info was received about channel 'ChanOpen', -- channel was opened + 'CmdLineChanged', -- command line was modified 'CmdLineEnter', -- after entering cmdline mode 'CmdLineLeave', -- before leaving cmdline mode 'CmdUndefined', -- command undefined 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; diff --git a/src/nvim/testdir/test_autocmd.vim b/src/nvim/testdir/test_autocmd.vim index 9e8d2081c8..5deb789f48 100644 --- a/src/nvim/testdir/test_autocmd.vim +++ b/src/nvim/testdir/test_autocmd.vim @@ -818,6 +818,18 @@ func Test_QuitPre() endfunc func Test_Cmdline() + au! CmdlineChanged : let g:text = getcmdline() + let g:text = 0 + call feedkeys(":echom 'hello'\", 'xt') + call assert_equal("echom 'hello'", g:text) + au! CmdlineChanged + + au! CmdlineChanged : let g:entered = expand('') + let g:entered = 0 + call feedkeys(":echom 'hello'\", 'xt') + call assert_equal(':', g:entered) + au! CmdlineChanged + au! CmdlineEnter : let g:entered = expand('') au! CmdlineLeave : let g:left = expand('') let g:entered = 0 -- cgit