aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichael Lingelbach <m.j.lbach@gmail.com>2022-01-08 08:14:24 -0800
committerMichael Lingelbach <m.j.lbach@gmail.com>2022-01-08 08:47:20 -0800
commit11142f6ffe46da1f20c570333a2c05b6e3015f56 (patch)
treec0e2658925eb1f5b99dece5ae872ad74d0999d0c /src
parentb4fbb9dcf2752d95b9be335d99b0c55efb5f17de (diff)
downloadrneovim-11142f6ffe46da1f20c570333a2c05b6e3015f56.tar.gz
rneovim-11142f6ffe46da1f20c570333a2c05b6e3015f56.tar.bz2
rneovim-11142f6ffe46da1f20c570333a2c05b6e3015f56.zip
feat(extmarks): add strict option
The strict option, when set to false, allows placing extmarks on invalid row and column values greater than the maximum buffer row or line column respectively. This allows for nvim_buf_set_extmark to be a drop-in replacement for nvim_buf_set_highlight.
Diffstat (limited to 'src')
-rw-r--r--src/nvim/api/extmark.c13
-rw-r--r--src/nvim/api/keysets.lua1
2 files changed, 11 insertions, 3 deletions
diff --git a/src/nvim/api/extmark.c b/src/nvim/api/extmark.c
index 742b953c2a..04456eee01 100644
--- a/src/nvim/api/extmark.c
+++ b/src/nvim/api/extmark.c
@@ -404,6 +404,10 @@ Array nvim_buf_get_extmarks(Buffer buffer, Integer ns_id, Object start, Object e
/// for left). Defaults to false.
/// - priority: a priority value for the highlight group. For
/// example treesitter highlighting uses a value of 100.
+/// - strict: boolean that indicates extmark should be placed
+/// even if the line or column value is past the end of the
+/// buffer or end of the line respectively. Defaults to true.
+///
/// @param[out] err Error details, if any
/// @return Id of the created/updated extmark
Integer nvim_buf_set_extmark(Buffer buffer, Integer ns_id, Integer line, Integer col,
@@ -596,7 +600,10 @@ Integer nvim_buf_set_extmark(Buffer buffer, Integer ns_id, Integer line, Integer
bool ephemeral = false;
OPTION_TO_BOOL(ephemeral, ephemeral, false);
- if (line < 0 || line > buf->b_ml.ml_line_count) {
+ bool strict = true;
+ OPTION_TO_BOOL(strict, strict, true);
+
+ if (line < 0 || (line > buf->b_ml.ml_line_count && strict)) {
api_set_error(err, kErrorTypeValidation, "line value outside range");
goto error;
} else if (line < buf->b_ml.ml_line_count) {
@@ -605,7 +612,7 @@ Integer nvim_buf_set_extmark(Buffer buffer, Integer ns_id, Integer line, Integer
if (col == -1) {
col = (Integer)len;
- } else if (col < -1 || col > (Integer)len) {
+ } else if (col < -1 || (col > (Integer)len && strict)) {
api_set_error(err, kErrorTypeValidation, "col value outside range");
goto error;
}
@@ -620,7 +627,7 @@ Integer nvim_buf_set_extmark(Buffer buffer, Integer ns_id, Integer line, Integer
// reuse len from before
line2 = (int)line;
}
- if (col2 > (Integer)len) {
+ if (col2 > (Integer)len && strict) {
api_set_error(err, kErrorTypeValidation, "end_col value outside range");
goto error;
}
diff --git a/src/nvim/api/keysets.lua b/src/nvim/api/keysets.lua
index 97ee885ff6..a385cfc64f 100644
--- a/src/nvim/api/keysets.lua
+++ b/src/nvim/api/keysets.lua
@@ -21,6 +21,7 @@ return {
"virt_lines";
"virt_lines_above";
"virt_lines_leftcol";
+ "strict";
};
keymap = {
"noremap";