build_stl_str_hl: Array name should be plural.

This commit is contained in:
Justin M. Keyes 2017-04-28 02:20:40 +02:00
parent 56911050e0
commit 2b6a3819e5

View File

@ -3060,7 +3060,7 @@ int build_stl_str_hl(
StlClickRecord *tabtab StlClickRecord *tabtab
) )
{ {
int groupitem[STL_MAX_ITEM]; int groupitems[STL_MAX_ITEM];
struct stl_item { struct stl_item {
// Where the item starts in the status line output buffer // Where the item starts in the status line output buffer
char_u *start; char_u *start;
@ -3080,7 +3080,7 @@ int build_stl_str_hl(
ClickFunc, ClickFunc,
Trunc Trunc
} type; } type;
} item[STL_MAX_ITEM]; } items[STL_MAX_ITEM];
#define TMPLEN 70 #define TMPLEN 70
char_u tmp[TMPLEN]; char_u tmp[TMPLEN];
char_u *usefmt = fmt; char_u *usefmt = fmt;
@ -3182,16 +3182,16 @@ int build_stl_str_hl(
if (groupdepth > 0) { if (groupdepth > 0) {
continue; continue;
} }
item[curitem].type = Separate; items[curitem].type = Separate;
item[curitem++].start = out_p; items[curitem++].start = out_p;
continue; continue;
} }
// STL_TRUNCMARK: Where to begin truncating if the statusline is too long. // STL_TRUNCMARK: Where to begin truncating if the statusline is too long.
if (*fmt_p == STL_TRUNCMARK) { if (*fmt_p == STL_TRUNCMARK) {
fmt_p++; fmt_p++;
item[curitem].type = Trunc; items[curitem].type = Trunc;
item[curitem++].start = out_p; items[curitem++].start = out_p;
continue; continue;
} }
@ -3207,7 +3207,7 @@ int build_stl_str_hl(
// Determine how long the group is. // Determine how long the group is.
// Note: We set the current output position to null // Note: We set the current output position to null
// so `vim_strsize` will work. // so `vim_strsize` will work.
char_u *t = item[groupitem[groupdepth]].start; char_u *t = items[groupitems[groupdepth]].start;
*out_p = NUL; *out_p = NUL;
long group_len = vim_strsize(t); long group_len = vim_strsize(t);
@ -3217,11 +3217,11 @@ int build_stl_str_hl(
// move the output pointer back to where the group started. // move the output pointer back to where the group started.
// Note: This erases any non-item characters that were in the group. // Note: This erases any non-item characters that were in the group.
// Otherwise there would be no reason to do this step. // Otherwise there would be no reason to do this step.
if (curitem > groupitem[groupdepth] + 1 if (curitem > groupitems[groupdepth] + 1
&& item[groupitem[groupdepth]].minwid == 0) { && items[groupitems[groupdepth]].minwid == 0) {
bool has_normal_items = false; bool has_normal_items = false;
for (long n = groupitem[groupdepth] + 1; n < curitem; n++) { for (long n = groupitems[groupdepth] + 1; n < curitem; n++) {
if (item[n].type == Normal || item[n].type == Highlight) { if (items[n].type == Normal || items[n].type == Highlight) {
has_normal_items = true; has_normal_items = true;
break; break;
} }
@ -3235,18 +3235,18 @@ int build_stl_str_hl(
// If the group is longer than it is allowed to be // If the group is longer than it is allowed to be
// truncate by removing bytes from the start of the group text. // truncate by removing bytes from the start of the group text.
if (group_len > item[groupitem[groupdepth]].maxwid) { if (group_len > items[groupitems[groupdepth]].maxwid) {
// { Determine the number of bytes to remove // { Determine the number of bytes to remove
long n; long n;
if (has_mbyte) { if (has_mbyte) {
/* Find the first character that should be included. */ /* Find the first character that should be included. */
n = 0; n = 0;
while (group_len >= item[groupitem[groupdepth]].maxwid) { while (group_len >= items[groupitems[groupdepth]].maxwid) {
group_len -= ptr2cells(t + n); group_len -= ptr2cells(t + n);
n += (*mb_ptr2len)(t + n); n += (*mb_ptr2len)(t + n);
} }
} else { } else {
n = (long)(out_p - t) - item[groupitem[groupdepth]].maxwid + 1; n = (long)(out_p - t) - items[groupitems[groupdepth]].maxwid + 1;
} }
// } // }
@ -3257,24 +3257,24 @@ int build_stl_str_hl(
memmove(t + 1, t + n, (size_t)(out_p - (t + n))); memmove(t + 1, t + n, (size_t)(out_p - (t + n)));
out_p = out_p - n + 1; out_p = out_p - n + 1;
/* Fill up space left over by half a double-wide char. */ /* Fill up space left over by half a double-wide char. */
while (++group_len < item[groupitem[groupdepth]].minwid) while (++group_len < items[groupitems[groupdepth]].minwid)
*out_p++ = fillchar; *out_p++ = fillchar;
// } // }
/* correct the start of the items for the truncation */ /* correct the start of the items for the truncation */
for (int idx = groupitem[groupdepth] + 1; idx < curitem; idx++) { for (int idx = groupitems[groupdepth] + 1; idx < curitem; idx++) {
// Shift everything back by the number of removed bytes // Shift everything back by the number of removed bytes
item[idx].start -= n; items[idx].start -= n;
// If the item was partially or completely truncated, set its // If the item was partially or completely truncated, set its
// start to the start of the group // start to the start of the group
if (item[idx].start < t) { if (items[idx].start < t) {
item[idx].start = t; items[idx].start = t;
} }
} }
// If the group is shorter than the minimum width, add padding characters. // If the group is shorter than the minimum width, add padding characters.
} else if (abs(item[groupitem[groupdepth]].minwid) > group_len) { } else if (abs(items[groupitems[groupdepth]].minwid) > group_len) {
long min_group_width = item[groupitem[groupdepth]].minwid; long min_group_width = items[groupitems[groupdepth]].minwid;
// If the group is left-aligned, add characters to the right. // If the group is left-aligned, add characters to the right.
if (min_group_width < 0) { if (min_group_width < 0) {
min_group_width = 0 - min_group_width; min_group_width = 0 - min_group_width;
@ -3293,8 +3293,8 @@ int build_stl_str_hl(
// } // }
// Adjust item start positions // Adjust item start positions
for (int n = groupitem[groupdepth] + 1; n < curitem; n++) { for (int n = groupitems[groupdepth] + 1; n < curitem; n++) {
item[n].start += group_len; items[n].start += group_len;
} }
// Prepend the fill characters // Prepend the fill characters
@ -3332,9 +3332,9 @@ int build_stl_str_hl(
// User highlight groups override the min width field // User highlight groups override the min width field
// to denote the styling to use. // to denote the styling to use.
if (*fmt_p == STL_USER_HL) { if (*fmt_p == STL_USER_HL) {
item[curitem].type = Highlight; items[curitem].type = Highlight;
item[curitem].start = out_p; items[curitem].start = out_p;
item[curitem].minwid = minwid > 9 ? 1 : minwid; items[curitem].minwid = minwid > 9 ? 1 : minwid;
fmt_p++; fmt_p++;
curitem++; curitem++;
continue; continue;
@ -3369,17 +3369,17 @@ int build_stl_str_hl(
/* %X ends the close label, go back to the previously /* %X ends the close label, go back to the previously
* define tab label nr. */ * define tab label nr. */
for (long n = curitem - 1; n >= 0; --n) for (long n = curitem - 1; n >= 0; --n)
if (item[n].type == TabPage && item[n].minwid >= 0) { if (items[n].type == TabPage && items[n].minwid >= 0) {
minwid = item[n].minwid; minwid = items[n].minwid;
break; break;
} }
} else } else
/* close nrs are stored as negative values */ /* close nrs are stored as negative values */
minwid = -minwid; minwid = -minwid;
} }
item[curitem].type = TabPage; items[curitem].type = TabPage;
item[curitem].start = out_p; items[curitem].start = out_p;
item[curitem].minwid = minwid; items[curitem].minwid = minwid;
fmt_p++; fmt_p++;
curitem++; curitem++;
continue; continue;
@ -3394,10 +3394,10 @@ int build_stl_str_hl(
if (*fmt_p != STL_CLICK_FUNC) { if (*fmt_p != STL_CLICK_FUNC) {
break; break;
} }
item[curitem].type = ClickFunc; items[curitem].type = ClickFunc;
item[curitem].start = out_p; items[curitem].start = out_p;
item[curitem].cmd = xmemdupz(t, (size_t) (((char *) fmt_p - t))); items[curitem].cmd = xmemdupz(t, (size_t) (((char *) fmt_p - t)));
item[curitem].minwid = minwid; items[curitem].minwid = minwid;
fmt_p++; fmt_p++;
curitem++; curitem++;
continue; continue;
@ -3420,11 +3420,11 @@ int build_stl_str_hl(
// Denotes the start of a new group // Denotes the start of a new group
if (*fmt_p == '(') { if (*fmt_p == '(') {
groupitem[groupdepth++] = curitem; groupitems[groupdepth++] = curitem;
item[curitem].type = Group; items[curitem].type = Group;
item[curitem].start = out_p; items[curitem].start = out_p;
item[curitem].minwid = minwid; items[curitem].minwid = minwid;
item[curitem].maxwid = maxwid; items[curitem].maxwid = maxwid;
fmt_p++; fmt_p++;
curitem++; curitem++;
continue; continue;
@ -3451,7 +3451,7 @@ int build_stl_str_hl(
case STL_FULLPATH: case STL_FULLPATH:
case STL_FILENAME: case STL_FILENAME:
{ {
// Set fillable to false to that ' ' in the filename will not // Set fillable to false so that ' ' in the filename will not
// get replaced with the fillchar // get replaced with the fillchar
fillable = false; fillable = false;
if (buf_spname(wp->w_buffer) != NULL) { if (buf_spname(wp->w_buffer) != NULL) {
@ -3703,9 +3703,9 @@ int build_stl_str_hl(
// Create a highlight item based on the name // Create a highlight item based on the name
if (*fmt_p == '#') { if (*fmt_p == '#') {
item[curitem].type = Highlight; items[curitem].type = Highlight;
item[curitem].start = out_p; items[curitem].start = out_p;
item[curitem].minwid = -syn_namen2id(t, (int)(fmt_p - t)); items[curitem].minwid = -syn_namen2id(t, (int)(fmt_p - t));
curitem++; curitem++;
fmt_p++; fmt_p++;
} }
@ -3716,8 +3716,8 @@ int build_stl_str_hl(
// If we made it this far, the item is normal and starts at // If we made it this far, the item is normal and starts at
// our current position in the output buffer. // our current position in the output buffer.
// Non-normal items would have `continued`. // Non-normal items would have `continued`.
item[curitem].start = out_p; items[curitem].start = out_p;
item[curitem].type = Normal; items[curitem].type = Normal;
// Copy the item string into the output buffer // Copy the item string into the output buffer
if (str != NULL && *str) { if (str != NULL && *str) {
@ -3874,7 +3874,7 @@ int build_stl_str_hl(
// Otherwise, there was nothing to print so mark the item as empty // Otherwise, there was nothing to print so mark the item as empty
} else { } else {
item[curitem].type = Empty; items[curitem].type = Empty;
} }
// Only free the string buffer if we allocated it. // Only free the string buffer if we allocated it.
@ -3899,8 +3899,7 @@ int build_stl_str_hl(
} }
// We have now processed the entire statusline format string. // We have now processed the entire statusline format string.
// What follows is post-processing to handle alignment and // What follows is post-processing to handle alignment and highlighting.
// highlighting factors.
int width = vim_strsize(out); int width = vim_strsize(out);
if (maxwidth > 0 && width > maxwidth) { if (maxwidth > 0 && width > maxwidth) {
@ -3915,13 +3914,13 @@ int build_stl_str_hl(
// Otherwise, look for the truncation item // Otherwise, look for the truncation item
} else { } else {
// Default to truncating at the first item // Default to truncating at the first item
trunc_p = item[0].start; trunc_p = items[0].start;
item_idx = 0; item_idx = 0;
for (int i = 0; i < itemcnt; i++) for (int i = 0; i < itemcnt; i++)
if (item[i].type == Trunc) { if (items[i].type == Trunc) {
// Truncate at %< item. // Truncate at %< items.
trunc_p = item[i].start; trunc_p = items[i].start;
item_idx = i; item_idx = i;
break; break;
} }
@ -3954,7 +3953,7 @@ int build_stl_str_hl(
// Ignore any items in the statusline that occur after // Ignore any items in the statusline that occur after
// the truncation point // the truncation point
for (int i = 0; i < itemcnt; i++) { for (int i = 0; i < itemcnt; i++) {
if (item[i].start > trunc_p) { if (items[i].start > trunc_p) {
itemcnt = i; itemcnt = i;
break; break;
} }
@ -4009,12 +4008,12 @@ int build_stl_str_hl(
for (int i = item_idx; i < itemcnt; i++) { for (int i = item_idx; i < itemcnt; i++) {
// Items starting at or after the end of the truncated section need // Items starting at or after the end of the truncated section need
// to be moved backwards. // to be moved backwards.
if (item[i].start >= trunc_end_p) { if (items[i].start >= trunc_end_p) {
item[i].start -= item_offset; items[i].start -= item_offset;
// Anything inside the truncated area is set to start // Anything inside the truncated area is set to start
// at the `<` truncation character. // at the `<` truncation character.
} else { } else {
item[i].start = trunc_p; items[i].start = trunc_p;
} }
} }
// } // }
@ -4030,7 +4029,7 @@ int build_stl_str_hl(
// figuring out how many groups there are. // figuring out how many groups there are.
int num_separators = 0; int num_separators = 0;
for (int i = 0; i < itemcnt; i++) { for (int i = 0; i < itemcnt; i++) {
if (item[i].type == Separate) { if (items[i].type == Separate) {
num_separators++; num_separators++;
} }
} }
@ -4042,7 +4041,7 @@ int build_stl_str_hl(
int separator_locations[STL_MAX_ITEM]; int separator_locations[STL_MAX_ITEM];
int index = 0; int index = 0;
for (int i = 0; i < itemcnt; i++) { for (int i = 0; i < itemcnt; i++) {
if (item[i].type == Separate) { if (items[i].type == Separate) {
separator_locations[index] = i; separator_locations[index] = i;
index++; index++;
} }
@ -4055,16 +4054,16 @@ int build_stl_str_hl(
for (int i = 0; i < num_separators; i++) { for (int i = 0; i < num_separators; i++) {
int dislocation = (i == (num_separators - 1)) ? int dislocation = (i == (num_separators - 1)) ?
final_spaces : standard_spaces; final_spaces : standard_spaces;
char_u *sep_loc = item[separator_locations[i]].start + dislocation; char_u *sep_loc = items[separator_locations[i]].start + dislocation;
STRMOVE(sep_loc, item[separator_locations[i]].start); STRMOVE(sep_loc, items[separator_locations[i]].start);
for (char_u *s = item[separator_locations[i]].start; s < sep_loc; s++) { for (char_u *s = items[separator_locations[i]].start; s < sep_loc; s++) {
*s = fillchar; *s = fillchar;
} }
for (int item_idx = separator_locations[i] + 1; for (int item_idx = separator_locations[i] + 1;
item_idx < itemcnt; item_idx < itemcnt;
item_idx++) { item_idx++) {
item[item_idx].start += dislocation; items[item_idx].start += dislocation;
} }
} }
@ -4076,9 +4075,9 @@ int build_stl_str_hl(
if (hltab != NULL) { if (hltab != NULL) {
struct stl_hlrec *sp = hltab; struct stl_hlrec *sp = hltab;
for (long l = 0; l < itemcnt; l++) { for (long l = 0; l < itemcnt; l++) {
if (item[l].type == Highlight) { if (items[l].type == Highlight) {
sp->start = item[l].start; sp->start = items[l].start;
sp->userhl = item[l].minwid; sp->userhl = items[l].minwid;
sp++; sp++;
} }
} }
@ -4090,14 +4089,14 @@ int build_stl_str_hl(
if (tabtab != NULL) { if (tabtab != NULL) {
StlClickRecord *cur_tab_rec = tabtab; StlClickRecord *cur_tab_rec = tabtab;
for (long l = 0; l < itemcnt; l++) { for (long l = 0; l < itemcnt; l++) {
if (item[l].type == TabPage) { if (items[l].type == TabPage) {
cur_tab_rec->start = (char *) item[l].start; cur_tab_rec->start = (char *) items[l].start;
if (item[l].minwid == 0) { if (items[l].minwid == 0) {
cur_tab_rec->def.type = kStlClickDisabled; cur_tab_rec->def.type = kStlClickDisabled;
cur_tab_rec->def.tabnr = 0; cur_tab_rec->def.tabnr = 0;
} else { } else {
int tabnr = item[l].minwid; int tabnr = items[l].minwid;
if (item[l].minwid > 0) { if (items[l].minwid > 0) {
cur_tab_rec->def.type = kStlClickTabSwitch; cur_tab_rec->def.type = kStlClickTabSwitch;
} else { } else {
cur_tab_rec->def.type = kStlClickTabClose; cur_tab_rec->def.type = kStlClickTabClose;
@ -4107,11 +4106,11 @@ int build_stl_str_hl(
} }
cur_tab_rec->def.func = NULL; cur_tab_rec->def.func = NULL;
cur_tab_rec++; cur_tab_rec++;
} else if (item[l].type == ClickFunc) { } else if (items[l].type == ClickFunc) {
cur_tab_rec->start = (char *) item[l].start; cur_tab_rec->start = (char *) items[l].start;
cur_tab_rec->def.type = kStlClickFuncRun; cur_tab_rec->def.type = kStlClickFuncRun;
cur_tab_rec->def.tabnr = item[l].minwid; cur_tab_rec->def.tabnr = items[l].minwid;
cur_tab_rec->def.func = item[l].cmd; cur_tab_rec->def.func = items[l].cmd;
cur_tab_rec++; cur_tab_rec++;
} }
} }