Mercurial > vim
comparison src/charset.c @ 14175:2ad722003b36 v8.1.0105
patch 8.1.0105: all tab stops are the same
commit https://github.com/vim/vim/commit/04958cbaf25eea27eceedaa987adfb354ad5f7fd
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Jun 23 19:23:02 2018 +0200
patch 8.1.0105: all tab stops are the same
Problem: All tab stops are the same.
Solution: Add the variable tabstop feature. (Christian Brabandt,
closes #2711)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sat, 23 Jun 2018 19:30:07 +0200 |
parents | 47b2db8a5709 |
children | 27b9a84395b5 |
comparison
equal
deleted
inserted
replaced
14174:d36eedd19166 | 14175:2ad722003b36 |
---|---|
810 * into account the size of a tab. | 810 * into account the size of a tab. |
811 * Use a define to make it fast, this is used very often!!! | 811 * Use a define to make it fast, this is used very often!!! |
812 * Also see getvcol() below. | 812 * Also see getvcol() below. |
813 */ | 813 */ |
814 | 814 |
815 #define RET_WIN_BUF_CHARTABSIZE(wp, buf, p, col) \ | 815 #ifdef FEAT_VARTABS |
816 # define RET_WIN_BUF_CHARTABSIZE(wp, buf, p, col) \ | |
817 if (*(p) == TAB && (!(wp)->w_p_list || lcs_tab1)) \ | |
818 { \ | |
819 return tabstop_padding(col, (buf)->b_p_ts, (buf)->b_p_vts_array); \ | |
820 } \ | |
821 else \ | |
822 return ptr2cells(p); | |
823 #else | |
824 # define RET_WIN_BUF_CHARTABSIZE(wp, buf, p, col) \ | |
816 if (*(p) == TAB && (!(wp)->w_p_list || lcs_tab1)) \ | 825 if (*(p) == TAB && (!(wp)->w_p_list || lcs_tab1)) \ |
817 { \ | 826 { \ |
818 int ts; \ | 827 int ts; \ |
819 ts = (buf)->b_p_ts; \ | 828 ts = (buf)->b_p_ts; \ |
820 return (int)(ts - (col % ts)); \ | 829 return (int)(ts - (col % ts)); \ |
821 } \ | 830 } \ |
822 else \ | 831 else \ |
823 return ptr2cells(p); | 832 return ptr2cells(p); |
833 #endif | |
824 | 834 |
825 int | 835 int |
826 chartabsize(char_u *p, colnr_T col) | 836 chartabsize(char_u *p, colnr_T col) |
827 { | 837 { |
828 RET_WIN_BUF_CHARTABSIZE(curwin, curbuf, p, col) | 838 RET_WIN_BUF_CHARTABSIZE(curwin, curbuf, p, col) |
1219 { | 1229 { |
1220 int n; | 1230 int n; |
1221 | 1231 |
1222 if (*s == TAB && (!wp->w_p_list || lcs_tab1)) | 1232 if (*s == TAB && (!wp->w_p_list || lcs_tab1)) |
1223 { | 1233 { |
1234 # ifdef FEAT_VARTABS | |
1235 return tabstop_padding(col, wp->w_buffer->b_p_ts, | |
1236 wp->w_buffer->b_p_vts_array); | |
1237 # else | |
1224 n = wp->w_buffer->b_p_ts; | 1238 n = wp->w_buffer->b_p_ts; |
1225 return (int)(n - (col % n)); | 1239 return (int)(n - (col % n)); |
1240 # endif | |
1226 } | 1241 } |
1227 n = ptr2cells(s); | 1242 n = ptr2cells(s); |
1228 /* Add one cell for a double-width character in the last column of the | 1243 /* Add one cell for a double-width character in the last column of the |
1229 * window, displayed with a ">". */ | 1244 * window, displayed with a ">". */ |
1230 if (n == 2 && MB_BYTE2LEN(*s) > 1 && in_win_border(wp, col)) | 1245 if (n == 2 && MB_BYTE2LEN(*s) > 1 && in_win_border(wp, col)) |
1280 char_u *ptr; /* points to current char */ | 1295 char_u *ptr; /* points to current char */ |
1281 char_u *posptr; /* points to char at pos->col */ | 1296 char_u *posptr; /* points to char at pos->col */ |
1282 char_u *line; /* start of the line */ | 1297 char_u *line; /* start of the line */ |
1283 int incr; | 1298 int incr; |
1284 int head; | 1299 int head; |
1300 #ifdef FEAT_VARTABS | |
1301 int *vts = wp->w_buffer->b_p_vts_array; | |
1302 #endif | |
1285 int ts = wp->w_buffer->b_p_ts; | 1303 int ts = wp->w_buffer->b_p_ts; |
1286 int c; | 1304 int c; |
1287 | 1305 |
1288 vcol = 0; | 1306 vcol = 0; |
1289 line = ptr = ml_get_buf(wp->w_buffer, pos->lnum, FALSE); | 1307 line = ptr = ml_get_buf(wp->w_buffer, pos->lnum, FALSE); |
1330 incr = 1; /* NUL at end of line only takes one column */ | 1348 incr = 1; /* NUL at end of line only takes one column */ |
1331 break; | 1349 break; |
1332 } | 1350 } |
1333 /* A tab gets expanded, depending on the current column */ | 1351 /* A tab gets expanded, depending on the current column */ |
1334 if (c == TAB) | 1352 if (c == TAB) |
1353 #ifdef FEAT_VARTABS | |
1354 incr = tabstop_padding(vcol, ts, vts); | |
1355 #else | |
1335 incr = ts - (vcol % ts); | 1356 incr = ts - (vcol % ts); |
1357 #endif | |
1336 else | 1358 else |
1337 { | 1359 { |
1338 #ifdef FEAT_MBYTE | 1360 #ifdef FEAT_MBYTE |
1339 if (has_mbyte) | 1361 if (has_mbyte) |
1340 { | 1362 { |