Blog: Better line wrapping in Vim: vim-7.2-breakindent.patch

File vim-7.2-breakindent.patch, 31.2 KB (added by retracile, 15 years ago)

updated patch

  • runtime/doc/eval.txt

     vim72/runtime/doc/eval.txt    |    4 +--
     vim72/runtime/doc/options.txt |   42 ++++++++++++++++++++++++++++---
     vim72/runtime/optwin.vim      |    9 ++++++
     vim72/src/charset.c           |   51 ++++++++++++++++++++++++--------------
     vim72/src/edit.c              |   21 ++++++++-------
     vim72/src/ex_cmds.c           |    2 -
     vim72/src/getchar.c           |    2 -
     vim72/src/gui_beval.c         |    2 -
     vim72/src/misc1.c             |   56 ++++++++++++++++++++++++++++++++++++------
     vim72/src/misc2.c             |    8 +++---
     vim72/src/normal.c            |    4 +--
     vim72/src/ops.c               |   14 +++++-----
     vim72/src/option.c            |   41 ++++++++++++++++++++++++++++++
     vim72/src/option.h            |    5 +++
     vim72/src/proto/charset.pro   |   10 +++----
     vim72/src/proto/misc1.pro     |    1 
     vim72/src/regexp.c            |    4 +--
     vim72/src/screen.c            |   37 ++++++++++++++++++++++++---
     vim72/src/structs.h           |    8 ++++++
     vim72/src/ui.c                |    2 -
     20 files changed, 253 insertions(+), 70 deletions(-)
    old new jumplist Compiled with |jumplist| suppo 
    58225822keymap                  Compiled with 'keymap' support.
    58235823langmap                 Compiled with 'langmap' support.
    58245824libcall                 Compiled with |libcall()| support.
    5825 linebreak               Compiled with 'linebreak', 'breakat' and 'showbreak'
    5826                         support.
     5825linebreak               Compiled with 'linebreak', 'breakat', 'showbreak' and
     5826                        'breakindent' support.
    58275827lispindent              Compiled with support for lisp indenting.
    58285828listcmds                Compiled with commands for the buffer list |:files|
    58295829                        and the argument list |arglist|.
  • runtime/doc/options.txt

    old new A jump table for the options with a shor 
    11601160        break if 'linebreak' is on.  Only works for ASCII and also for 8-bit
    11611161        characters when 'encoding' is an 8-bit encoding.
    11621162
     1163
     1164                                                *'breakindent'* *'bri'*
     1165'breakindent' 'bri'     boolean (default off)
     1166                        local to window
     1167                        {not in Vi}
     1168                        {not available when compiled without the |+linebreak|
     1169                        feature}
     1170        Every wrapped line will continue visually indented (same amount of
     1171        space as the beginning of that line), thus preserving horizontal blocks
     1172        of text.
     1173
     1174                                                *'breakindentmin'* *'brimin'*
     1175'breakindentmin' 'brimin' number (default 20)
     1176                        local to window
     1177                        {not in Vi}
     1178                        {not available when compiled without the |+linebreak|
     1179                        feature}
     1180        Minimum text width that will be kept after applying 'breakindent',
     1181        even if the resulting text should normally be narrower. This prevents
     1182        text indented almost to the right window border oocupying lot of
     1183        vertical space when broken.
     1184
     1185                                                *'breakindentshift'* *'brishift'*
     1186'breakindentshift' 'brishift' number (default 20)
     1187                        local to window
     1188                        {not in Vi}
     1189                        {not available when compiled without the |+linebreak|
     1190                        feature}
     1191        After applying 'breakindent', wrapped line beginning will be shift by
     1192        given number of characters. It permits dynamic French paragraph
     1193        indentation (negative) or emphasizing the line continuation
     1194        (positive).
     1195
    11631196                                                *'browsedir'* *'bsdir'*
    11641197'browsedir' 'bsdir'     string  (default: "last")
    11651198                        global
    A jump table for the options with a shor 
    42554288                        {not in Vi}
    42564289                        {not available when compiled without the  |+linebreak|
    42574290                        feature}
    4258         If on Vim will wrap long lines at a character in 'breakat' rather
     4291        If on, Vim will wrap long lines at a character in 'breakat' rather
    42594292        than at the last character that fits on the screen.  Unlike
    42604293        'wrapmargin' and 'textwidth', this does not insert <EOL>s in the file,
    4261         it only affects the way the file is displayed, not its contents.  The
    4262         value of 'showbreak' is used to put in front of wrapped lines.
    4263         This option is not used when the 'wrap' option is off or 'list' is on.
     4294        it only affects the way the file is displayed, not its contents.
     4295        If 'breakindent' is set, line is visually indented. Then, the value
     4296        of 'showbreak' is used to put in front of wrapped lines. This option
     4297        is not used when the 'wrap' option is off or 'list' is on.
    42644298        Note that <Tab> characters after an <EOL> are mostly not displayed
    42654299        with the right amount of white space.
    42664300
  • runtime/optwin.vim

    old new call <SID>BinOptionG("wrap", &wrap) 
    329329call append("$", "linebreak\twrap long lines at a character in 'breakat'")
    330330call append("$", "\t(local to window)")
    331331call <SID>BinOptionL("lbr")
     332call append("$", "breakindent\tpreserve indentation in wrapped text")
     333call append("$", "\t(local to window)")
     334call <SID>BinOptionL("bri")
     335call append("$", "breakindentmin\tminimum text width after indent in 'breakindent'")
     336call append("$", "\t(local to window)")
     337call <SID>OptionL("brimin")
     338call append("$", "breakindentshift\tshift beginning of 'breakindent'ed line by this number of characters (negative left)")
     339call append("$", "\t(local to window)")
     340call <SID>OptionL("brishift")
    332341call append("$", "breakat\twhich characters might cause a line break")
    333342call <SID>OptionG("brk", &brk)
    334343call append("$", "showbreak\tstring to put before wrapped screen lines")
  • src/charset.c

    old new win_chartabsize(wp, p, col) 
    833833 * taking into account the size of a tab
    834834 */
    835835    int
    836 linetabsize(s)
     836linetabsize(s, lnum)
    837837    char_u      *s;
     838    linenr_T    lnum;
    838839{
    839840    colnr_T     col = 0;
    840841
    841842    while (*s != NUL)
    842         col += lbr_chartabsize_adv(&s, col);
     843        col += lbr_chartabsize_adv(&s, col, lnum);
    843844    return (int)col;
    844845}
    845846
    linetabsize(s) 
    847848 * Like linetabsize(), but for a given window instead of the current one.
    848849 */
    849850    int
    850 win_linetabsize(wp, p, len)
     851win_linetabsize(wp, p, len, lnum)
    851852    win_T       *wp;
    852853    char_u      *p;
    853854    colnr_T     len;
     855    linenr_T    lnum;
    854856{
    855857    colnr_T     col = 0;
    856858    char_u      *s;
    857859
    858860    for (s = p; *s != NUL && (len == MAXCOL || s < p + len); mb_ptr_adv(s))
    859         col += win_lbr_chartabsize(wp, s, col, NULL);
     861        col += win_lbr_chartabsize(wp, s, col, NULL, lnum);
    860862    return (int)col;
    861863}
    862864
    vim_isprintc_strict(c) 
    985987 * like chartabsize(), but also check for line breaks on the screen
    986988 */
    987989    int
    988 lbr_chartabsize(s, col)
     990lbr_chartabsize(s, col, lnum)
    989991    unsigned char       *s;
    990992    colnr_T             col;
     993    linenr_T            lnum;
    991994{
    992995#ifdef FEAT_LINEBREAK
    993     if (!curwin->w_p_lbr && *p_sbr == NUL)
     996    if (!curwin->w_p_lbr && *p_sbr == NUL && !curwin->w_p_bri)
    994997    {
    995998#endif
    996999#ifdef FEAT_MBYTE
    lbr_chartabsize(s, col) 
    10001003        RET_WIN_BUF_CHARTABSIZE(curwin, curbuf, s, col)
    10011004#ifdef FEAT_LINEBREAK
    10021005    }
    1003     return win_lbr_chartabsize(curwin, s, col, NULL);
     1006    return win_lbr_chartabsize(curwin, s, col, NULL, lnum);
    10041007#endif
    10051008}
    10061009
    lbr_chartabsize(s, col) 
    10081011 * Call lbr_chartabsize() and advance the pointer.
    10091012 */
    10101013    int
    1011 lbr_chartabsize_adv(s, col)
     1014lbr_chartabsize_adv(s, col, lnum)
    10121015    char_u      **s;
    10131016    colnr_T     col;
     1017    linenr_T    lnum;
    10141018{
    10151019    int         retval;
    10161020
    1017     retval = lbr_chartabsize(*s, col);
     1021    retval = lbr_chartabsize(*s, col, lnum);
    10181022    mb_ptr_adv(*s);
    10191023    return retval;
    10201024}
    lbr_chartabsize_adv(s, col) 
    10251029 * If "headp" not NULL, set *headp to the size of what we for 'showbreak'
    10261030 * string at start of line.  Warning: *headp is only set if it's a non-zero
    10271031 * value, init to 0 before calling.
     1032 *
     1033 * linenr argument needed if in visual highlighting and breakindent=on, then
     1034 * the line calculated is not current; if 0, normal functionality is preserved.
    10281035 */
    10291036/*ARGSUSED*/
    10301037    int
    1031 win_lbr_chartabsize(wp, s, col, headp)
     1038win_lbr_chartabsize(wp, s, col, headp, lnum)
    10321039    win_T       *wp;
    10331040    char_u      *s;
    10341041    colnr_T     col;
    10351042    int         *headp;
     1043    linenr_T    lnum;
    10361044{
    10371045#ifdef FEAT_LINEBREAK
    10381046    int         c;
    win_lbr_chartabsize(wp, s, col, headp) 
    10511059    int         n;
    10521060
    10531061    /*
    1054      * No 'linebreak' and 'showbreak': return quickly.
     1062     * No 'linebreak' and 'showbreak' and 'breakindent': return quickly.
    10551063     */
    1056     if (!wp->w_p_lbr && *p_sbr == NUL)
     1064    if (!wp->w_p_lbr && !wp->w_p_bri && *p_sbr == NUL)
    10571065#endif
    10581066    {
    10591067#ifdef FEAT_MBYTE
    win_lbr_chartabsize(wp, s, col, headp) 
    11281136# endif
    11291137
    11301138    /*
    1131      * May have to add something for 'showbreak' string at start of line
     1139     * May have to add something for 'breakindent' and/or 'showbreak'
     1140     * string at start of line.
    11321141     * Set *headp to the size of what we add.
    11331142     */
    11341143    added = 0;
    1135     if (*p_sbr != NUL && wp->w_p_wrap && col != 0)
     1144    if ((*p_sbr != NUL || wp->w_p_bri) && wp->w_p_wrap && col != 0)
    11361145    {
    11371146        numberextra = win_col_off(wp);
    11381147        col += numberextra + mb_added;
    win_lbr_chartabsize(wp, s, col, headp) 
    11451154        }
    11461155        if (col == 0 || col + size > (colnr_T)W_WIDTH(wp))
    11471156        {
    1148             added = vim_strsize(p_sbr);
     1157            added = 0;
     1158            if (*p_sbr != NUL)
     1159                added += vim_strsize(p_sbr);
     1160            if (wp->w_p_bri)
     1161                added += get_breakindent_win(wp,lnum);
     1162
    11491163            if (tab_corr)
    11501164                size += (added / wp->w_buffer->b_p_ts) * wp->w_buffer->b_p_ts;
    11511165            else
    getvcol(wp, pos, start, cursor, end) 
    12481262
    12491263    /*
    12501264     * This function is used very often, do some speed optimizations.
    1251      * When 'list', 'linebreak' and 'showbreak' are not set use a simple loop.
     1265     * When 'list', 'linebreak', 'showbreak' and 'breakindent' are not set
     1266     * use a simple loop.
    12521267     * Also use this when 'list' is set but tabs take their normal size.
    12531268     */
    12541269    if ((!wp->w_p_list || lcs_tab1 != NUL)
    12551270#ifdef FEAT_LINEBREAK
    1256             && !wp->w_p_lbr && *p_sbr == NUL
     1271            && !wp->w_p_lbr && *p_sbr == NUL && !wp->w_p_bri
    12571272#endif
    12581273       )
    12591274    {
    getvcol(wp, pos, start, cursor, end) 
    13151330        {
    13161331            /* A tab gets expanded, depending on the current column */
    13171332            head = 0;
    1318             incr = win_lbr_chartabsize(wp, ptr, vcol, &head);
     1333            incr = win_lbr_chartabsize(wp, ptr, vcol, &head, pos->lnum);
    13191334            /* make sure we don't go past the end of the line */
    13201335            if (*ptr == NUL)
    13211336            {
  • src/edit.c

    old new edit(cmdchar, startln, count) 
    387387        if (startln)
    388388            Insstart.col = 0;
    389389    }
    390     Insstart_textlen = linetabsize(ml_get_curline());
     390    Insstart_textlen = linetabsize(ml_get_curline(), Insstart.lnum);
    391391    Insstart_blank_vcol = MAXCOL;
    392392    if (!did_ai)
    393393        ai_col = 0;
    change_indent(type, amount, round, repla 
    17901790            else
    17911791#endif
    17921792                ++new_cursor_col;
    1793             vcol += lbr_chartabsize(ptr + new_cursor_col, (colnr_T)vcol);
     1793            vcol += lbr_chartabsize(ptr + new_cursor_col, (colnr_T)vcol, curwin->w_cursor.lnum);
    17941794        }
    17951795        vcol = last_vcol;
    17961796
    stop_arrow() 
    63206320            ins_need_undo = FALSE;
    63216321        }
    63226322        Insstart = curwin->w_cursor;    /* new insertion starts here */
    6323         Insstart_textlen = linetabsize(ml_get_curline());
     6323        Insstart_textlen = linetabsize(ml_get_curline(),curwin->w_cursor.lnum);
    63246324        ai_col = 0;
    63256325#ifdef FEAT_VREPLACE
    63266326        if (State & VREPLACE_FLAG)
    oneleft() 
    66736673        for (;;)
    66746674        {
    66756675            coladvance(v - width);
    6676             /* getviscol() is slow, skip it when 'showbreak' is empty and
    6677              * there are no multi-byte characters */
    6678             if ((*p_sbr == NUL
     6676            /* getviscol() is slow, skip it when 'showbreak' is empty,
     6677             * 'breakindent' is not set and there are no multi-byte
     6678             * characters */
     6679            if ((*p_sbr == NUL && !curwin->w_p_bri
    66796680#  ifdef FEAT_MBYTE
    66806681                        && !has_mbyte
    66816682#  endif
    ins_tab() 
    93079308        getvcol(curwin, &fpos, &vcol, NULL, NULL);
    93089309        getvcol(curwin, cursor, &want_vcol, NULL, NULL);
    93099310
    9310         /* Use as many TABs as possible.  Beware of 'showbreak' and
     9311        /* Use as many TABs as possible.  Beware of 'breakindent', 'showbreak' and
    93119312         * 'linebreak' adding extra virtual columns. */
    93129313        while (vim_iswhite(*ptr))
    93139314        {
    9314             i = lbr_chartabsize((char_u *)"\t", vcol);
     9315            i = lbr_chartabsize((char_u *)"\t", vcol, cursor->lnum);
    93159316            if (vcol + i > want_vcol)
    93169317                break;
    93179318            if (*ptr != TAB)
    ins_tab() 
    93379338            /* Skip over the spaces we need. */
    93389339            while (vcol < want_vcol && *ptr == ' ')
    93399340            {
    9340                 vcol += lbr_chartabsize(ptr, vcol);
     9341                vcol += lbr_chartabsize(ptr, vcol, cursor->lnum);
    93419342                ++ptr;
    93429343                ++repl_off;
    93439344            }
    ins_copychar(lnum) 
    95859586    while ((colnr_T)temp < curwin->w_virtcol && *ptr != NUL)
    95869587    {
    95879588        prev_ptr = ptr;
    9588         temp += lbr_chartabsize_adv(&ptr, (colnr_T)temp);
     9589        temp += lbr_chartabsize_adv(&ptr, (colnr_T)temp, lnum);
    95899590    }
    95909591    if ((colnr_T)temp > curwin->w_virtcol)
    95919592        ptr = prev_ptr;
  • src/ex_cmds.c

    old new linelen(has_tab) 
    266266        ;
    267267    save = *last;
    268268    *last = NUL;
    269     len = linetabsize(line);            /* get line length */
     269    len = linetabsize(line, curwin->w_cursor.lnum); /* get line length */
    270270    if (has_tab != NULL)                /* check for embedded TAB */
    271271        *has_tab = (vim_strrchr(first, TAB) != NULL);
    272272    *last = save;
  • src/getchar.c

    old new vgetorpeek(advance) 
    25572557                                    if (!vim_iswhite(ptr[col]))
    25582558                                        curwin->w_wcol = vcol;
    25592559                                    vcol += lbr_chartabsize(ptr + col,
    2560                                                                (colnr_T)vcol);
     2560                                                               (colnr_T)vcol, curwin->w_cursor.lnum);
    25612561#ifdef FEAT_MBYTE
    25622562                                    if (has_mbyte)
    25632563                                        col += (*mb_ptr2len)(ptr + col);
  • src/gui_beval.c

    old new get_beval_info(beval, getword, winp, lnu 
    337337        {
    338338            /* Not past end of the file. */
    339339            lbuf = ml_get_buf(wp->w_buffer, lnum, FALSE);
    340             if (col <= win_linetabsize(wp, lbuf, (colnr_T)MAXCOL))
     340            if (col <= win_linetabsize(wp, lbuf, (colnr_T)MAXCOL, lnum))
    341341            {
    342342                /* Not past end of line. */
    343343                if (getword)
  • src/misc1.c

    old new get_number_indent(lnum) 
    451451    return (int)col;
    452452}
    453453
     454#ifdef FEAT_LINEBREAK
     455/*
     456 * Return appropriate space number for breakindent, taking influencing
     457 * parameters into account. Window must be specified, since it is not
     458 * necessarily always the current one. If lnum==0, current line is calculated,
     459 * specified line otherwise.
     460 */
     461   int
     462get_breakindent_win (wp,lnum)
     463    win_T*      wp;
     464    linenr_T    lnum;
     465{
     466    int bri;
     467    /* window width minus barren space, i.e. what rests for text */
     468    const int eff_wwidth = W_WIDTH(wp)
     469        - (wp->w_p_nu && !vim_strchr(p_cpo,CPO_NUMCOL)?number_width(wp):0);
     470        /* - (*p_sbr == NUL ? 0 : vim_strsize(p_sbr)); */
     471
     472    bri = get_indent_buf(wp->w_buffer,lnum?lnum:wp->w_cursor.lnum) + wp->w_p_brishift;
     473
     474    /* if numbering and 'c' in 'cpoptions', cancel it out effectively */
     475    /* (this could be replaced by an equivalent call to win_col_off2()) */
     476    if (curwin->w_p_nu && vim_strchr(p_cpo, CPO_NUMCOL))
     477        bri += number_width(wp);
     478
     479    /* never indent past left window margin */
     480    if (bri < 0)
     481        bri = 0;
     482    /* always leave at least bri_min characters on the left,
     483     * if text width is sufficient */
     484    else if (bri > eff_wwidth - wp->w_p_brimin)
     485        bri = eff_wwidth - wp->w_p_brimin < 0 ? 0 : eff_wwidth - wp->w_p_brimin;
     486
     487    return bri;
     488}
     489
     490
     491
     492#endif
     493
    454494#if defined(FEAT_CINDENT) || defined(FEAT_SMARTINDENT)
    455495
    456496static int cin_is_cinword __ARGS((char_u *line));
    plines_win_nofold(wp, lnum) 
    17301770    s = ml_get_buf(wp->w_buffer, lnum, FALSE);
    17311771    if (*s == NUL)              /* empty line */
    17321772        return 1;
    1733     col = win_linetabsize(wp, s, (colnr_T)MAXCOL);
     1773    col = win_linetabsize(wp, s, (colnr_T)MAXCOL, lnum);
    17341774
    17351775    /*
    17361776     * If list mode is on, then the '$' at the end of the line may take up one
    plines_win_col(wp, lnum, column) 
    17861826    col = 0;
    17871827    while (*s != NUL && --column >= 0)
    17881828    {
    1789         col += win_lbr_chartabsize(wp, s, (colnr_T)col, NULL);
     1829        col += win_lbr_chartabsize(wp, s, (colnr_T)col, NULL, lnum);
    17901830        mb_ptr_adv(s);
    17911831    }
    17921832
    plines_win_col(wp, lnum, column) 
    17981838     * 'ts') -- webb.
    17991839     */
    18001840    if (*s == TAB && (State & NORMAL) && (!wp->w_p_list || lcs_tab1))
    1801         col += win_lbr_chartabsize(wp, s, (colnr_T)col, NULL) - 1;
     1841        col += win_lbr_chartabsize(wp, s, (colnr_T)col, NULL, lnum) - 1;
    18021842
    18031843    /*
    18041844     * Add column offset for 'number', 'foldcolumn', etc.
    get_lisp_indent() 
    82138253                amount = 0;
    82148254                while (*that && col)
    82158255                {
    8216                     amount += lbr_chartabsize_adv(&that, (colnr_T)amount);
     8256                    amount += lbr_chartabsize_adv(&that, (colnr_T)amount, pos->lnum);
    82178257                    col--;
    82188258                }
    82198259
    get_lisp_indent() 
    82368276
    82378277                    while (vim_iswhite(*that))
    82388278                    {
    8239                         amount += lbr_chartabsize(that, (colnr_T)amount);
     8279                        amount += lbr_chartabsize(that, (colnr_T)amount, pos->lnum);
    82408280                        ++that;
    82418281                    }
    82428282
    get_lisp_indent() 
    82758315                                    --parencount;
    82768316                                if (*that == '\\' && *(that+1) != NUL)
    82778317                                    amount += lbr_chartabsize_adv(&that,
    8278                                                              (colnr_T)amount);
     8318                                                             (colnr_T)amount, pos->lnum);
    82798319                                amount += lbr_chartabsize_adv(&that,
    8280                                                              (colnr_T)amount);
     8320                                                             (colnr_T)amount, pos->lnum);
    82818321                            }
    82828322                        }
    82838323                        while (vim_iswhite(*that))
    82848324                        {
    8285                             amount += lbr_chartabsize(that, (colnr_T)amount);
     8325                            amount += lbr_chartabsize(that, (colnr_T)amount, pos->lnum);
    82868326                            that++;
    82878327                        }
    82888328                        if (!*that || *that == ';')
  • src/misc2.c

    old new coladvance2(pos, addspaces, finetune, wc 
    166166#ifdef FEAT_VIRTUALEDIT
    167167            if ((addspaces || finetune) && !VIsual_active)
    168168            {
    169                 curwin->w_curswant = linetabsize(line) + one_more;
     169                curwin->w_curswant = linetabsize(line, pos->lnum) + one_more;
    170170                if (curwin->w_curswant > 0)
    171171                    --curwin->w_curswant;
    172172            }
    coladvance2(pos, addspaces, finetune, wc 
    184184# endif
    185185                && wcol >= (colnr_T)width)
    186186        {
    187             csize = linetabsize(line);
     187            csize = linetabsize(line, pos->lnum);
    188188            if (csize > 0)
    189189                csize--;
    190190
    coladvance2(pos, addspaces, finetune, wc 
    206206        {
    207207            /* Count a tab for what it's worth (if list mode not on) */
    208208#ifdef FEAT_LINEBREAK
    209             csize = win_lbr_chartabsize(curwin, ptr, col, &head);
     209            csize = win_lbr_chartabsize(curwin, ptr, col, &head, pos->lnum);
    210210            mb_ptr_adv(ptr);
    211211#else
    212             csize = lbr_chartabsize_adv(&ptr, col);
     212            csize = lbr_chartabsize_adv(&ptr, col, pos->lnum);
    213213#endif
    214214            col += csize;
    215215        }
  • src/normal.c

    old new nv_screengo(oap, dir, dist) 
    43214321    int         dir;
    43224322    long        dist;
    43234323{
    4324     int         linelen = linetabsize(ml_get_curline());
     4324    int         linelen = linetabsize(ml_get_curline(), curwin->w_cursor.lnum);
    43254325    int         retval = OK;
    43264326    int         atend = FALSE;
    43274327    int         n;
    nv_screengo(oap, dir, dist) 
    43944394                    (void)hasFolding(curwin->w_cursor.lnum,
    43954395                                                &curwin->w_cursor.lnum, NULL);
    43964396#endif
    4397                 linelen = linetabsize(ml_get_curline());
     4397                linelen = linetabsize(ml_get_curline(), curwin->w_cursor.lnum);
    43984398                if (linelen > width1)
    43994399                    curwin->w_curswant += (((linelen - width1 - 1) / width2)
    44004400                                                                + 1) * width2;
  • src/ops.c

    old new shift_block(oap, amount) 
    428428        }
    429429        for ( ; vim_iswhite(*bd.textstart); )
    430430        {
    431             incr = lbr_chartabsize_adv(&bd.textstart, (colnr_T)(bd.start_vcol));
     431            incr = lbr_chartabsize_adv(&bd.textstart, (colnr_T)(bd.start_vcol), curwin->w_cursor.lnum);
    432432            total += incr;
    433433            bd.start_vcol += incr;
    434434        }
    shift_block(oap, amount) 
    488488
    489489        while (vim_iswhite(*non_white))
    490490        {
    491             incr = lbr_chartabsize_adv(&non_white, non_white_col);
     491            incr = lbr_chartabsize_adv(&non_white, non_white_col, curwin->w_cursor.lnum);
    492492            non_white_col += incr;
    493493        }
    494494
    shift_block(oap, amount) 
    512512            verbatim_copy_width -= bd.start_char_vcols;
    513513        while (verbatim_copy_width < destination_col)
    514514        {
    515             incr = lbr_chartabsize(verbatim_copy_end, verbatim_copy_width);
     515            incr = lbr_chartabsize(verbatim_copy_end, verbatim_copy_width, curwin->w_cursor.lnum);
    516516            if (verbatim_copy_width + incr > destination_col)
    517517                break;
    518518            verbatim_copy_width += incr;
    do_put(regname, dir, count, flags) 
    35183518            for (ptr = oldp; vcol < col && *ptr; )
    35193519            {
    35203520                /* Count a tab for what it's worth (if list mode not on) */
    3521                 incr = lbr_chartabsize_adv(&ptr, (colnr_T)vcol);
     3521                incr = lbr_chartabsize_adv(&ptr, (colnr_T)vcol, lnum);
    35223522                vcol += incr;
    35233523            }
    35243524            bd.textcol = (colnr_T)(ptr - oldp);
    do_put(regname, dir, count, flags) 
    35523552            /* calculate number of spaces required to fill right side of block*/
    35533553            spaces = y_width + 1;
    35543554            for (j = 0; j < yanklen; j++)
    3555                 spaces -= lbr_chartabsize(&y_array[i][j], 0);
     3555                spaces -= lbr_chartabsize(&y_array[i][j], 0, lnum);
    35563556            if (spaces < 0)
    35573557                spaces = 0;
    35583558
    block_prep(oap, bdp, lnum, is_del) 
    49124912    while (bdp->start_vcol < oap->start_vcol && *pstart)
    49134913    {
    49144914        /* Count a tab for what it's worth (if list mode not on) */
    4915         incr = lbr_chartabsize(pstart, (colnr_T)bdp->start_vcol);
     4915        incr = lbr_chartabsize(pstart, (colnr_T)bdp->start_vcol, lnum);
    49164916        bdp->start_vcol += incr;
    49174917#ifdef FEAT_VISUALEXTRA
    49184918        if (vim_iswhite(*pstart))
    block_prep(oap, bdp, lnum, is_del) 
    49814981            {
    49824982                /* Count a tab for what it's worth (if list mode not on) */
    49834983                prev_pend = pend;
    4984                 incr = lbr_chartabsize_adv(&pend, (colnr_T)bdp->end_vcol);
     4984                incr = lbr_chartabsize_adv(&pend, (colnr_T)bdp->end_vcol, lnum);
    49854985                bdp->end_vcol += incr;
    49864986            }
    49874987            if (bdp->end_vcol <= oap->end_vcol
    cursor_pos_info() 
    64196419            validate_virtcol();
    64206420            col_print(buf1, (int)curwin->w_cursor.col + 1,
    64216421                    (int)curwin->w_virtcol + 1);
    6422             col_print(buf2, (int)STRLEN(p), linetabsize(p));
     6422            col_print(buf2, (int)STRLEN(p), linetabsize(p, curwin->w_cursor.lnum));
    64236423
    64246424            if (char_count_cursor == byte_count_cursor
    64256425                    && char_count == byte_count)
  • src/option.c

    old new  
    186186#ifdef FEAT_ARABIC
    187187# define PV_ARAB        OPT_WIN(WV_ARAB)
    188188#endif
     189#ifdef FEAT_LINEBREAK
     190# define PV_BRI         OPT_WIN(WV_BRI)
     191# define PV_BRIMIN      OPT_WIN(WV_BRIMIN)
     192# define PV_BRISHIFT    OPT_WIN(WV_BRISHIFT)
     193#endif
    189194#ifdef FEAT_DIFF
    190195# define PV_DIFF        OPT_WIN(WV_DIFF)
    191196#endif
    static struct vimoption 
    630635                            {(char_u *)0L, (char_u *)0L}
    631636#endif
    632637                            },
     638    {"breakindent",   "bri",  P_BOOL|P_VI_DEF|P_VIM|P_RWIN,
     639#ifdef FEAT_LINEBREAK
     640                            (char_u *)VAR_WIN, PV_BRI,
     641#else
     642                            (char_u *)NULL, PV_NONE,
     643#endif
     644                            {(char_u *)FALSE, (char_u *)0L}},
     645    {"breakindentmin", "brimin", P_NUM|P_VI_DEF|P_VIM|P_RWIN,
     646#ifdef FEAT_LINEBREAK
     647                            (char_u *)VAR_WIN, PV_BRIMIN,
     648#else
     649                            (char_u *)NULL, PV_NONE,
     650#endif
     651                            {(char_u *)20L, (char_u *)20L}},
     652    {"breakindentshift", "brishift", P_NUM|P_VI_DEF|P_VIM|P_RWIN,
     653#ifdef FEAT_LINEBREAK
     654                            (char_u *)VAR_WIN, PV_BRISHIFT,
     655#else
     656                            (char_u *)NULL, PV_NONE,
     657#endif
     658                            {(char_u *)0L, (char_u *)0L}},
    633659    {"browsedir",   "bsdir",P_STRING|P_VI_DEF,
    634660#ifdef FEAT_BROWSE
    635661                            (char_u *)&p_bsdir, PV_NONE,
    set_num_option(opt_idx, varp, value, err 
    79537979        }
    79547980        curwin->w_nrwidth_line_count = 0;
    79557981    }
     7982
     7983    /* 'breakindentmin' must be positive */
     7984    else if (pp == &curwin->w_p_brimin)
     7985    {
     7986        if (curwin->w_p_brimin < 1)
     7987        {
     7988            errmsg = e_positive;
     7989            curwin->w_p_brimin = 1;
     7990        }
     7991    }
    79567992#endif
    79577993
    79587994    /*
    get_varp(p) 
    91349170        case PV_WRAP:   return (char_u *)&(curwin->w_p_wrap);
    91359171#ifdef FEAT_LINEBREAK
    91369172        case PV_LBR:    return (char_u *)&(curwin->w_p_lbr);
     9173        case PV_BRI:    return (char_u *)&(curwin->w_p_bri);
     9174        case PV_BRIMIN: return (char_u *)&(curwin->w_p_brimin);
     9175        case PV_BRISHIFT: return (char_u *)&(curwin->w_p_brishift);
    91379176#endif
    91389177#ifdef FEAT_SCROLLBIND
    91399178        case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
    copy_winopt(from, to) 
    93129351    to->wo_wrap = from->wo_wrap;
    93139352#ifdef FEAT_LINEBREAK
    93149353    to->wo_lbr = from->wo_lbr;
     9354    to->wo_bri = from->wo_bri;
     9355    to->wo_brimin = from->wo_brimin;
    93159356#endif
    93169357#ifdef FEAT_SCROLLBIND
    93179358    to->wo_scb = from->wo_scb;
  • src/option.h

    old new enum 
    10181018#ifdef FEAT_ARABIC
    10191019    , WV_ARAB
    10201020#endif
     1021#ifdef FEAT_LINEBREAK
     1022    , WV_BRI
     1023    , WV_BRIMIN
     1024    , WV_BRISHIFT
     1025#endif
    10211026#ifdef FEAT_DIFF
    10221027    , WV_DIFF
    10231028#endif
  • src/proto/charset.pro

    old new int ptr2cells __ARGS((char_u *p)); 
    1414int vim_strsize __ARGS((char_u *s));
    1515int vim_strnsize __ARGS((char_u *s, int len));
    1616int chartabsize __ARGS((char_u *p, colnr_T col));
    17 int linetabsize __ARGS((char_u *s));
    18 int win_linetabsize __ARGS((win_T *wp, char_u *p, colnr_T len));
     17int linetabsize __ARGS((char_u *s, linenr_T lnum));
     18int win_linetabsize __ARGS((win_T *wp, char_u *p, colnr_T len, linenr_T lnum));
    1919int vim_isIDc __ARGS((int c));
    2020int vim_iswordc __ARGS((int c));
    2121int vim_iswordp __ARGS((char_u *p));
    int vim_isfilec __ARGS((int c)); 
    2424int vim_isfilec_or_wc __ARGS((int c));
    2525int vim_isprintc __ARGS((int c));
    2626int vim_isprintc_strict __ARGS((int c));
    27 int lbr_chartabsize __ARGS((unsigned char *s, colnr_T col));
    28 int lbr_chartabsize_adv __ARGS((char_u **s, colnr_T col));
    29 int win_lbr_chartabsize __ARGS((win_T *wp, char_u *s, colnr_T col, int *headp));
     27int lbr_chartabsize __ARGS((unsigned char *s, colnr_T col, linenr_T lnum));
     28int lbr_chartabsize_adv __ARGS((char_u **s, colnr_T col, linenr_T lnum));
     29int win_lbr_chartabsize __ARGS((win_T *wp, char_u *s, colnr_T col, int *headp, linenr_T lnum));
    3030int in_win_border __ARGS((win_T *wp, colnr_T vcol));
    3131void getvcol __ARGS((win_T *wp, pos_T *pos, colnr_T *start, colnr_T *cursor, colnr_T *end));
    3232colnr_T getvcol_nolist __ARGS((pos_T *posp));
  • src/proto/misc1.pro

    old new int get_indent_buf __ARGS((buf_T *buf, l 
    55int get_indent_str __ARGS((char_u *ptr, int ts));
    66int set_indent __ARGS((int size, int flags));
    77int get_number_indent __ARGS((linenr_T lnum));
     8int get_breakindent_win __ARGS((win_T *wp, linenr_T lnum));
    89int open_line __ARGS((int dir, int flags, int old_indent));
    910int get_leader_len __ARGS((char_u *line, char_u **flags, int backward));
    1011int plines __ARGS((linenr_T lnum));
  • src/regexp.c

    old new regmatch(scan) 
    39813981                    if (top.col == MAXCOL || bot.col == MAXCOL)
    39823982                        end = MAXCOL;
    39833983                    cols = win_linetabsize(wp,
    3984                                       regline, (colnr_T)(reginput - regline));
     3984                                      regline, (colnr_T)(reginput - regline), reglnum + reg_firstlnum);
    39853985                    if (cols < start || cols > end - (*p_sel == 'e'))
    39863986                        status = RA_NOMATCH;
    39873987                }
    regmatch(scan) 
    40054005          case RE_VCOL:
    40064006            if (!re_num_cmp((long_u)win_linetabsize(
    40074007                            reg_win == NULL ? curwin : reg_win,
    4008                             regline, (colnr_T)(reginput - regline)) + 1, scan))
     4008                            regline, (colnr_T)(reginput - regline), reglnum + reg_firstlnum ) + 1, scan))
    40094009                status = RA_NOMATCH;
    40104010            break;
    40114011
  • src/screen.c

    old new win_line(wp, lnum, startrow, endrow, noc 
    26902690# define WL_SIGN        WL_FOLD         /* column for signs */
    26912691#endif
    26922692#define WL_NR           WL_SIGN + 1     /* line number */
     2693#ifdef FEAT_LINEBREAK
     2694# define WL_BRI         WL_NR + 1       /* 'breakindent' */
     2695#else
     2696# define WL_BRI         WL_NR
     2697#endif
    26932698#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
    2694 # define WL_SBR         WL_NR + 1       /* 'showbreak' or 'diff' */
     2699# define WL_SBR         WL_BRI + 1      /* 'showbreak' or 'diff' */
    26952700#else
    2696 # define WL_SBR         WL_NR
     2701# define WL_SBR         WL_BRI
    26972702#endif
    26982703#define WL_LINE         WL_SBR + 1      /* text in the line */
    26992704    int         draw_state = WL_START;  /* what to draw next */
    win_line(wp, lnum, startrow, endrow, noc 
    30023007#endif
    30033008        while (vcol < v && *ptr != NUL)
    30043009        {
    3005             c = win_lbr_chartabsize(wp, ptr, (colnr_T)vcol, NULL);
     3010            c = win_lbr_chartabsize(wp, ptr, (colnr_T)vcol, NULL, lnum);
    30063011            vcol += c;
    30073012#ifdef FEAT_MBYTE
    30083013            prev_ptr = ptr;
    win_line(wp, lnum, startrow, endrow, noc 
    33383343                }
    33393344            }
    33403345
     3346#ifdef FEAT_LINEBREAK
     3347            /* draw 'breakindent': indent wrapped text accordingly */
     3348            if (draw_state == WL_BRI -1 && n_extra == 0){
     3349                draw_state = WL_BRI;
     3350# ifdef FEAT_DIFF
     3351                /* FIXME: handle (filler_todo > 0): or modify showbreak so that ---- vim/lines are shorter by the amount needed? */
     3352# endif
     3353                if (wp->w_p_bri && row != startrow){ /* FIXME: what is startrow? Don't we need it as well?? */
     3354                    p_extra = NUL;
     3355                    c_extra = ' ';
     3356                    n_extra = get_breakindent_win(wp,lnum);
     3357                    char_attr = 0; /* was: hl_attr(HLF_AT); */
     3358                    /* FIXME: why do we need to adjust vcol if showbreak does not?? */
     3359                    vcol += n_extra;
     3360                    /* FIXME: is this relevant here? copied shamelessly from showbreak */
     3361                    /* Correct end of highlighted area for 'breakindent',
     3362                     * required when 'linebreak' is also set. */
     3363                    if (tocol == vcol)
     3364                        tocol += n_extra;
     3365                }
     3366            }
     3367#endif
     3368
     3369
    33413370#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
    33423371            if (draw_state == WL_SBR - 1 && n_extra == 0)
    33433372            {
    win_line(wp, lnum, startrow, endrow, noc 
    40354064# ifdef FEAT_MBYTE
    40364065                                has_mbyte ? mb_l :
    40374066# endif
    4038                                 1), (colnr_T)vcol, NULL) - 1;
     4067                                1), (colnr_T)vcol, NULL, lnum) - 1;
    40394068                    c_extra = ' ';
    40404069                    if (vim_iswhite(c))
    40414070                        c = ' ';
  • src/structs.h

    old new typedef struct 
    133133    int         wo_arab;
    134134# define w_p_arab w_onebuf_opt.wo_arab  /* 'arabic' */
    135135#endif
     136#ifdef FEAT_LINEBREAK
     137    int         wo_bri;
     138# define w_p_bri w_onebuf_opt.wo_bri    /* 'breakindent' */
     139    long        wo_brimin;
     140# define w_p_brimin w_onebuf_opt.wo_brimin /* 'breakindentmin' */
     141    long        wo_brishift;
     142# define w_p_brishift w_onebuf_opt.wo_brishift /* 'breakindentshift' */
     143#endif
    136144#ifdef FEAT_DIFF
    137145    int         wo_diff;
    138146# define w_p_diff w_onebuf_opt.wo_diff  /* 'diff' */
  • src/ui.c

    old new vcol2col(wp, lnum, vcol) 
    30273027    while (count <= vcol && *ptr != NUL)
    30283028    {
    30293029        ++col;
    3030         count += win_lbr_chartabsize(wp, ptr, count, NULL);
     3030        count += win_lbr_chartabsize(wp, ptr, count, NULL, lnum);
    30313031        mb_ptr_adv(ptr);
    30323032    }
    30333033    return col;