1
0
Fork 0
dotfiles/home/config/nvim/nifoc/statuscolumn.fnl

87 lines
4.2 KiB
Text
Raw Normal View History

2023-01-11 21:45:22 +00:00
(let [mod {}
api vim.api
o vim.opt
2023-01-14 16:07:11 +00:00
statusline (require :nifoc.statusline)
gitsigns (require :gitsigns)]
2023-01-11 21:45:22 +00:00
;; Line Number
(set mod.line-number
{:condition #(or (o.number:get) (o.relativenumber:get))
1 statusline.push-right
2 {:provider (fn []
(let [num (o.number:get)
relnum (o.relativenumber:get)]
(if (and num (not relnum)) "%l"
(and relnum (not num)) "%r"
"%{v:relnum?v:relnum:v:lnum}")))}})
;; Signs
(set mod.signs {:provider "%s" :hl {:bold true}})
;; gitsigns
2023-01-12 09:59:15 +00:00
(set mod.gitsigns
{:condition #(= vim.b.nifoc_gitsigns_enabled 1)
:init (fn [self]
(let [bufnr (api.nvim_get_current_buf)
lnum vim.v.lnum
sign (?. (vim.fn.sign_getplaced bufnr
{:group :gitsigns_vimfn_signs_
:id lnum
: lnum})
1 :signs 1)]
(set self.sign sign)
(set self.has_sign (not= sign nil))))
2023-01-14 16:07:11 +00:00
:provider " ▏"
:hl #(if $1.has_sign $1.sign.name :StatusLineNC)
:on_click {:name :heirline_statuscolumn_gitsigns
:callback (fn [self]
(let [mouse (vim.fn.getmousepos)
cursor-pos [mouse.line 0]]
(api.nvim_win_set_cursor mouse.winid
cursor-pos)
(vim.defer_fn #(gitsigns.blame_line {:full true})
100)))}})
(set mod.gitsigns-or-bar [{:condition #(and (not= vim.b.nifoc_gitsigns_enabled
1)
(or (o.number:get)
(o.relativenumber:get)))
:provider " ▏"
2023-01-12 09:59:15 +00:00
:hl :StatusLineNC}
mod.gitsigns])
2023-01-11 21:45:22 +00:00
;; Diagnostic signs
(set mod.diagnostic-signs
2023-01-14 16:07:11 +00:00
{:condition #(and (= vim.b.nifoc_diagnostics_enabled 1)
(> (length (vim.diagnostic.get 0)) 0))
:static {:sign-text {:DiagnosticSignError " "
:DiagnosticSignWarn " "
2023-01-11 21:45:22 +00:00
:DiagnosticSignInfo " "
2023-01-14 16:07:11 +00:00
:DiagnosticSignHint " "}}
2023-01-11 21:45:22 +00:00
:init (fn [self]
(let [bufnr (api.nvim_get_current_buf)
lnum vim.v.lnum
signs (?. (vim.fn.sign_getplaced bufnr
{:group "*" : lnum})
1 :signs)
diagnostic-signs (vim.tbl_filter #(vim.startswith $1.group
:vim.diagnostic)
signs)
sign (?. diagnostic-signs 1)]
(set self.bufnr bufnr)
(set self.sign sign)
(set self.has_sign (not= sign nil))))
:provider #(if $1.has_sign
(. $1.sign-text $1.sign.name)
" ")
:hl #(when $1.has_sign
$1.sign.name)
:on_click {:name :heirline_statuscolumn_diagnostic
:callback (fn [self]
2023-01-11 22:48:51 +00:00
(let [mouse (vim.fn.getmousepos)
line (- mouse.line 1)
cursor-pos [mouse.line 0]]
(api.nvim_win_set_cursor mouse.winid
cursor-pos)
(vim.defer_fn #(vim.diagnostic.open_float {:bufnr self.bufnr
:pos line
:scope :line})
2023-01-14 16:07:11 +00:00
100)))}})
2023-01-11 21:45:22 +00:00
mod)