mirror of
https://github.com/lewis6991/gitsigns.nvim
synced 2025-02-23 08:16:53 +00:00
Add support for line highlighting
This commit is contained in:
parent
bf7c8f2077
commit
e659f776d0
@ -156,7 +156,7 @@ require('gitsigns').setup {
|
||||
- [ ] Allow extra options to be passed to `git diff`
|
||||
- [ ] Folding of text around hunks
|
||||
- [ ] Diff against working tree instead of index, or diff against any SHA.
|
||||
- [ ] Line highlighting
|
||||
- [x] Line highlighting
|
||||
- [x] Hunk text object
|
||||
- [ ] Open diff mode of buffer against what gitsigns is comparing to (currently the index)
|
||||
- [ ] Share index watchers for files in the same repo
|
||||
|
@ -152,18 +152,20 @@ signs *gitsigns-config-signs*
|
||||
Type: `table`, Default:
|
||||
>
|
||||
{
|
||||
add = {hl = 'DiffAdd' , text = '│', numhl='GitSignsAddNr'},
|
||||
change = {hl = 'DiffChange', text = '│', numhl='GitSignsChangeNr'},
|
||||
delete = {hl = 'DiffDelete', text = '_', numhl='GitSignsDeleteNr'},
|
||||
topdelete = {hl = 'DiffDelete', text = '‾', numhl='GitSignsDeleteNr'},
|
||||
changedelete = {hl = 'DiffChange', text = '~', numhl='GitSignsChangeNr'},
|
||||
add = {hl = 'DiffAdd' , text = '│', numhl='GitSignsAddNr' , linehl='GitSignsAddLr' },
|
||||
change = {hl = 'DiffChange', text = '│', numhl='GitSignsChangeNr', linehl='GitSignsChangeLr' },
|
||||
delete = {hl = 'DiffDelete', text = '_', numhl='GitSignsDeleteNr', linehl='GitSignsDeleteLr' },
|
||||
topdelete = {hl = 'DiffDelete', text = '‾', numhl='GitSignsDeleteNr', linehl='GitSignsDeleteLr' },
|
||||
changedelete = {hl = 'DiffChange', text = '~', numhl='GitSignsChangeNr', linehl='GitSignsChangeLr' },
|
||||
}
|
||||
<
|
||||
Configuration for signs:
|
||||
• `hl` specifies the highlight group to use for the sign.
|
||||
• `text` specifies the character to use for the sign.
|
||||
• `numhl` specifies the highlight group to use for the number column (see
|
||||
|gitsigns-config.numhl|).
|
||||
• `numhl` specifies the highlight group to use for the number column
|
||||
(see |gitsigns-config.numhl|).
|
||||
• `linehl` specifies the highlight group to use for the line
|
||||
(see |gitsigns-config.linehl|).
|
||||
• `show_count` to enable showing count of hunk, e.g. number of deleted
|
||||
lines.
|
||||
|
||||
@ -220,6 +222,15 @@ numhl *gitsigns-config-numhl*
|
||||
the highlight group does not exist, then it is automatically defined
|
||||
and linked to the corresponding highlight group in `signs.*.hl`.
|
||||
|
||||
linehl *gitsigns-config-linehl*
|
||||
Type: `boolean`, Default: `false`
|
||||
|
||||
Enable/disable line highlights.
|
||||
|
||||
When enabled the highlights defined in `signs.*.linehl` are used. If
|
||||
the highlight group does not exist, then it is automatically defined
|
||||
and linked to the corresponding highlight group in `signs.*.hl`.
|
||||
|
||||
diff_algorithm *gitsigns-config-diff_algorithm*
|
||||
Type: `string`, Default: taken from 'diffopt'
|
||||
|
||||
|
@ -99,6 +99,7 @@ local function add_signs(bufnr, signs, reset)
|
||||
texthl = cs.hl,
|
||||
text = cs.text .. count_char,
|
||||
numhl = config.numhl and cs.numhl,
|
||||
linehl = config.linehl and cs.linehl,
|
||||
})
|
||||
end
|
||||
|
||||
@ -500,10 +501,14 @@ local function setup(cfg)
|
||||
for t, sign_name in pairs(sign_map) do
|
||||
local cs = config.signs[t]
|
||||
|
||||
if config.numhl then
|
||||
local hl_exists, _ = pcall(api.nvim_get_hl_by_name, cs.numhl, false)
|
||||
if not hl_exists then
|
||||
vim.cmd(('highlight link %s %s'):format(cs.numhl, cs.hl))
|
||||
local HlTy = {}
|
||||
|
||||
for _, hl in ipairs({ 'numhl', 'linehl' }) do
|
||||
if config[hl] then
|
||||
local hl_exists, _ = pcall(api.nvim_get_hl_by_name, cs[hl], false)
|
||||
if not hl_exists then
|
||||
vim.cmd(('highlight link %s %s'):format(cs[hl], cs.hl))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -511,6 +516,7 @@ local function setup(cfg)
|
||||
texthl = cs.hl,
|
||||
text = cs.text,
|
||||
numhl = config.numhl and cs.numhl,
|
||||
linehl = config.linehl and cs.linehl,
|
||||
})
|
||||
|
||||
end
|
||||
|
@ -12,18 +12,20 @@ local schema = {
|
||||
type = 'table',
|
||||
deep_extend = true,
|
||||
default = [[{
|
||||
add = {hl = 'DiffAdd' , text = '│', numhl='GitSignsAddNr'},
|
||||
change = {hl = 'DiffChange', text = '│', numhl='GitSignsChangeNr'},
|
||||
delete = {hl = 'DiffDelete', text = '_', numhl='GitSignsDeleteNr'},
|
||||
topdelete = {hl = 'DiffDelete', text = '‾', numhl='GitSignsDeleteNr'},
|
||||
changedelete = {hl = 'DiffChange', text = '~', numhl='GitSignsChangeNr'},
|
||||
add = {hl = 'DiffAdd' , text = '│', numhl='GitSignsAddNr' , linehl='GitSignsAddLr' },
|
||||
change = {hl = 'DiffChange', text = '│', numhl='GitSignsChangeNr', linehl='GitSignsChangeLr' },
|
||||
delete = {hl = 'DiffDelete', text = '_', numhl='GitSignsDeleteNr', linehl='GitSignsDeleteLr' },
|
||||
topdelete = {hl = 'DiffDelete', text = '‾', numhl='GitSignsDeleteNr', linehl='GitSignsDeleteLr' },
|
||||
changedelete = {hl = 'DiffChange', text = '~', numhl='GitSignsChangeNr', linehl='GitSignsChangeLr' },
|
||||
}]],
|
||||
description = [[
|
||||
Configuration for signs:
|
||||
• `hl` specifies the highlight group to use for the sign.
|
||||
• `text` specifies the character to use for the sign.
|
||||
• `numhl` specifies the highlight group to use for the number column (see
|
||||
|gitsigns-config.numhl|).
|
||||
• `numhl` specifies the highlight group to use for the number column
|
||||
(see |gitsigns-config.numhl|).
|
||||
• `linehl` specifies the highlight group to use for the line
|
||||
(see |gitsigns-config.linehl|).
|
||||
• `show_count` to enable showing count of hunk, e.g. number of deleted
|
||||
lines.
|
||||
]],
|
||||
@ -90,6 +92,18 @@ local schema = {
|
||||
]],
|
||||
},
|
||||
|
||||
linehl = {
|
||||
type = 'boolean',
|
||||
default = false,
|
||||
description = [[
|
||||
Enable/disable line highlights.
|
||||
|
||||
When enabled the highlights defined in `signs.*.linehl` are used. If
|
||||
the highlight group does not exist, then it is automatically defined
|
||||
and linked to the corresponding highlight group in `signs.*.hl`.
|
||||
]],
|
||||
},
|
||||
|
||||
diff_algorithm = {
|
||||
type = 'string',
|
||||
|
||||
|
@ -98,7 +98,8 @@ local function add_signs(bufnr: number, signs: {Sign}, reset: boolean)
|
||||
sign_define(stype, {
|
||||
texthl = cs.hl,
|
||||
text = cs.text..count_char,
|
||||
numhl = config.numhl and cs.numhl
|
||||
numhl = config.numhl and cs.numhl,
|
||||
linehl = config.linehl and cs.linehl
|
||||
})
|
||||
end
|
||||
|
||||
@ -500,17 +501,22 @@ local function setup(cfg: Config)
|
||||
for t, sign_name in pairs(sign_map) do
|
||||
local cs = config.signs[t]
|
||||
|
||||
if config.numhl then
|
||||
local hl_exists, _ = pcall(api.nvim_get_hl_by_name, cs.numhl, false)
|
||||
if not hl_exists then
|
||||
vim.cmd(('highlight link %s %s'):format(cs.numhl, cs.hl))
|
||||
local enum HlTy 'numhl' 'linehl' end
|
||||
|
||||
for _, hl in ipairs({'numhl', 'linehl'} as {HlTy}) do
|
||||
if config[hl] then
|
||||
local hl_exists, _ = pcall(api.nvim_get_hl_by_name, cs[hl], false)
|
||||
if not hl_exists then
|
||||
vim.cmd(('highlight link %s %s'):format(cs[hl], cs.hl))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
sign_define(sign_name, {
|
||||
texthl = cs.hl,
|
||||
text = cs.text,
|
||||
numhl = config.numhl and cs.numhl
|
||||
numhl = config.numhl and cs.numhl,
|
||||
linehl = config.linehl and cs.linehl
|
||||
})
|
||||
|
||||
end
|
||||
|
@ -12,18 +12,20 @@ local schema: {string:SchemaElem} = {
|
||||
type = 'table',
|
||||
deep_extend = true,
|
||||
default = [[{
|
||||
add = {hl = 'DiffAdd' , text = '│', numhl='GitSignsAddNr'},
|
||||
change = {hl = 'DiffChange', text = '│', numhl='GitSignsChangeNr'},
|
||||
delete = {hl = 'DiffDelete', text = '_', numhl='GitSignsDeleteNr'},
|
||||
topdelete = {hl = 'DiffDelete', text = '‾', numhl='GitSignsDeleteNr'},
|
||||
changedelete = {hl = 'DiffChange', text = '~', numhl='GitSignsChangeNr'},
|
||||
add = {hl = 'DiffAdd' , text = '│', numhl='GitSignsAddNr' , linehl='GitSignsAddLr' },
|
||||
change = {hl = 'DiffChange', text = '│', numhl='GitSignsChangeNr', linehl='GitSignsChangeLr' },
|
||||
delete = {hl = 'DiffDelete', text = '_', numhl='GitSignsDeleteNr', linehl='GitSignsDeleteLr' },
|
||||
topdelete = {hl = 'DiffDelete', text = '‾', numhl='GitSignsDeleteNr', linehl='GitSignsDeleteLr' },
|
||||
changedelete = {hl = 'DiffChange', text = '~', numhl='GitSignsChangeNr', linehl='GitSignsChangeLr' },
|
||||
}]],
|
||||
description = [[
|
||||
Configuration for signs:
|
||||
• `hl` specifies the highlight group to use for the sign.
|
||||
• `text` specifies the character to use for the sign.
|
||||
• `numhl` specifies the highlight group to use for the number column (see
|
||||
|gitsigns-config.numhl|).
|
||||
• `numhl` specifies the highlight group to use for the number column
|
||||
(see |gitsigns-config.numhl|).
|
||||
• `linehl` specifies the highlight group to use for the line
|
||||
(see |gitsigns-config.linehl|).
|
||||
• `show_count` to enable showing count of hunk, e.g. number of deleted
|
||||
lines.
|
||||
]]
|
||||
@ -90,6 +92,18 @@ local schema: {string:SchemaElem} = {
|
||||
]]
|
||||
},
|
||||
|
||||
linehl = {
|
||||
type = 'boolean',
|
||||
default = false,
|
||||
description = [[
|
||||
Enable/disable line highlights.
|
||||
|
||||
When enabled the highlights defined in `signs.*.linehl` are used. If
|
||||
the highlight group does not exist, then it is automatically defined
|
||||
and linked to the corresponding highlight group in `signs.*.hl`.
|
||||
]]
|
||||
},
|
||||
|
||||
diff_algorithm = {
|
||||
type = 'string',
|
||||
|
||||
|
@ -29,6 +29,7 @@ global record SignsConfig
|
||||
hl: string
|
||||
text: string
|
||||
numhl: string
|
||||
linehl: string
|
||||
keymaps: {string:string}
|
||||
end
|
||||
|
||||
@ -45,6 +46,7 @@ global record Config
|
||||
signs: {SignType: SignsConfig}
|
||||
count_chars: {string|number:string}
|
||||
numhl: boolean
|
||||
linehl: boolean
|
||||
sign_priority: number
|
||||
keymaps: {string:any}
|
||||
record watch_index
|
||||
|
Loading…
Reference in New Issue
Block a user