mirror of
https://github.com/vim/vim.git
synced 2025-09-25 03:54:15 -04:00
patch 8.1.1585: :let-heredoc does not trim enough
Problem: :let-heredoc does not trim enough. Solution: Trim indent from the contents based on the indent of the first line. Use let-heredoc in more tests.
This commit is contained in:
@@ -11565,13 +11565,24 @@ text...
|
||||
If {marker} is not supplied, then "." is used as the
|
||||
default marker.
|
||||
|
||||
Any white space characters in the lines of text are
|
||||
preserved. If "trim" is specified before {marker},
|
||||
then all the leading indentation exactly matching the
|
||||
leading indentation before `let` is stripped from the
|
||||
input lines and the line containing {marker}. Note
|
||||
that the difference between space and tab matters
|
||||
here.
|
||||
Without "trim" any white space characters in the lines
|
||||
of text are preserved. If "trim" is specified before
|
||||
{marker}, then indentation is stripped so you can do: >
|
||||
let text =<< trim END
|
||||
if ok
|
||||
echo 'done'
|
||||
endif
|
||||
END
|
||||
< Results in: ["if ok", " echo 'done'", "endif"]
|
||||
The marker must line up with "let" and the indentation
|
||||
of the first line is removed from all the text lines.
|
||||
Specifically: all the leading indentation exactly
|
||||
matching the leading indentation of the first
|
||||
non-empty text line is stripped from the input lines.
|
||||
All leading indentation exactly matching the leading
|
||||
indentation before `let` is stripped from the line
|
||||
containing {marker}. Note that the difference between
|
||||
space and tab matters here.
|
||||
|
||||
If {var-name} didn't exist yet, it is created.
|
||||
Cannot be followed by another command, but can be
|
||||
|
51
src/eval.c
51
src/eval.c
@@ -1254,7 +1254,9 @@ heredoc_get(exarg_T *eap, char_u *cmd)
|
||||
char_u *marker;
|
||||
list_T *l;
|
||||
char_u *p;
|
||||
int indent_len = 0;
|
||||
int marker_indent_len = 0;
|
||||
int text_indent_len = 0;
|
||||
char_u *text_indent = NULL;
|
||||
|
||||
if (eap->getline == NULL)
|
||||
{
|
||||
@@ -1268,15 +1270,17 @@ heredoc_get(exarg_T *eap, char_u *cmd)
|
||||
{
|
||||
cmd = skipwhite(cmd + 4);
|
||||
|
||||
// Trim the indentation from all the lines in the here document
|
||||
// Trim the indentation from all the lines in the here document.
|
||||
// The amount of indentation trimmed is the same as the indentation of
|
||||
// the :let command line.
|
||||
// the first line after the :let command line. To find the end marker
|
||||
// the indent of the :let command line is trimmed.
|
||||
p = *eap->cmdlinep;
|
||||
while (VIM_ISWHITE(*p))
|
||||
{
|
||||
p++;
|
||||
indent_len++;
|
||||
marker_indent_len++;
|
||||
}
|
||||
text_indent_len = -1;
|
||||
}
|
||||
|
||||
// The marker is the next word. Default marker is "."
|
||||
@@ -1300,31 +1304,50 @@ heredoc_get(exarg_T *eap, char_u *cmd)
|
||||
|
||||
for (;;)
|
||||
{
|
||||
int i = 0;
|
||||
int mi = 0;
|
||||
int ti = 0;
|
||||
|
||||
theline = eap->getline(NUL, eap->cookie, 0);
|
||||
if (theline != NULL && indent_len > 0)
|
||||
{
|
||||
// trim the indent matching the first line
|
||||
if (STRNCMP(theline, *eap->cmdlinep, indent_len) == 0)
|
||||
i = indent_len;
|
||||
}
|
||||
|
||||
if (theline == NULL)
|
||||
{
|
||||
semsg(_("E990: Missing end marker '%s'"), marker);
|
||||
break;
|
||||
}
|
||||
if (STRCMP(marker, theline + i) == 0)
|
||||
|
||||
// with "trim": skip the indent matching the :let line to find the
|
||||
// marker
|
||||
if (marker_indent_len > 0
|
||||
&& STRNCMP(theline, *eap->cmdlinep, marker_indent_len) == 0)
|
||||
mi = marker_indent_len;
|
||||
if (STRCMP(marker, theline + mi) == 0)
|
||||
{
|
||||
vim_free(theline);
|
||||
break;
|
||||
}
|
||||
|
||||
if (list_append_string(l, theline + i, -1) == FAIL)
|
||||
if (text_indent_len == -1 && *theline != NUL)
|
||||
{
|
||||
// set the text indent from the first line.
|
||||
p = theline;
|
||||
text_indent_len = 0;
|
||||
while (VIM_ISWHITE(*p))
|
||||
{
|
||||
p++;
|
||||
text_indent_len++;
|
||||
}
|
||||
text_indent = vim_strnsave(theline, text_indent_len);
|
||||
}
|
||||
// with "trim": skip the indent matching the first line
|
||||
if (text_indent != NULL)
|
||||
for (ti = 0; ti < text_indent_len; ++ti)
|
||||
if (theline[ti] != text_indent[ti])
|
||||
break;
|
||||
|
||||
if (list_append_string(l, theline + ti, -1) == FAIL)
|
||||
break;
|
||||
vim_free(theline);
|
||||
}
|
||||
vim_free(text_indent);
|
||||
|
||||
return l;
|
||||
}
|
||||
|
@@ -13,7 +13,7 @@ if !CanRunVimInTerminal()
|
||||
throw 'Skipped: cannot make screendumps'
|
||||
endif
|
||||
|
||||
let s:common_script =<< [CODE]
|
||||
let s:common_script =<< trim [CODE]
|
||||
call setline(1, ["one one one", "two tXo two", "three three three"])
|
||||
set balloonevalterm balloonexpr=MyBalloonExpr() balloondelay=100
|
||||
func MyBalloonExpr()
|
||||
|
@@ -95,24 +95,24 @@ func Test_cindent_expr()
|
||||
call setline(1, testinput)
|
||||
call cursor(1, 1)
|
||||
call feedkeys("^\<c-v>j$A;\<esc>", 'tnix')
|
||||
let expected =<< trim [CODE]
|
||||
let expected =<< [CODE]
|
||||
var_a = something();
|
||||
b = something();
|
||||
[CODE]
|
||||
b = something();
|
||||
[CODE]
|
||||
call assert_equal(expected, getline(1, '$'))
|
||||
|
||||
%d
|
||||
let testinput =<< trim [CODE]
|
||||
let testinput =<< [CODE]
|
||||
var_a = something()
|
||||
b = something()
|
||||
[CODE]
|
||||
[CODE]
|
||||
call setline(1, testinput)
|
||||
call cursor(1, 1)
|
||||
call feedkeys("^\<c-v>j$A;\<esc>", 'tnix')
|
||||
let expected =<< trim [CODE]
|
||||
let expected =<< [CODE]
|
||||
var_a = something();
|
||||
b = something()
|
||||
[CODE]
|
||||
[CODE]
|
||||
call assert_equal(expected, getline(1, '$'))
|
||||
bw!
|
||||
endfunc
|
||||
@@ -3243,32 +3243,32 @@ func Test_cindent_30()
|
||||
setl cindent ts=4 sw=4
|
||||
setl cino=+20
|
||||
|
||||
let code =<< trim [CODE]
|
||||
let code =<< [CODE]
|
||||
void
|
||||
foo()
|
||||
{
|
||||
foo()
|
||||
{
|
||||
if (a)
|
||||
{
|
||||
} else
|
||||
asdf;
|
||||
}
|
||||
[CODE]
|
||||
}
|
||||
[CODE]
|
||||
|
||||
call append(0, code)
|
||||
normal gg
|
||||
normal ]]=][
|
||||
|
||||
let expected =<< trim [CODE]
|
||||
let expected =<< [CODE]
|
||||
void
|
||||
foo()
|
||||
{
|
||||
foo()
|
||||
{
|
||||
if (a)
|
||||
{
|
||||
} else
|
||||
asdf;
|
||||
}
|
||||
}
|
||||
|
||||
[CODE]
|
||||
[CODE]
|
||||
|
||||
call assert_equal(expected, getline(1, '$'))
|
||||
enew! | close
|
||||
|
@@ -26,27 +26,29 @@ func Test_Debugger()
|
||||
endif
|
||||
|
||||
" Create a Vim script with some functions
|
||||
call writefile([
|
||||
\ 'func Foo()',
|
||||
\ ' let var1 = 1',
|
||||
\ ' let var2 = Bar(var1) + 9',
|
||||
\ ' return var2',
|
||||
\ 'endfunc',
|
||||
\ 'func Bar(var)',
|
||||
\ ' let var1 = 2 + a:var',
|
||||
\ ' let var2 = Bazz(var1) + 4',
|
||||
\ ' return var2',
|
||||
\ 'endfunc',
|
||||
\ 'func Bazz(var)',
|
||||
\ ' try',
|
||||
\ ' let var1 = 3 + a:var',
|
||||
\ ' let var3 = "another var"',
|
||||
\ ' let var3 = "value2"',
|
||||
\ ' catch',
|
||||
\ ' let var4 = "exception"',
|
||||
\ ' endtry',
|
||||
\ ' return var1',
|
||||
\ 'endfunc'], 'Xtest.vim')
|
||||
let lines =<< trim END
|
||||
func Foo()
|
||||
let var1 = 1
|
||||
let var2 = Bar(var1) + 9
|
||||
return var2
|
||||
endfunc
|
||||
func Bar(var)
|
||||
let var1 = 2 + a:var
|
||||
let var2 = Bazz(var1) + 4
|
||||
return var2
|
||||
endfunc
|
||||
func Bazz(var)
|
||||
try
|
||||
let var1 = 3 + a:var
|
||||
let var3 = "another var"
|
||||
let var3 = "value2"
|
||||
catch
|
||||
let var4 = "exception"
|
||||
endtry
|
||||
return var1
|
||||
endfunc
|
||||
END
|
||||
call writefile(lines, 'Xtest.vim')
|
||||
|
||||
" Start Vim in a terminal
|
||||
let buf = RunVimInTerminal('-S Xtest.vim', {})
|
||||
@@ -294,11 +296,13 @@ func Test_Debugger()
|
||||
" Tests for :breakadd file and :breakadd here
|
||||
" Breakpoints should be set before sourcing the file
|
||||
|
||||
call writefile([
|
||||
\ 'let var1 = 10',
|
||||
\ 'let var2 = 20',
|
||||
\ 'let var3 = 30',
|
||||
\ 'let var4 = 40'], 'Xtest.vim')
|
||||
let lines =<< trim END
|
||||
let var1 = 10
|
||||
let var2 = 20
|
||||
let var3 = 30
|
||||
let var4 = 40
|
||||
END
|
||||
call writefile(lines, 'Xtest.vim')
|
||||
|
||||
" Start Vim in a terminal
|
||||
let buf = RunVimInTerminal('Xtest.vim', {})
|
||||
|
@@ -277,13 +277,14 @@ func Test_resolve_win32()
|
||||
if executable('cscript')
|
||||
new Xfile
|
||||
wq
|
||||
call writefile([
|
||||
\ 'Set fs = CreateObject("Scripting.FileSystemObject")',
|
||||
\ 'Set ws = WScript.CreateObject("WScript.Shell")',
|
||||
\ 'Set shortcut = ws.CreateShortcut("Xlink.lnk")',
|
||||
\ 'shortcut.TargetPath = fs.BuildPath(ws.CurrentDirectory, "Xfile")',
|
||||
\ 'shortcut.Save'
|
||||
\], 'link.vbs')
|
||||
let lines =<< trim END
|
||||
Set fs = CreateObject("Scripting.FileSystemObject")
|
||||
Set ws = WScript.CreateObject("WScript.Shell")
|
||||
Set shortcut = ws.CreateShortcut("Xlink.lnk")
|
||||
shortcut.TargetPath = fs.BuildPath(ws.CurrentDirectory, "Xfile")
|
||||
shortcut.Save
|
||||
END
|
||||
call writefile(lines, 'link.vbs')
|
||||
silent !cscript link.vbs
|
||||
call delete('link.vbs')
|
||||
call assert_equal(s:normalize_fname(getcwd() . '\Xfile'), s:normalize_fname(resolve('./Xlink.lnk')))
|
||||
|
@@ -792,10 +792,11 @@ endfunc
|
||||
func Test_gui_dash_g()
|
||||
let cmd = GetVimCommand('Xscriptgui')
|
||||
call writefile([""], "Xtestgui")
|
||||
call writefile([
|
||||
\ 'au GUIEnter * call writefile(["insertmode: " . &insertmode], "Xtestgui")',
|
||||
\ 'au GUIEnter * qall',
|
||||
\ ], 'Xscriptgui')
|
||||
let lines =<< trim END
|
||||
au GUIEnter * call writefile(["insertmode: " . &insertmode], "Xtestgui")
|
||||
au GUIEnter * qall
|
||||
END
|
||||
call writefile(lines, 'Xscriptgui')
|
||||
call system(cmd . ' -g')
|
||||
call WaitForAssert({-> assert_equal(['insertmode: 0'], readfile('Xtestgui'))})
|
||||
|
||||
@@ -807,10 +808,11 @@ endfunc
|
||||
func Test_gui_dash_y()
|
||||
let cmd = GetVimCommand('Xscriptgui')
|
||||
call writefile([""], "Xtestgui")
|
||||
call writefile([
|
||||
\ 'au GUIEnter * call writefile(["insertmode: " . &insertmode], "Xtestgui")',
|
||||
\ 'au GUIEnter * qall',
|
||||
\ ], 'Xscriptgui')
|
||||
let lines =<< trim END
|
||||
au GUIEnter * call writefile(["insertmode: " . &insertmode], "Xtestgui")
|
||||
au GUIEnter * qall
|
||||
END
|
||||
call writefile(lines, 'Xscriptgui')
|
||||
call system(cmd . ' -y')
|
||||
call WaitForAssert({-> assert_equal(['insertmode: 1'], readfile('Xtestgui'))})
|
||||
|
||||
|
@@ -578,12 +578,13 @@ func Test_wincolor()
|
||||
throw 'Skipped: cannot make screendumps'
|
||||
endif
|
||||
|
||||
call writefile([
|
||||
\ 'set cursorline cursorcolumn rnu',
|
||||
\ 'call setline(1, ["","1111111111","22222222222","3 here 3",""])',
|
||||
\ 'set wincolor=Pmenu',
|
||||
\ '/here',
|
||||
\ ], 'Xtest_wincolor')
|
||||
let lines =<< trim END
|
||||
set cursorline cursorcolumn rnu
|
||||
call setline(1, ["","1111111111","22222222222","3 here 3",""])
|
||||
set wincolor=Pmenu
|
||||
/here
|
||||
END
|
||||
call writefile(lines, 'Xtest_wincolor')
|
||||
let buf = RunVimInTerminal('-S Xtest_wincolor', {'rows': 8})
|
||||
call term_wait(buf)
|
||||
call term_sendkeys(buf, "2G5lvj")
|
||||
|
@@ -255,18 +255,18 @@ action();
|
||||
|
||||
" Expected output
|
||||
let expected =<< trim [CODE]
|
||||
{
|
||||
/* Make sure the previous comment leader is not removed. */
|
||||
/* Make sure the previous comment leader is not removed. */
|
||||
// Should the next comment leader be left alone? Yes.
|
||||
// Should the next comment leader be left alone? Yes.
|
||||
/* Here the comment leader should be left intact. */ // And so should this one.
|
||||
/* Here the comment leader should be left intact. */ // And so should this one.
|
||||
if (condition) // Remove the next comment leader! OK, I will.
|
||||
action();
|
||||
if (condition) // Remove the next comment leader! OK, I will.
|
||||
action();
|
||||
}
|
||||
{
|
||||
/* Make sure the previous comment leader is not removed. */
|
||||
/* Make sure the previous comment leader is not removed. */
|
||||
// Should the next comment leader be left alone? Yes.
|
||||
// Should the next comment leader be left alone? Yes.
|
||||
/* Here the comment leader should be left intact. */ // And so should this one.
|
||||
/* Here the comment leader should be left intact. */ // And so should this one.
|
||||
if (condition) // Remove the next comment leader! OK, I will.
|
||||
action();
|
||||
if (condition) // Remove the next comment leader! OK, I will.
|
||||
action();
|
||||
}
|
||||
[CODE]
|
||||
|
||||
call assert_equal(expected, getline(1, '$'))
|
||||
@@ -378,30 +378,30 @@ int i = 7 /* foo *// 3
|
||||
exe "normal oSome code!\<CR>// Make sure backspacing does not remove this comment leader.\<Esc>0i\<C-H>\<Esc>"
|
||||
|
||||
" Expected output
|
||||
let expected =<< [CODE]
|
||||
{
|
||||
/* Make sure the previous comment leader is not removed. */
|
||||
/* Make sure the previous comment leader is not removed. */
|
||||
/* List: item1 foo bar baz foo bar baz item2 foo bar baz foo bar baz */
|
||||
/* List: item1 foo bar baz foo bar baz item2 foo bar baz foo bar baz */
|
||||
// Should the next comment leader be left alone? Yes.
|
||||
// Should the next comment leader be left alone? Yes.
|
||||
/* Here the comment leader should be left intact. */ // And so should this one.
|
||||
/* Here the comment leader should be left intact. */ // And so should this one.
|
||||
if (condition) // Remove the next comment leader! OK, I will.
|
||||
let expected =<< trim [CODE]
|
||||
{
|
||||
/* Make sure the previous comment leader is not removed. */
|
||||
/* Make sure the previous comment leader is not removed. */
|
||||
/* List: item1 foo bar baz foo bar baz item2 foo bar baz foo bar baz */
|
||||
/* List: item1 foo bar baz foo bar baz item2 foo bar baz foo bar baz */
|
||||
// Should the next comment leader be left alone? Yes.
|
||||
// Should the next comment leader be left alone? Yes.
|
||||
/* Here the comment leader should be left intact. */ // And so should this one.
|
||||
/* Here the comment leader should be left intact. */ // And so should this one.
|
||||
if (condition) // Remove the next comment leader! OK, I will.
|
||||
action();
|
||||
if (condition) // Remove the next comment leader! OK, I will.
|
||||
if (condition) // Remove the next comment leader! OK, I will.
|
||||
action();
|
||||
int i = 7 /* foo *// 3 // comment
|
||||
int i = 7 /* foo *// 3 // comment
|
||||
;
|
||||
int i = 7 /* foo *// 3 // comment
|
||||
int i = 7 /* foo *// 3 // comment
|
||||
;
|
||||
># Note that the last character of the ending comment leader (left angle bracket) is a comment leader itself. Make sure that this comment leader is not removed from the next line #< < On this line a new comment is opened which spans 2 lines. This comment should retain its comment leader.
|
||||
># Note that the last character of the ending comment leader (left angle bracket) is a comment leader itself. Make sure that this comment leader is not removed from the next line #< < On this line a new comment is opened which spans 2 lines. This comment should retain its comment leader.
|
||||
># Note that the last character of the ending comment leader (left angle bracket) is a comment leader itself. Make sure that this comment leader is not removed from the next line #< < On this line a new comment is opened which spans 2 lines. This comment should retain its comment leader.
|
||||
># Note that the last character of the ending comment leader (left angle bracket) is a comment leader itself. Make sure that this comment leader is not removed from the next line #< < On this line a new comment is opened which spans 2 lines. This comment should retain its comment leader.
|
||||
|
||||
Some code!// Make sure backspacing does not remove this comment leader.
|
||||
}
|
||||
[CODE]
|
||||
Some code!// Make sure backspacing does not remove this comment leader.
|
||||
}
|
||||
[CODE]
|
||||
|
||||
call assert_equal(expected, getline(1, '$'))
|
||||
close!
|
||||
|
@@ -210,10 +210,18 @@ END
|
||||
END
|
||||
call assert_equal(['Line1', ' Line2', "\tLine3", ' END'], var1)
|
||||
|
||||
let var1 =<< trim !!!
|
||||
Line1
|
||||
line2
|
||||
Line3
|
||||
!!!
|
||||
!!!
|
||||
call assert_equal(['Line1', ' line2', "\tLine3", '!!!',], var1)
|
||||
|
||||
let var1 =<< trim
|
||||
Line1
|
||||
.
|
||||
call assert_equal([' Line1'], var1)
|
||||
call assert_equal(['Line1'], var1)
|
||||
|
||||
" ignore "endfunc"
|
||||
let var1 =<< END
|
||||
|
@@ -85,14 +85,15 @@ func Test_memory_func_capture_vargs()
|
||||
" Case: if a local variable captures a:000, funccall object will be free
|
||||
" just after it finishes.
|
||||
let testfile = 'Xtest.vim'
|
||||
call writefile([
|
||||
\ 'func s:f(...)',
|
||||
\ ' let x = a:000',
|
||||
\ 'endfunc',
|
||||
\ 'for _ in range(10000)',
|
||||
\ ' call s:f(0)',
|
||||
\ 'endfor',
|
||||
\ ], testfile)
|
||||
let lines =<< trim END
|
||||
func s:f(...)
|
||||
let x = a:000
|
||||
endfunc
|
||||
for _ in range(10000)
|
||||
call s:f(0)
|
||||
endfor
|
||||
END
|
||||
call writefile(lines, testfile)
|
||||
|
||||
let vim = s:vim_new()
|
||||
call vim.start('--clean', '-c', 'set noswapfile', testfile)
|
||||
@@ -122,14 +123,15 @@ func Test_memory_func_capture_lvars()
|
||||
" free until garbage collector runs, but after that memory usage doesn't
|
||||
" increase so much even when rerun Xtest.vim since system memory caches.
|
||||
let testfile = 'Xtest.vim'
|
||||
call writefile([
|
||||
\ 'func s:f()',
|
||||
\ ' let x = l:',
|
||||
\ 'endfunc',
|
||||
\ 'for _ in range(10000)',
|
||||
\ ' call s:f()',
|
||||
\ 'endfor',
|
||||
\ ], testfile)
|
||||
let lines =<< trim END
|
||||
func s:f()
|
||||
let x = l:
|
||||
endfunc
|
||||
for _ in range(10000)
|
||||
call s:f()
|
||||
endfor
|
||||
END
|
||||
call writefile(lines, testfile)
|
||||
|
||||
let vim = s:vim_new()
|
||||
call vim.start('--clean', '-c', 'set noswapfile', testfile)
|
||||
|
@@ -102,13 +102,14 @@ func Test_mode_message_at_leaving_insert_by_ctrl_c()
|
||||
|
||||
" Set custom statusline built by user-defined function.
|
||||
let testfile = 'Xtest.vim'
|
||||
call writefile([
|
||||
\ 'func StatusLine() abort',
|
||||
\ ' return ""',
|
||||
\ 'endfunc',
|
||||
\ 'set statusline=%!StatusLine()',
|
||||
\ 'set laststatus=2',
|
||||
\ ], testfile)
|
||||
let lines =<< trim END
|
||||
func StatusLine() abort
|
||||
return ""
|
||||
endfunc
|
||||
set statusline=%!StatusLine()
|
||||
set laststatus=2
|
||||
END
|
||||
call writefile(lines, testfile)
|
||||
|
||||
let rows = 10
|
||||
let buf = term_start([GetVimProg(), '--clean', '-S', testfile], {'term_rows': rows})
|
||||
@@ -133,10 +134,11 @@ func Test_mode_message_at_leaving_insert_with_esc_mapped()
|
||||
|
||||
" Set custom statusline built by user-defined function.
|
||||
let testfile = 'Xtest.vim'
|
||||
call writefile([
|
||||
\ 'set laststatus=2',
|
||||
\ 'inoremap <Esc> <Esc>00',
|
||||
\ ], testfile)
|
||||
let lines =<< trim END
|
||||
set laststatus=2
|
||||
inoremap <Esc> <Esc>00
|
||||
END
|
||||
call writefile(lines, testfile)
|
||||
|
||||
let rows = 10
|
||||
let buf = term_start([GetVimProg(), '--clean', '-S', testfile], {'term_rows': rows})
|
||||
|
@@ -737,12 +737,13 @@ func Test_popup_and_previewwindow_dump()
|
||||
if !CanRunVimInTerminal()
|
||||
throw 'Skipped: cannot make screendumps'
|
||||
endif
|
||||
call writefile([
|
||||
\ 'set previewheight=9',
|
||||
\ 'silent! pedit',
|
||||
\ 'call setline(1, map(repeat(["ab"], 10), "v:val. v:key"))',
|
||||
\ 'exec "norm! G\<C-E>\<C-E>"',
|
||||
\ ], 'Xscript')
|
||||
let lines =<< trim END
|
||||
set previewheight=9
|
||||
silent! pedit
|
||||
call setline(1, map(repeat(["ab"], 10), "v:val. v:key"))
|
||||
exec "norm! G\<C-E>\<C-E>"
|
||||
END
|
||||
call writefile(lines, 'Xscript')
|
||||
let buf = RunVimInTerminal('-S Xscript', {})
|
||||
|
||||
" Test that popup and previewwindow do not overlap.
|
||||
@@ -799,11 +800,12 @@ func Test_popup_position()
|
||||
if !CanRunVimInTerminal()
|
||||
throw 'Skipped: cannot make screendumps'
|
||||
endif
|
||||
call writefile([
|
||||
\ '123456789_123456789_123456789_a',
|
||||
\ '123456789_123456789_123456789_b',
|
||||
\ ' 123',
|
||||
\ ], 'Xtest')
|
||||
let lines =<< trim END
|
||||
123456789_123456789_123456789_a
|
||||
123456789_123456789_123456789_b
|
||||
123
|
||||
END
|
||||
call writefile(lines, 'Xtest')
|
||||
let buf = RunVimInTerminal('Xtest', {})
|
||||
call term_sendkeys(buf, ":vsplit\<CR>")
|
||||
|
||||
@@ -842,11 +844,12 @@ func Test_popup_command()
|
||||
throw 'Skipped: cannot make screendumps and/or menu feature missing'
|
||||
endif
|
||||
|
||||
call writefile([
|
||||
\ 'one two three four five',
|
||||
\ 'and one two Xthree four five',
|
||||
\ 'one more two three four five',
|
||||
\ ], 'Xtest')
|
||||
let lines =<< trim END
|
||||
one two three four five
|
||||
and one two Xthree four five
|
||||
one more two three four five
|
||||
END
|
||||
call writefile(lines, 'Xtest')
|
||||
let buf = RunVimInTerminal('Xtest', {})
|
||||
call term_sendkeys(buf, ":source $VIMRUNTIME/menu.vim\<CR>")
|
||||
call term_sendkeys(buf, "/X\<CR>:popup PopUp\<CR>")
|
||||
|
@@ -9,16 +9,17 @@ func Test_simple_popup()
|
||||
if !CanRunVimInTerminal()
|
||||
throw 'Skipped: cannot make screendumps'
|
||||
endif
|
||||
call writefile([
|
||||
\ "call setline(1, range(1, 100))",
|
||||
\ "hi PopupColor1 ctermbg=lightblue",
|
||||
\ "hi PopupColor2 ctermbg=lightcyan",
|
||||
\ "hi Comment ctermfg=red",
|
||||
\ "call prop_type_add('comment', {'highlight': 'Comment'})",
|
||||
\ "let winid = popup_create('hello there', {'line': 3, 'col': 11, 'minwidth': 20, 'highlight': 'PopupColor1'})",
|
||||
\ "let winid2 = popup_create(['another one', 'another two', 'another three'], {'line': 3, 'col': 25, 'minwidth': 20})",
|
||||
\ "call setwinvar(winid2, '&wincolor', 'PopupColor2')",
|
||||
\], 'XtestPopup')
|
||||
let lines =<< trim END
|
||||
call setline(1, range(1, 100))
|
||||
hi PopupColor1 ctermbg=lightblue
|
||||
hi PopupColor2 ctermbg=lightcyan
|
||||
hi Comment ctermfg=red
|
||||
call prop_type_add('comment', {'highlight': 'Comment'})
|
||||
let winid = popup_create('hello there', {'line': 3, 'col': 11, 'minwidth': 20, 'highlight': 'PopupColor1'})
|
||||
let winid2 = popup_create(['another one', 'another two', 'another three'], {'line': 3, 'col': 25, 'minwidth': 20})
|
||||
call setwinvar(winid2, '&wincolor', 'PopupColor2')
|
||||
END
|
||||
call writefile(lines, 'XtestPopup')
|
||||
let buf = RunVimInTerminal('-S XtestPopup', {'rows': 10})
|
||||
call VerifyScreenDump(buf, 'Test_popupwin_01', {})
|
||||
|
||||
@@ -80,16 +81,18 @@ func Test_popup_with_border_and_padding()
|
||||
endif
|
||||
|
||||
for iter in range(0, 1)
|
||||
call writefile([iter == 1 ? '' : 'set enc=latin1',
|
||||
\ "call setline(1, range(1, 100))",
|
||||
\ "call popup_create('hello border', {'line': 2, 'col': 3, 'border': []})",
|
||||
\ "call popup_create('hello padding', {'line': 2, 'col': 23, 'padding': []})",
|
||||
\ "call popup_create('hello both', {'line': 2, 'col': 43, 'border': [], 'padding': []})",
|
||||
\ "call popup_create('border TL', {'line': 6, 'col': 3, 'border': [1, 0, 0, 4]})",
|
||||
\ "call popup_create('paddings', {'line': 6, 'col': 23, 'padding': [1, 3, 2, 4]})",
|
||||
\ "call popup_create('wrapped longer text', {'line': 8, 'col': 55, 'padding': [0, 3, 0, 3], 'border': [0, 1, 0, 1]})",
|
||||
\ "call popup_create('right aligned text', {'line': 11, 'col': 56, 'wrap': 0, 'padding': [0, 3, 0, 3], 'border': [0, 1, 0, 1]})",
|
||||
\], 'XtestPopupBorder')
|
||||
let lines =<< trim END
|
||||
call setline(1, range(1, 100))
|
||||
call popup_create('hello border', {'line': 2, 'col': 3, 'border': []})
|
||||
call popup_create('hello padding', {'line': 2, 'col': 23, 'padding': []})
|
||||
call popup_create('hello both', {'line': 2, 'col': 43, 'border': [], 'padding': []})
|
||||
call popup_create('border TL', {'line': 6, 'col': 3, 'border': [1, 0, 0, 4]})
|
||||
call popup_create('paddings', {'line': 6, 'col': 23, 'padding': [1, 3, 2, 4]})
|
||||
call popup_create('wrapped longer text', {'line': 8, 'col': 55, 'padding': [0, 3, 0, 3], 'border': [0, 1, 0, 1]})
|
||||
call popup_create('right aligned text', {'line': 11, 'col': 56, 'wrap': 0, 'padding': [0, 3, 0, 3], 'border': [0, 1, 0, 1]})
|
||||
END
|
||||
call insert(lines, iter == 1 ? '' : 'set enc=latin1')
|
||||
call writefile(lines, 'XtestPopupBorder')
|
||||
let buf = RunVimInTerminal('-S XtestPopupBorder', {'rows': 15})
|
||||
call VerifyScreenDump(buf, 'Test_popupwin_2' .. iter, {})
|
||||
|
||||
@@ -97,20 +100,21 @@ func Test_popup_with_border_and_padding()
|
||||
call delete('XtestPopupBorder')
|
||||
endfor
|
||||
|
||||
call writefile([
|
||||
\ "call setline(1, range(1, 100))",
|
||||
\ "hi BlueColor ctermbg=lightblue",
|
||||
\ "hi TopColor ctermbg=253",
|
||||
\ "hi RightColor ctermbg=245",
|
||||
\ "hi BottomColor ctermbg=240",
|
||||
\ "hi LeftColor ctermbg=248",
|
||||
\ "call popup_create('hello border', {'line': 2, 'col': 3, 'border': [], 'borderhighlight': ['BlueColor']})",
|
||||
\ "call popup_create(['hello border', 'and more'], {'line': 2, 'col': 23, 'border': [], 'borderhighlight': ['TopColor', 'RightColor', 'BottomColor', 'LeftColor']})",
|
||||
\ "call popup_create(['hello border', 'lines only'], {'line': 2, 'col': 43, 'border': [], 'borderhighlight': ['BlueColor'], 'borderchars': ['x']})",
|
||||
\ "call popup_create(['hello border', 'with corners'], {'line': 2, 'col': 60, 'border': [], 'borderhighlight': ['BlueColor'], 'borderchars': ['x', '#']})",
|
||||
\ "let winid = popup_create(['hello border', 'with numbers'], {'line': 6, 'col': 3, 'border': [], 'borderhighlight': ['BlueColor'], 'borderchars': ['0', '1', '2', '3', '4', '5', '6', '7']})",
|
||||
\ "call popup_create(['hello border', 'just blanks'], {'line': 7, 'col': 23, 'border': [], 'borderhighlight': ['BlueColor'], 'borderchars': [' ']})",
|
||||
\], 'XtestPopupBorder')
|
||||
let lines =<< trim END
|
||||
call setline(1, range(1, 100))
|
||||
hi BlueColor ctermbg=lightblue
|
||||
hi TopColor ctermbg=253
|
||||
hi RightColor ctermbg=245
|
||||
hi BottomColor ctermbg=240
|
||||
hi LeftColor ctermbg=248
|
||||
call popup_create('hello border', {'line': 2, 'col': 3, 'border': [], 'borderhighlight': ['BlueColor']})
|
||||
call popup_create(['hello border', 'and more'], {'line': 2, 'col': 23, 'border': [], 'borderhighlight': ['TopColor', 'RightColor', 'BottomColor', 'LeftColor']})
|
||||
call popup_create(['hello border', 'lines only'], {'line': 2, 'col': 43, 'border': [], 'borderhighlight': ['BlueColor'], 'borderchars': ['x']})
|
||||
call popup_create(['hello border', 'with corners'], {'line': 2, 'col': 60, 'border': [], 'borderhighlight': ['BlueColor'], 'borderchars': ['x', '#']})
|
||||
let winid = popup_create(['hello border', 'with numbers'], {'line': 6, 'col': 3, 'border': [], 'borderhighlight': ['BlueColor'], 'borderchars': ['0', '1', '2', '3', '4', '5', '6', '7']})
|
||||
call popup_create(['hello border', 'just blanks'], {'line': 7, 'col': 23, 'border': [], 'borderhighlight': ['BlueColor'], 'borderchars': [' ']})
|
||||
END
|
||||
call writefile(lines, 'XtestPopupBorder')
|
||||
let buf = RunVimInTerminal('-S XtestPopupBorder', {'rows': 12})
|
||||
call VerifyScreenDump(buf, 'Test_popupwin_22', {})
|
||||
|
||||
@@ -176,18 +180,19 @@ func Test_popup_with_syntax_win_execute()
|
||||
if !CanRunVimInTerminal()
|
||||
throw 'Skipped: cannot make screendumps'
|
||||
endif
|
||||
call writefile([
|
||||
\ "call setline(1, range(1, 100))",
|
||||
\ "hi PopupColor ctermbg=lightblue",
|
||||
\ "let winid = popup_create([",
|
||||
\ "\\ '#include <stdio.h>',",
|
||||
\ "\\ 'int main(void)',",
|
||||
\ "\\ '{',",
|
||||
\ "\\ ' printf(123);',",
|
||||
\ "\\ '}',",
|
||||
\ "\\], {'line': 3, 'col': 25, 'highlight': 'PopupColor'})",
|
||||
\ "call win_execute(winid, 'set syntax=cpp')",
|
||||
\], 'XtestPopup')
|
||||
let lines =<< trim END
|
||||
call setline(1, range(1, 100))
|
||||
hi PopupColor ctermbg=lightblue
|
||||
let winid = popup_create([
|
||||
\ '#include <stdio.h>',
|
||||
\ 'int main(void)',
|
||||
\ '{',
|
||||
\ ' printf(123);',
|
||||
\ '}',
|
||||
\], {'line': 3, 'col': 25, 'highlight': 'PopupColor'})
|
||||
call win_execute(winid, 'set syntax=cpp')
|
||||
END
|
||||
call writefile(lines, 'XtestPopup')
|
||||
let buf = RunVimInTerminal('-S XtestPopup', {'rows': 10})
|
||||
call VerifyScreenDump(buf, 'Test_popupwin_10', {})
|
||||
|
||||
@@ -356,6 +361,43 @@ func Test_popup_drag()
|
||||
call delete('XtestPopupDrag')
|
||||
endfunc
|
||||
|
||||
func Test_popup_with_mask()
|
||||
if !CanRunVimInTerminal()
|
||||
throw 'Skipped: cannot make screendumps'
|
||||
endif
|
||||
let lines =<< trim END
|
||||
call setline(1, repeat([join(range(1, 40), '')], 10))
|
||||
hi PopupColor ctermbg=lightgrey
|
||||
let winid = popup_create([
|
||||
\ 'some text',
|
||||
\ 'another line',
|
||||
\], {
|
||||
\ 'line': 2,
|
||||
\ 'col': 10,
|
||||
\ 'zindex': 90,
|
||||
\ 'padding': [],
|
||||
\ 'highlight': 'PopupColor',
|
||||
\ 'mask': [[1,1,1,1], [-5,-1,4,4], [7,9,2,3], [2,4,3,3]]})
|
||||
call popup_create([
|
||||
\ 'xxxxxxxxx',
|
||||
\ 'yyyyyyyyy',
|
||||
\], {
|
||||
\ 'line': 3,
|
||||
\ 'col': 18,
|
||||
\ 'zindex': 20})
|
||||
END
|
||||
call writefile(lines, 'XtestPopupMask')
|
||||
let buf = RunVimInTerminal('-S XtestPopupMask', {'rows': 10})
|
||||
call VerifyScreenDump(buf, 'Test_popupwin_mask_1', {})
|
||||
|
||||
call term_sendkeys(buf, ":call popup_move(winid, {'col': 11, 'line': 3})\<CR>")
|
||||
call VerifyScreenDump(buf, 'Test_popupwin_mask_2', {})
|
||||
|
||||
" clean up
|
||||
call StopVimInTerminal(buf)
|
||||
call delete('XtestPopupMask')
|
||||
endfunc
|
||||
|
||||
func Test_popup_select()
|
||||
if !CanRunVimInTerminal()
|
||||
throw 'Skipped: cannot make screendumps'
|
||||
|
@@ -856,7 +856,7 @@ func Test_efm1()
|
||||
call writefile(l, 'Xerrorfile1')
|
||||
call writefile(l[:-2], 'Xerrorfile2')
|
||||
|
||||
let m =<< trim [DATA]
|
||||
let m =<< [DATA]
|
||||
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 2
|
||||
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 3
|
||||
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 4
|
||||
@@ -878,7 +878,7 @@ func Test_efm1()
|
||||
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 20
|
||||
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 21
|
||||
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx line 22
|
||||
[DATA]
|
||||
[DATA]
|
||||
call writefile(m, 'Xtestfile')
|
||||
|
||||
let save_efm = &efm
|
||||
|
@@ -777,6 +777,8 @@ static char *(features[]) =
|
||||
|
||||
static int included_patches[] =
|
||||
{ /* Add new patch number below this line */
|
||||
/**/
|
||||
1585,
|
||||
/**/
|
||||
1584,
|
||||
/**/
|
||||
|
Reference in New Issue
Block a user