To: vim-dev@vim.org Subject: Patch 6.2.491 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit ------------ Patch 6.2.491 Problem: Decrementing a position doesn't take care of multi-byte chars. Solution: Adjust the column for multi-byte characters. Remove mb_dec(). (Yasuhiro Matsumoto) Files: src/mbyte.c, src/misc2.c, src/proto/mbyte.pro *** ../vim-6.2.490/src/mbyte.c Mon Apr 19 20:26:43 2004 --- src/mbyte.c Thu Apr 22 20:24:41 2004 *************** *** 2563,2591 **** } /* - * Decrement position "lp" by one character, taking care of multi-byte chars. - */ - int - mb_dec(lp) - pos_T *lp; - { - if (lp->col > 0) /* still within line */ - { - --lp->col; - mb_adjustpos(lp); - return 0; - } - if (lp->lnum > 1) /* there is a prior line */ - { - lp->lnum--; - lp->col = (colnr_T)STRLEN(ml_get(lp->lnum)); - mb_adjustpos(lp); - return 1; - } - return -1; /* at start of file */ - } - - /* * Try to un-escape a multi-byte character. * Used for the "to" and "from" part of a mapping. * Return the un-escaped string if it is a multi-byte character, and advance --- 2563,2568 ---- *** ../vim-6.2.490/src/misc2.c Mon Apr 19 20:26:43 2004 --- src/misc2.c Wed Apr 21 21:05:31 2004 *************** *** 412,437 **** int dec_cursor() { - #ifdef FEAT_MBYTE - return (has_mbyte ? mb_dec(&curwin->w_cursor) : dec(&curwin->w_cursor)); - #else return dec(&curwin->w_cursor); - #endif } int dec(lp) pos_T *lp; { ! if (lp->col > 0) ! { /* still within line */ lp->col--; return 0; } ! if (lp->lnum > 1) ! { /* there is a prior line */ lp->lnum--; ! lp->col = (colnr_T)STRLEN(ml_get(lp->lnum)); return 1; } return -1; /* at start of file */ --- 412,450 ---- int dec_cursor() { return dec(&curwin->w_cursor); } int dec(lp) pos_T *lp; { ! char_u *p; ! ! #ifdef FEAT_VIRTUALEDIT ! lp->coladd = 0; ! #endif ! if (lp->col > 0) /* still within line */ ! { lp->col--; + #ifdef FEAT_MBYTE + if (has_mbyte) + { + p = ml_get(lp->lnum); + lp->col -= (*mb_head_off)(p, p + lp->col); + } + #endif return 0; } ! if (lp->lnum > 1) /* there is a prior line */ ! { lp->lnum--; ! p = ml_get(lp->lnum); ! lp->col = (colnr_T)STRLEN(p); ! #ifdef FEAT_MBYTE ! if (has_mbyte) ! lp->col -= (*mb_head_off)(p, p + lp->col); ! #endif return 1; } return -1; /* at start of file */ *** ../vim-6.2.490/src/proto/mbyte.pro Mon Apr 5 20:28:39 2004 --- src/proto/mbyte.pro Wed Apr 21 21:01:55 2004 *************** *** 52,58 **** void mb_adjustpos __ARGS((pos_T *lp)); char_u *mb_prevptr __ARGS((char_u *line, char_u *p)); int mb_charlen __ARGS((char_u *str)); - int mb_dec __ARGS((pos_T *lp)); char_u *mb_unescape __ARGS((char_u **pp)); int mb_lefthalve __ARGS((int row, int col)); int mb_fix_col __ARGS((int col, int row)); --- 52,57 ---- *** ../vim-6.2.490/src/version.c Tue Apr 20 20:47:07 2004 --- src/version.c Thu Apr 22 20:26:13 2004 *************** *** 639,640 **** --- 639,642 ---- { /* Add new patch number below this line */ + /**/ + 491, /**/ -- Engineers are always delighted to share wisdom, even in areas in which they have no experience whatsoever. Their logic provides them with inherent insight into any field of expertise. This can be a problem when dealing with the illogical people who believe that knowledge can only be derived through experience. (Scott Adams - The Dilbert principle) /// 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 ///