Skip to content

Commit 5090a1f

Browse files
glepnirchrisbra
authored andcommitted
patch 9.1.1145: multi-line completion has wrong indentation for last line
Problem: When expanding omni completion items with newlines (e.g. `then\n\t\nend`), the end statement gets wrong indentation. Solution: Add OPENLINE_FORCE_INDENT flag to make open_line() use second_line_indent directly (glepnir) closes: #16614 Signed-off-by: glepnir <glephunter@gmail.com> Signed-off-by: Justin M. Keyes <justinkz@gmail.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
1 parent 5b97947 commit 5090a1f

9 files changed

Lines changed: 81 additions & 8 deletions

src/change.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1385,6 +1385,8 @@ del_bytes(
13851385
* OPENLINE_KEEPTRAIL keep trailing spaces
13861386
* OPENLINE_MARKFIX adjust mark positions after the line break
13871387
* OPENLINE_COM_LIST format comments with list or 2nd line indent
1388+
* OPENLINE_FORCE_INDENT set indent from second_line_indent, ignore
1389+
* 'autoindent'
13881390
*
13891391
* "second_line_indent": indent for after ^^D in Insert mode or if flag
13901392
* OPENLINE_COM_LIST
@@ -1498,9 +1500,11 @@ open_line(
14981500
if (dir == FORWARD && did_ai)
14991501
trunc_line = TRUE;
15001502

1503+
if ((flags & OPENLINE_FORCE_INDENT) && second_line_indent >= 0)
1504+
newindent = second_line_indent;
15011505
// If 'autoindent' and/or 'smartindent' is set, try to figure out what
15021506
// indent to use for the new line.
1503-
if (curbuf->b_p_ai || do_si)
1507+
else if (curbuf->b_p_ai || do_si)
15041508
{
15051509
// count white space on current line
15061510
#ifdef FEAT_VARTABS

src/insexpand.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4473,6 +4473,7 @@ ins_compl_expand_multiple(char_u *str)
44734473
{
44744474
char_u *start = str;
44754475
char_u *curr = str;
4476+
int base_indent = get_indent();
44764477

44774478
while (*curr != NUL)
44784479
{
@@ -4483,7 +4484,7 @@ ins_compl_expand_multiple(char_u *str)
44834484
ins_char_bytes(start, (int)(curr - start));
44844485

44854486
// Handle newline
4486-
open_line(FORWARD, OPENLINE_KEEPTRAIL, FALSE, NULL);
4487+
open_line(FORWARD, OPENLINE_KEEPTRAIL | OPENLINE_FORCE_INDENT, base_indent, NULL);
44874488
start = curr + 1;
44884489
}
44894490
curr++;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
|l+0&#ffffff0|o|c|a|l| |a| |=| |f+0#ff404010&|u|n|c| |(|)| +0#0000000&@57
2+
| +0#ff404010&@1| +0#0000000&@72
3+
|e+0#ff404010&|n|d> +0#0000000&@71
4+
|~+0#4040ff13&| | +0#0000001#e0e0e08|f|u|n|c|t|i|o|n| |(|)| @3| +0#4040ff13#ffffff0@56
5+
|~| | +0#0000001#ffd7ff255|f|o@1|b|a|r| @8| +0#4040ff13#ffffff0@56
6+
|~| | +0#0000001#ffd7ff255|你*&|好|^+&|@| @1|^|@|我*&|好| +&| +0#4040ff13#ffffff0@56
7+
|~| @73
8+
|~| @73
9+
|~| @73
10+
|~| @73
11+
|~| @73
12+
|-+2#0000000&@1| |O|m|n|i| |c|o|m|p|l|e|t|i|o|n| |(|^|O|^|N|^|P|)| |m+0#00e0003&|a|t|c|h| |1| |o|f| |3| +0#0000000&@34
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
|l+0&#ffffff0|o|c|a|l| |a| |=| |f|u|n|c| |(|)| @57
2+
@75
3+
|e|n|d> @71
4+
|~+0#4040ff13&| @73
5+
|~| @73
6+
|~| @73
7+
|~| @73
8+
|~| @73
9+
|~| @73
10+
|~| @73
11+
|~| @73
12+
|-+2#0000000&@1| |I|N|S|E|R|T| |-@1| +0&&@44|3|,|4| @10|A|l@1|
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
|l+0&#ffffff0|o|c|a|l| |a| |=| |f|u|n|c| |(|)| @57
2+
@2|l|o|c|a|l| |b| |=| |f+0#ff404010&|u|n|c| |(|)| +0#0000000&@55
3+
| +0#ff404010&@3| +0#0000000&@70
4+
| +0#ff404010&@1|e|n|d> +0#0000000&@69
5+
|e|n|d| | +0#0000001#e0e0e08|f|u|n|c|t|i|o|n| |(|)| @3| +0#0000000#ffffff0@54
6+
|~+0#4040ff13&| @2| +0#0000001#ffd7ff255|f|o@1|b|a|r| @8| +0#4040ff13#ffffff0@54
7+
|~| @2| +0#0000001#ffd7ff255|你*&|好|^+&|@| @1|^|@|我*&|好| +&| +0#4040ff13#ffffff0@54
8+
|~| @73
9+
|~| @73
10+
|~| @73
11+
|~| @73
12+
|-+2#0000000&@1| |O|m|n|i| |c|o|m|p|l|e|t|i|o|n| |(|^|O|^|N|^|P|)| |m+0#00e0003&|a|t|c|h| |1| |o|f| |3| +0#0000000&@34
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
|l+0&#ffffff0|o|c|a|l| |a| |=| |f|u|n|c| |(|)| @57
2+
@2|l|o|c|a|l| |b| |=| |f|u|n|c| |(|)| @55
3+
@75
4+
@2|e|n|d> @69
5+
|e|n|d| @71
6+
|~+0#4040ff13&| @73
7+
|~| @73
8+
|~| @73
9+
|~| @73
10+
|~| @73
11+
|~| @73
12+
|-+2#0000000&@1| |I|N|S|E|R|T| |-@1| +0&&@44|4|,|5|-|6| @8|A|l@1|

src/testdir/test_popup.vim

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1946,6 +1946,23 @@ func Test_pum_complete_with_special_characters()
19461946
call VerifyScreenDump(buf, 'Test_pum_with_special_characters_08', {})
19471947
call term_sendkeys(buf, "\<C-E>\<Esc>")
19481948

1949+
call term_sendkeys(buf, ":setlocal autoindent tabstop=2 shiftwidth=2\<CR>")
1950+
call term_sendkeys(buf, "Slocal a = \<C-X>\<C-O>")
1951+
call TermWait(buf, 50)
1952+
call VerifyScreenDump(buf, 'Test_pum_with_special_characters_09', {})
1953+
1954+
call term_sendkeys(buf, "\<C-Y>")
1955+
call TermWait(buf, 50)
1956+
call VerifyScreenDump(buf, 'Test_pum_with_special_characters_10', {})
1957+
1958+
call term_sendkeys(buf, "\<ESC>kAlocal b = \<C-X>\<C-O>")
1959+
call TermWait(buf, 50)
1960+
call VerifyScreenDump(buf, 'Test_pum_with_special_characters_11', {})
1961+
1962+
call term_sendkeys(buf, "\<C-Y>")
1963+
call TermWait(buf, 50)
1964+
call VerifyScreenDump(buf, 'Test_pum_with_special_characters_12', {})
1965+
19491966
call StopVimInTerminal(buf)
19501967
endfunc
19511968

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,8 @@ static char *(features[]) =
704704

705705
static int included_patches[] =
706706
{ /* Add new patch number below this line */
707+
/**/
708+
1145,
707709
/**/
708710
1144,
709711
/**/

src/vim.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,12 +1175,13 @@ extern int (*dyn_libintl_wputenv)(const wchar_t *envstring);
11751175
#define INSCHAR_COM_LIST 16 // format comments with list/2nd line indent
11761176

11771177
// flags for open_line()
1178-
#define OPENLINE_DELSPACES 0x01 // delete spaces after cursor
1179-
#define OPENLINE_DO_COM 0x02 // format comments
1180-
#define OPENLINE_KEEPTRAIL 0x04 // keep trailing spaces
1181-
#define OPENLINE_MARKFIX 0x08 // fix mark positions
1182-
#define OPENLINE_COM_LIST 0x10 // format comments with list/2nd line indent
1183-
#define OPENLINE_FORMAT 0x20 // formatting long comment
1178+
#define OPENLINE_DELSPACES 0x01 // delete spaces after cursor
1179+
#define OPENLINE_DO_COM 0x02 // format comments
1180+
#define OPENLINE_KEEPTRAIL 0x04 // keep trailing spaces
1181+
#define OPENLINE_MARKFIX 0x08 // fix mark positions
1182+
#define OPENLINE_COM_LIST 0x10 // format comments with list/2nd line indent
1183+
#define OPENLINE_FORMAT 0x20 // formatting long comment
1184+
#define OPENLINE_FORCE_INDENT 0x40 // use second_line_indent without indent logic
11841185

11851186
// There are five history tables:
11861187
#define HIST_CMD 0 // colon commands

0 commit comments

Comments
 (0)