To: vim_dev@googlegroups.com Subject: Patch 9.0.1595 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 9.0.1595 Problem: Line pointer becomes invalid when using spell checking. Solution: Call ml_get() at the right places. (Luuk van Baal, closes #12456) Files: src/drawline.c, src/drawscreen.c, src/testdir/test_spell.vim, src/testdir/dumps/Test_spell_10.dump, src/testdir/dumps/Test_spell_9.dump *** ../vim-9.0.1594/src/drawline.c 2023-05-27 22:22:06.458633197 +0100 --- src/drawline.c 2023-05-31 18:53:58.214167881 +0100 *************** *** 1449,1457 **** area_highlighting = TRUE; #endif - line = ml_get_buf(wp->w_buffer, lnum, FALSE); - ptr = line; - #ifdef FEAT_SPELL if (spv->spv_has_spell && !number_only) { --- 1449,1454 ---- *************** *** 1462,1489 **** // current line is valid. if (lnum == spv->spv_checked_lnum) cur_checked_col = spv->spv_checked_col; ! if (lnum != spv->spv_capcol_lnum) spv->spv_cap_col = -1; spv->spv_checked_lnum = 0; ! // For checking first word with a capital skip white space. ! if (spv->spv_cap_col == 0) ! spv->spv_cap_col = getwhitecols(line); // If current line is empty, check first word in next line for capital. ! else if (*skipwhite(line) == NUL) { spv->spv_cap_col = 0; spv->spv_capcol_lnum = lnum + 1; } - - // Get the start of the next line, so that words that wrap to the - // next line are found too: "etal.". - // Trick: skip a few chars for C/shell/Vim comments - nextline[SPWORDLEN] = NUL; - if (lnum < wp->w_buffer->b_ml.ml_line_count) - spell_cat_line(nextline + SPWORDLEN, - ml_get_buf(wp->w_buffer, lnum + 1, FALSE), SPWORDLEN); // Copy the end of the current line into nextline[]. if (nextline[SPWORDLEN] == NUL) { --- 1459,1494 ---- // current line is valid. if (lnum == spv->spv_checked_lnum) cur_checked_col = spv->spv_checked_col; ! // Previous line was not spell checked, check for capital. This happens ! // for the first line in an updated region or after a closed fold. ! if (spv->spv_capcol_lnum == 0 && check_need_cap(wp, lnum, 0)) ! spv->spv_cap_col = 0; ! else if (lnum != spv->spv_capcol_lnum) spv->spv_cap_col = -1; spv->spv_checked_lnum = 0; ! // Get the start of the next line, so that words that wrap to the ! // next line are found too: "etal.". ! // Trick: skip a few chars for C/shell/Vim comments ! nextline[SPWORDLEN] = NUL; ! if (lnum < wp->w_buffer->b_ml.ml_line_count) ! { ! line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE); ! spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN); ! } ! line = ml_get_buf(wp->w_buffer, lnum, FALSE); ! // If current line is empty, check first word in next line for capital. ! ptr = skipwhite(line); ! if (*ptr == NUL) { spv->spv_cap_col = 0; spv->spv_capcol_lnum = lnum + 1; } + // For checking first word with a capital skip white space. + else if (spv->spv_cap_col == 0) + spv->spv_cap_col = ptr - line; // Copy the end of the current line into nextline[]. if (nextline[SPWORDLEN] == NUL) { *************** *** 1514,1519 **** --- 1519,1527 ---- } #endif + line = ml_get_buf(wp->w_buffer, lnum, FALSE); + ptr = line; + if (wp->w_p_list) { if (wp->w_lcs_chars.space *** ../vim-9.0.1594/src/drawscreen.c 2023-05-27 22:22:06.458633197 +0100 --- src/drawscreen.c 2023-05-31 18:39:00.919200938 +0100 *************** *** 2197,2208 **** #ifdef FEAT_SPELL // Initialize spell related variables for the first drawn line. CLEAR_FIELD(spv); ! spv.spv_has_spell = spell_check_window(wp); ! if (spv.spv_has_spell) { spv.spv_unchanged = mod_top == 0; - spv.spv_capcol_lnum = mod_top ? mod_top : lnum; - spv.spv_cap_col = check_need_cap(wp, spv.spv_capcol_lnum, 0) ? 0 : - 1; } #endif --- 2197,2206 ---- #ifdef FEAT_SPELL // Initialize spell related variables for the first drawn line. CLEAR_FIELD(spv); ! if (spell_check_window(wp)) { + spv.spv_has_spell = TRUE; spv.spv_unchanged = mod_top == 0; } #endif *************** *** 2464,2482 **** fold_line(wp, fold_count, &win_foldinfo, lnum, row); ++row; --fold_count; - linenr_T lnume = lnum + fold_count; wp->w_lines[idx].wl_folded = TRUE; ! wp->w_lines[idx].wl_lastlnum = lnume; # ifdef FEAT_SYN_HL did_update = DID_FOLD; # endif # ifdef FEAT_SPELL ! // Check if the line after this fold requires a capital. ! if (spv.spv_has_spell && check_need_cap(wp, lnume + 1, 0)) ! { ! spv.spv_cap_col = 0; ! spv.spv_capcol_lnum = lnume + 1; ! } # endif } else --- 2462,2474 ---- fold_line(wp, fold_count, &win_foldinfo, lnum, row); ++row; --fold_count; wp->w_lines[idx].wl_folded = TRUE; ! wp->w_lines[idx].wl_lastlnum = lnum + fold_count; # ifdef FEAT_SYN_HL did_update = DID_FOLD; # endif # ifdef FEAT_SPELL ! spv.spv_capcol_lnum = 0; # endif } else *************** *** 2572,2577 **** --- 2564,2572 ---- #ifdef FEAT_SYN_HL did_update = DID_NONE; #endif + #ifdef FEAT_SPELL + spv.spv_capcol_lnum = 0; + #endif } if (lnum > buf->b_ml.ml_line_count) *** ../vim-9.0.1594/src/testdir/test_spell.vim 2023-05-25 17:14:18.223481261 +0100 --- src/testdir/test_spell.vim 2023-05-31 18:39:00.923200935 +0100 *************** *** 958,963 **** --- 958,964 ---- CheckScreendump let lines =<< trim END + call test_override('alloc_lines', 1) call setline(1, [ \ "This is some text without any spell errors. Everything", \ "should just be black, nothing wrong here.", *************** *** 980,985 **** --- 981,987 ---- CheckScreendump let lines =<< trim END + call test_override('alloc_lines', 1) call setline(1, [ \ " This line has a sepll error. and missing caps and trailing spaces. ", \ "another missing cap here.", *************** *** 1019,1024 **** --- 1021,1034 ---- call term_sendkeys(buf, "\\") call VerifyScreenDump(buf, 'Test_spell_8', {}) + " Adding an empty line does not remove Cap in "mod_bot" area + call term_sendkeys(buf, "zbO\") + call VerifyScreenDump(buf, 'Test_spell_9', {}) + + " Multiple empty lines does not remove Cap in the line after + call term_sendkeys(buf, "O\\") + call VerifyScreenDump(buf, 'Test_spell_10', {}) + " clean up call StopVimInTerminal(buf) endfunc *************** *** 1027,1032 **** --- 1037,1043 ---- CheckScreendump let lines =<< trim END + call test_override('alloc_lines', 1) call setline(1, [ \ "test "->repeat(20), \ "", *** ../vim-9.0.1594/src/testdir/dumps/Test_spell_10.dump 2023-05-31 18:55:40.850052601 +0100 --- src/testdir/dumps/Test_spell_10.dump 2023-05-31 18:39:00.919200938 +0100 *************** *** 0 **** --- 1,8 ---- + | +0&#ffffff0@2|T|h|i|s| |l|i|n|e| |h|a|s| |a| |s+0&#ffd7d7255|e|p|l@1| +0&#ffffff0|e|r@1|o|r|.| |a+0fd7ff255|n|d| +0&#ffffff0|m|i|s@1|i|n|g| |c|a|p|s| |a|n|d| |t|r|a|i|l|i|n|g| |s|p|a|c|e|s|.| @5 + |a+0fd7ff255|n|o|t|h|e|r| +0&#ffffff0|m|i|s@1|i|n|g| |c|a|p| |h|e|r|e| @50 + |++0#0000e05#a8a8a8255|-@1| @1|2| |l|i|n|e|s|:| |N|o|t|-@57 + > +0#0000000#ffffff0@74 + @75 + |a+0fd7ff255|n|d| +0&#ffffff0|h|e|r|e|.| @65 + |~+0#4040ff13&| @73 + | +0#0000000&@56|5|,|0|-|1| @8|A|l@1| *** ../vim-9.0.1594/src/testdir/dumps/Test_spell_9.dump 2023-05-31 18:55:40.854052598 +0100 --- src/testdir/dumps/Test_spell_9.dump 2023-05-31 18:39:00.919200938 +0100 *************** *** 0 **** --- 1,8 ---- + | +0&#ffffff0@2|T|h|i|s| |l|i|n|e| |h|a|s| |a| |s+0&#ffd7d7255|e|p|l@1| +0&#ffffff0|e|r@1|o|r|.| |a+0fd7ff255|n|d| +0&#ffffff0|m|i|s@1|i|n|g| |c|a|p|s| |a|n|d| |t|r|a|i|l|i|n|g| |s|p|a|c|e|s|.| @5 + |a+0fd7ff255|n|o|t|h|e|r| +0&#ffffff0|m|i|s@1|i|n|g| |c|a|p| |h|e|r|e| @50 + |++0#0000e05#a8a8a8255|-@1| @1|2| |l|i|n|e|s|:| |N|o|t|-@57 + > +0#0000000#ffffff0@74 + |a+0fd7ff255|n|d| +0&#ffffff0|h|e|r|e|.| @65 + |~+0#4040ff13&| @73 + |~| @73 + | +0#0000000&@56|5|,|0|-|1| @8|A|l@1| *** ../vim-9.0.1594/src/version.c 2023-05-31 17:12:07.892535672 +0100 --- src/version.c 2023-05-31 18:40:57.603072736 +0100 *************** *** 697,698 **** --- 697,700 ---- { /* Add new patch number below this line */ + /**/ + 1595, /**/ -- From "know your smileys": :-F Bucktoothed vampire with one tooth missing /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// \\\ \\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///