Skip to content

Commit b3c2a8c

Browse files
committed
Merge remote-tracking branch 'vim/master'
2 parents ba7f8db + 32bbd00 commit b3c2a8c

13 files changed

+247
-43
lines changed

src/ex_cmds2.c

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2041,7 +2041,7 @@ autowrite(buf_T *buf, int forceit)
20412041
}
20422042

20432043
/*
2044-
* flush all buffers, except the ones that are readonly
2044+
* Flush all buffers, except the ones that are readonly or are never written.
20452045
*/
20462046
void
20472047
autowrite_all(void)
@@ -2051,7 +2051,7 @@ autowrite_all(void)
20512051
if (!(p_aw || p_awa) || !p_write)
20522052
return;
20532053
FOR_ALL_BUFFERS(buf)
2054-
if (bufIsChanged(buf) && !buf->b_p_ro)
2054+
if (bufIsChanged(buf) && !buf->b_p_ro && !bt_dontwrite(buf))
20552055
{
20562056
bufref_T bufref;
20572057

@@ -2518,10 +2518,10 @@ buf_write_all(buf_T *buf, int forceit)
25182518
*/
25192519

25202520
static char_u *do_one_arg(char_u *str);
2521-
static int do_arglist(char_u *str, int what, int after);
2521+
static int do_arglist(char_u *str, int what, int after, int will_edit);
25222522
static void alist_check_arg_idx(void);
25232523
static int editing_arg_idx(win_T *win);
2524-
static int alist_add_list(int count, char_u **files, int after);
2524+
static void alist_add_list(int count, char_u **files, int after, int will_edit);
25252525
#define AL_SET 1
25262526
#define AL_ADD 2
25272527
#define AL_DEL 3
@@ -2626,7 +2626,7 @@ get_arglist_exp(
26262626
void
26272627
set_arglist(char_u *str)
26282628
{
2629-
do_arglist(str, AL_SET, 0);
2629+
do_arglist(str, AL_SET, 0, FALSE);
26302630
}
26312631

26322632
/*
@@ -2640,7 +2640,8 @@ set_arglist(char_u *str)
26402640
do_arglist(
26412641
char_u *str,
26422642
int what,
2643-
int after UNUSED) /* 0 means before first one */
2643+
int after UNUSED, // 0 means before first one
2644+
int will_edit) // will edit added argument
26442645
{
26452646
garray_T new_ga;
26462647
int exp_count;
@@ -2725,11 +2726,11 @@ do_arglist(
27252726

27262727
if (what == AL_ADD)
27272728
{
2728-
(void)alist_add_list(exp_count, exp_files, after);
2729+
alist_add_list(exp_count, exp_files, after, will_edit);
27292730
vim_free(exp_files);
27302731
}
27312732
else /* what == AL_SET */
2732-
alist_set(ALIST(curwin), exp_count, exp_files, FALSE, NULL, 0);
2733+
alist_set(ALIST(curwin), exp_count, exp_files, will_edit, NULL, 0);
27332734
}
27342735

27352736
alist_check_arg_idx();
@@ -3005,7 +3006,7 @@ ex_next(exarg_T *eap)
30053006
{
30063007
if (*eap->arg != NUL) /* redefine file list */
30073008
{
3008-
if (do_arglist(eap->arg, AL_SET, 0) == FAIL)
3009+
if (do_arglist(eap->arg, AL_SET, 0, TRUE) == FAIL)
30093010
return;
30103011
i = 0;
30113012
}
@@ -3025,7 +3026,7 @@ ex_argedit(exarg_T *eap)
30253026
// Whether curbuf will be reused, curbuf->b_ffname will be set.
30263027
int curbuf_is_reusable = curbuf_reusable();
30273028

3028-
if (do_arglist(eap->arg, AL_ADD, i) == FAIL)
3029+
if (do_arglist(eap->arg, AL_ADD, i, TRUE) == FAIL)
30293030
return;
30303031
#ifdef FEAT_TITLE
30313032
maketitle();
@@ -3047,7 +3048,8 @@ ex_argedit(exarg_T *eap)
30473048
ex_argadd(exarg_T *eap)
30483049
{
30493050
do_arglist(eap->arg, AL_ADD,
3050-
eap->addr_count > 0 ? (int)eap->line2 : curwin->w_arg_idx + 1);
3051+
eap->addr_count > 0 ? (int)eap->line2 : curwin->w_arg_idx + 1,
3052+
FALSE);
30513053
#ifdef FEAT_TITLE
30523054
maketitle();
30533055
#endif
@@ -3097,7 +3099,7 @@ ex_argdelete(exarg_T *eap)
30973099
else if (*eap->arg == NUL)
30983100
EMSG(_(e_argreq));
30993101
else
3100-
do_arglist(eap->arg, AL_DEL, 0);
3102+
do_arglist(eap->arg, AL_DEL, 0, FALSE);
31013103
#ifdef FEAT_TITLE
31023104
maketitle();
31033105
#endif
@@ -3342,13 +3344,13 @@ ex_listdo(exarg_T *eap)
33423344
* Add files[count] to the arglist of the current window after arg "after".
33433345
* The file names in files[count] must have been allocated and are taken over.
33443346
* Files[] itself is not taken over.
3345-
* Returns index of first added argument. Returns -1 when failed (out of mem).
33463347
*/
3347-
static int
3348+
static void
33483349
alist_add_list(
33493350
int count,
33503351
char_u **files,
3351-
int after) /* where to add: 0 = before first one */
3352+
int after, // where to add: 0 = before first one
3353+
int will_edit) // will edit adding argument
33523354
{
33533355
int i;
33543356
int old_argcount = ARGCOUNT;
@@ -3364,19 +3366,19 @@ alist_add_list(
33643366
(ARGCOUNT - after) * sizeof(aentry_T));
33653367
for (i = 0; i < count; ++i)
33663368
{
3369+
int flags = BLN_LISTED | (will_edit ? BLN_CURBUF : 0);
3370+
33673371
ARGLIST[after + i].ae_fname = files[i];
3368-
ARGLIST[after + i].ae_fnum =
3369-
buflist_add(files[i], BLN_LISTED | BLN_CURBUF);
3372+
ARGLIST[after + i].ae_fnum = buflist_add(files[i], flags);
33703373
}
33713374
ALIST(curwin)->al_ga.ga_len += count;
33723375
if (old_argcount > 0 && curwin->w_arg_idx >= after)
33733376
curwin->w_arg_idx += count;
3374-
return after;
3377+
return;
33753378
}
33763379

33773380
for (i = 0; i < count; ++i)
33783381
vim_free(files[i]);
3379-
return -1;
33803382
}
33813383

33823384
#if defined(FEAT_CMDL_COMPL) || defined(PROTO)

src/ex_docmd.c

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2046,12 +2046,15 @@ do_one_cmd(
20462046
errormsg = (char_u *)_(get_text_locked_msg());
20472047
goto doend;
20482048
}
2049+
20492050
/* Disallow editing another buffer when "curbuf_lock" is set.
2050-
* Do allow ":edit" (check for argument later).
2051-
* Do allow ":checktime" (it's postponed). */
2051+
* Do allow ":checktime" (it is postponed).
2052+
* Do allow ":edit" (check for an argument later).
2053+
* Do allow ":file" with no arguments (check for an argument later). */
20522054
if (!(ea.argt & CMDWIN)
2053-
&& ea.cmdidx != CMD_edit
20542055
&& ea.cmdidx != CMD_checktime
2056+
&& ea.cmdidx != CMD_edit
2057+
&& ea.cmdidx != CMD_file
20552058
&& !IS_USER_CMDIDX(ea.cmdidx)
20562059
&& curbuf_locked())
20572060
goto doend;
@@ -2137,6 +2140,10 @@ do_one_cmd(
21372140
else
21382141
ea.arg = skipwhite(p);
21392142

2143+
// ":file" cannot be run with an argument when "curbuf_lock" is set
2144+
if (ea.cmdidx == CMD_file && *ea.arg != NUL && curbuf_locked())
2145+
goto doend;
2146+
21402147
/*
21412148
* Check for "++opt=val" argument.
21422149
* Must be first, allow ":w ++enc=utf8 !cmd"
@@ -11740,6 +11747,18 @@ ses_do_win(win_T *wp)
1174011747
return TRUE;
1174111748
}
1174211749

11750+
static int
11751+
put_view_curpos(FILE *fd, win_T *wp, char *spaces)
11752+
{
11753+
int r;
11754+
11755+
if (wp->w_curswant == MAXCOL)
11756+
r = fprintf(fd, "%snormal! $", spaces);
11757+
else
11758+
r = fprintf(fd, "%snormal! 0%d|", spaces, wp->w_virtcol + 1);
11759+
return r < 0 || put_eol(fd) == FAIL ? FALSE : OK;
11760+
}
11761+
1174311762
/*
1174411763
* Write commands to "fd" to restore the view of a window.
1174511764
* Caller must make sure 'scrolloff' is zero.
@@ -11931,17 +11950,12 @@ put_view(
1193111950
(long)wp->w_virtcol + 1) < 0
1193211951
|| put_eol(fd) == FAIL
1193311952
|| put_line(fd, "else") == FAIL
11934-
|| fprintf(fd, " normal! 0%d|", wp->w_virtcol + 1) < 0
11935-
|| put_eol(fd) == FAIL
11953+
|| put_view_curpos(fd, wp, " ") == FAIL
1193611954
|| put_line(fd, "endif") == FAIL)
1193711955
return FAIL;
1193811956
}
11939-
else
11940-
{
11941-
if (fprintf(fd, "normal! 0%d|", wp->w_virtcol + 1) < 0
11942-
|| put_eol(fd) == FAIL)
11943-
return FAIL;
11944-
}
11957+
else if (put_view_curpos(fd, wp, "") == FAIL)
11958+
return FAIL;
1194511959
}
1194611960
}
1194711961

src/ex_getln.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,12 +436,18 @@ finish_incsearch_highlighting(
436436
}
437437
restore_viewstate(&is_state->old_viewstate);
438438
highlight_match = FALSE;
439+
440+
// by default search all lines
441+
search_first_line = 0;
442+
search_last_line = MAXLNUM;
443+
444+
p_magic = is_state->magic_save;
445+
439446
validate_cursor(); /* needed for TAB */
440447
if (call_update_screen)
441448
update_screen(SOME_VALID);
442449
else
443450
redraw_all_later(SOME_VALID);
444-
p_magic = is_state->magic_save;
445451
}
446452
}
447453

src/os_win32.c

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,14 @@ static void vtp_sgr_bulks(int argc, int *argv);
213213
static guicolor_T save_console_bg_rgb;
214214
static guicolor_T save_console_fg_rgb;
215215

216+
static int g_color_index_bg = 0;
217+
static int g_color_index_fg = 7;
218+
219+
# ifdef FEAT_TERMGUICOLORS
220+
static int default_console_color_bg = 0x000000; // black
221+
static int default_console_color_fg = 0xc0c0c0; // white
222+
# endif
223+
216224
# ifdef FEAT_TERMGUICOLORS
217225
# define USE_VTP (vtp_working && is_term_win32() && (p_tgc || (!p_tgc && t_colors >= 256)))
218226
# else
@@ -2628,6 +2636,10 @@ mch_init(void)
26282636
if (cterm_normal_bg_color == 0)
26292637
cterm_normal_bg_color = ((g_attrCurrent >> 4) & 0xf) + 1;
26302638

2639+
// Fg and Bg color index nunmber at startup
2640+
g_color_index_fg = g_attrDefault & 0xf;
2641+
g_color_index_bg = (g_attrDefault >> 4) & 0xf;
2642+
26312643
/* set termcap codes to current text attributes */
26322644
update_tcap(g_attrCurrent);
26332645

@@ -7664,6 +7676,9 @@ vtp_init(void)
76647676
DWORD ver, mode;
76657677
HMODULE hKerneldll;
76667678
DYN_CONSOLE_SCREEN_BUFFER_INFOEX csbi;
7679+
# ifdef FEAT_TERMGUICOLORS
7680+
COLORREF fg, bg;
7681+
# endif
76677682

76687683
ver = get_build_number();
76697684
vtp_working = (ver >= VTP_FIRST_SUPPORT_BUILD) ? 1 : 0;
@@ -7690,8 +7705,17 @@ vtp_init(void)
76907705
csbi.cbSize = sizeof(csbi);
76917706
if (has_csbiex)
76927707
pGetConsoleScreenBufferInfoEx(g_hConOut, &csbi);
7693-
save_console_bg_rgb = (guicolor_T)csbi.ColorTable[0];
7694-
save_console_fg_rgb = (guicolor_T)csbi.ColorTable[7];
7708+
save_console_bg_rgb = (guicolor_T)csbi.ColorTable[g_color_index_bg];
7709+
save_console_fg_rgb = (guicolor_T)csbi.ColorTable[g_color_index_fg];
7710+
7711+
# ifdef FEAT_TERMGUICOLORS
7712+
bg = (COLORREF)csbi.ColorTable[g_color_index_bg];
7713+
fg = (COLORREF)csbi.ColorTable[g_color_index_fg];
7714+
bg = (GetRValue(bg) << 16) | (GetGValue(bg) << 8) | GetBValue(bg);
7715+
fg = (GetRValue(fg) << 16) | (GetGValue(fg) << 8) | GetBValue(fg);
7716+
default_console_color_bg = bg;
7717+
default_console_color_fg = fg;
7718+
#endif
76957719

76967720
set_console_color_rgb();
76977721
}
@@ -7788,14 +7812,16 @@ set_console_color_rgb(void)
77887812
ctermfg = -1;
77897813
if (id > 0)
77907814
syn_id2cterm_bg(id, &ctermfg, &ctermbg);
7791-
fg = ctermfg != -1 ? ctermtoxterm(ctermfg) : 0xc0c0c0; /* white */
7815+
fg = ctermfg != -1 ? ctermtoxterm(ctermfg) : default_console_color_fg;
7816+
cterm_normal_fg_gui_color = fg;
77927817
}
77937818
if (bg == INVALCOLOR)
77947819
{
77957820
ctermbg = -1;
77967821
if (id > 0)
77977822
syn_id2cterm_bg(id, &ctermfg, &ctermbg);
7798-
bg = ctermbg != -1 ? ctermtoxterm(ctermbg) : 0x000000; /* black */
7823+
bg = ctermbg != -1 ? ctermtoxterm(ctermbg) : default_console_color_bg;
7824+
cterm_normal_bg_gui_color = bg;
77997825
}
78007826
fg = (GetRValue(fg) << 16) | (GetGValue(fg) << 8) | GetBValue(fg);
78017827
bg = (GetRValue(bg) << 16) | (GetGValue(bg) << 8) | GetBValue(bg);
@@ -7807,8 +7833,8 @@ set_console_color_rgb(void)
78077833
csbi.cbSize = sizeof(csbi);
78087834
csbi.srWindow.Right += 1;
78097835
csbi.srWindow.Bottom += 1;
7810-
csbi.ColorTable[0] = (COLORREF)bg;
7811-
csbi.ColorTable[7] = (COLORREF)fg;
7836+
csbi.ColorTable[g_color_index_bg] = (COLORREF)bg;
7837+
csbi.ColorTable[g_color_index_fg] = (COLORREF)fg;
78127838
if (has_csbiex)
78137839
pSetConsoleScreenBufferInfoEx(g_hConOut, &csbi);
78147840
# endif
@@ -7827,8 +7853,8 @@ reset_console_color_rgb(void)
78277853
csbi.cbSize = sizeof(csbi);
78287854
csbi.srWindow.Right += 1;
78297855
csbi.srWindow.Bottom += 1;
7830-
csbi.ColorTable[0] = (COLORREF)save_console_bg_rgb;
7831-
csbi.ColorTable[7] = (COLORREF)save_console_fg_rgb;
7856+
csbi.ColorTable[g_color_index_bg] = (COLORREF)save_console_bg_rgb;
7857+
csbi.ColorTable[g_color_index_fg] = (COLORREF)save_console_fg_rgb;
78327858
if (has_csbiex)
78337859
pSetConsoleScreenBufferInfoEx(g_hConOut, &csbi);
78347860
# endif
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
|f+0&#ffff4012|o@1| +0&#ffffff0|1| @64
2+
>f+0&#ffff4012|o@1| +0&#ffffff0|2| @64
3+
|f+0&#ffff4012|o@1| +0&#ffffff0|3| @64
4+
|f+0&#ffff4012|o@1| +0&#ffffff0|4| @64
5+
|f+0&#ffff4012|o@1| +0&#ffffff0|5| @64
6+
|f+0&#ffff4012|o@1| +0&#ffffff0|6| @64
7+
|f+0&#ffff4012|o@1| +0&#ffffff0|7| @64
8+
|f+0&#ffff4012|o@1| +0&#ffffff0|8| @64
9+
@52|2|,|1| @10|T|o|p|

src/testdir/test_arglist.vim

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,24 @@ func Test_argadd()
8080
call assert_equal(0, len(argv()))
8181
endfunc
8282

83+
func Test_argadd_empty_curbuf()
84+
new
85+
let curbuf = bufnr('%')
86+
call writefile(['test', 'Xargadd'], 'Xargadd')
87+
" must not re-use the current buffer.
88+
argadd Xargadd
89+
call assert_equal(curbuf, bufnr('%'))
90+
call assert_equal('', bufname('%'))
91+
call assert_equal(1, line('$'))
92+
rew
93+
call assert_notequal(curbuf, bufnr('%'))
94+
call assert_equal('Xargadd', bufname('%'))
95+
call assert_equal(2, line('$'))
96+
97+
%argd
98+
bwipe!
99+
endfunc
100+
83101
func Init_abc()
84102
args a b c
85103
next

src/testdir/test_command_count.vim

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,9 @@ endfunc
158158
func Test_command_count_4()
159159
%argd
160160
let bufnr = bufnr('$')
161-
arga aa bb cc dd ee ff
161+
next aa bb cc dd ee ff
162+
call assert_equal(bufnr, bufnr('%'))
163+
162164
3argu
163165
let args = []
164166
.,$-argdo call add(args, expand('%'))

0 commit comments

Comments
 (0)