ex_cmds_defs.h
Go to the documentation of this file.
1 #ifndef NVIM_EX_CMDS_DEFS_H
2 #define NVIM_EX_CMDS_DEFS_H
3 
4 #include <stdbool.h>
5 #include <stdint.h>
6 
7 #include "nvim/eval/typval.h"
8 #include "nvim/normal.h"
9 #include "nvim/pos.h" // for linenr_T
10 #include "nvim/regexp_defs.h"
11 
12 #ifdef INCLUDE_GENERATED_DECLARATIONS
13 # include "ex_cmds_enum.generated.h"
14 #endif
15 
16 // When adding an Ex command:
17 // 1. Add an entry to the table in src/nvim/ex_cmds.lua. Keep it sorted on the
18 // shortest version of the command name that works. If it doesn't start with
19 // a lower case letter, add it at the end.
20 //
21 // Each table entry is a table with the following keys:
22 //
23 // Key | Description
24 // ------- | -------------------------------------------------------------
25 // command | Name of the command. Required.
26 // enum | Name of the enum entry. If not set defaults to CMD_{command}.
27 // flags | A set of the flags from below list joined by bitwise or.
28 // func | Name of the function containing the implementation.
29 //
30 // Referenced function should be either non-static one or defined in
31 // ex_docmd.c and be coercible to ex_func_T type from below.
32 //
33 // All keys not described in the above table are reserved for future use.
34 //
35 // 2. Add a "case: CMD_xxx" in the big switch in ex_docmd.c.
36 // 3. Add an entry in the index for Ex commands at ":help ex-cmd-index".
37 // 4. Add documentation in ../doc/xxx.txt. Add a tag for both the short and
38 // long name of the command.
39 
40 #define EX_RANGE 0x001 // allow a linespecs
41 #define EX_BANG 0x002 // allow a ! after the command name
42 #define EX_EXTRA 0x004 // allow extra args after command name
43 #define EX_XFILE 0x008 // expand wildcards in extra part
44 #define EX_NOSPC 0x010 // no spaces allowed in the extra part
45 #define EX_DFLALL 0x020 // default file range is 1,$
46 #define EX_WHOLEFOLD 0x040 // extend range to include whole fold also
47  // when less than two numbers given
48 #define EX_NEEDARG 0x080 // argument required
49 #define EX_TRLBAR 0x100 // check for trailing vertical bar
50 #define EX_REGSTR 0x200 // allow "x for register designation
51 #define EX_COUNT 0x400 // allow count in argument, after command
52 #define EX_NOTRLCOM 0x800 // no trailing comment allowed
53 #define EX_ZEROR 0x1000 // zero line number allowed
54 #define EX_CTRLV 0x2000 // do not remove CTRL-V from argument
55 #define EX_CMDARG 0x4000 // allow "+command" argument
56 #define EX_BUFNAME 0x8000 // accepts buffer name
57 #define EX_BUFUNL 0x10000 // accepts unlisted buffer too
58 #define EX_ARGOPT 0x20000 // allow "++opt=val" argument
59 #define EX_SBOXOK 0x40000 // allowed in the sandbox
60 #define EX_CMDWIN 0x80000 // allowed in cmdline window; when missing
61  // disallows editing another buffer when
62  // current buffer is locked
63 #define EX_MODIFY 0x100000 // forbidden in non-'modifiable' buffer
64 #define EX_FLAGS 0x200000 // allow flags after count in argument
65 #define EX_KEEPSCRIPT 0x4000000 // keep sctx of where command was invoked
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
71 typedef 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 
86 typedef 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 
93 typedef void (*ex_func_T)(exarg_T *eap);
94 
95 // NOTE: These possible could be removed and changed so that
96 // Callback could take a "command" style string, and simply
97 // execute that (instead of it being a function).
98 //
99 // But it's still a bit weird to do that.
100 //
101 // Another option would be that we just make a callback reference to
102 // "execute($INPUT)" or something like that, so whatever the user
103 // sends in via autocmds is just executed via this.
104 //
105 // However, that would probably have some performance cost (probably
106 // very marginal, but still some cost either way).
107 typedef enum {
112 
116  union {
117  char *cmd;
119  } callable;
120 };
121 
122 #define AUCMD_EXECUTABLE_INIT { .type = CALLABLE_NONE }
123 
124 typedef char *(*LineGetter)(int, void *, int, bool);
125 
127 typedef struct cmdname {
128  char *cmd_name;
130  uint32_t cmd_argt;
133 
134 // A list used for saving values of "emsg_silent". Used by ex_try() to save the
135 // value of "emsg_silent" if it was non-zero. When this is done, the CSF_SILENT
136 // flag below is set.
137 typedef struct eslist_elem eslist_T;
138 struct eslist_elem {
139  int saved_emsg_silent; // saved value of "emsg_silent"
140  eslist_T *next; // next element on the list
141 };
142 
143 // For conditional commands a stack is kept of nested conditionals.
144 // When cs_idx < 0, there is no conditional command.
145 enum {
147 };
148 
149 typedef struct {
150  int cs_flags[CSTACK_LEN]; // CSF_ flags
151  char cs_pending[CSTACK_LEN]; // CSTP_: what's pending in ":finally"
152  union {
153  void *csp_rv[CSTACK_LEN]; // return typeval for pending return
154  void *csp_ex[CSTACK_LEN]; // exception for pending throw
155  } cs_pend;
156  void *cs_forinfo[CSTACK_LEN]; // info used by ":for"
157  int cs_line[CSTACK_LEN]; // line nr of ":while"/":for" line
158  int cs_idx; // current entry, or -1 if none
159  int cs_looplevel; // nr of nested ":while"s and ":for"s
160  int cs_trylevel; // nr of nested ":try"s
161  eslist_T *cs_emsg_silent_list; // saved values of "emsg_silent"
162  int cs_lflags; // loop flags: CSL_ flags
163 } cstack_T;
164 #define cs_rettv cs_pend.csp_rv
165 #define cs_exception cs_pend.csp_ex
166 
167 // Flags for the cs_lflags item in cstack_T.
168 enum {
169  CSL_HAD_LOOP = 1, // just found ":while" or ":for"
170  CSL_HAD_ENDLOOP = 2, // just found ":endwhile" or ":endfor"
171  CSL_HAD_CONT = 4, // just found ":continue"
172  CSL_HAD_FINA = 8, // just found ":finally"
173 };
174 
176 struct exarg {
177  char *arg;
178  char **args;
179  size_t *arglens;
180  size_t argc;
181  char *nextcmd;
182  char *cmd;
183  char **cmdlinep;
184  cmdidx_T cmdidx;
185  uint32_t argt;
186  int skip;
187  int forceit;
192  int flags;
193  char *do_ecmd_cmd;
195  int append;
196  int usefilter;
197  int amount;
198  int regname;
199  int force_bin;
200  int read_edit;
201  int force_ff;
202  int force_enc;
203  int bad_char;
204  int useridx;
205  char *errmsg;
207  void *cookie;
212  bool did_sandbox;
213 };
214 
215 #define FORCE_BIN 1 // ":edit ++bin file"
216 #define FORCE_NOBIN 2 // ":edit ++nobin file"
217 
218 // Values for "flags"
219 #define EXFLAG_LIST 0x01 // 'l': list
220 #define EXFLAG_NR 0x02 // '#': number
221 #define EXFLAG_PRINT 0x04 // 'p': print
222 
223 // used for completion on the command line
224 struct expand {
225  char *xp_pattern; // start of item to expand
226  int xp_context; // type of expansion
227  size_t xp_pattern_len; // bytes in xp_pattern before cursor
228  char *xp_arg; // completion function
229  LuaRef xp_luaref; // Ref to Lua completion function
230  sctx_T xp_script_ctx; // SCTX for completion function
231  int xp_backslash; // one of the XP_BS_ values
232 #ifndef BACKSLASH_IN_FILENAME
233  int xp_shell; // TRUE for a shell command, more
234  // characters need to be escaped
235 #endif
236  int xp_numfiles; // number of files found by file name completion
237  int xp_col; // cursor position in line
238  char **xp_files; // list of files
239  char *xp_line; // text being completed
240 };
241 
242 // values for xp_backslash
243 #define XP_BS_NONE 0 // nothing special for backslashes
244 #define XP_BS_ONE 1 // uses one backslash before a space
245 #define XP_BS_THREE 2 // uses three backslashes before a space
246 
250 typedef struct {
251  int split;
252  int tab;
253  bool browse;
254  bool confirm;
255  bool hide;
256  bool keepalt;
257  bool keepjumps;
258  bool keepmarks;
260  bool lockmarks;
261  bool noswapfile;
262  char *save_ei;
265 } cmdmod_T;
266 
268 typedef struct {
269  bool silent;
271  bool sandbox;
272  bool noautocmd;
273  long verbose;
275  struct {
276  bool file;
277  bool bar;
278  } magic;
279 } CmdParseInfo;
280 
281 #endif // NVIM_EX_CMDS_DEFS_H
exarg::line2
linenr_T line2
the second line number or count
Definition: ex_cmds_defs.h:190
expand::xp_backslash
int xp_backslash
Definition: ex_cmds_defs.h:231
cmdmod_T::keeppatterns
bool keeppatterns
true when ":keeppatterns" was used
Definition: ex_cmds_defs.h:259
ADDR_TABS
@ ADDR_TABS
Definition: ex_cmds_defs.h:77
LineGetter
char *(* LineGetter)(int, void *, int, bool)
Definition: ex_cmds_defs.h:124
cmdmod_T::keepmarks
bool keepmarks
true when ":keepmarks" was used
Definition: ex_cmds_defs.h:258
CSL_HAD_LOOP
@ CSL_HAD_LOOP
Definition: ex_cmds_defs.h:169
ADDR_UNSIGNED
@ ADDR_UNSIGNED
Definition: ex_cmds_defs.h:81
ADDR_BUFFERS
@ ADDR_BUFFERS
Definition: ex_cmds_defs.h:76
ADDR_TABS_RELATIVE
@ ADDR_TABS_RELATIVE
Definition: ex_cmds_defs.h:78
cmdname::cmd_name
char * cmd_name
Name of the command.
Definition: ex_cmds_defs.h:128
CALLABLE_NONE
@ CALLABLE_NONE
Definition: ex_cmds_defs.h:108
expand::xp_script_ctx
sctx_T xp_script_ctx
Definition: ex_cmds_defs.h:230
exarg::did_sandbox
bool did_sandbox
when true did sandbox++
Definition: ex_cmds_defs.h:212
cstack_T::cs_lflags
int cs_lflags
Definition: ex_cmds_defs.h:162
ADDR_WINDOWS
@ ADDR_WINDOWS
Definition: ex_cmds_defs.h:73
expand
Definition: ex_cmds_defs.h:224
cmdmod_T::noswapfile
bool noswapfile
true when ":noswapfile" was used
Definition: ex_cmds_defs.h:261
cmdname
Structure for command definition.
Definition: ex_cmds_defs.h:127
CmdParseInfo::verbose
long verbose
Definition: ex_cmds_defs.h:273
cmdmod_T::hide
bool hide
true when ":hide" was used
Definition: ex_cmds_defs.h:255
cstack_T::cs_emsg_silent_list
eslist_T * cs_emsg_silent_list
Definition: ex_cmds_defs.h:161
CmdParseInfo::bar
bool bar
Definition: ex_cmds_defs.h:277
CommandDefinition
struct cmdname CommandDefinition
Structure for command definition.
exarg::useridx
int useridx
user command index
Definition: ex_cmds_defs.h:204
expand::xp_luaref
LuaRef xp_luaref
Definition: ex_cmds_defs.h:229
exarg::force_enc
int force_enc
++enc= argument (index in cmd[])
Definition: ex_cmds_defs.h:202
exarg::flags
int flags
extra flags after count: EXFLAG_
Definition: ex_cmds_defs.h:192
exarg::read_edit
int read_edit
++edit argument
Definition: ex_cmds_defs.h:200
CmdParseInfo::file
bool file
Definition: ex_cmds_defs.h:276
ADDR_LINES
@ ADDR_LINES
Definition: ex_cmds_defs.h:72
aucmd_executable_t::type
AucmdExecutableType type
Definition: ex_cmds_defs.h:115
exarg::cmd
char * cmd
the name of the command (except for :make)
Definition: ex_cmds_defs.h:182
aucmd_executable_t::cb
Callback cb
Definition: ex_cmds_defs.h:118
cmdname::cmd_argt
uint32_t cmd_argt
Relevant flags from the declared above.
Definition: ex_cmds_defs.h:130
eslist_elem::saved_emsg_silent
int saved_emsg_silent
Definition: ex_cmds_defs.h:139
cstack_T
Definition: ex_cmds_defs.h:149
cmdmod_T::keepjumps
bool keepjumps
true when ":keepjumps" was used
Definition: ex_cmds_defs.h:257
exarg::arg
char * arg
argument of the command
Definition: ex_cmds_defs.h:177
exarg::do_ecmd_lnum
linenr_T do_ecmd_lnum
the line number in an edited file
Definition: ex_cmds_defs.h:194
void
void(WINAPI *pClosePseudoConsole)(HPCON)
aucmd_executable_t
Definition: ex_cmds_defs.h:114
ADDR_QUICKFIX_VALID
@ ADDR_QUICKFIX_VALID
Definition: ex_cmds_defs.h:79
CSL_HAD_ENDLOOP
@ CSL_HAD_ENDLOOP
Definition: ex_cmds_defs.h:170
sctx_T
Definition: typval.h:280
LuaRef
int LuaRef
Definition: types.h:23
CALLABLE_CB
@ CALLABLE_CB
Definition: ex_cmds_defs.h:110
exarg
Arguments used for Ex commands.
Definition: ex_cmds_defs.h:176
exarg::skip
int skip
don't execute the command, only parse it
Definition: ex_cmds_defs.h:186
cmdmod_T::filter_regmatch
regmatch_T filter_regmatch
set by :filter /pat/
Definition: ex_cmds_defs.h:263
cmdname::cmd_addr_type
cmd_addr_T cmd_addr_type
Flag for address type.
Definition: ex_cmds_defs.h:131
AucmdExecutableType
AucmdExecutableType
Definition: ex_cmds_defs.h:107
exarg::bad_char
int bad_char
BAD_KEEP, BAD_DROP or replacement byte.
Definition: ex_cmds_defs.h:203
expand::xp_col
int xp_col
Definition: ex_cmds_defs.h:237
exarg::did_esilent
int did_esilent
how many times emsg_silent was incremented
Definition: ex_cmds_defs.h:211
CSL_HAD_FINA
@ CSL_HAD_FINA
Definition: ex_cmds_defs.h:172
exarg::nextcmd
char * nextcmd
next command (NULL if none)
Definition: ex_cmds_defs.h:181
exarg::amount
int amount
number of '>' or '<' for shift command
Definition: ex_cmds_defs.h:197
ADDR_NONE
@ ADDR_NONE
Definition: ex_cmds_defs.h:83
cmdmod_T::keepalt
bool keepalt
true when ":keepalt" was used
Definition: ex_cmds_defs.h:256
CmdParseInfo::emsg_silent
bool emsg_silent
Definition: ex_cmds_defs.h:270
exarg::getline
LineGetter getline
Function used to get the next line.
Definition: ex_cmds_defs.h:206
CSL_HAD_CONT
@ CSL_HAD_CONT
Definition: ex_cmds_defs.h:171
CALLABLE_EX
@ CALLABLE_EX
Definition: ex_cmds_defs.h:109
exarg::arglens
size_t * arglens
length of command arguments
Definition: ex_cmds_defs.h:179
eslist_elem
Definition: ex_cmds_defs.h:138
CmdParseInfo::noautocmd
bool noautocmd
Definition: ex_cmds_defs.h:272
exarg::usefilter
int usefilter
TRUE with ":w !command" and ":r!command".
Definition: ex_cmds_defs.h:196
exarg::verbose_save
long verbose_save
saved value of p_verbose
Definition: ex_cmds_defs.h:209
exarg::cmdidx
cmdidx_T cmdidx
the index for the command
Definition: ex_cmds_defs.h:184
exarg::force_bin
int force_bin
0, FORCE_BIN or FORCE_NOBIN
Definition: ex_cmds_defs.h:199
exarg::args
char ** args
starting position of command arguments
Definition: ex_cmds_defs.h:178
cmdmod_T::browse
bool browse
true to invoke file dialog
Definition: ex_cmds_defs.h:253
exarg::regname
int regname
register name (NUL if none)
Definition: ex_cmds_defs.h:198
expand::xp_pattern
char * xp_pattern
Definition: ex_cmds_defs.h:225
CmdParseInfo::sandbox
bool sandbox
Definition: ex_cmds_defs.h:271
regexp_defs.h
typval.h
cmd_addr_T
cmd_addr_T
Definition: ex_cmds_defs.h:71
exarg::addr_type
cmd_addr_T addr_type
type of the count/range
Definition: ex_cmds_defs.h:191
CSTACK_LEN
@ CSTACK_LEN
Definition: ex_cmds_defs.h:146
exarg::errmsg
char * errmsg
returned error message
Definition: ex_cmds_defs.h:205
exarg::cookie
void * cookie
argument for getline()
Definition: ex_cmds_defs.h:207
exarg::forceit
int forceit
TRUE if ! present.
Definition: ex_cmds_defs.h:187
exarg::line1
linenr_T line1
the first line number
Definition: ex_cmds_defs.h:189
exarg::cstack
cstack_T * cstack
condition stack for ":if" etc.
Definition: ex_cmds_defs.h:208
cmdmod_T::confirm
bool confirm
true to invoke yes/no dialog
Definition: ex_cmds_defs.h:254
expand::xp_line
char * xp_line
Definition: ex_cmds_defs.h:239
cmdname::cmd_func
ex_func_T cmd_func
Function with implementation of this command.
Definition: ex_cmds_defs.h:129
cstack_T::cs_looplevel
int cs_looplevel
Definition: ex_cmds_defs.h:159
exarg::force_ff
int force_ff
++ff= argument (first char of argument)
Definition: ex_cmds_defs.h:201
CmdParseInfo::cmdmod
cmdmod_T cmdmod
Definition: ex_cmds_defs.h:274
expand::xp_numfiles
int xp_numfiles
Definition: ex_cmds_defs.h:236
expand::xp_pattern_len
size_t xp_pattern_len
Definition: ex_cmds_defs.h:227
exarg::argc
size_t argc
number of command arguments
Definition: ex_cmds_defs.h:180
exarg::argt
uint32_t argt
flags for the command
Definition: ex_cmds_defs.h:185
expand::xp_context
int xp_context
Definition: ex_cmds_defs.h:226
exarg::cmdlinep
char ** cmdlinep
pointer to pointer of allocated cmdline
Definition: ex_cmds_defs.h:183
cmdmod_T::lockmarks
bool lockmarks
true when ":lockmarks" was used
Definition: ex_cmds_defs.h:260
exarg::do_ecmd_cmd
char * do_ecmd_cmd
+command arg to be used in edited file
Definition: ex_cmds_defs.h:193
cmdmod_T
Definition: ex_cmds_defs.h:250
ADDR_ARGUMENTS
@ ADDR_ARGUMENTS
Definition: ex_cmds_defs.h:74
Callback
Definition: typval.h:78
exarg::save_msg_silent
int save_msg_silent
saved value of msg_silent
Definition: ex_cmds_defs.h:210
CmdParseInfo::silent
bool silent
Definition: ex_cmds_defs.h:269
exarg::addr_count
int addr_count
the number of addresses given
Definition: ex_cmds_defs.h:188
bool
#define bool
Definition: conv.h:18
expand::xp_arg
char * xp_arg
Definition: ex_cmds_defs.h:228
expand::xp_files
char ** xp_files
Definition: ex_cmds_defs.h:238
exarg::append
int append
TRUE with ":w >>file" command.
Definition: ex_cmds_defs.h:195
cmdmod_T::split
int split
flags for win_split()
Definition: ex_cmds_defs.h:251
aucmd_executable_t::cmd
char * cmd
Definition: ex_cmds_defs.h:117
ADDR_QUICKFIX
@ ADDR_QUICKFIX
Definition: ex_cmds_defs.h:80
cstack_T::cs_idx
int cs_idx
Definition: ex_cmds_defs.h:158
cmdmod_T::save_ei
char * save_ei
saved value of 'eventignore'
Definition: ex_cmds_defs.h:262
cmdmod_T::tab
int tab
0 when ":tab" was used
Definition: ex_cmds_defs.h:252
expand::xp_shell
int xp_shell
Definition: ex_cmds_defs.h:233
cstack_T::cs_trylevel
int cs_trylevel
Definition: ex_cmds_defs.h:160
regmatch_T
Definition: regexp_defs.h:142
eslist_elem::next
eslist_T * next
Definition: ex_cmds_defs.h:140
cmdmod_T::filter_force
bool filter_force
set for :filter!
Definition: ex_cmds_defs.h:264
linenr_T
long linenr_T
Line number type.
Definition: pos.h:5
CmdParseInfo
Stores command modifier info used by nvim_parse_cmd
Definition: ex_cmds_defs.h:268
aucmd_executable_t::callable
union aucmd_executable_t::@36 callable
ex_func_T
void(* ex_func_T)(exarg_T *eap)
Definition: ex_cmds_defs.h:93
ADDR_OTHER
@ ADDR_OTHER
Definition: ex_cmds_defs.h:82
normal.h
ADDR_LOADED_BUFFERS
@ ADDR_LOADED_BUFFERS
Definition: ex_cmds_defs.h:75
pos.h