To: vim-dev@vim.org Subject: Patch 6.2.462 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit ------------ Patch 6.2.462 Problem: Finding a matching parenthesis does not correctly handle a backslash in a trailing byte. Solution: Handle multi-byte characters correctly. (Taro Muraoka) Files: src/search.c *** ../vim-6.2.461/src/search.c Wed Mar 17 22:18:24 2004 --- src/search.c Fri Apr 9 11:25:06 2004 *************** *** 16,21 **** --- 16,22 ---- #ifdef FEAT_EVAL static int first_submatch __ARGS((regmmatch_T *rp)); #endif + static int check_prevcol __ARGS((char_u *linep, int col, int ch, int *prevcol)); static int inmacro __ARGS((char_u *, char_u *)); static int check_linecomment __ARGS((char_u *line)); static int cls __ARGS((void)); *************** *** 1491,1496 **** --- 1492,1521 ---- } /* + * Return TRUE if the character before "linep[col]" equals "ch". + * Return FALSE if "col" is zero. + * Update "*prevcol" to the column of the previous character, unless "prevcol" + * is NULL. + * Handles multibyte string correctly. + */ + static int + check_prevcol(linep, col, ch, prevcol) + char_u *linep; + int col; + int ch; + int *prevcol; + { + --col; + #ifdef FEAT_MBYTE + if (col > 0 && has_mbyte) + col -= (*mb_head_off)(linep, linep + col); + #endif + if (prevcol) + *prevcol = col; + return (col >= 0 && linep[col] == ch) ? TRUE : FALSE; + } + + /* * findmatchlimit -- find the matching paren or brace, if it exists within * maxtravel lines of here. A maxtravel of 0 means search until falling off * the edge of the file. *************** *** 1708,1715 **** /* Set "match_escaped" if there are an odd number of * backslashes. */ ! for (col = pos.col - 1; col >= 0 && linep[col] == '\\'; ! col--) bslcnt++; match_escaped = (bslcnt & 1); } --- 1733,1739 ---- /* Set "match_escaped" if there are an odd number of * backslashes. */ ! for (col = pos.col; check_prevcol(linep, col, '\\', &col);) bslcnt++; match_escaped = (bslcnt & 1); } *************** *** 2073,2079 **** if (curbuf->b_p_lisp && vim_strchr((char_u *)"(){}[]", c) != NULL && pos.col > 0 ! && linep[pos.col - 1] == '\\') break; #endif --- 2097,2103 ---- if (curbuf->b_p_lisp && vim_strchr((char_u *)"(){}[]", c) != NULL && pos.col > 0 ! && check_prevcol(linep, pos.col, '\\', NULL)) break; #endif *************** *** 2086,2093 **** if (!cpo_bsl) { ! for (col = pos.col - 1; col >= 0 && linep[col] == '\\'; ! col--) bslcnt++; } /* Only accept a match when 'M' is in 'cpo' or when ecaping is --- 2110,2116 ---- if (!cpo_bsl) { ! for (col = pos.col; check_prevcol(linep, col, '\\', &col);) bslcnt++; } /* Only accept a match when 'M' is in 'cpo' or when ecaping is *** ../vim-6.2.461/src/version.c Thu Apr 8 12:29:56 2004 --- src/version.c Fri Apr 9 19:29:27 2004 *************** *** 639,640 **** --- 639,642 ---- { /* Add new patch number below this line */ + /**/ + 462, /**/ -- Q: How many hardware engineers does it take to change a lightbulb? A: None. We'll fix it in software. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// Sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ Project leader for A-A-P -- http://www.A-A-P.org /// \\\ Buy at Amazon and help AIDS victims -- http://ICCF.nl/click1.html ///