refactor(options): remove get_option_value_strict

Problem: `get_option_value_for` can perfectly replace `get_option_value_strict`, making the latter redundant.

Solution: Remove `get_option_value_strict`
This commit is contained in:
Famiu Haque
2024-10-29 03:21:33 +06:00
committed by Lewis Russell
parent 3688a33354
commit 86e54734bf
2 changed files with 43 additions and 73 deletions

View File

@@ -3978,76 +3978,6 @@ int get_option_attrs(OptIndex opt_idx)
return attrs;
}
/// Check if option has a value in the requested scope.
///
/// @param opt_idx Option index in options[] table.
/// @param req_scope Requested option scope. See OptReqScope in option.h.
///
/// @return true if option has a value in the requested scope, false otherwise.
static bool option_has_scope(OptIndex opt_idx, OptReqScope req_scope)
{
if (opt_idx == kOptInvalid) {
return false;
}
vimoption_T *opt = get_option(opt_idx);
// Hidden option.
if (opt->var == NULL) {
return false;
}
// TTY option.
if (is_tty_option(opt->fullname)) {
return req_scope == kOptReqGlobal;
}
switch (req_scope) {
case kOptReqGlobal:
return opt->var != VAR_WIN;
case kOptReqBuf:
return opt->indir & PV_BUF;
case kOptReqWin:
return opt->indir & PV_WIN;
}
UNREACHABLE;
}
/// Get the option value in the requested scope.
///
/// @param opt_idx Option index in options[] table.
/// @param req_scope Requested option scope. See OptReqScope in option.h.
/// @param[in] from Pointer to buffer or window for local option value.
/// @param[out] err Error message, if any.
///
/// @return Option value in the requested scope. Returns a Nil option value if option is not found,
/// hidden or if it isn't present in the requested scope. (i.e. has no global, window-local or
/// buffer-local value depending on opt_scope).
OptVal get_option_value_strict(OptIndex opt_idx, OptReqScope req_scope, void *from, Error *err)
{
if (opt_idx == kOptInvalid || !option_has_scope(opt_idx, req_scope)) {
return NIL_OPTVAL;
}
vimoption_T *opt = get_option(opt_idx);
switchwin_T switchwin;
aco_save_T aco;
void *ctx = req_scope == kOptReqWin ? (void *)&switchwin
: (req_scope == kOptReqBuf ? (void *)&aco : NULL);
bool switched = switch_option_context(ctx, req_scope, from, err);
if (ERROR_SET(err)) {
return NIL_OPTVAL;
}
char *varp = get_varp_scope(opt, req_scope == kOptReqGlobal ? OPT_GLOBAL : OPT_LOCAL);
OptVal retv = optval_from_varp(opt_idx, varp);
if (switched) {
restore_option_context(ctx, req_scope);
}
return retv;
}
/// Get option value for buffer / window.
///
/// @param opt_idx Option index in options[] table.