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 #9150, closes #9056)
diff --git a/src/textformat.c b/src/textformat.c
index 9b96b7f..246f06f 100644
--- a/src/textformat.c
+++ b/src/textformat.c
@@ -1070,9 +1070,32 @@
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);
+# ifdef FEAT_LISP
+ if (curbuf->b_p_lisp)
+ indent = get_lisp_indent();
+ else
+# endif
+ {
+#ifdef FEAT_CINDENT
+ if (cindent_on())
+ {
+ indent =
+# ifdef FEAT_EVAL
+ *curbuf->b_p_inde != NUL ? get_expr_indent() :
+# endif
+ get_c_indent();
+ }
+ else
+#endif
+ indent = get_indent();
+ }
+ (void)set_indent(indent, SIN_CHANGED);
+ }
// put cursor on last non-space
State = NORMAL; // don't go past end-of-line