neovim

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

ex_cmds_defs.h (9842B)


      1 #pragma once
      2 
      3 #include <stdbool.h>
      4 #include <stdint.h>
      5 
      6 #include "nvim/eval/typval_defs.h"
      7 #include "nvim/ex_eval_defs.h"
      8 #include "nvim/os/time_defs.h"
      9 #include "nvim/regexp_defs.h"
     10 
     11 #include "ex_cmds_enum.generated.h"
     12 
     13 // When adding an Ex command:
     14 // 1. Add an entry to the table in src/nvim/ex_cmds.lua.  Keep it sorted on the
     15 //    shortest version of the command name that works.  If it doesn't start with
     16 //    a lower case letter, add it at the end.
     17 //
     18 //    Each table entry is a table with the following keys:
     19 //
     20 //      Key     | Description
     21 //      ------- | -------------------------------------------------------------
     22 //      command | Name of the command. Required.
     23 //      enum    | Name of the enum entry. If not set defaults to CMD_{command}.
     24 //      flags   | A set of the flags from below list joined by bitwise or.
     25 //      func    | Name of the function containing the implementation.
     26 //
     27 //    Referenced function should be either non-static one or defined in
     28 //    ex_docmd.c and be coercible to ex_func_T type from below.
     29 //
     30 //    All keys not described in the above table are reserved for future use.
     31 //
     32 // 2. Add an entry in the index for Ex commands at ":help ex-cmd-index".
     33 // 3. Add documentation in ../doc/xxx.txt.  Add a tag for both the short and
     34 //    long name of the command.
     35 
     36 #define EX_RANGE           0x001u  // allow a linespecs
     37 #define EX_BANG            0x002u  // allow a ! after the command name
     38 #define EX_EXTRA           0x004u  // allow extra args after command name
     39 #define EX_XFILE           0x008u  // expand wildcards in extra part
     40 #define EX_NOSPC           0x010u  // no spaces allowed in the extra part
     41 #define EX_DFLALL          0x020u  // default file range is 1,$
     42 #define EX_WHOLEFOLD       0x040u  // extend range to include whole fold also
     43                                   // when less than two numbers given
     44 #define EX_NEEDARG         0x080u  // argument required
     45 #define EX_TRLBAR          0x100u  // check for trailing vertical bar
     46 #define EX_REGSTR          0x200u  // allow "x for register designation
     47 #define EX_COUNT           0x400u  // allow count in argument, after command
     48 #define EX_NOTRLCOM        0x800u  // no trailing comment allowed
     49 #define EX_ZEROR          0x1000u  // zero line number allowed
     50 #define EX_CTRLV          0x2000u  // do not remove CTRL-V from argument
     51 #define EX_CMDARG         0x4000u  // allow "+command" argument
     52 #define EX_BUFNAME        0x8000u  // accepts buffer name
     53 #define EX_BUFUNL        0x10000u  // accepts unlisted buffer too
     54 #define EX_ARGOPT        0x20000u  // allow "++opt=val" argument
     55 #define EX_SBOXOK        0x40000u  // allowed in the sandbox
     56 #define EX_CMDWIN        0x80000u  // allowed in cmdline window
     57 #define EX_MODIFY       0x100000u  // forbidden in non-'modifiable' buffer
     58 #define EX_FLAGS        0x200000u  // allow flags after count in argument
     59 #define EX_LOCK_OK     0x1000000u  // command can be executed when textlock is
     60                                   // set; when missing disallows editing another
     61                                   // buffer when curbuf->b_ro_locked is set
     62 #define EX_KEEPSCRIPT  0x4000000u  // keep sctx of where command was invoked
     63 #define EX_PREVIEW     0x8000000u  // allow incremental command preview
     64 #define EX_FILES (EX_XFILE | EX_EXTRA)  // multiple extra files allowed
     65 #define EX_FILE1 (EX_FILES | EX_NOSPC)  // 1 file, defaults to current file
     66 #define EX_WORD1 (EX_EXTRA | EX_NOSPC)  // one extra word allowed
     67 
     68 /// values for cmd_addr_type
     69 typedef enum {
     70  ADDR_LINES,           ///< buffer line numbers
     71  ADDR_WINDOWS,         ///< window number
     72  ADDR_ARGUMENTS,       ///< argument number
     73  ADDR_LOADED_BUFFERS,  ///< buffer number of loaded buffer
     74  ADDR_BUFFERS,         ///< buffer number
     75  ADDR_TABS,            ///< tab page number
     76  ADDR_TABS_RELATIVE,   ///< Tab page that only relative
     77  ADDR_QUICKFIX_VALID,  ///< quickfix list valid entry number
     78  ADDR_QUICKFIX,        ///< quickfix list entry number
     79  ADDR_UNSIGNED,        ///< positive count or zero, defaults to 1
     80  ADDR_OTHER,           ///< something else, use line number for '$', '%', etc.
     81  ADDR_NONE,            ///< no range used
     82 } cmd_addr_T;
     83 
     84 typedef struct exarg exarg_T;
     85 
     86 // behavior for bad character, "++bad=" argument
     87 #define BAD_REPLACE     '?'     // replace it with '?' (default)
     88 #define BAD_KEEP        (-1)    // leave it
     89 #define BAD_DROP        (-2)    // erase it
     90 
     91 typedef void (*ex_func_T)(exarg_T *eap);
     92 typedef int (*ex_preview_func_T)(exarg_T *eap, int cmdpreview_ns, handle_T cmdpreview_bufnr);
     93 
     94 typedef char *(*LineGetter)(int, void *, int, bool);
     95 
     96 /// Structure for command definition.
     97 typedef struct {
     98  char *cmd_name;                      ///< Name of the command.
     99  ex_func_T cmd_func;                  ///< Function with implementation of this command.
    100  ex_preview_func_T cmd_preview_func;  ///< Preview callback function of this command.
    101  uint32_t cmd_argt;                   ///< Relevant flags from the declared above.
    102  cmd_addr_T cmd_addr_type;            ///< Flag for address type.
    103 } CommandDefinition;
    104 
    105 /// Arguments used for Ex commands.
    106 struct exarg {
    107  char *arg;                    ///< argument of the command
    108  char **args;                  ///< starting position of command arguments
    109  size_t *arglens;              ///< length of command arguments
    110  size_t argc;                  ///< number of command arguments
    111  char *nextcmd;                ///< next command (NULL if none)
    112  char *cmd;                    ///< the name of the command (except for :make)
    113  char **cmdlinep;              ///< pointer to pointer of allocated cmdline
    114  char *cmdline_tofree;         ///< free later
    115  cmdidx_T cmdidx;              ///< the index for the command
    116  uint32_t argt;                ///< flags for the command
    117  int skip;                     ///< don't execute the command, only parse it
    118  int forceit;                  ///< true if ! present
    119  int addr_count;               ///< the number of addresses given
    120  linenr_T line1;               ///< the first line number
    121  linenr_T line2;               ///< the second line number or count
    122  cmd_addr_T addr_type;         ///< type of the count/range
    123  int flags;                    ///< extra flags after count: EXFLAG_
    124  char *do_ecmd_cmd;            ///< +command arg to be used in edited file
    125  linenr_T do_ecmd_lnum;        ///< the line number in an edited file
    126  int append;                   ///< true with ":w >>file" command
    127  int usefilter;                ///< true with ":w !command" and ":r!command"
    128  int amount;                   ///< number of '>' or '<' for shift command
    129  int regname;                  ///< register name (NUL if none)
    130  int force_bin;                ///< 0, FORCE_BIN or FORCE_NOBIN
    131  int read_edit;                ///< ++edit argument
    132  int mkdir_p;                  ///< ++p argument
    133  int force_ff;                 ///< ++ff= argument (first char of argument)
    134  int force_enc;                ///< ++enc= argument (index in cmd[])
    135  int bad_char;                 ///< BAD_KEEP, BAD_DROP or replacement byte
    136  int useridx;                  ///< user command index
    137  char *errmsg;                 ///< returned error message
    138  LineGetter ea_getline;        ///< function used to get the next line
    139  void *cookie;                 ///< argument for ea_getline()
    140  cstack_T *cstack;             ///< condition stack for ":if" etc.
    141 };
    142 
    143 #define FORCE_BIN 1             // ":edit ++bin file"
    144 #define FORCE_NOBIN 2           // ":edit ++nobin file"
    145 
    146 // Values for "flags"
    147 #define EXFLAG_LIST     0x01    // 'l': list
    148 #define EXFLAG_NR       0x02    // '#': number
    149 #define EXFLAG_PRINT    0x04    // 'p': print
    150 
    151 enum {
    152  CMOD_SANDBOX      = 0x0001,  ///< ":sandbox"
    153  CMOD_SILENT       = 0x0002,  ///< ":silent"
    154  CMOD_ERRSILENT    = 0x0004,  ///< ":silent!"
    155  CMOD_UNSILENT     = 0x0008,  ///< ":unsilent"
    156  CMOD_NOAUTOCMD    = 0x0010,  ///< ":noautocmd"
    157  CMOD_HIDE         = 0x0020,  ///< ":hide"
    158  CMOD_BROWSE       = 0x0040,  ///< ":browse" - invoke file dialog
    159  CMOD_CONFIRM      = 0x0080,  ///< ":confirm" - invoke yes/no dialog
    160  CMOD_KEEPALT      = 0x0100,  ///< ":keepalt"
    161  CMOD_KEEPMARKS    = 0x0200,  ///< ":keepmarks"
    162  CMOD_KEEPJUMPS    = 0x0400,  ///< ":keepjumps"
    163  CMOD_LOCKMARKS    = 0x0800,  ///< ":lockmarks"
    164  CMOD_KEEPPATTERNS = 0x1000,  ///< ":keeppatterns"
    165  CMOD_NOSWAPFILE   = 0x2000,  ///< ":noswapfile"
    166 };
    167 
    168 /// Command modifiers ":vertical", ":browse", ":confirm", ":hide", etc. set a
    169 /// flag.  This needs to be saved for recursive commands, put them in a
    170 /// structure for easy manipulation.
    171 typedef struct {
    172  int cmod_flags;  ///< CMOD_ flags
    173 
    174  int cmod_split;  ///< flags for win_split()
    175  int cmod_tab;  ///< > 0 when ":tab" was used
    176  char *cmod_filter_pat;
    177  regmatch_T cmod_filter_regmatch;  ///< set by :filter /pat/
    178  bool cmod_filter_force;  ///< set for :filter!
    179 
    180  int cmod_verbose;  ///< 0 if not set, > 0 to set 'verbose' to cmod_verbose - 1
    181 
    182  // values for undo_cmdmod()
    183  char *cmod_save_ei;  ///< saved value of 'eventignore'
    184  int cmod_did_sandbox;  ///< set when "sandbox" was incremented
    185  OptInt cmod_verbose_save;  ///< if 'verbose' was set: value of p_verbose plus one
    186  int cmod_save_msg_silent;  ///< if non-zero: saved value of msg_silent + 1
    187  int cmod_save_msg_scroll;  ///< for restoring msg_scroll
    188  int cmod_did_esilent;  ///< incremented when emsg_silent is
    189 } cmdmod_T;
    190 
    191 /// Stores command modifier info used by `nvim_parse_cmd`
    192 typedef struct {
    193  cmdmod_T cmdmod;
    194  struct {
    195    bool file;
    196    bool bar;
    197  } magic;
    198 } CmdParseInfo;
    199 
    200 /// Previous :substitute replacement string definition
    201 typedef struct {
    202  char *sub;            ///< Previous replacement string.
    203  Timestamp timestamp;  ///< Time when it was last set.
    204  AdditionalData *additional_data;  ///< Additional data left from ShaDa file.
    205 } SubReplacementString;