aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2023-02-11 20:00:31 +0800
committerGitHub <noreply@github.com>2023-02-11 20:00:31 +0800
commit374955bcc571dff05f068ec18d0f578d1f334c5f (patch)
tree7abf6225aa4751316e1d6df16c3fcd3b4d311861
parent414ff7742faad10f407f141534d5314acda0ec70 (diff)
downloadrneovim-374955bcc571dff05f068ec18d0f578d1f334c5f.tar.gz
rneovim-374955bcc571dff05f068ec18d0f578d1f334c5f.tar.bz2
rneovim-374955bcc571dff05f068ec18d0f578d1f334c5f.zip
vim-patch:9.0.1300: 'statusline' only supports one "%=" item (#22218)
Problem: 'statusline' only supports one "%=" item. Solution: Add support for multiple "%=" items. (TJ DeVries, Yegappan Lakshmanan, closes vim/vim#11970, closes vim/vim#11965) https://github.com/vim/vim/commit/3ec78f973fdaec2cea8e036ed38037b2fe40670b Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
-rw-r--r--runtime/doc/options.txt6
-rw-r--r--runtime/doc/vim_diff.txt2
-rw-r--r--src/nvim/statusline.c13
-rw-r--r--src/nvim/testdir/test_statusline.vim4
4 files changed, 15 insertions, 10 deletions
diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt
index 17f1c822ff..e4106358f1 100644
--- a/runtime/doc/options.txt
+++ b/runtime/doc/options.txt
@@ -6201,8 +6201,10 @@ A jump table for the options with a short description can be found at |Q_op|.
this label.
< - Where to truncate line if too long. Default is at the start.
No width fields allowed.
- = - Separation point between alignment sections. Each section will
- be separated by an equal number of spaces.
+ = - Separation point between alignment sections. Each section will
+ be separated by an equal number of spaces. With one %= what
+ comes after it will be right-aligned. With two %= there is a
+ middle part, with white space left and right of it.
No width fields allowed.
# - Set highlight group. The name must follow and then a # again.
Thus use %#HLname# for highlight group HLname. The same
diff --git a/runtime/doc/vim_diff.txt b/runtime/doc/vim_diff.txt
index bb3b670b24..97fc211c36 100644
--- a/runtime/doc/vim_diff.txt
+++ b/runtime/doc/vim_diff.txt
@@ -267,7 +267,6 @@ Options:
'pumblend' pseudo-transparent popupmenu
'scrollback'
'signcolumn' supports up to 9 dynamic/fixed columns
- 'statusline' supports unlimited alignment sections
'tabline' %@Func@foo%X can call any function on mouse-click
'winblend' pseudo-transparency in floating windows |api-floatwin|
'winhighlight' window-local highlights
@@ -292,6 +291,7 @@ These Nvim features were later integrated into Vim.
- |WinScrolled|
- |:sign-define| "numhl" argument
- |:source| works with anonymous (no file) scripts
+- 'statusline' supports unlimited alignment sections
==============================================================================
5. Changed features *nvim-features-changed*
diff --git a/src/nvim/statusline.c b/src/nvim/statusline.c
index a094a5f945..6e0dc2e8f7 100644
--- a/src/nvim/statusline.c
+++ b/src/nvim/statusline.c
@@ -1094,7 +1094,7 @@ int build_stl_str_hl(win_T *wp, char *out, size_t outlen, char *fmt, char *opt_n
continue;
}
- // STL_SEPARATE: Separation place between left and right aligned items.
+ // STL_SEPARATE: Separation between items, filled with white space.
if (*fmt_p == STL_SEPARATE) {
fmt_p++;
// Ignored when we are inside of a grouping
@@ -2066,8 +2066,7 @@ int build_stl_str_hl(win_T *wp, char *out, size_t outlen, char *fmt, char *opt_n
int num_separators = 0;
for (int i = 0; i < itemcnt; i++) {
if (stl_items[i].type == Separate) {
- // Create an array of the start location for each
- // separator mark.
+ // Create an array of the start location for each separator mark.
stl_separator_locations[num_separators] = i;
num_separators++;
}
@@ -2079,17 +2078,17 @@ int build_stl_str_hl(win_T *wp, char *out, size_t outlen, char *fmt, char *opt_n
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;
+ for (int l = 0; l < num_separators; l++) {
+ int dislocation = (l == (num_separators - 1)) ? final_spaces : standard_spaces;
dislocation *= utf_char2len(fillchar);
- char *start = stl_items[stl_separator_locations[i]].start;
+ char *start = stl_items[stl_separator_locations[l]].start;
char *seploc = start + dislocation;
STRMOVE(seploc, start);
for (char *s = start; s < seploc;) {
MB_CHAR2BYTES(fillchar, s);
}
- for (int item_idx = stl_separator_locations[i] + 1;
+ for (int item_idx = stl_separator_locations[l] + 1;
item_idx < itemcnt;
item_idx++) {
stl_items[item_idx].start += dislocation;
diff --git a/src/nvim/testdir/test_statusline.vim b/src/nvim/testdir/test_statusline.vim
index 990c852ccd..1e06ad1c67 100644
--- a/src/nvim/testdir/test_statusline.vim
+++ b/src/nvim/testdir/test_statusline.vim
@@ -231,6 +231,10 @@ func Test_statusline()
" %=: Separation point between left and right aligned items.
set statusline=foo%=bar
call assert_match('^foo\s\+bar\s*$', s:get_statusline())
+ set statusline=foo%=bar%=baz
+ call assert_match('^foo\s\+bar\s\+baz\s*$', s:get_statusline())
+ set statusline=foo%=bar%=baz%=qux
+ call assert_match('^foo\s\+bar\s\+baz\s\+qux\s*$', s:get_statusline())
" Test min/max width, leading zeroes, left/right justify.
set statusline=%04B