From 42863634dd83d70710436bb599b13571d734c662 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 5 Jul 2022 14:58:59 +0800 Subject: vim-patch:8.2.3615: wrong indent in first line if re-formatting with indent expr Problem: When re-formatting with an indent expression the first line of a paragraph may get the wrong indent. (Martin F. Krafft) Solution: Apply the correct indenting function for the first line. (Christian Brabandt, closes vim/vim#9150, closes vim/vim#9056) https://github.com/vim/vim/commit/818ff25cd1aabf60b9cd239da2f1328a959954f7 --- src/nvim/ops.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src/nvim/ops.c') diff --git a/src/nvim/ops.c b/src/nvim/ops.c index a8198cfce9..cd7ae25a20 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -4547,9 +4547,20 @@ void format_lines(linenr_T line_count, int avoid_fex) */ if (is_end_par || force_format) { if (need_set_indent) { + int indent = 0; // amount of indent needed + // replace indent in first line with minimal number of // tabs and spaces, according to current options - (void)set_indent(get_indent(), SIN_CHANGED); + if (curbuf->b_p_lisp) { + indent = get_lisp_indent(); + } else { + if (cindent_on()) { + indent = *curbuf->b_p_inde != NUL ? get_expr_indent() : get_c_indent(); + } else { + indent = get_indent(); + } + } + (void)set_indent(indent, SIN_CHANGED); } // put cursor on last non-space -- cgit From 04ba37773e5755375f4fa3f5af23cbbdb5eb5fc8 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 5 Jul 2022 15:06:37 +0800 Subject: vim-patch:8.2.3754: undesired changing of the indent of the first formatted line Problem: Undesired changing of the indent of the first formatted line. Solution: Do not indent the first formatted line. https://github.com/vim/vim/commit/ecabb511074b3f56cdd5067553c947a291d04e17 --- src/nvim/ops.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src/nvim/ops.c') diff --git a/src/nvim/ops.c b/src/nvim/ops.c index cd7ae25a20..f2859bf707 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -4421,6 +4421,7 @@ void format_lines(linenr_T line_count, int avoid_fex) int smd_save; long count; bool need_set_indent = true; // set indent of next paragraph + linenr_T first_line = curwin->w_cursor.lnum; bool force_format = false; const int old_State = State; @@ -4549,9 +4550,13 @@ void format_lines(linenr_T line_count, int avoid_fex) if (need_set_indent) { int indent = 0; // amount of indent needed - // replace indent in first line with minimal number of - // tabs and spaces, according to current options - if (curbuf->b_p_lisp) { + // Replace indent in first line of a paragraph with minimal + // number of tabs and spaces, according to current options. + // For the very first formatted line keep the current + // indent. + if (curwin->w_cursor.lnum == first_line) { + indent = get_indent(); + } else if (curbuf->b_p_lisp) { indent = get_lisp_indent(); } else { if (cindent_on()) { -- cgit