Skip to content

Commit 5e66b42

Browse files
committed
patch 8.1.0815: dialog for file changed outside of Vim not tested
Problem: Dialog for file changed outside of Vim not tested. Solution: Add a test. Move FileChangedShell test. Add 'L' flag to feedkeys().
1 parent ed18f2c commit 5e66b42

6 files changed

Lines changed: 217 additions & 120 deletions

File tree

runtime/doc/eval.txt

Lines changed: 53 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*eval.txt* For Vim version 8.1. Last change: 2019 Jan 21
1+
*eval.txt* For Vim version 8.1. Last change: 2019 Jan 24
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -662,6 +662,16 @@ is not available it returns -1 or the default value you specify: >
662662
:echo get(myblob, idx, 999)
663663
664664
665+
Blob iteration ~
666+
667+
The |:for| loop executes commands for each byte of a Blob. The loop variable is
668+
set to each byte in the Blob. Example: >
669+
:for byte in 0z112233
670+
: call Doit(byte)
671+
:endfor
672+
This calls Doit() with 0x11, 0x22 and 0x33.
673+
674+
665675
Blob concatenation ~
666676

667677
Two blobs can be concatenated with the "+" operator: >
@@ -793,8 +803,9 @@ Expression syntax summary, from least to most significant:
793803
etc. As above, append ? for ignoring case, # for
794804
matching case
795805

796-
expr5 is expr5 same |List| instance
797-
expr5 isnot expr5 different |List| instance
806+
expr5 is expr5 same |List|, |Dictionary| or |Blob| instance
807+
expr5 isnot expr5 different |List|, |Dictionary| or |Blob|
808+
instance
798809

799810
|expr5| expr6
800811
expr6 + expr6 .. number addition, list or blob concatenation
@@ -962,12 +973,12 @@ Dictionary and arguments, use |get()| to get the function name: >
962973
if get(Part1, 'name') == get(Part2, 'name')
963974
" Part1 and Part2 refer to the same function
964975
965-
When using "is" or "isnot" with a |List| or a |Dictionary| this checks if the
966-
expressions are referring to the same |List| or |Dictionary| instance. A copy
967-
of a |List| is different from the original |List|. When using "is" without
968-
a |List| or a |Dictionary| it is equivalent to using "equal", using "isnot"
969-
equivalent to using "not equal". Except that a different type means the
970-
values are different: >
976+
Using "is" or "isnot" with a |List|, |Dictionary| or |Blob| checks whether
977+
the expressions are referring to the same |List|, |Dictionary| or |Blob|
978+
instance. A copy of a |List| is different from the original |List|. When
979+
using "is" without a |List|, |Dictionary| or |Blob|, it is equivalent to
980+
using "equal", using "isnot" equivalent to using "not equal". Except that
981+
a different type means the values are different: >
971982
echo 4 == '4'
972983
1
973984
echo 4 is '4'
@@ -1012,16 +1023,16 @@ can be matched like an ordinary character. Examples:
10121023

10131024
expr5 and expr6 *expr5* *expr6*
10141025
---------------
1015-
expr6 + expr6 .. Number addition or |List| concatenation *expr-+*
1016-
expr6 - expr6 .. Number subtraction *expr--*
1017-
expr6 . expr6 .. String concatenation *expr-.*
1026+
expr6 + expr6 Number addition, |List| or |Blob| concatenation *expr-+*
1027+
expr6 - expr6 Number subtraction *expr--*
1028+
expr6 . expr6 String concatenation *expr-.*
10181029

10191030
For |Lists| only "+" is possible and then both expr6 must be a list. The
10201031
result is a new list with the two lists Concatenated.
10211032

1022-
expr7 * expr7 .. Number multiplication *expr-star*
1023-
expr7 / expr7 .. Number division *expr-/*
1024-
expr7 % expr7 .. Number modulo *expr-%*
1033+
expr7 * expr7 Number multiplication *expr-star*
1034+
expr7 / expr7 Number division *expr-/*
1035+
expr7 % expr7 Number modulo *expr-%*
10251036

10261037
For all, except ".", Strings are converted to Numbers.
10271038
For bitwise operators see |and()|, |or()| and |xor()|.
@@ -4121,6 +4132,9 @@ feedkeys({string} [, {mode}]) *feedkeys()*
41214132
't' Handle keys as if typed; otherwise they are handled as
41224133
if coming from a mapping. This matters for undo,
41234134
opening folds, etc.
4135+
'L' Lowlevel input. Only works for Unix or when using the
4136+
GUI. Keys are used as if they were coming from the
4137+
terminal. Other flags are not used. *E980*
41244138
'i' Insert the string instead of appending (see above).
41254139
'x' Execute commands until typeahead is empty. This is
41264140
similar to using ":normal!". You can call feedkeys()
@@ -5740,6 +5754,10 @@ job_start({command} [, {options}]) *job_start()*
57405754
|:!cmd| this does not wait for the job to finish.
57415755
To start a job in a terminal window see |term_start()|.
57425756

5757+
If the job fails to start then |job_status()| on the returned
5758+
Job object results in "fail" and none of the callbacks will be
5759+
invoked.
5760+
57435761
{command} can be a String. This works best on MS-Windows. On
57445762
Unix it is split up in white-separated parts to be passed to
57455763
execvp(). Arguments in double quotes can contain white space.
@@ -11044,28 +11062,34 @@ This does NOT work: >
1104411062
NOTE: The ":append" and ":insert" commands don't work
1104511063
properly inside a ":while" and ":for" loop.
1104611064

11047-
:for {var} in {list} *:for* *E690* *E732*
11065+
:for {var} in {object} *:for* *E690* *E732*
1104811066
:endfo[r] *:endfo* *:endfor*
1104911067
Repeat the commands between ":for" and ":endfor" for
11050-
each item in {list}. Variable {var} is set to the
11051-
value of each item.
11052-
When an error is detected for a command inside the
11053-
loop, execution continues after the "endfor".
11054-
Changing {list} inside the loop affects what items are
11055-
used. Make a copy if this is unwanted: >
11068+
each item in {object}. {object} can be a |List| or
11069+
a |Blob|. Variable {var} is set to the value of each
11070+
item. When an error is detected for a command inside
11071+
the loop, execution continues after the "endfor".
11072+
Changing {object} inside the loop affects what items
11073+
are used. Make a copy if this is unwanted: >
1105611074
:for item in copy(mylist)
11057-
< When not making a copy, Vim stores a reference to the
11058-
next item in the list, before executing the commands
11059-
with the current item. Thus the current item can be
11060-
removed without effect. Removing any later item means
11061-
it will not be found. Thus the following example
11062-
works (an inefficient way to make a list empty): >
11075+
<
11076+
When {object} is a |List| and not making a copy, Vim
11077+
stores a reference to the next item in the |List|
11078+
before executing the commands with the current item.
11079+
Thus the current item can be removed without effect.
11080+
Removing any later item means it will not be found.
11081+
Thus the following example works (an inefficient way
11082+
to make a |List| empty): >
1106311083
for item in mylist
1106411084
call remove(mylist, 0)
1106511085
endfor
11066-
< Note that reordering the list (e.g., with sort() or
11086+
< Note that reordering the |List| (e.g., with sort() or
1106711087
reverse()) may have unexpected effects.
1106811088

11089+
When {object} is a |Blob|, Vim always makes a copy to
11090+
iterate over. Unlike with |List|, modifying the
11091+
|Blob| does not affect the iteration.
11092+
1106911093
:for [{var1}, {var2}, ...] in {listlist}
1107011094
:endfo[r]
1107111095
Like ":for" above, but each item in {listlist} must be

src/evalfunc.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3674,6 +3674,7 @@ f_feedkeys(typval_T *argvars, typval_T *rettv UNUSED)
36743674
int typed = FALSE;
36753675
int execute = FALSE;
36763676
int dangerous = FALSE;
3677+
int lowlevel = FALSE;
36773678
char_u *keys_esc;
36783679

36793680
/* This is not allowed in the sandbox. If the commands would still be
@@ -3697,6 +3698,7 @@ f_feedkeys(typval_T *argvars, typval_T *rettv UNUSED)
36973698
case 'i': insert = TRUE; break;
36983699
case 'x': execute = TRUE; break;
36993700
case '!': dangerous = TRUE; break;
3701+
case 'L': lowlevel = TRUE; break;
37003702
}
37013703
}
37023704
}
@@ -3708,7 +3710,16 @@ f_feedkeys(typval_T *argvars, typval_T *rettv UNUSED)
37083710
keys_esc = vim_strsave_escape_csi(keys);
37093711
if (keys_esc != NULL)
37103712
{
3711-
ins_typebuf(keys_esc, (remap ? REMAP_YES : REMAP_NONE),
3713+
if (lowlevel)
3714+
{
3715+
#ifdef USE_INPUT_BUF
3716+
add_to_input_buf(keys, (int)STRLEN(keys));
3717+
#else
3718+
emsg(_("E980: lowlevel input not supported"));
3719+
#endif
3720+
}
3721+
else
3722+
ins_typebuf(keys_esc, (remap ? REMAP_YES : REMAP_NONE),
37123723
insert ? 0 : typebuf.tb_len, !typed, FALSE);
37133724
vim_free(keys_esc);
37143725
if (vgetc_busy

src/testdir/Make_all.mak

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ NEW_TESTS = \
121121
test_feedkeys \
122122
test_file_perm \
123123
test_file_size \
124+
test_filechanged \
124125
test_fileformat \
125126
test_filetype \
126127
test_filter_cmd \
@@ -316,6 +317,7 @@ NEW_TESTS_RES = \
316317
test_exit.res \
317318
test_farsi.res \
318319
test_file_size.res \
320+
test_filechanged.res \
319321
test_find_complete.res \
320322
test_fixeol.res \
321323
test_fnameescape.res \

src/testdir/test_autocmd.vim

Lines changed: 1 addition & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1386,92 +1386,4 @@ func Test_Changed_FirstTime()
13861386
bwipe!
13871387
endfunc
13881388

1389-
func Test_FileChangedShell_reload()
1390-
if !has('unix')
1391-
return
1392-
endif
1393-
augroup testreload
1394-
au FileChangedShell Xchanged let g:reason = v:fcs_reason | let v:fcs_choice = 'reload'
1395-
augroup END
1396-
new Xchanged
1397-
call setline(1, 'reload this')
1398-
write
1399-
" Need to wait until the timestamp would change by at least a second.
1400-
sleep 2
1401-
silent !echo 'extra line' >>Xchanged
1402-
checktime
1403-
call assert_equal('changed', g:reason)
1404-
call assert_equal(2, line('$'))
1405-
call assert_equal('extra line', getline(2))
1406-
1407-
" Only triggers once
1408-
let g:reason = ''
1409-
checktime
1410-
call assert_equal('', g:reason)
1411-
1412-
" When deleted buffer is not reloaded
1413-
silent !rm Xchanged
1414-
let g:reason = ''
1415-
checktime
1416-
call assert_equal('deleted', g:reason)
1417-
call assert_equal(2, line('$'))
1418-
call assert_equal('extra line', getline(2))
1419-
1420-
" When recreated buffer is reloaded
1421-
call setline(1, 'buffer is changed')
1422-
silent !echo 'new line' >>Xchanged
1423-
let g:reason = ''
1424-
checktime
1425-
call assert_equal('conflict', g:reason)
1426-
call assert_equal(1, line('$'))
1427-
call assert_equal('new line', getline(1))
1428-
1429-
" Only mode changed
1430-
silent !chmod +x Xchanged
1431-
let g:reason = ''
1432-
checktime
1433-
call assert_equal('mode', g:reason)
1434-
call assert_equal(1, line('$'))
1435-
call assert_equal('new line', getline(1))
1436-
1437-
" Only time changed
1438-
sleep 2
1439-
silent !touch Xchanged
1440-
let g:reason = ''
1441-
checktime
1442-
call assert_equal('time', g:reason)
1443-
call assert_equal(1, line('$'))
1444-
call assert_equal('new line', getline(1))
1445-
1446-
if has('persistent_undo')
1447-
" With an undo file the reload can be undone and a change before the
1448-
" reload.
1449-
set undofile
1450-
call setline(2, 'before write')
1451-
write
1452-
call setline(2, 'after write')
1453-
sleep 2
1454-
silent !echo 'different line' >>Xchanged
1455-
let g:reason = ''
1456-
checktime
1457-
call assert_equal('conflict', g:reason)
1458-
call assert_equal(3, line('$'))
1459-
call assert_equal('before write', getline(2))
1460-
call assert_equal('different line', getline(3))
1461-
" undo the reload
1462-
undo
1463-
call assert_equal(2, line('$'))
1464-
call assert_equal('after write', getline(2))
1465-
" undo the change before reload
1466-
undo
1467-
call assert_equal(2, line('$'))
1468-
call assert_equal('before write', getline(2))
1469-
1470-
set noundofile
1471-
endif
1472-
1473-
1474-
au! testreload
1475-
bwipe!
1476-
call delete('Xchanged')
1477-
endfunc
1389+
" FileChangedShell tested in test_filechanged.vim

0 commit comments

Comments
 (0)