aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/api/buffer.c36
-rw-r--r--src/api/buffer.h5
2 files changed, 36 insertions, 5 deletions
diff --git a/src/api/buffer.c b/src/api/buffer.c
index 6dde6d6ae0..aeb507ac6e 100644
--- a/src/api/buffer.c
+++ b/src/api/buffer.c
@@ -321,9 +321,41 @@ void buffer_insert(Buffer buffer, int64_t index, StringArray lines, Error *err)
buffer_set_slice(buffer, index, index, false, true, lines, err);
}
-Position buffer_mark(Buffer buffer, String name, Error *err)
+Position buffer_get_mark(Buffer buffer, String name, Error *err)
{
- abort();
+ Position rv;
+ buf_T *buf = find_buffer(buffer, err);
+
+ if (!buf) {
+ return rv;
+ }
+
+ if (name.size != 0) {
+ set_api_error("mark name must be a single character", err);
+ return rv;
+ }
+
+ pos_T *posp;
+ buf_T *savebuf;
+ char mark = *name.data;
+
+ try_start();
+ switch_buffer(&savebuf, buf);
+ posp = getmark(mark, false);
+ restore_buffer(savebuf);
+
+ if (try_end(err)) {
+ return rv;
+ }
+
+ if (posp == NULL) {
+ set_api_error("invalid mark name", err);
+ return rv;
+ }
+
+ rv.row = posp->lnum;
+ rv.col = posp->col;
+ return rv;
}
static void switch_to_win_for_buf(buf_T *buf,
diff --git a/src/api/buffer.h b/src/api/buffer.h
index 1e7ec07ec5..33f4e5733f 100644
--- a/src/api/buffer.h
+++ b/src/api/buffer.h
@@ -133,14 +133,13 @@ bool buffer_is_valid(Buffer buffer);
/// @param[out] err Details of an error that may have occurred
void buffer_insert(Buffer buffer, int64_t index, StringArray lines, Error *err);
-/// Creates a mark in the buffer and returns a tuple(row, col) representing
-/// the position of the named mark
+/// Return a tuple (row,col) representing the position of the named mark
///
/// @param buffer The buffer handle
/// @param name The mark's name
/// @param[out] err Details of an error that may have occurred
/// @return The (row, col) tuple
-Position buffer_mark(Buffer buffer, String name, Error *err);
+Position buffer_get_mark(Buffer buffer, String name, Error *err);
#endif // NEOVIM_API_BUFFER_H