patch 9.1.1145: multi-line completion has wrong indentation for last line
Commit:
https://github.com/vim/vim/commit/5090a1fecb86c44be83d55e139ed79b7785fa090
Author: glepnir <[email protected]>
Date: Mon Feb 24 19:10:37 2025 +0100
patch 9.1.1145: multi-line completion has wrong indentation for last line
Problem: When expanding omni completion items with newlines (e.g.
`then
end`), 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 <[email protected]>
Signed-off-by: Justin M. Keyes <[email protected]>
Signed-off-by: Christian Brabandt <[email protected]>
diff --git a/src/change.c b/src/change.c
index 294adf7df..a3329bdcb 100644
--- a/src/change.c
+++ b/src/change.c
@@ -1385,6 +1385,8 @@ del_bytes(
* OPENLINE_KEEPTRAIL keep trailing spaces
* OPENLINE_MARKFIX adjust mark positions after the line break
* OPENLINE_COM_LIST format comments with list or 2nd line indent
+ * OPENLINE_FORCE_INDENT set indent from second_line_indent, ignore
+ * 'autoindent'
*
* "second_line_indent": indent for after ^^D in Insert mode or if flag
* OPENLINE_COM_LIST
@@ -1498,9 +1500,11 @@ open_line(
if (dir == FORWARD && did_ai)
trunc_line = TRUE;
+ if ((flags & OPENLINE_FORCE_INDENT) && second_line_indent >= 0)
+ newindent = second_line_indent;
// If 'autoindent' and/or 'smartindent' is set, try to figure out what
// indent to use for the new line.
- if (curbuf->b_p_ai || do_si)
+ else if (curbuf->b_p_ai || do_si)
{
// count white space on current line
#ifdef FEAT_VARTABS
diff --git a/src/insexpand.c b/src/insexpand.c
index deae1ce34..edc4265e4 100644
--- a/src/insexpand.c
+++ b/src/insexpand.c
@@ -4473,6 +4473,7 @@ ins_compl_expand_multiple(char_u *str)
{
char_u *start = str;
char_u *curr = str;
+ int base_indent = get_indent();
while (*curr != NUL)
{
@@ -4483,7 +4484,7 @@ ins_compl_expand_multiple(char_u *str)
ins_char_bytes(start, (int)(curr - start));
// Handle newline
- open_line(FORWARD, OPENLINE_KEEPTRAIL, FALSE, NULL);
+ open_line(FORWARD, OPENLINE_KEEPTRAIL | OPENLINE_FORCE_INDENT,
base_indent, NULL);
start = curr + 1;
}
curr++;
diff --git a/src/testdir/dumps/Test_pum_with_special_characters_09.dump
b/src/testdir/dumps/Test_pum_with_special_characters_09.dump
new file mode 100644
index 000000000..7a6cac7cd
--- /dev/null
+++ b/src/testdir/dumps/Test_pum_with_special_characters_09.dump
@@ -0,0 +1,12 @@
+|l+0&#ffffff0|o|c|a|l| |a| |=| |f+0#ff404010&|u|n|c| |(|)| +0#0000000&@57
+| +0#ff404010&@1| +0#0000000&@72
+|e+0#ff404010&|n|d> +0#0000000&@71
+|~+0#4040ff13&| | +0#0000001#e0e0e08|f|u|n|c|t|i|o|n| |(|)| @3|
+0#4040ff13#ffffff0@56
+|~| | +0#0000001#ffd7ff255|f|o@1|b|a|r| @8| +0#4040ff13#ffffff0@56
+|~| | +0#0000001#ffd7ff255|你*&|好|^+&|@| @1|^|@|我*&|好| +&|
+0#4040ff13#ffffff0@56
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|-+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
diff --git a/src/testdir/dumps/Test_pum_with_special_characters_10.dump
b/src/testdir/dumps/Test_pum_with_special_characters_10.dump
new file mode 100644
index 000000000..ccaea76f2
--- /dev/null
+++ b/src/testdir/dumps/Test_pum_with_special_characters_10.dump
@@ -0,0 +1,12 @@
+|l+0&#ffffff0|o|c|a|l| |a| |=| |f|u|n|c| |(|)| @57
+@75
+|e|n|d> @71
+|~+0#4040ff13&| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|-+2#0000000&@1| |I|N|S|E|R|T| |-@1| +0&&@44|3|,|4| @10|A|l@1|
diff --git a/src/testdir/dumps/Test_pum_with_special_characters_11.dump
b/src/testdir/dumps/Test_pum_with_special_characters_11.dump
new file mode 100644
index 000000000..f6d8387a8
--- /dev/null
+++ b/src/testdir/dumps/Test_pum_with_special_characters_11.dump
@@ -0,0 +1,12 @@
+|l+0&#ffffff0|o|c|a|l| |a| |=| |f|u|n|c| |(|)| @57
+@2|l|o|c|a|l| |b| |=| |f+0#ff404010&|u|n|c| |(|)| +0#0000000&@55
+| +0#ff404010&@3| +0#0000000&@70
+| +0#ff404010&@1|e|n|d> +0#0000000&@69
+|e|n|d| | +0#0000001#e0e0e08|f|u|n|c|t|i|o|n| |(|)| @3| +0#0000000#ffffff0@54
+|~+0#4040ff13&| @2| +0#0000001#ffd7ff255|f|o@1|b|a|r| @8|
+0#4040ff13#ffffff0@54
+|~| @2| +0#0000001#ffd7ff255|你*&|好|^+&|@| @1|^|@|我*&|好| +&|
+0#4040ff13#ffffff0@54
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|-+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
diff --git a/src/testdir/dumps/Test_pum_with_special_characters_12.dump
b/src/testdir/dumps/Test_pum_with_special_characters_12.dump
new file mode 100644
index 000000000..5807526ed
--- /dev/null
+++ b/src/testdir/dumps/Test_pum_with_special_characters_12.dump
@@ -0,0 +1,12 @@
+|l+0&#ffffff0|o|c|a|l| |a| |=| |f|u|n|c| |(|)| @57
+@2|l|o|c|a|l| |b| |=| |f|u|n|c| |(|)| @55
+@75
+@2|e|n|d> @69
+|e|n|d| @71
+|~+0#4040ff13&| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|-+2#0000000&@1| |I|N|S|E|R|T| |-@1| +0&&@44|4|,|5|-|6| @8|A|l@1|
diff --git a/src/testdir/test_popup.vim b/src/testdir/test_popup.vim
index 63f0016dc..82d2ef0be 100644
--- a/src/testdir/test_popup.vim
+++ b/src/testdir/test_popup.vim
@@ -1946,6 +1946,23 @@ func Test_pum_complete_with_special_characters()
call VerifyScreenDump(buf, 'Test_pum_with_special_characters_08', {})
call term_sendkeys(buf, "\<C-E>\<Esc>")
+ call term_sendkeys(buf, ":setlocal autoindent tabstop=2 shiftwidth=2\<CR>")
+ call term_sendkeys(buf, "Slocal a = \<C-X>\<C-O>")
+ call TermWait(buf, 50)
+ call VerifyScreenDump(buf, 'Test_pum_with_special_characters_09', {})
+
+ call term_sendkeys(buf, "\<C-Y>")
+ call TermWait(buf, 50)
+ call VerifyScreenDump(buf, 'Test_pum_with_special_characters_10', {})
+
+ call term_sendkeys(buf, "\<ESC>kAlocal b = \<C-X>\<C-O>")
+ call TermWait(buf, 50)
+ call VerifyScreenDump(buf, 'Test_pum_with_special_characters_11', {})
+
+ call term_sendkeys(buf, "\<C-Y>")
+ call TermWait(buf, 50)
+ call VerifyScreenDump(buf, 'Test_pum_with_special_characters_12', {})
+
call StopVimInTerminal(buf)
endfunc
diff --git a/src/version.c b/src/version.c
index 5652fc34d..0adb6521d 100644
--- a/src/version.c
+++ b/src/version.c
@@ -704,6 +704,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 1145,
/**/
1144,
/**/
diff --git a/src/vim.h b/src/vim.h
index 2ebc8fe02..da2835c1c 100644
--- a/src/vim.h
+++ b/src/vim.h
@@ -1175,12 +1175,13 @@ extern int (*dyn_libintl_wputenv)(const wchar_t
*envstring);
#define INSCHAR_COM_LIST 16 // format comments with list/2nd line indent
// flags for open_line()
-#define OPENLINE_DELSPACES 0x01 // delete spaces after cursor
-#define OPENLINE_DO_COM 0x02 // format comments
-#define OPENLINE_KEEPTRAIL 0x04 // keep trailing spaces
-#define OPENLINE_MARKFIX 0x08 // fix mark positions
-#define OPENLINE_COM_LIST 0x10 // format comments with list/2nd line
indent
-#define OPENLINE_FORMAT 0x20 // formatting long comment
+#define OPENLINE_DELSPACES 0x01 // delete spaces after cursor
+#define OPENLINE_DO_COM 0x02 // format comments
+#define OPENLINE_KEEPTRAIL 0x04 // keep trailing spaces
+#define OPENLINE_MARKFIX 0x08 // fix mark positions
+#define OPENLINE_COM_LIST 0x10 // format comments with list/2nd line
indent
+#define OPENLINE_FORMAT 0x20 // formatting long comment
+#define OPENLINE_FORCE_INDENT 0x40 // use second_line_indent without
indent logic
// There are five history tables:
#define HIST_CMD 0 // colon commands
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/vim_dev/E1tmcyx-00AgvX-Qt%40256bit.org.