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)
818ff25cd1
This commit is contained in:
zeertzjq
2022-07-05 14:58:59 +08:00
parent 6e2d23ac43
commit 42863634dd
3 changed files with 88 additions and 2 deletions

View File

@@ -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