aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/buffer.c
diff options
context:
space:
mode:
authorZyX <kp-pav@yandex.ru>2017-11-06 20:23:35 +0300
committerZyX <kp-pav@yandex.ru>2017-11-06 20:23:35 +0300
commit24a353364d6d186d528009fd0bb603d87183cf35 (patch)
treea4070dc00731475d6bbdd3c84e61806b33802f7a /src/nvim/buffer.c
parentf2660bee6aca35be3d0ddb1d225784476c13cd27 (diff)
parent946c2a8ee85830c543e389724575ae531e89b170 (diff)
downloadrneovim-24a353364d6d186d528009fd0bb603d87183cf35.tar.gz
rneovim-24a353364d6d186d528009fd0bb603d87183cf35.tar.bz2
rneovim-24a353364d6d186d528009fd0bb603d87183cf35.zip
Merge branch 'master' into expression-parser
Diffstat (limited to 'src/nvim/buffer.c')
-rw-r--r--src/nvim/buffer.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c
index 9d42fbc1b3..f874268910 100644
--- a/src/nvim/buffer.c
+++ b/src/nvim/buffer.c
@@ -5278,6 +5278,44 @@ int bufhl_add_hl(buf_T *buf,
return src_id;
}
+/// Add highlighting to a buffer, bounded by two cursor positions,
+/// with an offset.
+///
+/// @param buf Buffer to add highlights to
+/// @param src_id src_id to use or 0 to use a new src_id group,
+/// or -1 for ungrouped highlight.
+/// @param hl_id Highlight group id
+/// @param pos_start Cursor position to start the hightlighting at
+/// @param pos_end Cursor position to end the highlighting at
+/// @param offset Move the whole highlighting this many columns to the right
+void bufhl_add_hl_pos_offset(buf_T *buf,
+ int src_id,
+ int hl_id,
+ lpos_T pos_start,
+ lpos_T pos_end,
+ colnr_T offset)
+{
+ colnr_T hl_start = 0;
+ colnr_T hl_end = 0;
+
+ for (linenr_T lnum = pos_start.lnum; lnum <= pos_end.lnum; lnum ++) {
+ if (pos_start.lnum < lnum && lnum < pos_end.lnum) {
+ hl_start = offset;
+ hl_end = MAXCOL;
+ } else if (lnum == pos_start.lnum && lnum < pos_end.lnum) {
+ hl_start = pos_start.col + offset + 1;
+ hl_end = MAXCOL;
+ } else if (pos_start.lnum < lnum && lnum == pos_end.lnum) {
+ hl_start = offset;
+ hl_end = pos_end.col + offset;
+ } else if (pos_start.lnum == lnum && pos_end.lnum == lnum) {
+ hl_start = pos_start.col + offset + 1;
+ hl_end = pos_end.col + offset;
+ }
+ (void)bufhl_add_hl(buf, src_id, hl_id, lnum, hl_start, hl_end);
+ }
+}
+
/// Clear bufhl highlights from a given source group and range of lines.
///
/// @param buf The buffer to remove highlights from