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/pos.h" // for linenr_T
8 #include "nvim/normal.h"
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 RANGE 0x001 // allow a linespecs
40 #define BANG 0x002 // allow a ! after the command name
41 #define EXTRA 0x004 // allow extra args after command name
42 #define XFILE 0x008 // expand wildcards in extra part
43 #define NOSPC 0x010 // no spaces allowed in the extra part
44 #define DFLALL 0x020 // default file range is 1,$
45 #define WHOLEFOLD 0x040 // extend range to include whole fold also
46  // when less than two numbers given
47 #define NEEDARG 0x080 // argument required
48 #define TRLBAR 0x100 // check for trailing vertical bar
49 #define REGSTR 0x200 // allow "x for register designation
50 #define COUNT 0x400 // allow count in argument, after command
51 #define NOTRLCOM 0x800 // no trailing comment allowed
52 #define ZEROR 0x1000 // zero line number allowed
53 #define USECTRLV 0x2000 // do not remove CTRL-V from argument
54 #define NOTADR 0x4000 // number before command is not an address
55 #define EDITCMD 0x8000 // allow "+command" argument
56 #define BUFNAME 0x10000 // accepts buffer name
57 #define BUFUNL 0x20000 // accepts unlisted buffer too
58 #define ARGOPT 0x40000 // allow "++opt=val" argument
59 #define SBOXOK 0x80000 // allowed in the sandbox
60 #define CMDWIN 0x100000 // allowed in cmdline window; when missing
61  // disallows editing another buffer when
62  // curbuf_lock is set
63 #define MODIFY 0x200000 // forbidden in non-'modifiable' buffer
64 #define EXFLAGS 0x400000 // allow flags after count in argument
65 #define RESTRICT 0x800000L // forbidden in restricted mode
66 #define FILES (XFILE | EXTRA) // multiple extra files allowed
67 #define WORD1 (EXTRA | NOSPC) // one extra word allowed
68 #define FILE1 (FILES | NOSPC) // 1 file allowed, defaults to current file
69 
70 // values for cmd_addr_type
71 #define ADDR_LINES 0
72 #define ADDR_WINDOWS 1
73 #define ADDR_ARGUMENTS 2
74 #define ADDR_LOADED_BUFFERS 3
75 #define ADDR_BUFFERS 4
76 #define ADDR_TABS 5
77 #define ADDR_TABS_RELATIVE 6 // Tab page that only relative
78 #define ADDR_QUICKFIX 7
79 #define ADDR_OTHER 99
80 
81 typedef struct exarg exarg_T;
82 
83 /* behavior for bad character, "++bad=" argument */
84 #define BAD_REPLACE '?' /* replace it with '?' (default) */
85 #define BAD_KEEP -1 /* leave it */
86 #define BAD_DROP -2 /* erase it */
87 
88 typedef void (*ex_func_T)(exarg_T *eap);
89 
90 typedef char_u *(*LineGetter)(int, void *, int, bool);
91 
93 typedef struct cmdname {
96  uint32_t cmd_argt;
99 
100 // A list used for saving values of "emsg_silent". Used by ex_try() to save the
101 // value of "emsg_silent" if it was non-zero. When this is done, the CSF_SILENT
102 // flag below is set.
103 typedef struct eslist_elem eslist_T;
104 struct eslist_elem {
105  int saved_emsg_silent; // saved value of "emsg_silent"
106  eslist_T *next; // next element on the list
107 };
108 
109 // For conditional commands a stack is kept of nested conditionals.
110 // When cs_idx < 0, there is no conditional command.
111 enum {
113 };
114 
115 typedef struct {
116  int cs_flags[CSTACK_LEN]; // CSF_ flags
117  char cs_pending[CSTACK_LEN]; // CSTP_: what's pending in ":finally"
118  union {
119  void *csp_rv[CSTACK_LEN]; // return typeval for pending return
120  void *csp_ex[CSTACK_LEN]; // exception for pending throw
121  } cs_pend;
122  void *cs_forinfo[CSTACK_LEN]; // info used by ":for"
123  int cs_line[CSTACK_LEN]; // line nr of ":while"/":for" line
124  int cs_idx; // current entry, or -1 if none
125  int cs_looplevel; // nr of nested ":while"s and ":for"s
126  int cs_trylevel; // nr of nested ":try"s
127  eslist_T *cs_emsg_silent_list; // saved values of "emsg_silent"
128  int cs_lflags; // loop flags: CSL_ flags
129 } cstack_T;
130 # define cs_rettv cs_pend.csp_rv
131 # define cs_exception cs_pend.csp_ex
132 
133 // Flags for the cs_lflags item in cstack_T.
134 enum {
135  CSL_HAD_LOOP = 1, // just found ":while" or ":for"
136  CSL_HAD_ENDLOOP = 2, // just found ":endwhile" or ":endfor"
137  CSL_HAD_CONT = 4, // just found ":continue"
138  CSL_HAD_FINA = 8, // just found ":finally"
139 };
140 
142 struct exarg {
147  cmdidx_T cmdidx;
148  uint32_t argt;
149  int skip;
150  int forceit;
154  int addr_type;
155  int flags;
158  int append;
159  int usefilter;
160  int amount;
161  int regname;
162  int force_bin;
163  int read_edit;
164  int force_ff;
165  int force_enc;
166  int bad_char;
167  int useridx;
170  void *cookie;
175  bool did_sandbox;
176 };
177 
178 #define FORCE_BIN 1 // ":edit ++bin file"
179 #define FORCE_NOBIN 2 // ":edit ++nobin file"
180 
181 // Values for "flags"
182 #define EXFLAG_LIST 0x01 // 'l': list
183 #define EXFLAG_NR 0x02 // '#': number
184 #define EXFLAG_PRINT 0x04 // 'p': print
185 
186 // used for completion on the command line
187 struct expand {
188  int xp_context; // type of expansion
189  char_u *xp_pattern; // start of item to expand
190  size_t xp_pattern_len; // bytes in xp_pattern before cursor
191  char_u *xp_arg; // completion function
192  sctx_T xp_script_ctx; // SCTX for completion function
193  int xp_backslash; // one of the XP_BS_ values
194 #ifndef BACKSLASH_IN_FILENAME
195  int xp_shell; // TRUE for a shell command, more
196  // characters need to be escaped
197 #endif
198  int xp_numfiles; // number of files found by file name completion
199  char_u **xp_files; // list of files
200  char_u *xp_line; // text being completed
201  int xp_col; // cursor position in line
202 };
203 
204 // values for xp_backslash
205 #define XP_BS_NONE 0 // nothing special for backslashes
206 #define XP_BS_ONE 1 // uses one backslash before a space
207 #define XP_BS_THREE 2 // uses three backslashes before a space
208 
212 typedef struct {
213  int split;
214  int tab;
215  bool browse;
216  bool confirm;
217  bool hide;
218  bool keepalt;
219  bool keepjumps;
220  bool keepmarks;
222  bool lockmarks;
223  bool noswapfile;
227 } cmdmod_T;
228 
229 #endif // NVIM_EX_CMDS_DEFS_H
char_u * xp_arg
Definition: ex_cmds_defs.h:191
int save_msg_silent
saved value of msg_silent
Definition: ex_cmds_defs.h:173
int xp_numfiles
Definition: ex_cmds_defs.h:198
char_u * save_ei
saved value of &#39;eventignore&#39;
Definition: ex_cmds_defs.h:224
int cs_trylevel
Definition: ex_cmds_defs.h:126
LineGetter getline
Function used to get the next line.
Definition: ex_cmds_defs.h:169
char_u * cmd_name
Name of the command.
Definition: ex_cmds_defs.h:94
bool lockmarks
true when ":lockmarks" was used
Definition: ex_cmds_defs.h:222
Definition: ex_cmds_defs.h:138
int split
flags for win_split()
Definition: ex_cmds_defs.h:213
linenr_T do_ecmd_lnum
the line number in an edited file
Definition: ex_cmds_defs.h:157
char_u ** cmdlinep
pointer to pointer of allocated cmdline
Definition: ex_cmds_defs.h:146
char_u ** xp_files
Definition: ex_cmds_defs.h:199
bool keepalt
true when ":keepalt" was used
Definition: ex_cmds_defs.h:218
int amount
number of &#39;>&#39; or &#39;<&#39; for shift command
Definition: ex_cmds_defs.h:160
uint32_t argt
flags for the command
Definition: ex_cmds_defs.h:148
int force_bin
0, FORCE_BIN or FORCE_NOBIN
Definition: ex_cmds_defs.h:162
Definition: ex_cmds_defs.h:136
Definition: ex_cmds_defs.h:137
Structure for command definition.
Definition: ex_cmds_defs.h:93
char_u * arg
argument of the command
Definition: ex_cmds_defs.h:143
int xp_shell
Definition: ex_cmds_defs.h:195
int regname
register name (NUL if none)
Definition: ex_cmds_defs.h:161
eslist_T * cs_emsg_silent_list
Definition: ex_cmds_defs.h:127
char_u * do_ecmd_cmd
+command arg to be used in edited file
Definition: ex_cmds_defs.h:156
long verbose_save
saved value of p_verbose
Definition: ex_cmds_defs.h:172
int force_enc
++enc= argument (index in cmd[])
Definition: ex_cmds_defs.h:165
char_u * errmsg
returned error message
Definition: ex_cmds_defs.h:168
linenr_T line2
the second line number or count
Definition: ex_cmds_defs.h:153
Definition: regexp_defs.h:142
bool keepmarks
true when ":keepmarks" was used
Definition: ex_cmds_defs.h:220
int useridx
user command index
Definition: ex_cmds_defs.h:167
void(* ex_func_T)(exarg_T *eap)
Definition: ex_cmds_defs.h:88
cstack_T * cstack
condition stack for ":if" etc.
Definition: ex_cmds_defs.h:171
int xp_col
Definition: ex_cmds_defs.h:201
int tab
0 when ":tab" was used
Definition: ex_cmds_defs.h:214
size_t xp_pattern_len
Definition: ex_cmds_defs.h:190
char_u * xp_line
Definition: ex_cmds_defs.h:200
int read_edit
++edit argument
Definition: ex_cmds_defs.h:163
Definition: ex_cmds_defs.h:112
int bad_char
BAD_KEEP, BAD_DROP or replacement byte.
Definition: ex_cmds_defs.h:166
sctx_T xp_script_ctx
Definition: ex_cmds_defs.h:192
int xp_context
Definition: ex_cmds_defs.h:188
struct cmdname CommandDefinition
Structure for command definition.
ex_func_T cmd_func
Function with implementation of this command.
Definition: ex_cmds_defs.h:95
int cs_looplevel
Definition: ex_cmds_defs.h:125
cmdidx_T cmdidx
the index for the command
Definition: ex_cmds_defs.h:147
int addr_count
the number of addresses given
Definition: ex_cmds_defs.h:151
Definition: ex_cmds_defs.h:212
bool keeppatterns
true when ":keeppatterns" was used
Definition: ex_cmds_defs.h:221
int addr_type
type of the count/range
Definition: ex_cmds_defs.h:154
int cs_idx
Definition: ex_cmds_defs.h:124
uint32_t cmd_argt
Relevant flags from the declared above.
Definition: ex_cmds_defs.h:96
void * cookie
argument for getline()
Definition: ex_cmds_defs.h:170
int append
TRUE with ":w >>file" command.
Definition: ex_cmds_defs.h:158
char_u * xp_pattern
Definition: ex_cmds_defs.h:189
Arguments used for Ex commands.
Definition: ex_cmds_defs.h:142
int cmd_addr_type
Flag for address type.
Definition: ex_cmds_defs.h:97
bool did_sandbox
when true did sandbox++
Definition: ex_cmds_defs.h:175
int did_esilent
how many times emsg_silent was incremented
Definition: ex_cmds_defs.h:174
void(WINAPI *pClosePseudoConsole)(HPCON)
int flags
extra flags after count: EXFLAG_
Definition: ex_cmds_defs.h:155
long linenr_T
Definition: pos.h:4
int saved_emsg_silent
Definition: ex_cmds_defs.h:105
int usefilter
TRUE with ":w !command" and ":r!command".
Definition: ex_cmds_defs.h:159
bool filter_force
set for :filter!
Definition: ex_cmds_defs.h:226
unsigned char char_u
Definition: types.h:11
bool keepjumps
true when ":keepjumps" was used
Definition: ex_cmds_defs.h:219
regmatch_T filter_regmatch
set by :filter /pat/
Definition: ex_cmds_defs.h:225
int cs_lflags
Definition: ex_cmds_defs.h:128
char_u *(* LineGetter)(int, void *, int, bool)
Definition: ex_cmds_defs.h:90
Definition: ex_cmds_defs.h:135
int skip
don&#39;t execute the command, only parse it
Definition: ex_cmds_defs.h:149
int force_ff
++ff= argument (first char of argument)
Definition: ex_cmds_defs.h:164
bool hide
true when ":hide" was used
Definition: ex_cmds_defs.h:217
Definition: typval.h:265
char_u * nextcmd
next command (NULL if none)
Definition: ex_cmds_defs.h:144
bool browse
true to invoke file dialog
Definition: ex_cmds_defs.h:215
char_u * cmd
the name of the command (except for :make)
Definition: ex_cmds_defs.h:145
Definition: ex_cmds_defs.h:187
Definition: ex_cmds_defs.h:104
int xp_backslash
Definition: ex_cmds_defs.h:193
bool confirm
true to invoke yes/no dialog
Definition: ex_cmds_defs.h:216
Definition: ex_cmds_defs.h:115
eslist_T * next
Definition: ex_cmds_defs.h:106
bool noswapfile
true when ":noswapfile" was used
Definition: ex_cmds_defs.h:223
linenr_T line1
the first line number
Definition: ex_cmds_defs.h:152
int forceit
TRUE if ! present.
Definition: ex_cmds_defs.h:150