Skip to content

Commit

Permalink
Revert "Replace deprecated vim.api.nvim_buf_add_highlight with vim.hl…
Browse files Browse the repository at this point in the history
….range" (Fixes #144)

This reverts commit cb0631c.
  • Loading branch information
SidOfc committed Feb 4, 2025
1 parent acf2040 commit 47a4718
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 36 deletions.
17 changes: 9 additions & 8 deletions doc/carbon.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ USAGE *carbon-usag
directly anywhere in your |$MYVIMRC| file since such packages are
automatically loaded.

Carbon replaces |netrw| by default and remaps NetRW's |Explore| and Lexplore
Carbon replaces |netrw| by default and remaps NetRW's |Explore| and |Lexplore|
commands to Carbon's |carbon-command-Carbon| and |carbon-command-Lcarbon| commands
respectively. For more specific usage and configuration information, see:

Expand Down Expand Up @@ -817,9 +817,9 @@ UTIL *carbon-uti

Signature: `require('carbon.util').add_highlight(`{buf}, {...}`)`

Calls |vim.hl.range| like this:
Calls |nvim_buf_add_highlight| like this:

`vim.hl.range(`{buf}, <ns_id>, {...}`)`
`vim.api.nvim_buf_add_highlight(`{buf}, <ns_id>, {...}`)`

<ns_id> will be set to |carbon-constant-hl|.

Expand Down Expand Up @@ -1520,15 +1520,16 @@ VIEW *carbon-vie
<number end_column>,
}
<
|carbon-view-render| uses |vim.hl.range| to set the highlights.
|carbon-view-render| uses |nvim_buf_add_highlight| to set the highlights.
It is called the following way:

`vim.hl.range(`
`vim.api.nvim_buf_add_highlight(`
|carbon-view-buffer|,
|carbon-constant-hl|,
`highlight[1],`
`{lnum - 1, highlight[2]},`
`{lnum - 1, highlight[3]},`
`lnum - 1,`
`highlight[2],`
`highlight[3],`
`)`

Property: `path`
Expand Down Expand Up @@ -1816,7 +1817,7 @@ VIEW *carbon-vie

Highlights a region from {start} to {finish} with {group} for {duration}
milliseconds. {start} and {finish} must be values accepted by
|vim.hl.range|.
|vim.highlight.range|.

See |carbon-view-flash-bang| for more information about customizing the
highlighting properties when entries are revealed.
Expand Down
2 changes: 1 addition & 1 deletion lua/carbon/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ function util.clear_extmarks(buf, ...)
end

function util.add_highlight(buf, ...)
vim.hl.range(buf, constants.hl, ...)
vim.api.nvim_buf_add_highlight(buf, constants.hl, ...)
end

function util.window_neighbors(window_id, sides)
Expand Down
41 changes: 14 additions & 27 deletions lua/carbon/view.lua
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,8 @@ local function create_insert_move(ctx)

vim.api.nvim_buf_set_lines(0, ctx.edit_lnum, ctx.edit_lnum + 1, 1, { text })
util.clear_extmarks(0, { ctx.edit_lnum, 0 }, { ctx.edit_lnum, -1 }, {})
util.add_highlight(
0,
'CarbonDir',
{ ctx.edit_lnum, 0 },
{ ctx.edit_lnum, last_slash_col }
)
util.add_highlight(
0,
'CarbonFile',
{ ctx.edit_lnum, last_slash_col },
{ ctx.edit_lnum, -1 }
)
util.add_highlight(0, 'CarbonDir', ctx.edit_lnum, 0, last_slash_col)
util.add_highlight(0, 'CarbonFile', ctx.edit_lnum, last_slash_col, -1)
util.cursor(ctx.edit_lnum + 1, math.max(ctx.edit_col, vim.fn.col('.')))
end
end
Expand Down Expand Up @@ -388,7 +378,14 @@ function view:render()
end

for _, hl in ipairs(hls) do
vim.hl.range(buf, constants.hl, hl[1], { hl[2], hl[3] }, { hl[2], hl[4] })
vim.api.nvim_buf_add_highlight(
buf,
constants.hl,
hl[1],
hl[2],
hl[3],
hl[4]
)
end

if cursor then
Expand All @@ -412,7 +409,7 @@ end
function view:focus_flash(duration, group, start, finish)
local buf = self:buffer()

vim.hl.range(buf, constants.hl_tmp, group, start, finish, {})
vim.highlight.range(buf, constants.hl_tmp, group, start, finish, {})

vim.defer_fn(function()
if vim.api.nvim_buf_is_valid(buf) then
Expand Down Expand Up @@ -860,12 +857,7 @@ function view:delete()
end

util.clear_extmarks(0, { lnum_idx, highlight[2] }, { lnum_idx, -1 }, {})
util.add_highlight(
0,
'CarbonDanger',
{ lnum_idx, highlight[2] },
{ lnum_idx, -1 }
)
util.add_highlight(0, 'CarbonDanger', lnum_idx, highlight[2], -1)

vim.cmd.redraw()

Expand Down Expand Up @@ -899,7 +891,7 @@ function view:delete()
util.clear_extmarks(0, { lnum_idx, 0 }, { lnum_idx, -1 }, {})

for _, lhl in ipairs(cursor.line.highlights) do
util.add_highlight(0, lhl[1], { lnum_idx, lhl[2] }, { lnum_idx, lhl[3] })
util.add_highlight(0, lhl[1], lnum_idx, lhl[2], lhl[3])
end

self:render()
Expand Down Expand Up @@ -932,12 +924,7 @@ function view:move()
end

util.clear_extmarks(0, { lnum_idx, start_hl }, { lnum_idx, -1 }, {})
util.add_highlight(
0,
'CarbonPending',
{ lnum_idx, start_hl },
{ lnum_idx, -1 }
)
util.add_highlight(0, 'CarbonPending', lnum_idx, start_hl, -1)
vim.cmd.redraw({ bang = true })
vim.cmd.echohl('CarbonPending')

Expand Down

0 comments on commit 47a4718

Please sign in to comment.