ft=tex is recognised;gq on the various paragraphsI expect all paragraphs to be indented properly without a hanging indent, unless I configure such a hanging indent somehow.
I do not expect that the paragraphs within the \begin{center}/\end{center} keywords are indented differently. Why?
Sample file:
\documentclass{article} \usepackage[latin]{babel} \begin{document} Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce ut enim non libero efficitur aliquet. Maecenas metus justo, facilisis convallis blandit non, semper eu urna. Suspendisse diam diam, iaculis faucibus lorem eu, fringilla condimentum lectus. Quisque euismod diam at convallis vulputate. Pellentesque laoreet tortor sit amet mauris euismod ornare. Sed varius bibendum orci vel vehicula. Pellentesque tempor, ipsum et auctor accumsan, metus lectus ultrices odio, sed elementum mi ante at arcu. \begin{center} Proin nec risus consequat nunc dapibus consectetur. Mauris lacinia est a augue tristique accumsan. Morbi pretium, felis molestie eleifend condimentum, arcu ipsum congue nisl, quis euismod purus libero in ante. Donec id semper purus. Suspendisse eget aliquam nunc. Maecenas fringilla mauris vitae maximus condimentum. Cras a quam in mi dictum eleifend at a lorem. Sed convallis ante a commodo facilisis. Nam suscipit vulputate odio, vel dapibus nisl dignissim facilisis. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia curae; Vestibulum imperdiet maximus mi, id elementum odio. Aenean et odio tristique urna lacinia iaculis. Integer facilisis finibus nisl at porttitor. Aenean sollicitudin nibh sed arcu tincidunt volutpat. Vestibulum id sem ornare, auctor augue in, finibus lacus. Curabitur sed varius lorem. Fusce et consequat orci. Phasellus hendrerit, risus vitae condimentum volutpat, turpis risus tristique quam, a bibendum eros tortor id dolor. Integer diam augue, fermentum et nisi sed, facilisis mollis massa. Praesent arcu urna, maximus vulputate vehicula eu, rutrum a elit. Quisque in semper tellus. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia curae; \end{center} Cras malesuada mi nulla, non laoreet massa gravida pretium. Proin id suscipit orci. Suspendisse luctus ultrices dolor. Phasellus quis bibendum risus. Donec at ex cursus, condimentum mi non, efficitur augue. In hendrerit libero lorem, sollicitudin ornare ante imperdiet vel. Maecenas pellentesque, dolor ac maximus egestas, urna felis finibus velit, at blandit magna turpis non dui. \end{documnt}
Debian unstable
8.2.2434
No response
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub.
Triage notifications on the go with GitHub Mobile for iOS or Android.
![]()
I think this is not an indenting issue. This is about gq to format the paragraph. So Vim uses formatexpr/formatprg or falls back to internal formatting. So I think this is not about a runtime issue.
I think this is not an indenting issue. This is about
gqto format the paragraph. So Vim uses formatexpr/formatprg or falls back to internal formatting. So I think this is not about a runtime issue.
Neither formatprg nor formatexpr are set. In that case, "formatting is done internally". If I set ft=plaintex, then gq works fine, and it also doesn't do this funky indenting anywhere else, so I do think this is specific to ft=tex.
Neither formatprg nor formatexpr are set. In that case, "formatting is done internally". If I set ft=plaintex, then gq works fine, and it also doesn't do this funky indenting anywhere else, so I do think this is specific to ft=tex.
What I was trying to say is: It's not the indent script to blame here, since we are using gq to format and therefore the ping to the indentscript author is not helping. BTW: I see the same issue with ft=plaintex and vim --clean. And the filetype plugins for tex and plaintex do not show anything obvious that might cause this. So I think it's the internal formatting of Vim that is causing this for some reason.
Oh, I stand corrected. When Vim is formatting the lines, it will make use of the indentexpr. So it calls GetTexIndent() which will eventually call GetLastBeginIndentation() which will then return an additional indentation level of +1. So this is an issue of the indent script for tex, therefore pinging @zhou13 is correct and this needs to be fixed in the indent script. Sorry for the confusion.
So a workaround is to set :set indentexpr= before doing gq
This is strange to me. If I run gg=G on this file, everything is indented properly. If I place my cursor on the first line of the paragraph and press ==, it also indents properly. I am not sure things do not work out with gq. Maybe gq does not run the indentexpr for the first line?
yes, I have run it through a debugger. Vim joins the lines together and adds a linebreak and then uses the indentexpression for the line after the newly inserted line break. so not running the indentexpression through the first line of the paragraph.
Okay, so how about the following patch:
diff --git a/src/textformat.c b/src/textformat.c index 9b96b7fdb..c0bbaac5b 100644 --- a/src/textformat.c +++ b/src/textformat.c @@ -956,6 +956,7 @@ format_lines( int need_set_indent = TRUE; // set indent of next paragraph int force_format = FALSE; int old_State = State; + int indent = 0; // do indent // length of a line to force formatting: 3 * 'tw' max_len = comp_textwidth(TRUE) * 3; @@ -1070,9 +1071,23 @@ format_lines( if (is_end_par || force_format) { if (need_set_indent) + { // 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 + indent = +#ifdef FEAT_EVAL + *curbuf->b_p_inde != NUL ? get_expr_indent() : +#endif + get_c_indent(); + set_indent(indent, SIN_CHANGED); +#endif + } // put cursor on last non-space State = NORMAL; // don't go past end-of-line
This should make sure to use proper indentation for the first line.
I'll prepare a PR for this with a test
Before using b_p_inde and calling get_c_indent() it should check that cindent_on() returns TRUE.
If not, then it should call get_indent() as before.
Compare with the fix_indent() function.
thanks, I have adjusted the logic and created PR #9150