1
0
forked from aniani/vim

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>
This commit is contained in:
Yee Cheng Chin
2025-03-03 20:12:05 +01:00
committed by Christian Brabandt
parent d2219d547d
commit 0b5fe42071
7 changed files with 40 additions and 66 deletions

View File

@@ -415,14 +415,10 @@ edit(
* Get the current length of the redo buffer, those characters have to be
* skipped if we want to get to the inserted characters.
*/
ptr = get_inserted();
if (ptr == NULL)
new_insert_skip = 0;
else
{
new_insert_skip = (int)get_inserted_len();
vim_free(ptr);
}
string_T inserted = get_inserted();
new_insert_skip = (int)inserted.length;
if (inserted.string != NULL)
vim_free(inserted.string);
old_indent = 0;
@@ -2445,7 +2441,7 @@ stop_insert(
int nomove) // <c-\><c-o>, don't move cursor
{
int cc;
char_u *ptr;
string_T inserted;
stop_redo_ins();
replace_flush(); // abandon replace stack
@@ -2455,16 +2451,16 @@ stop_insert(
* Don't do it when "restart_edit" was set and nothing was inserted,
* otherwise CTRL-O w and then <Left> will clear "last_insert".
*/
ptr = get_inserted();
int added = ptr == NULL ? 0 : (int)get_inserted_len() - new_insert_skip;
inserted = get_inserted();
int added = inserted.string == NULL ? 0 : (int)inserted.length - new_insert_skip;
if (did_restart_edit == 0 || added > 0)
{
vim_free(last_insert);
last_insert = ptr;
last_insert = inserted.string;
last_insert_skip = added < 0 ? 0 : new_insert_skip;
}
else
vim_free(ptr);
vim_free(inserted.string);
if (!arrow_used && end_insert_pos != NULL)
{