Mercurial > vim
comparison src/ops.c @ 18808:7982f65d8f54 v8.1.2392
patch 8.1.2392: using old C style comments
Commit: https://github.com/vim/vim/commit/6e0ce171e19d0118ecd7c2b16e2a1bd50aa76013
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Dec 5 20:12:41 2019 +0100
patch 8.1.2392: using old C style comments
Problem: Using old C style comments.
Solution: Use // comments where appropriate.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 05 Dec 2019 20:15:04 +0100 |
parents | 49b78d6465e5 |
children | f9e41ffd3539 |
comparison
equal
deleted
inserted
replaced
18807:7e28c71af59a | 18808:7982f65d8f54 |
---|---|
70 int | 70 int |
71 get_op_type(int char1, int char2) | 71 get_op_type(int char1, int char2) |
72 { | 72 { |
73 int i; | 73 int i; |
74 | 74 |
75 if (char1 == 'r') /* ignore second character */ | 75 if (char1 == 'r') // ignore second character |
76 return OP_REPLACE; | 76 return OP_REPLACE; |
77 if (char1 == '~') /* when tilde is an operator */ | 77 if (char1 == '~') // when tilde is an operator |
78 return OP_TILDE; | 78 return OP_TILDE; |
79 if (char1 == 'g' && char2 == Ctrl_A) /* add */ | 79 if (char1 == 'g' && char2 == Ctrl_A) // add |
80 return OP_NR_ADD; | 80 return OP_NR_ADD; |
81 if (char1 == 'g' && char2 == Ctrl_X) /* subtract */ | 81 if (char1 == 'g' && char2 == Ctrl_X) // subtract |
82 return OP_NR_SUB; | 82 return OP_NR_SUB; |
83 for (i = 0; ; ++i) | 83 for (i = 0; ; ++i) |
84 { | 84 { |
85 if (opchars[i][0] == char1 && opchars[i][1] == char2) | 85 if (opchars[i][0] == char1 && opchars[i][1] == char2) |
86 break; | 86 break; |
150 block_col = curwin->w_cursor.col; | 150 block_col = curwin->w_cursor.col; |
151 | 151 |
152 for (i = oap->line_count; --i >= 0; ) | 152 for (i = oap->line_count; --i >= 0; ) |
153 { | 153 { |
154 first_char = *ml_get_curline(); | 154 first_char = *ml_get_curline(); |
155 if (first_char == NUL) /* empty line */ | 155 if (first_char == NUL) // empty line |
156 curwin->w_cursor.col = 0; | 156 curwin->w_cursor.col = 0; |
157 else if (oap->block_mode) | 157 else if (oap->block_mode) |
158 shift_block(oap, amount); | 158 shift_block(oap, amount); |
159 else | 159 else |
160 /* Move the line right if it doesn't start with '#', 'smartindent' | 160 // Move the line right if it doesn't start with '#', 'smartindent' |
161 * isn't set or 'cindent' isn't set or '#' isn't in 'cino'. */ | 161 // isn't set or 'cindent' isn't set or '#' isn't in 'cino'. |
162 #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT) | 162 #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT) |
163 if (first_char != '#' || !preprocs_left()) | 163 if (first_char != '#' || !preprocs_left()) |
164 #endif | 164 #endif |
165 shift_line(oap->op_type == OP_LSHIFT, p_sr, amount, FALSE); | 165 shift_line(oap->op_type == OP_LSHIFT, p_sr, amount, FALSE); |
166 ++curwin->w_cursor.lnum; | 166 ++curwin->w_cursor.lnum; |
170 if (oap->block_mode) | 170 if (oap->block_mode) |
171 { | 171 { |
172 curwin->w_cursor.lnum = oap->start.lnum; | 172 curwin->w_cursor.lnum = oap->start.lnum; |
173 curwin->w_cursor.col = block_col; | 173 curwin->w_cursor.col = block_col; |
174 } | 174 } |
175 else if (curs_top) /* put cursor on first line, for ">>" */ | 175 else if (curs_top) // put cursor on first line, for ">>" |
176 { | 176 { |
177 curwin->w_cursor.lnum = oap->start.lnum; | 177 curwin->w_cursor.lnum = oap->start.lnum; |
178 beginline(BL_SOL | BL_FIX); /* shift_line() may have set cursor.col */ | 178 beginline(BL_SOL | BL_FIX); // shift_line() may have set cursor.col |
179 } | 179 } |
180 else | 180 else |
181 --curwin->w_cursor.lnum; /* put cursor on last line, for ":>" */ | 181 --curwin->w_cursor.lnum; // put cursor on last line, for ":>" |
182 | 182 |
183 #ifdef FEAT_FOLDING | 183 #ifdef FEAT_FOLDING |
184 /* The cursor line is not in a closed fold */ | 184 // The cursor line is not in a closed fold |
185 foldOpenCursor(); | 185 foldOpenCursor(); |
186 #endif | 186 #endif |
187 | 187 |
188 | 188 |
189 if (oap->line_count > p_report) | 189 if (oap->line_count > p_report) |
289 int i = 0, j = 0; | 289 int i = 0, j = 0; |
290 int len; | 290 int len; |
291 #ifdef FEAT_RIGHTLEFT | 291 #ifdef FEAT_RIGHTLEFT |
292 int old_p_ri = p_ri; | 292 int old_p_ri = p_ri; |
293 | 293 |
294 p_ri = 0; /* don't want revins in indent */ | 294 p_ri = 0; // don't want revins in indent |
295 #endif | 295 #endif |
296 | 296 |
297 State = INSERT; /* don't want REPLACE for State */ | 297 State = INSERT; // don't want REPLACE for State |
298 block_prep(oap, &bd, curwin->w_cursor.lnum, TRUE); | 298 block_prep(oap, &bd, curwin->w_cursor.lnum, TRUE); |
299 if (bd.is_short) | 299 if (bd.is_short) |
300 return; | 300 return; |
301 | 301 |
302 /* total is number of screen columns to be inserted/removed */ | 302 // total is number of screen columns to be inserted/removed |
303 total = (int)((unsigned)amount * (unsigned)sw_val); | 303 total = (int)((unsigned)amount * (unsigned)sw_val); |
304 if ((total / sw_val) != amount) | 304 if ((total / sw_val) != amount) |
305 return; /* multiplication overflow */ | 305 return; // multiplication overflow |
306 | 306 |
307 oldp = ml_get_curline(); | 307 oldp = ml_get_curline(); |
308 | 308 |
309 if (!left) | 309 if (!left) |
310 { | 310 { |
312 * 1. Get start vcol | 312 * 1. Get start vcol |
313 * 2. Total ws vcols | 313 * 2. Total ws vcols |
314 * 3. Divvy into TABs & spp | 314 * 3. Divvy into TABs & spp |
315 * 4. Construct new string | 315 * 4. Construct new string |
316 */ | 316 */ |
317 total += bd.pre_whitesp; /* all virtual WS upto & incl a split TAB */ | 317 total += bd.pre_whitesp; // all virtual WS upto & incl a split TAB |
318 ws_vcol = bd.start_vcol - bd.pre_whitesp; | 318 ws_vcol = bd.start_vcol - bd.pre_whitesp; |
319 if (bd.startspaces) | 319 if (bd.startspaces) |
320 { | 320 { |
321 if (has_mbyte) | 321 if (has_mbyte) |
322 { | 322 { |
331 else | 331 else |
332 ++bd.textstart; | 332 ++bd.textstart; |
333 } | 333 } |
334 for ( ; VIM_ISWHITE(*bd.textstart); ) | 334 for ( ; VIM_ISWHITE(*bd.textstart); ) |
335 { | 335 { |
336 /* TODO: is passing bd.textstart for start of the line OK? */ | 336 // TODO: is passing bd.textstart for start of the line OK? |
337 incr = lbr_chartabsize_adv(bd.textstart, &bd.textstart, | 337 incr = lbr_chartabsize_adv(bd.textstart, &bd.textstart, |
338 (colnr_T)(bd.start_vcol)); | 338 (colnr_T)(bd.start_vcol)); |
339 total += incr; | 339 total += incr; |
340 bd.start_vcol += incr; | 340 bd.start_vcol += incr; |
341 } | 341 } |
342 /* OK, now total=all the VWS reqd, and textstart points at the 1st | 342 // OK, now total=all the VWS reqd, and textstart points at the 1st |
343 * non-ws char in the block. */ | 343 // non-ws char in the block. |
344 #ifdef FEAT_VARTABS | 344 #ifdef FEAT_VARTABS |
345 if (!curbuf->b_p_et) | 345 if (!curbuf->b_p_et) |
346 tabstop_fromto(ws_vcol, ws_vcol + total, | 346 tabstop_fromto(ws_vcol, ws_vcol + total, |
347 ts_val, curbuf->b_p_vts_array, &i, &j); | 347 ts_val, curbuf->b_p_vts_array, &i, &j); |
348 else | 348 else |
349 j = total; | 349 j = total; |
350 #else | 350 #else |
351 if (!curbuf->b_p_et) | 351 if (!curbuf->b_p_et) |
352 i = ((ws_vcol % ts_val) + total) / ts_val; /* number of tabs */ | 352 i = ((ws_vcol % ts_val) + total) / ts_val; // number of tabs |
353 if (i) | 353 if (i) |
354 j = ((ws_vcol % ts_val) + total) % ts_val; /* number of spp */ | 354 j = ((ws_vcol % ts_val) + total) % ts_val; // number of spp |
355 else | 355 else |
356 j = total; | 356 j = total; |
357 #endif | 357 #endif |
358 /* if we're splitting a TAB, allow for it */ | 358 // if we're splitting a TAB, allow for it |
359 bd.textcol -= bd.pre_whitesp_c - (bd.startspaces != 0); | 359 bd.textcol -= bd.pre_whitesp_c - (bd.startspaces != 0); |
360 len = (int)STRLEN(bd.textstart) + 1; | 360 len = (int)STRLEN(bd.textstart) + 1; |
361 newp = alloc(bd.textcol + i + j + len); | 361 newp = alloc(bd.textcol + i + j + len); |
362 if (newp == NULL) | 362 if (newp == NULL) |
363 return; | 363 return; |
364 vim_memset(newp, NUL, (size_t)(bd.textcol + i + j + len)); | 364 vim_memset(newp, NUL, (size_t)(bd.textcol + i + j + len)); |
365 mch_memmove(newp, oldp, (size_t)bd.textcol); | 365 mch_memmove(newp, oldp, (size_t)bd.textcol); |
366 vim_memset(newp + bd.textcol, TAB, (size_t)i); | 366 vim_memset(newp + bd.textcol, TAB, (size_t)i); |
367 vim_memset(newp + bd.textcol + i, ' ', (size_t)j); | 367 vim_memset(newp + bd.textcol + i, ' ', (size_t)j); |
368 /* the end */ | 368 // the end |
369 mch_memmove(newp + bd.textcol + i + j, bd.textstart, (size_t)len); | 369 mch_memmove(newp + bd.textcol + i + j, bd.textstart, (size_t)len); |
370 } | 370 } |
371 else /* left */ | 371 else // left |
372 { | 372 { |
373 colnr_T destination_col; /* column to which text in block will | 373 colnr_T destination_col; // column to which text in block will |
374 be shifted */ | 374 // be shifted |
375 char_u *verbatim_copy_end; /* end of the part of the line which is | 375 char_u *verbatim_copy_end; // end of the part of the line which is |
376 copied verbatim */ | 376 // copied verbatim |
377 colnr_T verbatim_copy_width;/* the (displayed) width of this part | 377 colnr_T verbatim_copy_width;// the (displayed) width of this part |
378 of line */ | 378 // of line |
379 unsigned fill; /* nr of spaces that replace a TAB */ | 379 unsigned fill; // nr of spaces that replace a TAB |
380 unsigned new_line_len; /* the length of the line after the | 380 unsigned new_line_len; // the length of the line after the |
381 block shift */ | 381 // block shift |
382 size_t block_space_width; | 382 size_t block_space_width; |
383 size_t shift_amount; | 383 size_t shift_amount; |
384 char_u *non_white = bd.textstart; | 384 char_u *non_white = bd.textstart; |
385 colnr_T non_white_col; | 385 colnr_T non_white_col; |
386 | 386 |
390 * number. Also, let's calculate the width of all the whitespace | 390 * number. Also, let's calculate the width of all the whitespace |
391 * characters that are displayed in the block and precede the searched | 391 * characters that are displayed in the block and precede the searched |
392 * non-whitespace character. | 392 * non-whitespace character. |
393 */ | 393 */ |
394 | 394 |
395 /* If "bd.startspaces" is set, "bd.textstart" points to the character, | 395 // If "bd.startspaces" is set, "bd.textstart" points to the character, |
396 * the part of which is displayed at the block's beginning. Let's start | 396 // the part of which is displayed at the block's beginning. Let's start |
397 * searching from the next character. */ | 397 // searching from the next character. |
398 if (bd.startspaces) | 398 if (bd.startspaces) |
399 MB_PTR_ADV(non_white); | 399 MB_PTR_ADV(non_white); |
400 | 400 |
401 /* The character's column is in "bd.start_vcol". */ | 401 // The character's column is in "bd.start_vcol". |
402 non_white_col = bd.start_vcol; | 402 non_white_col = bd.start_vcol; |
403 | 403 |
404 while (VIM_ISWHITE(*non_white)) | 404 while (VIM_ISWHITE(*non_white)) |
405 { | 405 { |
406 incr = lbr_chartabsize_adv(bd.textstart, &non_white, non_white_col); | 406 incr = lbr_chartabsize_adv(bd.textstart, &non_white, non_white_col); |
407 non_white_col += incr; | 407 non_white_col += incr; |
408 } | 408 } |
409 | 409 |
410 block_space_width = non_white_col - oap->start_vcol; | 410 block_space_width = non_white_col - oap->start_vcol; |
411 /* We will shift by "total" or "block_space_width", whichever is less. | 411 // We will shift by "total" or "block_space_width", whichever is less. |
412 */ | |
413 shift_amount = (block_space_width < (size_t)total | 412 shift_amount = (block_space_width < (size_t)total |
414 ? block_space_width : (size_t)total); | 413 ? block_space_width : (size_t)total); |
415 | 414 |
416 /* The column to which we will shift the text. */ | 415 // The column to which we will shift the text. |
417 destination_col = (colnr_T)(non_white_col - shift_amount); | 416 destination_col = (colnr_T)(non_white_col - shift_amount); |
418 | 417 |
419 /* Now let's find out how much of the beginning of the line we can | 418 // Now let's find out how much of the beginning of the line we can |
420 * reuse without modification. */ | 419 // reuse without modification. |
421 verbatim_copy_end = bd.textstart; | 420 verbatim_copy_end = bd.textstart; |
422 verbatim_copy_width = bd.start_vcol; | 421 verbatim_copy_width = bd.start_vcol; |
423 | 422 |
424 /* If "bd.startspaces" is set, "bd.textstart" points to the character | 423 // If "bd.startspaces" is set, "bd.textstart" points to the character |
425 * preceding the block. We have to subtract its width to obtain its | 424 // preceding the block. We have to subtract its width to obtain its |
426 * column number. */ | 425 // column number. |
427 if (bd.startspaces) | 426 if (bd.startspaces) |
428 verbatim_copy_width -= bd.start_char_vcols; | 427 verbatim_copy_width -= bd.start_char_vcols; |
429 while (verbatim_copy_width < destination_col) | 428 while (verbatim_copy_width < destination_col) |
430 { | 429 { |
431 char_u *line = verbatim_copy_end; | 430 char_u *line = verbatim_copy_end; |
432 | 431 |
433 /* TODO: is passing verbatim_copy_end for start of the line OK? */ | 432 // TODO: is passing verbatim_copy_end for start of the line OK? |
434 incr = lbr_chartabsize(line, verbatim_copy_end, | 433 incr = lbr_chartabsize(line, verbatim_copy_end, |
435 verbatim_copy_width); | 434 verbatim_copy_width); |
436 if (verbatim_copy_width + incr > destination_col) | 435 if (verbatim_copy_width + incr > destination_col) |
437 break; | 436 break; |
438 verbatim_copy_width += incr; | 437 verbatim_copy_width += incr; |
439 MB_PTR_ADV(verbatim_copy_end); | 438 MB_PTR_ADV(verbatim_copy_end); |
440 } | 439 } |
441 | 440 |
442 /* If "destination_col" is different from the width of the initial | 441 // If "destination_col" is different from the width of the initial |
443 * part of the line that will be copied, it means we encountered a tab | 442 // part of the line that will be copied, it means we encountered a tab |
444 * character, which we will have to partly replace with spaces. */ | 443 // character, which we will have to partly replace with spaces. |
445 fill = destination_col - verbatim_copy_width; | 444 fill = destination_col - verbatim_copy_width; |
446 | 445 |
447 /* The replacement line will consist of: | 446 // The replacement line will consist of: |
448 * - the beginning of the original line up to "verbatim_copy_end", | 447 // - the beginning of the original line up to "verbatim_copy_end", |
449 * - "fill" number of spaces, | 448 // - "fill" number of spaces, |
450 * - the rest of the line, pointed to by non_white. */ | 449 // - the rest of the line, pointed to by non_white. |
451 new_line_len = (unsigned)(verbatim_copy_end - oldp) | 450 new_line_len = (unsigned)(verbatim_copy_end - oldp) |
452 + fill | 451 + fill |
453 + (unsigned)STRLEN(non_white) + 1; | 452 + (unsigned)STRLEN(non_white) + 1; |
454 | 453 |
455 newp = alloc(new_line_len); | 454 newp = alloc(new_line_len); |
457 return; | 456 return; |
458 mch_memmove(newp, oldp, (size_t)(verbatim_copy_end - oldp)); | 457 mch_memmove(newp, oldp, (size_t)(verbatim_copy_end - oldp)); |
459 vim_memset(newp + (verbatim_copy_end - oldp), ' ', (size_t)fill); | 458 vim_memset(newp + (verbatim_copy_end - oldp), ' ', (size_t)fill); |
460 STRMOVE(newp + (verbatim_copy_end - oldp) + fill, non_white); | 459 STRMOVE(newp + (verbatim_copy_end - oldp) + fill, non_white); |
461 } | 460 } |
462 /* replace the line */ | 461 // replace the line |
463 ml_replace(curwin->w_cursor.lnum, newp, FALSE); | 462 ml_replace(curwin->w_cursor.lnum, newp, FALSE); |
464 changed_bytes(curwin->w_cursor.lnum, (colnr_T)bd.textcol); | 463 changed_bytes(curwin->w_cursor.lnum, (colnr_T)bd.textcol); |
465 State = oldstate; | 464 State = oldstate; |
466 curwin->w_cursor.col = oldcol; | 465 curwin->w_cursor.col = oldcol; |
467 #ifdef FEAT_RIGHTLEFT | 466 #ifdef FEAT_RIGHTLEFT |
479 char_u *s, | 478 char_u *s, |
480 int b_insert, | 479 int b_insert, |
481 struct block_def *bdp) | 480 struct block_def *bdp) |
482 { | 481 { |
483 int ts_val; | 482 int ts_val; |
484 int count = 0; /* extra spaces to replace a cut TAB */ | 483 int count = 0; // extra spaces to replace a cut TAB |
485 int spaces = 0; /* non-zero if cutting a TAB */ | 484 int spaces = 0; // non-zero if cutting a TAB |
486 colnr_T offset; /* pointer along new line */ | 485 colnr_T offset; // pointer along new line |
487 unsigned s_len; /* STRLEN(s) */ | 486 unsigned s_len; // STRLEN(s) |
488 char_u *newp, *oldp; /* new, old lines */ | 487 char_u *newp, *oldp; // new, old lines |
489 linenr_T lnum; /* loop var */ | 488 linenr_T lnum; // loop var |
490 int oldstate = State; | 489 int oldstate = State; |
491 | 490 |
492 State = INSERT; /* don't want REPLACE for State */ | 491 State = INSERT; // don't want REPLACE for State |
493 s_len = (unsigned)STRLEN(s); | 492 s_len = (unsigned)STRLEN(s); |
494 | 493 |
495 for (lnum = oap->start.lnum + 1; lnum <= oap->end.lnum; lnum++) | 494 for (lnum = oap->start.lnum + 1; lnum <= oap->end.lnum; lnum++) |
496 { | 495 { |
497 block_prep(oap, bdp, lnum, TRUE); | 496 block_prep(oap, bdp, lnum, TRUE); |
498 if (bdp->is_short && b_insert) | 497 if (bdp->is_short && b_insert) |
499 continue; /* OP_INSERT, line ends before block start */ | 498 continue; // OP_INSERT, line ends before block start |
500 | 499 |
501 oldp = ml_get(lnum); | 500 oldp = ml_get(lnum); |
502 | 501 |
503 if (b_insert) | 502 if (b_insert) |
504 { | 503 { |
505 ts_val = bdp->start_char_vcols; | 504 ts_val = bdp->start_char_vcols; |
506 spaces = bdp->startspaces; | 505 spaces = bdp->startspaces; |
507 if (spaces != 0) | 506 if (spaces != 0) |
508 count = ts_val - 1; /* we're cutting a TAB */ | 507 count = ts_val - 1; // we're cutting a TAB |
509 offset = bdp->textcol; | 508 offset = bdp->textcol; |
510 } | 509 } |
511 else /* append */ | 510 else // append |
512 { | 511 { |
513 ts_val = bdp->end_char_vcols; | 512 ts_val = bdp->end_char_vcols; |
514 if (!bdp->is_short) /* spaces = padding after block */ | 513 if (!bdp->is_short) // spaces = padding after block |
515 { | 514 { |
516 spaces = (bdp->endspaces ? ts_val - bdp->endspaces : 0); | 515 spaces = (bdp->endspaces ? ts_val - bdp->endspaces : 0); |
517 if (spaces != 0) | 516 if (spaces != 0) |
518 count = ts_val - 1; /* we're cutting a TAB */ | 517 count = ts_val - 1; // we're cutting a TAB |
519 offset = bdp->textcol + bdp->textlen - (spaces != 0); | 518 offset = bdp->textcol + bdp->textlen - (spaces != 0); |
520 } | 519 } |
521 else /* spaces = padding to block edge */ | 520 else // spaces = padding to block edge |
522 { | 521 { |
523 /* if $ used, just append to EOL (ie spaces==0) */ | 522 // if $ used, just append to EOL (ie spaces==0) |
524 if (!bdp->is_MAX) | 523 if (!bdp->is_MAX) |
525 spaces = (oap->end_vcol - bdp->end_vcol) + 1; | 524 spaces = (oap->end_vcol - bdp->end_vcol) + 1; |
526 count = spaces; | 525 count = spaces; |
527 offset = bdp->textcol + bdp->textlen; | 526 offset = bdp->textcol + bdp->textlen; |
528 } | 527 } |
530 | 529 |
531 if (has_mbyte && spaces > 0) | 530 if (has_mbyte && spaces > 0) |
532 { | 531 { |
533 int off; | 532 int off; |
534 | 533 |
535 /* Avoid starting halfway a multi-byte character. */ | 534 // Avoid starting halfway a multi-byte character. |
536 if (b_insert) | 535 if (b_insert) |
537 { | 536 { |
538 off = (*mb_head_off)(oldp, oldp + offset + spaces); | 537 off = (*mb_head_off)(oldp, oldp + offset + spaces); |
539 } | 538 } |
540 else | 539 else |
548 | 547 |
549 newp = alloc(STRLEN(oldp) + s_len + count + 1); | 548 newp = alloc(STRLEN(oldp) + s_len + count + 1); |
550 if (newp == NULL) | 549 if (newp == NULL) |
551 continue; | 550 continue; |
552 | 551 |
553 /* copy up to shifted part */ | 552 // copy up to shifted part |
554 mch_memmove(newp, oldp, (size_t)(offset)); | 553 mch_memmove(newp, oldp, (size_t)(offset)); |
555 oldp += offset; | 554 oldp += offset; |
556 | 555 |
557 /* insert pre-padding */ | 556 // insert pre-padding |
558 vim_memset(newp + offset, ' ', (size_t)spaces); | 557 vim_memset(newp + offset, ' ', (size_t)spaces); |
559 | 558 |
560 /* copy the new text */ | 559 // copy the new text |
561 mch_memmove(newp + offset + spaces, s, (size_t)s_len); | 560 mch_memmove(newp + offset + spaces, s, (size_t)s_len); |
562 offset += s_len; | 561 offset += s_len; |
563 | 562 |
564 if (spaces && !bdp->is_short) | 563 if (spaces && !bdp->is_short) |
565 { | 564 { |
566 /* insert post-padding */ | 565 // insert post-padding |
567 vim_memset(newp + offset + spaces, ' ', (size_t)(ts_val - spaces)); | 566 vim_memset(newp + offset + spaces, ' ', (size_t)(ts_val - spaces)); |
568 /* We're splitting a TAB, don't copy it. */ | 567 // We're splitting a TAB, don't copy it. |
569 oldp++; | 568 oldp++; |
570 /* We allowed for that TAB, remember this now */ | 569 // We allowed for that TAB, remember this now |
571 count++; | 570 count++; |
572 } | 571 } |
573 | 572 |
574 if (spaces > 0) | 573 if (spaces > 0) |
575 offset += count; | 574 offset += count; |
577 | 576 |
578 ml_replace(lnum, newp, FALSE); | 577 ml_replace(lnum, newp, FALSE); |
579 | 578 |
580 if (lnum == oap->end.lnum) | 579 if (lnum == oap->end.lnum) |
581 { | 580 { |
582 /* Set "']" mark to the end of the block instead of the end of | 581 // Set "']" mark to the end of the block instead of the end of |
583 * the insert in the first line. */ | 582 // the insert in the first line. |
584 curbuf->b_op_end.lnum = oap->end.lnum; | 583 curbuf->b_op_end.lnum = oap->end.lnum; |
585 curbuf->b_op_end.col = offset; | 584 curbuf->b_op_end.col = offset; |
586 } | 585 } |
587 } /* for all lnum */ | 586 } // for all lnum |
588 | 587 |
589 changed_lines(oap->start.lnum + 1, 0, oap->end.lnum + 1, 0L); | 588 changed_lines(oap->start.lnum + 1, 0, oap->end.lnum + 1, 0L); |
590 | 589 |
591 State = oldstate; | 590 State = oldstate; |
592 } | 591 } |
601 int c; | 600 int c; |
602 char_u *start; | 601 char_u *start; |
603 | 602 |
604 while (*arg != NUL) | 603 while (*arg != NUL) |
605 { | 604 { |
606 /* Stuff a sequence of normal ASCII characters, that's fast. Also | 605 // Stuff a sequence of normal ASCII characters, that's fast. Also |
607 * stuff K_SPECIAL to get the effect of a special key when "literally" | 606 // stuff K_SPECIAL to get the effect of a special key when "literally" |
608 * is TRUE. */ | 607 // is TRUE. |
609 start = arg; | 608 start = arg; |
610 while ((*arg >= ' ' | 609 while ((*arg >= ' ' |
611 #ifndef EBCDIC | 610 #ifndef EBCDIC |
612 && *arg < DEL /* EBCDIC: chars above space are normal */ | 611 && *arg < DEL // EBCDIC: chars above space are normal |
613 #endif | 612 #endif |
614 ) | 613 ) |
615 || (*arg == K_SPECIAL && !literally)) | 614 || (*arg == K_SPECIAL && !literally)) |
616 ++arg; | 615 ++arg; |
617 if (arg > start) | 616 if (arg > start) |
618 stuffReadbuffLen(start, (long)(arg - start)); | 617 stuffReadbuffLen(start, (long)(arg - start)); |
619 | 618 |
620 /* stuff a single special character */ | 619 // stuff a single special character |
621 if (*arg != NUL) | 620 if (*arg != NUL) |
622 { | 621 { |
623 if (has_mbyte) | 622 if (has_mbyte) |
624 c = mb_cptr2char_adv(&arg); | 623 c = mb_cptr2char_adv(&arg); |
625 else | 624 else |
645 char_u *newp, *oldp; | 644 char_u *newp, *oldp; |
646 struct block_def bd; | 645 struct block_def bd; |
647 linenr_T old_lcount = curbuf->b_ml.ml_line_count; | 646 linenr_T old_lcount = curbuf->b_ml.ml_line_count; |
648 int did_yank = FALSE; | 647 int did_yank = FALSE; |
649 | 648 |
650 if (curbuf->b_ml.ml_flags & ML_EMPTY) /* nothing to do */ | 649 if (curbuf->b_ml.ml_flags & ML_EMPTY) // nothing to do |
651 return OK; | 650 return OK; |
652 | 651 |
653 /* Nothing to delete, return here. Do prepare undo, for op_change(). */ | 652 // Nothing to delete, return here. Do prepare undo, for op_change(). |
654 if (oap->empty) | 653 if (oap->empty) |
655 return u_save_cursor(); | 654 return u_save_cursor(); |
656 | 655 |
657 if (!curbuf->b_p_ma) | 656 if (!curbuf->b_p_ma) |
658 { | 657 { |
699 /* | 698 /* |
700 * It's an error to operate on an empty region, when 'E' included in | 699 * It's an error to operate on an empty region, when 'E' included in |
701 * 'cpoptions' (Vi compatible). | 700 * 'cpoptions' (Vi compatible). |
702 */ | 701 */ |
703 if (virtual_op) | 702 if (virtual_op) |
704 /* Virtual editing: Nothing gets deleted, but we set the '[ and '] | 703 // Virtual editing: Nothing gets deleted, but we set the '[ and '] |
705 * marks as if it happened. */ | 704 // marks as if it happened. |
706 goto setmarks; | 705 goto setmarks; |
707 if (vim_strchr(p_cpo, CPO_EMPTYREGION) != NULL) | 706 if (vim_strchr(p_cpo, CPO_EMPTYREGION) != NULL) |
708 beep_flush(); | 707 beep_flush(); |
709 return OK; | 708 return OK; |
710 } | 709 } |
716 */ | 715 */ |
717 if (oap->regname != '_') | 716 if (oap->regname != '_') |
718 { | 717 { |
719 if (oap->regname != 0) | 718 if (oap->regname != 0) |
720 { | 719 { |
721 /* check for read-only register */ | 720 // check for read-only register |
722 if (!valid_yank_reg(oap->regname, TRUE)) | 721 if (!valid_yank_reg(oap->regname, TRUE)) |
723 { | 722 { |
724 beep_flush(); | 723 beep_flush(); |
725 return OK; | 724 return OK; |
726 } | 725 } |
727 get_yank_register(oap->regname, TRUE); /* yank into specif'd reg. */ | 726 get_yank_register(oap->regname, TRUE); // yank into specif'd reg. |
728 if (op_yank(oap, TRUE, FALSE) == OK) /* yank without message */ | 727 if (op_yank(oap, TRUE, FALSE) == OK) // yank without message |
729 did_yank = TRUE; | 728 did_yank = TRUE; |
730 } | 729 } |
731 | 730 |
732 /* | 731 /* |
733 * Put deleted text into register 1 and shift number registers if the | 732 * Put deleted text into register 1 and shift number registers if the |
742 shift_delete_registers(); | 741 shift_delete_registers(); |
743 if (op_yank(oap, TRUE, FALSE) == OK) | 742 if (op_yank(oap, TRUE, FALSE) == OK) |
744 did_yank = TRUE; | 743 did_yank = TRUE; |
745 } | 744 } |
746 | 745 |
747 /* Yank into small delete register when no named register specified | 746 // Yank into small delete register when no named register specified |
748 * and the delete is within one line. */ | 747 // and the delete is within one line. |
749 if (( | 748 if (( |
750 #ifdef FEAT_CLIPBOARD | 749 #ifdef FEAT_CLIPBOARD |
751 ((clip_unnamed & CLIP_UNNAMED) && oap->regname == '*') || | 750 ((clip_unnamed & CLIP_UNNAMED) && oap->regname == '*') || |
752 ((clip_unnamed & CLIP_UNNAMED_PLUS) && oap->regname == '+') || | 751 ((clip_unnamed & CLIP_UNNAMED_PLUS) && oap->regname == '+') || |
753 #endif | 752 #endif |
769 */ | 768 */ |
770 if (!did_yank) | 769 if (!did_yank) |
771 { | 770 { |
772 int msg_silent_save = msg_silent; | 771 int msg_silent_save = msg_silent; |
773 | 772 |
774 msg_silent = 0; /* must display the prompt */ | 773 msg_silent = 0; // must display the prompt |
775 n = ask_yesno((char_u *)_("cannot yank; delete anyway"), TRUE); | 774 n = ask_yesno((char_u *)_("cannot yank; delete anyway"), TRUE); |
776 msg_silent = msg_silent_save; | 775 msg_silent = msg_silent_save; |
777 if (n != 'y') | 776 if (n != 'y') |
778 { | 777 { |
779 emsg(_(e_abort)); | 778 emsg(_(e_abort)); |
797 return FAIL; | 796 return FAIL; |
798 | 797 |
799 for (lnum = curwin->w_cursor.lnum; lnum <= oap->end.lnum; ++lnum) | 798 for (lnum = curwin->w_cursor.lnum; lnum <= oap->end.lnum; ++lnum) |
800 { | 799 { |
801 block_prep(oap, &bd, lnum, TRUE); | 800 block_prep(oap, &bd, lnum, TRUE); |
802 if (bd.textlen == 0) /* nothing to delete */ | 801 if (bd.textlen == 0) // nothing to delete |
803 continue; | 802 continue; |
804 | 803 |
805 /* Adjust cursor position for tab replaced by spaces and 'lbr'. */ | 804 // Adjust cursor position for tab replaced by spaces and 'lbr'. |
806 if (lnum == curwin->w_cursor.lnum) | 805 if (lnum == curwin->w_cursor.lnum) |
807 { | 806 { |
808 curwin->w_cursor.col = bd.textcol + bd.startspaces; | 807 curwin->w_cursor.col = bd.textcol + bd.startspaces; |
809 curwin->w_cursor.coladd = 0; | 808 curwin->w_cursor.coladd = 0; |
810 } | 809 } |
815 n = bd.textlen - bd.startspaces - bd.endspaces; | 814 n = bd.textlen - bd.startspaces - bd.endspaces; |
816 oldp = ml_get(lnum); | 815 oldp = ml_get(lnum); |
817 newp = alloc(STRLEN(oldp) + 1 - n); | 816 newp = alloc(STRLEN(oldp) + 1 - n); |
818 if (newp == NULL) | 817 if (newp == NULL) |
819 continue; | 818 continue; |
820 /* copy up to deleted part */ | 819 // copy up to deleted part |
821 mch_memmove(newp, oldp, (size_t)bd.textcol); | 820 mch_memmove(newp, oldp, (size_t)bd.textcol); |
822 /* insert spaces */ | 821 // insert spaces |
823 vim_memset(newp + bd.textcol, ' ', | 822 vim_memset(newp + bd.textcol, ' ', |
824 (size_t)(bd.startspaces + bd.endspaces)); | 823 (size_t)(bd.startspaces + bd.endspaces)); |
825 /* copy the part after the deleted part */ | 824 // copy the part after the deleted part |
826 oldp += bd.textcol + bd.textlen; | 825 oldp += bd.textcol + bd.textlen; |
827 STRMOVE(newp + bd.textcol + bd.startspaces + bd.endspaces, oldp); | 826 STRMOVE(newp + bd.textcol + bd.startspaces + bd.endspaces, oldp); |
828 /* replace the line */ | 827 // replace the line |
829 ml_replace(lnum, newp, FALSE); | 828 ml_replace(lnum, newp, FALSE); |
830 | 829 |
831 #ifdef FEAT_PROP_POPUP | 830 #ifdef FEAT_PROP_POPUP |
832 if (curbuf->b_has_textprop && n != 0) | 831 if (curbuf->b_has_textprop && n != 0) |
833 adjust_prop_columns(lnum, bd.textcol, -n, 0); | 832 adjust_prop_columns(lnum, bd.textcol, -n, 0); |
835 } | 834 } |
836 | 835 |
837 check_cursor_col(); | 836 check_cursor_col(); |
838 changed_lines(curwin->w_cursor.lnum, curwin->w_cursor.col, | 837 changed_lines(curwin->w_cursor.lnum, curwin->w_cursor.col, |
839 oap->end.lnum + 1, 0L); | 838 oap->end.lnum + 1, 0L); |
840 oap->line_count = 0; /* no lines deleted */ | 839 oap->line_count = 0; // no lines deleted |
841 } | 840 } |
842 else if (oap->motion_type == MLINE) | 841 else if (oap->motion_type == MLINE) |
843 { | 842 { |
844 if (oap->op_type == OP_CHANGE) | 843 if (oap->op_type == OP_CHANGE) |
845 { | 844 { |
846 /* Delete the lines except the first one. Temporarily move the | 845 // Delete the lines except the first one. Temporarily move the |
847 * cursor to the next line. Save the current line number, if the | 846 // cursor to the next line. Save the current line number, if the |
848 * last line is deleted it may be changed. | 847 // last line is deleted it may be changed. |
849 */ | |
850 if (oap->line_count > 1) | 848 if (oap->line_count > 1) |
851 { | 849 { |
852 lnum = curwin->w_cursor.lnum; | 850 lnum = curwin->w_cursor.lnum; |
853 ++curwin->w_cursor.lnum; | 851 ++curwin->w_cursor.lnum; |
854 del_lines((long)(oap->line_count - 1), TRUE); | 852 del_lines((long)(oap->line_count - 1), TRUE); |
855 curwin->w_cursor.lnum = lnum; | 853 curwin->w_cursor.lnum = lnum; |
856 } | 854 } |
857 if (u_save_cursor() == FAIL) | 855 if (u_save_cursor() == FAIL) |
858 return FAIL; | 856 return FAIL; |
859 if (curbuf->b_p_ai) /* don't delete indent */ | 857 if (curbuf->b_p_ai) // don't delete indent |
860 { | 858 { |
861 beginline(BL_WHITE); /* cursor on first non-white */ | 859 beginline(BL_WHITE); // cursor on first non-white |
862 did_ai = TRUE; /* delete the indent when ESC hit */ | 860 did_ai = TRUE; // delete the indent when ESC hit |
863 ai_col = curwin->w_cursor.col; | 861 ai_col = curwin->w_cursor.col; |
864 } | 862 } |
865 else | 863 else |
866 beginline(0); /* cursor in column 0 */ | 864 beginline(0); // cursor in column 0 |
867 truncate_line(FALSE); /* delete the rest of the line */ | 865 truncate_line(FALSE); // delete the rest of the line |
868 /* leave cursor past last char in line */ | 866 // leave cursor past last char in line |
869 if (oap->line_count > 1) | 867 if (oap->line_count > 1) |
870 u_clearline(); /* "U" command not possible after "2cc" */ | 868 u_clearline(); // "U" command not possible after "2cc" |
871 } | 869 } |
872 else | 870 else |
873 { | 871 { |
874 del_lines(oap->line_count, TRUE); | 872 del_lines(oap->line_count, TRUE); |
875 beginline(BL_WHITE | BL_FIX); | 873 beginline(BL_WHITE | BL_FIX); |
876 u_clearline(); /* "U" command not possible after "dd" */ | 874 u_clearline(); // "U" command not possible after "dd" |
877 } | 875 } |
878 } | 876 } |
879 else | 877 else |
880 { | 878 { |
881 if (virtual_op) | 879 if (virtual_op) |
882 { | 880 { |
883 int endcol = 0; | 881 int endcol = 0; |
884 | 882 |
885 /* For virtualedit: break the tabs that are partly included. */ | 883 // For virtualedit: break the tabs that are partly included. |
886 if (gchar_pos(&oap->start) == '\t') | 884 if (gchar_pos(&oap->start) == '\t') |
887 { | 885 { |
888 if (u_save_cursor() == FAIL) /* save first line for undo */ | 886 if (u_save_cursor() == FAIL) // save first line for undo |
889 return FAIL; | 887 return FAIL; |
890 if (oap->line_count == 1) | 888 if (oap->line_count == 1) |
891 endcol = getviscol2(oap->end.col, oap->end.coladd); | 889 endcol = getviscol2(oap->end.col, oap->end.coladd); |
892 coladvance_force(getviscol2(oap->start.col, oap->start.coladd)); | 890 coladvance_force(getviscol2(oap->start.col, oap->start.coladd)); |
893 oap->start = curwin->w_cursor; | 891 oap->start = curwin->w_cursor; |
898 oap->end.coladd = curwin->w_cursor.coladd; | 896 oap->end.coladd = curwin->w_cursor.coladd; |
899 curwin->w_cursor = oap->start; | 897 curwin->w_cursor = oap->start; |
900 } | 898 } |
901 } | 899 } |
902 | 900 |
903 /* Break a tab only when it's included in the area. */ | 901 // Break a tab only when it's included in the area. |
904 if (gchar_pos(&oap->end) == '\t' | 902 if (gchar_pos(&oap->end) == '\t' |
905 && (int)oap->end.coladd < oap->inclusive) | 903 && (int)oap->end.coladd < oap->inclusive) |
906 { | 904 { |
907 /* save last line for undo */ | 905 // save last line for undo |
908 if (u_save((linenr_T)(oap->end.lnum - 1), | 906 if (u_save((linenr_T)(oap->end.lnum - 1), |
909 (linenr_T)(oap->end.lnum + 1)) == FAIL) | 907 (linenr_T)(oap->end.lnum + 1)) == FAIL) |
910 return FAIL; | 908 return FAIL; |
911 curwin->w_cursor = oap->end; | 909 curwin->w_cursor = oap->end; |
912 coladvance_force(getviscol2(oap->end.col, oap->end.coladd)); | 910 coladvance_force(getviscol2(oap->end.col, oap->end.coladd)); |
915 } | 913 } |
916 if (has_mbyte) | 914 if (has_mbyte) |
917 mb_adjust_opend(oap); | 915 mb_adjust_opend(oap); |
918 } | 916 } |
919 | 917 |
920 if (oap->line_count == 1) /* delete characters within one line */ | 918 if (oap->line_count == 1) // delete characters within one line |
921 { | 919 { |
922 if (u_save_cursor() == FAIL) /* save line for undo */ | 920 if (u_save_cursor() == FAIL) // save line for undo |
923 return FAIL; | 921 return FAIL; |
924 | 922 |
925 /* if 'cpoptions' contains '$', display '$' at end of change */ | 923 // if 'cpoptions' contains '$', display '$' at end of change |
926 if ( vim_strchr(p_cpo, CPO_DOLLAR) != NULL | 924 if ( vim_strchr(p_cpo, CPO_DOLLAR) != NULL |
927 && oap->op_type == OP_CHANGE | 925 && oap->op_type == OP_CHANGE |
928 && oap->end.lnum == curwin->w_cursor.lnum | 926 && oap->end.lnum == curwin->w_cursor.lnum |
929 && !oap->is_VIsual) | 927 && !oap->is_VIsual) |
930 display_dollar(oap->end.col - !oap->inclusive); | 928 display_dollar(oap->end.col - !oap->inclusive); |
931 | 929 |
932 n = oap->end.col - oap->start.col + 1 - !oap->inclusive; | 930 n = oap->end.col - oap->start.col + 1 - !oap->inclusive; |
933 | 931 |
934 if (virtual_op) | 932 if (virtual_op) |
935 { | 933 { |
936 /* fix up things for virtualedit-delete: | 934 // fix up things for virtualedit-delete: |
937 * break the tabs which are going to get in our way | 935 // break the tabs which are going to get in our way |
938 */ | |
939 char_u *curline = ml_get_curline(); | 936 char_u *curline = ml_get_curline(); |
940 int len = (int)STRLEN(curline); | 937 int len = (int)STRLEN(curline); |
941 | 938 |
942 if (oap->end.coladd != 0 | 939 if (oap->end.coladd != 0 |
943 && (int)oap->end.col >= len - 1 | 940 && (int)oap->end.col >= len - 1 |
944 && !(oap->start.coladd && (int)oap->end.col >= len - 1)) | 941 && !(oap->start.coladd && (int)oap->end.col >= len - 1)) |
945 n++; | 942 n++; |
946 /* Delete at least one char (e.g, when on a control char). */ | 943 // Delete at least one char (e.g, when on a control char). |
947 if (n == 0 && oap->start.coladd != oap->end.coladd) | 944 if (n == 0 && oap->start.coladd != oap->end.coladd) |
948 n = 1; | 945 n = 1; |
949 | 946 |
950 /* When deleted a char in the line, reset coladd. */ | 947 // When deleted a char in the line, reset coladd. |
951 if (gchar_cursor() != NUL) | 948 if (gchar_cursor() != NUL) |
952 curwin->w_cursor.coladd = 0; | 949 curwin->w_cursor.coladd = 0; |
953 } | 950 } |
954 (void)del_bytes((long)n, !virtual_op, | 951 (void)del_bytes((long)n, !virtual_op, |
955 oap->op_type == OP_DELETE && !oap->is_VIsual); | 952 oap->op_type == OP_DELETE && !oap->is_VIsual); |
956 } | 953 } |
957 else /* delete characters between lines */ | 954 else // delete characters between lines |
958 { | 955 { |
959 pos_T curpos; | 956 pos_T curpos; |
960 | 957 |
961 /* save deleted and changed lines for undo */ | 958 // save deleted and changed lines for undo |
962 if (u_save((linenr_T)(curwin->w_cursor.lnum - 1), | 959 if (u_save((linenr_T)(curwin->w_cursor.lnum - 1), |
963 (linenr_T)(curwin->w_cursor.lnum + oap->line_count)) == FAIL) | 960 (linenr_T)(curwin->w_cursor.lnum + oap->line_count)) == FAIL) |
964 return FAIL; | 961 return FAIL; |
965 | 962 |
966 truncate_line(TRUE); /* delete from cursor to end of line */ | 963 truncate_line(TRUE); // delete from cursor to end of line |
967 | 964 |
968 curpos = curwin->w_cursor; /* remember curwin->w_cursor */ | 965 curpos = curwin->w_cursor; // remember curwin->w_cursor |
969 ++curwin->w_cursor.lnum; | 966 ++curwin->w_cursor.lnum; |
970 del_lines((long)(oap->line_count - 2), FALSE); | 967 del_lines((long)(oap->line_count - 2), FALSE); |
971 | 968 |
972 /* delete from start of line until op_end */ | 969 // delete from start of line until op_end |
973 n = (oap->end.col + 1 - !oap->inclusive); | 970 n = (oap->end.col + 1 - !oap->inclusive); |
974 curwin->w_cursor.col = 0; | 971 curwin->w_cursor.col = 0; |
975 (void)del_bytes((long)n, !virtual_op, | 972 (void)del_bytes((long)n, !virtual_op, |
976 oap->op_type == OP_DELETE && !oap->is_VIsual); | 973 oap->op_type == OP_DELETE && !oap->is_VIsual); |
977 curwin->w_cursor = curpos; /* restore curwin->w_cursor */ | 974 curwin->w_cursor = curpos; // restore curwin->w_cursor |
978 (void)do_join(2, FALSE, FALSE, FALSE, FALSE); | 975 (void)do_join(2, FALSE, FALSE, FALSE, FALSE); |
979 } | 976 } |
980 } | 977 } |
981 | 978 |
982 msgmore(curbuf->b_ml.ml_line_count - old_lcount); | 979 msgmore(curbuf->b_ml.ml_line_count - old_lcount); |
1023 int n = State; | 1020 int n = State; |
1024 | 1021 |
1025 State = REPLACE; | 1022 State = REPLACE; |
1026 ins_char(c); | 1023 ins_char(c); |
1027 State = n; | 1024 State = n; |
1028 /* Backup to the replaced character. */ | 1025 // Backup to the replaced character. |
1029 dec_cursor(); | 1026 dec_cursor(); |
1030 } | 1027 } |
1031 | 1028 |
1032 /* | 1029 /* |
1033 * Replace a whole area with one character. | 1030 * Replace a whole area with one character. |
1042 struct block_def bd; | 1039 struct block_def bd; |
1043 char_u *after_p = NULL; | 1040 char_u *after_p = NULL; |
1044 int had_ctrl_v_cr = FALSE; | 1041 int had_ctrl_v_cr = FALSE; |
1045 | 1042 |
1046 if ((curbuf->b_ml.ml_flags & ML_EMPTY ) || oap->empty) | 1043 if ((curbuf->b_ml.ml_flags & ML_EMPTY ) || oap->empty) |
1047 return OK; /* nothing to do */ | 1044 return OK; // nothing to do |
1048 | 1045 |
1049 if (c == REPLACE_CR_NCHAR) | 1046 if (c == REPLACE_CR_NCHAR) |
1050 { | 1047 { |
1051 had_ctrl_v_cr = TRUE; | 1048 had_ctrl_v_cr = TRUE; |
1052 c = CAR; | 1049 c = CAR; |
1070 if (oap->block_mode) | 1067 if (oap->block_mode) |
1071 { | 1068 { |
1072 bd.is_MAX = (curwin->w_curswant == MAXCOL); | 1069 bd.is_MAX = (curwin->w_curswant == MAXCOL); |
1073 for ( ; curwin->w_cursor.lnum <= oap->end.lnum; ++curwin->w_cursor.lnum) | 1070 for ( ; curwin->w_cursor.lnum <= oap->end.lnum; ++curwin->w_cursor.lnum) |
1074 { | 1071 { |
1075 curwin->w_cursor.col = 0; /* make sure cursor position is valid */ | 1072 curwin->w_cursor.col = 0; // make sure cursor position is valid |
1076 block_prep(oap, &bd, curwin->w_cursor.lnum, TRUE); | 1073 block_prep(oap, &bd, curwin->w_cursor.lnum, TRUE); |
1077 if (bd.textlen == 0 && (!virtual_op || bd.is_MAX)) | 1074 if (bd.textlen == 0 && (!virtual_op || bd.is_MAX)) |
1078 continue; /* nothing to replace */ | 1075 continue; // nothing to replace |
1079 | 1076 |
1080 /* n == number of extra chars required | 1077 // n == number of extra chars required |
1081 * If we split a TAB, it may be replaced by several characters. | 1078 // If we split a TAB, it may be replaced by several characters. |
1082 * Thus the number of characters may increase! | 1079 // Thus the number of characters may increase! |
1083 */ | 1080 // If the range starts in virtual space, count the initial |
1084 /* If the range starts in virtual space, count the initial | 1081 // coladd offset as part of "startspaces" |
1085 * coladd offset as part of "startspaces" */ | |
1086 if (virtual_op && bd.is_short && *bd.textstart == NUL) | 1082 if (virtual_op && bd.is_short && *bd.textstart == NUL) |
1087 { | 1083 { |
1088 pos_T vpos; | 1084 pos_T vpos; |
1089 | 1085 |
1090 vpos.lnum = curwin->w_cursor.lnum; | 1086 vpos.lnum = curwin->w_cursor.lnum; |
1091 getvpos(&vpos, oap->start_vcol); | 1087 getvpos(&vpos, oap->start_vcol); |
1092 bd.startspaces += vpos.coladd; | 1088 bd.startspaces += vpos.coladd; |
1093 n = bd.startspaces; | 1089 n = bd.startspaces; |
1094 } | 1090 } |
1095 else | 1091 else |
1096 /* allow for pre spaces */ | 1092 // allow for pre spaces |
1097 n = (bd.startspaces ? bd.start_char_vcols - 1 : 0); | 1093 n = (bd.startspaces ? bd.start_char_vcols - 1 : 0); |
1098 | 1094 |
1099 /* allow for post spp */ | 1095 // allow for post spp |
1100 n += (bd.endspaces | 1096 n += (bd.endspaces |
1101 && !bd.is_oneChar | 1097 && !bd.is_oneChar |
1102 && bd.end_char_vcols > 0) ? bd.end_char_vcols - 1 : 0; | 1098 && bd.end_char_vcols > 0) ? bd.end_char_vcols - 1 : 0; |
1103 /* Figure out how many characters to replace. */ | 1099 // Figure out how many characters to replace. |
1104 numc = oap->end_vcol - oap->start_vcol + 1; | 1100 numc = oap->end_vcol - oap->start_vcol + 1; |
1105 if (bd.is_short && (!virtual_op || bd.is_MAX)) | 1101 if (bd.is_short && (!virtual_op || bd.is_MAX)) |
1106 numc -= (oap->end_vcol - bd.end_vcol) + 1; | 1102 numc -= (oap->end_vcol - bd.end_vcol) + 1; |
1107 | 1103 |
1108 /* A double-wide character can be replaced only up to half the | 1104 // A double-wide character can be replaced only up to half the |
1109 * times. */ | 1105 // times. |
1110 if ((*mb_char2cells)(c) > 1) | 1106 if ((*mb_char2cells)(c) > 1) |
1111 { | 1107 { |
1112 if ((numc & 1) && !bd.is_short) | 1108 if ((numc & 1) && !bd.is_short) |
1113 { | 1109 { |
1114 ++bd.endspaces; | 1110 ++bd.endspaces; |
1115 ++n; | 1111 ++n; |
1116 } | 1112 } |
1117 numc = numc / 2; | 1113 numc = numc / 2; |
1118 } | 1114 } |
1119 | 1115 |
1120 /* Compute bytes needed, move character count to num_chars. */ | 1116 // Compute bytes needed, move character count to num_chars. |
1121 num_chars = numc; | 1117 num_chars = numc; |
1122 numc *= (*mb_char2len)(c); | 1118 numc *= (*mb_char2len)(c); |
1123 /* oldlen includes textlen, so don't double count */ | 1119 // oldlen includes textlen, so don't double count |
1124 n += numc - bd.textlen; | 1120 n += numc - bd.textlen; |
1125 | 1121 |
1126 oldp = ml_get_curline(); | 1122 oldp = ml_get_curline(); |
1127 oldlen = STRLEN(oldp); | 1123 oldlen = STRLEN(oldp); |
1128 newp = alloc(oldlen + 1 + n); | 1124 newp = alloc(oldlen + 1 + n); |
1129 if (newp == NULL) | 1125 if (newp == NULL) |
1130 continue; | 1126 continue; |
1131 vim_memset(newp, NUL, (size_t)(oldlen + 1 + n)); | 1127 vim_memset(newp, NUL, (size_t)(oldlen + 1 + n)); |
1132 /* copy up to deleted part */ | 1128 // copy up to deleted part |
1133 mch_memmove(newp, oldp, (size_t)bd.textcol); | 1129 mch_memmove(newp, oldp, (size_t)bd.textcol); |
1134 oldp += bd.textcol + bd.textlen; | 1130 oldp += bd.textcol + bd.textlen; |
1135 /* insert pre-spaces */ | 1131 // insert pre-spaces |
1136 vim_memset(newp + bd.textcol, ' ', (size_t)bd.startspaces); | 1132 vim_memset(newp + bd.textcol, ' ', (size_t)bd.startspaces); |
1137 /* insert replacement chars CHECK FOR ALLOCATED SPACE */ | 1133 // insert replacement chars CHECK FOR ALLOCATED SPACE |
1138 /* REPLACE_CR_NCHAR/REPLACE_NL_NCHAR is used for entering CR | 1134 // REPLACE_CR_NCHAR/REPLACE_NL_NCHAR is used for entering CR |
1139 * literally. */ | 1135 // literally. |
1140 if (had_ctrl_v_cr || (c != '\r' && c != '\n')) | 1136 if (had_ctrl_v_cr || (c != '\r' && c != '\n')) |
1141 { | 1137 { |
1142 if (has_mbyte) | 1138 if (has_mbyte) |
1143 { | 1139 { |
1144 n = (int)STRLEN(newp); | 1140 n = (int)STRLEN(newp); |
1147 } | 1143 } |
1148 else | 1144 else |
1149 vim_memset(newp + STRLEN(newp), c, (size_t)numc); | 1145 vim_memset(newp + STRLEN(newp), c, (size_t)numc); |
1150 if (!bd.is_short) | 1146 if (!bd.is_short) |
1151 { | 1147 { |
1152 /* insert post-spaces */ | 1148 // insert post-spaces |
1153 vim_memset(newp + STRLEN(newp), ' ', (size_t)bd.endspaces); | 1149 vim_memset(newp + STRLEN(newp), ' ', (size_t)bd.endspaces); |
1154 /* copy the part after the changed part */ | 1150 // copy the part after the changed part |
1155 STRMOVE(newp + STRLEN(newp), oldp); | 1151 STRMOVE(newp + STRLEN(newp), oldp); |
1156 } | 1152 } |
1157 } | 1153 } |
1158 else | 1154 else |
1159 { | 1155 { |
1160 /* Replacing with \r or \n means splitting the line. */ | 1156 // Replacing with \r or \n means splitting the line. |
1161 after_p = alloc(oldlen + 1 + n - STRLEN(newp)); | 1157 after_p = alloc(oldlen + 1 + n - STRLEN(newp)); |
1162 if (after_p != NULL) | 1158 if (after_p != NULL) |
1163 STRMOVE(after_p, oldp); | 1159 STRMOVE(after_p, oldp); |
1164 } | 1160 } |
1165 /* replace the line */ | 1161 // replace the line |
1166 ml_replace(curwin->w_cursor.lnum, newp, FALSE); | 1162 ml_replace(curwin->w_cursor.lnum, newp, FALSE); |
1167 if (after_p != NULL) | 1163 if (after_p != NULL) |
1168 { | 1164 { |
1169 ml_append(curwin->w_cursor.lnum++, after_p, 0, FALSE); | 1165 ml_append(curwin->w_cursor.lnum++, after_p, 0, FALSE); |
1170 appended_lines_mark(curwin->w_cursor.lnum, 1L); | 1166 appended_lines_mark(curwin->w_cursor.lnum, 1L); |
1194 n = gchar_cursor(); | 1190 n = gchar_cursor(); |
1195 if (n != NUL) | 1191 if (n != NUL) |
1196 { | 1192 { |
1197 if ((*mb_char2len)(c) > 1 || (*mb_char2len)(n) > 1) | 1193 if ((*mb_char2len)(c) > 1 || (*mb_char2len)(n) > 1) |
1198 { | 1194 { |
1199 /* This is slow, but it handles replacing a single-byte | 1195 // This is slow, but it handles replacing a single-byte |
1200 * with a multi-byte and the other way around. */ | 1196 // with a multi-byte and the other way around. |
1201 if (curwin->w_cursor.lnum == oap->end.lnum) | 1197 if (curwin->w_cursor.lnum == oap->end.lnum) |
1202 oap->end.col += (*mb_char2len)(c) - (*mb_char2len)(n); | 1198 oap->end.col += (*mb_char2len)(c) - (*mb_char2len)(n); |
1203 replace_character(c); | 1199 replace_character(c); |
1204 } | 1200 } |
1205 else | 1201 else |
1208 { | 1204 { |
1209 int end_vcol = 0; | 1205 int end_vcol = 0; |
1210 | 1206 |
1211 if (curwin->w_cursor.lnum == oap->end.lnum) | 1207 if (curwin->w_cursor.lnum == oap->end.lnum) |
1212 { | 1208 { |
1213 /* oap->end has to be recalculated when | 1209 // oap->end has to be recalculated when |
1214 * the tab breaks */ | 1210 // the tab breaks |
1215 end_vcol = getviscol2(oap->end.col, | 1211 end_vcol = getviscol2(oap->end.col, |
1216 oap->end.coladd); | 1212 oap->end.coladd); |
1217 } | 1213 } |
1218 coladvance_force(getviscol()); | 1214 coladvance_force(getviscol()); |
1219 if (curwin->w_cursor.lnum == oap->end.lnum) | 1215 if (curwin->w_cursor.lnum == oap->end.lnum) |
1228 | 1224 |
1229 if (curwin->w_cursor.lnum == oap->start.lnum | 1225 if (curwin->w_cursor.lnum == oap->start.lnum |
1230 && oap->start.col == oap->end.col && oap->start.coladd) | 1226 && oap->start.col == oap->end.col && oap->start.coladd) |
1231 virtcols -= oap->start.coladd; | 1227 virtcols -= oap->start.coladd; |
1232 | 1228 |
1233 /* oap->end has been trimmed so it's effectively inclusive; | 1229 // oap->end has been trimmed so it's effectively inclusive; |
1234 * as a result an extra +1 must be counted so we don't | 1230 // as a result an extra +1 must be counted so we don't |
1235 * trample the NUL byte. */ | 1231 // trample the NUL byte. |
1236 coladvance_force(getviscol2(oap->end.col, oap->end.coladd) + 1); | 1232 coladvance_force(getviscol2(oap->end.col, oap->end.coladd) + 1); |
1237 curwin->w_cursor.col -= (virtcols + 1); | 1233 curwin->w_cursor.col -= (virtcols + 1); |
1238 for (; virtcols >= 0; virtcols--) | 1234 for (; virtcols >= 0; virtcols--) |
1239 { | 1235 { |
1240 if ((*mb_char2len)(c) > 1) | 1236 if ((*mb_char2len)(c) > 1) |
1244 if (inc(&curwin->w_cursor) == -1) | 1240 if (inc(&curwin->w_cursor) == -1) |
1245 break; | 1241 break; |
1246 } | 1242 } |
1247 } | 1243 } |
1248 | 1244 |
1249 /* Advance to next character, stop at the end of the file. */ | 1245 // Advance to next character, stop at the end of the file. |
1250 if (inc_cursor() == -1) | 1246 if (inc_cursor() == -1) |
1251 break; | 1247 break; |
1252 } | 1248 } |
1253 } | 1249 } |
1254 | 1250 |
1256 check_cursor(); | 1252 check_cursor(); |
1257 changed_lines(oap->start.lnum, oap->start.col, oap->end.lnum + 1, 0L); | 1253 changed_lines(oap->start.lnum, oap->start.col, oap->end.lnum + 1, 0L); |
1258 | 1254 |
1259 if (!cmdmod.lockmarks) | 1255 if (!cmdmod.lockmarks) |
1260 { | 1256 { |
1261 /* Set "'[" and "']" marks. */ | 1257 // Set "'[" and "']" marks. |
1262 curbuf->b_op_start = oap->start; | 1258 curbuf->b_op_start = oap->start; |
1263 curbuf->b_op_end = oap->end; | 1259 curbuf->b_op_end = oap->end; |
1264 } | 1260 } |
1265 | 1261 |
1266 return OK; | 1262 return OK; |
1281 if (u_save((linenr_T)(oap->start.lnum - 1), | 1277 if (u_save((linenr_T)(oap->start.lnum - 1), |
1282 (linenr_T)(oap->end.lnum + 1)) == FAIL) | 1278 (linenr_T)(oap->end.lnum + 1)) == FAIL) |
1283 return; | 1279 return; |
1284 | 1280 |
1285 pos = oap->start; | 1281 pos = oap->start; |
1286 if (oap->block_mode) /* Visual block mode */ | 1282 if (oap->block_mode) // Visual block mode |
1287 { | 1283 { |
1288 for (; pos.lnum <= oap->end.lnum; ++pos.lnum) | 1284 for (; pos.lnum <= oap->end.lnum; ++pos.lnum) |
1289 { | 1285 { |
1290 int one_change; | 1286 int one_change; |
1291 | 1287 |
1307 #endif | 1303 #endif |
1308 } | 1304 } |
1309 if (did_change) | 1305 if (did_change) |
1310 changed_lines(oap->start.lnum, 0, oap->end.lnum + 1, 0L); | 1306 changed_lines(oap->start.lnum, 0, oap->end.lnum + 1, 0L); |
1311 } | 1307 } |
1312 else /* not block mode */ | 1308 else // not block mode |
1313 { | 1309 { |
1314 if (oap->motion_type == MLINE) | 1310 if (oap->motion_type == MLINE) |
1315 { | 1311 { |
1316 oap->start.col = 0; | 1312 oap->start.col = 0; |
1317 pos.col = 0; | 1313 pos.col = 0; |
1364 #endif | 1360 #endif |
1365 } | 1361 } |
1366 } | 1362 } |
1367 | 1363 |
1368 if (!did_change && oap->is_VIsual) | 1364 if (!did_change && oap->is_VIsual) |
1369 /* No change: need to remove the Visual selection */ | 1365 // No change: need to remove the Visual selection |
1370 redraw_curbuf_later(INVERTED); | 1366 redraw_curbuf_later(INVERTED); |
1371 | 1367 |
1372 if (!cmdmod.lockmarks) | 1368 if (!cmdmod.lockmarks) |
1373 { | 1369 { |
1374 // Set '[ and '] marks. | 1370 // Set '[ and '] marks. |
1398 { | 1394 { |
1399 if (has_mbyte) | 1395 if (has_mbyte) |
1400 { | 1396 { |
1401 int len = (*mb_ptr2len)(ml_get_pos(pos)); | 1397 int len = (*mb_ptr2len)(ml_get_pos(pos)); |
1402 | 1398 |
1403 /* we're counting bytes, not characters */ | 1399 // we're counting bytes, not characters |
1404 if (len > 0) | 1400 if (len > 0) |
1405 todo -= len - 1; | 1401 todo -= len - 1; |
1406 } | 1402 } |
1407 did_change |= swapchar(op_type, pos); | 1403 did_change |= swapchar(op_type, pos); |
1408 if (inc(pos) == -1) /* at end of file */ | 1404 if (inc(pos) == -1) // at end of file |
1409 break; | 1405 break; |
1410 } | 1406 } |
1411 return did_change; | 1407 return did_change; |
1412 } | 1408 } |
1413 | 1409 |
1424 int c; | 1420 int c; |
1425 int nc; | 1421 int nc; |
1426 | 1422 |
1427 c = gchar_pos(pos); | 1423 c = gchar_pos(pos); |
1428 | 1424 |
1429 /* Only do rot13 encoding for ASCII characters. */ | 1425 // Only do rot13 encoding for ASCII characters. |
1430 if (c >= 0x80 && op_type == OP_ROT13) | 1426 if (c >= 0x80 && op_type == OP_ROT13) |
1431 return FALSE; | 1427 return FALSE; |
1432 | 1428 |
1433 if (op_type == OP_UPPER && c == 0xdf | 1429 if (op_type == OP_UPPER && c == 0xdf |
1434 && (enc_latin1like || STRCMP(p_enc, "iso-8859-2") == 0)) | 1430 && (enc_latin1like || STRCMP(p_enc, "iso-8859-2") == 0)) |
1435 { | 1431 { |
1436 pos_T sp = curwin->w_cursor; | 1432 pos_T sp = curwin->w_cursor; |
1437 | 1433 |
1438 /* Special handling of German sharp s: change to "SS". */ | 1434 // Special handling of German sharp s: change to "SS". |
1439 curwin->w_cursor = *pos; | 1435 curwin->w_cursor = *pos; |
1440 del_char(FALSE); | 1436 del_char(FALSE); |
1441 ins_char('S'); | 1437 ins_char('S'); |
1442 ins_char('S'); | 1438 ins_char('S'); |
1443 curwin->w_cursor = sp; | 1439 curwin->w_cursor = sp; |
1444 inc(pos); | 1440 inc(pos); |
1445 } | 1441 } |
1446 | 1442 |
1447 if (enc_dbcs != 0 && c >= 0x100) /* No lower/uppercase letter */ | 1443 if (enc_dbcs != 0 && c >= 0x100) // No lower/uppercase letter |
1448 return FALSE; | 1444 return FALSE; |
1449 nc = c; | 1445 nc = c; |
1450 if (MB_ISLOWER(c)) | 1446 if (MB_ISLOWER(c)) |
1451 { | 1447 { |
1452 if (op_type == OP_ROT13) | 1448 if (op_type == OP_ROT13) |
1466 if (enc_utf8 && (c >= 0x80 || nc >= 0x80)) | 1462 if (enc_utf8 && (c >= 0x80 || nc >= 0x80)) |
1467 { | 1463 { |
1468 pos_T sp = curwin->w_cursor; | 1464 pos_T sp = curwin->w_cursor; |
1469 | 1465 |
1470 curwin->w_cursor = *pos; | 1466 curwin->w_cursor = *pos; |
1471 /* don't use del_char(), it also removes composing chars */ | 1467 // don't use del_char(), it also removes composing chars |
1472 del_bytes(utf_ptr2len(ml_get_cursor()), FALSE, FALSE); | 1468 del_bytes(utf_ptr2len(ml_get_cursor()), FALSE, FALSE); |
1473 ins_char(nc); | 1469 ins_char(nc); |
1474 curwin->w_cursor = sp; | 1470 curwin->w_cursor = sp; |
1475 } | 1471 } |
1476 else | 1472 else |
1491 colnr_T ind_pre = 0, ind_post; | 1487 colnr_T ind_pre = 0, ind_post; |
1492 struct block_def bd; | 1488 struct block_def bd; |
1493 int i; | 1489 int i; |
1494 pos_T t1; | 1490 pos_T t1; |
1495 | 1491 |
1496 /* edit() changes this - record it for OP_APPEND */ | 1492 // edit() changes this - record it for OP_APPEND |
1497 bd.is_MAX = (curwin->w_curswant == MAXCOL); | 1493 bd.is_MAX = (curwin->w_curswant == MAXCOL); |
1498 | 1494 |
1499 /* vis block is still marked. Get rid of it now. */ | 1495 // vis block is still marked. Get rid of it now. |
1500 curwin->w_cursor.lnum = oap->start.lnum; | 1496 curwin->w_cursor.lnum = oap->start.lnum; |
1501 update_screen(INVERTED); | 1497 update_screen(INVERTED); |
1502 | 1498 |
1503 if (oap->block_mode) | 1499 if (oap->block_mode) |
1504 { | 1500 { |
1505 /* When 'virtualedit' is used, need to insert the extra spaces before | 1501 // When 'virtualedit' is used, need to insert the extra spaces before |
1506 * doing block_prep(). When only "block" is used, virtual edit is | 1502 // doing block_prep(). When only "block" is used, virtual edit is |
1507 * already disabled, but still need it when calling | 1503 // already disabled, but still need it when calling |
1508 * coladvance_force(). */ | 1504 // coladvance_force(). |
1509 if (curwin->w_cursor.coladd > 0) | 1505 if (curwin->w_cursor.coladd > 0) |
1510 { | 1506 { |
1511 int old_ve_flags = ve_flags; | 1507 int old_ve_flags = ve_flags; |
1512 | 1508 |
1513 ve_flags = VE_ALL; | 1509 ve_flags = VE_ALL; |
1517 ? oap->end_vcol + 1 : getviscol()); | 1513 ? oap->end_vcol + 1 : getviscol()); |
1518 if (oap->op_type == OP_APPEND) | 1514 if (oap->op_type == OP_APPEND) |
1519 --curwin->w_cursor.col; | 1515 --curwin->w_cursor.col; |
1520 ve_flags = old_ve_flags; | 1516 ve_flags = old_ve_flags; |
1521 } | 1517 } |
1522 /* Get the info about the block before entering the text */ | 1518 // Get the info about the block before entering the text |
1523 block_prep(oap, &bd, oap->start.lnum, TRUE); | 1519 block_prep(oap, &bd, oap->start.lnum, TRUE); |
1524 /* Get indent information */ | 1520 // Get indent information |
1525 ind_pre = (colnr_T)getwhitecols_curline(); | 1521 ind_pre = (colnr_T)getwhitecols_curline(); |
1526 firstline = ml_get(oap->start.lnum) + bd.textcol; | 1522 firstline = ml_get(oap->start.lnum) + bd.textcol; |
1527 | 1523 |
1528 if (oap->op_type == OP_APPEND) | 1524 if (oap->op_type == OP_APPEND) |
1529 firstline += bd.textlen; | 1525 firstline += bd.textlen; |
1532 | 1528 |
1533 if (oap->op_type == OP_APPEND) | 1529 if (oap->op_type == OP_APPEND) |
1534 { | 1530 { |
1535 if (oap->block_mode && curwin->w_cursor.coladd == 0) | 1531 if (oap->block_mode && curwin->w_cursor.coladd == 0) |
1536 { | 1532 { |
1537 /* Move the cursor to the character right of the block. */ | 1533 // Move the cursor to the character right of the block. |
1538 curwin->w_set_curswant = TRUE; | 1534 curwin->w_set_curswant = TRUE; |
1539 while (*ml_get_cursor() != NUL | 1535 while (*ml_get_cursor() != NUL |
1540 && (curwin->w_cursor.col < bd.textcol + bd.textlen)) | 1536 && (curwin->w_cursor.col < bd.textcol + bd.textlen)) |
1541 ++curwin->w_cursor.col; | 1537 ++curwin->w_cursor.col; |
1542 if (bd.is_short && !bd.is_MAX) | 1538 if (bd.is_short && !bd.is_MAX) |
1543 { | 1539 { |
1544 /* First line was too short, make it longer and adjust the | 1540 // First line was too short, make it longer and adjust the |
1545 * values in "bd". */ | 1541 // values in "bd". |
1546 if (u_save_cursor() == FAIL) | 1542 if (u_save_cursor() == FAIL) |
1547 return; | 1543 return; |
1548 for (i = 0; i < bd.endspaces; ++i) | 1544 for (i = 0; i < bd.endspaces; ++i) |
1549 ins_char(' '); | 1545 ins_char(' '); |
1550 bd.textlen += bd.endspaces; | 1546 bd.textlen += bd.endspaces; |
1553 else | 1549 else |
1554 { | 1550 { |
1555 curwin->w_cursor = oap->end; | 1551 curwin->w_cursor = oap->end; |
1556 check_cursor_col(); | 1552 check_cursor_col(); |
1557 | 1553 |
1558 /* Works just like an 'i'nsert on the next character. */ | 1554 // Works just like an 'i'nsert on the next character. |
1559 if (!LINEEMPTY(curwin->w_cursor.lnum) | 1555 if (!LINEEMPTY(curwin->w_cursor.lnum) |
1560 && oap->start_vcol != oap->end_vcol) | 1556 && oap->start_vcol != oap->end_vcol) |
1561 inc_cursor(); | 1557 inc_cursor(); |
1562 } | 1558 } |
1563 } | 1559 } |
1564 | 1560 |
1565 t1 = oap->start; | 1561 t1 = oap->start; |
1566 (void)edit(NUL, FALSE, (linenr_T)count1); | 1562 (void)edit(NUL, FALSE, (linenr_T)count1); |
1567 | 1563 |
1568 /* When a tab was inserted, and the characters in front of the tab | 1564 // When a tab was inserted, and the characters in front of the tab |
1569 * have been converted to a tab as well, the column of the cursor | 1565 // have been converted to a tab as well, the column of the cursor |
1570 * might have actually been reduced, so need to adjust here. */ | 1566 // might have actually been reduced, so need to adjust here. |
1571 if (t1.lnum == curbuf->b_op_start_orig.lnum | 1567 if (t1.lnum == curbuf->b_op_start_orig.lnum |
1572 && LT_POS(curbuf->b_op_start_orig, t1)) | 1568 && LT_POS(curbuf->b_op_start_orig, t1)) |
1573 oap->start = curbuf->b_op_start_orig; | 1569 oap->start = curbuf->b_op_start_orig; |
1574 | 1570 |
1575 /* If user has moved off this line, we don't know what to do, so do | 1571 // If user has moved off this line, we don't know what to do, so do |
1576 * nothing. | 1572 // nothing. |
1577 * Also don't repeat the insert when Insert mode ended with CTRL-C. */ | 1573 // Also don't repeat the insert when Insert mode ended with CTRL-C. |
1578 if (curwin->w_cursor.lnum != oap->start.lnum || got_int) | 1574 if (curwin->w_cursor.lnum != oap->start.lnum || got_int) |
1579 return; | 1575 return; |
1580 | 1576 |
1581 if (oap->block_mode) | 1577 if (oap->block_mode) |
1582 { | 1578 { |
1583 struct block_def bd2; | 1579 struct block_def bd2; |
1584 int did_indent = FALSE; | 1580 int did_indent = FALSE; |
1585 size_t len; | 1581 size_t len; |
1586 int add; | 1582 int add; |
1587 | 1583 |
1588 /* If indent kicked in, the firstline might have changed | 1584 // If indent kicked in, the firstline might have changed |
1589 * but only do that, if the indent actually increased. */ | 1585 // but only do that, if the indent actually increased. |
1590 ind_post = (colnr_T)getwhitecols_curline(); | 1586 ind_post = (colnr_T)getwhitecols_curline(); |
1591 if (curbuf->b_op_start.col > ind_pre && ind_post > ind_pre) | 1587 if (curbuf->b_op_start.col > ind_pre && ind_post > ind_pre) |
1592 { | 1588 { |
1593 bd.textcol += ind_post - ind_pre; | 1589 bd.textcol += ind_post - ind_pre; |
1594 bd.start_vcol += ind_post - ind_pre; | 1590 bd.start_vcol += ind_post - ind_pre; |
1595 did_indent = TRUE; | 1591 did_indent = TRUE; |
1596 } | 1592 } |
1597 | 1593 |
1598 /* The user may have moved the cursor before inserting something, try | 1594 // The user may have moved the cursor before inserting something, try |
1599 * to adjust the block for that. But only do it, if the difference | 1595 // to adjust the block for that. But only do it, if the difference |
1600 * does not come from indent kicking in. */ | 1596 // does not come from indent kicking in. |
1601 if (oap->start.lnum == curbuf->b_op_start_orig.lnum | 1597 if (oap->start.lnum == curbuf->b_op_start_orig.lnum |
1602 && !bd.is_MAX && !did_indent) | 1598 && !bd.is_MAX && !did_indent) |
1603 { | 1599 { |
1604 if (oap->op_type == OP_INSERT | 1600 if (oap->op_type == OP_INSERT |
1605 && oap->start.col + oap->start.coladd | 1601 && oap->start.col + oap->start.coladd |
1618 + curbuf->b_op_start_orig.coladd) | 1614 + curbuf->b_op_start_orig.coladd) |
1619 { | 1615 { |
1620 int t = getviscol2(curbuf->b_op_start_orig.col, | 1616 int t = getviscol2(curbuf->b_op_start_orig.col, |
1621 curbuf->b_op_start_orig.coladd); | 1617 curbuf->b_op_start_orig.coladd); |
1622 oap->start.col = curbuf->b_op_start_orig.col; | 1618 oap->start.col = curbuf->b_op_start_orig.col; |
1623 /* reset pre_textlen to the value of OP_INSERT */ | 1619 // reset pre_textlen to the value of OP_INSERT |
1624 pre_textlen += bd.textlen; | 1620 pre_textlen += bd.textlen; |
1625 pre_textlen -= t - oap->start_vcol; | 1621 pre_textlen -= t - oap->start_vcol; |
1626 oap->start_vcol = t; | 1622 oap->start_vcol = t; |
1627 oap->op_type = OP_INSERT; | 1623 oap->op_type = OP_INSERT; |
1628 } | 1624 } |
1663 && (ins_len = (long)STRLEN(firstline) - pre_textlen) > 0) | 1659 && (ins_len = (long)STRLEN(firstline) - pre_textlen) > 0) |
1664 { | 1660 { |
1665 ins_text = vim_strnsave(firstline, (int)ins_len); | 1661 ins_text = vim_strnsave(firstline, (int)ins_len); |
1666 if (ins_text != NULL) | 1662 if (ins_text != NULL) |
1667 { | 1663 { |
1668 /* block handled here */ | 1664 // block handled here |
1669 if (u_save(oap->start.lnum, | 1665 if (u_save(oap->start.lnum, |
1670 (linenr_T)(oap->end.lnum + 1)) == OK) | 1666 (linenr_T)(oap->end.lnum + 1)) == OK) |
1671 block_insert(oap, ins_text, (oap->op_type == OP_INSERT), | 1667 block_insert(oap, ins_text, (oap->op_type == OP_INSERT), |
1672 &bd); | 1668 &bd); |
1673 | 1669 |
1706 if (!p_paste && curbuf->b_p_si | 1702 if (!p_paste && curbuf->b_p_si |
1707 # ifdef FEAT_CINDENT | 1703 # ifdef FEAT_CINDENT |
1708 && !curbuf->b_p_cin | 1704 && !curbuf->b_p_cin |
1709 # endif | 1705 # endif |
1710 ) | 1706 ) |
1711 can_si = TRUE; /* It's like opening a new line, do si */ | 1707 can_si = TRUE; // It's like opening a new line, do si |
1712 #endif | 1708 #endif |
1713 } | 1709 } |
1714 | 1710 |
1715 /* First delete the text in the region. In an empty buffer only need to | 1711 // First delete the text in the region. In an empty buffer only need to |
1716 * save for undo */ | 1712 // save for undo |
1717 if (curbuf->b_ml.ml_flags & ML_EMPTY) | 1713 if (curbuf->b_ml.ml_flags & ML_EMPTY) |
1718 { | 1714 { |
1719 if (u_save_cursor() == FAIL) | 1715 if (u_save_cursor() == FAIL) |
1720 return FALSE; | 1716 return FALSE; |
1721 } | 1717 } |
1724 | 1720 |
1725 if ((l > curwin->w_cursor.col) && !LINEEMPTY(curwin->w_cursor.lnum) | 1721 if ((l > curwin->w_cursor.col) && !LINEEMPTY(curwin->w_cursor.lnum) |
1726 && !virtual_op) | 1722 && !virtual_op) |
1727 inc_cursor(); | 1723 inc_cursor(); |
1728 | 1724 |
1729 /* check for still on same line (<CR> in inserted text meaningless) */ | 1725 // check for still on same line (<CR> in inserted text meaningless) |
1730 /* skip blank lines too */ | 1726 // skip blank lines too |
1731 if (oap->block_mode) | 1727 if (oap->block_mode) |
1732 { | 1728 { |
1733 /* Add spaces before getting the current line length. */ | 1729 // Add spaces before getting the current line length. |
1734 if (virtual_op && (curwin->w_cursor.coladd > 0 | 1730 if (virtual_op && (curwin->w_cursor.coladd > 0 |
1735 || gchar_cursor() == NUL)) | 1731 || gchar_cursor() == NUL)) |
1736 coladvance_force(getviscol()); | 1732 coladvance_force(getviscol()); |
1737 firstline = ml_get(oap->start.lnum); | 1733 firstline = ml_get(oap->start.lnum); |
1738 pre_textlen = (long)STRLEN(firstline); | 1734 pre_textlen = (long)STRLEN(firstline); |
1752 * block. | 1748 * block. |
1753 * Don't repeat the insert when Insert mode ended with CTRL-C. | 1749 * Don't repeat the insert when Insert mode ended with CTRL-C. |
1754 */ | 1750 */ |
1755 if (oap->block_mode && oap->start.lnum != oap->end.lnum && !got_int) | 1751 if (oap->block_mode && oap->start.lnum != oap->end.lnum && !got_int) |
1756 { | 1752 { |
1757 /* Auto-indenting may have changed the indent. If the cursor was past | 1753 // Auto-indenting may have changed the indent. If the cursor was past |
1758 * the indent, exclude that indent change from the inserted text. */ | 1754 // the indent, exclude that indent change from the inserted text. |
1759 firstline = ml_get(oap->start.lnum); | 1755 firstline = ml_get(oap->start.lnum); |
1760 if (bd.textcol > (colnr_T)pre_indent) | 1756 if (bd.textcol > (colnr_T)pre_indent) |
1761 { | 1757 { |
1762 long new_indent = (long)getwhitecols(firstline); | 1758 long new_indent = (long)getwhitecols(firstline); |
1763 | 1759 |
1766 } | 1762 } |
1767 | 1763 |
1768 ins_len = (long)STRLEN(firstline) - pre_textlen; | 1764 ins_len = (long)STRLEN(firstline) - pre_textlen; |
1769 if (ins_len > 0) | 1765 if (ins_len > 0) |
1770 { | 1766 { |
1771 /* Subsequent calls to ml_get() flush the firstline data - take a | 1767 // Subsequent calls to ml_get() flush the firstline data - take a |
1772 * copy of the inserted text. */ | 1768 // copy of the inserted text. |
1773 if ((ins_text = alloc(ins_len + 1)) != NULL) | 1769 if ((ins_text = alloc(ins_len + 1)) != NULL) |
1774 { | 1770 { |
1775 vim_strncpy(ins_text, firstline + bd.textcol, (size_t)ins_len); | 1771 vim_strncpy(ins_text, firstline + bd.textcol, (size_t)ins_len); |
1776 for (linenr = oap->start.lnum + 1; linenr <= oap->end.lnum; | 1772 for (linenr = oap->start.lnum + 1; linenr <= oap->end.lnum; |
1777 linenr++) | 1773 linenr++) |
1779 block_prep(oap, &bd, linenr, TRUE); | 1775 block_prep(oap, &bd, linenr, TRUE); |
1780 if (!bd.is_short || virtual_op) | 1776 if (!bd.is_short || virtual_op) |
1781 { | 1777 { |
1782 pos_T vpos; | 1778 pos_T vpos; |
1783 | 1779 |
1784 /* If the block starts in virtual space, count the | 1780 // If the block starts in virtual space, count the |
1785 * initial coladd offset as part of "startspaces" */ | 1781 // initial coladd offset as part of "startspaces" |
1786 if (bd.is_short) | 1782 if (bd.is_short) |
1787 { | 1783 { |
1788 vpos.lnum = linenr; | 1784 vpos.lnum = linenr; |
1789 (void)getvpos(&vpos, oap->start_vcol); | 1785 (void)getvpos(&vpos, oap->start_vcol); |
1790 } | 1786 } |
1792 vpos.coladd = 0; | 1788 vpos.coladd = 0; |
1793 oldp = ml_get(linenr); | 1789 oldp = ml_get(linenr); |
1794 newp = alloc(STRLEN(oldp) + vpos.coladd + ins_len + 1); | 1790 newp = alloc(STRLEN(oldp) + vpos.coladd + ins_len + 1); |
1795 if (newp == NULL) | 1791 if (newp == NULL) |
1796 continue; | 1792 continue; |
1797 /* copy up to block start */ | 1793 // copy up to block start |
1798 mch_memmove(newp, oldp, (size_t)bd.textcol); | 1794 mch_memmove(newp, oldp, (size_t)bd.textcol); |
1799 offset = bd.textcol; | 1795 offset = bd.textcol; |
1800 vim_memset(newp + offset, ' ', (size_t)vpos.coladd); | 1796 vim_memset(newp + offset, ' ', (size_t)vpos.coladd); |
1801 offset += vpos.coladd; | 1797 offset += vpos.coladd; |
1802 mch_memmove(newp + offset, ins_text, (size_t)ins_len); | 1798 mch_memmove(newp + offset, ins_text, (size_t)ins_len); |
1827 if (curwin->w_cursor.col > 0 | 1823 if (curwin->w_cursor.col > 0 |
1828 && gchar_cursor() == NUL | 1824 && gchar_cursor() == NUL |
1829 && (ve_flags & VE_ONEMORE) == 0 | 1825 && (ve_flags & VE_ONEMORE) == 0 |
1830 && !(restart_edit || (State & INSERT))) | 1826 && !(restart_edit || (State & INSERT))) |
1831 { | 1827 { |
1832 /* Put the cursor on the last character in the line. */ | 1828 // Put the cursor on the last character in the line. |
1833 dec_cursor(); | 1829 dec_cursor(); |
1834 | 1830 |
1835 if (ve_flags == VE_ALL) | 1831 if (ve_flags == VE_ALL) |
1836 { | 1832 { |
1837 colnr_T scol, ecol; | 1833 colnr_T scol, ecol; |
1838 | 1834 |
1839 /* Coladd is set to the width of the last character. */ | 1835 // Coladd is set to the width of the last character. |
1840 getvcol(curwin, &curwin->w_cursor, &scol, NULL, &ecol); | 1836 getvcol(curwin, &curwin->w_cursor, &scol, NULL, &ecol); |
1841 curwin->w_cursor.coladd = ecol - scol + 1; | 1837 curwin->w_cursor.coladd = ecol - scol + 1; |
1842 } | 1838 } |
1843 } | 1839 } |
1844 } | 1840 } |
1867 int leader_offset = get_last_leader_offset(line, &comment_flags); | 1863 int leader_offset = get_last_leader_offset(line, &comment_flags); |
1868 | 1864 |
1869 *is_comment = FALSE; | 1865 *is_comment = FALSE; |
1870 if (leader_offset != -1) | 1866 if (leader_offset != -1) |
1871 { | 1867 { |
1872 /* Let's check whether the line ends with an unclosed comment. | 1868 // Let's check whether the line ends with an unclosed comment. |
1873 * If the last comment leader has COM_END in flags, there's no comment. | 1869 // If the last comment leader has COM_END in flags, there's no comment. |
1874 */ | |
1875 while (*comment_flags) | 1870 while (*comment_flags) |
1876 { | 1871 { |
1877 if (*comment_flags == COM_END | 1872 if (*comment_flags == COM_END |
1878 || *comment_flags == ':') | 1873 || *comment_flags == ':') |
1879 break; | 1874 break; |
1889 lead_len = get_leader_len(line, &comment_flags, FALSE, include_space); | 1884 lead_len = get_leader_len(line, &comment_flags, FALSE, include_space); |
1890 | 1885 |
1891 if (lead_len == 0) | 1886 if (lead_len == 0) |
1892 return line; | 1887 return line; |
1893 | 1888 |
1894 /* Find: | 1889 // Find: |
1895 * - COM_END, | 1890 // - COM_END, |
1896 * - colon, | 1891 // - colon, |
1897 * whichever comes first. | 1892 // whichever comes first. |
1898 */ | |
1899 while (*comment_flags) | 1893 while (*comment_flags) |
1900 { | 1894 { |
1901 if (*comment_flags == COM_END | 1895 if (*comment_flags == COM_END |
1902 || *comment_flags == ':') | 1896 || *comment_flags == ':') |
1903 break; | 1897 break; |
1904 ++comment_flags; | 1898 ++comment_flags; |
1905 } | 1899 } |
1906 | 1900 |
1907 /* If we found a colon, it means that we are not processing a line | 1901 // If we found a colon, it means that we are not processing a line |
1908 * starting with a closing part of a three-part comment. That's good, | 1902 // starting with a closing part of a three-part comment. That's good, |
1909 * because we don't want to remove those as this would be annoying. | 1903 // because we don't want to remove those as this would be annoying. |
1910 */ | |
1911 if (*comment_flags == ':' || *comment_flags == NUL) | 1904 if (*comment_flags == ':' || *comment_flags == NUL) |
1912 line += lead_len; | 1905 line += lead_len; |
1913 | 1906 |
1914 return line; | 1907 return line; |
1915 } | 1908 } |
1934 { | 1927 { |
1935 char_u *curr = NULL; | 1928 char_u *curr = NULL; |
1936 char_u *curr_start = NULL; | 1929 char_u *curr_start = NULL; |
1937 char_u *cend; | 1930 char_u *cend; |
1938 char_u *newp; | 1931 char_u *newp; |
1939 char_u *spaces; /* number of spaces inserted before a line */ | 1932 char_u *spaces; // number of spaces inserted before a line |
1940 int endcurr1 = NUL; | 1933 int endcurr1 = NUL; |
1941 int endcurr2 = NUL; | 1934 int endcurr2 = NUL; |
1942 int currsize = 0; /* size of the current line */ | 1935 int currsize = 0; // size of the current line |
1943 int sumsize = 0; /* size of the long new line */ | 1936 int sumsize = 0; // size of the long new line |
1944 linenr_T t; | 1937 linenr_T t; |
1945 colnr_T col = 0; | 1938 colnr_T col = 0; |
1946 int ret = OK; | 1939 int ret = OK; |
1947 int *comments = NULL; | 1940 int *comments = NULL; |
1948 int remove_comments = (use_formatoptions == TRUE) | 1941 int remove_comments = (use_formatoptions == TRUE) |
1955 | 1948 |
1956 if (save_undo && u_save((linenr_T)(curwin->w_cursor.lnum - 1), | 1949 if (save_undo && u_save((linenr_T)(curwin->w_cursor.lnum - 1), |
1957 (linenr_T)(curwin->w_cursor.lnum + count)) == FAIL) | 1950 (linenr_T)(curwin->w_cursor.lnum + count)) == FAIL) |
1958 return FAIL; | 1951 return FAIL; |
1959 | 1952 |
1960 /* Allocate an array to store the number of spaces inserted before each | 1953 // Allocate an array to store the number of spaces inserted before each |
1961 * line. We will use it to pre-compute the length of the new line and the | 1954 // line. We will use it to pre-compute the length of the new line and the |
1962 * proper placement of each original line in the new one. */ | 1955 // proper placement of each original line in the new one. |
1963 spaces = lalloc_clear(count, TRUE); | 1956 spaces = lalloc_clear(count, TRUE); |
1964 if (spaces == NULL) | 1957 if (spaces == NULL) |
1965 return FAIL; | 1958 return FAIL; |
1966 if (remove_comments) | 1959 if (remove_comments) |
1967 { | 1960 { |
1981 for (t = 0; t < count; ++t) | 1974 for (t = 0; t < count; ++t) |
1982 { | 1975 { |
1983 curr = curr_start = ml_get((linenr_T)(curwin->w_cursor.lnum + t)); | 1976 curr = curr_start = ml_get((linenr_T)(curwin->w_cursor.lnum + t)); |
1984 if (t == 0 && setmark && !cmdmod.lockmarks) | 1977 if (t == 0 && setmark && !cmdmod.lockmarks) |
1985 { | 1978 { |
1986 /* Set the '[ mark. */ | 1979 // Set the '[ mark. |
1987 curwin->w_buffer->b_op_start.lnum = curwin->w_cursor.lnum; | 1980 curwin->w_buffer->b_op_start.lnum = curwin->w_cursor.lnum; |
1988 curwin->w_buffer->b_op_start.col = (colnr_T)STRLEN(curr); | 1981 curwin->w_buffer->b_op_start.col = (colnr_T)STRLEN(curr); |
1989 } | 1982 } |
1990 if (remove_comments) | 1983 if (remove_comments) |
1991 { | 1984 { |
1992 /* We don't want to remove the comment leader if the | 1985 // We don't want to remove the comment leader if the |
1993 * previous line is not a comment. */ | 1986 // previous line is not a comment. |
1994 if (t > 0 && prev_was_comment) | 1987 if (t > 0 && prev_was_comment) |
1995 { | 1988 { |
1996 | 1989 |
1997 char_u *new_curr = skip_comment(curr, TRUE, insert_space, | 1990 char_u *new_curr = skip_comment(curr, TRUE, insert_space, |
1998 &prev_was_comment); | 1991 &prev_was_comment); |
2013 || (mb_ptr2char(curr) < 0x100 && endcurr1 < 0x100)) | 2006 || (mb_ptr2char(curr) < 0x100 && endcurr1 < 0x100)) |
2014 && (!has_format_option(FO_MBYTE_JOIN2) | 2007 && (!has_format_option(FO_MBYTE_JOIN2) |
2015 || mb_ptr2char(curr) < 0x100 || endcurr1 < 0x100) | 2008 || mb_ptr2char(curr) < 0x100 || endcurr1 < 0x100) |
2016 ) | 2009 ) |
2017 { | 2010 { |
2018 /* don't add a space if the line is ending in a space */ | 2011 // don't add a space if the line is ending in a space |
2019 if (endcurr1 == ' ') | 2012 if (endcurr1 == ' ') |
2020 endcurr1 = endcurr2; | 2013 endcurr1 = endcurr2; |
2021 else | 2014 else |
2022 ++spaces[t]; | 2015 ++spaces[t]; |
2023 /* extra space when 'joinspaces' set and line ends in '.' */ | 2016 // extra space when 'joinspaces' set and line ends in '.' |
2024 if ( p_js | 2017 if ( p_js |
2025 && (endcurr1 == '.' | 2018 && (endcurr1 == '.' |
2026 || (vim_strchr(p_cpo, CPO_JOINSP) == NULL | 2019 || (vim_strchr(p_cpo, CPO_JOINSP) == NULL |
2027 && (endcurr1 == '?' || endcurr1 == '!')))) | 2020 && (endcurr1 == '?' || endcurr1 == '!')))) |
2028 ++spaces[t]; | 2021 ++spaces[t]; |
2057 ret = FAIL; | 2050 ret = FAIL; |
2058 goto theend; | 2051 goto theend; |
2059 } | 2052 } |
2060 } | 2053 } |
2061 | 2054 |
2062 /* store the column position before last line */ | 2055 // store the column position before last line |
2063 col = sumsize - currsize - spaces[count - 1]; | 2056 col = sumsize - currsize - spaces[count - 1]; |
2064 | 2057 |
2065 /* allocate the space for the new line */ | 2058 // allocate the space for the new line |
2066 newp = alloc(sumsize + 1); | 2059 newp = alloc(sumsize + 1); |
2067 if (newp == NULL) | 2060 if (newp == NULL) |
2068 { | 2061 { |
2069 ret = FAIL; | 2062 ret = FAIL; |
2070 goto theend; | 2063 goto theend; |
2137 #endif | 2130 #endif |
2138 ml_replace(curwin->w_cursor.lnum, newp, FALSE); | 2131 ml_replace(curwin->w_cursor.lnum, newp, FALSE); |
2139 | 2132 |
2140 if (setmark && !cmdmod.lockmarks) | 2133 if (setmark && !cmdmod.lockmarks) |
2141 { | 2134 { |
2142 /* Set the '] mark. */ | 2135 // Set the '] mark. |
2143 curwin->w_buffer->b_op_end.lnum = curwin->w_cursor.lnum; | 2136 curwin->w_buffer->b_op_end.lnum = curwin->w_cursor.lnum; |
2144 curwin->w_buffer->b_op_end.col = (colnr_T)sumsize; | 2137 curwin->w_buffer->b_op_end.col = (colnr_T)sumsize; |
2145 } | 2138 } |
2146 | 2139 |
2147 /* Only report the change in the first line here, del_lines() will report | 2140 // Only report the change in the first line here, del_lines() will report |
2148 * the deleted line. */ | 2141 // the deleted line. |
2149 changed_lines(curwin->w_cursor.lnum, currsize, | 2142 changed_lines(curwin->w_cursor.lnum, currsize, |
2150 curwin->w_cursor.lnum + 1, 0L); | 2143 curwin->w_cursor.lnum + 1, 0L); |
2151 /* | 2144 /* |
2152 * Delete following lines. To do this we move the cursor there | 2145 * Delete following lines. To do this we move the cursor there |
2153 * briefly, and then move it back. After del_lines() the cursor may | 2146 * briefly, and then move it back. After del_lines() the cursor may |
2257 * Implementation of the format operator 'gq'. | 2250 * Implementation of the format operator 'gq'. |
2258 */ | 2251 */ |
2259 static void | 2252 static void |
2260 op_format( | 2253 op_format( |
2261 oparg_T *oap, | 2254 oparg_T *oap, |
2262 int keep_cursor) /* keep cursor on same text char */ | 2255 int keep_cursor) // keep cursor on same text char |
2263 { | 2256 { |
2264 long old_line_count = curbuf->b_ml.ml_line_count; | 2257 long old_line_count = curbuf->b_ml.ml_line_count; |
2265 | 2258 |
2266 /* Place the cursor where the "gq" or "gw" command was given, so that "u" | 2259 // Place the cursor where the "gq" or "gw" command was given, so that "u" |
2267 * can put it back there. */ | 2260 // can put it back there. |
2268 curwin->w_cursor = oap->cursor_start; | 2261 curwin->w_cursor = oap->cursor_start; |
2269 | 2262 |
2270 if (u_save((linenr_T)(oap->start.lnum - 1), | 2263 if (u_save((linenr_T)(oap->start.lnum - 1), |
2271 (linenr_T)(oap->end.lnum + 1)) == FAIL) | 2264 (linenr_T)(oap->end.lnum + 1)) == FAIL) |
2272 return; | 2265 return; |
2273 curwin->w_cursor = oap->start; | 2266 curwin->w_cursor = oap->start; |
2274 | 2267 |
2275 if (oap->is_VIsual) | 2268 if (oap->is_VIsual) |
2276 /* When there is no change: need to remove the Visual selection */ | 2269 // When there is no change: need to remove the Visual selection |
2277 redraw_curbuf_later(INVERTED); | 2270 redraw_curbuf_later(INVERTED); |
2278 | 2271 |
2279 if (!cmdmod.lockmarks) | 2272 if (!cmdmod.lockmarks) |
2280 /* Set '[ mark at the start of the formatted area */ | 2273 // Set '[ mark at the start of the formatted area |
2281 curbuf->b_op_start = oap->start; | 2274 curbuf->b_op_start = oap->start; |
2282 | 2275 |
2283 /* For "gw" remember the cursor position and put it back below (adjusted | 2276 // For "gw" remember the cursor position and put it back below (adjusted |
2284 * for joined and split lines). */ | 2277 // for joined and split lines). |
2285 if (keep_cursor) | 2278 if (keep_cursor) |
2286 saved_cursor = oap->cursor_start; | 2279 saved_cursor = oap->cursor_start; |
2287 | 2280 |
2288 format_lines(oap->line_count, keep_cursor); | 2281 format_lines(oap->line_count, keep_cursor); |
2289 | 2282 |
2297 beginline(BL_WHITE | BL_FIX); | 2290 beginline(BL_WHITE | BL_FIX); |
2298 old_line_count = curbuf->b_ml.ml_line_count - old_line_count; | 2291 old_line_count = curbuf->b_ml.ml_line_count - old_line_count; |
2299 msgmore(old_line_count); | 2292 msgmore(old_line_count); |
2300 | 2293 |
2301 if (!cmdmod.lockmarks) | 2294 if (!cmdmod.lockmarks) |
2302 /* put '] mark on the end of the formatted area */ | 2295 // put '] mark on the end of the formatted area |
2303 curbuf->b_op_end = curwin->w_cursor; | 2296 curbuf->b_op_end = curwin->w_cursor; |
2304 | 2297 |
2305 if (keep_cursor) | 2298 if (keep_cursor) |
2306 { | 2299 { |
2307 curwin->w_cursor = saved_cursor; | 2300 curwin->w_cursor = saved_cursor; |
2314 | 2307 |
2315 FOR_ALL_WINDOWS(wp) | 2308 FOR_ALL_WINDOWS(wp) |
2316 { | 2309 { |
2317 if (wp->w_old_cursor_lnum != 0) | 2310 if (wp->w_old_cursor_lnum != 0) |
2318 { | 2311 { |
2319 /* When lines have been inserted or deleted, adjust the end of | 2312 // When lines have been inserted or deleted, adjust the end of |
2320 * the Visual area to be redrawn. */ | 2313 // the Visual area to be redrawn. |
2321 if (wp->w_old_cursor_lnum > wp->w_old_visual_lnum) | 2314 if (wp->w_old_cursor_lnum > wp->w_old_visual_lnum) |
2322 wp->w_old_cursor_lnum += old_line_count; | 2315 wp->w_old_cursor_lnum += old_line_count; |
2323 else | 2316 else |
2324 wp->w_old_visual_lnum += old_line_count; | 2317 wp->w_old_visual_lnum += old_line_count; |
2325 } | 2318 } |
2333 */ | 2326 */ |
2334 static void | 2327 static void |
2335 op_formatexpr(oparg_T *oap) | 2328 op_formatexpr(oparg_T *oap) |
2336 { | 2329 { |
2337 if (oap->is_VIsual) | 2330 if (oap->is_VIsual) |
2338 /* When there is no change: need to remove the Visual selection */ | 2331 // When there is no change: need to remove the Visual selection |
2339 redraw_curbuf_later(INVERTED); | 2332 redraw_curbuf_later(INVERTED); |
2340 | 2333 |
2341 if (fex_format(oap->start.lnum, oap->line_count, NUL) != 0) | 2334 if (fex_format(oap->start.lnum, oap->line_count, NUL) != 0) |
2342 /* As documented: when 'formatexpr' returns non-zero fall back to | 2335 // As documented: when 'formatexpr' returns non-zero fall back to |
2343 * internal formatting. */ | 2336 // internal formatting. |
2344 op_format(oap, FALSE); | 2337 op_format(oap, FALSE); |
2345 } | 2338 } |
2346 | 2339 |
2347 int | 2340 int |
2348 fex_format( | 2341 fex_format( |
2349 linenr_T lnum, | 2342 linenr_T lnum, |
2350 long count, | 2343 long count, |
2351 int c) /* character to be inserted */ | 2344 int c) // character to be inserted |
2352 { | 2345 { |
2353 int use_sandbox = was_set_insecurely((char_u *)"formatexpr", | 2346 int use_sandbox = was_set_insecurely((char_u *)"formatexpr", |
2354 OPT_LOCAL); | 2347 OPT_LOCAL); |
2355 int r; | 2348 int r; |
2356 char_u *fex; | 2349 char_u *fex; |
2361 */ | 2354 */ |
2362 set_vim_var_nr(VV_LNUM, lnum); | 2355 set_vim_var_nr(VV_LNUM, lnum); |
2363 set_vim_var_nr(VV_COUNT, count); | 2356 set_vim_var_nr(VV_COUNT, count); |
2364 set_vim_var_char(c); | 2357 set_vim_var_char(c); |
2365 | 2358 |
2366 /* Make a copy, the option could be changed while calling it. */ | 2359 // Make a copy, the option could be changed while calling it. |
2367 fex = vim_strsave(curbuf->b_p_fex); | 2360 fex = vim_strsave(curbuf->b_p_fex); |
2368 if (fex == NULL) | 2361 if (fex == NULL) |
2369 return 0; | 2362 return 0; |
2370 | 2363 |
2371 /* | 2364 /* |
2391 * first line. | 2384 * first line. |
2392 */ | 2385 */ |
2393 void | 2386 void |
2394 format_lines( | 2387 format_lines( |
2395 linenr_T line_count, | 2388 linenr_T line_count, |
2396 int avoid_fex) /* don't use 'formatexpr' */ | 2389 int avoid_fex) // don't use 'formatexpr' |
2397 { | 2390 { |
2398 int max_len; | 2391 int max_len; |
2399 int is_not_par; /* current line not part of parag. */ | 2392 int is_not_par; // current line not part of parag. |
2400 int next_is_not_par; /* next line not part of paragraph */ | 2393 int next_is_not_par; // next line not part of paragraph |
2401 int is_end_par; /* at end of paragraph */ | 2394 int is_end_par; // at end of paragraph |
2402 int prev_is_end_par = FALSE;/* prev. line not part of parag. */ | 2395 int prev_is_end_par = FALSE;// prev. line not part of parag. |
2403 int next_is_start_par = FALSE; | 2396 int next_is_start_par = FALSE; |
2404 int leader_len = 0; /* leader len of current line */ | 2397 int leader_len = 0; // leader len of current line |
2405 int next_leader_len; /* leader len of next line */ | 2398 int next_leader_len; // leader len of next line |
2406 char_u *leader_flags = NULL; /* flags for leader of current line */ | 2399 char_u *leader_flags = NULL; // flags for leader of current line |
2407 char_u *next_leader_flags; /* flags for leader of next line */ | 2400 char_u *next_leader_flags; // flags for leader of next line |
2408 int do_comments; /* format comments */ | 2401 int do_comments; // format comments |
2409 int do_comments_list = 0; /* format comments with 'n' or '2' */ | 2402 int do_comments_list = 0; // format comments with 'n' or '2' |
2410 int advance = TRUE; | 2403 int advance = TRUE; |
2411 int second_indent = -1; /* indent for second line (comment | 2404 int second_indent = -1; // indent for second line (comment |
2412 * aware) */ | 2405 // aware) |
2413 int do_second_indent; | 2406 int do_second_indent; |
2414 int do_number_indent; | 2407 int do_number_indent; |
2415 int do_trail_white; | 2408 int do_trail_white; |
2416 int first_par_line = TRUE; | 2409 int first_par_line = TRUE; |
2417 int smd_save; | 2410 int smd_save; |
2418 long count; | 2411 long count; |
2419 int need_set_indent = TRUE; /* set indent of next paragraph */ | 2412 int need_set_indent = TRUE; // set indent of next paragraph |
2420 int force_format = FALSE; | 2413 int force_format = FALSE; |
2421 int old_State = State; | 2414 int old_State = State; |
2422 | 2415 |
2423 /* length of a line to force formatting: 3 * 'tw' */ | 2416 // length of a line to force formatting: 3 * 'tw' |
2424 max_len = comp_textwidth(TRUE) * 3; | 2417 max_len = comp_textwidth(TRUE) * 3; |
2425 | 2418 |
2426 /* check for 'q', '2' and '1' in 'formatoptions' */ | 2419 // check for 'q', '2' and '1' in 'formatoptions' |
2427 do_comments = has_format_option(FO_Q_COMS); | 2420 do_comments = has_format_option(FO_Q_COMS); |
2428 do_second_indent = has_format_option(FO_Q_SECOND); | 2421 do_second_indent = has_format_option(FO_Q_SECOND); |
2429 do_number_indent = has_format_option(FO_Q_NUMBER); | 2422 do_number_indent = has_format_option(FO_Q_NUMBER); |
2430 do_trail_white = has_format_option(FO_WHITE_PAR); | 2423 do_trail_white = has_format_option(FO_WHITE_PAR); |
2431 | 2424 |
2501 { | 2494 { |
2502 if (do_second_indent && !LINEEMPTY(curwin->w_cursor.lnum + 1)) | 2495 if (do_second_indent && !LINEEMPTY(curwin->w_cursor.lnum + 1)) |
2503 { | 2496 { |
2504 if (leader_len == 0 && next_leader_len == 0) | 2497 if (leader_len == 0 && next_leader_len == 0) |
2505 { | 2498 { |
2506 /* no comment found */ | 2499 // no comment found |
2507 second_indent = | 2500 second_indent = |
2508 get_indent_lnum(curwin->w_cursor.lnum + 1); | 2501 get_indent_lnum(curwin->w_cursor.lnum + 1); |
2509 } | 2502 } |
2510 else | 2503 else |
2511 { | 2504 { |
2515 } | 2508 } |
2516 else if (do_number_indent) | 2509 else if (do_number_indent) |
2517 { | 2510 { |
2518 if (leader_len == 0 && next_leader_len == 0) | 2511 if (leader_len == 0 && next_leader_len == 0) |
2519 { | 2512 { |
2520 /* no comment found */ | 2513 // no comment found |
2521 second_indent = | 2514 second_indent = |
2522 get_number_indent(curwin->w_cursor.lnum); | 2515 get_number_indent(curwin->w_cursor.lnum); |
2523 } | 2516 } |
2524 else | 2517 else |
2525 { | 2518 { |
2526 /* get_number_indent() is now "comment aware"... */ | 2519 // get_number_indent() is now "comment aware"... |
2527 second_indent = | 2520 second_indent = |
2528 get_number_indent(curwin->w_cursor.lnum); | 2521 get_number_indent(curwin->w_cursor.lnum); |
2529 do_comments_list = 1; | 2522 do_comments_list = 1; |
2530 } | 2523 } |
2531 } | 2524 } |
2545 * getting long, format it. | 2538 * getting long, format it. |
2546 */ | 2539 */ |
2547 if (is_end_par || force_format) | 2540 if (is_end_par || force_format) |
2548 { | 2541 { |
2549 if (need_set_indent) | 2542 if (need_set_indent) |
2550 /* replace indent in first line with minimal number of | 2543 // replace indent in first line with minimal number of |
2551 * tabs and spaces, according to current options */ | 2544 // tabs and spaces, according to current options |
2552 (void)set_indent(get_indent(), SIN_CHANGED); | 2545 (void)set_indent(get_indent(), SIN_CHANGED); |
2553 | 2546 |
2554 /* put cursor on last non-space */ | 2547 // put cursor on last non-space |
2555 State = NORMAL; /* don't go past end-of-line */ | 2548 State = NORMAL; // don't go past end-of-line |
2556 coladvance((colnr_T)MAXCOL); | 2549 coladvance((colnr_T)MAXCOL); |
2557 while (curwin->w_cursor.col && vim_isspace(gchar_cursor())) | 2550 while (curwin->w_cursor.col && vim_isspace(gchar_cursor())) |
2558 dec_cursor(); | 2551 dec_cursor(); |
2559 | 2552 |
2560 /* do the formatting, without 'showmode' */ | 2553 // do the formatting, without 'showmode' |
2561 State = INSERT; /* for open_line() */ | 2554 State = INSERT; // for open_line() |
2562 smd_save = p_smd; | 2555 smd_save = p_smd; |
2563 p_smd = FALSE; | 2556 p_smd = FALSE; |
2564 insertchar(NUL, INSCHAR_FORMAT | 2557 insertchar(NUL, INSCHAR_FORMAT |
2565 + (do_comments ? INSCHAR_DO_COM : 0) | 2558 + (do_comments ? INSCHAR_DO_COM : 0) |
2566 + (do_comments && do_comments_list | 2559 + (do_comments && do_comments_list |
2567 ? INSCHAR_COM_LIST : 0) | 2560 ? INSCHAR_COM_LIST : 0) |
2568 + (avoid_fex ? INSCHAR_NO_FEX : 0), second_indent); | 2561 + (avoid_fex ? INSCHAR_NO_FEX : 0), second_indent); |
2569 State = old_State; | 2562 State = old_State; |
2570 p_smd = smd_save; | 2563 p_smd = smd_save; |
2571 second_indent = -1; | 2564 second_indent = -1; |
2572 /* at end of par.: need to set indent of next par. */ | 2565 // at end of par.: need to set indent of next par. |
2573 need_set_indent = is_end_par; | 2566 need_set_indent = is_end_par; |
2574 if (is_end_par) | 2567 if (is_end_par) |
2575 { | 2568 { |
2576 /* When called with a negative line count, break at the | 2569 // When called with a negative line count, break at the |
2577 * end of the paragraph. */ | 2570 // end of the paragraph. |
2578 if (line_count < 0) | 2571 if (line_count < 0) |
2579 break; | 2572 break; |
2580 first_par_line = TRUE; | 2573 first_par_line = TRUE; |
2581 } | 2574 } |
2582 force_format = FALSE; | 2575 force_format = FALSE; |
2615 { | 2608 { |
2616 beep_flush(); | 2609 beep_flush(); |
2617 break; | 2610 break; |
2618 } | 2611 } |
2619 first_par_line = FALSE; | 2612 first_par_line = FALSE; |
2620 /* If the line is getting long, format it next time */ | 2613 // If the line is getting long, format it next time |
2621 if (STRLEN(ml_get_curline()) > (size_t)max_len) | 2614 if (STRLEN(ml_get_curline()) > (size_t)max_len) |
2622 force_format = TRUE; | 2615 force_format = TRUE; |
2623 else | 2616 else |
2624 force_format = FALSE; | 2617 force_format = FALSE; |
2625 } | 2618 } |
2637 char_u *s = ml_get(lnum); | 2630 char_u *s = ml_get(lnum); |
2638 size_t l; | 2631 size_t l; |
2639 | 2632 |
2640 if (*s == NUL) | 2633 if (*s == NUL) |
2641 return FALSE; | 2634 return FALSE; |
2642 /* Don't use STRLEN() inside VIM_ISWHITE(), SAS/C complains: "macro | 2635 // Don't use STRLEN() inside VIM_ISWHITE(), SAS/C complains: "macro |
2643 * invocation may call function multiple times". */ | 2636 // invocation may call function multiple times". |
2644 l = STRLEN(s) - 1; | 2637 l = STRLEN(s) - 1; |
2645 return VIM_ISWHITE(s[l]); | 2638 return VIM_ISWHITE(s[l]); |
2646 } | 2639 } |
2647 | 2640 |
2648 /* | 2641 /* |
2658 linenr_T lnum, | 2651 linenr_T lnum, |
2659 int *leader_len, | 2652 int *leader_len, |
2660 char_u **leader_flags, | 2653 char_u **leader_flags, |
2661 int do_comments) | 2654 int do_comments) |
2662 { | 2655 { |
2663 char_u *flags = NULL; /* init for GCC */ | 2656 char_u *flags = NULL; // init for GCC |
2664 char_u *ptr; | 2657 char_u *ptr; |
2665 | 2658 |
2666 ptr = ml_get(lnum); | 2659 ptr = ml_get(lnum); |
2667 if (do_comments) | 2660 if (do_comments) |
2668 *leader_len = get_leader_len(ptr, leader_flags, FALSE, TRUE); | 2661 *leader_len = get_leader_len(ptr, leader_flags, FALSE, TRUE); |
2690 */ | 2683 */ |
2691 int | 2684 int |
2692 paragraph_start(linenr_T lnum) | 2685 paragraph_start(linenr_T lnum) |
2693 { | 2686 { |
2694 char_u *p; | 2687 char_u *p; |
2695 int leader_len = 0; /* leader len of current line */ | 2688 int leader_len = 0; // leader len of current line |
2696 char_u *leader_flags = NULL; /* flags for leader of current line */ | 2689 char_u *leader_flags = NULL; // flags for leader of current line |
2697 int next_leader_len; /* leader len of next line */ | 2690 int next_leader_len; // leader len of next line |
2698 char_u *next_leader_flags; /* flags for leader of next line */ | 2691 char_u *next_leader_flags; // flags for leader of next line |
2699 int do_comments; /* format comments */ | 2692 int do_comments; // format comments |
2700 | 2693 |
2701 if (lnum <= 1) | 2694 if (lnum <= 1) |
2702 return TRUE; /* start of the file */ | 2695 return TRUE; // start of the file |
2703 | 2696 |
2704 p = ml_get(lnum - 1); | 2697 p = ml_get(lnum - 1); |
2705 if (*p == NUL) | 2698 if (*p == NUL) |
2706 return TRUE; /* after empty line */ | 2699 return TRUE; // after empty line |
2707 | 2700 |
2708 do_comments = has_format_option(FO_Q_COMS); | 2701 do_comments = has_format_option(FO_Q_COMS); |
2709 if (fmt_check_par(lnum - 1, &leader_len, &leader_flags, do_comments)) | 2702 if (fmt_check_par(lnum - 1, &leader_len, &leader_flags, do_comments)) |
2710 return TRUE; /* after non-paragraph line */ | 2703 return TRUE; // after non-paragraph line |
2711 | 2704 |
2712 if (fmt_check_par(lnum, &next_leader_len, &next_leader_flags, do_comments)) | 2705 if (fmt_check_par(lnum, &next_leader_len, &next_leader_flags, do_comments)) |
2713 return TRUE; /* "lnum" is not a paragraph line */ | 2706 return TRUE; // "lnum" is not a paragraph line |
2714 | 2707 |
2715 if (has_format_option(FO_WHITE_PAR) && !ends_in_white(lnum - 1)) | 2708 if (has_format_option(FO_WHITE_PAR) && !ends_in_white(lnum - 1)) |
2716 return TRUE; /* missing trailing space in previous line. */ | 2709 return TRUE; // missing trailing space in previous line. |
2717 | 2710 |
2718 if (has_format_option(FO_Q_NUMBER) && (get_number_indent(lnum) > 0)) | 2711 if (has_format_option(FO_Q_NUMBER) && (get_number_indent(lnum) > 0)) |
2719 return TRUE; /* numbered item starts in "lnum". */ | 2712 return TRUE; // numbered item starts in "lnum". |
2720 | 2713 |
2721 if (!same_leader(lnum - 1, leader_len, leader_flags, | 2714 if (!same_leader(lnum - 1, leader_len, leader_flags, |
2722 next_leader_len, next_leader_flags)) | 2715 next_leader_len, next_leader_flags)) |
2723 return TRUE; /* change of comment leader. */ | 2716 return TRUE; // change of comment leader. |
2724 | 2717 |
2725 return FALSE; | 2718 return FALSE; |
2726 } | 2719 } |
2727 | 2720 |
2728 /* | 2721 /* |
2767 line = ml_get(lnum); | 2760 line = ml_get(lnum); |
2768 pstart = line; | 2761 pstart = line; |
2769 prev_pstart = line; | 2762 prev_pstart = line; |
2770 while (bdp->start_vcol < oap->start_vcol && *pstart) | 2763 while (bdp->start_vcol < oap->start_vcol && *pstart) |
2771 { | 2764 { |
2772 /* Count a tab for what it's worth (if list mode not on) */ | 2765 // Count a tab for what it's worth (if list mode not on) |
2773 incr = lbr_chartabsize(line, pstart, (colnr_T)bdp->start_vcol); | 2766 incr = lbr_chartabsize(line, pstart, (colnr_T)bdp->start_vcol); |
2774 bdp->start_vcol += incr; | 2767 bdp->start_vcol += incr; |
2775 if (VIM_ISWHITE(*pstart)) | 2768 if (VIM_ISWHITE(*pstart)) |
2776 { | 2769 { |
2777 bdp->pre_whitesp += incr; | 2770 bdp->pre_whitesp += incr; |
2784 } | 2777 } |
2785 prev_pstart = pstart; | 2778 prev_pstart = pstart; |
2786 MB_PTR_ADV(pstart); | 2779 MB_PTR_ADV(pstart); |
2787 } | 2780 } |
2788 bdp->start_char_vcols = incr; | 2781 bdp->start_char_vcols = incr; |
2789 if (bdp->start_vcol < oap->start_vcol) /* line too short */ | 2782 if (bdp->start_vcol < oap->start_vcol) // line too short |
2790 { | 2783 { |
2791 bdp->end_vcol = bdp->start_vcol; | 2784 bdp->end_vcol = bdp->start_vcol; |
2792 bdp->is_short = TRUE; | 2785 bdp->is_short = TRUE; |
2793 if (!is_del || oap->op_type == OP_APPEND) | 2786 if (!is_del || oap->op_type == OP_APPEND) |
2794 bdp->endspaces = oap->end_vcol - oap->start_vcol + 1; | 2787 bdp->endspaces = oap->end_vcol - oap->start_vcol + 1; |
2795 } | 2788 } |
2796 else | 2789 else |
2797 { | 2790 { |
2798 /* notice: this converts partly selected Multibyte characters to | 2791 // notice: this converts partly selected Multibyte characters to |
2799 * spaces, too. */ | 2792 // spaces, too. |
2800 bdp->startspaces = bdp->start_vcol - oap->start_vcol; | 2793 bdp->startspaces = bdp->start_vcol - oap->start_vcol; |
2801 if (is_del && bdp->startspaces) | 2794 if (is_del && bdp->startspaces) |
2802 bdp->startspaces = bdp->start_char_vcols - bdp->startspaces; | 2795 bdp->startspaces = bdp->start_char_vcols - bdp->startspaces; |
2803 pend = pstart; | 2796 pend = pstart; |
2804 bdp->end_vcol = bdp->start_vcol; | 2797 bdp->end_vcol = bdp->start_vcol; |
2805 if (bdp->end_vcol > oap->end_vcol) /* it's all in one character */ | 2798 if (bdp->end_vcol > oap->end_vcol) // it's all in one character |
2806 { | 2799 { |
2807 bdp->is_oneChar = TRUE; | 2800 bdp->is_oneChar = TRUE; |
2808 if (oap->op_type == OP_INSERT) | 2801 if (oap->op_type == OP_INSERT) |
2809 bdp->endspaces = bdp->start_char_vcols - bdp->startspaces; | 2802 bdp->endspaces = bdp->start_char_vcols - bdp->startspaces; |
2810 else if (oap->op_type == OP_APPEND) | 2803 else if (oap->op_type == OP_APPEND) |
2815 else | 2808 else |
2816 { | 2809 { |
2817 bdp->startspaces = oap->end_vcol - oap->start_vcol + 1; | 2810 bdp->startspaces = oap->end_vcol - oap->start_vcol + 1; |
2818 if (is_del && oap->op_type != OP_LSHIFT) | 2811 if (is_del && oap->op_type != OP_LSHIFT) |
2819 { | 2812 { |
2820 /* just putting the sum of those two into | 2813 // just putting the sum of those two into |
2821 * bdp->startspaces doesn't work for Visual replace, | 2814 // bdp->startspaces doesn't work for Visual replace, |
2822 * so we have to split the tab in two */ | 2815 // so we have to split the tab in two |
2823 bdp->startspaces = bdp->start_char_vcols | 2816 bdp->startspaces = bdp->start_char_vcols |
2824 - (bdp->start_vcol - oap->start_vcol); | 2817 - (bdp->start_vcol - oap->start_vcol); |
2825 bdp->endspaces = bdp->end_vcol - oap->end_vcol - 1; | 2818 bdp->endspaces = bdp->end_vcol - oap->end_vcol - 1; |
2826 } | 2819 } |
2827 } | 2820 } |
2829 else | 2822 else |
2830 { | 2823 { |
2831 prev_pend = pend; | 2824 prev_pend = pend; |
2832 while (bdp->end_vcol <= oap->end_vcol && *pend != NUL) | 2825 while (bdp->end_vcol <= oap->end_vcol && *pend != NUL) |
2833 { | 2826 { |
2834 /* Count a tab for what it's worth (if list mode not on) */ | 2827 // Count a tab for what it's worth (if list mode not on) |
2835 prev_pend = pend; | 2828 prev_pend = pend; |
2836 incr = lbr_chartabsize_adv(line, &pend, (colnr_T)bdp->end_vcol); | 2829 incr = lbr_chartabsize_adv(line, &pend, (colnr_T)bdp->end_vcol); |
2837 bdp->end_vcol += incr; | 2830 bdp->end_vcol += incr; |
2838 } | 2831 } |
2839 if (bdp->end_vcol <= oap->end_vcol | 2832 if (bdp->end_vcol <= oap->end_vcol |
2840 && (!is_del | 2833 && (!is_del |
2841 || oap->op_type == OP_APPEND | 2834 || oap->op_type == OP_APPEND |
2842 || oap->op_type == OP_REPLACE)) /* line too short */ | 2835 || oap->op_type == OP_REPLACE)) // line too short |
2843 { | 2836 { |
2844 bdp->is_short = TRUE; | 2837 bdp->is_short = TRUE; |
2845 /* Alternative: include spaces to fill up the block. | 2838 // Alternative: include spaces to fill up the block. |
2846 * Disadvantage: can lead to trailing spaces when the line is | 2839 // Disadvantage: can lead to trailing spaces when the line is |
2847 * short where the text is put */ | 2840 // short where the text is put |
2848 /* if (!is_del || oap->op_type == OP_APPEND) */ | 2841 // if (!is_del || oap->op_type == OP_APPEND) |
2849 if (oap->op_type == OP_APPEND || virtual_op) | 2842 if (oap->op_type == OP_APPEND || virtual_op) |
2850 bdp->endspaces = oap->end_vcol - bdp->end_vcol | 2843 bdp->endspaces = oap->end_vcol - bdp->end_vcol |
2851 + oap->inclusive; | 2844 + oap->inclusive; |
2852 else | 2845 else |
2853 bdp->endspaces = 0; /* replace doesn't add characters */ | 2846 bdp->endspaces = 0; // replace doesn't add characters |
2854 } | 2847 } |
2855 else if (bdp->end_vcol > oap->end_vcol) | 2848 else if (bdp->end_vcol > oap->end_vcol) |
2856 { | 2849 { |
2857 bdp->endspaces = bdp->end_vcol - oap->end_vcol - 1; | 2850 bdp->endspaces = bdp->end_vcol - oap->end_vcol - 1; |
2858 if (!is_del && bdp->endspaces) | 2851 if (!is_del && bdp->endspaces) |
2876 * Handle the add/subtract operator. | 2869 * Handle the add/subtract operator. |
2877 */ | 2870 */ |
2878 void | 2871 void |
2879 op_addsub( | 2872 op_addsub( |
2880 oparg_T *oap, | 2873 oparg_T *oap, |
2881 linenr_T Prenum1, /* Amount of add/subtract */ | 2874 linenr_T Prenum1, // Amount of add/subtract |
2882 int g_cmd) /* was g<c-a>/g<c-x> */ | 2875 int g_cmd) // was g<c-a>/g<c-x> |
2883 { | 2876 { |
2884 pos_T pos; | 2877 pos_T pos; |
2885 struct block_def bd; | 2878 struct block_def bd; |
2886 int change_cnt = 0; | 2879 int change_cnt = 0; |
2887 linenr_T amount = Prenum1; | 2880 linenr_T amount = Prenum1; |
2926 } | 2919 } |
2927 | 2920 |
2928 pos = oap->start; | 2921 pos = oap->start; |
2929 for (; pos.lnum <= oap->end.lnum; ++pos.lnum) | 2922 for (; pos.lnum <= oap->end.lnum; ++pos.lnum) |
2930 { | 2923 { |
2931 if (oap->block_mode) /* Visual block mode */ | 2924 if (oap->block_mode) // Visual block mode |
2932 { | 2925 { |
2933 block_prep(oap, &bd, pos.lnum, FALSE); | 2926 block_prep(oap, &bd, pos.lnum, FALSE); |
2934 pos.col = bd.textcol; | 2927 pos.col = bd.textcol; |
2935 length = bd.textlen; | 2928 length = bd.textlen; |
2936 } | 2929 } |
2938 { | 2931 { |
2939 curwin->w_cursor.col = 0; | 2932 curwin->w_cursor.col = 0; |
2940 pos.col = 0; | 2933 pos.col = 0; |
2941 length = (colnr_T)STRLEN(ml_get(pos.lnum)); | 2934 length = (colnr_T)STRLEN(ml_get(pos.lnum)); |
2942 } | 2935 } |
2943 else /* oap->motion_type == MCHAR */ | 2936 else // oap->motion_type == MCHAR |
2944 { | 2937 { |
2945 if (pos.lnum == oap->start.lnum && !oap->inclusive) | 2938 if (pos.lnum == oap->start.lnum && !oap->inclusive) |
2946 dec(&(oap->end)); | 2939 dec(&(oap->end)); |
2947 length = (colnr_T)STRLEN(ml_get(pos.lnum)); | 2940 length = (colnr_T)STRLEN(ml_get(pos.lnum)); |
2948 pos.col = 0; | 2941 pos.col = 0; |
2960 } | 2953 } |
2961 } | 2954 } |
2962 one_change = do_addsub(oap->op_type, &pos, length, amount); | 2955 one_change = do_addsub(oap->op_type, &pos, length, amount); |
2963 if (one_change) | 2956 if (one_change) |
2964 { | 2957 { |
2965 /* Remember the start position of the first change. */ | 2958 // Remember the start position of the first change. |
2966 if (change_cnt == 0) | 2959 if (change_cnt == 0) |
2967 startpos = curbuf->b_op_start; | 2960 startpos = curbuf->b_op_start; |
2968 ++change_cnt; | 2961 ++change_cnt; |
2969 } | 2962 } |
2970 | 2963 |
2987 #endif | 2980 #endif |
2988 if (change_cnt) | 2981 if (change_cnt) |
2989 changed_lines(oap->start.lnum, 0, oap->end.lnum + 1, 0L); | 2982 changed_lines(oap->start.lnum, 0, oap->end.lnum + 1, 0L); |
2990 | 2983 |
2991 if (!change_cnt && oap->is_VIsual) | 2984 if (!change_cnt && oap->is_VIsual) |
2992 /* No change: need to remove the Visual selection */ | 2985 // No change: need to remove the Visual selection |
2993 redraw_curbuf_later(INVERTED); | 2986 redraw_curbuf_later(INVERTED); |
2994 | 2987 |
2995 /* Set '[ mark if something changed. Keep the last end | 2988 // Set '[ mark if something changed. Keep the last end |
2996 * position from do_addsub(). */ | 2989 // position from do_addsub(). |
2997 if (change_cnt > 0 && !cmdmod.lockmarks) | 2990 if (change_cnt > 0 && !cmdmod.lockmarks) |
2998 curbuf->b_op_start = startpos; | 2991 curbuf->b_op_start = startpos; |
2999 | 2992 |
3000 if (change_cnt > p_report) | 2993 if (change_cnt > p_report) |
3001 smsg(NGETTEXT("%ld line changed", "%ld lines changed", | 2994 smsg(NGETTEXT("%ld line changed", "%ld lines changed", |
3017 linenr_T Prenum1) | 3010 linenr_T Prenum1) |
3018 { | 3011 { |
3019 int col; | 3012 int col; |
3020 char_u *buf1; | 3013 char_u *buf1; |
3021 char_u buf2[NUMBUFLEN]; | 3014 char_u buf2[NUMBUFLEN]; |
3022 int pre; /* 'X'/'x': hex; '0': octal; 'B'/'b': bin */ | 3015 int pre; // 'X'/'x': hex; '0': octal; 'B'/'b': bin |
3023 static int hexupper = FALSE; /* 0xABC */ | 3016 static int hexupper = FALSE; // 0xABC |
3024 uvarnumber_T n; | 3017 uvarnumber_T n; |
3025 uvarnumber_T oldn; | 3018 uvarnumber_T oldn; |
3026 char_u *ptr; | 3019 char_u *ptr; |
3027 int c; | 3020 int c; |
3028 int todel; | 3021 int todel; |
3083 && (!has_mbyte || | 3076 && (!has_mbyte || |
3084 !(*mb_head_off)(ptr, ptr + col - 1)) | 3077 !(*mb_head_off)(ptr, ptr + col - 1)) |
3085 && vim_isxdigit(ptr[col + 1])))) | 3078 && vim_isxdigit(ptr[col + 1])))) |
3086 { | 3079 { |
3087 | 3080 |
3088 /* In case of binary/hexadecimal pattern overlap match, rescan */ | 3081 // In case of binary/hexadecimal pattern overlap match, rescan |
3089 | 3082 |
3090 col = pos->col; | 3083 col = pos->col; |
3091 | 3084 |
3092 while (col > 0 && vim_isdigit(ptr[col])) | 3085 while (col > 0 && vim_isdigit(ptr[col])) |
3093 { | 3086 { |
3112 && ptr[col - 1] == '0' | 3105 && ptr[col - 1] == '0' |
3113 && (!has_mbyte || | 3106 && (!has_mbyte || |
3114 !(*mb_head_off)(ptr, ptr + col - 1)) | 3107 !(*mb_head_off)(ptr, ptr + col - 1)) |
3115 && vim_isbdigit(ptr[col + 1]))) | 3108 && vim_isbdigit(ptr[col + 1]))) |
3116 { | 3109 { |
3117 /* Found hexadecimal or binary number, move to its start. */ | 3110 // Found hexadecimal or binary number, move to its start. |
3118 --col; | 3111 --col; |
3119 if (has_mbyte) | 3112 if (has_mbyte) |
3120 col -= (*mb_head_off)(ptr, ptr + col); | 3113 col -= (*mb_head_off)(ptr, ptr + col); |
3121 } | 3114 } |
3122 else | 3115 else |
3175 goto theend; | 3168 goto theend; |
3176 } | 3169 } |
3177 | 3170 |
3178 if (doalp && ASCII_ISALPHA(firstdigit)) | 3171 if (doalp && ASCII_ISALPHA(firstdigit)) |
3179 { | 3172 { |
3180 /* decrement or increment alphabetic character */ | 3173 // decrement or increment alphabetic character |
3181 if (op_type == OP_NR_SUB) | 3174 if (op_type == OP_NR_SUB) |
3182 { | 3175 { |
3183 if (CharOrd(firstdigit) < Prenum1) | 3176 if (CharOrd(firstdigit) < Prenum1) |
3184 { | 3177 { |
3185 if (isupper(firstdigit)) | 3178 if (isupper(firstdigit)) |
3224 if (col > 0 && ptr[col - 1] == '-' | 3217 if (col > 0 && ptr[col - 1] == '-' |
3225 && (!has_mbyte || | 3218 && (!has_mbyte || |
3226 !(*mb_head_off)(ptr, ptr + col - 1)) | 3219 !(*mb_head_off)(ptr, ptr + col - 1)) |
3227 && !visual) | 3220 && !visual) |
3228 { | 3221 { |
3229 /* negative number */ | 3222 // negative number |
3230 --col; | 3223 --col; |
3231 negative = TRUE; | 3224 negative = TRUE; |
3232 } | 3225 } |
3233 /* get the number value (unsigned) */ | 3226 // get the number value (unsigned) |
3234 if (visual && VIsual_mode != 'V') | 3227 if (visual && VIsual_mode != 'V') |
3235 maxlen = (curbuf->b_visual.vi_curswant == MAXCOL | 3228 maxlen = (curbuf->b_visual.vi_curswant == MAXCOL |
3236 ? (int)STRLEN(ptr) - col | 3229 ? (int)STRLEN(ptr) - col |
3237 : length); | 3230 : length); |
3238 | 3231 |
3240 0 + (dobin ? STR2NR_BIN : 0) | 3233 0 + (dobin ? STR2NR_BIN : 0) |
3241 + (dooct ? STR2NR_OCT : 0) | 3234 + (dooct ? STR2NR_OCT : 0) |
3242 + (dohex ? STR2NR_HEX : 0), | 3235 + (dohex ? STR2NR_HEX : 0), |
3243 NULL, &n, maxlen, FALSE); | 3236 NULL, &n, maxlen, FALSE); |
3244 | 3237 |
3245 /* ignore leading '-' for hex and octal and bin numbers */ | 3238 // ignore leading '-' for hex and octal and bin numbers |
3246 if (pre && negative) | 3239 if (pre && negative) |
3247 { | 3240 { |
3248 ++col; | 3241 ++col; |
3249 --length; | 3242 --length; |
3250 negative = FALSE; | 3243 negative = FALSE; |
3251 } | 3244 } |
3252 /* add or subtract */ | 3245 // add or subtract |
3253 subtract = FALSE; | 3246 subtract = FALSE; |
3254 if (op_type == OP_NR_SUB) | 3247 if (op_type == OP_NR_SUB) |
3255 subtract ^= TRUE; | 3248 subtract ^= TRUE; |
3256 if (negative) | 3249 if (negative) |
3257 subtract ^= TRUE; | 3250 subtract ^= TRUE; |
3259 oldn = n; | 3252 oldn = n; |
3260 if (subtract) | 3253 if (subtract) |
3261 n -= (uvarnumber_T)Prenum1; | 3254 n -= (uvarnumber_T)Prenum1; |
3262 else | 3255 else |
3263 n += (uvarnumber_T)Prenum1; | 3256 n += (uvarnumber_T)Prenum1; |
3264 /* handle wraparound for decimal numbers */ | 3257 // handle wraparound for decimal numbers |
3265 if (!pre) | 3258 if (!pre) |
3266 { | 3259 { |
3267 if (subtract) | 3260 if (subtract) |
3268 { | 3261 { |
3269 if (n > oldn) | 3262 if (n > oldn) |
3272 negative ^= TRUE; | 3265 negative ^= TRUE; |
3273 } | 3266 } |
3274 } | 3267 } |
3275 else | 3268 else |
3276 { | 3269 { |
3277 /* add */ | 3270 // add |
3278 if (n < oldn) | 3271 if (n < oldn) |
3279 { | 3272 { |
3280 n = (n ^ (uvarnumber_T)-1); | 3273 n = (n ^ (uvarnumber_T)-1); |
3281 negative ^= TRUE; | 3274 negative ^= TRUE; |
3282 } | 3275 } |
3285 negative = FALSE; | 3278 negative = FALSE; |
3286 } | 3279 } |
3287 | 3280 |
3288 if (visual && !was_positive && !negative && col > 0) | 3281 if (visual && !was_positive && !negative && col > 0) |
3289 { | 3282 { |
3290 /* need to remove the '-' */ | 3283 // need to remove the '-' |
3291 col--; | 3284 col--; |
3292 length++; | 3285 length++; |
3293 } | 3286 } |
3294 | 3287 |
3295 /* | 3288 /* |
3314 if (isupper(c)) | 3307 if (isupper(c)) |
3315 hexupper = TRUE; | 3308 hexupper = TRUE; |
3316 else | 3309 else |
3317 hexupper = FALSE; | 3310 hexupper = FALSE; |
3318 } | 3311 } |
3319 /* del_char() will mark line needing displaying */ | 3312 // del_char() will mark line needing displaying |
3320 (void)del_char(FALSE); | 3313 (void)del_char(FALSE); |
3321 c = gchar_cursor(); | 3314 c = gchar_cursor(); |
3322 } | 3315 } |
3323 | 3316 |
3324 /* | 3317 /* |
3351 { | 3344 { |
3352 int i; | 3345 int i; |
3353 int bit = 0; | 3346 int bit = 0; |
3354 int bits = sizeof(uvarnumber_T) * 8; | 3347 int bits = sizeof(uvarnumber_T) * 8; |
3355 | 3348 |
3356 /* leading zeros */ | 3349 // leading zeros |
3357 for (bit = bits; bit > 0; bit--) | 3350 for (bit = bits; bit > 0; bit--) |
3358 if ((n >> (bit - 1)) & 0x1) break; | 3351 if ((n >> (bit - 1)) & 0x1) break; |
3359 | 3352 |
3360 for (i = 0; bit > 0; bit--) | 3353 for (i = 0; bit > 0; bit--) |
3361 buf2[i++] = ((n >> (bit - 1)) & 0x1) ? '1' : '0'; | 3354 buf2[i++] = ((n >> (bit - 1)) & 0x1) ? '1' : '0'; |
3385 if (firstdigit == '0' && !(dooct && pre == 0)) | 3378 if (firstdigit == '0' && !(dooct && pre == 0)) |
3386 while (length-- > 0) | 3379 while (length-- > 0) |
3387 *ptr++ = '0'; | 3380 *ptr++ = '0'; |
3388 *ptr = NUL; | 3381 *ptr = NUL; |
3389 STRCAT(buf1, buf2); | 3382 STRCAT(buf1, buf2); |
3390 ins_str(buf1); /* insert the new number */ | 3383 ins_str(buf1); // insert the new number |
3391 vim_free(buf1); | 3384 vim_free(buf1); |
3392 endpos = curwin->w_cursor; | 3385 endpos = curwin->w_cursor; |
3393 if (did_change && curwin->w_cursor.col) | 3386 if (did_change && curwin->w_cursor.col) |
3394 --curwin->w_cursor.col; | 3387 --curwin->w_cursor.col; |
3395 } | 3388 } |
3396 | 3389 |
3397 if (did_change && !cmdmod.lockmarks) | 3390 if (did_change && !cmdmod.lockmarks) |
3398 { | 3391 { |
3399 /* set the '[ and '] marks */ | 3392 // set the '[ and '] marks |
3400 curbuf->b_op_start = startpos; | 3393 curbuf->b_op_start = startpos; |
3401 curbuf->b_op_end = endpos; | 3394 curbuf->b_op_end = endpos; |
3402 if (curbuf->b_op_end.col > 0) | 3395 if (curbuf->b_op_end.col > 0) |
3403 --curbuf->b_op_end.col; | 3396 --curbuf->b_op_end.col; |
3404 } | 3397 } |
3458 dpy = xterm_dpy; | 3451 dpy = xterm_dpy; |
3459 # else | 3452 # else |
3460 return; | 3453 return; |
3461 # endif | 3454 # endif |
3462 | 3455 |
3463 /* Get selection to export */ | 3456 // Get selection to export |
3464 if (clip_plus.owned) | 3457 if (clip_plus.owned) |
3465 motion_type = clip_convert_selection(&str, &len, &clip_plus); | 3458 motion_type = clip_convert_selection(&str, &len, &clip_plus); |
3466 else if (clip_star.owned) | 3459 else if (clip_star.owned) |
3467 motion_type = clip_convert_selection(&str, &len, &clip_star); | 3460 motion_type = clip_convert_selection(&str, &len, &clip_star); |
3468 | 3461 |
3469 /* Check it's OK */ | 3462 // Check it's OK |
3470 if (dpy != NULL && str != NULL && motion_type >= 0 | 3463 if (dpy != NULL && str != NULL && motion_type >= 0 |
3471 && len < 1024*1024 && len > 0) | 3464 && len < 1024*1024 && len > 0) |
3472 { | 3465 { |
3473 int ok = TRUE; | 3466 int ok = TRUE; |
3474 | 3467 |
3475 /* The CUT_BUFFER0 is supposed to always contain latin1. Convert from | 3468 // The CUT_BUFFER0 is supposed to always contain latin1. Convert from |
3476 * 'enc' when it is a multi-byte encoding. When 'enc' is an 8-bit | 3469 // 'enc' when it is a multi-byte encoding. When 'enc' is an 8-bit |
3477 * encoding conversion usually doesn't work, so keep the text as-is. | 3470 // encoding conversion usually doesn't work, so keep the text as-is. |
3478 */ | |
3479 if (has_mbyte) | 3471 if (has_mbyte) |
3480 { | 3472 { |
3481 vimconv_T vc; | 3473 vimconv_T vc; |
3482 | 3474 |
3483 vc.vc_type = CONV_NONE; | 3475 vc.vc_type = CONV_NONE; |
3504 { | 3496 { |
3505 ok = FALSE; | 3497 ok = FALSE; |
3506 } | 3498 } |
3507 } | 3499 } |
3508 | 3500 |
3509 /* Do not store the string if conversion failed. Better to use any | 3501 // Do not store the string if conversion failed. Better to use any |
3510 * other selection than garbled text. */ | 3502 // other selection than garbled text. |
3511 if (ok) | 3503 if (ok) |
3512 { | 3504 { |
3513 XStoreBuffer(dpy, (char *)str, (int)len, 0); | 3505 XStoreBuffer(dpy, (char *)str, (int)len, 0); |
3514 XFlush(dpy); | 3506 XFlush(dpy); |
3515 } | 3507 } |
3516 } | 3508 } |
3517 | 3509 |
3518 vim_free(str); | 3510 vim_free(str); |
3519 } | 3511 } |
3520 #endif | 3512 #endif |
3521 #endif /* FEAT_CLIPBOARD || PROTO */ | 3513 #endif // FEAT_CLIPBOARD || PROTO |
3522 | 3514 |
3523 void | 3515 void |
3524 clear_oparg(oparg_T *oap) | 3516 clear_oparg(oparg_T *oap) |
3525 { | 3517 { |
3526 vim_memset(oap, 0, sizeof(oparg_T)); | 3518 vim_memset(oap, 0, sizeof(oparg_T)); |
3571 | 3563 |
3572 if (is_word) | 3564 if (is_word) |
3573 words++; | 3565 words++; |
3574 *wc += words; | 3566 *wc += words; |
3575 | 3567 |
3576 /* Add eol_size if the end of line was reached before hitting limit. */ | 3568 // Add eol_size if the end of line was reached before hitting limit. |
3577 if (i < limit && line[i] == NUL) | 3569 if (i < limit && line[i] == NUL) |
3578 { | 3570 { |
3579 i += eol_size; | 3571 i += eol_size; |
3580 chars += eol_size; | 3572 chars += eol_size; |
3581 } | 3573 } |
3647 { | 3639 { |
3648 #ifdef FEAT_LINEBREAK | 3640 #ifdef FEAT_LINEBREAK |
3649 char_u * saved_sbr = p_sbr; | 3641 char_u * saved_sbr = p_sbr; |
3650 char_u * saved_w_sbr = curwin->w_p_sbr; | 3642 char_u * saved_w_sbr = curwin->w_p_sbr; |
3651 | 3643 |
3652 /* Make 'sbr' empty for a moment to get the correct size. */ | 3644 // Make 'sbr' empty for a moment to get the correct size. |
3653 p_sbr = empty_option; | 3645 p_sbr = empty_option; |
3654 curwin->w_p_sbr = empty_option; | 3646 curwin->w_p_sbr = empty_option; |
3655 #endif | 3647 #endif |
3656 oparg.is_VIsual = 1; | 3648 oparg.is_VIsual = 1; |
3657 oparg.block_mode = TRUE; | 3649 oparg.block_mode = TRUE; |
3662 p_sbr = saved_sbr; | 3654 p_sbr = saved_sbr; |
3663 curwin->w_p_sbr = saved_w_sbr; | 3655 curwin->w_p_sbr = saved_w_sbr; |
3664 #endif | 3656 #endif |
3665 if (curwin->w_curswant == MAXCOL) | 3657 if (curwin->w_curswant == MAXCOL) |
3666 oparg.end_vcol = MAXCOL; | 3658 oparg.end_vcol = MAXCOL; |
3667 /* Swap the start, end vcol if needed */ | 3659 // Swap the start, end vcol if needed |
3668 if (oparg.end_vcol < oparg.start_vcol) | 3660 if (oparg.end_vcol < oparg.start_vcol) |
3669 { | 3661 { |
3670 oparg.end_vcol += oparg.start_vcol; | 3662 oparg.end_vcol += oparg.start_vcol; |
3671 oparg.start_vcol = oparg.end_vcol - oparg.start_vcol; | 3663 oparg.start_vcol = oparg.end_vcol - oparg.start_vcol; |
3672 oparg.end_vcol -= oparg.start_vcol; | 3664 oparg.end_vcol -= oparg.start_vcol; |
3675 line_count_selected = max_pos.lnum - min_pos.lnum + 1; | 3667 line_count_selected = max_pos.lnum - min_pos.lnum + 1; |
3676 } | 3668 } |
3677 | 3669 |
3678 for (lnum = 1; lnum <= curbuf->b_ml.ml_line_count; ++lnum) | 3670 for (lnum = 1; lnum <= curbuf->b_ml.ml_line_count; ++lnum) |
3679 { | 3671 { |
3680 /* Check for a CTRL-C every 100000 characters. */ | 3672 // Check for a CTRL-C every 100000 characters. |
3681 if (byte_count > last_check) | 3673 if (byte_count > last_check) |
3682 { | 3674 { |
3683 ui_breakcheck(); | 3675 ui_breakcheck(); |
3684 if (got_int) | 3676 if (got_int) |
3685 return; | 3677 return; |
3686 last_check = byte_count + 100000L; | 3678 last_check = byte_count + 100000L; |
3687 } | 3679 } |
3688 | 3680 |
3689 /* Do extra processing for VIsual mode. */ | 3681 // Do extra processing for VIsual mode. |
3690 if (VIsual_active | 3682 if (VIsual_active |
3691 && lnum >= min_pos.lnum && lnum <= max_pos.lnum) | 3683 && lnum >= min_pos.lnum && lnum <= max_pos.lnum) |
3692 { | 3684 { |
3693 char_u *s = NULL; | 3685 char_u *s = NULL; |
3694 long len = 0L; | 3686 long len = 0L; |
3729 byte_count_cursor -= eol_size; | 3721 byte_count_cursor -= eol_size; |
3730 } | 3722 } |
3731 } | 3723 } |
3732 else | 3724 else |
3733 { | 3725 { |
3734 /* In non-visual mode, check for the line the cursor is on */ | 3726 // In non-visual mode, check for the line the cursor is on |
3735 if (lnum == curwin->w_cursor.lnum) | 3727 if (lnum == curwin->w_cursor.lnum) |
3736 { | 3728 { |
3737 word_count_cursor += word_count; | 3729 word_count_cursor += word_count; |
3738 char_count_cursor += char_count; | 3730 char_count_cursor += char_count; |
3739 byte_count_cursor = byte_count + | 3731 byte_count_cursor = byte_count + |
3741 &word_count_cursor, &char_count_cursor, | 3733 &word_count_cursor, &char_count_cursor, |
3742 (varnumber_T)(curwin->w_cursor.col + 1), | 3734 (varnumber_T)(curwin->w_cursor.col + 1), |
3743 eol_size); | 3735 eol_size); |
3744 } | 3736 } |
3745 } | 3737 } |
3746 /* Add to the running totals */ | 3738 // Add to the running totals |
3747 byte_count += line_count_info(ml_get(lnum), &word_count, | 3739 byte_count += line_count_info(ml_get(lnum), &word_count, |
3748 &char_count, (varnumber_T)MAXCOL, | 3740 &char_count, (varnumber_T)MAXCOL, |
3749 eol_size); | 3741 eol_size); |
3750 } | 3742 } |
3751 | 3743 |
3752 /* Correction for when last line doesn't have an EOL. */ | 3744 // Correction for when last line doesn't have an EOL. |
3753 if (!curbuf->b_p_eol && (curbuf->b_p_bin || !curbuf->b_p_fixeol)) | 3745 if (!curbuf->b_p_eol && (curbuf->b_p_bin || !curbuf->b_p_fixeol)) |
3754 byte_count -= eol_size; | 3746 byte_count -= eol_size; |
3755 | 3747 |
3756 if (dict == NULL) | 3748 if (dict == NULL) |
3757 { | 3749 { |
4326 // Prepare for redoing. Only use the nchar field for "r", | 4318 // Prepare for redoing. Only use the nchar field for "r", |
4327 // otherwise it might be the second char of the operator. | 4319 // otherwise it might be the second char of the operator. |
4328 if (cap->cmdchar == 'g' && (cap->nchar == 'n' | 4320 if (cap->cmdchar == 'g' && (cap->nchar == 'n' |
4329 || cap->nchar == 'N')) | 4321 || cap->nchar == 'N')) |
4330 prep_redo(oap->regname, cap->count0, | 4322 prep_redo(oap->regname, cap->count0, |
4331 get_op_char(oap->op_type), get_extra_op_char(oap->op_type), | 4323 get_op_char(oap->op_type), |
4324 get_extra_op_char(oap->op_type), | |
4332 oap->motion_force, cap->cmdchar, cap->nchar); | 4325 oap->motion_force, cap->cmdchar, cap->nchar); |
4333 else if (cap->cmdchar != ':') | 4326 else if (cap->cmdchar != ':') |
4334 { | 4327 { |
4335 int nchar = oap->op_type == OP_REPLACE ? cap->nchar : NUL; | 4328 int nchar = oap->op_type == OP_REPLACE ? cap->nchar : NUL; |
4336 | 4329 |