Patch 8.1.1996
Problem: More functions can be used as methods.
Solution: Make various functions usable as a method.
Files: runtime/doc/eval.txt, src/evalfunc.c,
src/testdir/test_bufwintabinfo.vim,
src/testdir/test_cursor_func.vim, src/testdir/test_expr.vim,
src/testdir/test_functions.vim, src/testdir/test_put.vim,
src/testdir/test_quickfix.vim, src/testdir/test_sha256.vim,
src/testdir/test_tabpage.vim, src/testdir/test_tagjump.vim,
src/testdir/test_vartabs.vim
*** ../vim-8.1.1995/runtime/doc/eval.txt 2019-09-06 21:34:25.358847422 +0200
--- runtime/doc/eval.txt 2019-09-06 22:43:39.034873216 +0200
***************
*** 8382,8387 ****
--- 8396,8405 ----
only the items listed in {what} are set. Refer to |setqflist()|
for the list of supported keys in {what}.
+ Can also be used as a |method|, the base is passed as the
+ second argument: >
+ GetLoclist()->setloclist(winnr)
+
setmatches({list} [, {win}]) *setmatches()*
Restores a list of matches saved by |getmatches() for the
current window|. Returns 0 if successful, otherwise -1. All
***************
*** 8390,8395 ****
--- 8408,8416 ----
If {win} is specified, use the window with this number or
window ID instead of the current window.
+ Can also be used as a |method|: >
+ GetMatches()->setmatches()
+ <
*setpos()*
setpos({expr}, {list})
Set the position for {expr}. Possible values:
***************
*** 8439,8444 ****
--- 8460,8468 ----
also set the preferred column. Also see the "curswant" key in
|winrestview()|.
+ Can also be used as a |method|: >
+ GetPosition()->setpos('.')
+
setqflist({list} [, {action} [, {what}]]) *setqflist()*
Create or replace or add to the quickfix list.
***************
*** 8540,8546 ****
independent of the 'errorformat' setting. Use a command like
`:cc 1` to jump to the first position.
!
*setreg()*
setreg({regname}, {value} [, {options}])
Set the register {regname} to {value}.
--- 8564,8573 ----
independent of the 'errorformat' setting. Use a command like
`:cc 1` to jump to the first position.
! Can also be used as a |method|, the base is passed as the
! second argument: >
! GetErrorlist()->setqflist()
! <
*setreg()*
setreg({regname}, {value} [, {options}])
Set the register {regname} to {value}.
***************
*** 8588,8593 ****
--- 8615,8624 ----
nothing: >
:call setreg('a', '', 'al')
+ < Can also be used as a |method|, the base is passed as the
+ second argument: >
+ GetText()->setreg('a')
+
settabvar({tabnr}, {varname}, {val}) *settabvar()*
Set tab-local variable {varname} to {val} in tab page {tabnr}.
|t:var|
***************
*** 8597,8602 ****
--- 8628,8636 ----
Tabs are numbered starting with one.
This function is not available in the |sandbox|.
+ Can also be used as a |method|, the base is used as the value: >
+ GetValue()->settabvar(tab, name)
+
settabwinvar({tabnr}, {winnr}, {varname}, {val}) *settabwinvar()*
Set option or local variable {varname} in window {winnr} to
{val}.
***************
*** 8615,8620 ****
--- 8649,8657 ----
:call settabwinvar(3, 2, "myvar", "foobar")
< This function is not available in the |sandbox|.
+ Can also be used as a |method|, the base is used as the value: >
+ GetValue()->settabvar(tab, winnr, name)
+
settagstack({nr}, {dict} [, {action}]) *settagstack()*
Modify the tag stack of the window {nr} using {dict}.
{nr} can be the window number or the |window-ID|.
***************
*** 8646,8667 ****
call settagstack(1003, stack)
unlet stack
<
! setwinvar({nr}, {varname}, {val}) *setwinvar()*
Like |settabwinvar()| for the current tab page.
Examples: >
:call setwinvar(1, "&list", 0)
:call setwinvar(2, "myvar", "foobar")
sha256({string}) *sha256()*
Returns a String with 64 hex characters, which is the SHA256
checksum of {string}.
! {only available when compiled with the |+cryptv| feature}
shellescape({string} [, {special}]) *shellescape()*
Escape {string} for use as a shell command argument.
! On MS-Windows and MS-DOS, when 'shellslash' is not set, it
! will enclose {string} in double quotes and double all double
! quotes within {string}.
Otherwise it will enclose {string} in single quotes and
replace all "'" with "'\''".
--- 8683,8714 ----
call settagstack(1003, stack)
unlet stack
<
! Can also be used as a |method|, the base is used as the Dict: >
! GetStack()->settagstack(winnr)
!
! setwinvar({winnr}, {varname}, {val}) *setwinvar()*
Like |settabwinvar()| for the current tab page.
Examples: >
:call setwinvar(1, "&list", 0)
:call setwinvar(2, "myvar", "foobar")
+ < Can also be used as a |method|, the base is used as the value: >
+ GetValue()->setwinvar(winnr, name)
+
sha256({string}) *sha256()*
Returns a String with 64 hex characters, which is the SHA256
checksum of {string}.
!
! Can also be used as a |method|: >
! GetText()->sha256()
!
! < {only available when compiled with the |+cryptv| feature}
shellescape({string} [, {special}]) *shellescape()*
Escape {string} for use as a shell command argument.
! On MS-Windows, when 'shellslash' is not set, it will enclose
! {string} in double quotes and double all double quotes within
! {string}.
Otherwise it will enclose {string} in single quotes and
replace all "'" with "'\''".
***************
*** 8687,8692 ****
--- 8734,8741 ----
:call system("chmod +w -- " . shellescape(expand("%")))
< See also |::S|.
+ Can also be used as a |method|: >
+ GetCommand()->shellescape()
shiftwidth([{col}]) *shiftwidth()*
Returns the effective value of 'shiftwidth'. This is the
***************
*** 8700,8705 ****
--- 8749,8757 ----
'vartabstop' feature. If the 'vartabstop' setting is enabled and
no {col} argument is given, column 1 will be assumed.
+ Can also be used as a |method|: >
+ GetColumn()->shiftwidth()
+
sign_ functions are documented here: |sign-functions-details|
*** ../vim-8.1.1995/src/evalfunc.c 2019-09-06 22:00:50.369745851 +0200
--- src/evalfunc.c 2019-09-06 22:43:45.306843334 +0200
***************
*** 336,341 ****
--- 336,342 ----
#define FEARG_1 1 // base is the first argument
#define FEARG_2 2 // base is the second argument
#define FEARG_3 3 // base is the third argument
+ #define FEARG_4 4 // base is the fourth argument
#define FEARG_LAST 9 // base is the last argument
static funcentry_T global_functions[] =
***************
*** 721,740 ****
{"setenv", 2, 2, FEARG_2, f_setenv},
{"setfperm", 2, 2, FEARG_1, f_setfperm},
{"setline", 2, 2, FEARG_2, f_setline},
! {"setloclist", 2, 4, 0, f_setloclist},
! {"setmatches", 1, 2, 0, f_setmatches},
! {"setpos", 2, 2, 0, f_setpos},
! {"setqflist", 1, 3, 0, f_setqflist},
! {"setreg", 2, 3, 0, f_setreg},
! {"settabvar", 3, 3, 0, f_settabvar},
! {"settabwinvar", 4, 4, 0, f_settabwinvar},
! {"settagstack", 2, 3, 0, f_settagstack},
! {"setwinvar", 3, 3, 0, f_setwinvar},
#ifdef FEAT_CRYPT
! {"sha256", 1, 1, 0, f_sha256},
#endif
! {"shellescape", 1, 2, 0, f_shellescape},
! {"shiftwidth", 0, 1, 0, f_shiftwidth},
#ifdef FEAT_SIGNS
{"sign_define", 1, 2, FEARG_1, f_sign_define},
{"sign_getdefined", 0, 1, FEARG_1, f_sign_getdefined},
--- 722,741 ----
{"setenv", 2, 2, FEARG_2, f_setenv},
{"setfperm", 2, 2, FEARG_1, f_setfperm},
{"setline", 2, 2, FEARG_2, f_setline},
! {"setloclist", 2, 4, FEARG_2, f_setloclist},
! {"setmatches", 1, 2, FEARG_1, f_setmatches},
! {"setpos", 2, 2, FEARG_2, f_setpos},
! {"setqflist", 1, 3, FEARG_1, f_setqflist},
! {"setreg", 2, 3, FEARG_2, f_setreg},
! {"settabvar", 3, 3, FEARG_3, f_settabvar},
! {"settabwinvar", 4, 4, FEARG_4, f_settabwinvar},
! {"settagstack", 2, 3, FEARG_2, f_settagstack},
! {"setwinvar", 3, 3, FEARG_3, f_setwinvar},
#ifdef FEAT_CRYPT
! {"sha256", 1, 1, FEARG_1, f_sha256},
#endif
! {"shellescape", 1, 2, FEARG_1, f_shellescape},
! {"shiftwidth", 0, 1, FEARG_1, f_shiftwidth},
#ifdef FEAT_SIGNS
{"sign_define", 1, 2, FEARG_1, f_sign_define},
{"sign_getdefined", 0, 1, FEARG_1, f_sign_getdefined},
***************
*** 1060,1065 ****
--- 1061,1076 ----
for (i = 2; i < argcount; ++i)
argv[i + 1] = argvars[i];
}
+ else if (global_functions[fi].f_argtype == FEARG_4)
+ {
+ // base value goes fourth
+ argv[0] = argvars[0];
+ argv[1] = argvars[1];
+ argv[2] = argvars[2];
+ argv[3] = *basetv;
+ for (i = 3; i < argcount; ++i)
+ argv[i + 1] = argvars[i];
+ }
else
{
// FEARG_1: base value goes first
*** ../vim-8.1.1995/src/testdir/test_bufwintabinfo.vim 2019-08-31 19:13:27.839704613 +0200
--- src/testdir/test_bufwintabinfo.vim 2019-09-06 22:35:36.909420198 +0200
***************
*** 47,53 ****
tabnew | let w3_id = win_getid()
new | let w4_id = win_getid()
vert new | let w5_id = win_getid()
! call setwinvar(0, 'signal', 'green')
tabfirst
let winlist = getwininfo()
call assert_equal(5, len(winlist))
--- 47,53 ----
tabnew | let w3_id = win_getid()
new | let w4_id = win_getid()
vert new | let w5_id = win_getid()
! eval 'green'->setwinvar(0, 'signal')
tabfirst
let winlist = getwininfo()
call assert_equal(5, len(winlist))
*** ../vim-8.1.1995/src/testdir/test_cursor_func.vim 2019-09-06 21:34:25.362847408 +0200
--- src/testdir/test_cursor_func.vim 2019-09-06 22:25:42.648731973 +0200
***************
*** 37,43 ****
" Very short version of what matchparen does.
function s:Highlight_Matching_Pair()
let save_cursor = getcurpos()
! call setpos('.', save_cursor)
endfunc
func Test_curswant_with_autocommand()
--- 37,43 ----
" Very short version of what matchparen does.
function s:Highlight_Matching_Pair()
let save_cursor = getcurpos()
! eval save_cursor->setpos('.')
endfunc
func Test_curswant_with_autocommand()
*** ../vim-8.1.1995/src/testdir/test_expr.vim 2019-08-24 20:49:58.825320302 +0200
--- src/testdir/test_expr.vim 2019-09-06 22:24:13.785040376 +0200
***************
*** 504,510 ****
let set[0]['conceal'] = 5
let exp[0]['conceal'] = '5'
endif
! call setmatches(set)
call assert_equal(exp, getmatches())
endfunc
--- 504,510 ----
let set[0]['conceal'] = 5
let exp[0]['conceal'] = '5'
endif
! eval set->setmatches()
call assert_equal(exp, getmatches())
endfunc
*** ../vim-8.1.1995/src/testdir/test_functions.vim 2019-09-06 21:34:25.362847408 +0200
--- src/testdir/test_functions.vim 2019-09-06 22:42:44.219137076 +0200
***************
*** 1180,1186 ****
let save_shell = &shell
set shell=bash
call assert_equal("'text'", shellescape('text'))
! call assert_equal("'te\"xt'", shellescape('te"xt'))
call assert_equal("'te'\\''xt'", shellescape("te'xt"))
call assert_equal("'te%xt'", shellescape("te%xt"))
--- 1180,1186 ----
let save_shell = &shell
set shell=bash
call assert_equal("'text'", shellescape('text'))
! call assert_equal("'te\"xt'", 'te"xt'->shellescape())
call assert_equal("'te'\\''xt'", shellescape("te'xt"))
call assert_equal("'te%xt'", shellescape("te%xt"))
*** ../vim-8.1.1995/src/testdir/test_put.vim 2019-08-24 22:58:08.307264136 +0200
--- src/testdir/test_put.vim 2019-09-06 22:28:49.016084184 +0200
***************
*** 41,47 ****
call assert_equal(['Line 3', '', 'Line 1', 'Line2'], getline(1,'$'))
" clean up
bw!
! call setreg('a', a[0], a[1])
endfunc
func Test_put_expr()
--- 41,47 ----
call assert_equal(['Line 3', '', 'Line 1', 'Line2'], getline(1,'$'))
" clean up
bw!
! eval a[0]->setreg('a', a[1])
endfunc
func Test_put_expr()
*** ../vim-8.1.1995/src/testdir/test_quickfix.vim 2019-09-01 14:45:23.757964939 +0200
--- src/testdir/test_quickfix.vim 2019-09-06 22:22:16.293447497 +0200
***************
*** 711,717 ****
" NOTE: problem 1:
" intentionally not setting 'lnum' so that the quickfix entries are not
" valid
! call setloclist(0, qflist, ' ')
endfor
" Test A
--- 711,717 ----
" NOTE: problem 1:
" intentionally not setting 'lnum' so that the quickfix entries are not
" valid
! eval qflist->setloclist(0, ' ')
endfor
" Test A
***************
*** 1515,1521 ****
func Test_setqflist_invalid_nr()
" The following command used to crash Vim
! call setqflist([], ' ', {'nr' : $XXX_DOES_NOT_EXIST})
endfunc
func Test_quickfix_set_list_with_act()
--- 1515,1521 ----
func Test_setqflist_invalid_nr()
" The following command used to crash Vim
! eval []->setqflist(' ', {'nr' : $XXX_DOES_NOT_EXIST})
endfunc
func Test_quickfix_set_list_with_act()
*** ../vim-8.1.1995/src/testdir/test_sha256.vim 2019-06-15 17:57:43.972724036 +0200
--- src/testdir/test_sha256.vim 2019-09-06 22:41:17.407565683 +0200
***************
*** 6,22 ****
function Test_sha256()
" test for empty string:
! call assert_equal(sha256(""), 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855')
"'test for 1 char:
! call assert_equal(sha256("a"), 'ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb')
"
"test for 3 chars:
! call assert_equal(sha256("abc"), 'ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad')
" test for contains meta char:
! call assert_equal(sha256("foo\nbar"), '807eff6267f3f926a21d234f7b0cf867a86f47e07a532f15e8cc39ed110ca776')
" test for contains non-ascii char:
! call assert_equal(sha256("\xde\xad\xbe\xef"), '5f78c33274e43fa9de5659265c1d917e25c03722dcb0b8d27db8d5feaa813953')
endfunction
--- 6,22 ----
function Test_sha256()
" test for empty string:
! call assert_equal('e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855', sha256(""))
"'test for 1 char:
! call assert_equal('ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb', sha256("a"))
"
"test for 3 chars:
! call assert_equal('ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad', "abc"->sha256())
" test for contains meta char:
! call assert_equal('807eff6267f3f926a21d234f7b0cf867a86f47e07a532f15e8cc39ed110ca776', sha256("foo\nbar"))
" test for contains non-ascii char:
! call assert_equal('5f78c33274e43fa9de5659265c1d917e25c03722dcb0b8d27db8d5feaa813953', sha256("\xde\xad\xbe\xef"))
endfunction
*** ../vim-8.1.1995/src/testdir/test_tabpage.vim 2019-09-01 14:45:23.757964939 +0200
--- src/testdir/test_tabpage.vim 2019-09-06 22:32:25.614644995 +0200
***************
*** 34,40 ****
tabnew
tabfirst
call settabvar(2, 'val_num', 100)
! call settabvar(2, 'val_str', 'SetTabVar test')
call settabvar(2, 'val_list', ['red', 'blue', 'green'])
"
call assert_true(gettabvar(2, 'val_num') == 100 && gettabvar(2, 'val_str') == 'SetTabVar test' && gettabvar(2, 'val_list') == ['red', 'blue', 'green'])
--- 34,40 ----
tabnew
tabfirst
call settabvar(2, 'val_num', 100)
! eval 'SetTabVar test'->settabvar(2, 'val_str')
call settabvar(2, 'val_list', ['red', 'blue', 'green'])
"
call assert_true(gettabvar(2, 'val_num') == 100 && gettabvar(2, 'val_str') == 'SetTabVar test' && gettabvar(2, 'val_list') == ['red', 'blue', 'green'])
***************
*** 183,189 ****
let s:li = split(join(map(copy(winr), 'gettabwinvar('.tabn.', v:val, "a")')), '\s\+')
call assert_equal(['a', 'a'], s:li)
let s:li = []
! C call map(copy(winr), 'settabwinvar('.tabn.', v:val, ''a'', v:val*2)')
let s:li = split(join(map(copy(winr), 'gettabwinvar('.tabn.', v:val, "a")')), '\s\+')
call assert_equal(['2', '4'], s:li)
--- 183,189 ----
let s:li = split(join(map(copy(winr), 'gettabwinvar('.tabn.', v:val, "a")')), '\s\+')
call assert_equal(['a', 'a'], s:li)
let s:li = []
! C call map(copy(winr), '(v:val*2)->settabwinvar(' .. tabn .. ', v:val, ''a'')')
let s:li = split(join(map(copy(winr), 'gettabwinvar('.tabn.', v:val, "a")')), '\s\+')
call assert_equal(['2', '4'], s:li)
*** ../vim-8.1.1995/src/testdir/test_tagjump.vim 2019-08-31 19:13:27.839704613 +0200
--- src/testdir/test_tagjump.vim 2019-09-06 22:38:23.368472859 +0200
***************
*** 303,309 ****
" Try to set current index to invalid values
call settagstack(1, {'curidx' : -1})
call assert_equal(1, gettagstack().curidx)
! call settagstack(1, {'curidx' : 50})
call assert_equal(4, gettagstack().curidx)
" Try pushing invalid items onto the stack
--- 303,309 ----
" Try to set current index to invalid values
call settagstack(1, {'curidx' : -1})
call assert_equal(1, gettagstack().curidx)
! eval {'curidx' : 50}->settagstack(1)
call assert_equal(4, gettagstack().curidx)
" Try pushing invalid items onto the stack
*** ../vim-8.1.1995/src/testdir/test_vartabs.vim 2019-06-15 17:57:43.976724009 +0200
--- src/testdir/test_vartabs.vim 2019-09-06 22:44:14.286706052 +0200
***************
*** 329,335 ****
let lines = ScreenLines([1, 2], winwidth(0))
call s:compare_lines(expect2, lines)
call assert_equal(20, shiftwidth(virtcol('.')-2))
! call assert_equal(30, shiftwidth(virtcol('.')))
norm! $>>
let expect3 = [' ', ' x ', '~ ']
let lines = ScreenLines([1, 3], winwidth(0))
--- 329,335 ----
let lines = ScreenLines([1, 2], winwidth(0))
call s:compare_lines(expect2, lines)
call assert_equal(20, shiftwidth(virtcol('.')-2))
! call assert_equal(30, virtcol('.')->shiftwidth())
norm! $>>
let expect3 = [' ', ' x ', '~ ']
let lines = ScreenLines([1, 3], winwidth(0))
*** ../vim-8.1.1995/src/version.c 2019-09-06 22:00:50.369745851 +0200
--- src/version.c 2019-09-06 22:18:01.350327398 +0200
***************
*** 759,760 ****
--- 759,762 ----
{ /* Add new patch number below this line */
+ /**/
+ 1996,
/**/
--
$ echo pizza > /dev/oven
/// Bram Moolenaar -- Br...@Moolenaar.net --
http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features --
http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language --
http://www.Zimbu.org ///
\\\ help me help AIDS victims --
http://ICCF-Holland.org ///