Merge #9970 from janlazo/vim-8.1.0794

vim-patch:8.0.1708,8.1.{369,794,1242}
This commit is contained in:
Justin M. Keyes
2019-05-03 11:03:49 +02:00
committed by GitHub
8 changed files with 137 additions and 45 deletions

View File

@@ -432,6 +432,16 @@ flag when defining the function, it is not relevant when executing it. >
. .
:endfunction :endfunction
:set cpo-=C :set cpo-=C
<
*line-continuation-comment*
To add a comment in between the lines start with '\" '. Notice the space
after the double quote. Example: >
let array = [
"\ first entry comment
\ 'first',
"\ second entry comment
\ 'second',
\ ]
Rationale: Rationale:
Most programs work with a trailing backslash to indicate line Most programs work with a trailing backslash to indicate line
@@ -440,6 +450,14 @@ Rationale:
:map xx asdf\ :map xx asdf\
< Therefore the unusual leading backslash is used. < Therefore the unusual leading backslash is used.
Starting a comment in a continuation line results in all following
continuation lines to be part of the comment. Since it was like this
for a long time, when making it possible to add a comment halfway a
sequence of continuation lines, it was not possible to use \", since
that was a valid continuation line. Using '"\ ' comes closest, even
though it may look a bit weird. Requiring the space after the
backslash is to make it very unlikely this is a normal comment line.
============================================================================== ==============================================================================
5. Using Vim packages *packages* 5. Using Vim packages *packages*

View File

@@ -10,7 +10,7 @@ endif
let b:did_indent = 1 let b:did_indent = 1
setlocal indentexpr=GetVimIndent() setlocal indentexpr=GetVimIndent()
setlocal indentkeys+==end,=else,=cat,=fina,=END,0\\ setlocal indentkeys+==end,=else,=cat,=fina,=END,0\\,0=\"\\\
let b:undo_indent = "setl indentkeys< indentexpr<" let b:undo_indent = "setl indentkeys< indentexpr<"
@@ -31,15 +31,17 @@ function GetVimIndent()
endtry endtry
endfunc endfunc
let s:lineContPat = '^\s*\(\\\|"\\ \)'
function GetVimIndentIntern() function GetVimIndentIntern()
" Find a non-blank line above the current line. " Find a non-blank line above the current line.
let lnum = prevnonblank(v:lnum - 1) let lnum = prevnonblank(v:lnum - 1)
" If the current line doesn't start with '\' and below a line that starts " If the current line doesn't start with '\' or '"\ ' and below a line that
" with '\', use the indent of the line above it. " starts with '\' or '"\ ', use the indent of the line above it.
let cur_text = getline(v:lnum) let cur_text = getline(v:lnum)
if cur_text !~ '^\s*\\' if cur_text !~ s:lineContPat
while lnum > 0 && getline(lnum) =~ '^\s*\\' while lnum > 0 && getline(lnum) =~ s:lineContPat
let lnum = lnum - 1 let lnum = lnum - 1
endwhile endwhile
endif endif
@@ -51,10 +53,10 @@ function GetVimIndentIntern()
let prev_text = getline(lnum) let prev_text = getline(lnum)
" Add a 'shiftwidth' after :if, :while, :try, :catch, :finally, :function " Add a 'shiftwidth' after :if, :while, :try, :catch, :finally, :function
" and :else. Add it three times for a line that starts with '\' after " and :else. Add it three times for a line that starts with '\' or '"\ '
" a line that doesn't (or g:vim_indent_cont if it exists). " after a line that doesn't (or g:vim_indent_cont if it exists).
let ind = indent(lnum) let ind = indent(lnum)
if cur_text =~ '^\s*\\' && v:lnum > 1 && prev_text !~ '^\s*\\' if cur_text =~ s:lineContPat && v:lnum > 1 && prev_text !~ s:lineContPat
if exists("g:vim_indent_cont") if exists("g:vim_indent_cont")
let ind = ind + g:vim_indent_cont let ind = ind + g:vim_indent_cont
else else

View File

@@ -12880,33 +12880,36 @@ static void f_mkdir(typval_T *argvars, typval_T *rettv, FunPtr fptr)
char buf[NUMBUFLEN]; char buf[NUMBUFLEN];
const char *const dir = tv_get_string_buf(&argvars[0], buf); const char *const dir = tv_get_string_buf(&argvars[0], buf);
if (*dir == NUL) { if (*dir == NUL) {
rettv->vval.v_number = FAIL; return;
} else {
if (*path_tail((char_u *)dir) == NUL) {
// Remove trailing slashes.
*path_tail_with_sep((char_u *)dir) = NUL;
}
if (argvars[1].v_type != VAR_UNKNOWN) {
if (argvars[2].v_type != VAR_UNKNOWN) {
prot = tv_get_number_chk(&argvars[2], NULL);
}
if (prot != -1 && strcmp(tv_get_string(&argvars[1]), "p") == 0) {
char *failed_dir;
int ret = os_mkdir_recurse(dir, prot, &failed_dir);
if (ret != 0) {
EMSG3(_(e_mkdir), failed_dir, os_strerror(ret));
xfree(failed_dir);
rettv->vval.v_number = FAIL;
return;
} else {
rettv->vval.v_number = OK;
return;
}
}
}
rettv->vval.v_number = prot == -1 ? FAIL : vim_mkdir_emsg(dir, prot);
} }
if (*path_tail((char_u *)dir) == NUL) {
// Remove trailing slashes.
*path_tail_with_sep((char_u *)dir) = NUL;
}
if (argvars[1].v_type != VAR_UNKNOWN) {
if (argvars[2].v_type != VAR_UNKNOWN) {
prot = tv_get_number_chk(&argvars[2], NULL);
if (prot == -1) {
return;
}
}
if (strcmp(tv_get_string(&argvars[1]), "p") == 0) {
char *failed_dir;
int ret = os_mkdir_recurse(dir, prot, &failed_dir);
if (ret != 0) {
EMSG3(_(e_mkdir), failed_dir, os_strerror(ret));
xfree(failed_dir);
rettv->vval.v_number = FAIL;
return;
} else {
rettv->vval.v_number = OK;
return;
}
}
}
rettv->vval.v_number = vim_mkdir_emsg(dir, prot);
} }
/// "mode()" function /// "mode()" function

View File

@@ -3403,13 +3403,18 @@ char_u *getsourceline(int c, void *cookie, int indent)
// Get the next line and concatenate it when it starts with a // Get the next line and concatenate it when it starts with a
// backslash. We always need to read the next line, keep it in // backslash. We always need to read the next line, keep it in
// sp->nextline. // sp->nextline.
// Also check for a comment in between continuation lines: "\ .
sp->nextline = get_one_sourceline(sp); sp->nextline = get_one_sourceline(sp);
if (sp->nextline != NULL && *(p = skipwhite(sp->nextline)) == '\\') { if (sp->nextline != NULL
&& (*(p = skipwhite(sp->nextline)) == '\\'
|| (p[0] == '"' && p[1] == '\\' && p[2] == ' '))) {
garray_T ga; garray_T ga;
ga_init(&ga, (int)sizeof(char_u), 400); ga_init(&ga, (int)sizeof(char_u), 400);
ga_concat(&ga, line); ga_concat(&ga, line);
ga_concat(&ga, p + 1); if (*p == '\\') {
ga_concat(&ga, p + 1);
}
for (;; ) { for (;; ) {
xfree(sp->nextline); xfree(sp->nextline);
sp->nextline = get_one_sourceline(sp); sp->nextline = get_one_sourceline(sp);
@@ -3417,15 +3422,16 @@ char_u *getsourceline(int c, void *cookie, int indent)
break; break;
} }
p = skipwhite(sp->nextline); p = skipwhite(sp->nextline);
if (*p != '\\') { if (*p == '\\') {
// Adjust the growsize to the current length to speed up
// concatenating many lines.
if (ga.ga_len > 400) {
ga_set_growsize(&ga, (ga.ga_len > 8000) ? 8000 : ga.ga_len);
}
ga_concat(&ga, p + 1);
} else if (p[0] != '"' || p[1] != '\\' || p[2] != ' ') {
break; break;
} }
// Adjust the growsize to the current length to speed up
// concatenating many lines.
if (ga.ga_len > 400) {
ga_set_growsize(&ga, (ga.ga_len > 8000) ? 8000 : ga.ga_len);
}
ga_concat(&ga, p + 1);
} }
ga_append(&ga, NUL); ga_append(&ga, NUL);
xfree(line); xfree(line);

View File

@@ -4505,8 +4505,8 @@ static int get_tabpage_arg(exarg_T *eap)
tab_number = 0; tab_number = 0;
} else { } else {
tab_number = eap->line2; tab_number = eap->line2;
if (!unaccept_arg0 && **eap->cmdlinep == '-') { if (!unaccept_arg0 && *skipwhite(*eap->cmdlinep) == '-') {
--tab_number; tab_number--;
if (tab_number < unaccept_arg0) { if (tab_number < unaccept_arg0) {
eap->errmsg = e_invarg; eap->errmsg = e_invarg;
} }

View File

@@ -21,3 +21,31 @@ func Test_E963()
call assert_fails("let v:oldfiles=''", 'E963:') call assert_fails("let v:oldfiles=''", 'E963:')
call assert_equal(v_o, v:oldfiles) call assert_equal(v_o, v:oldfiles)
endfunc endfunc
func Test_mkdir_p()
call mkdir('Xmkdir/nested', 'p')
call assert_true(isdirectory('Xmkdir/nested'))
try
" Trying to make existing directories doesn't error
call mkdir('Xmkdir', 'p')
call mkdir('Xmkdir/nested', 'p')
catch /E739:/
call assert_report('mkdir(..., "p") failed for an existing directory')
endtry
" 'p' doesn't suppress real errors
call writefile([], 'Xfile')
call assert_fails('call mkdir("Xfile", "p")', 'E739')
call delete('Xfile')
call delete('Xmkdir', 'rf')
endfunc
func Test_line_continuation()
let array = [5,
"\ ignore this
\ 6,
"\ more to ignore
"\ more moreto ignore
\ ]
"\ and some more
call assert_equal([5, 6], array)
endfunc

View File

@@ -1,5 +1,6 @@
" Tests for tabpage " Tests for tabpage
" source screendump.vim
function Test_tabpage() function Test_tabpage()
bw! bw!
@@ -105,6 +106,14 @@ function Test_tabpage()
call assert_equal(4, tabpagenr()) call assert_equal(4, tabpagenr())
7tabmove 5 7tabmove 5
call assert_equal(5, tabpagenr()) call assert_equal(5, tabpagenr())
-tabmove
call assert_equal(4, tabpagenr())
+tabmove
call assert_equal(5, tabpagenr())
-2tabmove
call assert_equal(3, tabpagenr())
+3tabmove
call assert_equal(6, tabpagenr())
" The following are a no-op " The following are a no-op
norm! 2gt norm! 2gt
@@ -547,4 +556,27 @@ func Test_tabs()
bw! bw!
endfunc endfunc
func Test_tabpage_cmdheight()
if !CanRunVimInTerminal()
throw 'Skipped: only works with terminal'
endif
call writefile([
\ 'set laststatus=2',
\ 'set cmdheight=2',
\ 'tabnew',
\ 'set cmdheight=3',
\ 'tabnext',
\ 'redraw!',
\ 'echo "hello\nthere"',
\ 'tabnext',
\ 'redraw',
\ ], 'XTest_tabpage_cmdheight')
" Check that cursor line is concealed
let buf = RunVimInTerminal('-S XTest_tabpage_cmdheight', {'statusoff': 3})
call VerifyScreenDump(buf, 'Test_tabpage_cmdheight', {})
call StopVimInTerminal(buf)
call delete('XTest_conceal')
endfunc
" vim: shiftwidth=2 sts=2 expandtab " vim: shiftwidth=2 sts=2 expandtab

View File

@@ -3793,6 +3793,9 @@ static void enter_tabpage(tabpage_T *tp, buf_T *old_curbuf, int trigger_enter_au
* the frames for that. When the Vim window was resized need to update * the frames for that. When the Vim window was resized need to update
* frame sizes too. Use the stored value of p_ch, so that it can be * frame sizes too. Use the stored value of p_ch, so that it can be
* different for each tab page. */ * different for each tab page. */
if (p_ch != curtab->tp_ch_used) {
clear_cmdline = true;
}
p_ch = curtab->tp_ch_used; p_ch = curtab->tp_ch_used;
if (curtab->tp_old_Rows != Rows || (old_off != firstwin->w_winrow if (curtab->tp_old_Rows != Rows || (old_off != firstwin->w_winrow
)) ))