Mirror of the Vim source from https://github.com/vim/vim
修订版 | 748793fcb4e25165036bd1f4081e8fe9594d4da4 (tree) |
---|---|
时间 | 2021-12-07 05:00:05 |
作者 | Bram Moolenaar <Bram@vim....> |
Commiter | Bram Moolenaar |
patch 8.2.3754: undesired changing of the indent of the first formatted line
Commit: https://github.com/vim/vim/commit/ecabb511074b3f56cdd5067553c947a291d04e17
Author: Bram Moolenaar <Bram@vim.org>
Date: Mon Dec 6 19:51:01 2021 +0000
@@ -172,7 +172,8 @@ | ||
172 | 172 | \ 'metus lectus ultrices odio, sed elementum mi ante at arcu.', '', '\begin{center}', '', |
173 | 173 | \ 'Proin nec risus consequat nunc dapibus consectetur. Mauris lacinia est a augue', |
174 | 174 | \ 'tristique accumsan. Morbi pretium, felis molestie eleifend condimentum, arcu', |
175 | - \ 'ipsum congue nisl, quis euismod purus libero in ante. Donec id semper purus.', | |
175 | + \ 'ipsum congue nisl, quis euismod purus libero in ante.', '', | |
176 | + \ 'Donec id semper purus.', | |
176 | 177 | \ 'Suspendisse eget aliquam nunc. Maecenas fringilla mauris vitae maximus', |
177 | 178 | \ 'condimentum. Cras a quam in mi dictum eleifend at a lorem. Sed convallis', |
178 | 179 | \ 'ante a commodo facilisis. Nam suscipit vulputate odio, vel dapibus nisl', |
@@ -181,10 +182,10 @@ | ||
181 | 182 | 1d_ |
182 | 183 | call cursor(5, 1) |
183 | 184 | ka |
184 | - call cursor(15, 1) | |
185 | + call cursor(14, 1) | |
185 | 186 | kb |
186 | 187 | norm! 'agqap |
187 | - norm! 'bgqap | |
188 | + norm! 'bgqG | |
188 | 189 | let expected = [ '\documentclass{article}', '', '\begin{document}', '', |
189 | 190 | \ 'Lorem ipsum dolor sit amet, consectetur adipiscing', |
190 | 191 | \ 'elit. Fusce ut enim non libero efficitur aliquet.', |
@@ -201,9 +202,10 @@ | ||
201 | 202 | \ ' consectetur. Mauris lacinia est a augue', |
202 | 203 | \ ' tristique accumsan. Morbi pretium, felis', |
203 | 204 | \ ' molestie eleifend condimentum, arcu ipsum congue', |
204 | - \ ' nisl, quis euismod purus libero in ante. Donec', | |
205 | - \ ' id semper purus. Suspendisse eget aliquam nunc.', | |
206 | - \ ' Maecenas fringilla mauris vitae maximus', | |
205 | + \ ' nisl, quis euismod purus libero in ante.', | |
206 | + \ '', | |
207 | + \ ' Donec id semper purus. Suspendisse eget aliquam', | |
208 | + \ ' nunc. Maecenas fringilla mauris vitae maximus', | |
207 | 209 | \ ' condimentum. Cras a quam in mi dictum eleifend', |
208 | 210 | \ ' at a lorem. Sed convallis ante a commodo', |
209 | 211 | \ ' facilisis. Nam suscipit vulputate odio, vel', |
@@ -217,4 +219,28 @@ | ||
217 | 219 | delfunction GetTeXIndent |
218 | 220 | endfu |
219 | 221 | |
222 | +func Test_formatting_keeps_first_line_indent() | |
223 | + let lines =<< trim END | |
224 | + foo() | |
225 | + { | |
226 | + int x; // manually positioned | |
227 | + // more text that will be formatted | |
228 | + // but not reindented | |
229 | + END | |
230 | + new | |
231 | + call setline(1, lines) | |
232 | + setlocal sw=4 cindent tw=45 et | |
233 | + normal! 4Ggqj | |
234 | + let expected =<< trim END | |
235 | + foo() | |
236 | + { | |
237 | + int x; // manually positioned | |
238 | + // more text that will be | |
239 | + // formatted but not | |
240 | + // reindented | |
241 | + END | |
242 | + call assert_equal(expected, getline(1, '$')) | |
243 | + bwipe! | |
244 | +endfunc | |
245 | + | |
220 | 246 | " vim: shiftwidth=2 sts=2 expandtab |
@@ -954,6 +954,7 @@ | ||
954 | 954 | int smd_save; |
955 | 955 | long count; |
956 | 956 | int need_set_indent = TRUE; // set indent of next paragraph |
957 | + linenr_T first_line = curwin->w_cursor.lnum; | |
957 | 958 | int force_format = FALSE; |
958 | 959 | int old_State = State; |
959 | 960 |
@@ -1073,8 +1074,13 @@ | ||
1073 | 1074 | { |
1074 | 1075 | int indent = 0; // amount of indent needed |
1075 | 1076 | |
1076 | - // replace indent in first line with minimal number of | |
1077 | - // tabs and spaces, according to current options | |
1077 | + // Replace indent in first line of a paragraph with minimal | |
1078 | + // number of tabs and spaces, according to current options. | |
1079 | + // For the very first formatted line keep the current | |
1080 | + // indent. | |
1081 | + if (curwin->w_cursor.lnum == first_line) | |
1082 | + indent = get_indent(); | |
1083 | + else | |
1078 | 1084 | # ifdef FEAT_LISP |
1079 | 1085 | if (curbuf->b_p_lisp) |
1080 | 1086 | indent = get_lisp_indent(); |
@@ -754,6 +754,8 @@ | ||
754 | 754 | static int included_patches[] = |
755 | 755 | { /* Add new patch number below this line */ |
756 | 756 | /**/ |
757 | + 3754, | |
758 | +/**/ | |
757 | 759 | 3753, |
758 | 760 | /**/ |
759 | 761 | 3752, |