robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

Justin M. Keyesrefactor(api): drop CmdParseInfo indirection #406578c285c6c33

master
9.8 KiB202 linesraw
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  // extra part is a single argument (no split on
41                                   // whitespace)
42#define EX_DFLALL          0x020U  // default file range is 1,$
43#define EX_WHOLEFOLD       0x040U  // extend range to include whole fold also
44                                   // when less than two numbers given
45#define EX_NEEDARG         0x080U  // argument required
46#define EX_TRLBAR          0x100U  // check for trailing vertical bar
47#define EX_REGSTR          0x200U  // allow "x for register designation
48#define EX_COUNT           0x400U  // allow count in argument, after command
49#define EX_NOTRLCOM        0x800U  // no trailing comment allowed
50#define EX_ZEROR          0x1000U  // zero line number allowed
51#define EX_CTRLV          0x2000U  // do not remove CTRL-V from argument
52#define EX_CMDARG         0x4000U  // allow "+command" argument
53#define EX_BUFNAME        0x8000U  // accepts buffer name
54#define EX_BUFUNL        0x10000U  // accepts unlisted buffer too
55#define EX_ARGOPT        0x20000U  // allow "++opt=val" argument
56#define EX_SBOXOK        0x40000U  // allowed in the sandbox
57#define EX_BUFLOCK_OK    0x80000U  // Command is allowed when curbuf is `b_ro_locked` (e.g. during
58                                   // a quickfix or diff critical section). Legacy name: EX_CMDWIN.
59                                   // Implies EX_LOCK_OK.
60#define EX_MODIFY       0x100000U  // forbidden in non-'modifiable' buffer
61#define EX_FLAGS        0x200000U  // allow flags after count in argument
62#define EX_LOCK_OK     0x1000000U  // Command allowed when |textlock| is set. EX_BUFLOCK_OK is per-buffer.
63#define EX_KEEPSCRIPT  0x4000000U  // keep sctx of where command was invoked
64#define EX_PREVIEW     0x8000000U  // allow incremental command preview
65#define EX_ARGSPACE   0x40000000U  // completion: keep spaces in arg lead
66#define EX_FILES (EX_XFILE | EX_EXTRA)  // multiple extra files allowed
67#define EX_FILE1 (EX_FILES | EX_NOSPC)  // 1 file, defaults to current file
68#define EX_WORD1 (EX_EXTRA | EX_NOSPC)  // one extra word allowed
69
70/// values for cmd_addr_type
71typedef enum {
72  ADDR_LINES,           ///< buffer line numbers
73  ADDR_WINDOWS,         ///< window number
74  ADDR_ARGUMENTS,       ///< argument number
75  ADDR_LOADED_BUFFERS,  ///< buffer number of loaded buffer
76  ADDR_BUFFERS,         ///< buffer number
77  ADDR_TABS,            ///< tab page number
78  ADDR_TABS_RELATIVE,   ///< Tab page that only relative
79  ADDR_QUICKFIX_VALID,  ///< quickfix list valid entry number
80  ADDR_QUICKFIX,        ///< quickfix list entry number
81  ADDR_UNSIGNED,        ///< positive count or zero, defaults to 1
82  ADDR_OTHER,           ///< something else, use line number for '$', '%', etc.
83  ADDR_NONE,            ///< no range used
84} cmd_addr_T;
85
86typedef struct exarg exarg_T;
87
88// behavior for bad character, "++bad=" argument
89#define BAD_REPLACE     '?'     // replace it with '?' (default)
90#define BAD_KEEP        (-1)    // leave it
91#define BAD_DROP        (-2)    // erase it
92
93typedef void (*ex_func_T)(exarg_T *eap);
94typedef int (*ex_preview_func_T)(exarg_T *eap, int cmdpreview_ns, handle_T cmdpreview_bufnr);
95
96typedef char *(*LineGetter)(int, void *, int, bool);
97
98/// Structure for command definition.
99typedef struct {
100  char *cmd_name;                      ///< Name of the command.
101  ex_func_T cmd_func;                  ///< Function with implementation of this command.
102  ex_preview_func_T cmd_preview_func;  ///< Preview callback function of this command.
103  uint32_t cmd_argt;                   ///< Relevant flags from the declared above.
104  cmd_addr_T cmd_addr_type;            ///< Flag for address type.
105} CommandDefinition;
106
107/// Arguments used for Ex commands.
108struct exarg {
109  char *arg;                    ///< argument of the command
110  char **args;                  ///< starting position of command arguments
111  size_t *arglens;              ///< length of command arguments
112  size_t argc;                  ///< number of command arguments
113  char *nextcmd;                ///< next command (NULL if none)
114  char *cmd;                    ///< the name of the command (except for :make)
115  char **cmdlinep;              ///< pointer to pointer of allocated cmdline
116  char *cmdline_tofree;         ///< free later
117  cmdidx_T cmdidx;              ///< the index for the command
118  uint32_t argt;                ///< flags for the command
119  int skip;                     ///< don't execute the command, only parse it
120  int forceit;                  ///< true if ! present
121  int addr_count;               ///< the number of addresses given
122  linenr_T line1;               ///< the first line number
123  linenr_T line2;               ///< the second line number or count
124  cmd_addr_T addr_type;         ///< type of the count/range
125  int flags;                    ///< extra flags after count: EXFLAG_
126  char *do_ecmd_cmd;            ///< +command arg to be used in edited file
127  linenr_T do_ecmd_lnum;        ///< the line number in an edited file
128  int append;                   ///< true with ":w >>file" command
129  int usefilter;                ///< true with ":w !command" and ":r!command"
130  int amount;                   ///< number of '>' or '<' for shift command
131  int regname;                  ///< register name (NUL if none)
132  int force_bin;                ///< 0, FORCE_BIN or FORCE_NOBIN
133  int read_edit;                ///< ++edit argument
134  int mkdir_p;                  ///< ++p argument
135  int force_ff;                 ///< ++ff= argument (first char of argument)
136  int force_enc;                ///< ++enc= argument (index in cmd[])
137  int bad_char;                 ///< BAD_KEEP, BAD_DROP or replacement byte
138  int useridx;                  ///< user command index
139  char *errmsg;                 ///< returned error message
140  LineGetter ea_getline;        ///< function used to get the next line
141  void *cookie;                 ///< argument for ea_getline()
142  cstack_T *cstack;             ///< condition stack for ":if" etc.
143  struct {                      ///< special char handling in command args
144    bool file;
145    bool bar;
146  } magic;
147};
148
149#define FORCE_BIN 1             // ":edit ++bin file"
150#define FORCE_NOBIN 2           // ":edit ++nobin file"
151
152// Values for "flags"
153#define EXFLAG_LIST     0x01    // 'l': list
154#define EXFLAG_NR       0x02    // '#': number
155#define EXFLAG_PRINT    0x04    // 'p': print
156
157enum {
158  CMOD_SANDBOX      = 0x0001,  ///< ":sandbox"
159  CMOD_SILENT       = 0x0002,  ///< ":silent"
160  CMOD_ERRSILENT    = 0x0004,  ///< ":silent!"
161  CMOD_UNSILENT     = 0x0008,  ///< ":unsilent"
162  CMOD_NOAUTOCMD    = 0x0010,  ///< ":noautocmd"
163  CMOD_HIDE         = 0x0020,  ///< ":hide"
164  CMOD_BROWSE       = 0x0040,  ///< ":browse" - invoke file dialog
165  CMOD_CONFIRM      = 0x0080,  ///< ":confirm" - invoke yes/no dialog
166  CMOD_KEEPALT      = 0x0100,  ///< ":keepalt"
167  CMOD_KEEPMARKS    = 0x0200,  ///< ":keepmarks"
168  CMOD_KEEPJUMPS    = 0x0400,  ///< ":keepjumps"
169  CMOD_LOCKMARKS    = 0x0800,  ///< ":lockmarks"
170  CMOD_KEEPPATTERNS = 0x1000,  ///< ":keeppatterns"
171  CMOD_NOSWAPFILE   = 0x2000,  ///< ":noswapfile"
172};
173
174/// Command modifiers ":vertical", ":browse", ":confirm", ":hide", etc. set a
175/// flag.  This needs to be saved for recursive commands, put them in a
176/// structure for easy manipulation.
177typedef struct {
178  int cmod_flags;  ///< CMOD_ flags
179
180  int cmod_split;  ///< flags for win_split()
181  int cmod_tab;  ///< > 0 when ":tab" was used
182  char *cmod_filter_pat;
183  regmatch_T cmod_filter_regmatch;  ///< set by :filter /pat/
184  bool cmod_filter_force;  ///< set for :filter!
185
186  int cmod_verbose;  ///< 0 if not set, > 0 to set 'verbose' to cmod_verbose - 1
187
188  // values for undo_cmdmod()
189  char *cmod_save_ei;  ///< saved value of 'eventignore'
190  int cmod_did_sandbox;  ///< set when "sandbox" was incremented
191  OptInt cmod_verbose_save;  ///< if 'verbose' was set: value of p_verbose plus one
192  int cmod_save_msg_silent;  ///< if non-zero: saved value of msg_silent + 1
193  int cmod_save_msg_scroll;  ///< for restoring msg_scroll
194  int cmod_did_esilent;  ///< incremented when emsg_silent is
195} cmdmod_T;
196
197/// Previous :substitute replacement string definition
198typedef struct {
199  char *sub;            ///< Previous replacement string.
200  Timestamp timestamp;  ///< Time when it was last set.
201  AdditionalData *additional_data;  ///< Additional data left from ShaDa file.
202} SubReplacementString;