Patch 8.2.3754

10 views
Skip to first unread message

Bram Moolenaar

unread,
Dec 6, 2021, 2:51:54 PM12/6/21
to vim...@googlegroups.com

Patch 8.2.3754 (after 8.2.3615)
Problem: Undesired changing of the indent of the first formatted line.
Solution: Do not indent the first formatted line.
Files: src/textformat.c, src/testdir/test_indent.vim


*** ../vim-8.2.3753/src/textformat.c 2021-11-18 13:56:33.603725506 +0000
--- src/textformat.c 2021-12-06 18:05:32.723550030 +0000
***************
*** 954,959 ****
--- 954,960 ----
int smd_save;
long count;
int need_set_indent = TRUE; // set indent of next paragraph
+ linenr_T first_line = curwin->w_cursor.lnum;
int force_format = FALSE;
int old_State = State;

***************
*** 1073,1080 ****
{
int indent = 0; // amount of indent needed

! // replace indent in first line with minimal number of
! // tabs and spaces, according to current options
# ifdef FEAT_LISP
if (curbuf->b_p_lisp)
indent = get_lisp_indent();
--- 1074,1086 ----
{
int indent = 0; // amount of indent needed

! // 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
# ifdef FEAT_LISP
if (curbuf->b_p_lisp)
indent = get_lisp_indent();
*** ../vim-8.2.3753/src/testdir/test_indent.vim 2021-11-18 13:56:33.603725506 +0000
--- src/testdir/test_indent.vim 2021-12-06 19:44:53.151971593 +0000
***************
*** 172,178 ****
\ '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',
--- 172,179 ----
\ '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',
***************
*** 181,190 ****
1d_
call cursor(5, 1)
ka
! call cursor(15, 1)
kb
norm! 'agqap
! norm! 'bgqap
let expected = [ '\documentclass{article}', '', '\begin{document}', '',
\ 'Lorem ipsum dolor sit amet, consectetur adipiscing',
\ 'elit. Fusce ut enim non libero efficitur aliquet.',
--- 182,191 ----
1d_
call cursor(5, 1)
ka
! call cursor(14, 1)
kb
norm! 'agqap
! norm! 'bgqG
let expected = [ '\documentclass{article}', '', '\begin{document}', '',
\ 'Lorem ipsum dolor sit amet, consectetur adipiscing',
\ 'elit. Fusce ut enim non libero efficitur aliquet.',
***************
*** 201,209 ****
\ ' 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',
--- 202,211 ----
\ ' 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',
***************
*** 217,220 ****
--- 219,246 ----
delfunction GetTeXIndent
endfu

+ func Test_formatting_keeps_first_line_indent()
+ let lines =<< trim END
+ foo()
+ {
+ int x; // manually positioned
+ // more text that will be formatted
+ // but not reindented
+ END
+ new
+ call setline(1, lines)
+ setlocal sw=4 cindent tw=45 et
+ normal! 4Ggqj
+ let expected =<< trim END
+ foo()
+ {
+ int x; // manually positioned
+ // more text that will be
+ // formatted but not
+ // reindented
+ END
+ call assert_equal(expected, getline(1, '$'))
+ bwipe!
+ endfunc
+
" vim: shiftwidth=2 sts=2 expandtab
*** ../vim-8.2.3753/src/version.c 2021-12-06 15:06:49.335517805 +0000
--- src/version.c 2021-12-06 19:50:26.222736276 +0000
***************
*** 755,756 ****
--- 755,758 ----
{ /* Add new patch number below this line */
+ /**/
+ 3754,
/**/

--
A consultant is a person who takes your money and annoys your employees while
tirelessly searching for the best way to extend the consulting contract.
(Scott Adams - The Dilbert principle)

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

Gary Johnson

unread,
Dec 6, 2021, 7:46:46 PM12/6/21
to vim...@googlegroups.com
On 2021-12-06, Bram Moolenaar wrote:
> Patch 8.2.3754 (after 8.2.3615)
> Problem: Undesired changing of the indent of the first formatted line.
> Solution: Do not indent the first formatted line.
> Files: src/textformat.c, src/testdir/test_indent.vim

Wonderful! Works with all the testing I did with C, Vim script and
plain text. Thank you!

I hope this works for the OP. The indentation of the OP's example
is now different after gggqG, even when using vim-latex's
'indentexpr', but it looks good.

Regards,
Gary

Bram Moolenaar

unread,
Dec 7, 2021, 7:24:38 AM12/7/21
to vim...@googlegroups.com, Gary Johnson
As far as I digged into it, the start of a paragraph is indented based
on what comes before. In a "center" section it gets a bit more indent,
the rest of the paragraph too. Before the change, the first line of the
paragraph kept the indent, while following lines were indented a bit
more. Same for the second paragraph. That resulted in the strange
result where the first line of a paragraph wasn't indented.

After the last change, when starting the formatting just before the
first paragraph, all lines of the paragraphs are indented. If starting
on the first line, then that line keeps its indent. If the user wants
to have auto-indent for that line too, then it should be indented with
"==" first. If you want the behavior of after patch 8.2.3615 you could
add a mapping for "gq" to "==gq".

--
Contrary to popular belief, it's often your clothing that gets promoted, not
you.
Reply all
Reply to author
Forward
0 new messages