Skip to content

Commit

Permalink
feat: add foldclosed option for sign segments
Browse files Browse the repository at this point in the history
When set to true, show signs from lines in a closed fold on the
first line of that closed fold.
  • Loading branch information
luukvbaal committed Feb 1, 2024
1 parent f9bb3f9 commit bbd163c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Requires Neovim >= 0.10.

![image](https://user-images.githubusercontent.com/31730729/230627808-de0b1e97-116d-4016-b4ba-cb709dfcd980.png)

_Status column containing a fold column without fold depth digits, a custom sign segment that will only show diagnostic signs, a number column with right aligned relative numbers and a sign segment that is only 1 cell wide that shows all other signs._
_Status column containing a fold column without fold depth digits, a custom sign segment that will only show diagnostic signs, a number column with right aligned relative numbers and a sign segment that is only 1 cell wide that shows all other signs.

## Install

Expand Down Expand Up @@ -124,6 +124,7 @@ Each segment can contain the following elements:
-- virtual or wrapped part of a line (when v:virtnum != 0).
fillchar = " ", -- character used to fill a segment with less signs than maxwidth
fillcharhl = nil, -- highlight group used for fillchar (SignColumn/CursorLineSign if omitted)
foldclosed = false, -- when true, show signs from lines in a closed fold on the first line
}
}
```
Expand Down
13 changes: 13 additions & 0 deletions lua/statuscol.lua
Original file line number Diff line number Diff line change
Expand Up @@ -141,19 +141,31 @@ end

--- Place signs with sign text in sign segments.
local function place_signs(win, signs)
local lines = {}
for i = 1, #signs do
local s = signs[i][4]
if not s.sign_text then goto nextsign end

local name = s.sign_name or s.sign_text
if not s.sign_hl_group then s.sign_hl_group = "NoTexthl" end
if not s.sign_name then name = name..s.sign_hl_group end
if not sign_cache[name] then sign_cache_add(win, s, name) end
local sign = sign_cache[name]
if not sign.segment then goto nextsign end

local ss = signsegments[sign.segment]
local wss = ss.wins[win]
local sss = wss.signs
local lnum = signs[i][2] + 1

if ss.foldclosed then
if not lines[lnum] then lines[lnum] = f.foldclosed(lnum) end
if lines[lnum] > 0 then
lnum = lines[lnum]
for j = lnum, f.foldclosedend(lnum) do lines[j] = lnum end
end
end

if not sss[lnum] then sss[lnum] = {} end
-- Insert by priority. Potentially remove when nvim_buf_get_extmarks() can return sorted list.
for j = 1, ss.maxwidth do
Expand Down Expand Up @@ -323,6 +335,7 @@ function M.setup(user)
ss.maxwidth = ss.maxwidth or 1
ss.colwidth = ss.colwidth or 2
ss.fillchar = ss.fillchar or " "
ss.foldclosed = ss.foldclosed or false
if ss.fillcharhl then ss.fillcharhl = "%#"..ss.fillcharhl.."#" end
if setscl ~= false then setscl = true end
if not segment.text then segment.text = {builtin.signfunc} end
Expand Down

0 comments on commit bbd163c

Please sign in to comment.