Skip to content

Commit e95b546

Browse files
committed
Merge remote-tracking branch 'vim/master'
2 parents 703ff61 + d79a262 commit e95b546

File tree

11 files changed

+452
-176
lines changed

11 files changed

+452
-176
lines changed

runtime/doc/eval.txt

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2110,6 +2110,8 @@ cursor({lnum}, {col} [, {off}])
21102110
cursor({list}) Number move cursor to position in {list}
21112111
deepcopy({expr} [, {noref}]) any make a full copy of {expr}
21122112
delete({fname} [, {flags}]) Number delete the file or directory {fname}
2113+
deletebufline({expr}, {first}[, {last}])
2114+
Number delete lines from buffer {expr}
21132115
did_filetype() Number |TRUE| if FileType autocmd event used
21142116
diff_filler({lnum}) Number diff filler lines about {lnum}
21152117
diff_hlID({lnum}, {col}) Number diff highlighting at {lnum}/{col}
@@ -2560,6 +2562,21 @@ append({lnum}, {expr}) *append()*
25602562
0 for success. Example: >
25612563
:let failed = append(line('$'), "# THE END")
25622564
:let failed = append(0, ["Chapter 1", "the beginning"])
2565+
2566+
appendbufline({expr}, {lnum}, {text}) *appendbufline()*
2567+
Like |append()| but append the text in buffer {expr}.
2568+
2569+
For the use of {expr}, see |bufname()|.
2570+
2571+
{lnum} is used like with |append()|. Note that using |line()|
2572+
would use the current buffer, not the one appending to.
2573+
Use "$" to append at the end of the buffer.
2574+
2575+
On success 0 is returned, on failure 1 is returned.
2576+
2577+
If {expr} is not a valid buffer or {lnum} is not valid, an
2578+
error message is given. Example: >
2579+
:let failed = appendbufline(13, 0, "# THE START")
25632580
<
25642581
*argc()*
25652582
argc() The result is the number of files in the argument list of the
@@ -3502,8 +3519,19 @@ delete({fname} [, {flags}]) *delete()*
35023519
successful and -1 when the deletion failed or partly failed.
35033520

35043521
Use |remove()| to delete an item from a |List|.
3505-
To delete a line from the buffer use |:delete|. Use |:exe|
3506-
when the line number is in a variable.
3522+
To delete a line from the buffer use |:delete| or
3523+
|deletebufline()|.
3524+
3525+
deletebufline({expr}, {first}[, {last}]) *deletebufline()*
3526+
Delete lines {first} to {last} (inclusive) from buffer {expr}.
3527+
If {last} is omitted then delete line {first} only.
3528+
On success 0 is returned, on failure 1 is returned.
3529+
3530+
For the use of {expr}, see |bufname()| above.
3531+
3532+
{first} and {last} are used like with |setline()|. Note that
3533+
when using |line()| this refers to the current buffer. Use "$"
3534+
to refer to the last line in buffer {expr}.
35073535

35083536
*did_filetype()*
35093537
did_filetype() Returns |TRUE| when autocommands are being executed and the

src/buffer.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5743,6 +5743,10 @@ buf_spname(buf_T *buf)
57435743
#endif
57445744
if (buf->b_fname != NULL)
57455745
return buf->b_fname;
5746+
#ifdef FEAT_JOB_CHANNEL
5747+
if (bt_prompt(buf))
5748+
return (char_u *)_("[Prompt]");
5749+
#endif
57465750
return (char_u *)_("[Scratch]");
57475751
}
57485752

src/edit.c

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -811,6 +811,14 @@ edit(
811811
do
812812
{
813813
c = safe_vgetc();
814+
815+
if (stop_insert_mode)
816+
{
817+
// Insert mode ended, possibly from a callback.
818+
count = 0;
819+
nomove = TRUE;
820+
goto doESCkey;
821+
}
814822
} while (c == K_IGNORE || c == K_NOP);
815823

816824
/* Don't want K_CURSORHOLD for the second key, e.g., after CTRL-V. */
@@ -1165,6 +1173,18 @@ edit(
11651173
break;
11661174

11671175
case Ctrl_W: /* delete word before the cursor */
1176+
#ifdef FEAT_JOB_CHANNEL
1177+
if (bt_prompt(curbuf) && (mod_mask & MOD_MASK_SHIFT) == 0)
1178+
{
1179+
// In a prompt window CTRL-W is used for window commands.
1180+
// Use Shift-CTRL-W to delete a word.
1181+
stuffcharReadbuff(Ctrl_W);
1182+
restart_edit = 'i';
1183+
nomove = TRUE;
1184+
count = 0;
1185+
goto doESCkey;
1186+
}
1187+
#endif
11681188
did_backspace = ins_bs(c, BACKSPACE_WORD, &inserted_space);
11691189
auto_format(FALSE, TRUE);
11701190
break;
@@ -1400,11 +1420,10 @@ edit(
14001420
#ifdef FEAT_JOB_CHANNEL
14011421
if (bt_prompt(curbuf))
14021422
{
1403-
buf_T *buf = curbuf;
1404-
14051423
invoke_prompt_callback();
1406-
if (curbuf != buf)
1407-
// buffer changed, get out of Insert mode
1424+
if (!bt_prompt(curbuf))
1425+
// buffer changed to a non-prompt buffer, get out of
1426+
// Insert mode
14081427
goto doESCkey;
14091428
break;
14101429
}
@@ -1878,10 +1897,25 @@ init_prompt(int cmdchar_todo)
18781897
coladvance((colnr_T)MAXCOL);
18791898
changed_bytes(curbuf->b_ml.ml_line_count, 0);
18801899
}
1900+
1901+
// Insert always starts after the prompt, allow editing text after it.
1902+
if (Insstart_orig.lnum != curwin->w_cursor.lnum
1903+
|| Insstart_orig.col != (int)STRLEN(prompt))
1904+
{
1905+
Insstart.lnum = curwin->w_cursor.lnum;
1906+
Insstart.col = STRLEN(prompt);
1907+
Insstart_orig = Insstart;
1908+
Insstart_textlen = Insstart.col;
1909+
Insstart_blank_vcol = MAXCOL;
1910+
arrow_used = FALSE;
1911+
}
1912+
18811913
if (cmdchar_todo == 'A')
18821914
coladvance((colnr_T)MAXCOL);
18831915
if (cmdchar_todo == 'I' || curwin->w_cursor.col <= (int)STRLEN(prompt))
18841916
curwin->w_cursor.col = STRLEN(prompt);
1917+
/* Make sure the cursor is in a valid position. */
1918+
check_cursor();
18851919
}
18861920

18871921
/*
@@ -9448,7 +9482,7 @@ ins_bs(
94489482

94499483
/* If deleted before the insertion point, adjust it */
94509484
if (curwin->w_cursor.lnum == Insstart_orig.lnum
9451-
&& curwin->w_cursor.col < Insstart_orig.col)
9485+
&& curwin->w_cursor.col < Insstart_orig.col)
94529486
Insstart_orig.col = curwin->w_cursor.col;
94539487

94549488
/* vi behaviour: the cursor moves backward but the character that
@@ -9498,6 +9532,11 @@ ins_mouse(int c)
94989532
* previous one to stop insert there properly. */
94999533
curwin = old_curwin;
95009534
curbuf = curwin->w_buffer;
9535+
#ifdef FEAT_JOB_CHANNEL
9536+
if (bt_prompt(curbuf))
9537+
// Restart Insert mode when re-entering the prompt buffer.
9538+
curbuf->b_prompt_insert = 'A';
9539+
#endif
95019540
}
95029541
start_arrow(curwin == old_curwin ? &tpos : NULL);
95039542
if (curwin != new_curwin && win_valid(new_curwin))

0 commit comments

Comments
 (0)