1
+ local ffi = require (" ffi" )
1
2
local wo = vim .wo
2
3
local fn = vim .fn
3
4
local api = vim .api
@@ -22,12 +23,6 @@ local default_config = {
22
23
--- @type string | boolean
23
24
comment_signs = ' spaces' ,
24
25
25
- -- We can't calculate precisely the current foldcolumn width so we
26
- -- take its maximum value from 'foldcolumn' option. But if it is
27
- -- set to 'auto' we have no digit to use. This value will be use in
28
- -- this case.
29
- foldcolumn = 3 ,
30
-
31
26
sections = {
32
27
left = {
33
28
' content' ,
@@ -69,38 +64,12 @@ local function fold_text(config)
69
64
end
70
65
end
71
66
72
- -- Calculate widths of the number column.
73
- local num_col_width = math.max ( # tostring (api .nvim_buf_line_count (0 )),
74
- wo .numberwidth )
75
-
76
- -- We can't calculate precisely the current foldcolumn width.
77
- -- So we assume it has the maximum value taken from 'foldcolumn' option ...
78
- local fold_col_width = wo .foldcolumn :match (' %d+$' ) or config .foldcolumn
79
-
80
- -- Calculate width of the signs column.
81
- local sign_col_width = 0
82
- local signcolumn = wo .signcolumn
83
- if signcolumn :match (' ^auto' ) or
84
- (signcolumn :match (' ^number' ) and not wo .number )
85
- then
86
- -- Calculate the maximum number of signes placed on any line
87
- -- in current buffer.
88
- local signs = vim .fn .sign_getplaced (' %' , { group = ' *' })[1 ].signs
89
- local spl = {} -- signs per line
90
- for _ , sign in ipairs (signs ) do
91
- spl [sign .lnum ] = (spl [sign .lnum ] or 0 ) + 1
92
- end
93
- local max_spl = math.max ( unpack (vim .tbl_values (spl )) or 0 )
67
+ --- The offset of a window, occupied by line number column,
68
+ --- fold column and sign column.
69
+ --- @type number
70
+ local gutter_width = ffi .C .curwin_col_off ()
94
71
95
- signcolumn = signcolumn :match (' %d+$' ) or math.huge
96
- sign_col_width = math.min (signcolumn , max_spl )
97
- elseif signcolumn :match (' ^yes' ) then
98
- sign_col_width = signcolumn :match (' %d+$' ) or 1
99
- end
100
- sign_col_width = sign_col_width * 2
101
-
102
- local visible_win_width =
103
- api .nvim_win_get_width (0 ) - num_col_width - fold_col_width - sign_col_width
72
+ local visible_win_width = api .nvim_win_get_width (0 ) - gutter_width
104
73
105
74
-- Calculate the summation length of all the sections of the fold text string.
106
75
local fold_text_len = 0
@@ -110,15 +79,10 @@ local function fold_text(config)
110
79
111
80
r .expansion_str = string.rep (config .fill_char , visible_win_width - fold_text_len )
112
81
113
- -- ... but real foldcolumn doesn't always have its maximum value, so we need
114
- -- to close the gap between right section and the boder of the window.
115
- r .end_str = string.rep (config .fill_char , fold_col_width - 1 )
116
-
117
82
local result = ' '
118
83
for _ , str in ipairs (r .left ) do result = result .. str end
119
84
result = result .. r .expansion_str
120
85
for _ , str in ipairs (r .right ) do result = result .. str end
121
- result = result .. r .end_str
122
86
123
87
return result
124
88
end
0 commit comments