patch 9.1.1169: using global variable for get_insert()/get_lambda_name()
Problem: using global variable for get_insert()/get_lambda_name()
(after v9.1.1151)
Solution: let the functions return a string_T object instead
(Yee Cheng Chin)
In #16720, `get_insert()` was modified to store a string length in a
global variable to be queried immediately by another `get_insert_len()`
function, which is somewhat fragile. Instead, just have the function
itself return a `string_T` object instead. Also do the same for
`get_lambda_name()` which has similar issues.
closes: #16775
Signed-off-by: Yee Cheng Chin <ychin.git@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
diff --git a/src/getchar.c b/src/getchar.c
index 014e575..05ae373 100644
--- a/src/getchar.c
+++ b/src/getchar.c
@@ -88,9 +88,6 @@
static size_t last_recorded_len = 0; // number of last recorded chars
-static size_t last_get_inserted_len = 0; // length of the string returned from the
- // last call to get_inserted()
-
#ifdef FEAT_EVAL
mapblock_T *last_used_map = NULL;
int last_used_sid = -1;
@@ -203,19 +200,13 @@
* Return the contents of the redo buffer as a single string.
* K_SPECIAL and CSI in the returned string are escaped.
*/
- char_u *
+ string_T
get_inserted(void)
{
- return get_buffcont(&redobuff, FALSE, &last_get_inserted_len);
-}
-
-/*
- * Return the length of string returned from the last call of get_inserted().
- */
- size_t
-get_inserted_len(void)
-{
- return last_get_inserted_len;
+ size_t len = 0;
+ char_u* str = get_buffcont(&redobuff, FALSE, &len);
+ string_T ret = { str, len };
+ return ret;
}
/*