mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 03:18:16 +00:00
Merge pull request #21267 from zeertzjq/vim-8.2.3900
vim-patch:8.2.{3900,partial:3908}: it is not easy to use a script-local function for an option
This commit is contained in:
@@ -388,6 +388,11 @@ mode, so that a CTRL-Z doesn't end the text on DOS.
|
|||||||
The `redraw!` command may not be needed, depending on whether executing a
|
The `redraw!` command may not be needed, depending on whether executing a
|
||||||
shell command shows something on the display or not.
|
shell command shows something on the display or not.
|
||||||
|
|
||||||
|
If the 'diffexpr' expression starts with s: or |<SID>|, then it is replaced
|
||||||
|
with the script ID (|local-function|). Example: >
|
||||||
|
set diffexpr=s:MyDiffExpr()
|
||||||
|
set diffexpr=<SID>SomeDiffExpr()
|
||||||
|
<
|
||||||
*E810* *E97*
|
*E810* *E97*
|
||||||
Vim will do a test if the diff output looks alright. If it doesn't, you will
|
Vim will do a test if the diff output looks alright. If it doesn't, you will
|
||||||
get an error message. Possible causes:
|
get an error message. Possible causes:
|
||||||
@@ -439,4 +444,9 @@ evaluating 'patchexpr'. This hopefully avoids that files in the current
|
|||||||
directory are accidentally patched. Vim will also delete files starting with
|
directory are accidentally patched. Vim will also delete files starting with
|
||||||
v:fname_in and ending in ".rej" and ".orig".
|
v:fname_in and ending in ".rej" and ".orig".
|
||||||
|
|
||||||
|
If the 'patchexpr' expression starts with s: or |<SID>|, then it is replaced
|
||||||
|
with the script ID (|local-function|). Example: >
|
||||||
|
set patchexpr=s:MyPatchExpr()
|
||||||
|
set patchexpr=<SID>SomePatchExpr()
|
||||||
|
<
|
||||||
vim:tw=78:ts=8:noet:ft=help:norl:
|
vim:tw=78:ts=8:noet:ft=help:norl:
|
||||||
|
@@ -116,6 +116,11 @@ method can be very slow!
|
|||||||
Try to avoid the "=", "a" and "s" return values, since Vim often has to search
|
Try to avoid the "=", "a" and "s" return values, since Vim often has to search
|
||||||
backwards for a line for which the fold level is defined. This can be slow.
|
backwards for a line for which the fold level is defined. This can be slow.
|
||||||
|
|
||||||
|
If the 'foldexpr' expression starts with s: or |<SID>|, then it is replaced
|
||||||
|
with the script ID (|local-function|). Examples: >
|
||||||
|
set foldexpr=s:MyFoldExpr()
|
||||||
|
set foldexpr=<SID>SomeFoldExpr()
|
||||||
|
<
|
||||||
An example of using "a1" and "s1": For a multi-line C comment, a line
|
An example of using "a1" and "s1": For a multi-line C comment, a line
|
||||||
containing "/*" would return "a1" to start a fold, and a line containing "*/"
|
containing "/*" would return "a1" to start a fold, and a line containing "*/"
|
||||||
would return "s1" to end the fold after that line: >
|
would return "s1" to end the fold after that line: >
|
||||||
@@ -521,6 +526,11 @@ The resulting line is truncated to fit in the window, it never wraps.
|
|||||||
When there is room after the text, it is filled with the character specified
|
When there is room after the text, it is filled with the character specified
|
||||||
by 'fillchars'.
|
by 'fillchars'.
|
||||||
|
|
||||||
|
If the 'foldtext' expression starts with s: or |<SID>|, then it is replaced
|
||||||
|
with the script ID (|local-function|). Examples: >
|
||||||
|
set foldtext=s:MyFoldText()
|
||||||
|
set foldtext=<SID>SomeFoldText()
|
||||||
|
<
|
||||||
Note that backslashes need to be used for characters that the ":set" command
|
Note that backslashes need to be used for characters that the ":set" command
|
||||||
handles differently: Space, backslash and double-quote. |option-backslash|
|
handles differently: Space, backslash and double-quote. |option-backslash|
|
||||||
|
|
||||||
|
@@ -2738,6 +2738,11 @@ A jump table for the options with a short description can be found at |Q_op|.
|
|||||||
When the expression evaluates to non-zero Vim will fall back to using
|
When the expression evaluates to non-zero Vim will fall back to using
|
||||||
the internal format mechanism.
|
the internal format mechanism.
|
||||||
|
|
||||||
|
If the expression starts with s: or |<SID>|, then it is replaced with
|
||||||
|
the script ID (|local-function|). Example: >
|
||||||
|
set formatexpr=s:MyFormatExpr()
|
||||||
|
set formatexpr=<SID>SomeFormatExpr()
|
||||||
|
<
|
||||||
The expression will be evaluated in the |sandbox| when set from a
|
The expression will be evaluated in the |sandbox| when set from a
|
||||||
modeline, see |sandbox-option|. That stops the option from working,
|
modeline, see |sandbox-option|. That stops the option from working,
|
||||||
since changing the buffer text is not allowed.
|
since changing the buffer text is not allowed.
|
||||||
@@ -3362,6 +3367,11 @@ A jump table for the options with a short description can be found at |Q_op|.
|
|||||||
found. Allows doing "gf" on the name after an 'include' statement.
|
found. Allows doing "gf" on the name after an 'include' statement.
|
||||||
Also used for |<cfile>|.
|
Also used for |<cfile>|.
|
||||||
|
|
||||||
|
If the expression starts with s: or |<SID>|, then it is replaced with
|
||||||
|
the script ID (|local-function|). Example: >
|
||||||
|
set includeexpr=s:MyIncludeExpr(v:fname)
|
||||||
|
set includeexpr=<SID>SomeIncludeExpr(v:fname)
|
||||||
|
<
|
||||||
The expression will be evaluated in the |sandbox| when set from a
|
The expression will be evaluated in the |sandbox| when set from a
|
||||||
modeline, see |sandbox-option|.
|
modeline, see |sandbox-option|.
|
||||||
This option cannot be set in a modeline when 'modelineexpr' is off.
|
This option cannot be set in a modeline when 'modelineexpr' is off.
|
||||||
@@ -3417,6 +3427,11 @@ A jump table for the options with a short description can be found at |Q_op|.
|
|||||||
The expression is evaluated with |v:lnum| set to the line number for
|
The expression is evaluated with |v:lnum| set to the line number for
|
||||||
which the indent is to be computed. The cursor is also in this line
|
which the indent is to be computed. The cursor is also in this line
|
||||||
when the expression is evaluated (but it may be moved around).
|
when the expression is evaluated (but it may be moved around).
|
||||||
|
If the expression starts with s: or |<SID>|, then it is replaced with
|
||||||
|
the script ID (|local-function|). Example: >
|
||||||
|
set indentexpr=s:MyIndentExpr()
|
||||||
|
set indentexpr=<SID>SomeIndentExpr()
|
||||||
|
<
|
||||||
The expression must return the number of spaces worth of indent. It
|
The expression must return the number of spaces worth of indent. It
|
||||||
can return "-1" to keep the current indent (this means 'autoindent' is
|
can return "-1" to keep the current indent (this means 'autoindent' is
|
||||||
used for the indent).
|
used for the indent).
|
||||||
|
@@ -155,6 +155,11 @@ an error message. In that case Vim will delete the file. In the default
|
|||||||
value for non-MS-Windows a trick is used: Adding "v:shell_error" will result
|
value for non-MS-Windows a trick is used: Adding "v:shell_error" will result
|
||||||
in a non-zero number when the system() call fails.
|
in a non-zero number when the system() call fails.
|
||||||
|
|
||||||
|
If the expression starts with s: or |<SID>|, then it is replaced with the
|
||||||
|
script ID (|local-function|). Example: >
|
||||||
|
set printexpr=s:MyPrintFile()
|
||||||
|
set printexpr=<SID>SomePrintFile()
|
||||||
|
<
|
||||||
This option cannot be set from a |modeline| or in the |sandbox|, for security
|
This option cannot be set from a |modeline| or in the |sandbox|, for security
|
||||||
reasons.
|
reasons.
|
||||||
|
|
||||||
|
@@ -711,7 +711,7 @@ void eval_patch(const char *const origfile, const char *const difffile, const ch
|
|||||||
set_vim_var_string(VV_FNAME_IN, origfile, -1);
|
set_vim_var_string(VV_FNAME_IN, origfile, -1);
|
||||||
set_vim_var_string(VV_FNAME_DIFF, difffile, -1);
|
set_vim_var_string(VV_FNAME_DIFF, difffile, -1);
|
||||||
set_vim_var_string(VV_FNAME_OUT, outfile, -1);
|
set_vim_var_string(VV_FNAME_OUT, outfile, -1);
|
||||||
(void)eval_to_bool((char *)p_pex, &err, NULL, false);
|
(void)eval_to_bool(p_pex, &err, NULL, false);
|
||||||
set_vim_var_string(VV_FNAME_IN, NULL, -1);
|
set_vim_var_string(VV_FNAME_IN, NULL, -1);
|
||||||
set_vim_var_string(VV_FNAME_DIFF, NULL, -1);
|
set_vim_var_string(VV_FNAME_DIFF, NULL, -1);
|
||||||
set_vim_var_string(VV_FNAME_OUT, NULL, -1);
|
set_vim_var_string(VV_FNAME_OUT, NULL, -1);
|
||||||
@@ -5511,7 +5511,7 @@ void get_system_output_as_rettv(typval_T *argvars, typval_T *rettv, bool retlist
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Get a callback from "arg". It can be a Funcref or a function name.
|
/// Get a callback from "arg". It can be a Funcref or a function name.
|
||||||
bool callback_from_typval(Callback *const callback, typval_T *const arg)
|
bool callback_from_typval(Callback *const callback, const typval_T *const arg)
|
||||||
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT
|
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT
|
||||||
{
|
{
|
||||||
int r = OK;
|
int r = OK;
|
||||||
|
@@ -1845,7 +1845,7 @@ static int nlua_is_thread(lua_State *lstate)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool nlua_is_table_from_lua(typval_T *const arg)
|
bool nlua_is_table_from_lua(const typval_T *const arg)
|
||||||
{
|
{
|
||||||
if (arg->v_type == VAR_DICT) {
|
if (arg->v_type == VAR_DICT) {
|
||||||
return arg->vval.v_dict->lua_table_ref != LUA_NOREF;
|
return arg->vval.v_dict->lua_table_ref != LUA_NOREF;
|
||||||
@@ -1856,7 +1856,7 @@ bool nlua_is_table_from_lua(typval_T *const arg)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
char_u *nlua_register_table_as_callable(typval_T *const arg)
|
char_u *nlua_register_table_as_callable(const typval_T *const arg)
|
||||||
{
|
{
|
||||||
LuaRef table_ref = LUA_NOREF;
|
LuaRef table_ref = LUA_NOREF;
|
||||||
if (arg->v_type == VAR_DICT) {
|
if (arg->v_type == VAR_DICT) {
|
||||||
|
@@ -622,7 +622,7 @@ EXTERN char *p_opfunc; // 'operatorfunc'
|
|||||||
EXTERN char_u *p_para; // 'paragraphs'
|
EXTERN char_u *p_para; // 'paragraphs'
|
||||||
EXTERN int p_paste; // 'paste'
|
EXTERN int p_paste; // 'paste'
|
||||||
EXTERN char *p_pt; // 'pastetoggle'
|
EXTERN char *p_pt; // 'pastetoggle'
|
||||||
EXTERN char_u *p_pex; // 'patchexpr'
|
EXTERN char *p_pex; // 'patchexpr'
|
||||||
EXTERN char *p_pm; // 'patchmode'
|
EXTERN char *p_pm; // 'patchmode'
|
||||||
EXTERN char_u *p_path; // 'path'
|
EXTERN char_u *p_path; // 'path'
|
||||||
EXTERN char_u *p_cdpath; // 'cdpath'
|
EXTERN char_u *p_cdpath; // 'cdpath'
|
||||||
|
@@ -17,6 +17,7 @@
|
|||||||
#include "nvim/drawscreen.h"
|
#include "nvim/drawscreen.h"
|
||||||
#include "nvim/eval.h"
|
#include "nvim/eval.h"
|
||||||
#include "nvim/eval/typval_defs.h"
|
#include "nvim/eval/typval_defs.h"
|
||||||
|
#include "nvim/eval/userfunc.h"
|
||||||
#include "nvim/eval/vars.h"
|
#include "nvim/eval/vars.h"
|
||||||
#include "nvim/ex_getln.h"
|
#include "nvim/ex_getln.h"
|
||||||
#include "nvim/fold.h"
|
#include "nvim/fold.h"
|
||||||
@@ -1341,10 +1342,6 @@ char *did_set_string_option(int opt_idx, char **varp, char *oldval, char *errbuf
|
|||||||
newFoldLevel();
|
newFoldLevel();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (varp == &curwin->w_p_fde) { // 'foldexpr'
|
|
||||||
if (foldmethodIsExpr(curwin)) {
|
|
||||||
foldUpdateAll(curwin);
|
|
||||||
}
|
|
||||||
} else if (gvarp == &curwin->w_allbuf_opt.wo_fmr) { // 'foldmarker'
|
} else if (gvarp == &curwin->w_allbuf_opt.wo_fmr) { // 'foldmarker'
|
||||||
p = vim_strchr(*varp, ',');
|
p = vim_strchr(*varp, ',');
|
||||||
if (p == NULL) {
|
if (p == NULL) {
|
||||||
@@ -1484,6 +1481,55 @@ char *did_set_string_option(int opt_idx, char **varp, char *oldval, char *errbuf
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if (varp == &p_dex
|
||||||
|
|| varp == &curwin->w_p_fde
|
||||||
|
|| varp == &curwin->w_p_fdt
|
||||||
|
|| gvarp == &p_fex
|
||||||
|
|| gvarp == &p_inex
|
||||||
|
|| gvarp == &p_inde
|
||||||
|
|| varp == &p_pex
|
||||||
|
|| varp == &p_pexpr) { // '*expr' options
|
||||||
|
char **p_opt = NULL;
|
||||||
|
|
||||||
|
// If the option value starts with <SID> or s:, then replace that with
|
||||||
|
// the script identifier.
|
||||||
|
|
||||||
|
if (varp == &p_dex) { // 'diffexpr'
|
||||||
|
p_opt = &p_dex;
|
||||||
|
}
|
||||||
|
if (varp == &curwin->w_p_fde) { // 'foldexpr'
|
||||||
|
p_opt = &curwin->w_p_fde;
|
||||||
|
}
|
||||||
|
if (varp == &curwin->w_p_fdt) { // 'foldtext'
|
||||||
|
p_opt = &curwin->w_p_fdt;
|
||||||
|
}
|
||||||
|
if (gvarp == &p_fex) { // 'formatexpr'
|
||||||
|
p_opt = &curbuf->b_p_fex;
|
||||||
|
}
|
||||||
|
if (gvarp == &p_inex) { // 'includeexpr'
|
||||||
|
p_opt = &curbuf->b_p_inex;
|
||||||
|
}
|
||||||
|
if (gvarp == &p_inde) { // 'indentexpr'
|
||||||
|
p_opt = &curbuf->b_p_inde;
|
||||||
|
}
|
||||||
|
if (varp == &p_pex) { // 'patchexpr'
|
||||||
|
p_opt = &p_pex;
|
||||||
|
}
|
||||||
|
if (varp == &p_pexpr) { // 'printexpr'
|
||||||
|
p_opt = &p_pexpr;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (p_opt != NULL) {
|
||||||
|
char *name = get_scriptlocal_funcname(*p_opt);
|
||||||
|
if (name != NULL) {
|
||||||
|
free_string_option(*p_opt);
|
||||||
|
*p_opt = name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (varp == &curwin->w_p_fde && foldmethodIsExpr(curwin)) {
|
||||||
|
foldUpdateAll(curwin);
|
||||||
|
}
|
||||||
} else if (gvarp == &p_cfu) { // 'completefunc'
|
} else if (gvarp == &p_cfu) { // 'completefunc'
|
||||||
if (set_completefunc_option() == FAIL) {
|
if (set_completefunc_option() == FAIL) {
|
||||||
errmsg = e_invarg;
|
errmsg = e_invarg;
|
||||||
|
@@ -1,4 +1,5 @@
|
|||||||
" Tests for diff mode
|
" Tests for diff mode
|
||||||
|
|
||||||
source shared.vim
|
source shared.vim
|
||||||
source screendump.vim
|
source screendump.vim
|
||||||
source check.vim
|
source check.vim
|
||||||
@@ -681,15 +682,25 @@ func Test_diffexpr()
|
|||||||
set diffexpr=NewDiffFunc()
|
set diffexpr=NewDiffFunc()
|
||||||
call assert_fails('windo diffthis', ['E117:', 'E97:'])
|
call assert_fails('windo diffthis', ['E117:', 'E97:'])
|
||||||
diffoff!
|
diffoff!
|
||||||
|
|
||||||
|
" Using a script-local function
|
||||||
|
func s:NewDiffExpr()
|
||||||
|
endfunc
|
||||||
|
set diffexpr=s:NewDiffExpr()
|
||||||
|
call assert_equal(expand('<SID>') .. 'NewDiffExpr()', &diffexpr)
|
||||||
|
set diffexpr=<SID>NewDiffExpr()
|
||||||
|
call assert_equal(expand('<SID>') .. 'NewDiffExpr()', &diffexpr)
|
||||||
|
|
||||||
%bwipe!
|
%bwipe!
|
||||||
set diffexpr& diffopt&
|
set diffexpr& diffopt&
|
||||||
|
delfunc DiffExpr
|
||||||
|
delfunc s:NewDiffExpr
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
func Test_diffpatch()
|
func Test_diffpatch()
|
||||||
" The patch program on MS-Windows may fail or hang.
|
" The patch program on MS-Windows may fail or hang.
|
||||||
if !executable('patch') || !has('unix')
|
CheckExecutable patch
|
||||||
return
|
CheckUnix
|
||||||
endif
|
|
||||||
new
|
new
|
||||||
insert
|
insert
|
||||||
***************
|
***************
|
||||||
@@ -1250,10 +1261,19 @@ func Test_patchexpr()
|
|||||||
call assert_equal(2, winnr('$'))
|
call assert_equal(2, winnr('$'))
|
||||||
call assert_true(&diff)
|
call assert_true(&diff)
|
||||||
|
|
||||||
|
" Using a script-local function
|
||||||
|
func s:NewPatchExpr()
|
||||||
|
endfunc
|
||||||
|
set patchexpr=s:NewPatchExpr()
|
||||||
|
call assert_equal(expand('<SID>') .. 'NewPatchExpr()', &patchexpr)
|
||||||
|
set patchexpr=<SID>NewPatchExpr()
|
||||||
|
call assert_equal(expand('<SID>') .. 'NewPatchExpr()', &patchexpr)
|
||||||
|
|
||||||
call delete('Xinput')
|
call delete('Xinput')
|
||||||
call delete('Xdiff')
|
call delete('Xdiff')
|
||||||
set patchexpr&
|
set patchexpr&
|
||||||
delfunc TPatch
|
delfunc TPatch
|
||||||
|
delfunc s:NewPatchExpr
|
||||||
%bwipe!
|
%bwipe!
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
@@ -330,6 +330,16 @@ func Test_edit_11_indentexpr()
|
|||||||
set cinkeys&vim indentkeys&vim
|
set cinkeys&vim indentkeys&vim
|
||||||
set nocindent indentexpr=
|
set nocindent indentexpr=
|
||||||
delfu Do_Indent
|
delfu Do_Indent
|
||||||
|
|
||||||
|
" Using a script-local function
|
||||||
|
func s:NewIndentExpr()
|
||||||
|
endfunc
|
||||||
|
set indentexpr=s:NewIndentExpr()
|
||||||
|
call assert_equal(expand('<SID>') .. 'NewIndentExpr()', &indentexpr)
|
||||||
|
set indentexpr=<SID>NewIndentExpr()
|
||||||
|
call assert_equal(expand('<SID>') .. 'NewIndentExpr()', &indentexpr)
|
||||||
|
set indentexpr&
|
||||||
|
|
||||||
bw!
|
bw!
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
@@ -1273,6 +1273,63 @@ func Test_fold_jump()
|
|||||||
bw!
|
bw!
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
" Test for using a script-local function for 'foldexpr'
|
||||||
|
func Test_foldexpr_scriptlocal_func()
|
||||||
|
func! s:FoldFunc()
|
||||||
|
let g:FoldLnum = v:lnum
|
||||||
|
endfunc
|
||||||
|
new | only
|
||||||
|
call setline(1, 'abc')
|
||||||
|
let g:FoldLnum = 0
|
||||||
|
set foldmethod=expr foldexpr=s:FoldFunc()
|
||||||
|
redraw!
|
||||||
|
call assert_equal(expand('<SID>') .. 'FoldFunc()', &foldexpr)
|
||||||
|
call assert_equal(1, g:FoldLnum)
|
||||||
|
set foldmethod& foldexpr=
|
||||||
|
bw!
|
||||||
|
new | only
|
||||||
|
call setline(1, 'abc')
|
||||||
|
let g:FoldLnum = 0
|
||||||
|
set foldmethod=expr foldexpr=<SID>FoldFunc()
|
||||||
|
redraw!
|
||||||
|
call assert_equal(expand('<SID>') .. 'FoldFunc()', &foldexpr)
|
||||||
|
call assert_equal(1, g:FoldLnum)
|
||||||
|
set foldmethod& foldexpr=
|
||||||
|
delfunc s:FoldFunc
|
||||||
|
bw!
|
||||||
|
endfunc
|
||||||
|
|
||||||
|
" Test for using a script-local function for 'foldtext'
|
||||||
|
func Test_foldtext_scriptlocal_func()
|
||||||
|
func! s:FoldText()
|
||||||
|
let g:FoldTextArgs = [v:foldstart, v:foldend]
|
||||||
|
return foldtext()
|
||||||
|
endfunc
|
||||||
|
new | only
|
||||||
|
call setline(1, range(50))
|
||||||
|
let g:FoldTextArgs = []
|
||||||
|
set foldmethod=manual
|
||||||
|
set foldtext=s:FoldText()
|
||||||
|
norm! 4Gzf4j
|
||||||
|
redraw!
|
||||||
|
call assert_equal(expand('<SID>') .. 'FoldText()', &foldtext)
|
||||||
|
call assert_equal([4, 8], g:FoldTextArgs)
|
||||||
|
set foldtext&
|
||||||
|
bw!
|
||||||
|
new | only
|
||||||
|
call setline(1, range(50))
|
||||||
|
let g:FoldTextArgs = []
|
||||||
|
set foldmethod=manual
|
||||||
|
set foldtext=<SID>FoldText()
|
||||||
|
norm! 8Gzf4j
|
||||||
|
redraw!
|
||||||
|
call assert_equal(expand('<SID>') .. 'FoldText()', &foldtext)
|
||||||
|
call assert_equal([8, 12], g:FoldTextArgs)
|
||||||
|
set foldtext&
|
||||||
|
bw!
|
||||||
|
delfunc s:FoldText
|
||||||
|
endfunc
|
||||||
|
|
||||||
" Make sure a fold containing a nested fold is split correctly when using
|
" Make sure a fold containing a nested fold is split correctly when using
|
||||||
" foldmethod=indent
|
" foldmethod=indent
|
||||||
func Test_fold_split()
|
func Test_fold_split()
|
||||||
|
@@ -226,6 +226,32 @@ func Test_gf_includeexpr()
|
|||||||
delfunc IncFunc
|
delfunc IncFunc
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
" Test for using a script-local function for 'includeexpr'
|
||||||
|
func Test_includeexpr_scriptlocal_func()
|
||||||
|
func! s:IncludeFunc()
|
||||||
|
let g:IncludeFname = v:fname
|
||||||
|
return ''
|
||||||
|
endfunc
|
||||||
|
set includeexpr=s:IncludeFunc()
|
||||||
|
call assert_equal(expand('<SID>') .. 'IncludeFunc()', &includeexpr)
|
||||||
|
new | only
|
||||||
|
call setline(1, 'TestFile1')
|
||||||
|
let g:IncludeFname = ''
|
||||||
|
call assert_fails('normal! gf', 'E447:')
|
||||||
|
call assert_equal('TestFile1', g:IncludeFname)
|
||||||
|
bw!
|
||||||
|
set includeexpr=<SID>IncludeFunc()
|
||||||
|
call assert_equal(expand('<SID>') .. 'IncludeFunc()', &includeexpr)
|
||||||
|
new | only
|
||||||
|
call setline(1, 'TestFile2')
|
||||||
|
let g:IncludeFname = ''
|
||||||
|
call assert_fails('normal! gf', 'E447:')
|
||||||
|
call assert_equal('TestFile2', g:IncludeFname)
|
||||||
|
set includeexpr&
|
||||||
|
delfunc s:IncludeFunc
|
||||||
|
bw!
|
||||||
|
endfunc
|
||||||
|
|
||||||
" Check that expanding directories can handle more than 255 entries.
|
" Check that expanding directories can handle more than 255 entries.
|
||||||
func Test_gf_subdirs_wildcard()
|
func Test_gf_subdirs_wildcard()
|
||||||
let cwd = getcwd()
|
let cwd = getcwd()
|
||||||
|
@@ -125,6 +125,14 @@ func Test_printexpr()
|
|||||||
set printexpr=PrintFails(v:fname_in)
|
set printexpr=PrintFails(v:fname_in)
|
||||||
call assert_fails('hardcopy', 'E365:')
|
call assert_fails('hardcopy', 'E365:')
|
||||||
|
|
||||||
|
" Using a script-local function
|
||||||
|
func s:NewPrintExpr()
|
||||||
|
endfunc
|
||||||
|
set printexpr=s:NewPrintExpr()
|
||||||
|
call assert_equal(expand('<SID>') .. 'NewPrintExpr()', &printexpr)
|
||||||
|
set printexpr=<SID>NewPrintExpr()
|
||||||
|
call assert_equal(expand('<SID>') .. 'NewPrintExpr()', &printexpr)
|
||||||
|
|
||||||
set printexpr&
|
set printexpr&
|
||||||
bwipe
|
bwipe
|
||||||
endfunc
|
endfunc
|
||||||
|
@@ -255,6 +255,45 @@ func Test_normal_formatexpr_returns_nonzero()
|
|||||||
close!
|
close!
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
" Test for using a script-local function for 'formatexpr'
|
||||||
|
func Test_formatexpr_scriptlocal_func()
|
||||||
|
func! s:Format()
|
||||||
|
let g:FormatArgs = [v:lnum, v:count]
|
||||||
|
endfunc
|
||||||
|
set formatexpr=s:Format()
|
||||||
|
call assert_equal(expand('<SID>') .. 'Format()', &formatexpr)
|
||||||
|
new | only
|
||||||
|
call setline(1, range(1, 40))
|
||||||
|
let g:FormatArgs = []
|
||||||
|
normal! 2GVjgq
|
||||||
|
call assert_equal([2, 2], g:FormatArgs)
|
||||||
|
bw!
|
||||||
|
set formatexpr=<SID>Format()
|
||||||
|
call assert_equal(expand('<SID>') .. 'Format()', &formatexpr)
|
||||||
|
new | only
|
||||||
|
call setline(1, range(1, 40))
|
||||||
|
let g:FormatArgs = []
|
||||||
|
normal! 4GVjgq
|
||||||
|
call assert_equal([4, 2], g:FormatArgs)
|
||||||
|
bw!
|
||||||
|
let &formatexpr = 's:Format()'
|
||||||
|
new | only
|
||||||
|
call setline(1, range(1, 40))
|
||||||
|
let g:FormatArgs = []
|
||||||
|
normal! 6GVjgq
|
||||||
|
call assert_equal([6, 2], g:FormatArgs)
|
||||||
|
bw!
|
||||||
|
let &formatexpr = '<SID>Format()'
|
||||||
|
new | only
|
||||||
|
call setline(1, range(1, 40))
|
||||||
|
let g:FormatArgs = []
|
||||||
|
normal! 8GVjgq
|
||||||
|
call assert_equal([8, 2], g:FormatArgs)
|
||||||
|
setlocal formatexpr=
|
||||||
|
delfunc s:Format
|
||||||
|
bw!
|
||||||
|
endfunc
|
||||||
|
|
||||||
" basic test for formatprg
|
" basic test for formatprg
|
||||||
func Test_normal06_formatprg()
|
func Test_normal06_formatprg()
|
||||||
" only test on non windows platform
|
" only test on non windows platform
|
||||||
|
Reference in New Issue
Block a user