diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile | 1 | ||||
-rw-r--r-- | src/beval.c | 5 | ||||
-rw-r--r-- | src/beval.h | 5 | ||||
-rw-r--r-- | src/buffer.c | 24 | ||||
-rw-r--r-- | src/charset.c | 24 | ||||
-rw-r--r-- | src/edit.c | 62 | ||||
-rw-r--r-- | src/evalfunc.c | 3 | ||||
-rw-r--r-- | src/ex_cmds.c | 75 | ||||
-rw-r--r-- | src/feature.h | 7 | ||||
-rw-r--r-- | src/gui_beval.c | 7 | ||||
-rw-r--r-- | src/gui_w32.c | 7 | ||||
-rw-r--r-- | src/hardcopy.c | 5 | ||||
-rw-r--r-- | src/message.c | 5 | ||||
-rw-r--r-- | src/misc1.c | 191 | ||||
-rw-r--r-- | src/ops.c | 19 | ||||
-rw-r--r-- | src/option.c | 484 | ||||
-rw-r--r-- | src/option.h | 4 | ||||
-rw-r--r-- | src/proto/misc1.pro | 1 | ||||
-rw-r--r-- | src/proto/option.pro | 9 | ||||
-rw-r--r-- | src/screen.c | 8 | ||||
-rw-r--r-- | src/structs.h | 7 | ||||
-rw-r--r-- | src/testdir/Make_all.mak | 3 | ||||
-rw-r--r-- | src/testdir/gen_opt_test.vim | 2 | ||||
-rw-r--r-- | src/testdir/test_breakindent.vim | 625 | ||||
-rw-r--r-- | src/testdir/test_vartabs.vim | 257 | ||||
-rw-r--r-- | src/version.c | 7 | ||||
-rw-r--r-- | src/workshop.c | 18 |
27 files changed, 1691 insertions, 174 deletions
diff --git a/src/Makefile b/src/Makefile index ca972547f6..e9a15a0cfa 100644 --- a/src/Makefile +++ b/src/Makefile @@ -2305,6 +2305,7 @@ test_arglist \ test_usercommands \ test_utf8 \ test_utf8_comparisons \ + test_vartabs \ test_viminfo \ test_vimscript \ test_virtualedit \ diff --git a/src/beval.c b/src/beval.c index 4ceddca19f..74750a27d0 100644 --- a/src/beval.c +++ b/src/beval.c @@ -124,6 +124,11 @@ get_beval_info( *lnump = lnum; *textp = lbuf; *colp = col; +#ifdef FEAT_VARTABS + if (beval->vts) + vim_free(beval->vts); + beval->vts = tabstop_copy(wp->w_buffer->b_p_vts_array); +#endif beval->ts = wp->w_buffer->b_p_ts; return OK; } diff --git a/src/beval.h b/src/beval.h index f4d1d80e9a..49ba05b2ec 100644 --- a/src/beval.h +++ b/src/beval.h @@ -71,7 +71,10 @@ typedef struct BalloonEvalStruct void *clientData; /* For callback */ #endif - int ts; /* tabstop setting for this buffer */ + int ts; // tabstop setting for this buffer +#ifdef FEAT_VARTABS + int *vts; // vartabstop setting for this buffer +#endif char_u *msg; } BalloonEval; diff --git a/src/buffer.c b/src/buffer.c index 254aad461d..1f1833fc74 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -271,7 +271,7 @@ open_buffer( /* * Set/reset the Changed flag first, autocmds may change the buffer. * Apply the automatic commands, before processing the modelines. - * So the modelines have priority over auto commands. + * So the modelines have priority over autocommands. */ /* When reading stdin, the buffer contents always needs writing, so set * the changed flag. Unless in readonly mode: "ls | gview -". @@ -2159,6 +2159,19 @@ free_buf_options( clear_string_option(&buf->b_p_fo); clear_string_option(&buf->b_p_flp); clear_string_option(&buf->b_p_isk); +#ifdef FEAT_VARTABS + clear_string_option(&buf->b_p_vsts); + if (buf->b_p_vsts_nopaste) + vim_free(buf->b_p_vsts_nopaste); + buf->b_p_vsts_nopaste = NULL; + if (buf->b_p_vsts_array) + vim_free(buf->b_p_vsts_array); + buf->b_p_vsts_array = NULL; + clear_string_option(&buf->b_p_vts); + if (buf->b_p_vts_array) + vim_free(buf->b_p_vts_array); + buf->b_p_vts_array = NULL; +#endif #ifdef FEAT_KEYMAP clear_string_option(&buf->b_p_keymap); keymap_clear(&buf->b_kmap_ga); @@ -5190,7 +5203,7 @@ ex_buffer_all(exarg_T *eap) win_close(wp, FALSE); wpnext = firstwin; /* just in case an autocommand does something strange with windows */ - tpnext = first_tabpage; /* start all over...*/ + tpnext = first_tabpage; /* start all over... */ open_wins = 0; } else @@ -5650,8 +5663,8 @@ bt_prompt(buf_T *buf) } /* - * Return TRUE if "buf" is a "nofile", "acwrite" or "terminal" buffer. - * This means the buffer name is not a file name. + * Return TRUE if "buf" is a "nofile", "acwrite", "terminal" or "prompt" + * buffer. This means the buffer name is not a file name. */ int bt_nofile(buf_T *buf) @@ -5663,7 +5676,8 @@ bt_nofile(buf_T *buf) } /* - * Return TRUE if "buf" is a "nowrite", "nofile" or "terminal" buffer. + * Return TRUE if "buf" is a "nowrite", "nofile", "terminal" or "prompt" + * buffer. */ int bt_dontwrite(buf_T *buf) diff --git a/src/charset.c b/src/charset.c index 179fc89db3..a4816887e4 100644 --- a/src/charset.c +++ b/src/charset.c @@ -812,7 +812,16 @@ vim_strnsize(char_u *s, int len) * Also see getvcol() below. */ -#define RET_WIN_BUF_CHARTABSIZE(wp, buf, p, col) \ +#ifdef FEAT_VARTABS +# define RET_WIN_BUF_CHARTABSIZE(wp, buf, p, col) \ + if (*(p) == TAB && (!(wp)->w_p_list || lcs_tab1)) \ + { \ + return tabstop_padding(col, (buf)->b_p_ts, (buf)->b_p_vts_array); \ + } \ + else \ + return ptr2cells(p); +#else +# define RET_WIN_BUF_CHARTABSIZE(wp, buf, p, col) \ if (*(p) == TAB && (!(wp)->w_p_list || lcs_tab1)) \ { \ int ts; \ @@ -821,6 +830,7 @@ vim_strnsize(char_u *s, int len) } \ else \ return ptr2cells(p); +#endif int chartabsize(char_u *p, colnr_T col) @@ -1221,8 +1231,13 @@ win_nolbr_chartabsize( if (*s == TAB && (!wp->w_p_list || lcs_tab1)) { +# ifdef FEAT_VARTABS + return tabstop_padding(col, wp->w_buffer->b_p_ts, + wp->w_buffer->b_p_vts_array); +# else n = wp->w_buffer->b_p_ts; return (int)(n - (col % n)); +# endif } n = ptr2cells(s); /* Add one cell for a double-width character in the last column of the @@ -1282,6 +1297,9 @@ getvcol( char_u *line; /* start of the line */ int incr; int head; +#ifdef FEAT_VARTABS + int *vts = wp->w_buffer->b_p_vts_array; +#endif int ts = wp->w_buffer->b_p_ts; int c; @@ -1332,7 +1350,11 @@ getvcol( } /* A tab gets expanded, depending on the current column */ if (c == TAB) +#ifdef FEAT_VARTABS + incr = tabstop_padding(vcol, ts, vts); +#else incr = ts - (vcol % ts); +#endif else { #ifdef FEAT_MBYTE diff --git a/src/edit.c b/src/edit.c index 6a636b9e12..d4de825af1 100644 --- a/src/edit.c +++ b/src/edit.c @@ -742,7 +742,14 @@ edit( mincol = curwin->w_wcol; validate_cursor_col(); - if ((int)curwin->w_wcol < mincol - curbuf->b_p_ts + if ( +#ifdef FEAT_VARTABS + (int)curwin->w_wcol < mincol - tabstop_at( + get_nolist_virtcol(), curbuf->b_p_ts, + curbuf->b_p_vts_array) +#else + (int)curwin->w_wcol < mincol - curbuf->b_p_ts +#endif && curwin->w_wrow == W_WINROW(curwin) + curwin->w_height - 1 - p_so && (curwin->w_cursor.lnum != curwin->w_topline @@ -9329,23 +9336,31 @@ ins_bs( */ if ( mode == BACKSPACE_CHAR && ((p_sta && in_indent) - || (get_sts_value() != 0 + || ((get_sts_value() != 0 +#ifdef FEAT_VARTABS + || tabstop_count(curbuf->b_p_vsts_array) +#endif + ) && curwin->w_cursor.col > 0 && (*(ml_get_cursor() - 1) == TAB || (*(ml_get_cursor() - 1) == ' ' && (!*inserted_space_p || arrow_used)))))) { +#ifndef FEAT_VARTABS int ts; +#endif colnr_T vcol; colnr_T want_vcol; colnr_T start_vcol; *inserted_space_p = FALSE; +#ifndef FEAT_VARTABS if (p_sta && in_indent) ts = (int)get_sw_value(curbuf); else ts = (int)get_sts_value(); +#endif /* Compute the virtual column where we want to be. Since * 'showbreak' may get in the way, need to get the last column of * the previous character. */ @@ -9354,7 +9369,15 @@ ins_bs( dec_cursor(); getvcol(curwin, &curwin->w_cursor, NULL, NULL, &want_vcol); inc_cursor(); +#ifdef FEAT_VARTABS + if (p_sta && in_indent) + want_vcol = (want_vcol / curbuf->b_p_sw) * curbuf->b_p_sw; + else + want_vcol = tabstop_start(want_vcol, curbuf->b_p_sts, + curbuf->b_p_vsts_array); +#else want_vcol = (want_vcol / ts) * ts; +#endif /* delete characters until we are at or before want_vcol */ while (vcol > want_vcol @@ -10144,10 +10167,22 @@ ins_tab(void) #endif /* - * When nothing special, insert TAB like a normal character + * When nothing special, insert TAB like a normal character. */ if (!curbuf->b_p_et +#ifdef FEAT_VARTABS + && !(p_sta && ind + /* These five lines mean 'tabstop' != 'shiftwidth' */ + && ((tabstop_count(curbuf->b_p_vts_array) > 1) + || (tabstop_count(curbuf->b_p_vts_array) == 1 + && tabstop_first(curbuf->b_p_vts_array) + != get_sw_value(curbuf)) + || (tabstop_count(curbuf->b_p_vts_array) == 0 + && curbuf->b_p_ts != get_sw_value(curbuf)))) + && tabstop_count(curbuf->b_p_vsts_array) == 0 +#else && !(p_sta && ind && curbuf->b_p_ts != get_sw_value(curbuf)) +#endif && get_sts_value() == 0) return TRUE; @@ -10162,6 +10197,20 @@ ins_tab(void) #endif AppendToRedobuff((char_u *)"\t"); +#ifdef FEAT_VARTABS + if (p_sta && ind) /* insert tab in indent, use 'shiftwidth' */ + { + temp = (int)curbuf->b_p_sw; + temp -= get_nolist_virtcol() % temp; + } + else if (tabstop_count(curbuf->b_p_vsts_array) > 0 || curbuf->b_p_sts > 0) + /* use 'softtabstop' when set */ + temp = tabstop_padding(get_nolist_virtcol(), curbuf->b_p_sts, + curbuf->b_p_vsts_array); + else /* otherwise use 'tabstop' */ + temp = tabstop_padding(get_nolist_virtcol(), curbuf->b_p_ts, + curbuf->b_p_vts_array); +#else if (p_sta && ind) /* insert tab in indent, use 'shiftwidth' */ temp = (int)get_sw_value(curbuf); else if (curbuf->b_p_sts != 0) /* use 'softtabstop' when set */ @@ -10169,6 +10218,7 @@ ins_tab(void) else /* otherwise use 'tabstop' */ temp = (int)curbuf->b_p_ts; temp -= get_nolist_virtcol() % temp; +#endif /* * Insert the first space with ins_char(). It will delete one char in @@ -10193,7 +10243,13 @@ ins_tab(void) /* * When 'expandtab' not set: Replace spaces by TABs where possible. */ +#ifdef FEAT_VARTABS + if (!curbuf->b_p_et && (tabstop_count(curbuf->b_p_vsts_array) > 0 + || get_sts_value() > 0 + || (p_sta && ind))) +#else if (!curbuf->b_p_et && (get_sts_value() || (p_sta && ind))) +#endif { char_u *ptr; #ifdef FEAT_VREPLACE diff --git a/src/evalfunc.c b/src/evalfunc.c index 7325f5dfc5..0cd7527f77 100644 --- a/src/evalfunc.c +++ b/src/evalfunc.c @@ -6436,6 +6436,9 @@ f_has(typval_T *argvars, typval_T *rettv) "user-commands", /* was accidentally included in 5.4 */ "user_commands", #endif +#ifdef FEAT_VARTABS + "vartabs", +#endif #ifdef FEAT_VIMINFO "viminfo", #endif diff --git a/src/ex_cmds.c b/src/ex_cmds.c index 60d72023c9..53334342c1 100644 --- a/src/ex_cmds.c +++ b/src/ex_cmds.c @@ -673,12 +673,17 @@ ex_retab(exarg_T *eap) long vcol; long start_col = 0; /* For start of white-space string */ long start_vcol = 0; /* For start of white-space string */ - int temp; long old_len; char_u *ptr; char_u *new_line = (char_u *)1; /* init to non-NULL */ int did_undo; /* called u_save for current line */ +#ifdef FEAT_VARTABS + int *new_ts = 0; + char_u *new_ts_str; /* string value of tab argument */ +#else + int temp; int new_ts; +#endif int save_list; linenr_T first_line = 0; /* first changed line */ linenr_T last_line = 0; /* last changed line */ @@ -686,6 +691,23 @@ ex_retab(exarg_T *eap) save_list = curwin->w_p_list; curwin->w_p_list = 0; /* don't want list mode here */ +#ifdef FEAT_VARTABS + new_ts_str = eap->arg; + if (!tabstop_set(eap->arg, &new_ts)) + return; + while (vim_isdigit(*(eap->arg)) || *(eap->arg) == ',') + ++(eap->arg); + + // This ensures that either new_ts and new_ts_str are freshly allocated, + // or new_ts points to an existing array and new_ts_str is null. + if (new_ts == 0) + { + new_ts = curbuf->b_p_vts_array; + new_ts_str = NULL; + } + else + new_ts_str = vim_strnsave(new_ts_str, eap->arg - new_ts_str); +#else new_ts = getdigits(&(eap->arg)); if (new_ts < 0) { @@ -694,6 +716,7 @@ ex_retab(exarg_T *eap) } if (new_ts == 0) new_ts = curbuf->b_p_ts; +#endif for (lnum = eap->line1; !got_int && lnum <= eap->line2; ++lnum) { ptr = ml_get(lnum); @@ -726,6 +749,16 @@ ex_retab(exarg_T *eap) num_tabs = 0; if (!curbuf->b_p_et) { +#ifdef FEAT_VARTABS + int t, s; + + tabstop_fromto(start_vcol, vcol, + tabstop_count(new_ts)? 0: curbuf->b_p_ts, + new_ts, + &t, &s); + num_tabs = t; + num_spaces = s; +#else temp = new_ts - (start_vcol % new_ts); if (num_spaces >= temp) { @@ -734,6 +767,7 @@ ex_retab(exarg_T *eap) } num_tabs += num_spaces / new_ts; num_spaces -= (num_spaces / new_ts) * new_ts; +#endif } if (curbuf->b_p_et || got_tab || (num_spaces + num_tabs < len)) @@ -791,14 +825,53 @@ ex_retab(exarg_T *eap) if (got_int) EMSG(_(e_interr)); +#ifdef FEAT_VARTABS + // If a single value was given then it can be considered equal to + // either the value of 'tabstop' or the value of 'vartabstop'. + if (tabstop_count(curbuf->b_p_vts_array) == 0 + && tabstop_count(new_ts) == 1 + && curbuf->b_p_ts == tabstop_first(new_ts)) + ; /* not changed */ + else if (tabstop_count(curbuf->b_p_vts_array) > 0 + && tabstop_eq(curbuf->b_p_vts_array, new_ts)) + ; /* not changed */ + else + redraw_curbuf_later(NOT_VALID); +#else if (curbuf->b_p_ts != new_ts) redraw_curbuf_later(NOT_VALID); +#endif if (first_line != 0) changed_lines(first_line, 0, last_line + 1, 0L); curwin->w_p_list = save_list; /* restore 'list' */ +#ifdef FEAT_VARTABS + if (new_ts_str != NULL) /* set the new tabstop */ + { + // If 'vartabstop' is in use or if the value given to retab has more + // than one tabstop then update 'vartabstop'. + int *old_vts_ary = curbuf->b_p_vts_array; + + if (tabstop_count(old_vts_ary) > 0 || tabstop_count(new_ts) > 1) + { + set_string_option_direct((char_u *)"vts", -1, new_ts_str, + OPT_FREE|OPT_LOCAL, 0); + vim_free(new_ts_str); + curbuf->b_p_vts_array = new_ts; + vim_free(old_vts_ary); + } + else + { + // 'vartabstop' wasn't in use and a single value was given to + // retab then update 'tabstop'. + curbuf->b_p_ts = tabstop_first(new_ts); + vim_free(new_ts); + } + } +#else curbuf->b_p_ts = new_ts; +#endif coladvance(curwin->w_curswant); u_clearline(); diff --git a/src/feature.h b/src/feature.h index 5b915b838c..762a70cee7 100644 --- a/src/feature.h +++ b/src/feature.h @@ -806,6 +806,13 @@ #endif /* + * +vartabs 'vartabstop' and 'varsofttabstop' options. + */ +#ifdef FEAT_BIG +# define FEAT_VARTABS +#endif + +/* * Preferences: * ============ */ diff --git a/src/gui_beval.c b/src/gui_beval.c index 8c1cd9696f..7e4625080f 100644 --- a/src/gui_beval.c +++ b/src/gui_beval.c @@ -130,6 +130,9 @@ gui_mch_create_beval_area( beval->msg = mesg; beval->msgCB = mesgCB; beval->clientData = clientData; +#ifdef FEAT_VARTABS + beval->vts = NULL; +#endif /* * Set up event handler which will keep its eyes on the pointer, @@ -172,6 +175,10 @@ gui_mch_destroy_beval_area(BalloonEval *beval) # else XtDestroyWidget(beval->balloonShell); # endif +# ifdef FEAT_VARTABS + if (beval->vts) + vim_free(beval->vts); +# endif vim_free(beval); } #endif diff --git a/src/gui_w32.c b/src/gui_w32.c index 49aa1e0bd2..855381108b 100644 --- a/src/gui_w32.c +++ b/src/gui_w32.c @@ -8934,6 +8934,9 @@ gui_mch_create_beval_area( beval->msg = mesg; beval->msgCB = mesgCB; beval->clientData = clientData; +#ifdef FEAT_VARTABS + beval->vts = NULL; +#endif InitCommonControls(); cur_beval = beval; @@ -8990,6 +8993,10 @@ TrackUserActivity(UINT uMsg) void gui_mch_destroy_beval_area(BalloonEval *beval) { +#ifdef FEAT_VARTABS + if (beval->vts) + vim_free(beval->vts); +#endif vim_free(beval); } #endif /* FEAT_BEVAL_GUI */ diff --git a/src/hardcopy.c b/src/hardcopy.c index 420ceb7638..44e9d4fe84 100644 --- a/src/hardcopy.c +++ b/src/hardcopy.c @@ -915,7 +915,12 @@ hardcopy_line( if (line[col] == TAB || tab_spaces != 0) { if (tab_spaces == 0) +#ifdef FEAT_VARTABS + tab_spaces = tabstop_padding(print_pos, curbuf->b_p_ts, + curbuf->b_p_vts_array); +#else tab_spaces = (int)(curbuf->b_p_ts - (print_pos % curbuf->b_p_ts)); +#endif while (tab_spaces > 0) { diff --git a/src/message.c b/src/message.c index fd087a4a79..4dac5ae04d 100644 --- a/src/message.c +++ b/src/message.c @@ -1831,7 +1831,12 @@ msg_prt_line(char_u *s, int list) if (c == TAB && (!list || lcs_tab1)) { /* tab amount depends on current column */ +#ifdef FEAT_VARTABS + n_extra = tabstop_padding(col, curbuf->b_p_ts, + curbuf->b_p_vts_array) - 1; +#else n_extra = curbuf->b_p_ts - col % curbuf->b_p_ts - 1; +#endif if (!list) { c = ' '; diff --git a/src/misc1.c b/src/misc1.c index d797a0bc65..5242ca5729 100644 --- a/src/misc1.c +++ b/src/misc1.c @@ -36,7 +36,12 @@ static garray_T ga_users; int get_indent(void) { +#ifdef FEAT_VARTABS + return get_indent_str_vtab(ml_get_curline(), (int)curbuf->b_p_ts, + curbuf->b_p_vts_array, FALSE); +#else return get_indent_str(ml_get_curline(), (int)curbuf->b_p_ts, FALSE); +#endif } /* @@ -45,7 +50,12 @@ get_indent(void) int get_indent_lnum(linenr_T lnum) { +#ifdef FEAT_VARTABS + return get_indent_str_vtab(ml_get(lnum), (int)curbuf->b_p_ts, + curbuf->b_p_vts_array, FALSE); +#else return get_indent_str(ml_get(lnum), (int)curbuf->b_p_ts, FALSE); +#endif } #if defined(FEAT_FOLDING) || defined(PROTO) @@ -56,7 +66,12 @@ get_indent_lnum(linenr_T lnum) int get_indent_buf(buf_T *buf, linenr_T lnum) { +#ifdef FEAT_VARTABS + return get_indent_str_vtab(ml_get_buf(buf, lnum, FALSE), + (int)curbuf->b_p_ts, buf->b_p_vts_array, FALSE); +#else return get_indent_str(ml_get_buf(buf, lnum, FALSE), (int)buf->b_p_ts, FALSE); +#endif } #endif @@ -91,6 +106,37 @@ get_indent_str( return count; } +#ifdef FEAT_VARTABS +/* + * Count the size (in window cells) of the indent in line "ptr", using + * variable tabstops. + * if "list" is TRUE, count only screen size for tabs. + */ + int +get_indent_str_vtab(char_u *ptr, int ts, int *vts, int list) +{ + int count = 0; + + for ( ; *ptr; ++ptr) + { + if (*ptr == TAB) /* count a tab for what it is worth */ + { + if (!list || lcs_tab1) + count += tabstop_padding(count, ts, vts); + else + /* In list mode, when tab is not set, count screen char width + * for Tab, displays: ^I */ + count += ptr2cells(ptr); + } + else if (*ptr == ' ') + ++count; /* count a space for one */ + else + break; + } + return count; +} +#endif + /* * Set the indent of the current line. * Leaves the cursor on the first non-blank in the line. @@ -115,6 +161,9 @@ set_indent( int line_len; int doit = FALSE; int ind_done = 0; /* measured in spaces */ +#ifdef FEAT_VARTABS + int ind_col = 0; +#endif int tab_pad; int retval = FALSE; int orig_char_len = -1; /* number of initial whitespace chars when @@ -147,8 +196,13 @@ set_indent( { if (*p == TAB) { +#ifdef FEAT_VARTABS + tab_pad = tabstop_padding(ind_done, curbuf->b_p_ts, + curbuf->b_p_vts_array); +#else tab_pad = (int)curbuf->b_p_ts - (ind_done % (int)curbuf->b_p_ts); +#endif /* stop if this tab will overshoot the target */ if (todo < tab_pad) break; @@ -165,23 +219,51 @@ set_indent( ++p; } +#ifdef FEAT_VARTABS + /* These diverge from this point. */ + ind_col = ind_done; +#endif /* Set initial number of whitespace chars to copy if we are * preserving indent but expandtab is set */ if (curbuf->b_p_et) orig_char_len = ind_len; /* Fill to next tabstop with a tab, if possible */ +#ifdef FEAT_VARTABS + tab_pad = tabstop_padding(ind_done, curbuf->b_p_ts, + curbuf->b_p_vts_array); +#else tab_pad = (int)curbuf->b_p_ts - (ind_done % (int)curbuf->b_p_ts); +#endif if (todo >= tab_pad && orig_char_len == -1) { doit = TRUE; todo -= tab_pad; ++ind_len; /* ind_done += tab_pad; */ +#ifdef FEAT_VARTABS + ind_col += tab_pad; +#endif } } /* count tabs required for indent */ +#ifdef FEAT_VARTABS + for (;;) + { + tab_pad = tabstop_padding(ind_col, curbuf->b_p_ts, + curbuf->b_p_vts_array); + if (todo < tab_pad) + break; + if (*p != TAB) + doit = TRUE; + else + ++p; + todo -= tab_pad; + ++ind_len; + ind_col += tab_pad; + } +#else while (todo >= (int)curbuf->b_p_ts) { if (*p != TAB) @@ -192,6 +274,7 @@ set_indent( ++ind_len; /* ind_done += (int)curbuf->b_p_ts; */ } +#endif } /* count spaces required for indent */ while (todo > 0) @@ -266,8 +349,13 @@ set_indent( { if (*p == TAB) { +#ifdef FEAT_VARTABS + tab_pad = tabstop_padding(ind_done, curbuf->b_p_ts, + curbuf->b_p_vts_array); +#else tab_pad = (int)curbuf->b_p_ts - (ind_done % (int)curbuf->b_p_ts); +#endif /* stop if this tab will overshoot the target */ if (todo < tab_pad) break; @@ -283,21 +371,42 @@ set_indent( } /* Fill to next tabstop with a tab, if possible */ +#ifdef FEAT_VARTABS + tab_pad = tabstop_padding(ind_done, curbuf->b_p_ts, + curbuf->b_p_vts_array); +#else tab_pad = (int)curbuf->b_p_ts - (ind_done % (int)curbuf->b_p_ts); +#endif if (todo >= tab_pad) { *s++ = TAB; todo -= tab_pad; +#ifdef FEAT_VARTABS + ind_done += tab_pad; +#endif } p = skipwhite(p); } +#ifdef FEAT_VARTABS + for (;;) + { + tab_pad = tabstop_padding(ind_done, curbuf->b_p_ts, + curbuf->b_p_vts_array); + if (todo < tab_pad) + break; + *s++ = TAB; + todo -= tab_pad; + ind_done += tab_pad; + } +#else while (todo >= (int)curbuf->b_p_ts) { *s++ = TAB; todo -= (int)curbuf->b_p_ts; } +#endif } while (todo > 0) { @@ -350,6 +459,9 @@ copy_indent(int size, char_u *src) int tab_pad; int ind_done; int round; +#ifdef FEAT_VARTABS + int ind_col; +#endif /* Round 1: compute the number of characters needed for the indent * Round 2: copy the characters. */ @@ -358,6 +470,9 @@ copy_indent(int size, char_u *src) todo = size; ind_len = 0; ind_done = 0; +#ifdef FEAT_VARTABS + ind_col = 0; +#endif s = src; /* Count/copy the usable portion of the source line */ @@ -365,18 +480,29 @@ copy_indent(int size, char_u *src) { if (*s == TAB) { +#ifdef FEAT_VARTABS + tab_pad = tabstop_padding(ind_done, curbuf->b_p_ts, + curbuf->b_p_vts_array); +#else tab_pad = (int)curbuf->b_p_ts - (ind_done % (int)curbuf->b_p_ts); +#endif /* Stop if this tab will overshoot the target */ if (todo < tab_pad) break; todo -= tab_pad; ind_done += tab_pad; +#ifdef FEAT_VARTABS + ind_col += tab_pad; +#endif } else { --todo; ++ind_done; +#ifdef FEAT_VARTABS + ++ind_col; +#endif } ++ind_len; if (p != NULL) @@ -385,22 +511,48 @@ copy_indent(int size, char_u *src) } /* Fill to next tabstop with a tab, if possible */ +#ifdef FEAT_VARTABS + tab_pad = tabstop_padding(ind_done, curbuf->b_p_ts, + curbuf->b_p_vts_array); +#else tab_pad = (int)curbuf->b_p_ts - (ind_done % (int)curbuf->b_p_ts); +#endif if (todo >= tab_pad && !curbuf->b_p_et) { todo -= tab_pad; ++ind_len; +#ifdef FEAT_VARTABS + ind_col += tab_pad; +#endif if (p != NULL) *p++ = TAB; } /* Add tabs required for indent */ - while (todo >= (int)curbuf->b_p_ts && !curbuf->b_p_et) + if (!curbuf->b_p_et) { - todo -= (int)curbuf->b_p_ts; - ++ind_len; - if (p != NULL) - *p++ = TAB; +#ifdef FEAT_VARTABS + for (;;) + { + tab_pad = tabstop_padding(ind_col, curbuf->b_p_ts, + curbuf->b_p_vts_array); + if (todo < tab_pad) + break; + todo -= tab_pad; + ++ind_len; + ind_col += tab_pad; + if (p != NULL) + *p++ = TAB; + } +#else + while (todo >= (int)curbuf->b_p_ts) + { + todo -= (int)curbuf->b_p_ts; + ++ind_len; + if (p != NULL) + *p++ = TAB; + } +#endif } /* Count/add spaces required for indent */ @@ -497,6 +649,9 @@ get_breakindent_win( static long prev_ts = 0L; /* cached tabstop value */ static char_u *prev_line = NULL; /* cached pointer to line */ static varnumber_T prev_tick = 0; /* changedtick of cached value */ +#ifdef FEAT_VARTABS + static int *prev_vts = NULL; /* cached vartabs values */ +#endif int bri = 0; /* window width minus window margin space, i.e. what rests for text */ const int eff_wwidth = wp->w_width @@ -506,13 +661,24 @@ get_breakindent_win( /* used cached indent, unless pointer or 'tabstop' changed */ if (prev_line != line || prev_ts != wp->w_buffer->b_p_ts - || prev_tick != CHANGEDTICK(wp->w_buffer)) + || prev_tick != CHANGEDTICK(wp->w_buffer) +#ifdef FEAT_VARTABS + || prev_vts != wp->w_buffer->b_p_vts_array +#endif + ) { prev_line = line; prev_ts = wp->w_buffer->b_p_ts; prev_tick = CHANGEDTICK(wp->w_buffer); +#ifdef FEAT_VARTABS + prev_vts = wp->w_buffer->b_p_vts_array; + prev_indent = get_indent_str_vtab(line, + (int)wp->w_buffer->b_p_ts, + wp->w_buffer->b_p_vts_array, wp->w_p_list); +#else prev_indent = get_indent_str(line, (int)wp->w_buffer->b_p_ts, wp->w_p_list); +#endif } bri = prev_indent + wp->w_p_brishift; @@ -741,7 +907,12 @@ open_line( /* * count white space on current line */ +#ifdef FEAT_VARTABS + newindent = get_indent_str_vtab(saved_line, curbuf->b_p_ts, + curbuf->b_p_vts_array, FALSE); +#else newindent = get_indent_str(saved_line, (int)curbuf->b_p_ts, FALSE); +#endif if (newindent == 0 && !(flags & OPENLINE_COM_LIST)) newindent = second_line_indent; /* for ^^D command in insert mode */ @@ -1264,7 +1435,13 @@ open_line( || do_si #endif ) - newindent = get_indent_str(leader, (int)curbuf->b_p_ts, FALSE); +#ifdef FEAT_VARTABS + newindent = get_indent_str_vtab(leader, curbuf->b_p_ts, + curbuf->b_p_vts_array, FALSE); +#else + newindent = get_indent_str(leader, + (int)curbuf->b_p_ts, FALSE); +#endif /* Add the indent offset */ if (newindent + off < 0) @@ -398,6 +398,9 @@ shift_block(oparg_T *oap, int a |