Skip to content

Commit

Permalink
feat: pad builtin.lnumfunc with 'numberwidth'
Browse files Browse the repository at this point in the history
Fix #150
  • Loading branch information
luukvbaal committed Dec 26, 2024
1 parent 8822f76 commit 81d1cfb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions lua/statuscol.lua
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ local function update_callargs(args, win, tick)
args.tick = tick
opts.win = win
args.nu = a.nvim_get_option_value("nu", opts)
args.nuw = a.nvim_get_option_value("nuw", opts)
args.rnu = a.nvim_get_option_value("rnu", opts)
local culopt = a.nvim_get_option_value("culopt", opts)
args.cul = a.nvim_get_option_value("cul", opts) and (culopt:find("nu") or culopt:find("bo"))
Expand Down
6 changes: 4 additions & 2 deletions lua/statuscol/builtin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ function M.lnumfunc(args, segment)
lnum = reverse(lnum):gsub("%d%d%d", "%1"..thou):reverse():gsub("^%"..thou, "")
end

lnum = tostring(lnum)
local pad = (' '):rep(args.nuw - #lnum)

This comment has been minimized.

Copy link
@Nawar9

Nawar9 Dec 26, 2024

@luukvbaal I think this should be local pad = (' '):rep(args.nuw - #lnum - 1) to be compatible with the default behavior of nvim.
If you check out :h numberwidth you'll see ... Since one space is always between the number and the text, there is one less character for the number itself. ... Thus with the Vim default of 4 there is room for a line number up to 999. ...
Without the -1 there is currently room for 9999 with the default value of 4.

This comment has been minimized.

Copy link
@luukvbaal

luukvbaal Dec 26, 2024

Author Owner

I'm not sure, since the reasoning behind that off-by-one discrepancy doesn't apply to builtin.lnumfunc (trailing space isn't included), isn't the current logic less surprising?

This comment has been minimized.

Copy link
@Nawar9

Nawar9 Dec 26, 2024

I get your point. What I was aiming for is for builtin.lnumfunc to behave exactly like %l and the default statuscolumn, with the added flexibility of keeping or removing the trailing space. The idea is to avoid newcomers having to modify numberwidth to get the same behavior they had before.
And since the default value is 4 (which means 3 digits), you are effectively changing the default number of digits to 4 for users who don't actively change it, which -in my opinion- is too much screen real estate for line number, but I could be wrong here.
That said, it's great to have the option to change it, and if you think this approach is less surprising, then that's awesome.

if args.relnum == 0 and not culright and args.rnu then
return lnum.."%="
return lnum..pad.."%="
else
return "%="..lnum
return "%="..pad..lnum
end
end

Expand Down

0 comments on commit 81d1cfb

Please sign in to comment.