0
0
mirror of https://github.com/vim/vim.git synced 2025-07-26 11:04:33 -04:00

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.
This commit is contained in:
Bram Moolenaar 2021-12-06 19:51:01 +00:00
parent 3e55a973b5
commit ecabb51107
3 changed files with 42 additions and 8 deletions

View File

@ -172,7 +172,8 @@ func Test_indent_func_with_gq()
\ '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.',
\ '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,10 +182,10 @@ func Test_indent_func_with_gq()
1d_
call cursor(5, 1)
ka
call cursor(15, 1)
call cursor(14, 1)
kb
norm! 'agqap
norm! 'bgqap
norm! 'bgqG
let expected = [ '\documentclass{article}', '', '\begin{document}', '',
\ 'Lorem ipsum dolor sit amet, consectetur adipiscing',
\ 'elit. Fusce ut enim non libero efficitur aliquet.',
@ -201,9 +202,10 @@ func Test_indent_func_with_gq()
\ ' 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',
\ ' 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,4 +219,28 @@ func Test_indent_func_with_gq()
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

View File

@ -954,6 +954,7 @@ format_lines(
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,8 +1074,13 @@ format_lines(
{
int indent = 0; // amount of indent needed
// replace indent in first line with minimal number of
// tabs and spaces, according to current options
// 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();

View File

@ -753,6 +753,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
3754,
/**/
3753,
/**/