aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/api/private/helpers.c
diff options
context:
space:
mode:
authorJavier Lopez <graulopezjavier@gmail.com>2021-10-05 10:49:20 -0500
committerGitHub <noreply@github.com>2021-10-05 08:49:20 -0700
commit49fdc62114a5f37def3ff60ca0c4d8638903ac24 (patch)
tree8d75845ca18d9dd9c6da261473673445ab0bef27 /src/nvim/api/private/helpers.c
parent912a6e5a9c58fce74134f9f8c2801373928e8289 (diff)
downloadrneovim-49fdc62114a5f37def3ff60ca0c4d8638903ac24.tar.gz
rneovim-49fdc62114a5f37def3ff60ca0c4d8638903ac24.tar.bz2
rneovim-49fdc62114a5f37def3ff60ca0c4d8638903ac24.zip
feat(api): named marks set, get, delete #15346
Adds the following API functions. - nvim_buf_set_mark(buf, name, line, col) * Set marks in a buffer. - nvim_buf_del_mark(buf, name) * Delete a mark that belongs to buffer. - nvim_del_mark(name) * Delete a global mark. - nvim_get_mark(name) * Get a global mark. Tests: - Adds test to all the new api functions, and adds more for the existing nvim_buf_get_mark. * Tests include failure cases. Documentation: - Adds documentation for all the new functions, and improves the existing fucntion docs.
Diffstat (limited to 'src/nvim/api/private/helpers.c')
-rw-r--r--src/nvim/api/private/helpers.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c
index 7b70c183c3..46ef41cc38 100644
--- a/src/nvim/api/private/helpers.c
+++ b/src/nvim/api/private/helpers.c
@@ -25,6 +25,7 @@
#include "nvim/lua/executor.h"
#include "nvim/map.h"
#include "nvim/map_defs.h"
+#include "nvim/mark.h"
#include "nvim/memline.h"
#include "nvim/memory.h"
#include "nvim/msgpack_rpc/helpers.h"
@@ -1671,3 +1672,42 @@ void api_free_keydict(void *dict, KeySetLink *table)
}
}
+/// Set a named mark
+/// buffer and mark name must be validated already
+/// @param buffer Buffer to set the mark on
+/// @param name Mark name
+/// @param line Line number
+/// @param col Column/row number
+/// @return true if the mark was set, else false
+bool set_mark(buf_T *buf, String name, Integer line, Integer col, Error *err)
+{
+ buf = buf == NULL ? curbuf : buf;
+ // If line == 0 the marks is being deleted
+ bool res = false;
+ bool deleting = false;
+ if (line == 0) {
+ col = 0;
+ deleting = true;
+ } else {
+ if (col > MAXCOL) {
+ api_set_error(err, kErrorTypeValidation, "Column value outside range");
+ return res;
+ }
+ if (line < 1 || line > buf->b_ml.ml_line_count) {
+ api_set_error(err, kErrorTypeValidation, "Line value outside range");
+ return res;
+ }
+ }
+ pos_T pos = { line, (int)col, (int)col };
+ res = setmark_pos(*name.data, &pos, buf->handle);
+ if (!res) {
+ if (deleting) {
+ api_set_error(err, kErrorTypeException,
+ "Failed to delete named mark: %c", *name.data);
+ } else {
+ api_set_error(err, kErrorTypeException,
+ "Failed to set named mark: %c", *name.data);
+ }
+ }
+ return res;
+}