neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

option_defs.h (7923B)


      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 
     10 #include "options_enum.generated.h"
     11 
     12 /// Option flags.
     13 typedef enum {
     14  kOptFlagExpand    = 1 << 0,  ///< Environment expansion.
     15                               ///< NOTE: kOptFlagExpand can never be used for local or hidden options.
     16  kOptFlagNoDefExp  = 1 << 1,  ///< Don't expand default value.
     17  kOptFlagNoDefault = 1 << 2,  ///< Don't set to default value.
     18  kOptFlagWasSet    = 1 << 3,  ///< Option has been set/reset.
     19  kOptFlagNoMkrc    = 1 << 4,  ///< Don't include in :mkvimrc output.
     20  kOptFlagUIOption  = 1 << 5,  ///< Send option to remote UI.
     21  kOptFlagRedrTabl  = 1 << 6,  ///< Redraw tabline.
     22  kOptFlagRedrStat  = 1 << 7,  ///< Redraw status lines.
     23  kOptFlagRedrWin   = 1 << 8,  ///< Redraw current window and recompute text.
     24  kOptFlagRedrBuf   = 1 << 9,  ///< Redraw current buffer and recompute text.
     25  kOptFlagRedrAll   = kOptFlagRedrBuf | kOptFlagRedrWin,  ///< Redraw all windows and recompute text.
     26  kOptFlagRedrClear = kOptFlagRedrAll | kOptFlagRedrStat,  ///< Clear and redraw all and recompute text.
     27  kOptFlagComma     = 1 << 10,  ///< Comma-separated list.
     28  kOptFlagOneComma  = (1 << 11) | kOptFlagComma,  ///< Comma-separated list that cannot have two consecutive commas.
     29  kOptFlagNoDup     = 1 << 12,  ///< Don't allow duplicate strings.
     30  kOptFlagFlagList  = 1 << 13,  ///< List of single-char flags.
     31  kOptFlagSecure    = 1 << 14,  ///< Cannot change in modeline or secure mode.
     32  kOptFlagGettext   = 1 << 15,  ///< Expand default value with _().
     33  kOptFlagNoGlob    = 1 << 16,  ///< Do not use local value for global vimrc.
     34  kOptFlagNFname    = 1 << 17,  ///< Only normal file name chars allowed.
     35  kOptFlagInsecure  = 1 << 18,  ///< Option was set from a modeline.
     36  kOptFlagPriMkrc   = 1 << 19,  ///< Priority for :mkvimrc (setting option has side effects).
     37  kOptFlagNoML      = 1 << 20,  ///< Not allowed in modeline.
     38  kOptFlagCurswant  = 1 << 21,  ///< Update curswant required; not needed when there is a redraw flag.
     39  kOptFlagNDname    = 1 << 22,  ///< Only normal directory name chars allowed.
     40  kOptFlagHLOnly    = 1 << 23,  ///< Option only changes highlight, not text.
     41  kOptFlagMLE       = 1 << 24,  ///< Under control of 'modelineexpr'.
     42  kOptFlagFunc      = 1 << 25,  ///< Accept a function reference or a lambda.
     43  kOptFlagColon     = 1 << 26,  ///< Values use colons to create sublists.
     44 } OptFlags;
     45 
     46 /// Option value type.
     47 /// These types are also used as type flags by using the type value as an index for the type_flags
     48 /// bit field (@see option_has_type()).
     49 typedef enum {
     50  kOptValTypeNil = -1,  // Make sure Nil can't be bitshifted and used as an option type flag.
     51  kOptValTypeBoolean,
     52  kOptValTypeNumber,
     53  kOptValTypeString,
     54 } OptValType;
     55 
     56 /// Scopes that an option can support.
     57 typedef enum {
     58  kOptScopeGlobal = 0,  ///< Request global option value
     59  kOptScopeWin,      ///< Request window-local option value
     60  kOptScopeBuf,      ///< Request buffer-local option value
     61 } OptScope;
     62 /// Always update this whenever a new option scope is added.
     63 #define kOptScopeSize (kOptScopeBuf + 1)
     64 typedef uint8_t OptScopeFlags;
     65 
     66 typedef union {
     67  // boolean options are actually tri-states because they have a third "None" value.
     68  TriState boolean;
     69  OptInt number;
     70  String string;
     71 } OptValData;
     72 
     73 /// Option value
     74 typedef struct {
     75  OptValType type;
     76  OptValData data;
     77 } OptVal;
     78 
     79 /// :set operator types
     80 typedef enum {
     81  OP_NONE = 0,
     82  OP_ADDING,      ///< "opt+=arg"
     83  OP_PREPENDING,  ///< "opt^=arg"
     84  OP_REMOVING,    ///< "opt-=arg"
     85 } set_op_T;
     86 
     87 /// Argument for the callback function (opt_did_set_cb_T) invoked after an
     88 /// option value is modified.
     89 typedef struct {
     90  /// Pointer to the option variable.  The variable can be an OptInt (numeric
     91  /// option), an int (boolean option) or a char pointer (string option).
     92  void *os_varp;
     93  OptIndex os_idx;
     94  int os_flags;
     95 
     96  /// Old value of the option.
     97  OptValData os_oldval;
     98  /// New value of the option.
     99  OptValData os_newval;
    100 
    101  /// Option value was checked to be safe, no need to set kOptFlagInsecure
    102  /// Used for the 'keymap', 'filetype' and 'syntax' options.
    103  bool os_value_checked;
    104  /// Option value changed.  Used for the 'filetype' and 'syntax' options.
    105  bool os_value_changed;
    106 
    107  /// Used by the 'isident', 'iskeyword', 'isprint' and 'isfname' options.
    108  /// Set to true if the character table is modified when processing the
    109  /// option and need to be restored because of a failure.
    110  bool os_restore_chartab;
    111 
    112  /// If the value specified for an option is not valid and the error message
    113  /// is parameterized, then the "os_errbuf" buffer is used to store the error
    114  /// message (when it is not NULL).
    115  char *os_errbuf;
    116  /// length of the error buffer
    117  size_t os_errbuflen;
    118 
    119  void *os_win;
    120  void *os_buf;
    121 } optset_T;
    122 
    123 /// Type for the callback function that is invoked after an option value is
    124 /// changed to validate and apply the new value.
    125 ///
    126 /// Returns NULL if the option value is valid and successfully applied.
    127 /// Otherwise returns an error message.
    128 typedef const char *(*opt_did_set_cb_T)(optset_T *args);
    129 
    130 /// Argument for the callback function (opt_expand_cb_T) invoked after a string
    131 /// option value is expanded for cmdline completion.
    132 typedef struct {
    133  /// Pointer to the option variable. It's always a string.
    134  char *oe_varp;
    135  OptIndex oe_idx;
    136  /// The original option value, escaped.
    137  char *oe_opt_value;
    138 
    139  /// true if using set+= instead of set=
    140  bool oe_append;
    141  /// true if we would like to add the original option value as the first choice.
    142  bool oe_include_orig_val;
    143 
    144  /// Regex from the cmdline, for matching potential options against.
    145  regmatch_T *oe_regmatch;
    146  /// The expansion context.
    147  expand_T *oe_xp;
    148 
    149  /// The full argument passed to :set. For example, if the user inputs
    150  /// ":set dip=icase,algorithm:my<Tab>", oe_xp->xp_pattern will only have
    151  /// "my", but oe_set_arg will contain the whole "icase,algorithm:my".
    152  char *oe_set_arg;
    153 } optexpand_T;
    154 
    155 /// Type for the callback function that is invoked when expanding possible
    156 /// string option values during cmdline completion.
    157 ///
    158 /// Strings in returned matches will be managed and freed by caller.
    159 ///
    160 /// Returns OK if the expansion succeeded (numMatches and matches have to be
    161 /// set). Otherwise returns FAIL.
    162 ///
    163 /// Note: If returned FAIL or *numMatches is 0, *matches will NOT be freed by
    164 /// caller.
    165 typedef int (*opt_expand_cb_T)(optexpand_T *args, int *numMatches, char ***matches);
    166 
    167 typedef struct {
    168  char *fullname;                    ///< full option name
    169  char *shortname;                   ///< permissible abbreviation
    170  uint32_t flags;                    ///< see above
    171  OptValType type;                   ///< option type
    172  OptScopeFlags scope_flags;         ///< option scope flags, see OptScope
    173  void *var;                         ///< global option: pointer to variable;
    174                                     ///< window-local option: NULL;
    175                                     ///< buffer-local option: global value
    176  unsigned *flags_var;
    177  ssize_t scope_idx[kOptScopeSize];  ///< index of option at every scope.
    178  bool immutable;                    ///< option is immutable, trying to set it will give an error.
    179 
    180  const char **values;               ///< possible values for string options
    181  const size_t values_len;           ///< length of values array
    182 
    183  /// callback function to invoke after an option is modified to validate and
    184  /// apply the new value.
    185  opt_did_set_cb_T opt_did_set_cb;
    186 
    187  /// callback function to invoke when expanding possible values on the
    188  /// cmdline. Only useful for string options.
    189  opt_expand_cb_T opt_expand_cb;
    190 
    191  OptVal def_val;                    ///< default value
    192  sctx_T script_ctx;                 ///< script in which the option was last set
    193 } vimoption_T;