summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2018-06-23 19:23:02 +0200
committerBram Moolenaar <Bram@vim.org>2018-06-23 19:23:02 +0200
commit04958cbaf25eea27eceedaa987adfb354ad5f7fd (patch)
tree9a47e4e99b5b702e12d08c0424a91ae701eabb4d
parent5ec7414a1c0512832f60c17437d6374cbf4b08e9 (diff)
patch 8.1.0105: all tab stops are the samev8.1.0105
Problem: All tab stops are the same. Solution: Add the variable tabstop feature. (Christian Brabandt, closes #2711)
-rw-r--r--runtime/doc/change.txt5
-rw-r--r--runtime/doc/options.txt46
-rw-r--r--runtime/doc/various.txt1
-rw-r--r--runtime/optwin.vim8
-rw-r--r--src/Makefile1
-rw-r--r--src/beval.c5
-rw-r--r--src/beval.h5
-rw-r--r--src/buffer.c24
-rw-r--r--src/charset.c24
-rw-r--r--src/edit.c62
-rw-r--r--src/evalfunc.c3
-rw-r--r--src/ex_cmds.c75
-rw-r--r--src/feature.h7
-rw-r--r--src/gui_beval.c7
-rw-r--r--src/gui_w32.c7
-rw-r--r--src/hardcopy.c5
-rw-r--r--src/message.c5
-rw-r--r--src/misc1.c191
-rw-r--r--src/ops.c19
-rw-r--r--src/option.c484
-rw-r--r--src/option.h4
-rw-r--r--src/proto/misc1.pro1
-rw-r--r--src/proto/option.pro9
-rw-r--r--src/screen.c8
-rw-r--r--src/structs.h7
-rw-r--r--src/testdir/Make_all.mak3
-rw-r--r--src/testdir/gen_opt_test.vim2
-rw-r--r--src/testdir/test_breakindent.vim625
-rw-r--r--src/testdir/test_vartabs.vim257
-rw-r--r--src/version.c7
-rw-r--r--src/workshop.c18
31 files changed, 1751 insertions, 174 deletions
diff --git a/runtime/doc/change.txt b/runtime/doc/change.txt
index 05c18e64d3..b59f28f47b 100644
--- a/runtime/doc/change.txt
+++ b/runtime/doc/change.txt
@@ -987,6 +987,11 @@ This replaces each 'E' character with a euro sign. Read more in |<Char->|.
this (that's a good habit anyway).
`:retab!` may also change a sequence of spaces by
<Tab> characters, which can mess up a printf().
+ If the |+vartabs| feature is enabled then a list of
+ tab widths separated by commas may be used in place of
+ a single tabstop. Each value in the list represents
+ the width of one tabstop, except the final value which
+ applies to all following tabstops.
{not in Vi}
*retab-example*
diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt
index d37fa641a4..65a9d17ea7 100644
--- a/runtime/doc/options.txt
+++ b/runtime/doc/options.txt
@@ -7172,6 +7172,10 @@ A jump table for the options with a short description can be found at |Q_op|.
set.
NOTE: This option is set to 0 when 'compatible' is set.
+ If Vim is compiled with the |+vartabs| feature then the value of
+ 'softtabstop' will be ignored if |'varsofttabstop'| is set to
+ anything other than an empty string.
+
*'spell'* *'nospell'*
'spell' boolean (default off)
local to window
@@ -7723,6 +7727,10 @@ A jump table for the options with a short description can be found at |Q_op|.
though. Otherwise aligned comments will be wrong when 'tabstop' is
changed.
+ If Vim is compiled with the |+vartabs| feature then the value of
+ 'tabstop' will be ignored if |'vartabstop'| is set to anything other
+ than an empty string.
+
*'tagbsearch'* *'tbs'* *'notagbsearch'* *'notbs'*
'tagbsearch' 'tbs' boolean (default on)
global
@@ -8468,6 +8476,44 @@ A jump table for the options with a short description can be found at |Q_op|.
written to disk (see |crash-recovery|). Also used for the
|CursorHold| autocommand event.
+ *'varsofttabstop'* *'vsts'*
+'varsofttabstop' 'vsts' string (default "")
+ local to buffer
+ {only available when compiled with the |+vartabs|
+ feature}
+ {not in Vi}
+ A list of the number of spaces that a <Tab> counts for while editing,
+ such as inserting a <Tab> or using <BS>. It "feels" like variable-
+ width <Tab>s are being inserted, while in fact a mixture of spaces
+ and <Tab>s is used. Tab widths are separated with commas, with the
+ final value applying to all subsequent tabs.
+
+ For example, when editing assembly language files where statements
+ start in the 8th column and comments in the 40th, it may be useful
+ to use the following: >
+ :set varsofttabstop=8,32,8
+< This will set soft tabstops at the 8th and 40th columns, and at every
+ 8th column thereafter.
+
+ Note that the value of |'softtabstop'| will be ignored while
+ 'varsofttabstop' is set.
+
+ *'vartabstop'* *'vts'*
+'vartabstop' 'vts' string (default "")
+ local to buffer
+ {only available when compiled with the |+vartabs|
+ feature}
+ {not in Vi}
+ A list of the number of spaces that a <Tab> in the file counts for,
+ separated by commas. Each value corresponds to one tab, with the
+ final value applying to all subsequent tabs. For example: >
+ :set vartabstop=4,20,10,8
+< This will make the first tab 4 spaces wide, the second 20 spaces,
+ the third 10 spaces, and all following tabs 8 spaces.
+
+ Note that the value of |'tabstop'| will be ignored while 'vartabstop'
+ is set.
+
*'verbose'* *'vbs'*
'verbose' 'vbs' number (default 0)
global
diff --git a/runtime/doc/various.txt b/runtime/doc/various.txt
index 7c8f3111c1..bd2b35ed74 100644
--- a/runtime/doc/various.txt
+++ b/runtime/doc/various.txt
@@ -453,6 +453,7 @@ N *+timers* the |timer_start()| function
N *+title* Setting the window 'title' and 'icon'
N *+toolbar* |gui-toolbar|
N *+user_commands* User-defined commands. |user-commands|
+B *+vartabs* Variable-width tabstops. |'vartabstop'|
N *+viminfo* |'viminfo'|
*+vertsplit* Vertically split windows |:vsplit|; Always enabled
since 8.0.1118.
diff --git a/runtime/optwin.vim b/runtime/optwin.vim
index cd1bea0cb2..5ab5792ae7 100644
--- a/runtime/optwin.vim
+++ b/runtime/optwin.vim
@@ -856,6 +856,14 @@ call <SID>OptionL("ts")
call append("$", "shiftwidth\tnumber of spaces used for each step of (auto)indent")
call append("$", "\t(local to buffer)")
call <SID>OptionL("sw")
+if has("vartabs")
+ call append("$", "vartabstop\tlist of number of spaces a tab counts for")
+ call append("$", "\t(local to buffer)")
+ call <SID>OptionL("vts")
+ call append("$", "varsofttabstop\tlist of number of spaces a soft tabsstop counts for")
+ call append("$", "\t(local to buffer)")
+ call <SID>OptionL("vsts")
+endif
call append("$", "smarttab\ta <Tab> in an indent inserts 'shiftwidth' spaces")
call <SID>BinOptionG("sta", &sta)
call append("$", "softtabstop\tif non-zero, number of spaces to insert for a <Tab>")
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_p