[vim/vim] Add CmdlineMoved autocmd (PR #15040)

36 views
Skip to first unread message

Shougo

unread,
Jun 18, 2024, 12:01:02 AM (9 days ago) Jun 18
to vim/vim, Subscribed

It is useful to emulate cmdline.


You can view, comment on, or merge this pull request online at:

  https://github.com/vim/vim/pull/15040

Commit Summary

File Changes

(7 files)

Patch Links:


Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/15040@github.com>

Shougo

unread,
Jun 18, 2024, 5:18:31 AM (8 days ago) Jun 18
to vim/vim, Push

@Shougo pushed 1 commit.


View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/15040/before/101ddea8fb3f2da3e7dfd9658595be2549b2d304/after/219840bc99efd656c0761d8a3ef513d07b6541e7@github.com>

Christian Brabandt

unread,
Jun 18, 2024, 2:29:45 PM (8 days ago) Jun 18
to vim/vim, Subscribed

Thanks. The change to syntax/vim.vim is not needed, we will however need to re-generate the vim.vim syntax script. I wonder what happens, if the autocommand changes the cursor position? Does it recursively trigger the autocommand (I hope not)?


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/15040/c2176716632@github.com>

Shougo

unread,
Jun 18, 2024, 8:14:26 PM (8 days ago) Jun 18
to vim/vim, Subscribed

I wonder what happens, if the autocommand changes the cursor position? Does it recursively trigger the autocommand (I hope not)?

I have tested the behavior.

If ++nested is not set, it works without nesting call.
If ++nested is set, it will be infinite loop.

Found errors in Test_Cmdline():
Caught exception in Test_Cmdline(): Vim(call):E218: Autocommand nesting too deep @ command line..script /home/shougo/src/vim/src/testdir/runtest.vim[607]..func
tion RunTheTest[57]..Test_Cmdline[108]..CmdlineMoved Autocommands for ":"..CmdlineMoved Autocommands for ":"..CmdlineMoved Autocommands for ":"..CmdlineMoved A
utocommands for ":"..CmdlineMoved Autocommands for ":"..CmdlineMoved Autocommands for ":"..CmdlineMoved Autocommands for ":"..CmdlineMoved Autocommands for ":"
..CmdlineMoved Autocommands for ":"..CmdlineMoved Autocommands for ":"

I think it is expected behavior.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/15040/c2177285810@github.com>

Shougo

unread,
Jun 18, 2024, 8:14:26 PM (8 days ago) Jun 18
to vim/vim, Push

@Shougo pushed 1 commit.

  • 31183f7 Add cursor position change test

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/15040/before/219840bc99efd656c0761d8a3ef513d07b6541e7/after/31183f77d6512e27d51455d13e38e91fbe78ce16@github.com>

Shougo

unread,
Jun 18, 2024, 8:14:58 PM (8 days ago) Jun 18
to vim/vim, Subscribed

I have added the test for it.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/15040/c2177286316@github.com>

Christian Brabandt

unread,
Jun 19, 2024, 2:08:43 PM (7 days ago) Jun 19
to vim/vim, Subscribed

thanks. I am not a big fan of adding yet another auto command... Wouldn't be CursorMovedC be the better name, that way it would be in more sync to the existing CursorMoved and CursorMovedI autocommands I would think.

Can you please back out the change to syntax/vim.vim and also please rename the auto command?


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/15040/c2179262603@github.com>

Shougo

unread,
Jun 19, 2024, 7:59:49 PM (7 days ago) Jun 19
to vim/vim, Subscribed

OK.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/15040/c2179588872@github.com>

Shougo

unread,
Jun 19, 2024, 8:14:23 PM (7 days ago) Jun 19
to vim/vim, Push

@Shougo pushed 1 commit.

  • e464b56 Rename CmdlineMoved to CursorMovedC

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/15040/before/31183f77d6512e27d51455d13e38e91fbe78ce16/after/e464b56e37ceac07a8335180cd49cac5fb9b5eba@github.com>

Shougo

unread,
Jun 19, 2024, 8:14:46 PM (7 days ago) Jun 19
to vim/vim, Subscribed

Can you please back out the change to syntax/vim.vim and also please rename the auto command?

Done.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/15040/c2179599220@github.com>

Christian Brabandt

unread,
Jun 20, 2024, 4:07:34 PM (6 days ago) Jun 20
to vim/vim, Subscribed

Closed #15040 via d095214.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/15040/issue_event/13233974613@github.com>

Christian Brabandt

unread,
Jun 20, 2024, 4:07:51 PM (6 days ago) Jun 20
to vim/vim, Subscribed

thanks!


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/15040/c2181474960@github.com>

zeertzjq

unread,
Jun 20, 2024, 7:56:15 PM (6 days ago) Jun 20
to vim/vim, Subscribed

@zeertzjq commented on this pull request.


In src/testdir/test_autocmd.vim:

> @@ -2096,6 +2096,21 @@ func Test_Cmdline()
   au! CmdlineEnter
   au! CmdlineLeave
   let &shellslash = save_shellslash
+
+  au! CursorMovedC : let g:pos = getcmdpos()
+  let g:pos = 0
+  call feedkeys(":hello\<Left>\<ESC>", 'xt')
+  call assert_equal(5, g:pos)
+  call feedkeys(":12345678\<C-R>=setcmdpos(3)\<CR>\<ESC>", 'xt')
+  call assert_equal(3, g:pos)
+  au! CursorMovedC
+
+  " CursorMovedC changes the cursor position.
+  au! CursorMovedC : let g:pos = getcmdpos() | call setcmdpos(getcmdpos()-1)

It seems that this test doesn't really make sense, because setcmdpos() doesn't actually work when called in an autocommand:

		Only works while editing the command line, thus you must use
		|c_CTRL-\_e|, |c_CTRL-R_=| or |c_CTRL-R_CTRL-R| with '='.  For
		|c_CTRL-\_e| and |c_CTRL-R_CTRL-R| with '=' the position is
		set after the command line is set to the expression.  For
		|c_CTRL-R_=| it is set after evaluating the expression but
		before inserting the resulting text.


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/15040/review/2131573597@github.com>

Shougo

unread,
Jun 20, 2024, 8:37:38 PM (6 days ago) Jun 20
to vim/vim, Subscribed

@Shougo commented on this pull request.


In src/testdir/test_autocmd.vim:

> @@ -2096,6 +2096,21 @@ func Test_Cmdline()
   au! CmdlineEnter
   au! CmdlineLeave
   let &shellslash = save_shellslash
+
+  au! CursorMovedC : let g:pos = getcmdpos()
+  let g:pos = 0
+  call feedkeys(":hello\<Left>\<ESC>", 'xt')
+  call assert_equal(5, g:pos)
+  call feedkeys(":12345678\<C-R>=setcmdpos(3)\<CR>\<ESC>", 'xt')
+  call assert_equal(3, g:pos)
+  au! CursorMovedC
+
+  " CursorMovedC changes the cursor position.
+  au! CursorMovedC : let g:pos = getcmdpos() | call setcmdpos(getcmdpos()-1)

Hm.... If so, why it is nesting?

#15040 (comment)


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/15040/review/2131600797@github.com>

zeertzjq

unread,
Jun 20, 2024, 11:27:57 PM (6 days ago) Jun 20
to vim/vim, Subscribed

@zeertzjq commented on this pull request.


In src/testdir/test_autocmd.vim:

> @@ -2096,6 +2096,21 @@ func Test_Cmdline()
   au! CmdlineEnter
   au! CmdlineLeave
   let &shellslash = save_shellslash
+
+  au! CursorMovedC : let g:pos = getcmdpos()
+  let g:pos = 0
+  call feedkeys(":hello\<Left>\<ESC>", 'xt')
+  call assert_equal(5, g:pos)
+  call feedkeys(":12345678\<C-R>=setcmdpos(3)\<CR>\<ESC>", 'xt')
+  call assert_equal(3, g:pos)
+  au! CursorMovedC
+
+  " CursorMovedC changes the cursor position.
+  au! CursorMovedC : let g:pos = getcmdpos() | call setcmdpos(getcmdpos()-1)

Because you are triggering CursorMovedC even if cursor didn't move.


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/15040/review/2131717787@github.com>

zeertzjq

unread,
Jun 21, 2024, 12:33:00 AM (6 days ago) Jun 21
to vim/vim, Subscribed

@zeertzjq commented on this pull request.


In src/testdir/test_autocmd.vim:

> @@ -2096,6 +2096,21 @@ func Test_Cmdline()
   au! CmdlineEnter
   au! CmdlineLeave
   let &shellslash = save_shellslash
+
+  au! CursorMovedC : let g:pos = getcmdpos()
+  let g:pos = 0
+  call feedkeys(":hello\<Left>\<ESC>", 'xt')
+  call assert_equal(5, g:pos)
+  call feedkeys(":12345678\<C-R>=setcmdpos(3)\<CR>\<ESC>", 'xt')
+  call assert_equal(3, g:pos)
+  au! CursorMovedC
+
+  " CursorMovedC changes the cursor position.
+  au! CursorMovedC : let g:pos = getcmdpos() | call setcmdpos(getcmdpos()-1)

It seems that the initial value of save_cmdspos is also wrong, as it is using the position from the previous cmdline. I'll fix these problems in #15064.


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/15040/review/2131761061@github.com>

Shougo

unread,
Jun 21, 2024, 12:33:12 AM (6 days ago) Jun 21
to vim/vim, Subscribed

@Shougo commented on this pull request.


In src/testdir/test_autocmd.vim:

> @@ -2096,6 +2096,21 @@ func Test_Cmdline()
   au! CmdlineEnter
   au! CmdlineLeave
   let &shellslash = save_shellslash
+
+  au! CursorMovedC : let g:pos = getcmdpos()
+  let g:pos = 0
+  call feedkeys(":hello\<Left>\<ESC>", 'xt')
+  call assert_equal(5, g:pos)
+  call feedkeys(":12345678\<C-R>=setcmdpos(3)\<CR>\<ESC>", 'xt')
+  call assert_equal(3, g:pos)
+  au! CursorMovedC
+
+  " CursorMovedC changes the cursor position.
+  au! CursorMovedC : let g:pos = getcmdpos() | call setcmdpos(getcmdpos()-1)

Oh...


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/15040/review/2131761151@github.com>

Reply all
Reply to author
Forward
0 new messages