Skip to content

Commit 3cc4453

Browse files
committed
Merge remote-tracking branch 'vim/master'
2 parents 4338f80 + dac1947 commit 3cc4453

21 files changed

Lines changed: 2223 additions & 74 deletions

runtime/defaults.vim

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
" The default vimrc file.
22
"
33
" Maintainer: Bram Moolenaar <[email protected]>
4-
" Last change: 2016 Aug 28
4+
" Last change: 2016 Sep 02
55
"
66
" This is loaded if no vimrc file was found.
77
" Except when Vim is run with "-u NONE" or "-C".
@@ -13,6 +13,12 @@ if v:progname =~? "evim"
1313
finish
1414
endif
1515

16+
" Bail out if something that ran earlier, e.g. a system wide vimrc, does not
17+
" want Vim to use these default values.
18+
if exists('skip_defaults_vim')
19+
finish
20+
endif
21+
1622
" Use Vim settings, rather than Vi settings (much better!).
1723
" This must be first, because it changes other options as a side effect.
1824
set nocompatible

src/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2126,8 +2126,9 @@ test_arglist \
21262126
test_matchadd_conceal_utf8 \
21272127
test_menu \
21282128
test_messages \
2129-
test_nested_function \
2129+
test_nested_function \
21302130
test_netbeans \
2131+
test_normal \
21312132
test_options \
21322133
test_packadd \
21332134
test_partial \

src/buffer.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,8 @@ buf_clear_file(buf_T *buf)
670670

671671
/*
672672
* buf_freeall() - free all things allocated for a buffer that are related to
673-
* the file. flags:
673+
* the file. Careful: get here with "curwin" NULL when exiting.
674+
* flags:
674675
* BFA_DEL buffer is going to be deleted
675676
* BFA_WIPE buffer is going to be wiped out
676677
* BFA_KEEP_UNDO do not free undo information
@@ -681,7 +682,13 @@ buf_freeall(buf_T *buf, int flags)
681682
#ifdef FEAT_AUTOCMD
682683
int is_curbuf = (buf == curbuf);
683684
bufref_T bufref;
685+
# ifdef FEAT_WINDOWS
686+
int is_curwin = (curwin!= NULL && curwin->w_buffer == buf);
687+
win_T *the_curwin = curwin;
688+
tabpage_T *the_curtab = curtab;
689+
# endif
684690

691+
/* Make sure the buffer isn't closed by autocommands. */
685692
buf->b_closing = TRUE;
686693
set_bufref(&bufref, buf);
687694
if (buf->b_ml.ml_mfp != NULL)
@@ -709,6 +716,19 @@ buf_freeall(buf_T *buf, int flags)
709716
return;
710717
}
711718
buf->b_closing = FALSE;
719+
720+
# ifdef FEAT_WINDOWS
721+
/* If the buffer was in curwin and the window has changed, go back to that
722+
* window, if it still exists. This avoids that ":edit x" triggering a
723+
* "tabnext" BufUnload autocmd leaves a window behind without a buffer. */
724+
if (is_curwin && curwin != the_curwin && win_valid_any_tab(the_curwin))
725+
{
726+
block_autocmds();
727+
goto_tabpage_win(the_curtab, the_curwin);
728+
unblock_autocmds();
729+
}
730+
# endif
731+
712732
# ifdef FEAT_EVAL
713733
if (aborting()) /* autocmds may abort script processing */
714734
return;

src/ex_cmds.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3935,25 +3935,28 @@ do_ecmd(
39353935
auto_buf = TRUE;
39363936
else
39373937
{
3938+
win_T *the_curwin = curwin;
3939+
3940+
/* Set the w_closing flag to avoid that autocommands close the
3941+
* window. */
3942+
the_curwin->w_closing = TRUE;
3943+
39383944
if (curbuf == old_curbuf.br_buf)
39393945
#endif
39403946
buf_copy_options(buf, BCO_ENTER);
39413947

3942-
/* close the link to the current buffer */
3948+
/* Close the link to the current buffer. This will set
3949+
* curwin->w_buffer to NULL. */
39433950
u_sync(FALSE);
39443951
close_buffer(oldwin, curbuf,
39453952
(flags & ECMD_HIDE) ? 0 : DOBUF_UNLOAD, FALSE);
39463953

39473954
#ifdef FEAT_AUTOCMD
3948-
/* Autocommands may open a new window and leave oldwin open
3949-
* which leads to crashes since the above call sets
3950-
* oldwin->w_buffer to NULL. */
3951-
if (curwin != oldwin && oldwin != aucmd_win
3952-
&& win_valid(oldwin) && oldwin->w_buffer == NULL)
3953-
win_close(oldwin, FALSE);
3955+
the_curwin->w_closing = FALSE;
39543956

39553957
# ifdef FEAT_EVAL
3956-
if (aborting()) /* autocmds may abort script processing */
3958+
/* autocmds may abort script processing */
3959+
if (aborting() && curwin->w_buffer != NULL)
39573960
{
39583961
vim_free(new_name);
39593962
goto theend;

src/ex_docmd.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2482,12 +2482,7 @@ do_one_cmd(
24822482
&& !IS_USER_CMDIDX(ea.cmdidx))
24832483
{
24842484
/* Command not allowed when editing the command line. */
2485-
#ifdef FEAT_CMDWIN
2486-
if (cmdwin_type != 0)
2487-
errormsg = (char_u *)_(e_cmdwin);
2488-
else
2489-
#endif
2490-
errormsg = (char_u *)_(e_secure);
2485+
errormsg = get_text_locked_msg();
24912486
goto doend;
24922487
}
24932488
#ifdef FEAT_AUTOCMD

src/ex_getln.c

Lines changed: 52 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -177,17 +177,22 @@ getcmdline(
177177
int histype; /* history type to be used */
178178
#endif
179179
#ifdef FEAT_SEARCH_EXTRA
180-
pos_T old_cursor;
180+
pos_T search_start; /* where 'incsearch' starts searching */
181+
pos_T save_cursor;
181182
colnr_T old_curswant;
183+
colnr_T init_curswant = curwin->w_curswant;
182184
colnr_T old_leftcol;
185+
colnr_T init_leftcol = curwin->w_leftcol;
183186
linenr_T old_topline;
184-
pos_T cursor_start;
187+
linenr_T init_topline = curwin->w_topline;
185188
pos_T match_start = curwin->w_cursor;
186189
pos_T match_end;
187190
# ifdef FEAT_DIFF
188191
int old_topfill;
192+
int init_topfill = curwin->w_topfill;
189193
# endif
190194
linenr_T old_botline;
195+
linenr_T init_botline = curwin->w_botline;
191196
int did_incsearch = FALSE;
192197
int incsearch_postponed = FALSE;
193198
#endif
@@ -230,8 +235,8 @@ getcmdline(
230235
ccline.overstrike = FALSE; /* always start in insert mode */
231236
#ifdef FEAT_SEARCH_EXTRA
232237
clearpos(&match_end);
233-
old_cursor = curwin->w_cursor; /* needs to be restored later */
234-
cursor_start = old_cursor;
238+
save_cursor = curwin->w_cursor; /* may be restored later */
239+
search_start = curwin->w_cursor;
235240
old_curswant = curwin->w_curswant;
236241
old_leftcol = curwin->w_leftcol;
237242
old_topline = curwin->w_topline;
@@ -1006,11 +1011,17 @@ getcmdline(
10061011
ccline.cmdbuff[ccline.cmdlen] = NUL;
10071012
#ifdef FEAT_SEARCH_EXTRA
10081013
if (ccline.cmdlen == 0)
1009-
old_cursor = cursor_start;
1010-
else
10111014
{
1012-
old_cursor = match_start;
1013-
decl(&old_cursor);
1015+
search_start = save_cursor;
1016+
/* save view settings, so that the screen
1017+
* won't be restored at the wrong position */
1018+
old_curswant = init_curswant;
1019+
old_leftcol = init_leftcol;
1020+
old_topline = init_topline;
1021+
# ifdef FEAT_DIFF
1022+
old_topfill = init_topfill;
1023+
# endif
1024+
old_botline = init_botline;
10141025
}
10151026
#endif
10161027
redrawcmd();
@@ -1040,7 +1051,7 @@ getcmdline(
10401051
}
10411052
#ifdef FEAT_SEARCH_EXTRA
10421053
if (ccline.cmdlen == 0)
1043-
old_cursor = cursor_start;
1054+
search_start = save_cursor;
10441055
#endif
10451056
redraw_cmdline = TRUE;
10461057
goto returncmd; /* back to cmd mode */
@@ -1127,7 +1138,7 @@ getcmdline(
11271138
ccline.cmdbuff[ccline.cmdlen] = NUL;
11281139
#ifdef FEAT_SEARCH_EXTRA
11291140
if (ccline.cmdlen == 0)
1130-
old_cursor = cursor_start;
1141+
search_start = save_cursor;
11311142
#endif
11321143
redrawcmd();
11331144
goto cmdline_changed;
@@ -1476,7 +1487,7 @@ getcmdline(
14761487
if (did_incsearch)
14771488
{
14781489
curwin->w_cursor = match_end;
1479-
if (!equalpos(curwin->w_cursor, old_cursor))
1490+
if (!equalpos(curwin->w_cursor, search_start))
14801491
{
14811492
c = gchar_cursor();
14821493
/* If 'ignorecase' and 'smartcase' are set and the
@@ -1665,9 +1676,9 @@ getcmdline(
16651676
#endif
16661677
goto cmdline_not_changed;
16671678

1679+
#ifdef FEAT_SEARCH_EXTRA
16681680
case Ctrl_G: /* next match */
16691681
case Ctrl_T: /* previous match */
1670-
#ifdef FEAT_SEARCH_EXTRA
16711682
if (p_is && !cmd_silent && (firstc == '/' || firstc == '?'))
16721683
{
16731684
pos_T t;
@@ -1693,25 +1704,25 @@ getcmdline(
16931704
--emsg_off;
16941705
if (i)
16951706
{
1696-
old_cursor = match_start;
1707+
search_start = match_start;
16971708
match_end = t;
16981709
match_start = t;
16991710
if (c == Ctrl_T && firstc == '/')
17001711
{
17011712
/* move just before the current match, so that
17021713
* when nv_search finishes the cursor will be
17031714
* put back on the match */
1704-
old_cursor = t;
1705-
(void)decl(&old_cursor);
1715+
search_start = t;
1716+
(void)decl(&search_start);
17061717
}
1707-
if (lt(t, old_cursor) && c == Ctrl_G)
1718+
if (lt(t, search_start) && c == Ctrl_G)
17081719
{
17091720
/* wrap around */
1710-
old_cursor = t;
1721+
search_start = t;
17111722
if (firstc == '?')
1712-
(void)incl(&old_cursor);
1723+
(void)incl(&search_start);
17131724
else
1714-
(void)decl(&old_cursor);
1725+
(void)decl(&search_start);
17151726
}
17161727

17171728
set_search_match(&match_end);
@@ -1732,8 +1743,9 @@ getcmdline(
17321743
}
17331744
else
17341745
vim_beep(BO_ERROR);
1746+
goto cmdline_not_changed;
17351747
}
1736-
goto cmdline_not_changed;
1748+
break;
17371749
#endif
17381750

17391751
case Ctrl_V:
@@ -1877,7 +1889,7 @@ getcmdline(
18771889
continue;
18781890
}
18791891
incsearch_postponed = FALSE;
1880-
curwin->w_cursor = old_cursor; /* start at old position */
1892+
curwin->w_cursor = search_start; /* start at old position */
18811893

18821894
/* If there is no command line, don't do anything */
18831895
if (ccline.cmdlen == 0)
@@ -1995,9 +2007,18 @@ getcmdline(
19952007
#ifdef FEAT_SEARCH_EXTRA
19962008
if (did_incsearch)
19972009
{
1998-
curwin->w_cursor = old_cursor;
19992010
if (gotesc)
2000-
curwin->w_cursor = cursor_start;
2011+
curwin->w_cursor = save_cursor;
2012+
else
2013+
{
2014+
if (!equalpos(save_cursor, search_start))
2015+
{
2016+
/* put the '" mark at the original position */
2017+
curwin->w_cursor = save_cursor;
2018+
setpcmark();
2019+
}
2020+
curwin->w_cursor = search_start;
2021+
}
20012022
curwin->w_curswant = old_curswant;
20022023
curwin->w_leftcol = old_leftcol;
20032024
curwin->w_topline = old_topline;
@@ -2140,13 +2161,18 @@ text_locked(void)
21402161
*/
21412162
void
21422163
text_locked_msg(void)
2164+
{
2165+
EMSG(_(get_text_locked_msg()));
2166+
}
2167+
2168+
char_u *
2169+
get_text_locked_msg(void)
21432170
{
21442171
#ifdef FEAT_CMDWIN
21452172
if (cmdwin_type != 0)
2146-
EMSG(_(e_cmdwin));
2147-
else
2173+
return e_cmdwin;
21482174
#endif
2149-
EMSG(_(e_secure));
2175+
return e_secure;
21502176
}
21512177

21522178
#if defined(FEAT_AUTOCMD) || defined(PROTO)

0 commit comments

Comments
 (0)