mirror of
https://github.com/neovim/neovim.git
synced 2025-10-16 06:46:07 +00:00
refactor(options): set option value for non-current context directly
Problem: Currently, we use `switch_option_context` to temporarily switch the current option context before setting an option for a different buffer / window. This is not ideal because we already support getting and setting option values for non-current contexts in the underlying implementation. Solution: Set option value for non-current context by passing the context directly to the lower level functions. Also introduce a new `OptCtx` struct to store option context information, this will scale much better if we add more option scopes and other context information in the future.
This commit is contained in:
@@ -81,6 +81,12 @@ typedef struct {
|
||||
OptValData data;
|
||||
} OptVal;
|
||||
|
||||
/// Context that an option is being set for.
|
||||
typedef struct {
|
||||
win_T *win;
|
||||
buf_T *buf;
|
||||
} OptCtx;
|
||||
|
||||
/// :set operator types
|
||||
typedef enum {
|
||||
OP_NONE = 0,
|
||||
@@ -122,8 +128,7 @@ typedef struct {
|
||||
/// length of the error buffer
|
||||
size_t os_errbuflen;
|
||||
|
||||
void *os_win;
|
||||
void *os_buf;
|
||||
OptCtx os_ctx;
|
||||
} optset_T;
|
||||
|
||||
/// Type for the callback function that is invoked after an option value is
|
||||
@@ -192,3 +197,12 @@ typedef struct {
|
||||
OptVal def_val; ///< default value
|
||||
LastSet last_set; ///< script in which the option was last set
|
||||
} vimoption_T;
|
||||
|
||||
/// Execute code with autocmd context
|
||||
#define WITH_AUCMD_CONTEXT(ctx, code) \
|
||||
do { \
|
||||
aco_save_T _aco; \
|
||||
aucmd_prepbuf_win(&_aco, ctx.buf, ctx.win); \
|
||||
code; \
|
||||
aucmd_restbuf(&_aco); \
|
||||
} while (0)
|
||||
|
Reference in New Issue
Block a user