robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
aa1d8a2702
master
1#pragma once 2 3#include <stdbool.h> 4#include <stddef.h> 5 6#include "nvim/api/private/defs.h" 7#include "nvim/cmdexpand_defs.h" 8#include "nvim/regexp_defs.h" 9#include "nvim/types_defs.h" 10 11#include "options_enum.generated.h" 12 13/// Option flags. 14typedef enum { 15kOptFlagExpand = 1 <<0 ,///< Environment expansion. 16///< NOTE: kOptFlagExpand can never be used for local or hidden options. 17kOptFlagNoDefExp = 1 <<1 ,///< Don't expand default value. 18kOptFlagNoDefault = 1 <<2 ,///< Don't set to default value. 19kOptFlagWasSet = 1 <<3 ,///< Option has been set/reset. 20kOptFlagNoMkrc = 1 <<4 ,///< Don't include in :mkvimrc output. 21kOptFlagUIOption = 1 <<5 ,///< Send option to remote UI. 22kOptFlagRedrTabl = 1 <<6 ,///< Redraw tabline. 23kOptFlagRedrStat = 1 <<7 ,///< Redraw status lines. 24kOptFlagRedrWin = 1 <<8 ,///< Redraw current window and recompute text. 25kOptFlagRedrBuf = 1 <<9 ,///< Redraw current buffer and recompute text. 26kOptFlagRedrAll = kOptFlagRedrBuf |kOptFlagRedrWin ,///< Redraw all windows and recompute text. 27kOptFlagRedrClear = kOptFlagRedrAll |kOptFlagRedrStat ,///< Clear and redraw all and recompute text. 28kOptFlagComma = 1 <<10 ,///< Comma-separated list. 29kOptFlagOneComma = (1 <<11 ) |kOptFlagComma ,///< Comma-separated list that cannot have two consecutive commas. 30kOptFlagNoDup = 1 <<12 ,///< Don't allow duplicate strings. 31kOptFlagFlagList = 1 <<13 ,///< List of single-char flags. 32kOptFlagSecure = 1 <<14 ,///< Cannot change in modelines, secure mode, or the sandbox. 33kOptFlagGettext = 1 <<15 ,///< Expand default value with _(). 34kOptFlagNoGlob = 1 <<16 ,///< Do not use local value for global vimrc. 35kOptFlagNFname = 1 <<17 ,///< Only normal file name chars allowed. 36kOptFlagInsecure = 1 <<18 ,///< Value contains untrusted content; evaluate it in the sandbox. 37kOptFlagPriMkrc = 1 <<19 ,///< Priority for :mkvimrc (setting option has side effects). 38kOptFlagCurswant = 1 <<20 ,///< Update curswant required; not needed when there is a redraw flag. 39kOptFlagNDname = 1 <<21 ,///< Only normal directory name chars allowed. 40kOptFlagHLOnly = 1 <<22 ,///< Option only changes highlight, not text. 41kOptFlagMLE = 1 <<23 ,///< Under control of 'modelineexpr'. 42kOptFlagFunc = 1 <<24 ,///< Callback option: Lua function, or Vimscript funcref. 43kOptFlagColon = 1 <<25 ,///< Values use colons to create sublists. 44kOptFlagExpr = 1 <<26 ,///< Callback option: Vimscript expr, e.g. 'foldexpr'. 45}OptFlags ; 46 47/// Scopes that an option can support. 48typedef enum { 49kOptScopeGlobal = 0 ,///< Request global option value 50kOptScopeWin ,///< Request window-local option value 51kOptScopeBuf ,///< Request buffer-local option value 52kOptScopeTab ,///< Request tabpage-local option value 53}OptScope ; 54/// Always update this whenever a new option scope is added. 55#define kOptScopeSize (kOptScopeTab + 1) 56typedef uint8_t OptScopeFlags ; 57 58/// Value kind of one key in a dict option (see "schema" in options.lua). 59typedef enum { 60kOptSchemaFlag ,///< bare flag, e.g. 'diffopt' "filler" 61kOptSchemaNum ,///< "key:N" non-negative number, e.g. 'diffopt' "context:4" 62kOptSchemaSNum ,///< "key:N" signed number, e.g. 'breakindentopt' "shift:-2" 63kOptSchemaEnum ,///< "key:val" where val is one of "enum_values", e.g. "algorithm:patience" 64kOptSchemaStr ,///< "key:val" where val is a free string, e.g. 'previewpopup' "highlight:Foo" 65}OptSchemaKind ; 66 67/// One key of a dict option, generated from its `dict` schema in options.lua. 68/// Consumed by opt_strings_check(). A NULL "name" terminates the array. 69typedef struct { 70const char * name ;///< key name, without a trailing ':' 71OptSchemaKind kind ; 72const char ** enum_values ;///< kOptSchemaEnum: NULL-terminated valid values; else NULL 73}OptSchemaItem ; 74 75/// Schema for a dict option (`schema.dict` in options.lua). 76typedef struct { 77FieldHashfn get_field ;///< Keyset perfect-hash lookup, for opt_fill(). 78const OptSchemaItem * schema ;///< Grammar, for opt_strings_check() validation. 79size_t size ;///< sizeof the keyset, for opt_keyset() storage. 80}OptDictSchema ; 81 82/// :set operator types 83typedef enum { 84OP_NONE = 0 , 85OP_ADDING ,///< "opt+=arg" 86OP_PREPENDING ,///< "opt^=arg" 87OP_REMOVING ,///< "opt-=arg" 88}set_op_T ; 89 90/// Arguments for validating an option value or applying it after storage. 91typedef struct { 92/// Pointer to the option variable. The variable can be an OptInt (numeric 93/// option), an int (boolean option), a char pointer (string option), or a Callback. 94/// Holds the old value during validation and the new value when applying it. 95void * os_varp ; 96OptIndex os_idx ; 97int os_flags ; 98 99/// Old value of the option. 100Object os_oldval ; 101/// New value of the option (not yet stored during validation). 102Object os_newval ; 103 104/// Option value was checked to be safe, no need to set kOptFlagInsecure 105/// Used for the 'keymap', 'filetype' and 'syntax' options. 106bool os_value_checked ; 107/// Option value changed. Used for the 'filetype' and 'syntax' options. 108bool os_value_changed ; 109 110/// Used by the 'isident', 'iskeyword', 'isprint' and 'isfname' options. 111/// Set to true if the character table is modified when processing the 112/// option and need to be restored because of a failure. 113bool os_restore_chartab ; 114 115/// If the value specified for an option is not valid and the error message 116/// is parameterized, then the "os_errbuf" buffer is used to store the error 117/// message (when it is not NULL). 118const CharBuf * os_errbuf ; 119 120win_T * os_win ; 121buf_T * os_buf ; 122}optset_T ; 123 124/// Check a candidate value without changing option variables or derived state, 125/// or evaluating user code. Return an error message, or NULL on success. 126typedef const char * (* opt_validate_cb_T )(const optset_T * args ); 127 128/// Type for the callback function invoked after storing an option value to 129/// apply it and update derived state. 130/// 131/// Returns NULL on success, or an error message if the value could not be applied. 132typedef const char * (* opt_did_set_cb_T )(optset_T * args ); 133 134/// Argument for the callback function (opt_expand_cb_T) invoked after a string 135/// option value is expanded for cmdline completion. 136typedef struct { 137/// Pointer to the option variable. It's always a string. 138char * oe_varp ; 139OptIndex oe_idx ; 140/// The original option value, escaped. 141char * oe_opt_value ; 142 143/// true if using set+= instead of set= 144bool oe_append ; 145/// true if we would like to add the original option value as the first choice. 146bool oe_include_orig_val ; 147 148/// Regex from the cmdline, for matching potential options against. 149regmatch_T * oe_regmatch ; 150/// The expansion context. 151expand_T * oe_xp ; 152 153/// The full argument passed to :set. For example, if the user inputs 154/// ":set dip=icase,algorithm:my<Tab>", oe_xp->xp_pattern will only have 155/// "my", but oe_set_arg will contain the whole "icase,algorithm:my". 156char * oe_set_arg ; 157}optexpand_T ; 158 159/// Type for the callback function that is invoked when expanding possible 160/// string option values during cmdline completion. 161/// 162/// Strings in returned matches will be managed and freed by caller. 163/// 164/// Returns OK if the expansion succeeded (numMatches and matches have to be 165/// set). Otherwise returns FAIL. 166/// 167/// Note: If returned FAIL or *numMatches is 0, *matches will NOT be freed by 168/// caller. 169typedef int (* opt_expand_cb_T )(optexpand_T * args ,int * numMatches ,char *** matches ); 170 171typedef struct { 172char * fullname ;///< full option name 173char * shortname ;///< permissible abbreviation 174uint32_t flags ;///< see above 175ObjectType type ;///< option type 176OptScopeFlags scope_flags ;///< option scope flags, see OptScope 177void * var ;///< global option: pointer to variable; 178///< window-local option: NULL; 179///< buffer-local option: global value 180unsigned * flags_var ; 181ssize_t scope_idx [kOptScopeSize ];///< index of option at every scope. 182bool immutable ;///< option is immutable, trying to set it will give an error. 183 184const char ** values ;///< possible values for string options 185const size_t values_len ;///< length of values array 186 187/// Grammar of a dict option ("schema.dict" in options.lua); NULL otherwise. 188const OptSchemaItem * schema ; 189 190/// Validate a candidate value before storing it, without side effects. 191opt_validate_cb_T opt_validate_cb ; 192 193/// Apply the stored value. Some handlers still perform option-specific validation. 194opt_did_set_cb_T opt_did_set_cb ; 195 196/// callback function to invoke when expanding possible values on the 197/// cmdline. Only useful for string options. 198opt_expand_cb_T opt_expand_cb ; 199 200Object def_val ;///< default value 201sctx_T script_ctx ;///< script in which the option was last set 202}vimoption_T ;