aboutsummaryrefslogtreecommitdiff
path: root/src/klib
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2024-03-31 11:20:05 +0800
committerGitHub <noreply@github.com>2024-03-31 11:20:05 +0800
commite1ff2c51cad755d0ddc04a23df23e317d77023ed (patch)
treea32389bcb708f2b0efed0134ffafc206b527db08 /src/klib
parent12240600f5d2c992aa77bc4592edc16814abfafd (diff)
downloadrneovim-e1ff2c51cad755d0ddc04a23df23e317d77023ed.tar.gz
rneovim-e1ff2c51cad755d0ddc04a23df23e317d77023ed.tar.bz2
rneovim-e1ff2c51cad755d0ddc04a23df23e317d77023ed.zip
feat(lua): pass keys before mapping to vim.on_key() callback (#28098)
Keys before mapping (i.e. typed keys) are passed as the second argument.
Diffstat (limited to 'src/klib')
-rw-r--r--src/klib/kvec.h17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/klib/kvec.h b/src/klib/kvec.h
index a32b35a14c..1b9e6fd9f8 100644
--- a/src/klib/kvec.h
+++ b/src/klib/kvec.h
@@ -153,6 +153,12 @@
type init_array[INIT_SIZE]; \
}
+#define KVI_INITIAL_VALUE(v) { \
+ .size = 0, \
+ .capacity = ARRAY_SIZE((v).init_array), \
+ .items = (v).init_array \
+}
+
/// Initialize vector with preallocated array
///
/// @param[out] v Vector to initialize.
@@ -218,6 +224,17 @@ static inline void *_memcpy_free(void *const restrict dest, void *const restrict
} \
} while (0)
+#define kvi_concat_len(v, data, len) \
+ if (len > 0) { \
+ kvi_ensure_more_space(v, len); \
+ assert((v).items); \
+ memcpy((v).items + (v).size, data, sizeof((v).items[0]) * len); \
+ (v).size = (v).size + len; \
+ }
+
+#define kvi_concat(v, str) kvi_concat_len(v, str, strlen(str))
+#define kvi_splice(v1, v0) kvi_concat_len(v1, (v0).items, (v0).size)
+
/// Get location where to store new element to a vector with preallocated array
///
/// @param[in,out] v Vector to push to.