aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/usercmd.c
diff options
context:
space:
mode:
authorFamiu Haque <famiuhaque@proton.me>2023-05-23 14:25:10 +0600
committerFamiu Haque <famiuhaque@proton.me>2023-05-23 15:20:41 +0600
commitcfd4fdfea4d0e68ea50ad412b88b5289ded6fd6f (patch)
tree9cae576fc90b55c9586286706a9d1754762bea8b /src/nvim/usercmd.c
parent62a80c36c158ecf4ffc8c93d8891aeb2f0d2f287 (diff)
downloadrneovim-cfd4fdfea4d0e68ea50ad412b88b5289ded6fd6f.tar.gz
rneovim-cfd4fdfea4d0e68ea50ad412b88b5289ded6fd6f.tar.bz2
rneovim-cfd4fdfea4d0e68ea50ad412b88b5289ded6fd6f.zip
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.
Diffstat (limited to 'src/nvim/usercmd.c')
-rw-r--r--src/nvim/usercmd.c22
1 files changed, 11 insertions, 11 deletions
diff --git a/src/nvim/usercmd.c b/src/nvim/usercmd.c
index 11f2620aaa..c56b241988 100644
--- a/src/nvim/usercmd.c
+++ b/src/nvim/usercmd.c
@@ -1754,8 +1754,8 @@ Dictionary commands_array(buf_T *buf)
Dictionary d = ARRAY_DICT_INIT;
ucmd_T *cmd = USER_CMD_GA(gap, i);
- PUT(d, "name", STRING_OBJ(cstr_to_string(cmd->uc_name)));
- PUT(d, "definition", STRING_OBJ(cstr_to_string(cmd->uc_rep)));
+ PUT(d, "name", CSTR_TO_OBJ(cmd->uc_name));
+ PUT(d, "definition", CSTR_TO_OBJ(cmd->uc_rep));
PUT(d, "script_id", INTEGER_OBJ(cmd->uc_script_ctx.sc_sid));
PUT(d, "bang", BOOLEAN_OBJ(!!(cmd->uc_argt & EX_BANG)));
PUT(d, "bar", BOOLEAN_OBJ(!!(cmd->uc_argt & EX_TRLBAR)));
@@ -1775,21 +1775,21 @@ Dictionary commands_array(buf_T *buf)
case (EX_EXTRA | EX_NOSPC | EX_NEEDARG):
arg[0] = '1'; break;
}
- PUT(d, "nargs", STRING_OBJ(cstr_to_string(arg)));
+ PUT(d, "nargs", CSTR_TO_OBJ(arg));
char *cmd_compl = get_command_complete(cmd->uc_compl);
PUT(d, "complete", (cmd_compl == NULL
- ? NIL : STRING_OBJ(cstr_to_string(cmd_compl))));
+ ? NIL : CSTR_TO_OBJ(cmd_compl)));
PUT(d, "complete_arg", cmd->uc_compl_arg == NULL
- ? NIL : STRING_OBJ(cstr_to_string(cmd->uc_compl_arg)));
+ ? NIL : CSTR_TO_OBJ(cmd->uc_compl_arg));
Object obj = NIL;
if (cmd->uc_argt & EX_COUNT) {
if (cmd->uc_def >= 0) {
snprintf(str, sizeof(str), "%" PRId64, cmd->uc_def);
- obj = STRING_OBJ(cstr_to_string(str)); // -count=N
+ obj = CSTR_TO_OBJ(str); // -count=N
} else {
- obj = STRING_OBJ(cstr_to_string("0")); // -count
+ obj = CSTR_TO_OBJ("0"); // -count
}
}
PUT(d, "count", obj);
@@ -1797,12 +1797,12 @@ Dictionary commands_array(buf_T *buf)
obj = NIL;
if (cmd->uc_argt & EX_RANGE) {
if (cmd->uc_argt & EX_DFLALL) {
- obj = STRING_OBJ(cstr_to_string("%")); // -range=%
+ obj = CSTR_TO_OBJ("%"); // -range=%
} else if (cmd->uc_def >= 0) {
snprintf(str, sizeof(str), "%" PRId64, cmd->uc_def);
- obj = STRING_OBJ(cstr_to_string(str)); // -range=N
+ obj = CSTR_TO_OBJ(str); // -range=N
} else {
- obj = STRING_OBJ(cstr_to_string(".")); // -range
+ obj = CSTR_TO_OBJ("."); // -range
}
}
PUT(d, "range", obj);
@@ -1811,7 +1811,7 @@ Dictionary commands_array(buf_T *buf)
for (int j = 0; addr_type_complete[j].expand != ADDR_NONE; j++) {
if (addr_type_complete[j].expand != ADDR_LINES
&& addr_type_complete[j].expand == cmd->uc_addr_type) {
- obj = STRING_OBJ(cstr_to_string(addr_type_complete[j].name));
+ obj = CSTR_TO_OBJ(addr_type_complete[j].name);
break;
}
}