Allow custom formatters for b:gitsigns_status

Resolves #15
This commit is contained in:
Lewis Russell 2020-11-16 23:10:47 +00:00
parent a66043e4f5
commit 2dd4f3c8eb
4 changed files with 18 additions and 10 deletions

View File

@ -72,6 +72,7 @@ require('gitsigns').setup {
interval = 1000
}
sign_priority = 6,
status_formatter = nil, -- Use default
}
```
@ -80,10 +81,9 @@ For information on configuring neovim via lua please see
## Status Line
Use `b:gitsigns_status` or `b:gitsigns_status_dict`. `b:gitsigns_status` is
a preformatted and ready to use string (e.g. `+10 -5 ~1`) and ommits zero
values. `b:gitsigns_status_dict`is a dictionary with the keys `added`,
`removed`, `changed`.
Use `b:gitsigns_status` or `b:gitsigns_status_dict`. `b:gitsigns_status` is a
is formatted using `config.status_formatter`. `b:gitsigns_status_dict`is a
dictionary with the keys `added`, `removed`, `changed` and `head`.
Example:
```viml

View File

@ -52,7 +52,8 @@ the default settings:
watch_index = {
interval = 1000
},
sign_priority = 6
sign_priority = 6,
status_formatter = nil -- Use default
}
<
@ -127,9 +128,9 @@ STATUSLINE *gitsigns-statusline*
*b:gitsigns_status* *b:gitsigns_status_dict*
The buffer variables `b:gitsigns_status` and `b:gitsigns_status_dict` are
provided. `b:gitsigns_status` is a preformatted and ready to use string (e.g.
`+10 -5 ~1`) and ommits zero values. `b:gitsigns_status_dict` is a dictionary
with the keys `added`, `removed`, `changed`.
provided. `b:gitsigns_status` is formatted using `config.status_formatter`
. `b:gitsigns_status_dict` is a dictionary with the keys `added`, `removed`,
`changed` and `head`.
Example:
>

View File

@ -404,13 +404,14 @@ local update = debounce_trailing(100, async('update', function(bufnr)
bcache.diffs = await(run_diff, staged, buftext)
local status, signs = process_diffs(bcache.diffs)
status.head = bcache.abbrev_head
await_main()
add_signs(bufnr, signs, true)
set_buf_var(bufnr, 'gitsigns_status_dict', status)
set_buf_var(bufnr, 'gitsigns_status', mk_status_txt(status))
set_buf_var(bufnr, 'gitsigns_status', config.status_formatter(status))
update_cnt = update_cnt + 1
dprint(string.format('updates: %s, jobs: %s', update_cnt, job_cnt), bufnr, 'update')
@ -764,6 +765,10 @@ local function setup(cfg)
config = vim.tbl_deep_extend("keep", cfg or {}, default_config)
if type(config.status_formatter) ~= 'function' then
config.status_formatter = mk_status_txt
end
-- Define signs
for t, sign_name in pairs(sign_map) do
vim.fn.sign_define(sign_name, {

View File

@ -18,10 +18,12 @@ return {
['n <leader>hu'] = '<cmd>lua require"gitsigns".undo_stage_hunk()<CR>',
['n <leader>hr'] = '<cmd>lua require"gitsigns".reset_hunk()<CR>',
['n <leader>hp'] = '<cmd>lua require"gitsigns".preview_hunk()<CR>',
['n m'] = '<cmd>lua require"gitsigns".dump_cache()<CR>',
},
watch_index = {
interval = 1000
},
debug_mode = false,
sign_priority = 6
sign_priority = 6,
status_formatter = nil, -- Use default
}