Skip to content

Commit f0d8449

Browse files
committed
Merge remote-tracking branch 'vim/master'
2 parents 797c379 + 0b37a2f commit f0d8449

17 files changed

Lines changed: 167 additions & 103 deletions

runtime/menu.vim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
" You can also use this as a start for your own set of menus.
33
"
44
" Maintainer: Bram Moolenaar <[email protected]>
5-
" Last Change: 2020 Mar 19
5+
" Last Change: 2020 Mar 29
66

77
" Note that ":an" (short for ":anoremenu") is often used to make a menu work
88
" in all modes and avoid side effects from mappings defined by the user.
@@ -727,7 +727,7 @@ func s:BMAdd()
727727
call s:BMShow()
728728
else
729729
let name = expand("<afile>")
730-
let num = expand("<abuf>")
730+
let num = expand("<abuf>") + 0 " add zero to convert to a number type
731731
if s:BMCanAdd(name, num)
732732
call <SID>BMFilename(name, num)
733733
let s:bmenu_count += 1

src/evalvars.c

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3463,7 +3463,6 @@ f_getwinvar(typval_T *argvars, typval_T *rettv)
34633463
f_getbufvar(typval_T *argvars, typval_T *rettv)
34643464
{
34653465
buf_T *buf;
3466-
buf_T *save_curbuf;
34673466
char_u *varname;
34683467
dictitem_T *v;
34693468
int done = FALSE;
@@ -3478,12 +3477,13 @@ f_getbufvar(typval_T *argvars, typval_T *rettv)
34783477

34793478
if (buf != NULL && varname != NULL)
34803479
{
3481-
// set curbuf to be our buf, temporarily
3482-
save_curbuf = curbuf;
3483-
curbuf = buf;
3484-
34853480
if (*varname == '&')
34863481
{
3482+
buf_T *save_curbuf = curbuf;
3483+
3484+
// set curbuf to be our buf, temporarily
3485+
curbuf = buf;
3486+
34873487
if (varname[1] == NUL)
34883488
{
34893489
// get all buffer-local options in a dict
@@ -3498,22 +3498,21 @@ f_getbufvar(typval_T *argvars, typval_T *rettv)
34983498
else if (get_option_tv(&varname, rettv, TRUE) == OK)
34993499
// buffer-local-option
35003500
done = TRUE;
3501+
3502+
// restore previous notion of curbuf
3503+
curbuf = save_curbuf;
35013504
}
35023505
else
35033506
{
35043507
// Look up the variable.
35053508
// Let getbufvar({nr}, "") return the "b:" dictionary.
3506-
v = find_var_in_ht(&curbuf->b_vars->dv_hashtab,
3507-
'b', varname, FALSE);
3509+
v = find_var_in_ht(&buf->b_vars->dv_hashtab, 'b', varname, FALSE);
35083510
if (v != NULL)
35093511
{
35103512
copy_tv(&v->di_tv, rettv);
35113513
done = TRUE;
35123514
}
35133515
}
3514-
3515-
// restore previous notion of curbuf
3516-
curbuf = save_curbuf;
35173516
}
35183517

35193518
if (!done && argvars[2].v_type != VAR_UNKNOWN)
@@ -3620,11 +3619,11 @@ f_setbufvar(typval_T *argvars, typval_T *rettv UNUSED)
36203619
}
36213620
else
36223621
{
3623-
buf_T *save_curbuf = curbuf;
3624-
36253622
bufvarname = alloc(STRLEN(varname) + 3);
36263623
if (bufvarname != NULL)
36273624
{
3625+
buf_T *save_curbuf = curbuf;
3626+
36283627
curbuf = buf;
36293628
STRCPY(bufvarname, "b:");
36303629
STRCPY(bufvarname + 2, varname);

src/fileio.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -261,11 +261,21 @@ readfile(
261261
{
262262
if (apply_autocmds_exarg(EVENT_BUFREADCMD, NULL, sfname,
263263
FALSE, curbuf, eap))
264+
{
265+
int status = OK;
264266
#ifdef FEAT_EVAL
265-
return aborting() ? FAIL : OK;
266-
#else
267-
return OK;
268-
#endif
267+
if (aborting())
268+
status = FAIL;
269+
#endif
270+
// The BufReadCmd code usually uses ":read" to get the text and
271+
// perhaps ":file" to change the buffer name. But we should
272+
// consider this to work like ":edit", thus reset the
273+
// BF_NOTEDITED flag. Then ":write" will work to overwrite the
274+
// same file.
275+
if (status == OK)
276+
curbuf->b_flags &= ~BF_NOTEDITED;
277+
return status;
278+
}
269279
}
270280
else if (apply_autocmds_exarg(EVENT_FILEREADCMD, sfname, sfname,
271281
FALSE, NULL, eap))

src/if_lua.c

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -398,16 +398,6 @@ static const luaV_Reg luaV_dll[] = {
398398

399399
static HANDLE hinstLua = NULL;
400400

401-
static void
402-
end_dynamic_lua(void)
403-
{
404-
if (hinstLua)
405-
{
406-
close_dll(hinstLua);
407-
hinstLua = 0;
408-
}
409-
}
410-
411401
static int
412402
lua_link_init(char *libname, int verbose)
413403
{
@@ -2121,9 +2111,6 @@ lua_end(void)
21212111
{
21222112
lua_close(L);
21232113
L = NULL;
2124-
#ifdef DYNAMIC_LUA
2125-
end_dynamic_lua();
2126-
#endif
21272114
}
21282115
}
21292116

src/if_perl.xs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,7 @@ perl_init(void)
762762
}
763763

764764
/*
765-
* perl_end(): clean up after ourselves
765+
* Clean up after ourselves.
766766
*/
767767
void
768768
perl_end(void)
@@ -777,13 +777,6 @@ perl_end(void)
777777
Perl_sys_term();
778778
#endif
779779
}
780-
#ifdef DYNAMIC_PERL
781-
if (hPerlLib)
782-
{
783-
close_dll(hPerlLib);
784-
hPerlLib = NULL;
785-
}
786-
#endif
787780
}
788781

789782
/*

src/if_python.c

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -654,19 +654,6 @@ static struct
654654
{"", NULL},
655655
};
656656

657-
/*
658-
* Free python.dll
659-
*/
660-
static void
661-
end_dynamic_python(void)
662-
{
663-
if (hinstPython)
664-
{
665-
close_dll(hinstPython);
666-
hinstPython = 0;
667-
}
668-
}
669-
670657
/*
671658
* Load library and get all pointers.
672659
* Parameter 'libname' provides name of DLL.
@@ -889,7 +876,6 @@ python_end(void)
889876
# endif
890877
Py_Finalize();
891878
}
892-
end_dynamic_python();
893879
#else
894880
if (Py_IsInitialized())
895881
{

src/if_python3.c

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -634,19 +634,6 @@ py3__Py_XDECREF(PyObject *op)
634634
# define Py_XDECREF(op) py3__Py_XDECREF(_PyObject_CAST(op))
635635
# endif
636636

637-
/*
638-
* Free python.dll
639-
*/
640-
static void
641-
end_dynamic_python3(void)
642-
{
643-
if (hinstPy3 != 0)
644-
{
645-
close_dll(hinstPy3);
646-
hinstPy3 = 0;
647-
}
648-
}
649-
650637
/*
651638
* Load library and get all pointers.
652639
* Parameter 'libname' provides name of DLL.
@@ -873,10 +860,6 @@ python3_end(void)
873860
Py_Finalize();
874861
}
875862

876-
#ifdef DYNAMIC_PYTHON3
877-
end_dynamic_python3();
878-
#endif
879-
880863
--recurse;
881864
}
882865

src/if_ruby.c

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -735,19 +735,6 @@ static struct
735735
{"", NULL},
736736
};
737737

738-
/*
739-
* Free ruby.dll
740-
*/
741-
static void
742-
end_dynamic_ruby(void)
743-
{
744-
if (hinstRuby)
745-
{
746-
close_dll(hinstRuby);
747-
hinstRuby = NULL;
748-
}
749-
}
750-
751738
/*
752739
* Load library and get all pointers.
753740
* Parameter 'libname' provides name of DLL.
@@ -797,9 +784,6 @@ ruby_enabled(int verbose)
797784
void
798785
ruby_end(void)
799786
{
800-
#ifdef DYNAMIC_RUBY
801-
end_dynamic_ruby();
802-
#endif
803787
}
804788

805789
void

src/if_tcl.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -280,13 +280,6 @@ tcl_enabled(int verbose)
280280
void
281281
tcl_end(void)
282282
{
283-
#ifdef DYNAMIC_TCL
284-
if (hTclLib)
285-
{
286-
close_dll(hTclLib);
287-
hTclLib = NULL;
288-
}
289-
#endif
290283
}
291284

292285
/////////////////////////////////////////////////////////////////////////////

src/testdir/test_autocmd.vim

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1536,6 +1536,40 @@ func Test_Cmd_Autocmds()
15361536
enew!
15371537
endfunc
15381538

1539+
func s:ReadFile()
1540+
setl noswapfile nomodified
1541+
let filename = resolve(expand("<afile>:p"))
1542+
execute 'read' fnameescape(filename)
1543+
1d_
1544+
exe 'file' fnameescape(filename)
1545+
setl buftype=acwrite
1546+
endfunc
1547+
1548+
func s:WriteFile()
1549+
let filename = resolve(expand("<afile>:p"))
1550+
setl buftype=
1551+
noautocmd execute 'write' fnameescape(filename)
1552+
setl buftype=acwrite
1553+
setl nomodified
1554+
endfunc
1555+
1556+
func Test_BufReadCmd()
1557+
autocmd BufReadCmd *.test call s:ReadFile()
1558+
autocmd BufWriteCmd *.test call s:WriteFile()
1559+
1560+
call writefile(['one', 'two', 'three'], 'Xcmd.test')
1561+
edit Xcmd.test
1562+
call assert_match('Xcmd.test" line 1 of 3', execute('file'))
1563+
normal! Gofour
1564+
write
1565+
call assert_equal(['one', 'two', 'three', 'four'], readfile('Xcmd.test'))
1566+
1567+
bwipe!
1568+
call delete('Xcmd.test')
1569+
au! BufReadCmd
1570+
au! BufWriteCmd
1571+
endfunc
1572+
15391573
func SetChangeMarks(start, end)
15401574
exe a:start. 'mark ['
15411575
exe a:end. 'mark ]'

0 commit comments

Comments
 (0)