mirror of
https://github.com/neovim/neovim.git
synced 2025-09-27 05:28:33 +00:00
vim-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.
ecabb51107
This commit is contained in:
@@ -4421,6 +4421,7 @@ void format_lines(linenr_T line_count, int avoid_fex)
|
||||
int smd_save;
|
||||
long count;
|
||||
bool need_set_indent = true; // set indent of next paragraph
|
||||
linenr_T first_line = curwin->w_cursor.lnum;
|
||||
bool force_format = false;
|
||||
const int old_State = State;
|
||||
|
||||
@@ -4549,9 +4550,13 @@ void format_lines(linenr_T line_count, int avoid_fex)
|
||||
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
|
||||
if (curbuf->b_p_lisp) {
|
||||
// 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 if (curbuf->b_p_lisp) {
|
||||
indent = get_lisp_indent();
|
||||
} else {
|
||||
if (cindent_on()) {
|
||||
|
@@ -195,7 +195,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',
|
||||
@@ -204,10 +205,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.',
|
||||
@@ -224,9 +225,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',
|
||||
@@ -240,4 +242,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
|
||||
|
Reference in New Issue
Block a user