comparison src/change.c @ 18265:fe5afdc03bd2 v8.1.2127

patch 8.1.2127: the indent.c file is a bit big Commit: https://github.com/vim/vim/commit/14c01f83487d5c53192297a710eda2b8a4ab17c9 Author: Bram Moolenaar <Bram@vim.org> Date: Wed Oct 9 22:53:08 2019 +0200 patch 8.1.2127: the indent.c file is a bit big Problem: The indent.c file is a bit big. Solution: Move C-indent code a a new cindent.c file. Move other indent-related code to indent.c. (Yegappan Lakshmanan, closes #5031)
author Bram Moolenaar <Bram@vim.org>
date Wed, 09 Oct 2019 23:00:04 +0200
parents 6c3a8312486d
children 5da355d15b88
comparison
equal deleted inserted replaced
18264:5202d9b99bee 18265:fe5afdc03bd2
1246 1246
1247 // mark the buffer as changed and prepare for displaying 1247 // mark the buffer as changed and prepare for displaying
1248 inserted_bytes(lnum, curwin->w_cursor.col, -count); 1248 inserted_bytes(lnum, curwin->w_cursor.col, -count);
1249 1249
1250 return OK; 1250 return OK;
1251 }
1252
1253 /*
1254 * Copy the indent from ptr to the current line (and fill to size)
1255 * Leaves the cursor on the first non-blank in the line.
1256 * Returns TRUE if the line was changed.
1257 */
1258 static int
1259 copy_indent(int size, char_u *src)
1260 {
1261 char_u *p = NULL;
1262 char_u *line = NULL;
1263 char_u *s;
1264 int todo;
1265 int ind_len;
1266 int line_len = 0;
1267 int tab_pad;
1268 int ind_done;
1269 int round;
1270 #ifdef FEAT_VARTABS
1271 int ind_col;
1272 #endif
1273
1274 // Round 1: compute the number of characters needed for the indent
1275 // Round 2: copy the characters.
1276 for (round = 1; round <= 2; ++round)
1277 {
1278 todo = size;
1279 ind_len = 0;
1280 ind_done = 0;
1281 #ifdef FEAT_VARTABS
1282 ind_col = 0;
1283 #endif
1284 s = src;
1285
1286 // Count/copy the usable portion of the source line
1287 while (todo > 0 && VIM_ISWHITE(*s))
1288 {
1289 if (*s == TAB)
1290 {
1291 #ifdef FEAT_VARTABS
1292 tab_pad = tabstop_padding(ind_done, curbuf->b_p_ts,
1293 curbuf->b_p_vts_array);
1294 #else
1295 tab_pad = (int)curbuf->b_p_ts
1296 - (ind_done % (int)curbuf->b_p_ts);
1297 #endif
1298 // Stop if this tab will overshoot the target
1299 if (todo < tab_pad)
1300 break;
1301 todo -= tab_pad;
1302 ind_done += tab_pad;
1303 #ifdef FEAT_VARTABS
1304 ind_col += tab_pad;
1305 #endif
1306 }
1307 else
1308 {
1309 --todo;
1310 ++ind_done;
1311 #ifdef FEAT_VARTABS
1312 ++ind_col;
1313 #endif
1314 }
1315 ++ind_len;
1316 if (p != NULL)
1317 *p++ = *s;
1318 ++s;
1319 }
1320
1321 // Fill to next tabstop with a tab, if possible
1322 #ifdef FEAT_VARTABS
1323 tab_pad = tabstop_padding(ind_done, curbuf->b_p_ts,
1324 curbuf->b_p_vts_array);
1325 #else
1326 tab_pad = (int)curbuf->b_p_ts - (ind_done % (int)curbuf->b_p_ts);
1327 #endif
1328 if (todo >= tab_pad && !curbuf->b_p_et)
1329 {
1330 todo -= tab_pad;
1331 ++ind_len;
1332 #ifdef FEAT_VARTABS
1333 ind_col += tab_pad;
1334 #endif
1335 if (p != NULL)
1336 *p++ = TAB;
1337 }
1338
1339 // Add tabs required for indent
1340 if (!curbuf->b_p_et)
1341 {
1342 #ifdef FEAT_VARTABS
1343 for (;;)
1344 {
1345 tab_pad = tabstop_padding(ind_col, curbuf->b_p_ts,
1346 curbuf->b_p_vts_array);
1347 if (todo < tab_pad)
1348 break;
1349 todo -= tab_pad;
1350 ++ind_len;
1351 ind_col += tab_pad;
1352 if (p != NULL)
1353 *p++ = TAB;
1354 }
1355 #else
1356 while (todo >= (int)curbuf->b_p_ts)
1357 {
1358 todo -= (int)curbuf->b_p_ts;
1359 ++ind_len;
1360 if (p != NULL)
1361 *p++ = TAB;
1362 }
1363 #endif
1364 }
1365
1366 // Count/add spaces required for indent
1367 while (todo > 0)
1368 {
1369 --todo;
1370 ++ind_len;
1371 if (p != NULL)
1372 *p++ = ' ';
1373 }
1374
1375 if (p == NULL)
1376 {
1377 // Allocate memory for the result: the copied indent, new indent
1378 // and the rest of the line.
1379 line_len = (int)STRLEN(ml_get_curline()) + 1;
1380 line = alloc(ind_len + line_len);
1381 if (line == NULL)
1382 return FALSE;
1383 p = line;
1384 }
1385 }
1386
1387 // Append the original line
1388 mch_memmove(p, ml_get_curline(), (size_t)line_len);
1389
1390 // Replace the line
1391 ml_replace(curwin->w_cursor.lnum, line, FALSE);
1392
1393 // Put the cursor after the indent.
1394 curwin->w_cursor.col = ind_len;
1395 return TRUE;
1396 } 1251 }
1397 1252
1398 /* 1253 /*
1399 * open_line: Add a new line below or above the current line. 1254 * open_line: Add a new line below or above the current line.
1400 * 1255 *