robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
8c285c6c33
master
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 { 72ADDR_LINES ,///< buffer line numbers 73ADDR_WINDOWS ,///< window number 74ADDR_ARGUMENTS ,///< argument number 75ADDR_LOADED_BUFFERS ,///< buffer number of loaded buffer 76ADDR_BUFFERS ,///< buffer number 77ADDR_TABS ,///< tab page number 78ADDR_TABS_RELATIVE ,///< Tab page that only relative 79ADDR_QUICKFIX_VALID ,///< quickfix list valid entry number 80ADDR_QUICKFIX ,///< quickfix list entry number 81ADDR_UNSIGNED ,///< positive count or zero, defaults to 1 82ADDR_OTHER ,///< something else, use line number for '$', '%', etc. 83ADDR_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 { 100char * cmd_name ;///< Name of the command. 101ex_func_T cmd_func ;///< Function with implementation of this command. 102ex_preview_func_T cmd_preview_func ;///< Preview callback function of this command. 103uint32_t cmd_argt ;///< Relevant flags from the declared above. 104cmd_addr_T cmd_addr_type ;///< Flag for address type. 105}CommandDefinition ; 106 107/// Arguments used for Ex commands. 108struct exarg { 109char * arg ;///< argument of the command 110char ** args ;///< starting position of command arguments 111size_t * arglens ;///< length of command arguments 112size_t argc ;///< number of command arguments 113char * nextcmd ;///< next command (NULL if none) 114char * cmd ;///< the name of the command (except for :make) 115char ** cmdlinep ;///< pointer to pointer of allocated cmdline 116char * cmdline_tofree ;///< free later 117cmdidx_T cmdidx ;///< the index for the command 118uint32_t argt ;///< flags for the command 119int skip ;///< don't execute the command, only parse it 120int forceit ;///< true if ! present 121int addr_count ;///< the number of addresses given 122linenr_T line1 ;///< the first line number 123linenr_T line2 ;///< the second line number or count 124cmd_addr_T addr_type ;///< type of the count/range 125int flags ;///< extra flags after count: EXFLAG_ 126char * do_ecmd_cmd ;///< +command arg to be used in edited file 127linenr_T do_ecmd_lnum ;///< the line number in an edited file 128int append ;///< true with ":w >>file" command 129int usefilter ;///< true with ":w !command" and ":r!command" 130int amount ;///< number of '>' or '<' for shift command 131int regname ;///< register name (NUL if none) 132int force_bin ;///< 0, FORCE_BIN or FORCE_NOBIN 133int read_edit ;///< ++edit argument 134int mkdir_p ;///< ++p argument 135int force_ff ;///< ++ff= argument (first char of argument) 136int force_enc ;///< ++enc= argument (index in cmd[]) 137int bad_char ;///< BAD_KEEP, BAD_DROP or replacement byte 138int useridx ;///< user command index 139char * errmsg ;///< returned error message 140LineGetter ea_getline ;///< function used to get the next line 141void * cookie ;///< argument for ea_getline() 142cstack_T * cstack ;///< condition stack for ":if" etc. 143struct {///< special char handling in command args 144bool file ; 145bool 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 { 158CMOD_SANDBOX = 0x0001 ,///< ":sandbox" 159CMOD_SILENT = 0x0002 ,///< ":silent" 160CMOD_ERRSILENT = 0x0004 ,///< ":silent!" 161CMOD_UNSILENT = 0x0008 ,///< ":unsilent" 162CMOD_NOAUTOCMD = 0x0010 ,///< ":noautocmd" 163CMOD_HIDE = 0x0020 ,///< ":hide" 164CMOD_BROWSE = 0x0040 ,///< ":browse" - invoke file dialog 165CMOD_CONFIRM = 0x0080 ,///< ":confirm" - invoke yes/no dialog 166CMOD_KEEPALT = 0x0100 ,///< ":keepalt" 167CMOD_KEEPMARKS = 0x0200 ,///< ":keepmarks" 168CMOD_KEEPJUMPS = 0x0400 ,///< ":keepjumps" 169CMOD_LOCKMARKS = 0x0800 ,///< ":lockmarks" 170CMOD_KEEPPATTERNS = 0x1000 ,///< ":keeppatterns" 171CMOD_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 { 178int cmod_flags ;///< CMOD_ flags 179 180int cmod_split ;///< flags for win_split() 181int cmod_tab ;///< > 0 when ":tab" was used 182char * cmod_filter_pat ; 183regmatch_T cmod_filter_regmatch ;///< set by :filter /pat/ 184bool cmod_filter_force ;///< set for :filter! 185 186int cmod_verbose ;///< 0 if not set, > 0 to set 'verbose' to cmod_verbose - 1 187 188// values for undo_cmdmod() 189char * cmod_save_ei ;///< saved value of 'eventignore' 190int cmod_did_sandbox ;///< set when "sandbox" was incremented 191OptInt cmod_verbose_save ;///< if 'verbose' was set: value of p_verbose plus one 192int cmod_save_msg_silent ;///< if non-zero: saved value of msg_silent + 1 193int cmod_save_msg_scroll ;///< for restoring msg_scroll 194int cmod_did_esilent ;///< incremented when emsg_silent is 195}cmdmod_T ; 196 197/// Previous :substitute replacement string definition 198typedef struct { 199char * sub ;///< Previous replacement string. 200Timestamp timestamp ;///< Time when it was last set. 201AdditionalData * additional_data ;///< Additional data left from ShaDa file. 202}SubReplacementString ;