Mercurial > vim
comparison src/testdir/test_cmdline.vim @ 29894:d8fc1effa724 v9.0.0285
patch 9.0.0285: it is not easy to change the command line from a plugin
Commit: https://github.com/vim/vim/commit/07ea5f1509fe8dafe3262ed2702b4d0fc99e288b
Author: Shougo Matsushita <Shougo.Matsu@gmail.com>
Date: Sat Aug 27 12:22:25 2022 +0100
patch 9.0.0285: it is not easy to change the command line from a plugin
Problem: It is not easy to change the command line from a plugin.
Solution: Add setcmdline(). (Shougo Matsushita, closes https://github.com/vim/vim/issues/10869)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 27 Aug 2022 13:30:04 +0200 |
parents | e038b8dd7cd9 |
children | b366b19d1a3e |
comparison
equal
deleted
inserted
replaced
29893:0ee1b461d692 | 29894:d8fc1effa724 |
---|---|
3260 call assert_equal(0, pumvisible()) | 3260 call assert_equal(0, pumvisible()) |
3261 cunmap <F2> | 3261 cunmap <F2> |
3262 set wildoptions& wildmenu& | 3262 set wildoptions& wildmenu& |
3263 endfunc | 3263 endfunc |
3264 | 3264 |
3265 func Test_setcmdline() | |
3266 func SetText(text, pos) | |
3267 call assert_equal(0, setcmdline(a:text)) | |
3268 call assert_equal(a:text, getcmdline()) | |
3269 call assert_equal(len(a:text) + 1, getcmdpos()) | |
3270 | |
3271 call assert_equal(0, setcmdline(a:text, a:pos)) | |
3272 call assert_equal(a:text, getcmdline()) | |
3273 call assert_equal(a:pos, getcmdpos()) | |
3274 | |
3275 call assert_fails('call setcmdline("' .. a:text .. '", -1)', 'E487:') | |
3276 call assert_fails('call setcmdline({}, 0)', 'E928:') | |
3277 call assert_fails('call setcmdline("' .. a:text .. '", {})', 'E728:') | |
3278 | |
3279 return '' | |
3280 endfunc | |
3281 | |
3282 call feedkeys(":\<C-R>=SetText('set rtp?', 2)\<CR>\<CR>", 'xt') | |
3283 call assert_equal('set rtp?', @:) | |
3284 | |
3285 " setcmdline() returns 1 when not editing the command line. | |
3286 call assert_equal(1, 'foo'->setcmdline()) | |
3287 | |
3288 " Called in custom function | |
3289 func CustomComplete(A, L, P) | |
3290 call assert_equal(0, setcmdline("DoCmd ")) | |
3291 return "January\nFebruary\nMars\n" | |
3292 endfunc | |
3293 | |
3294 com! -nargs=* -complete=custom,CustomComplete DoCmd : | |
3295 call feedkeys(":DoCmd \<C-A>\<C-B>\"\<CR>", 'tx') | |
3296 call assert_equal('"DoCmd January February Mars', @:) | |
3297 | |
3298 " Called in <expr> | |
3299 cnoremap <expr>a setcmdline('let foo=') | |
3300 call feedkeys(":a\<CR>", 'tx') | |
3301 call assert_equal('let foo=0', @:) | |
3302 cunmap a | |
3303 endfunc | |
3304 | |
3265 " vim: shiftwidth=2 sts=2 expandtab | 3305 " vim: shiftwidth=2 sts=2 expandtab |