mirror of
https://github.com/neovim/neovim.git
synced 2026-02-20 17:29:54 +10:00
Problem: The way option scopes currently work is inflexible and does not allow for nested option scopes or easily finding the value of an option at any arbitrary scope without having to do long handwritten switch-case statements like in `get_varp()`. `.indir` is also confusing and redundant since option indices for each scope can be autogenerated. Solution: Expand option scopes in such a way that an option can support any amount of scopes using a set of scope flags, similarly to how it's already done for option types. Also make options contain information about its index at each scope it supports. This allows for massively simplifying `get_varp()` and `get_varp_scope()` in the future by just using a struct for options at each scope. This would be done by creating a table that stores the offset of an option's variable at a scope by using the option's index at that scope as a key. This PR also autogenerates enums for option indices at each scope to remove the need for `.indir` entirely, and also to allow easily iterating over options all options that support any scope. Ref: #29314
68 lines
2.3 KiB
C
68 lines
2.3 KiB
C
#pragma once
|
||
|
||
#include <stdbool.h>
|
||
#include <stdint.h>
|
||
#include <stdio.h> // IWYU pragma: keep
|
||
|
||
#include "nvim/api/private/defs.h" // IWYU pragma: keep
|
||
#include "nvim/api/private/helpers.h"
|
||
#include "nvim/cmdexpand_defs.h" // IWYU pragma: keep
|
||
#include "nvim/eval/typval_defs.h"
|
||
#include "nvim/ex_cmds_defs.h" // IWYU pragma: keep
|
||
#include "nvim/macros_defs.h"
|
||
#include "nvim/option_defs.h" // IWYU pragma: keep
|
||
#include "nvim/types_defs.h" // IWYU pragma: keep
|
||
|
||
/// flags for buf_copy_options()
|
||
enum {
|
||
BCO_ENTER = 1, ///< going to enter the buffer
|
||
BCO_ALWAYS = 2, ///< always copy the options
|
||
BCO_NOHELP = 4, ///< don't touch the help related options
|
||
};
|
||
|
||
/// Flags for option-setting functions
|
||
///
|
||
/// When OPT_GLOBAL and OPT_LOCAL are both missing, set both local and global
|
||
/// values, get local value.
|
||
typedef enum {
|
||
OPT_GLOBAL = 0x01, ///< Use global value.
|
||
OPT_LOCAL = 0x02, ///< Use local value.
|
||
OPT_MODELINE = 0x04, ///< Option in modeline.
|
||
OPT_WINONLY = 0x08, ///< Only set window-local options.
|
||
OPT_NOWIN = 0x10, ///< Don’t set window-local options.
|
||
OPT_ONECOLUMN = 0x20, ///< list options one per line
|
||
OPT_NO_REDRAW = 0x40, ///< ignore redraw flags on option
|
||
OPT_SKIPRTP = 0x80, ///< "skiprtp" in 'sessionoptions'
|
||
} OptionSetFlags;
|
||
|
||
/// Get name of OptValType as a string.
|
||
static inline const char *optval_type_get_name(const OptValType type)
|
||
{
|
||
switch (type) {
|
||
case kOptValTypeNil:
|
||
return "nil";
|
||
case kOptValTypeBoolean:
|
||
return "boolean";
|
||
case kOptValTypeNumber:
|
||
return "number";
|
||
case kOptValTypeString:
|
||
return "string";
|
||
}
|
||
UNREACHABLE;
|
||
}
|
||
|
||
// OptVal helper macros.
|
||
#define NIL_OPTVAL ((OptVal) { .type = kOptValTypeNil })
|
||
#define BOOLEAN_OPTVAL(b) ((OptVal) { .type = kOptValTypeBoolean, .data.boolean = b })
|
||
#define NUMBER_OPTVAL(n) ((OptVal) { .type = kOptValTypeNumber, .data.number = n })
|
||
#define STRING_OPTVAL(s) ((OptVal) { .type = kOptValTypeString, .data.string = s })
|
||
|
||
#define CSTR_AS_OPTVAL(s) STRING_OPTVAL(cstr_as_string(s))
|
||
#define CSTR_TO_OPTVAL(s) STRING_OPTVAL(cstr_to_string(s))
|
||
#define STATIC_CSTR_AS_OPTVAL(s) STRING_OPTVAL(STATIC_CSTR_AS_STRING(s))
|
||
#define STATIC_CSTR_TO_OPTVAL(s) STRING_OPTVAL(STATIC_CSTR_TO_STRING(s))
|
||
|
||
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
||
# include "option.h.generated.h"
|
||
#endif
|