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