diff options
author | Famiu Haque <famiuhaque@proton.me> | 2023-05-23 14:25:10 +0600 |
---|---|---|
committer | Famiu Haque <famiuhaque@proton.me> | 2023-05-23 15:20:41 +0600 |
commit | cfd4fdfea4d0e68ea50ad412b88b5289ded6fd6f (patch) | |
tree | 9cae576fc90b55c9586286706a9d1754762bea8b /src/nvim/api/autocmd.c | |
parent | 62a80c36c158ecf4ffc8c93d8891aeb2f0d2f287 (diff) | |
download | rneovim-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/api/autocmd.c')
-rw-r--r-- | src/nvim/api/autocmd.c | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/src/nvim/api/autocmd.c b/src/nvim/api/autocmd.c index 6ecbff2606..14937cfd8f 100644 --- a/src/nvim/api/autocmd.c +++ b/src/nvim/api/autocmd.c @@ -293,17 +293,17 @@ Array nvim_get_autocmds(Dict(get_autocmds) *opts, Error *err) break; case kCallbackFuncref: case kCallbackPartial: - PUT(autocmd_info, "callback", STRING_OBJ(cstr_as_string(callback_to_string(cb)))); + PUT(autocmd_info, "callback", CSTR_AS_OBJ(callback_to_string(cb))); break; default: abort(); } } else { - PUT(autocmd_info, "command", STRING_OBJ(cstr_as_string(xstrdup(ac->exec.callable.cmd)))); + PUT(autocmd_info, "command", CSTR_TO_OBJ(ac->exec.callable.cmd)); } - PUT(autocmd_info, "pattern", STRING_OBJ(cstr_to_string(ap->pat))); - PUT(autocmd_info, "event", STRING_OBJ(cstr_to_string(event_nr2name(event)))); + PUT(autocmd_info, "pattern", CSTR_TO_OBJ(ap->pat)); + PUT(autocmd_info, "event", CSTR_TO_OBJ(event_nr2name(event))); PUT(autocmd_info, "once", BOOLEAN_OBJ(ac->once)); if (ap->buflocal_nr) { @@ -475,7 +475,7 @@ Integer nvim_create_autocmd(uint64_t channel_id, Object event, Dict(create_autoc } if (patterns.size == 0) { - ADD(patterns, STRING_OBJ(STATIC_CSTR_TO_STRING("*"))); + ADD(patterns, STATIC_CSTR_TO_OBJ("*")); } VALIDATE_R((event_array.size > 0), "event", { @@ -587,7 +587,7 @@ void nvim_clear_autocmds(Dict(clear_autocmds) *opts, Error *err) // When we create the autocmds, we want to say that they are all matched, so that's * // but when we clear them, we want to say that we didn't pass a pattern, so that's NUL if (patterns.size == 0) { - ADD(patterns, STRING_OBJ(STATIC_CSTR_TO_STRING(""))); + ADD(patterns, STATIC_CSTR_TO_OBJ("")); } // If we didn't pass any events, that means clear all events. @@ -763,7 +763,7 @@ void nvim_exec_autocmds(Object event, Dict(exec_autocmds) *opts, Error *err) } if (patterns.size == 0) { - ADD(patterns, STRING_OBJ(STATIC_CSTR_TO_STRING(""))); + ADD(patterns, STATIC_CSTR_TO_OBJ("")); } if (HAS_KEY(opts->data)) { @@ -894,7 +894,7 @@ static bool get_patterns_from_pattern_or_buf(Array *patterns, Object pattern, Ob } snprintf((char *)pattern_buflocal, BUFLOCAL_PAT_LEN, "<buffer=%d>", (int)buf->handle); - ADD(*patterns, STRING_OBJ(cstr_to_string(pattern_buflocal))); + ADD(*patterns, CSTR_TO_OBJ(pattern_buflocal)); } return true; |