Skip to content

Commit 1204c03

Browse files
committed
Merge remote-tracking branch 'vim/master'
2 parents 544305e + 9d7fdd4 commit 1204c03

50 files changed

Lines changed: 800 additions & 198 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

runtime/doc/eval.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5228,6 +5228,7 @@ getwininfo([{winid}]) *getwininfo()*
52285228
tab pages is returned.
52295229

52305230
Each List item is a Dictionary with the following entries:
5231+
botline last displayed buffer line
52315232
bufnr number of buffer in the window
52325233
height window height (excluding winbar)
52335234
loclist 1 if showing a location list
@@ -5237,6 +5238,7 @@ getwininfo([{winid}]) *getwininfo()*
52375238
terminal 1 if a terminal window
52385239
{only with the +terminal feature}
52395240
tabnr tab page number
5241+
topline first displayed buffer line
52405242
variables a reference to the dictionary with
52415243
window-local variables
52425244
width window width

src/buffer.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2167,11 +2167,9 @@ free_buf_options(
21672167
clear_string_option(&buf->b_p_isk);
21682168
#ifdef FEAT_VARTABS
21692169
clear_string_option(&buf->b_p_vsts);
2170-
if (buf->b_p_vsts_nopaste)
2171-
vim_free(buf->b_p_vsts_nopaste);
2170+
vim_free(buf->b_p_vsts_nopaste);
21722171
buf->b_p_vsts_nopaste = NULL;
2173-
if (buf->b_p_vsts_array)
2174-
vim_free(buf->b_p_vsts_array);
2172+
vim_free(buf->b_p_vsts_array);
21752173
buf->b_p_vsts_array = NULL;
21762174
clear_string_option(&buf->b_p_vts);
21772175
VIM_CLEAR(buf->b_p_vts_array);

src/channel.c

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1823,6 +1823,7 @@ channel_consume(channel_T *channel, ch_part_T part, int len)
18231823

18241824
mch_memmove(buf, buf + len, node->rq_buflen - len);
18251825
node->rq_buflen -= len;
1826+
node->rq_buffer[node->rq_buflen] = NUL;
18261827
}
18271828

18281829
/*
@@ -1845,7 +1846,7 @@ channel_collapse(channel_T *channel, ch_part_T part, int want_nl)
18451846
return FAIL;
18461847

18471848
last_node = node->rq_next;
1848-
len = node->rq_buflen + last_node->rq_buflen + 1;
1849+
len = node->rq_buflen + last_node->rq_buflen;
18491850
if (want_nl)
18501851
while (last_node->rq_next != NULL
18511852
&& channel_first_nl(last_node) == NULL)
@@ -1854,7 +1855,7 @@ channel_collapse(channel_T *channel, ch_part_T part, int want_nl)
18541855
len += last_node->rq_buflen;
18551856
}
18561857

1857-
p = newbuf = alloc(len);
1858+
p = newbuf = alloc(len + 1);
18581859
if (newbuf == NULL)
18591860
return FAIL; /* out of memory */
18601861
mch_memmove(p, node->rq_buffer, node->rq_buflen);
@@ -1868,6 +1869,7 @@ channel_collapse(channel_T *channel, ch_part_T part, int want_nl)
18681869
p += n->rq_buflen;
18691870
vim_free(n->rq_buffer);
18701871
}
1872+
*p = NUL;
18711873
node->rq_buflen = (long_u)(p - newbuf);
18721874

18731875
/* dispose of the collapsed nodes and their buffers */
@@ -2692,30 +2694,20 @@ may_invoke_callback(channel_T *channel, ch_part_T part)
26922694
}
26932695
buf = node->rq_buffer;
26942696

2695-
if (nl == NULL)
2696-
{
2697-
/* Flush remaining message that is missing a NL. */
2698-
char_u *new_buf;
2699-
2700-
new_buf = vim_realloc(buf, node->rq_buflen + 1);
2701-
if (new_buf == NULL)
2702-
/* This might fail over and over again, should the message
2703-
* be dropped? */
2704-
return FALSE;
2705-
buf = new_buf;
2706-
node->rq_buffer = buf;
2707-
nl = buf + node->rq_buflen++;
2708-
*nl = NUL;
2709-
}
2710-
2711-
/* Convert NUL to NL, the internal representation. */
2712-
for (p = buf; p < nl && p < buf + node->rq_buflen; ++p)
2697+
// Convert NUL to NL, the internal representation.
2698+
for (p = buf; (nl == NULL || p < nl)
2699+
&& p < buf + node->rq_buflen; ++p)
27132700
if (*p == NUL)
27142701
*p = NL;
27152702

2716-
if (nl + 1 == buf + node->rq_buflen)
2703+
if (nl == NULL)
2704+
{
2705+
// get the whole buffer, drop the NL
2706+
msg = channel_get(channel, part, NULL);
2707+
}
2708+
else if (nl + 1 == buf + node->rq_buflen)
27172709
{
2718-
/* get the whole buffer, drop the NL */
2710+
// get the whole buffer
27192711
msg = channel_get(channel, part, NULL);
27202712
*nl = NUL;
27212713
}

src/crypt.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ typedef struct {
4242
/* Optional function pointer for a self-test. */
4343
int (* self_test_fn)();
4444

45-
/* Function pointer for initializing encryption/decription. */
45+
// Function pointer for initializing encryption/description.
4646
void (* init_fn)(cryptstate_T *state, char_u *key,
4747
char_u *salt, int salt_len, char_u *seed, int seed_len);
4848

src/diff.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -866,7 +866,11 @@ diff_try_update(
866866
int
867867
diff_internal(void)
868868
{
869-
return (diff_flags & DIFF_INTERNAL) != 0 && *p_dex == NUL;
869+
return (diff_flags & DIFF_INTERNAL) != 0
870+
#ifdef FEAT_EVAL
871+
&& *p_dex == NUL
872+
#endif
873+
;
870874
}
871875

872876
/*

src/eval.c

Lines changed: 40 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,39 @@ static char_u *find_option_end(char_u **arg, int *opt_flags);
253253
/* for VIM_VERSION_ defines */
254254
#include "version.h"
255255

256+
/*
257+
* Return "n1" divided by "n2", taking care of dividing by zero.
258+
*/
259+
static varnumber_T
260+
num_divide(varnumber_T n1, varnumber_T n2)
261+
{
262+
varnumber_T result;
263+
264+
if (n2 == 0) // give an error message?
265+
{
266+
if (n1 == 0)
267+
result = VARNUM_MIN; // similar to NaN
268+
else if (n1 < 0)
269+
result = -VARNUM_MAX;
270+
else
271+
result = VARNUM_MAX;
272+
}
273+
else
274+
result = n1 / n2;
275+
276+
return result;
277+
}
278+
279+
/*
280+
* Return "n1" modulus "n2", taking care of dividing by zero.
281+
*/
282+
static varnumber_T
283+
num_modulus(varnumber_T n1, varnumber_T n2)
284+
{
285+
// Give an error when n2 is 0?
286+
return (n2 == 0) ? 0 : (n1 % n2);
287+
}
288+
256289

257290
#if defined(EBCDIC) || defined(PROTO)
258291
/*
@@ -1758,8 +1791,8 @@ ex_let_one(
17581791
case '+': n = numval + n; break;
17591792
case '-': n = numval - n; break;
17601793
case '*': n = numval * n; break;
1761-
case '/': n = numval / n; break;
1762-
case '%': n = numval % n; break;
1794+
case '/': n = (long)num_divide(numval, n); break;
1795+
case '%': n = (long)num_modulus(numval, n); break;
17631796
}
17641797
}
17651798
else if (opt_type == 0 && stringval != NULL) // string
@@ -2538,8 +2571,8 @@ tv_op(typval_T *tv1, typval_T *tv2, char_u *op)
25382571
case '+': n += tv_get_number(tv2); break;
25392572
case '-': n -= tv_get_number(tv2); break;
25402573
case '*': n *= tv_get_number(tv2); break;
2541-
case '/': n /= tv_get_number(tv2); break;
2542-
case '%': n %= tv_get_number(tv2); break;
2574+
case '/': n = num_divide(n, tv_get_number(tv2)); break;
2575+
case '%': n = num_modulus(n, tv_get_number(tv2)); break;
25432576
}
25442577
clear_tv(tv1);
25452578
tv1->v_type = VAR_NUMBER;
@@ -4113,26 +4146,10 @@ eval6(
41134146
if (op == '*')
41144147
n1 = n1 * n2;
41154148
else if (op == '/')
4116-
{
4117-
if (n2 == 0) /* give an error message? */
4118-
{
4119-
if (n1 == 0)
4120-
n1 = VARNUM_MIN; /* similar to NaN */
4121-
else if (n1 < 0)
4122-
n1 = -VARNUM_MAX;
4123-
else
4124-
n1 = VARNUM_MAX;
4125-
}
4126-
else
4127-
n1 = n1 / n2;
4128-
}
4149+
n1 = num_divide(n1, n2);
41294150
else
4130-
{
4131-
if (n2 == 0) /* give an error message? */
4132-
n1 = 0;
4133-
else
4134-
n1 = n1 % n2;
4135-
}
4151+
n1 = num_modulus(n1, n2);
4152+
41364153
rettv->v_type = VAR_NUMBER;
41374154
rettv->vval.v_number = n1;
41384155
}

src/evalfunc.c

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2451,7 +2451,7 @@ f_char2nr(typval_T *argvars, typval_T *rettv)
24512451
utf8 = (int)tv_get_number_chk(&argvars[1], NULL);
24522452

24532453
if (utf8)
2454-
rettv->vval.v_number = (*utf_ptr2char)(tv_get_string(&argvars[0]));
2454+
rettv->vval.v_number = utf_ptr2char(tv_get_string(&argvars[0]));
24552455
else
24562456
rettv->vval.v_number = (*mb_ptr2char)(tv_get_string(&argvars[0]));
24572457
}
@@ -4811,6 +4811,7 @@ f_getchar(typval_T *argvars, typval_T *rettv)
48114811
{
48124812
varnumber_T n;
48134813
int error = FALSE;
4814+
int save_reg_executing = reg_executing;
48144815

48154816
#ifdef MESSAGE_QUEUE
48164817
// vpeekc() used to check for messages, but that caused problems, invoking
@@ -4845,6 +4846,7 @@ f_getchar(typval_T *argvars, typval_T *rettv)
48454846
}
48464847
--no_mapping;
48474848
--allow_keys;
4849+
reg_executing = save_reg_executing;
48484850

48494851
set_vim_var_nr(VV_MOUSE_WIN, 0);
48504852
set_vim_var_nr(VV_MOUSE_WINID, 0);
@@ -5480,9 +5482,23 @@ getpos_both(
54805482
(varnumber_T)0);
54815483
if (getcurpos)
54825484
{
5485+
int save_set_curswant = curwin->w_set_curswant;
5486+
colnr_T save_curswant = curwin->w_curswant;
5487+
colnr_T save_virtcol = curwin->w_virtcol;
5488+
54835489
update_curswant();
54845490
list_append_number(l, curwin->w_curswant == MAXCOL ?
54855491
(varnumber_T)MAXCOL : (varnumber_T)curwin->w_curswant + 1);
5492+
5493+
// Do not change "curswant", as it is unexpected that a get
5494+
// function has a side effect.
5495+
if (save_set_curswant)
5496+
{
5497+
curwin->w_set_curswant = save_set_curswant;
5498+
curwin->w_curswant = save_curswant;
5499+
curwin->w_virtcol = save_virtcol;
5500+
curwin->w_valid &= ~VALID_VIRTCOL;
5501+
}
54865502
}
54875503
}
54885504
else
@@ -5770,6 +5786,8 @@ get_win_info(win_T *wp, short tpnr, short winnr)
57705786
dict_add_number(dict, "winid", wp->w_id);
57715787
dict_add_number(dict, "height", wp->w_height);
57725788
dict_add_number(dict, "winrow", wp->w_winrow + 1);
5789+
dict_add_number(dict, "topline", wp->w_topline);
5790+
dict_add_number(dict, "botline", wp->w_botline - 1);
57735791
#ifdef FEAT_MENU
57745792
dict_add_number(dict, "winbar", wp->w_winbar_height);
57755793
#endif
@@ -6163,7 +6181,7 @@ f_has(typval_T *argvars, typval_T *rettv)
61636181
#ifdef MSWIN
61646182
"win32",
61656183
#endif
6166-
#if defined(UNIX) && (defined(__CYGWIN32__) || defined(__CYGWIN__))
6184+
#if defined(UNIX) && defined(__CYGWIN__)
61676185
"win32unix",
61686186
#endif
61696187
#ifdef _WIN64
@@ -8724,7 +8742,7 @@ f_nr2char(typval_T *argvars, typval_T *rettv)
87248742
if (argvars[1].v_type != VAR_UNKNOWN)
87258743
utf8 = (int)tv_get_number_chk(&argvars[1], NULL);
87268744
if (utf8)
8727-
buf[(*utf_char2bytes)((int)tv_get_number(&argvars[0]), buf)] = NUL;
8745+
buf[utf_char2bytes((int)tv_get_number(&argvars[0]), buf)] = NUL;
87288746
else
87298747
buf[(*mb_char2bytes)((int)tv_get_number(&argvars[0]), buf)] = NUL;
87308748
}
@@ -11678,7 +11696,7 @@ f_sign_jump(typval_T *argvars, typval_T *rettv)
1167811696

1167911697
rettv->vval.v_number = -1;
1168011698

11681-
// Sign identifer
11699+
// Sign identifier
1168211700
sign_id = (int)tv_get_number_chk(&argvars[0], &notanum);
1168311701
if (notanum)
1168411702
return;
@@ -11730,7 +11748,7 @@ f_sign_place(typval_T *argvars, typval_T *rettv)
1173011748

1173111749
rettv->vval.v_number = -1;
1173211750

11733-
// Sign identifer
11751+
// Sign identifier
1173411752
sign_id = (int)tv_get_number_chk(&argvars[0], &notanum);
1173511753
if (notanum)
1173611754
return;

src/ex_cmds2.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2453,7 +2453,7 @@ check_changed_any(
24532453

24542454
goto_tabpage_win(tp, wp);
24552455

2456-
/* Paranoia: did autocms wipe out the buffer with changes? */
2456+
// Paranoia: did autocmd wipe out the buffer with changes?
24572457
if (!bufref_valid(&bufref))
24582458
goto theend;
24592459
goto buf_found;

src/ex_docmd.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10286,6 +10286,7 @@ save_current_state(save_state_T *sst)
1028610286
sst->save_insertmode = p_im;
1028710287
sst->save_finish_op = finish_op;
1028810288
sst->save_opcount = opcount;
10289+
sst->save_reg_executing = reg_executing;
1028910290

1029010291
msg_scroll = FALSE; /* no msg scrolling in Normal mode */
1029110292
restart_edit = 0; /* don't go to Insert mode */
@@ -10311,6 +10312,7 @@ restore_current_state(save_state_T *sst)
1031110312
p_im = sst->save_insertmode;
1031210313
finish_op = sst->save_finish_op;
1031310314
opcount = sst->save_opcount;
10315+
reg_executing = sst->save_reg_executing;
1031410316
msg_didout |= sst->save_msg_didout; /* don't reset msg_didout now */
1031510317

1031610318
/* Restore the state (needed when called from a function executed for

src/globals.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ EXTERN int mouse_dragging INIT(= 0); /* extending Visual area with
426426
# if defined(FEAT_MOUSE_DEC)
427427
/*
428428
* When the DEC mouse has been pressed but not yet released we enable
429-
* automatic querys for the mouse position.
429+
* automatic queries for the mouse position.
430430
*/
431431
EXTERN int WantQueryMouse INIT(= FALSE);
432432
# endif

0 commit comments

Comments
 (0)