Skip to content

Commit e3a1395

Browse files
committed
Merge pull request #156 from bfredl/bufhl
buffer: add wrappers for add_highlight/clear_highlight functions
2 parents 4373c94 + 62e347a commit e3a1395

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

neovim/api/buffer.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,20 @@ def range(self, start, end):
127127
"""Return a `Range` object, which represents part of the Buffer."""
128128
return Range(self, start, end)
129129

130+
def add_highlight(self, hl_group, line, col_start=0,
131+
col_end=-1, src_id=-1, async=None):
132+
"""Add a highlight to the buffer."""
133+
if async is None:
134+
async = (src_id != 0)
135+
return self._session.request('buffer_add_highlight', self, src_id,
136+
hl_group, line, col_start,
137+
col_end, async=async)
138+
139+
def clear_highlight(self, src_id, line_start=0, line_end=-1, async=True):
140+
"""clear highlights from the buffer."""
141+
self._session.request('buffer_clear_highlight', self, src_id,
142+
line_start, line_end, async=async)
143+
130144
@property
131145
def name(self):
132146
"""Get the buffer name."""

neovim/api/nvim.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,10 @@ def quit(self, quit_command='qa!'):
222222
# ignore it.
223223
pass
224224

225+
def new_highlight_source(self):
226+
"""Return new src_id for use with Buffer.add_highlight."""
227+
return self.current.buffer.add_highlight("", 0, src_id=0)
228+
225229

226230
class Current(object):
227231

0 commit comments

Comments
 (0)