To: vim-dev@vim.org Subject: Patch 5.6.075 Fcc: outbox From: Bram Moolenaar ------------ Patch 5.6.075 Problem: When using "I" or "A" in Visual block mode while 'sts' is set may change spaces to a Tab the inserted text is not correct. (Mike Steed) And some other problems when using "A" to append after the end of the line. Solution: Check for change in spaces/tabs after inserting the text. Append spaces to fill the gap between the end-of-line and the right edge of the block. Files: src/ops.c *** ../vim-5.6.74/src/ops.c Tue May 9 17:51:49 2000 --- src/ops.c Fri Jun 2 12:28:27 2000 *************** *** 1630,1638 **** * Thus the number of characters may increase! */ /* allow for pre spaces */ ! n = (bd.startspaces ? bd.start_char_vcols - 1 : 0 ); /* allow for post spp */ ! n += ( bd.endspaces && !bd.is_oneChar ? bd.end_char_vcols - 1 : 0 ); n += (oap->end_vcol - oap->start_vcol) - bd.textlen + 1; oldp = ml_get_curline(); --- 1630,1638 ---- * Thus the number of characters may increase! */ /* allow for pre spaces */ ! n = (bd.startspaces ? bd.start_char_vcols - 1 : 0); /* allow for post spp */ ! n += (bd.endspaces && !bd.is_oneChar ? bd.end_char_vcols - 1 : 0); n += (oap->end_vcol - oap->start_vcol) - bd.textlen + 1; oldp = ml_get_curline(); *************** *** 1827,1841 **** long ins_len, pre_textlen = 0; char_u *firstline, *ins_text; struct block_def bd; if (u_save((linenr_t)(oap->start.lnum - 1), (linenr_t)(oap->end.lnum + 1)) == FAIL) return; /* edit() changes this - record it for OP_APPEND */ ! bd.is_MAX = (curwin->w_curswant==MAXCOL); /* beyond EOL allowed in VIsual mode */ ! bd.is_EOL = (linetabsize( ml_get_curline()) == (int)oap->end_vcol); /* vis block is still marked. Get rid of it now. */ curwin->w_cursor.lnum = oap->start.lnum; --- 1827,1842 ---- long ins_len, pre_textlen = 0; char_u *firstline, *ins_text; struct block_def bd; + int i; if (u_save((linenr_t)(oap->start.lnum - 1), (linenr_t)(oap->end.lnum + 1)) == FAIL) return; /* edit() changes this - record it for OP_APPEND */ ! bd.is_MAX = (curwin->w_curswant == MAXCOL); /* beyond EOL allowed in VIsual mode */ ! bd.is_EOL = (linetabsize(ml_get_curline()) == (int)oap->end_vcol); /* vis block is still marked. Get rid of it now. */ curwin->w_cursor.lnum = oap->start.lnum; *************** *** 1843,1852 **** if (oap->block_mode) { ! /* We first input the new text */ ! firstline = ml_get(oap->start.lnum); ! pre_textlen = STRLEN(firstline); block_prep(oap, &bd, oap->start.lnum, TRUE); } if (oap->op_type == OP_APPEND) --- 1844,1855 ---- if (oap->block_mode) { ! /* Get the info about the block before entering the text */ block_prep(oap, &bd, oap->start.lnum, TRUE); + firstline = ml_get(oap->start.lnum) + bd.textcol; + if (oap->op_type == OP_APPEND) + firstline += bd.textlen; + pre_textlen = STRLEN(firstline); } if (oap->op_type == OP_APPEND) *************** *** 1858,1863 **** --- 1861,1874 ---- while (inc_cursor() == 0 && (curwin->w_cursor.col < bd.textcol + bd.textlen)) ; + if (bd.is_short && !bd.is_MAX) + { + /* First line was too short, make it longer and adjust the + * values in "bd". */ + for (i = 0; i < bd.endspaces; ++i) + ins_char(' '); + bd.textlen += bd.endspaces; + } } else { *************** *** 1880,1900 **** if (oap->block_mode) { ! firstline = ml_get(oap->start.lnum); /* * Subsequent calls to ml_get() flush the firstline data - take a * copy of the required string. */ if ((ins_len = STRLEN(firstline) - pre_textlen) > 0) { if ((ins_text = alloc_check((unsigned)(ins_len + 1))) != 0) { ! if (oap->op_type == OP_APPEND) ! STRNCPY(ins_text, firstline + bd.textcol + bd.textlen, ! ins_len); ! else ! STRNCPY(ins_text, firstline + bd.textcol, ins_len); *(ins_text + ins_len) = NUL; /* block handled here */ --- 1891,1929 ---- if (oap->block_mode) { ! struct block_def bd2; ! ! /* ! * Spaces and tabs in the indent may have changed to other spaces and ! * tabs. Get the starting column again and correct the lenght. ! * Don't do this when "$" used, end-of-line will have changed. ! */ ! block_prep(oap, &bd2, oap->start.lnum, TRUE); ! if (!bd.is_MAX || bd2.textlen < bd.textlen) ! { ! if (oap->op_type == OP_APPEND) ! { ! pre_textlen += bd2.textlen - bd.textlen; ! if (bd2.endspaces) ! --bd2.textlen; ! } ! bd.textcol = bd2.textcol; ! bd.textlen = bd2.textlen; ! } ! /* * Subsequent calls to ml_get() flush the firstline data - take a * copy of the required string. */ + firstline = ml_get(oap->start.lnum) + bd.textcol; + if (oap->op_type == OP_APPEND) + firstline += bd.textlen; if ((ins_len = STRLEN(firstline) - pre_textlen) > 0) { if ((ins_text = alloc_check((unsigned)(ins_len + 1))) != 0) { ! STRNCPY(ins_text, firstline, ins_len); *(ins_text + ins_len) = NUL; /* block handled here */ *************** *** 3673,3679 **** bdp->end_vcol += incr; ++pend; } ! if (bdp->end_vcol < oap->end_vcol && (!is_del || oap->op_type == OP_APPEND || oap->op_type == OP_REPLACE)) /* line too short */ --- 3702,3708 ---- bdp->end_vcol += incr; ++pend; } ! if (bdp->end_vcol <= oap->end_vcol && (!is_del || oap->op_type == OP_APPEND || oap->op_type == OP_REPLACE)) /* line too short */ *************** *** 3682,3688 **** bdp->is_short = TRUE; #endif if (oap->op_type == OP_APPEND) ! bdp->endspaces = oap->end_vcol - bdp->end_vcol; else bdp->endspaces = 0; } --- 3711,3717 ---- bdp->is_short = TRUE; #endif if (oap->op_type == OP_APPEND) ! bdp->endspaces = oap->end_vcol - bdp->end_vcol + 1; else bdp->endspaces = 0; } *** ../vim-5.6.74/src/version.c Thu Jun 1 19:54:28 2000 --- src/version.c Fri Jun 2 12:33:41 2000 *************** *** 420,421 **** --- 420,423 ---- { /* Add new patch number below this line */ + /**/ + 75, /**/ -- ARTHUR: If you do not open these doors, we will take this castle by force ... [A bucket of slops land on ARTHUR. He tries to retain his dignity.] "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD /-/-- Bram Moolenaar --- Bram@moolenaar.net --- http://www.moolenaar.net --\-\ \-\-- Vim: http://www.vim.org ---- ICCF Holland: http://www.vim.org/iccf --/-/