aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTJ DeVries <devries.timothyj@gmail.com>2016-06-10 11:21:49 -0400
committerMarco Hinz <mh.codebro@gmail.com>2016-06-14 20:10:11 +0200
commitaa22b5fd9a10a6094ea3d9cd88d3bfb3496a1acf (patch)
tree2351674920166351d59bf7f711a9ea6b6f2bd31f /src
parent20447ba0983a29537ae9d8df435fdf0f412c4258 (diff)
downloadrneovim-aa22b5fd9a10a6094ea3d9cd88d3bfb3496a1acf.tar.gz
rneovim-aa22b5fd9a10a6094ea3d9cd88d3bfb3496a1acf.tar.bz2
rneovim-aa22b5fd9a10a6094ea3d9cd88d3bfb3496a1acf.zip
Add new functionality to the `=` marker in the STL
This new functionality is explained in the documentation. Also, many tests have been added to the buffer_spec.lua file
Diffstat (limited to 'src')
-rw-r--r--src/nvim/buffer.c68
-rw-r--r--src/nvim/option.c7
-rw-r--r--src/nvim/option_defs.h4
3 files changed, 53 insertions, 26 deletions
diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c
index 71ec20c788..72724b0ffd 100644
--- a/src/nvim/buffer.c
+++ b/src/nvim/buffer.c
@@ -2849,7 +2849,7 @@ typedef enum {
/// is "curwin".
///
/// Items are drawn interspersed with the text that surrounds it
-/// Specials: %-<wid>(xxx%) => group, %= => middle marker, %< => truncation
+/// Specials: %-<wid>(xxx%) => group, %= => separation marker, %< => truncation
/// Item: %-<minwid>.<maxwid><itemch> All but <itemch> are optional
///
/// If maxwidth is not zero, the string will be filled at any middle marker
@@ -2893,7 +2893,7 @@ int build_stl_str_hl(
Normal,
Empty,
Group,
- Middle,
+ Separate,
Highlight,
TabPage,
ClickFunc,
@@ -2994,14 +2994,14 @@ int build_stl_str_hl(
continue;
}
- // STL_MIDDLEMARK: Separation place between left and right aligned items.
- if (*fmt_p == STL_MIDDLEMARK) {
+ // STL_SEPARATE: Separation place between left and right aligned items.
+ if (*fmt_p == STL_SEPARATE) {
fmt_p++;
// Ignored when we are inside of a grouping
if (groupdepth > 0) {
continue;
}
- item[curitem].type = Middle;
+ item[curitem].type = Separate;
item[curitem++].start = out_p;
continue;
}
@@ -3840,27 +3840,53 @@ int build_stl_str_hl(
width = maxwidth;
// If there is room left in our statusline, and room left in our buffer,
- // add characters at the middle marker (if there is one) to
+ // add characters at the separate marker (if there is one) to
// fill up the available space.
} else if (width < maxwidth
- && STRLEN(out) + maxwidth - width + 1 < outlen) {
- for (int item_idx = 0; item_idx < itemcnt; item_idx++) {
- if (item[item_idx].type == Middle) {
- // Move the statusline to make room for the middle characters
- char_u *middle_end = item[item_idx].start + (maxwidth - width);
- STRMOVE(middle_end, item[item_idx].start);
-
- // Fill the middle section with our fill character
- for (char_u *s = item[item_idx].start; s < middle_end; s++)
- *s = fillchar;
+ && STRLEN(out) + maxwidth - width + 1 < outlen) {
+ // Find how many separators there are, which we will use when
+ // figuring out how many groups there are.
+ int num_separators = 0;
+ for (int i = 0; i < itemcnt; i++) {
+ if (item[i].type == Separate) {
+ num_separators++;
+ }
+ }
- // Adjust the offset of any items after the middle
- for (item_idx++; item_idx < itemcnt; item_idx++)
- item[item_idx].start += maxwidth - width;
+ // If we have separated groups, then we deal with it now
+ if (num_separators) {
+ // Create an array of the start location for each
+ // separator mark.
+ int separator_locations[STL_MAX_ITEM];
+ int index = 0;
+ for (int i = 0; i < itemcnt; i++) {
+ if (item[i].type == Separate) {
+ separator_locations[index] = i;
+ index++;
+ }
+ }
- width = maxwidth;
- break;
+ int standard_spaces = (maxwidth - width) / num_separators;
+ int final_spaces = (maxwidth - width) -
+ standard_spaces * (num_separators - 1);
+
+ for (int i = 0; i < num_separators; i++) {
+ int dislocation = (i == (num_separators - 1)) ?
+ final_spaces : standard_spaces;
+ char_u *sep_loc = item[separator_locations[i]].start + dislocation;
+ STRMOVE(sep_loc, item[separator_locations[i]].start);
+ for (char_u *s = item[separator_locations[i]].start; s < sep_loc; s++) {
+ *s = fillchar;
+ }
+
+ for (int item_idx = separator_locations[i] + 1;
+ item_idx < itemcnt;
+ item_idx++) {
+ item[item_idx].start += dislocation;
+ }
}
+
+ width = maxwidth;
}
}
diff --git a/src/nvim/option.c b/src/nvim/option.c
index ac906d82ad..52a1fd8558 100644
--- a/src/nvim/option.c
+++ b/src/nvim/option.c
@@ -3403,9 +3403,10 @@ char_u *check_stl_option(char_u *s)
if (!*s)
break;
s++;
- if (*s != '%' && *s != ')')
- ++itemcnt;
- if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK) {
+ if (*s != '%' && *s != ')') {
+ itemcnt++;
+ }
+ if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_SEPARATE) {
s++;
continue;
}
diff --git a/src/nvim/option_defs.h b/src/nvim/option_defs.h
index 904e97f8ca..b1a2b00bdb 100644
--- a/src/nvim/option_defs.h
+++ b/src/nvim/option_defs.h
@@ -258,7 +258,7 @@ enum {
STL_ARGLISTSTAT = 'a', ///< Argument list status as (x of y).
STL_PAGENUM = 'N', ///< Page number (when printing).
STL_VIM_EXPR = '{', ///< Start of expression to substitute.
- STL_MIDDLEMARK = '=', ///< Separation between left and right.
+ STL_SEPARATE = '=', ///< Separation between alignment sections.
STL_TRUNCMARK = '<', ///< Truncation mark if line is too long.
STL_USER_HL = '*', ///< Highlight from (User)1..9 or 0.
STL_HIGHLIGHT = '#', ///< Highlight name.
@@ -274,7 +274,7 @@ enum {
STL_HELPFLAG, STL_HELPFLAG_ALT, STL_FILETYPE, STL_FILETYPE_ALT, \
STL_PREVIEWFLAG, STL_PREVIEWFLAG_ALT, STL_MODIFIED, STL_MODIFIED_ALT, \
STL_QUICKFIX, STL_PERCENTAGE, STL_ALTPERCENT, STL_ARGLISTSTAT, STL_PAGENUM, \
- STL_VIM_EXPR, STL_MIDDLEMARK, STL_TRUNCMARK, STL_USER_HL, STL_HIGHLIGHT, \
+ STL_VIM_EXPR, STL_SEPARATE, STL_TRUNCMARK, STL_USER_HL, STL_HIGHLIGHT, \
STL_TABPAGENR, STL_TABCLOSENR, STL_CLICK_FUNC, \
0, \
})