mirror of
https://github.com/neovim/neovim.git
synced 2025-09-28 14:08:32 +00:00
feat(column)!: rework 'statuscolumn' %r/l items
Problem: A custom 'statuscolumn' needs to check a bunch of options and placed signs to replicate the default number column. Solution: Rework %l item to include the necessary logic to mimic the default number column. Remove now redundant %r item.
This commit is contained in:
@@ -587,12 +587,13 @@ static void draw_statuscol(win_T *wp, winlinevars_T *wlv, linenr_T lnum, int vir
|
||||
|
||||
char buf[MAXPATHL];
|
||||
// When a buffer's line count has changed, make a best estimate for the full
|
||||
// width of the status column by building with "w_nrwidth_line_count". Add
|
||||
// potentially truncated width and rebuild before drawing anything.
|
||||
// width of the status column by building with the largest possible line number.
|
||||
// Add potentially truncated width and rebuild before drawing anything.
|
||||
if (wp->w_statuscol_line_count != wp->w_nrwidth_line_count) {
|
||||
wp->w_statuscol_line_count = wp->w_nrwidth_line_count;
|
||||
set_vim_var_nr(VV_VIRTNUM, 0);
|
||||
int width = build_statuscol_str(wp, wp->w_nrwidth_line_count, 0, buf, stcp);
|
||||
int width = build_statuscol_str(wp, wp->w_nrwidth_line_count,
|
||||
wp->w_nrwidth_line_count, buf, stcp);
|
||||
if (width > stcp->width) {
|
||||
int addwidth = MIN(width - stcp->width, MAX_STCWIDTH - stcp->width);
|
||||
wp->w_nrwidth += addwidth;
|
||||
|
@@ -8037,8 +8037,7 @@ return {
|
||||
Some of the items from the 'statusline' format are different for
|
||||
'statuscolumn':
|
||||
|
||||
%l line number of currently drawn line
|
||||
%r relative line number of currently drawn line
|
||||
%l line number column for currently drawn line
|
||||
%s sign column for currently drawn line
|
||||
%C fold column for currently drawn line
|
||||
|
||||
@@ -8065,11 +8064,8 @@ return {
|
||||
handler should be written with this in mind.
|
||||
|
||||
Examples: >vim
|
||||
" Relative number with bar separator and click handlers:
|
||||
set statuscolumn=%@SignCb@%s%=%T%@NumCb@%r│%T
|
||||
|
||||
" Right aligned relative cursor line number:
|
||||
let &stc='%=%{v:relnum?v:relnum:v:lnum} '
|
||||
" Line number with bar separator and click handlers:
|
||||
set statuscolumn=%@SignCb@%s%=%T%@NumCb@%l│%T
|
||||
|
||||
" Line numbers in hexadecimal for non wrapped part of lines:
|
||||
let &stc='%=%{v:virtnum>0?"":printf("%x",v:lnum)} '
|
||||
|
@@ -1017,7 +1017,6 @@ int build_stl_str_hl(win_T *wp, char *out, size_t outlen, char *fmt, OptIndex op
|
||||
int evaldepth = 0;
|
||||
|
||||
int curitem = 0;
|
||||
int foldsignitem = -1;
|
||||
bool prevchar_isflag = true;
|
||||
bool prevchar_isitem = false;
|
||||
|
||||
@@ -1234,6 +1233,8 @@ int build_stl_str_hl(win_T *wp, char *out, size_t outlen, char *fmt, OptIndex op
|
||||
}
|
||||
int minwid = 0;
|
||||
int maxwid = 9999;
|
||||
int foldsignitem = -1; // Start of fold or sign item
|
||||
bool left_align_num = false; // Number item for should be left-aligned
|
||||
bool left_align = false;
|
||||
|
||||
// Denotes that numbers should be left-padded with zeros
|
||||
@@ -1505,12 +1506,20 @@ int build_stl_str_hl(win_T *wp, char *out, size_t outlen, char *fmt, OptIndex op
|
||||
}
|
||||
|
||||
case STL_LINE:
|
||||
// Overload %l with v:lnum for 'statuscolumn'
|
||||
if (stcp != NULL) {
|
||||
if (wp->w_p_nu && !get_vim_var_nr(VV_VIRTNUM)) {
|
||||
num = (int)get_vim_var_nr(VV_LNUM);
|
||||
// Overload %l with v:(re)lnum for 'statuscolumn'. Place a sign when 'signcolumn'
|
||||
// is set to "number". Take care of alignment for 'number' + 'relativenumber'.
|
||||
if (stcp != NULL && (wp->w_p_nu || wp->w_p_rnu) && get_vim_var_nr(VV_VIRTNUM) == 0) {
|
||||
if (wp->w_maxscwidth == SCL_NUM && stcp->sattrs[0].text[0]) {
|
||||
goto stcsign;
|
||||
}
|
||||
} else {
|
||||
int relnum = (int)get_vim_var_nr(VV_RELNUM);
|
||||
num = (!wp->w_p_rnu || (wp->w_p_nu && relnum == 0)) ? (int)get_vim_var_nr(VV_LNUM) : relnum;
|
||||
left_align_num = wp->w_p_rnu && wp->w_p_nu && relnum == 0;
|
||||
if (!left_align_num) {
|
||||
stl_items[curitem].type = Separate;
|
||||
stl_items[curitem++].start = out_p;
|
||||
}
|
||||
} else if (stcp == NULL) {
|
||||
num = (wp->w_buffer->b_ml.ml_flags & ML_EMPTY) ? 0 : wp->w_cursor.lnum;
|
||||
}
|
||||
break;
|
||||
@@ -1609,16 +1618,9 @@ int build_stl_str_hl(win_T *wp, char *out, size_t outlen, char *fmt, OptIndex op
|
||||
|
||||
case STL_ROFLAG:
|
||||
case STL_ROFLAG_ALT:
|
||||
// Overload %r with v:relnum for 'statuscolumn'
|
||||
if (stcp != NULL) {
|
||||
if (wp->w_p_rnu && !get_vim_var_nr(VV_VIRTNUM)) {
|
||||
num = (int)get_vim_var_nr(VV_RELNUM);
|
||||
}
|
||||
} else {
|
||||
itemisflag = true;
|
||||
if (wp->w_buffer->b_p_ro) {
|
||||
str = (opt == STL_ROFLAG_ALT) ? ",RO" : _("[RO]");
|
||||
}
|
||||
itemisflag = true;
|
||||
if (wp->w_buffer->b_p_ro) {
|
||||
str = (opt == STL_ROFLAG_ALT) ? ",RO" : _("[RO]");
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -1632,11 +1634,12 @@ int build_stl_str_hl(win_T *wp, char *out, size_t outlen, char *fmt, OptIndex op
|
||||
|
||||
case STL_FOLDCOL: // 'C' for 'statuscolumn'
|
||||
case STL_SIGNCOL: { // 's' for 'statuscolumn'
|
||||
stcsign:
|
||||
if (stcp == NULL) {
|
||||
break;
|
||||
}
|
||||
int fdc = opt == STL_FOLDCOL ? compute_foldcolumn(wp, 0) : 0;
|
||||
int width = opt == STL_FOLDCOL ? fdc > 0 : wp->w_scwidth;
|
||||
int width = opt == STL_FOLDCOL ? fdc > 0 : opt == STL_SIGNCOL ? wp->w_scwidth : 1;
|
||||
|
||||
if (width <= 0) {
|
||||
break;
|
||||
@@ -1844,7 +1847,6 @@ int build_stl_str_hl(win_T *wp, char *out, size_t outlen, char *fmt, OptIndex op
|
||||
|
||||
// For a 'statuscolumn' sign or fold item, add an item to reset the highlight group
|
||||
if (foldsignitem >= 0) {
|
||||
foldsignitem = -1;
|
||||
stl_items[curitem].type = Highlight;
|
||||
stl_items[curitem].start = out_p;
|
||||
stl_items[curitem].minwid = 0;
|
||||
@@ -1949,6 +1951,11 @@ int build_stl_str_hl(win_T *wp, char *out, size_t outlen, char *fmt, OptIndex op
|
||||
|
||||
// Item processed, move to the next
|
||||
curitem++;
|
||||
// For a 'statuscolumn' number item that is left aligned, add a separator item.
|
||||
if (left_align_num) {
|
||||
stl_items[curitem].type = Separate;
|
||||
stl_items[curitem++].start = out_p;
|
||||
}
|
||||
}
|
||||
|
||||
*out_p = NUL;
|
||||
|
Reference in New Issue
Block a user