mirror of
https://github.com/neovim/neovim.git
synced 2025-09-07 11:58:17 +00:00
refactor(api): new helper macros
Adds new API helper macros `CSTR_AS_OBJ()`, `STATIC_CSTR_AS_OBJ()`, and `STATIC_CSTR_TO_OBJ()`, which cleans up a lot of the current code. These macros will also be used extensively in the upcoming option refactor PRs because then API Objects will be used to get/set options. This PR also modifies pre-existing code to use old API helper macros like `CSTR_TO_OBJ()` to make them cleaner.
This commit is contained in:
@@ -531,7 +531,7 @@ static void find_runtime_cb(char *fname, void *cookie)
|
||||
{
|
||||
Array *rv = (Array *)cookie;
|
||||
if (fname != NULL) {
|
||||
ADD(*rv, STRING_OBJ(cstr_to_string(fname)));
|
||||
ADD(*rv, CSTR_TO_OBJ(fname));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1383,7 +1383,7 @@ Dictionary nvim_get_mode(void)
|
||||
get_mode(modestr);
|
||||
bool blocked = input_blocking();
|
||||
|
||||
PUT(rv, "mode", STRING_OBJ(cstr_to_string(modestr)));
|
||||
PUT(rv, "mode", CSTR_TO_OBJ(modestr));
|
||||
PUT(rv, "blocking", BOOLEAN_OBJ(blocked));
|
||||
|
||||
return rv;
|
||||
@@ -1926,7 +1926,7 @@ Array nvim__inspect_cell(Integer grid, Integer row, Integer col, Arena *arena, E
|
||||
}
|
||||
ret = arena_array(arena, 3);
|
||||
size_t off = g->line_offset[(size_t)row] + (size_t)col;
|
||||
ADD_C(ret, STRING_OBJ(cstr_as_string((char *)g->chars[off])));
|
||||
ADD_C(ret, CSTR_AS_OBJ((char *)g->chars[off]));
|
||||
int attr = g->attrs[off];
|
||||
ADD_C(ret, DICTIONARY_OBJ(hl_get_attr_by_id(attr, true, arena, err)));
|
||||
// will not work first time
|
||||
@@ -2035,7 +2035,7 @@ Array nvim_get_mark(String name, Dictionary opts, Error *err)
|
||||
ADD(rv, INTEGER_OBJ(row));
|
||||
ADD(rv, INTEGER_OBJ(col));
|
||||
ADD(rv, INTEGER_OBJ(bufnr));
|
||||
ADD(rv, STRING_OBJ(cstr_to_string(filename)));
|
||||
ADD(rv, CSTR_TO_OBJ(filename));
|
||||
|
||||
if (allocated) {
|
||||
xfree(filename);
|
||||
|
Reference in New Issue
Block a user