aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/option.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/option.c')
-rw-r--r--src/nvim/option.c274
1 files changed, 112 insertions, 162 deletions
diff --git a/src/nvim/option.c b/src/nvim/option.c
index bb86d10425..3d805dc319 100644
--- a/src/nvim/option.c
+++ b/src/nvim/option.c
@@ -22,6 +22,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <uv.h>
#include "auto/config.h"
#include "klib/kvec.h"
@@ -47,6 +48,7 @@
#include "nvim/errors.h"
#include "nvim/eval.h"
#include "nvim/eval/typval.h"
+#include "nvim/eval/typval_defs.h"
#include "nvim/eval/vars.h"
#include "nvim/eval/window.h"
#include "nvim/ex_cmds_defs.h"
@@ -58,6 +60,7 @@
#include "nvim/garray_defs.h"
#include "nvim/gettext_defs.h"
#include "nvim/globals.h"
+#include "nvim/grid_defs.h"
#include "nvim/highlight.h"
#include "nvim/highlight_defs.h"
#include "nvim/highlight_group.h"
@@ -74,6 +77,7 @@
#include "nvim/memfile.h"
#include "nvim/memline.h"
#include "nvim/memory.h"
+#include "nvim/memory_defs.h"
#include "nvim/message.h"
#include "nvim/mouse.h"
#include "nvim/move.h"
@@ -88,7 +92,6 @@
#include "nvim/os/os.h"
#include "nvim/os/os_defs.h"
#include "nvim/path.h"
-#include "nvim/plines.h"
#include "nvim/popupmenu.h"
#include "nvim/pos_defs.h"
#include "nvim/regexp.h"
@@ -104,7 +107,6 @@
#include "nvim/terminal.h"
#include "nvim/types_defs.h"
#include "nvim/ui.h"
-#include "nvim/ui_defs.h"
#include "nvim/undo.h"
#include "nvim/undo_defs.h"
#include "nvim/vim_defs.h"
@@ -228,7 +230,7 @@ static void set_init_default_backupskip(void)
#endif
{
p = vim_getenv(names[i]);
- plen = 0; // will be calcuated below
+ plen = 0; // will be calculated below
}
if (p != NULL && *p != NUL) {
bool has_trailing_path_sep = false;
@@ -429,7 +431,7 @@ void set_init_1(bool clean_arg)
/// Get default value for option, based on the option's type and scope.
///
/// @param opt_idx Option index in options[] table.
-/// @param opt_flags Option flags.
+/// @param opt_flags Option flags (can be OPT_LOCAL, OPT_GLOBAL or a combination).
///
/// @return Default value of option for the scope specified in opt_flags.
static OptVal get_option_default(const OptIndex opt_idx, int opt_flags)
@@ -480,7 +482,7 @@ static void change_option_default(const OptIndex opt_idx, OptVal value)
/// This does not take care of side effects!
///
/// @param opt_idx Option index in options[] table.
-/// @param opt_flags Option flags.
+/// @param opt_flags Option flags (can be OPT_LOCAL, OPT_GLOBAL or a combination).
static void set_option_default(const OptIndex opt_idx, int opt_flags)
{
OptVal def_val = get_option_default(opt_idx, opt_flags);
@@ -497,7 +499,7 @@ static void set_option_default(const OptIndex opt_idx, int opt_flags)
/// Set all options (except terminal options) to their default value.
///
-/// @param opt_flags Option flags.
+/// @param opt_flags Option flags (can be OPT_LOCAL, OPT_GLOBAL or a combination).
static void set_options_default(int opt_flags)
{
for (OptIndex opt_idx = 0; opt_idx < kOptCount; opt_idx++) {
@@ -531,8 +533,8 @@ static void set_string_default(OptIndex opt_idx, char *val, bool allocated)
/// For an option value that contains comma separated items, find "newval" in
/// "origval". Return NULL if not found.
-static char *find_dup_item(char *origval, const char *newval, const size_t newvallen,
- uint32_t flags)
+static const char *find_dup_item(const char *origval, const char *newval, const size_t newvallen,
+ uint32_t flags)
FUNC_ATTR_NONNULL_ARG(2)
{
if (origval == NULL) {
@@ -541,7 +543,7 @@ static char *find_dup_item(char *origval, const char *newval, const size_t newva
int bs = 0;
- for (char *s = origval; *s != NUL; s++) {
+ for (const char *s = origval; *s != NUL; s++) {
if ((!(flags & kOptFlagComma) || s == origval || (s[-1] == ',' && !(bs & 1)))
&& strncmp(s, newval, newvallen) == 0
&& (!(flags & kOptFlagComma) || s[newvallen] == ',' || s[newvallen] == NUL)) {
@@ -725,7 +727,7 @@ void ex_set(exarg_T *eap)
/// Copy the new string value into allocated memory for the option.
/// Can't use set_option_direct(), because we need to remove the backslashes.
-static char *stropt_copy_value(char *origval, char **argp, set_op_T op,
+static char *stropt_copy_value(const char *origval, char **argp, set_op_T op,
uint32_t flags FUNC_ATTR_UNUSED)
{
char *arg = *argp;
@@ -772,7 +774,7 @@ static char *stropt_copy_value(char *origval, char **argp, set_op_T op,
}
/// Expand environment variables and ~ in string option value 'newval'.
-static char *stropt_expand_envvar(OptIndex opt_idx, char *origval, char *newval, set_op_T op)
+static char *stropt_expand_envvar(OptIndex opt_idx, const char *origval, char *newval, set_op_T op)
{
char *s = option_expand(opt_idx, newval);
if (s == NULL) {
@@ -792,7 +794,7 @@ static char *stropt_expand_envvar(OptIndex opt_idx, char *origval, char *newval,
/// Concatenate the original and new values of a string option, adding a "," if
/// needed.
-static void stropt_concat_with_comma(char *origval, char *newval, set_op_T op, uint32_t flags)
+static void stropt_concat_with_comma(const char *origval, char *newval, set_op_T op, uint32_t flags)
{
int len = 0;
int comma = ((flags & kOptFlagComma) && *origval != NUL && *newval != NUL);
@@ -818,7 +820,8 @@ static void stropt_concat_with_comma(char *origval, char *newval, set_op_T op, u
/// Remove a value from a string option. Copy string option value in "origval"
/// to "newval" and then remove the string "strval" of length "len".
-static void stropt_remove_val(char *origval, char *newval, uint32_t flags, char *strval, int len)
+static void stropt_remove_val(const char *origval, char *newval, uint32_t flags, const char *strval,
+ int len)
{
// Remove newval[] from origval[]. (Note: "len" has been set above
// and is used here).
@@ -870,13 +873,13 @@ static void stropt_remove_dupflags(char *newval, uint32_t flags)
/// set {opt}={val}
/// set {opt}:{val}
static char *stropt_get_newval(int nextchar, OptIndex opt_idx, char **argp, void *varp,
- char *origval, set_op_T *op_arg, uint32_t flags)
+ const char *origval, set_op_T *op_arg, uint32_t flags)
{
char *arg = *argp;
set_op_T op = *op_arg;
char *save_arg = NULL;
char *newval;
- char *s = NULL;
+ const char *s = NULL;
arg++; // jump to after the '=' or ':'
@@ -977,12 +980,12 @@ static int validate_opt_idx(win_T *win, OptIndex opt_idx, int opt_flags, uint32_
// Skip all options that are not window-local (used when showing
// an already loaded buffer in a window).
- if ((opt_flags & OPT_WINONLY) && (opt_idx == kOptInvalid || !option_is_window_local(opt_idx))) {
+ if ((opt_flags & OPT_WINONLY) && !option_is_window_local(opt_idx)) {
return FAIL;
}
// Skip all options that are window-local (used for :vimgrep).
- if ((opt_flags & OPT_NOWIN) && opt_idx != kOptInvalid && option_is_window_local(opt_idx)) {
+ if ((opt_flags & OPT_NOWIN) && option_is_window_local(opt_idx)) {
return FAIL;
}
@@ -1192,9 +1195,10 @@ static OptVal get_option_newval(OptIndex opt_idx, int opt_flags, set_prefix_T pr
break;
}
case kOptValTypeString: {
- char *oldval_str = oldval.data.string.data;
+ const char *oldval_str = oldval.data.string.data;
// Get the new value for the option
- char *newval_str = stropt_get_newval(nextchar, opt_idx, argp, varp, oldval_str, &op, flags);
+ const char *newval_str = stropt_get_newval(nextchar, opt_idx, argp, varp, oldval_str, &op,
+ flags);
newval = CSTR_AS_OPTVAL(newval_str);
break;
}
@@ -1276,6 +1280,7 @@ static void do_one_set_option(int opt_flags, char **argp, bool *did_show, char *
gotocmdline(true); // cursor at status line
*did_show = true; // remember that we did a line
}
+ msg_ext_set_kind("list_cmd");
showoneopt(&options[opt_idx], opt_flags);
if (p_verbose > 0) {
@@ -1474,7 +1479,7 @@ void did_set_title(void)
/// set_options_bin - called when 'bin' changes value.
///
-/// @param opt_flags OPT_LOCAL and/or OPT_GLOBAL
+/// @param opt_flags Option flags (can be OPT_LOCAL, OPT_GLOBAL or a combination).
void set_options_bin(int oldval, int newval, int opt_flags)
{
// The option values that are changed when 'bin' changes are
@@ -1565,7 +1570,7 @@ char *find_shada_parameter(int type)
/// These string options cannot be indirect!
/// If "val" is NULL expand the current value of the option.
/// Return pointer to NameBuff, or NULL when not expanded.
-static char *option_expand(OptIndex opt_idx, char *val)
+static char *option_expand(OptIndex opt_idx, const char *val)
{
// if option doesn't need expansion nothing to do
if (!(options[opt_idx].flags & kOptFlagExpand) || is_option_hidden(opt_idx)) {
@@ -1651,7 +1656,7 @@ void check_options(void)
///
/// @param wp Window.
/// @param opt_idx Option index in options[] table.
-/// @param opt_flags Option flags.
+/// @param opt_flags Option flags (can be OPT_LOCAL, OPT_GLOBAL or a combination).
///
/// @return True if option was set from a modeline or in secure mode, false if it wasn't.
int was_set_insecurely(win_T *const wp, OptIndex opt_idx, int opt_flags)
@@ -1735,8 +1740,14 @@ bool parse_winhl_opt(const char *winhl, win_T *wp)
p = wp->w_p_winhl;
}
+ if (wp != NULL && wp->w_ns_hl_winhl < 0) {
+ // 'winhighlight' shouldn't be used for this window.
+ // Only check that the value is valid.
+ wp = NULL;
+ }
+
if (!*p) {
- if (wp != NULL && wp->w_ns_hl_winhl && wp->w_ns_hl == wp->w_ns_hl_winhl) {
+ if (wp != NULL && wp->w_ns_hl_winhl > 0 && wp->w_ns_hl == wp->w_ns_hl_winhl) {
wp->w_ns_hl = 0;
wp->w_hl_needs_update = true;
}
@@ -1970,8 +1981,8 @@ static const char *did_set_cmdheight(optset_T *args)
{
OptInt old_value = args->os_oldval.number;
- if (p_ch > Rows - min_rows() + 1) {
- p_ch = Rows - min_rows() + 1;
+ if (p_ch > Rows - min_rows(curtab) + 1) {
+ p_ch = Rows - min_rows(curtab) + 1;
}
// if p_ch changed value, change the command line height
@@ -2109,14 +2120,14 @@ static const char *did_set_laststatus(optset_T *args)
// When switching to global statusline, decrease topframe height
// Also clear the cmdline to remove the ruler if there is one
if (value == 3 && old_value != 3) {
- frame_new_height(topframe, topframe->fr_height - STATUS_HEIGHT, false, false);
+ frame_new_height(topframe, topframe->fr_height - STATUS_HEIGHT, false, false, false);
win_comp_pos();
clear_cmdline = true;
}
// When switching from global statusline, increase height of topframe by STATUS_HEIGHT
// in order to to re-add the space that was previously taken by the global statusline
if (old_value == 3 && value != 3) {
- frame_new_height(topframe, topframe->fr_height + STATUS_HEIGHT, false, false);
+ frame_new_height(topframe, topframe->fr_height + STATUS_HEIGHT, false, false, false);
win_comp_pos();
}
@@ -2750,10 +2761,11 @@ static const char *check_num_option_bounds(OptIndex opt_idx, OptInt *newval, cha
switch (opt_idx) {
case kOptLines:
- if (*newval < min_rows() && full_screen) {
- vim_snprintf(errbuf, errbuflen, _("E593: Need at least %d lines"), min_rows());
+ if (*newval < min_rows_for_all_tabpages() && full_screen) {
+ vim_snprintf(errbuf, errbuflen, _("E593: Need at least %d lines"),
+ min_rows_for_all_tabpages());
errmsg = errbuf;
- *newval = min_rows();
+ *newval = min_rows_for_all_tabpages();
}
// True max size is defined by check_screensize().
*newval = MIN(*newval, INT_MAX);
@@ -2860,8 +2872,6 @@ static const char *validate_num_option(OptIndex opt_idx, OptInt *newval, char *e
case kOptCmdheight:
if (value < 0) {
return e_positive;
- } else {
- p_ch_was_zero = value == 0;
}
break;
case kOptHistory:
@@ -2871,13 +2881,6 @@ static const char *validate_num_option(OptIndex opt_idx, OptInt *newval, char *e
return e_invarg;
}
break;
- case kOptMsghistory:
- if (value < 0) {
- return e_positive;
- } else if (value > 10000) {
- return e_invarg;
- }
- break;
case kOptPyxversion:
if (value == 0) {
*newval = 3;
@@ -3118,17 +3121,10 @@ bool optval_equal(OptVal o1, OptVal o2)
UNREACHABLE;
}
-/// Get type of option. Does not support multitype options.
+/// Get type of option.
static OptValType option_get_type(const OptIndex opt_idx)
{
- assert(!option_is_multitype(opt_idx));
-
- // If the option only supports a single type, it means that the index of the option's type flag
- // corresponds to the value of the type enum. So get the index of the type flag using xctz() and
- // use that as the option's type.
- OptValType type = xctz(options[opt_idx].type_flags);
- assert(type > kOptValTypeNil && type < kOptValTypeSize);
- return type;
+ return options[opt_idx].type;
}
/// Create OptVal from var pointer.
@@ -3146,11 +3142,6 @@ OptVal optval_from_varp(OptIndex opt_idx, void *varp)
return BOOLEAN_OPTVAL(curbufIsChanged());
}
- if (option_is_multitype(opt_idx)) {
- // Multitype options are stored as OptVal.
- return *(OptVal *)varp;
- }
-
OptValType type = option_get_type(opt_idx);
switch (type) {
@@ -3261,33 +3252,6 @@ OptVal object_as_optval(Object o, bool *error)
UNREACHABLE;
}
-/// Get an allocated string containing a list of valid types for an option.
-/// For options with a singular type, it returns the name of the type. For options with multiple
-/// possible types, it returns a slash separated list of types. For example, if an option can be a
-/// number, boolean or string, the function returns "number/boolean/string"
-static char *option_get_valid_types(OptIndex opt_idx)
-{
- StringBuilder str = KV_INITIAL_VALUE;
- kv_resize(str, 32);
-
- // Iterate through every valid option value type and check if the option supports that type
- for (OptValType type = 0; type < kOptValTypeSize; type++) {
- if (option_has_type(opt_idx, type)) {
- const char *typename = optval_type_get_name(type);
-
- if (str.size == 0) {
- kv_concat(str, typename);
- } else {
- kv_printf(str, "/%s", typename);
- }
- }
- }
-
- // Ensure that the string is NUL-terminated.
- kv_push(str, NUL);
- return str.items;
-}
-
/// Check if option is hidden.
///
/// @param opt_idx Option index in options[] table.
@@ -3300,25 +3264,10 @@ bool is_option_hidden(OptIndex opt_idx)
&& options[opt_idx].var == &options[opt_idx].def_val.data;
}
-/// Check if option is multitype (supports multiple types).
-static bool option_is_multitype(OptIndex opt_idx)
-{
- const OptTypeFlags type_flags = get_option(opt_idx)->type_flags;
- assert(type_flags != 0);
- return !is_power_of_two(type_flags);
-}
-
/// Check if option supports a specific type.
bool option_has_type(OptIndex opt_idx, OptValType type)
{
- // Ensure that type flags variable can hold all types.
- STATIC_ASSERT(kOptValTypeSize <= sizeof(OptTypeFlags) * 8,
- "Option type_flags cannot fit all option types");
- // Ensure that the type is valid before accessing type_flags.
- assert(type > kOptValTypeNil && type < kOptValTypeSize);
- // Bitshift 1 by the value of type to get the type's corresponding flag, and check if it's set in
- // the type_flags bit field.
- return get_option(opt_idx)->type_flags & (1 << type);
+ return opt_idx != kOptInvalid && options[opt_idx].type == type;
}
/// Check if option supports a specific scope.
@@ -3377,18 +3326,18 @@ uint32_t get_option_flags(OptIndex opt_idx)
/// Gets the value for an option.
///
-/// @param opt_idx Option index in options[] table.
-/// @param[in] scope Option scope (can be OPT_LOCAL, OPT_GLOBAL or a combination).
+/// @param opt_idx Option index in options[] table.
+/// @param opt_flags Option flags (can be OPT_LOCAL, OPT_GLOBAL or a combination).
///
/// @return [allocated] Option value. Returns NIL_OPTVAL for invalid option index.
-OptVal get_option_value(OptIndex opt_idx, int scope)
+OptVal get_option_value(OptIndex opt_idx, int opt_flags)
{
if (opt_idx == kOptInvalid) { // option not in the options[] table.
return NIL_OPTVAL;
}
vimoption_T *opt = &options[opt_idx];
- void *varp = get_varp_scope(opt, scope);
+ void *varp = get_varp_scope(opt, opt_flags);
return optval_copy(optval_from_varp(opt_idx, varp));
}
@@ -3461,7 +3410,7 @@ static bool is_option_local_value_unset(OptIndex opt_idx)
/// @param opt_idx Index in options[] table. Must not be kOptInvalid.
/// @param[in] varp Option variable pointer, cannot be NULL.
/// @param old_value Old option value.
-/// @param opt_flags Option flags.
+/// @param opt_flags Option flags (can be OPT_LOCAL, OPT_GLOBAL or a combination).
/// @param set_sid Script ID. Special values:
/// 0: Use current script ID.
/// SID_NONE: Don't set script ID.
@@ -3473,8 +3422,7 @@ static bool is_option_local_value_unset(OptIndex opt_idx)
/// @return NULL on success, an untranslated error message on error.
static const char *did_set_option(OptIndex opt_idx, void *varp, OptVal old_value, OptVal new_value,
int opt_flags, scid_T set_sid, const bool direct,
- const bool value_replaced, char *errbuf, // NOLINT(readability-non-const-parameter)
- size_t errbuflen)
+ const bool value_replaced, char *errbuf, size_t errbuflen)
{
vimoption_T *opt = &options[opt_idx];
const char *errmsg = NULL;
@@ -3656,11 +3604,10 @@ static const char *validate_option_value(const OptIndex opt_idx, OptVal *newval,
}
} else if (!option_has_type(opt_idx, newval->type)) {
char *rep = optval_to_cstr(*newval);
- char *valid_types = option_get_valid_types(opt_idx);
+ const char *type_str = optval_type_get_name(opt->type);
snprintf(errbuf, IOSIZE, _("Invalid value for option '%s': expected %s, got %s %s"),
- opt->fullname, valid_types, optval_type_get_name(newval->type), rep);
+ opt->fullname, type_str, optval_type_get_name(newval->type), rep);
xfree(rep);
- xfree(valid_types);
errmsg = errbuf;
} else if (newval->type == kOptValTypeNumber) {
// Validate and bound check num option values.
@@ -3674,7 +3621,7 @@ static const char *validate_option_value(const OptIndex opt_idx, OptVal *newval,
///
/// @param opt_idx Index in options[] table. Must not be kOptInvalid.
/// @param value New option value. Might get freed.
-/// @param opt_flags Option flags.
+/// @param opt_flags Option flags (can be OPT_LOCAL, OPT_GLOBAL or a combination).
/// @param set_sid Script ID. Special values:
/// 0: Use current script ID.
/// SID_NONE: Don't set script ID.
@@ -3778,7 +3725,7 @@ static const char *set_option(const OptIndex opt_idx, OptVal value, int opt_flag
///
/// @param opt_idx Option index in options[] table.
/// @param value Option value.
-/// @param opt_flags Option flags.
+/// @param opt_flags Option flags (can be OPT_LOCAL, OPT_GLOBAL or a combination).
/// @param set_sid Script ID. Special values:
/// 0: Use current script ID.
/// SID_NONE: Don't set script ID.
@@ -3800,14 +3747,14 @@ void set_option_direct(OptIndex opt_idx, OptVal value, int opt_flags, scid_T set
///
/// @param opt_idx Option index in options[] table.
/// @param value Option value.
-/// @param opt_flags Option flags.
+/// @param opt_flags Option flags (can be OPT_LOCAL, OPT_GLOBAL or a combination).
/// @param set_sid Script ID. Special values:
/// 0: Use current script ID.
/// SID_NONE: Don't set script ID.
-/// @param req_scope Requested option scope. See OptScope in option.h.
+/// @param scope Option scope. See OptScope in option.h.
/// @param[in] from Target buffer/window.
void set_option_direct_for(OptIndex opt_idx, OptVal value, int opt_flags, scid_T set_sid,
- OptScope req_scope, void *const from)
+ OptScope scope, void *const from)
{
buf_T *save_curbuf = curbuf;
win_T *save_curwin = curwin;
@@ -3815,7 +3762,7 @@ void set_option_direct_for(OptIndex opt_idx, OptVal value, int opt_flags, scid_T
// Don't use switch_option_context(), as that calls aucmd_prepbuf(), which may have unintended
// side-effects when setting an option directly. Just change the values of curbuf and curwin if
// needed, no need to properly switch the window / buffer.
- switch (req_scope) {
+ switch (scope) {
case kOptScopeGlobal:
break;
case kOptScopeWin:
@@ -3898,7 +3845,7 @@ const char *set_option_value_handle_tty(const char *name, OptIndex opt_idx, cons
///
/// @param opt_idx Option index in options[] table.
/// @param value Option value. If NIL_OPTVAL, the option value is cleared.
-/// @param opt_flags OPT_LOCAL or 0 (both)
+/// @param opt_flags Option flags (can be OPT_LOCAL, OPT_GLOBAL or a combination).
void set_option_value_give_err(const OptIndex opt_idx, OptVal value, int opt_flags)
{
const char *errmsg = set_option_value(opt_idx, value, opt_flags);
@@ -3911,14 +3858,14 @@ void set_option_value_give_err(const OptIndex opt_idx, OptVal value, int opt_fla
/// Switch current context to get/set option value for window/buffer.
///
/// @param[out] ctx Current context. switchwin_T for window and aco_save_T for buffer.
-/// @param req_scope Requested option scope. See OptScope in option.h.
+/// @param scope Option scope. See OptScope in option.h.
/// @param[in] from Target buffer/window.
/// @param[out] err Error message, if any.
///
/// @return true if context was switched, false otherwise.
-static bool switch_option_context(void *const ctx, OptScope req_scope, void *const from, Error *err)
+static bool switch_option_context(void *const ctx, OptScope scope, void *const from, Error *err)
{
- switch (req_scope) {
+ switch (scope) {
case kOptScopeGlobal:
return false;
case kOptScopeWin: {
@@ -3933,7 +3880,7 @@ static bool switch_option_context(void *const ctx, OptScope req_scope, void *con
== FAIL) {
restore_win_noblock(switchwin, true);
- if (try_end(err)) {
+ if (ERROR_SET(err)) {
return false;
}
api_set_error(err, kErrorTypeException, "Problem while switching windows");
@@ -3957,9 +3904,9 @@ static bool switch_option_context(void *const ctx, OptScope req_scope, void *con
/// Restore context after getting/setting option for window/buffer. See switch_option_context() for
/// params.
-static void restore_option_context(void *const ctx, OptScope req_scope)
+static void restore_option_context(void *const ctx, OptScope scope)
{
- switch (req_scope) {
+ switch (scope) {
case kOptScopeGlobal:
break;
case kOptScopeWin:
@@ -3977,28 +3924,28 @@ static void restore_option_context(void *const ctx, OptScope req_scope)
/// @param[out] flagsp Set to the option flags (see OptFlags) (if not NULL).
/// @param[in] scope Option scope (can be OPT_LOCAL, OPT_GLOBAL or a combination).
/// @param[out] hidden Whether option is hidden.
-/// @param req_scope Requested option scope. See OptScope in option.h.
+/// @param scope Option scope. See OptScope in option.h.
/// @param[in] from Target buffer/window.
/// @param[out] err Error message, if any.
///
/// @return Option value. Must be freed by caller.
-OptVal get_option_value_for(OptIndex opt_idx, int scope, const OptScope req_scope, void *const from,
+OptVal get_option_value_for(OptIndex opt_idx, int opt_flags, const OptScope scope, void *const from,
Error *err)
{
switchwin_T switchwin;
aco_save_T aco;
- void *ctx = req_scope == kOptScopeWin ? (void *)&switchwin
- : (req_scope == kOptScopeBuf ? (void *)&aco : NULL);
+ void *ctx = scope == kOptScopeWin ? (void *)&switchwin
+ : (scope == kOptScopeBuf ? (void *)&aco : NULL);
- bool switched = switch_option_context(ctx, req_scope, from, err);
+ bool switched = switch_option_context(ctx, scope, from, err);
if (ERROR_SET(err)) {
return NIL_OPTVAL;
}
- OptVal retv = get_option_value(opt_idx, scope);
+ OptVal retv = get_option_value(opt_idx, opt_flags);
if (switched) {
- restore_option_context(ctx, req_scope);
+ restore_option_context(ctx, scope);
}
return retv;
@@ -4010,19 +3957,19 @@ OptVal get_option_value_for(OptIndex opt_idx, int scope, const OptScope req_scop
/// @param opt_idx Option index in options[] table.
/// @param[in] value Option value.
/// @param[in] opt_flags Flags: OPT_LOCAL, OPT_GLOBAL, or 0 (both).
-/// @param req_scope Requested option scope. See OptScope in option.h.
+/// @param scope Option scope. See OptScope in option.h.
/// @param[in] from Target buffer/window.
/// @param[out] err Error message, if any.
void set_option_value_for(const char *name, OptIndex opt_idx, OptVal value, const int opt_flags,
- const OptScope req_scope, void *const from, Error *err)
+ const OptScope scope, void *const from, Error *err)
FUNC_ATTR_NONNULL_ARG(1)
{
switchwin_T switchwin;
aco_save_T aco;
- void *ctx = req_scope == kOptScopeWin ? (void *)&switchwin
- : (req_scope == kOptScopeBuf ? (void *)&aco : NULL);
+ void *ctx = scope == kOptScopeWin ? (void *)&switchwin
+ : (scope == kOptScopeBuf ? (void *)&aco : NULL);
- bool switched = switch_option_context(ctx, req_scope, from, err);
+ bool switched = switch_option_context(ctx, scope, from, err);
if (ERROR_SET(err)) {
return;
}
@@ -4033,14 +3980,14 @@ void set_option_value_for(const char *name, OptIndex opt_idx, OptVal value, cons
}
if (switched) {
- restore_option_context(ctx, req_scope);
+ restore_option_context(ctx, scope);
}
}
/// if 'all' == false: show changed options
/// if 'all' == true: show all normal options
///
-/// @param opt_flags OPT_LOCAL and/or OPT_GLOBAL
+/// @param opt_flags Option flags (can be OPT_LOCAL, OPT_GLOBAL or a combination).
static void showoptions(bool all, int opt_flags)
{
#define INC 20
@@ -4048,6 +3995,7 @@ static void showoptions(bool all, int opt_flags)
vimoption_T **items = xmalloc(sizeof(vimoption_T *) * OPTION_COUNT);
+ msg_ext_set_kind("list_cmd");
// Highlight title
if (opt_flags & OPT_GLOBAL) {
msg_puts_title(_("\n--- Global option values ---"));
@@ -4166,7 +4114,7 @@ void ui_refresh_options(void)
/// showoneopt: show the value of one option
/// must not be called with a hidden option!
///
-/// @param opt_flags OPT_LOCAL or OPT_GLOBAL
+/// @param opt_flags Option flags (can be OPT_LOCAL, OPT_GLOBAL or a combination).
static void showoneopt(vimoption_T *opt, int opt_flags)
{
int save_silent = silent_mode;
@@ -4389,7 +4337,7 @@ static int put_set(FILE *fd, char *cmd, OptIndex opt_idx, void *varp)
return FAIL;
}
- char *value_str = value.data.string.data;
+ const char *value_str = value.data.string.data;
char *buf = NULL;
char *part = NULL;
@@ -4451,18 +4399,18 @@ static int put_set(FILE *fd, char *cmd, OptIndex opt_idx, void *varp)
return OK;
}
-void *get_varp_scope_from(vimoption_T *p, int scope, buf_T *buf, win_T *win)
+void *get_varp_scope_from(vimoption_T *p, int opt_flags, buf_T *buf, win_T *win)
{
OptIndex opt_idx = get_opt_idx(p);
- if ((scope & OPT_GLOBAL) && !option_is_global_only(opt_idx)) {
+ if ((opt_flags & OPT_GLOBAL) && !option_is_global_only(opt_idx)) {
if (option_is_window_local(opt_idx)) {
return GLOBAL_WO(get_varp_from(p, buf, win));
}
return p->var;
}
- if ((scope & OPT_LOCAL) && option_is_global_local(opt_idx)) {
+ if ((opt_flags & OPT_LOCAL) && option_is_global_local(opt_idx)) {
switch (opt_idx) {
case kOptFormatprg:
return &(buf->b_p_fp);
@@ -4533,17 +4481,17 @@ void *get_varp_scope_from(vimoption_T *p, int scope, buf_T *buf, win_T *win)
/// Get pointer to option variable, depending on local or global scope.
///
-/// @param scope can be OPT_LOCAL, OPT_GLOBAL or a combination.
-void *get_varp_scope(vimoption_T *p, int scope)
+/// @param opt_flags Option flags (can be OPT_LOCAL, OPT_GLOBAL or a combination).
+void *get_varp_scope(vimoption_T *p, int opt_flags)
{
- return get_varp_scope_from(p, scope, curbuf, curwin);
+ return get_varp_scope_from(p, opt_flags, curbuf, curwin);
}
/// Get pointer to option variable at 'opt_idx', depending on local or global
/// scope.
-void *get_option_varp_scope_from(OptIndex opt_idx, int scope, buf_T *buf, win_T *win)
+void *get_option_varp_scope_from(OptIndex opt_idx, int opt_flags, buf_T *buf, win_T *win)
{
- return get_varp_scope_from(&(options[opt_idx]), scope, buf, win);
+ return get_varp_scope_from(&(options[opt_idx]), opt_flags, buf, win);
}
void *get_varp_from(vimoption_T *p, buf_T *buf, win_T *win)
@@ -5282,7 +5230,7 @@ void buf_copy_options(buf_T *buf, int flags)
// or to a help buffer.
if (dont_do_help) {
buf->b_p_isk = save_p_isk;
- if (p_vts && p_vts != empty_string_option && !buf->b_p_vts_array) {
+ if (p_vts && *p_vts != NUL && !buf->b_p_vts_array) {
tabstop_set(p_vts, &buf->b_p_vts_array);
} else {
buf->b_p_vts_array = NULL;
@@ -5295,7 +5243,7 @@ void buf_copy_options(buf_T *buf, int flags)
COPY_OPT_SCTX(buf, kBufOptTabstop);
buf->b_p_vts = xstrdup(p_vts);
COPY_OPT_SCTX(buf, kBufOptVartabstop);
- if (p_vts && p_vts != empty_string_option && !buf->b_p_vts_array) {
+ if (p_vts && *p_vts != NUL && !buf->b_p_vts_array) {
tabstop_set(p_vts, &buf->b_p_vts_array);
} else {
buf->b_p_vts_array = NULL;
@@ -5348,7 +5296,7 @@ static char expand_option_name[5] = { 't', '_', NUL, NUL, NUL };
static int expand_option_flags = 0;
static bool expand_option_append = false;
-/// @param opt_flags OPT_GLOBAL and/or OPT_LOCAL
+/// @param opt_flags Option flags (can be OPT_LOCAL, OPT_GLOBAL or a combination).
void set_context_in_set_cmd(expand_T *xp, char *arg, int opt_flags)
{
expand_option_flags = opt_flags;
@@ -5771,6 +5719,7 @@ int ExpandStringSetting(expand_T *xp, regmatch_T *regmatch, int *numMatches, cha
optexpand_T args = {
.oe_varp = get_varp_scope(&options[expand_option_idx], expand_option_flags),
+ .oe_idx = expand_option_idx,
.oe_append = expand_option_append,
.oe_regmatch = regmatch,
.oe_xp = xp,
@@ -5900,12 +5849,12 @@ int ExpandSettingSubtract(expand_T *xp, regmatch_T *regmatch, int *numMatches, c
/// Get the value for the numeric or string option///opp in a nice format into
/// NameBuff[]. Must not be called with a hidden option!
///
-/// @param opt_flags OPT_GLOBAL and/or OPT_LOCAL
+/// @param opt_flags Option flags (can be OPT_LOCAL, OPT_GLOBAL or a combination).
///
/// TODO(famiu): Replace this with optval_to_cstr() if possible.
-static void option_value2string(vimoption_T *opt, int scope)
+static void option_value2string(vimoption_T *opt, int opt_flags)
{
- void *varp = get_varp_scope(opt, scope);
+ void *varp = get_varp_scope(opt, opt_flags);
assert(varp != NULL);
if (option_has_type(get_opt_idx(opt), kOptValTypeNumber)) {
@@ -6009,19 +5958,19 @@ int fill_culopt_flags(char *val, win_T *wp)
p = val;
}
while (*p != NUL) {
- // Note: Keep this in sync with p_culopt_values.
+ // Note: Keep this in sync with opt_culopt_values.
if (strncmp(p, "line", 4) == 0) {
p += 4;
- culopt_flags_new |= CULOPT_LINE;
+ culopt_flags_new |= kOptCuloptFlagLine;
} else if (strncmp(p, "both", 4) == 0) {
p += 4;
- culopt_flags_new |= CULOPT_LINE | CULOPT_NBR;
+ culopt_flags_new |= kOptCuloptFlagLine | kOptCuloptFlagNumber;
} else if (strncmp(p, "number", 6) == 0) {
p += 6;
- culopt_flags_new |= CULOPT_NBR;
+ culopt_flags_new |= kOptCuloptFlagNumber;
} else if (strncmp(p, "screenline", 10) == 0) {
p += 10;
- culopt_flags_new |= CULOPT_SCRLINE;
+ culopt_flags_new |= kOptCuloptFlagScreenline;
}
if (*p != ',' && *p != NUL) {
@@ -6033,7 +5982,7 @@ int fill_culopt_flags(char *val, win_T *wp)
}
// Can't have both "line" and "screenline".
- if ((culopt_flags_new & CULOPT_LINE) && (culopt_flags_new & CULOPT_SCRLINE)) {
+ if ((culopt_flags_new & kOptCuloptFlagLine) && (culopt_flags_new & kOptCuloptFlagScreenline)) {
return FAIL;
}
wp->w_p_culopt_flags = culopt_flags_new;
@@ -6143,7 +6092,8 @@ char *get_flp_value(buf_T *buf)
/// Get the local or global value of 'virtualedit' flags.
unsigned get_ve_flags(win_T *wp)
{
- return (wp->w_ve_flags ? wp->w_ve_flags : ve_flags) & ~(VE_NONE | VE_NONEU);
+ return (wp->w_ve_flags ? wp->w_ve_flags : ve_flags)
+ & ~(unsigned)(kOptVeFlagNone | kOptVeFlagNoneU);
}
/// Get the local or global value of 'showbreak'.
@@ -6221,7 +6171,7 @@ int default_fileformat(void)
/// Sets 'fileformat'.
///
/// @param eol_style End-of-line style.
-/// @param opt_flags OPT_LOCAL and/or OPT_GLOBAL
+/// @param opt_flags Option flags (can be OPT_LOCAL, OPT_GLOBAL or a combination).
void set_fileformat(int eol_style, int opt_flags)
{
char *p = NULL;
@@ -6352,14 +6302,14 @@ int get_sidescrolloff_value(win_T *wp)
return (int)(wp->w_p_siso < 0 ? p_siso : wp->w_p_siso);
}
-Dict get_vimoption(String name, int scope, buf_T *buf, win_T *win, Arena *arena, Error *err)
+Dict get_vimoption(String name, int opt_flags, buf_T *buf, win_T *win, Arena *arena, Error *err)
{
OptIndex opt_idx = find_option_len(name.data, name.size);
VALIDATE_S(opt_idx != kOptInvalid, "option (not found)", name.data, {
return (Dict)ARRAY_DICT_INIT;
});
- return vimoption2dict(&options[opt_idx], scope, buf, win, arena);
+ return vimoption2dict(&options[opt_idx], opt_flags, buf, win, arena);
}
Dict get_all_vimoptions(Arena *arena)
@@ -6372,7 +6322,7 @@ Dict get_all_vimoptions(Arena *arena)
return retval;
}
-static Dict vimoption2dict(vimoption_T *opt, int req_scope, buf_T *buf, win_T *win, Arena *arena)
+static Dict vimoption2dict(vimoption_T *opt, int opt_flags, buf_T *buf, win_T *win, Arena *arena)
{
OptIndex opt_idx = get_opt_idx(opt);
Dict dict = arena_dict(arena, 13);
@@ -6399,7 +6349,7 @@ static Dict vimoption2dict(vimoption_T *opt, int req_scope, buf_T *buf, win_T *w
PUT_C(dict, "was_set", BOOLEAN_OBJ(opt->flags & kOptFlagWasSet));
LastSet last_set = { .channel_id = 0 };
- if (req_scope == OPT_GLOBAL) {
+ if (opt_flags == OPT_GLOBAL) {
last_set = opt->last_set;
} else {
// Scope is either OPT_LOCAL or a fallback mode was requested.
@@ -6409,7 +6359,7 @@ static Dict vimoption2dict(vimoption_T *opt, int req_scope, buf_T *buf, win_T *w
if (option_has_scope(opt_idx, kOptScopeWin)) {
last_set = win->w_p_script_ctx[opt->scope_idx[kOptScopeWin]];
}
- if (req_scope != OPT_LOCAL && last_set.script_ctx.sc_sid == 0) {
+ if (opt_flags != OPT_LOCAL && last_set.script_ctx.sc_sid == 0) {
last_set = opt->last_set;
}
}