comparison src/charset.c @ 5995:ef83b423ebf7 v7.4.338

updated for version 7.4.338 Problem: Cannot wrap lines taking indent into account. Solution: Add the 'breakindent' option. (many authors, final improvements by Christian Brabandt)
author Bram Moolenaar <bram@vim.org>
date Wed, 25 Jun 2014 14:39:50 +0200
parents 50dbef5e774a
children b4962cf3a1c0
comparison
equal deleted inserted replaced
5994:ca18c797aafe 5995:ef83b423ebf7
865 linetabsize_col(startcol, s) 865 linetabsize_col(startcol, s)
866 int startcol; 866 int startcol;
867 char_u *s; 867 char_u *s;
868 { 868 {
869 colnr_T col = startcol; 869 colnr_T col = startcol;
870 char_u *line = s; /* pointer to start of line, for breakindent */
870 871
871 while (*s != NUL) 872 while (*s != NUL)
872 col += lbr_chartabsize_adv(&s, col); 873 col += lbr_chartabsize_adv(line, &s, col);
873 return (int)col; 874 return (int)col;
874 } 875 }
875 876
876 /* 877 /*
877 * Like linetabsize(), but for a given window instead of the current one. 878 * Like linetabsize(), but for a given window instead of the current one.
878 */ 879 */
879 int 880 int
880 win_linetabsize(wp, p, len) 881 win_linetabsize(wp, line, len)
881 win_T *wp; 882 win_T *wp;
882 char_u *p; 883 char_u *line;
883 colnr_T len; 884 colnr_T len;
884 { 885 {
885 colnr_T col = 0; 886 colnr_T col = 0;
886 char_u *s; 887 char_u *s;
887 888
888 for (s = p; *s != NUL && (len == MAXCOL || s < p + len); mb_ptr_adv(s)) 889 for (s = line; *s != NUL && (len == MAXCOL || s < line + len);
889 col += win_lbr_chartabsize(wp, s, col, NULL); 890 mb_ptr_adv(s))
891 col += win_lbr_chartabsize(wp, line, s, col, NULL);
890 return (int)col; 892 return (int)col;
891 } 893 }
892 894
893 /* 895 /*
894 * Return TRUE if 'c' is a normal identifier character: 896 * Return TRUE if 'c' is a normal identifier character:
1019 1021
1020 /* 1022 /*
1021 * like chartabsize(), but also check for line breaks on the screen 1023 * like chartabsize(), but also check for line breaks on the screen
1022 */ 1024 */
1023 int 1025 int
1024 lbr_chartabsize(s, col) 1026 lbr_chartabsize(line, s, col)
1027 char_u *line; /* start of the line */
1025 unsigned char *s; 1028 unsigned char *s;
1026 colnr_T col; 1029 colnr_T col;
1027 { 1030 {
1028 #ifdef FEAT_LINEBREAK 1031 #ifdef FEAT_LINEBREAK
1029 if (!curwin->w_p_lbr && *p_sbr == NUL) 1032 if (!curwin->w_p_lbr && *p_sbr == NUL && !curwin->w_p_bri)
1030 { 1033 {
1031 #endif 1034 #endif
1032 #ifdef FEAT_MBYTE 1035 #ifdef FEAT_MBYTE
1033 if (curwin->w_p_wrap) 1036 if (curwin->w_p_wrap)
1034 return win_nolbr_chartabsize(curwin, s, col, NULL); 1037 return win_nolbr_chartabsize(curwin, s, col, NULL);
1035 #endif 1038 #endif
1036 RET_WIN_BUF_CHARTABSIZE(curwin, curbuf, s, col) 1039 RET_WIN_BUF_CHARTABSIZE(curwin, curbuf, s, col)
1037 #ifdef FEAT_LINEBREAK 1040 #ifdef FEAT_LINEBREAK
1038 } 1041 }
1039 return win_lbr_chartabsize(curwin, s, col, NULL); 1042 return win_lbr_chartabsize(curwin, line == NULL ? s : line, s, col, NULL);
1040 #endif 1043 #endif
1041 } 1044 }
1042 1045
1043 /* 1046 /*
1044 * Call lbr_chartabsize() and advance the pointer. 1047 * Call lbr_chartabsize() and advance the pointer.
1045 */ 1048 */
1046 int 1049 int
1047 lbr_chartabsize_adv(s, col) 1050 lbr_chartabsize_adv(line, s, col)
1051 char_u *line; /* start of the line */
1048 char_u **s; 1052 char_u **s;
1049 colnr_T col; 1053 colnr_T col;
1050 { 1054 {
1051 int retval; 1055 int retval;
1052 1056
1053 retval = lbr_chartabsize(*s, col); 1057 retval = lbr_chartabsize(line, *s, col);
1054 mb_ptr_adv(*s); 1058 mb_ptr_adv(*s);
1055 return retval; 1059 return retval;
1056 } 1060 }
1057 1061
1058 /* 1062 /*
1061 * If "headp" not NULL, set *headp to the size of what we for 'showbreak' 1065 * If "headp" not NULL, set *headp to the size of what we for 'showbreak'
1062 * string at start of line. Warning: *headp is only set if it's a non-zero 1066 * string at start of line. Warning: *headp is only set if it's a non-zero
1063 * value, init to 0 before calling. 1067 * value, init to 0 before calling.
1064 */ 1068 */
1065 int 1069 int
1066 win_lbr_chartabsize(wp, s, col, headp) 1070 win_lbr_chartabsize(wp, line, s, col, headp)
1067 win_T *wp; 1071 win_T *wp;
1072 char_u *line; /* start of the line */
1068 char_u *s; 1073 char_u *s;
1069 colnr_T col; 1074 colnr_T col;
1070 int *headp UNUSED; 1075 int *headp UNUSED;
1071 { 1076 {
1072 #ifdef FEAT_LINEBREAK 1077 #ifdef FEAT_LINEBREAK
1084 char_u *ps; 1089 char_u *ps;
1085 int tab_corr = (*s == TAB); 1090 int tab_corr = (*s == TAB);
1086 int n; 1091 int n;
1087 1092
1088 /* 1093 /*
1089 * No 'linebreak' and 'showbreak': return quickly. 1094 * No 'linebreak', 'showbreak' and 'breakindent': return quickly.
1090 */ 1095 */
1091 if (!wp->w_p_lbr && *p_sbr == NUL) 1096 if (!wp->w_p_lbr && !wp->w_p_bri && *p_sbr == NUL)
1092 #endif 1097 #endif
1093 { 1098 {
1094 #ifdef FEAT_MBYTE 1099 #ifdef FEAT_MBYTE
1095 if (wp->w_p_wrap) 1100 if (wp->w_p_wrap)
1096 return win_nolbr_chartabsize(wp, s, col, headp); 1101 return win_nolbr_chartabsize(wp, s, col, headp);
1161 mb_added = 1; 1166 mb_added = 1;
1162 } 1167 }
1163 # endif 1168 # endif
1164 1169
1165 /* 1170 /*
1166 * May have to add something for 'showbreak' string at start of line 1171 * May have to add something for 'breakindent' and/or 'showbreak'
1172 * string at start of line.
1167 * Set *headp to the size of what we add. 1173 * Set *headp to the size of what we add.
1168 */ 1174 */
1169 added = 0; 1175 added = 0;
1170 if (*p_sbr != NUL && wp->w_p_wrap && col != 0) 1176 if ((*p_sbr != NUL || wp->w_p_bri) && wp->w_p_wrap && col != 0)
1171 { 1177 {
1172 numberextra = win_col_off(wp); 1178 numberextra = win_col_off(wp);
1173 col += numberextra + mb_added; 1179 col += numberextra + mb_added;
1174 if (col >= (colnr_T)W_WIDTH(wp)) 1180 if (col >= (colnr_T)W_WIDTH(wp))
1175 { 1181 {
1178 if (numberextra > 0) 1184 if (numberextra > 0)
1179 col = col % numberextra; 1185 col = col % numberextra;
1180 } 1186 }
1181 if (col == 0 || col + size > (colnr_T)W_WIDTH(wp)) 1187 if (col == 0 || col + size > (colnr_T)W_WIDTH(wp))
1182 { 1188 {
1183 added = vim_strsize(p_sbr); 1189 added = 0;
1190 if (*p_sbr != NUL)
1191 added += vim_strsize(p_sbr);
1192 if (wp->w_p_bri)
1193 added += get_breakindent_win(wp, line);
1194
1184 if (tab_corr) 1195 if (tab_corr)
1185 size += (added / wp->w_buffer->b_p_ts) * wp->w_buffer->b_p_ts; 1196 size += (added / wp->w_buffer->b_p_ts) * wp->w_buffer->b_p_ts;
1186 else 1197 else
1187 size += added; 1198 size += added;
1188 if (col != 0) 1199 if (col != 0)
1272 colnr_T *end; 1283 colnr_T *end;
1273 { 1284 {
1274 colnr_T vcol; 1285 colnr_T vcol;
1275 char_u *ptr; /* points to current char */ 1286 char_u *ptr; /* points to current char */
1276 char_u *posptr; /* points to char at pos->col */ 1287 char_u *posptr; /* points to char at pos->col */
1288 char_u *line; /* start of the line */
1277 int incr; 1289 int incr;
1278 int head; 1290 int head;
1279 int ts = wp->w_buffer->b_p_ts; 1291 int ts = wp->w_buffer->b_p_ts;
1280 int c; 1292 int c;
1281 1293
1282 vcol = 0; 1294 vcol = 0;
1283 ptr = ml_get_buf(wp->w_buffer, pos->lnum, FALSE); 1295 line = ptr = ml_get_buf(wp->w_buffer, pos->lnum, FALSE);
1284 if (pos->col == MAXCOL) 1296 if (pos->col == MAXCOL)
1285 posptr = NULL; /* continue until the NUL */ 1297 posptr = NULL; /* continue until the NUL */
1286 else 1298 else
1287 posptr = ptr + pos->col; 1299 posptr = ptr + pos->col;
1288 1300
1289 /* 1301 /*
1290 * This function is used very often, do some speed optimizations. 1302 * This function is used very often, do some speed optimizations.
1291 * When 'list', 'linebreak' and 'showbreak' are not set use a simple loop. 1303 * When 'list', 'linebreak', 'showbreak' and 'breakindent' are not set
1304 * use a simple loop.
1292 * Also use this when 'list' is set but tabs take their normal size. 1305 * Also use this when 'list' is set but tabs take their normal size.
1293 */ 1306 */
1294 if ((!wp->w_p_list || lcs_tab1 != NUL) 1307 if ((!wp->w_p_list || lcs_tab1 != NUL)
1295 #ifdef FEAT_LINEBREAK 1308 #ifdef FEAT_LINEBREAK
1296 && !wp->w_p_lbr && *p_sbr == NUL 1309 && !wp->w_p_lbr && *p_sbr == NUL && !wp->w_p_bri
1297 #endif 1310 #endif
1298 ) 1311 )
1299 { 1312 {
1300 #ifndef FEAT_MBYTE 1313 #ifndef FEAT_MBYTE
1301 head = 0; 1314 head = 0;
1353 { 1366 {
1354 for (;;) 1367 for (;;)
1355 { 1368 {
1356 /* A tab gets expanded, depending on the current column */ 1369 /* A tab gets expanded, depending on the current column */
1357 head = 0; 1370 head = 0;
1358 incr = win_lbr_chartabsize(wp, ptr, vcol, &head); 1371 incr = win_lbr_chartabsize(wp, line, ptr, vcol, &head);
1359 /* make sure we don't go past the end of the line */ 1372 /* make sure we don't go past the end of the line */
1360 if (*ptr == NUL) 1373 if (*ptr == NUL)
1361 { 1374 {
1362 incr = 1; /* NUL at end of line only takes one column */ 1375 incr = 1; /* NUL at end of line only takes one column */
1363 break; 1376 break;