refactor: remove CPO_TO_CPO_FLAGS() (#26718)

Just pass p_cpo to replace_termcodes() directly.
This allows removing option_vars.h from keycodes.h, and also avoids the
mistake of passing 0 as cpo_flags.
This commit is contained in:
zeertzjq
2023-12-23 15:53:28 +08:00
committed by GitHub
parent 3c667d3e0f
commit c16d5729b5
8 changed files with 32 additions and 39 deletions

View File

@@ -852,8 +852,8 @@ int get_mouse_button(int code, bool *is_click, bool *is_drag)
/// K_SPECIAL by itself is replaced by K_SPECIAL KS_SPECIAL KE_FILLER.
///
/// When "flags" has REPTERM_FROM_PART, trailing <C-v> is included, otherwise it is removed (to make
/// ":map xx ^V" map xx to nothing). When cpo_flags contains FLAG_CPO_BSLASH, a backslash can be
/// used in place of <C-v>. All other <C-v> characters are removed.
/// ":map xx ^V" map xx to nothing). When cpo_val contains CPO_BSLASH, a backslash can be used in
/// place of <C-v>. All other <C-v> characters are removed.
///
/// @param[in] from What characters to replace.
/// @param[in] from_len Length of the "from" argument.
@@ -867,20 +867,21 @@ int get_mouse_button(int code, bool *is_click, bool *is_drag)
/// REPTERM_NO_SPECIAL do not accept <key> notation
/// REPTERM_NO_SIMPLIFY do not simplify <C-H> into 0x08, etc.
/// @param[out] did_simplify set when some <C-H> code was simplified, unless it is NULL.
/// @param[in] cpo_flags Relevant flags derived from p_cpo, see CPO_TO_CPO_FLAGS.
/// @param[in] cpo_val The value of 'cpoptions' to use. Only CPO_BSLASH matters.
///
/// @return The same as what `*bufp` is set to.
char *replace_termcodes(const char *const from, const size_t from_len, char **const bufp,
const scid_T sid_arg, const int flags, bool *const did_simplify,
const int cpo_flags)
FUNC_ATTR_NONNULL_ARG(1, 3)
const char *const cpo_val)
FUNC_ATTR_NONNULL_ARG(1, 3, 7)
{
char key;
size_t dlen = 0;
const char *src;
const char *const end = from + from_len - 1;
const bool do_backslash = !(cpo_flags & FLAG_CPO_BSLASH); // backslash is a special character
// backslash is a special character
const bool do_backslash = (vim_strchr(cpo_val, CPO_BSLASH) == NULL);
const bool do_special = !(flags & REPTERM_NO_SPECIAL);
bool allocated = (*bufp == NULL);