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/*
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
41#define RANGE 0x001 /* allow a linespecs */
42#define BANG 0x002 /* allow a ! after the command name */
43#define EXTRA 0x004 /* allow extra args after command name */
44#define XFILE 0x008 /* expand wildcards in extra part */
45#define NOSPC 0x010 /* no spaces allowed in the extra part */
46#define DFLALL 0x020 /* default file range is 1,$ */
47#define WHOLEFOLD 0x040 /* extend range to include whole fold also
48 when less than two numbers given */
49#define NEEDARG 0x080 /* argument required */
50#define TRLBAR 0x100 /* check for trailing vertical bar */
51#define REGSTR 0x200 /* allow "x for register designation */
52#define COUNT 0x400 /* allow count in argument, after command */
53#define NOTRLCOM 0x800 /* no trailing comment allowed */
54#define ZEROR 0x1000 /* zero line number allowed */
55#define USECTRLV 0x2000 /* do not remove CTRL-V from argument */
56#define NOTADR 0x4000 /* number before command is not an address */
57#define EDITCMD 0x8000 /* allow "+command" argument */
58#define BUFNAME 0x10000 /* accepts buffer name */
59#define BUFUNL 0x20000 /* accepts unlisted buffer too */
60#define ARGOPT 0x40000 /* allow "++opt=val" argument */
61#define SBOXOK 0x80000 /* allowed in the sandbox */
62#define CMDWIN 0x100000 /* allowed in cmdline window; when missing
63 * disallows editing another buffer when
64 * curbuf_lock is set */
65#define MODIFY 0x200000 /* forbidden in non-'modifiable' buffer */
66#define EXFLAGS 0x400000 /* allow flags after count in argument */
67#define FILES (XFILE | EXTRA) /* multiple extra files allowed */
68#define WORD1 (EXTRA | NOSPC) /* one extra word allowed */
69#define FILE1 (FILES | NOSPC) /* 1 file allowed, defaults to current file */
70
71// values for cmd_addr_type
72#define ADDR_LINES 0
73#define ADDR_WINDOWS 1
74#define ADDR_ARGUMENTS 2
75#define ADDR_LOADED_BUFFERS 3
76#define ADDR_BUFFERS 4
77#define ADDR_TABS 5
78#define ADDR_TABS_RELATIVE 6 // Tab page that only relative
79#define ADDR_QUICKFIX 7
80#define ADDR_OTHER 99
81
82typedef struct exarg exarg_T;
83
84/* behavior for bad character, "++bad=" argument */
85#define BAD_REPLACE '?' /* replace it with '?' (default) */
86#define BAD_KEEP -1 /* leave it */
87#define BAD_DROP -2 /* erase it */
88
89typedef void (*ex_func_T)(exarg_T *eap);
90
91typedef char_u *(*LineGetter)(int, void *, int);
92
93/// Structure for command definition.
94typedef struct cmdname {
95 char_u *cmd_name; ///< Name of the command.
96 ex_func_T cmd_func; ///< Function with implementation of this command.
97 uint32_t cmd_argt; ///< Relevant flags from the declared above.
98 int cmd_addr_type; ///< Flag for address type
99} CommandDefinition;
100
101/// Arguments used for Ex commands.
102struct exarg {
103 char_u *arg; ///< argument of the command
104 char_u *nextcmd; ///< next command (NULL if none)
105 char_u *cmd; ///< the name of the command (except for :make)
106 char_u **cmdlinep; ///< pointer to pointer of allocated cmdline
107 cmdidx_T cmdidx; ///< the index for the command
108 uint32_t argt; ///< flags for the command
109 int skip; ///< don't execute the command, only parse it
110 int forceit; ///< TRUE if ! present
111 int addr_count; ///< the number of addresses given
112 linenr_T line1; ///< the first line number
113 linenr_T line2; ///< the second line number or count
114 int addr_type; ///< type of the count/range
115 int flags; ///< extra flags after count: EXFLAG_
116 char_u *do_ecmd_cmd; ///< +command arg to be used in edited file
117 linenr_T do_ecmd_lnum; ///< the line number in an edited file
118 int append; ///< TRUE with ":w >>file" command
119 int usefilter; ///< TRUE with ":w !command" and ":r!command"
120 int amount; ///< number of '>' or '<' for shift command
121 int regname; ///< register name (NUL if none)
122 int force_bin; ///< 0, FORCE_BIN or FORCE_NOBIN
123 int read_edit; ///< ++edit argument
124 int force_ff; ///< ++ff= argument (index in cmd[])
125 int force_enc; ///< ++enc= argument (index in cmd[])
126 int bad_char; ///< BAD_KEEP, BAD_DROP or replacement byte
127 int useridx; ///< user command index
128 char_u *errmsg; ///< returned error message
129 LineGetter getline; ///< Function used to get the next line
130 void *cookie; ///< argument for getline()
131 struct condstack *cstack; ///< condition stack for ":if" etc.
132};
133
134#define FORCE_BIN 1 // ":edit ++bin file"
135#define FORCE_NOBIN 2 // ":edit ++nobin file"
136
137// Values for "flags"
138#define EXFLAG_LIST 0x01 // 'l': list
139#define EXFLAG_NR 0x02 // '#': number
140#define EXFLAG_PRINT 0x04 // 'p': print
141
142// used for completion on the command line
143struct expand {
144 int xp_context; // type of expansion
145 char_u *xp_pattern; // start of item to expand
146 size_t xp_pattern_len; // bytes in xp_pattern before cursor
147 char_u *xp_arg; // completion function
148 sctx_T xp_script_ctx; // SCTX for completion function
149 int xp_backslash; // one of the XP_BS_ values
150#ifndef BACKSLASH_IN_FILENAME
151 int xp_shell; // TRUE for a shell command, more
152 // characters need to be escaped
153#endif
154 int xp_numfiles; // number of files found by file name completion
155 char_u **xp_files; // list of files
156 char_u *xp_line; // text being completed
157 int xp_col; // cursor position in line
158};
159
160// values for xp_backslash
161#define XP_BS_NONE 0 // nothing special for backslashes
162#define XP_BS_ONE 1 // uses one backslash before a space
163#define XP_BS_THREE 2 // uses three backslashes before a space
164
165/// Command modifiers ":vertical", ":browse", ":confirm", ":hide", etc. set a
166/// flag. This needs to be saved for recursive commands, put them in a
167/// structure for easy manipulation.
168typedef struct {
169 int split; ///< flags for win_split()
170 int tab; ///< > 0 when ":tab" was used
171 bool browse; ///< true to invoke file dialog
172 bool confirm; ///< true to invoke yes/no dialog
173 bool hide; ///< true when ":hide" was used
174 bool keepalt; ///< true when ":keepalt" was used
175 bool keepjumps; ///< true when ":keepjumps" was used
176 bool keepmarks; ///< true when ":keepmarks" was used
177 bool keeppatterns; ///< true when ":keeppatterns" was used
178 bool lockmarks; ///< true when ":lockmarks" was used
179 bool noswapfile; ///< true when ":noswapfile" was used
180 char_u *save_ei; ///< saved value of 'eventignore'
181 regmatch_T filter_regmatch; ///< set by :filter /pat/
182 bool filter_force; ///< set for :filter!
183} cmdmod_T;
184
185#endif // NVIM_EX_CMDS_DEFS_H
186