diff options
author | VVKot <volodymyr.kot.ua@gmail.com> | 2021-02-13 20:02:48 +0000 |
---|---|---|
committer | VVKot <volodymyr.kot.ua@gmail.com> | 2021-03-28 08:38:21 +0100 |
commit | 7fc58ec99a7546851d2a87b6548fd36d5d9c5abc (patch) | |
tree | e295de4e03277edc4b982a9bb420b7fa6c6b4a64 /src/nvim/option.c | |
parent | facb1d897e67f3ed71de658854d34cf48f4a3b98 (diff) | |
download | rneovim-7fc58ec99a7546851d2a87b6548fd36d5d9c5abc.tar.gz rneovim-7fc58ec99a7546851d2a87b6548fd36d5d9c5abc.tar.bz2 rneovim-7fc58ec99a7546851d2a87b6548fd36d5d9c5abc.zip |
vim-patch:8.1.0542: shiftwidth() does not take 'vartabstop' into account
Problem: shiftwidth() does not take 'vartabstop' into account.
Solution: Use the cursor position or a position explicitly passed.
Also make >> and << work better with 'vartabstop'. (Christian
Brabandt)
https://github.com/vim/vim/commit/f951416a8396a54bbbe21de1a8b16716428549f2
Diffstat (limited to 'src/nvim/option.c')
-rw-r--r-- | src/nvim/option.c | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/src/nvim/option.c b/src/nvim/option.c index 67740e8d9f..7d21086fd4 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -7342,11 +7342,39 @@ int tabstop_first(long *ts) /// 'tabstop' value when 'shiftwidth' is zero. int get_sw_value(buf_T *buf) { - long result = buf->b_p_sw ? buf->b_p_sw : buf->b_p_ts; + long result = get_sw_value_col(buf, 0); assert(result >= 0 && result <= INT_MAX); return (int)result; } +// Idem, using the first non-black in the current line. +long get_sw_value_indent(buf_T *buf) +{ + pos_T pos = curwin->w_cursor; + + pos.col = (colnr_T)getwhitecols_curline(); + return get_sw_value_pos(buf, &pos); +} + +// Idem, using "pos". +long get_sw_value_pos(buf_T *buf, pos_T *pos) +{ + pos_T save_cursor = curwin->w_cursor; + long sw_value; + + curwin->w_cursor = *pos; + sw_value = get_sw_value_col(buf, get_nolist_virtcol()); + curwin->w_cursor = save_cursor; + return sw_value; +} + +// Idem, using virtual column "col". +long get_sw_value_col(buf_T *buf, colnr_T col) +{ + return buf->b_p_sw ? buf->b_p_sw + : tabstop_at(col, buf->b_p_ts, buf->b_p_vts_array); +} + /// Return the effective softtabstop value for the current buffer, /// using the shiftwidth value when 'softtabstop' is negative. int get_sts_value(void) |