Skip to content

Commit cb0631c

Browse files
committed
Replace deprecated vim.api.nvim_buf_add_highlight with vim.hl.range
1 parent 12f0e11 commit cb0631c

File tree

3 files changed

+36
-24
lines changed

3 files changed

+36
-24
lines changed

doc/carbon.txt

+8-9
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ USAGE *carbon-usag
4040
directly anywhere in your |$MYVIMRC| file since such packages are
4141
automatically loaded.
4242

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

@@ -817,9 +817,9 @@ UTIL *carbon-uti
817817

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

820-
Calls |nvim_buf_add_highlight| like this:
820+
Calls |vim.hl.range| like this:
821821

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

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

@@ -1520,16 +1520,15 @@ VIEW *carbon-vie
15201520
<number end_column>,
15211521
}
15221522
<
1523-
|carbon-view-render| uses |nvim_buf_add_highlight| to set the highlights.
1523+
|carbon-view-render| uses |vim.hl.range| to set the highlights.
15241524
It is called the following way:
15251525

1526-
`vim.api.nvim_buf_add_highlight(`
1526+
`vim.hl.range(`
15271527
|carbon-view-buffer|,
15281528
|carbon-constant-hl|,
15291529
`highlight[1],`
1530-
`lnum - 1,`
1531-
`highlight[2],`
1532-
`highlight[3],`
1530+
`{lnum - 1, highlight[2]},`
1531+
`{lnum - 1, highlight[3]},`
15331532
`)`
15341533

15351534
Property: `path`
@@ -1817,7 +1816,7 @@ VIEW *carbon-vie
18171816

18181817
Highlights a region from {start} to {finish} with {group} for {duration}
18191818
milliseconds. {start} and {finish} must be values accepted by
1820-
|vim.highlight.range|.
1819+
|vim.hl.range|.
18211820

18221821
See |carbon-view-flash-bang| for more information about customizing the
18231822
highlighting properties when entries are revealed.

lua/carbon/util.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ function util.clear_extmarks(buf, ...)
203203
end
204204

205205
function util.add_highlight(buf, ...)
206-
vim.api.nvim_buf_add_highlight(buf, constants.hl, ...)
206+
vim.hl.range(buf, constants.hl, ...)
207207
end
208208

209209
function util.window_neighbors(window_id, sides)

lua/carbon/view.lua

+27-14
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,18 @@ local function create_insert_move(ctx)
5858

5959
vim.api.nvim_buf_set_lines(0, ctx.edit_lnum, ctx.edit_lnum + 1, 1, { text })
6060
util.clear_extmarks(0, { ctx.edit_lnum, 0 }, { ctx.edit_lnum, -1 }, {})
61-
util.add_highlight(0, 'CarbonDir', ctx.edit_lnum, 0, last_slash_col)
62-
util.add_highlight(0, 'CarbonFile', ctx.edit_lnum, last_slash_col, -1)
61+
util.add_highlight(
62+
0,
63+
'CarbonDir',
64+
{ ctx.edit_lnum, 0 },
65+
{ ctx.edit_lnum, last_slash_col }
66+
)
67+
util.add_highlight(
68+
0,
69+
'CarbonFile',
70+
{ ctx.edit_lnum, last_slash_col },
71+
{ ctx.edit_lnum, -1 }
72+
)
6373
util.cursor(ctx.edit_lnum + 1, math.max(ctx.edit_col, vim.fn.col('.')))
6474
end
6575
end
@@ -378,14 +388,7 @@ function view:render()
378388
end
379389

380390
for _, hl in ipairs(hls) do
381-
vim.api.nvim_buf_add_highlight(
382-
buf,
383-
constants.hl,
384-
hl[1],
385-
hl[2],
386-
hl[3],
387-
hl[4]
388-
)
391+
vim.hl.range(buf, constants.hl, hl[1], { hl[2], hl[3] }, { hl[2], hl[4] })
389392
end
390393

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

412-
vim.highlight.range(buf, constants.hl_tmp, group, start, finish, {})
415+
vim.hl.range(buf, constants.hl_tmp, group, start, finish, {})
413416

414417
vim.defer_fn(function()
415418
if vim.api.nvim_buf_is_valid(buf) then
@@ -857,7 +860,12 @@ function view:delete()
857860
end
858861

859862
util.clear_extmarks(0, { lnum_idx, highlight[2] }, { lnum_idx, -1 }, {})
860-
util.add_highlight(0, 'CarbonDanger', lnum_idx, highlight[2], -1)
863+
util.add_highlight(
864+
0,
865+
'CarbonDanger',
866+
{ lnum_idx, highlight[2] },
867+
{ lnum_idx, -1 }
868+
)
861869

862870
vim.cmd.redraw()
863871

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

893901
for _, lhl in ipairs(cursor.line.highlights) do
894-
util.add_highlight(0, lhl[1], lnum_idx, lhl[2], lhl[3])
902+
util.add_highlight(0, lhl[1], { lnum_idx, lhl[2] }, { lnum_idx, lhl[3] })
895903
end
896904

897905
self:render()
@@ -924,7 +932,12 @@ function view:move()
924932
end
925933

926934
util.clear_extmarks(0, { lnum_idx, start_hl }, { lnum_idx, -1 }, {})
927-
util.add_highlight(0, 'CarbonPending', lnum_idx, start_hl, -1)
935+
util.add_highlight(
936+
0,
937+
'CarbonPending',
938+
{ lnum_idx, start_hl },
939+
{ lnum_idx, -1 }
940+
)
928941
vim.cmd.redraw({ bang = true })
929942
vim.cmd.echohl('CarbonPending')
930943

0 commit comments

Comments
 (0)