Skip to content

Commit 47a4718

Browse files
committed
Revert "Replace deprecated vim.api.nvim_buf_add_highlight with vim.hl.range" (Fixes #144)
This reverts commit cb0631c.
1 parent acf2040 commit 47a4718

File tree

3 files changed

+24
-36
lines changed

3 files changed

+24
-36
lines changed

doc/carbon.txt

+9-8
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 |vim.hl.range| like this:
820+
Calls |nvim_buf_add_highlight| like this:
821821

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

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

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

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

15341535
Property: `path`
@@ -1816,7 +1817,7 @@ VIEW *carbon-vie
18161817

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

18211822
See |carbon-view-flash-bang| for more information about customizing the
18221823
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.hl.range(buf, constants.hl, ...)
206+
vim.api.nvim_buf_add_highlight(buf, constants.hl, ...)
207207
end
208208

209209
function util.window_neighbors(window_id, sides)

lua/carbon/view.lua

+14-27
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,8 @@ 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(
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-
)
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)
7363
util.cursor(ctx.edit_lnum + 1, math.max(ctx.edit_col, vim.fn.col('.')))
7464
end
7565
end
@@ -388,7 +378,14 @@ function view:render()
388378
end
389379

390380
for _, hl in ipairs(hls) do
391-
vim.hl.range(buf, constants.hl, hl[1], { hl[2], hl[3] }, { hl[2], hl[4] })
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+
)
392389
end
393390

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

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

417414
vim.defer_fn(function()
418415
if vim.api.nvim_buf_is_valid(buf) then
@@ -860,12 +857,7 @@ function view:delete()
860857
end
861858

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

870862
vim.cmd.redraw()
871863

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

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

905897
self:render()
@@ -932,12 +924,7 @@ function view:move()
932924
end
933925

934926
util.clear_extmarks(0, { lnum_idx, start_hl }, { lnum_idx, -1 }, {})
935-
util.add_highlight(
936-
0,
937-
'CarbonPending',
938-
{ lnum_idx, start_hl },
939-
{ lnum_idx, -1 }
940-
)
927+
util.add_highlight(0, 'CarbonPending', lnum_idx, start_hl, -1)
941928
vim.cmd.redraw({ bang = true })
942929
vim.cmd.echohl('CarbonPending')
943930

0 commit comments

Comments
 (0)