blob: caf61eda8b9d48bab4575d29ffb852d62e0be7f7 [file] [log] [blame]
Bram Moolenaaredf3f972016-08-29 22:49:24 +02001/* vi:set ts=8 sts=4 sw=4 noet:
Bram Moolenaar071d4272004-06-13 20:20:40 +00002 *
3 * VIM - Vi IMproved by Bram Moolenaar
4 *
5 * Do ":help uganda" in Vim to read copying and usage conditions.
6 * Do ":help credits" in Vim to see a list of people who contributed.
7 */
8
9/*
10 * This file contains various definitions of structures that are used by Vim
11 */
12
13/*
14 * There is something wrong in the SAS compiler that makes typedefs not
15 * valid in include files. Has been fixed in version 6.58.
16 */
17#if defined(SASC) && SASC < 658
18typedef long linenr_T;
Bram Moolenaar5fd0ca72009-05-13 16:56:33 +000019typedef int colnr_T;
Bram Moolenaar071d4272004-06-13 20:20:40 +000020typedef unsigned short short_u;
21#endif
22
John Marriott79f6ffd2024-10-31 10:06:54 +010023// structure to store a string (including it's length)
24typedef struct
25{
26 char_u *string; // the string
27 size_t length; // length of the string (excluding the NUL)
28} string_T;
29
Bram Moolenaar071d4272004-06-13 20:20:40 +000030/*
Bram Moolenaar29ddebe2019-01-26 17:28:26 +010031 * Position in file or buffer.
Bram Moolenaar071d4272004-06-13 20:20:40 +000032 */
33typedef struct
34{
Bram Moolenaar29ddebe2019-01-26 17:28:26 +010035 linenr_T lnum; // line number
36 colnr_T col; // column number
37 colnr_T coladd; // extra virtual column
Bram Moolenaar071d4272004-06-13 20:20:40 +000038} pos_T;
39
Bram Moolenaar071d4272004-06-13 20:20:40 +000040
41/*
42 * Same, but without coladd.
43 */
44typedef struct
45{
Bram Moolenaar29ddebe2019-01-26 17:28:26 +010046 linenr_T lnum; // line number
47 colnr_T col; // column number
Bram Moolenaar071d4272004-06-13 20:20:40 +000048} lpos_T;
49
50/*
51 * Structure used for growing arrays.
52 * This is used to store information that only grows, is deleted all at
53 * once, and needs to be accessed by index. See ga_clear() and ga_grow().
54 */
55typedef struct growarray
56{
Bram Moolenaar6cb39f92019-07-04 16:05:14 +020057 int ga_len; // current number of items used
58 int ga_maxlen; // maximum number of items possible
59 int ga_itemsize; // sizeof(item)
60 int ga_growsize; // number of items to grow each time
61 void *ga_data; // pointer to the first item
Bram Moolenaar071d4272004-06-13 20:20:40 +000062} garray_T;
63
64#define GA_EMPTY {0, 0, 0, 0, NULL}
65
ichizok663d18d2025-01-02 18:06:00 +010066// On rare systems "char" is unsigned, sometimes we really want a signed 8-bit
67// value.
68typedef signed char int8_T;
69typedef double float_T;
70
71typedef struct typval_S typval_T;
72typedef struct listvar_S list_T;
73typedef struct dictvar_S dict_T;
74typedef struct partial_S partial_T;
75typedef struct blobvar_S blob_T;
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +010076typedef struct tuplevar_S tuple_T;
ichizok663d18d2025-01-02 18:06:00 +010077
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000078typedef struct window_S win_T;
79typedef struct wininfo_S wininfo_T;
80typedef struct frame_S frame_T;
Bram Moolenaar6cb39f92019-07-04 16:05:14 +020081typedef int scid_T; // script ID
82typedef struct file_buffer buf_T; // forward declaration
Bram Moolenaare4f25e42017-07-07 11:54:15 +020083typedef struct terminal_S term_T;
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +020084
Bram Moolenaar1b9645d2017-09-17 23:03:31 +020085#ifdef FEAT_MENU
86typedef struct VimMenu vimmenu_T;
87#endif
88
Bram Moolenaar67979662020-06-20 22:50:47 +020089// maximum value for sc_version
90#define SCRIPT_VERSION_MAX 4
Bram Moolenaar8a7d6542020-01-26 15:56:19 +010091// value for sc_version in a Vim9 script file
92#define SCRIPT_VERSION_VIM9 999999
93
Bram Moolenaar45e5fd12017-06-04 14:58:02 +020094/*
Bram Moolenaarfe72d082019-12-20 19:07:00 +010095 * SCript ConteXt (SCTX): identifies a script line.
Bram Moolenaarf29c1c62018-09-10 21:05:02 +020096 * When sourcing a script "sc_lnum" is zero, "sourcing_lnum" is the current
97 * line number. When executing a user function "sc_lnum" is the line where the
98 * function was defined, "sourcing_lnum" is the line number inside the
99 * function. When stored with a function, mapping, option, etc. "sc_lnum" is
100 * the line number in the script "sc_sid".
Bram Moolenaar7ebcba62020-01-12 17:42:55 +0100101 *
102 * sc_version is also here, for convenience.
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200103 */
104typedef struct {
Bram Moolenaar9b8d6222020-12-28 18:26:00 +0100105#ifdef FEAT_EVAL
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200106 scid_T sc_sid; // script ID
Bram Moolenaarded5f1b2018-11-10 17:33:29 +0100107 int sc_seq; // sourcing sequence number
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200108 linenr_T sc_lnum; // line number
Bram Moolenaar9b8d6222020-12-28 18:26:00 +0100109#endif
Bram Moolenaar558ca4a2019-04-04 18:15:38 +0200110 int sc_version; // :scriptversion
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200111} sctx_T;
112
113/*
Bram Moolenaar45e5fd12017-06-04 14:58:02 +0200114 * Reference to a buffer that stores the value of buf_free_count.
Bram Moolenaarb25f9a92016-07-10 18:21:50 +0200115 * bufref_valid() only needs to check "buf" when the count differs.
116 */
117typedef struct {
118 buf_T *br_buf;
Bram Moolenaar45e5fd12017-06-04 14:58:02 +0200119 int br_fnum;
Bram Moolenaarb25f9a92016-07-10 18:21:50 +0200120 int br_buf_free_count;
121} bufref_T;
122
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +0200123/*
124 * This is here because regexp.h needs pos_T and below regprog_T is used.
125 */
126#include "regexp.h"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000127
128/*
129 * This is here because gui.h needs the pos_T and win_T, and win_T needs gui.h
130 * for scrollbar_T.
131 */
132#ifdef FEAT_GUI
133# include "gui.h"
134#else
135# ifdef FEAT_XCLIPBOARD
136# include <X11/Intrinsic.h>
137# endif
Bram Moolenaar1b58cdd2016-08-22 23:04:33 +0200138# define guicolor_T long
Bram Moolenaar8a633e32016-04-21 21:10:14 +0200139# define INVALCOLOR ((guicolor_T)0x1ffffff)
Bram Moolenaar6cb39f92019-07-04 16:05:14 +0200140 // only used for cterm.bg_rgb and cterm.fg_rgb: use cterm color
Bram Moolenaard4fc5772018-02-27 14:39:03 +0100141# define CTERMCOLOR ((guicolor_T)0x1fffffe)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000142#endif
Bram Moolenaard4fc5772018-02-27 14:39:03 +0100143#define COLOR_INVALID(x) ((x) == INVALCOLOR || (x) == CTERMCOLOR)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000144
Bram Moolenaar87fd0922021-11-20 13:47:45 +0000145#ifdef FEAT_TERMINAL
146# include "libvterm/include/vterm.h"
147typedef struct {
148 VTermColor fg;
149 VTermColor bg;
150} termcellcolor_T;
151#endif
152
Bram Moolenaar071d4272004-06-13 20:20:40 +0000153/*
154 * marks: positions in a file
155 * (a normal mark is a lnum/col pair, the same as a file position)
156 */
157
Bram Moolenaar6cb39f92019-07-04 16:05:14 +0200158#define NMARKS ('z' - 'a' + 1) // max. # of named marks
Bram Moolenaar1e78e692019-07-22 20:18:27 +0200159#define EXTRA_MARKS 10 // marks 0-9
Bram Moolenaar6cb39f92019-07-04 16:05:14 +0200160#define JUMPLISTSIZE 100 // max. # of marks in jump list
161#define TAGSTACKSIZE 20 // max. # of tags in tag stack
Bram Moolenaar071d4272004-06-13 20:20:40 +0000162
163typedef struct filemark
164{
Bram Moolenaar6cb39f92019-07-04 16:05:14 +0200165 pos_T mark; // cursor position
166 int fnum; // file number
Bram Moolenaar071d4272004-06-13 20:20:40 +0000167} fmark_T;
168
Bram Moolenaar6cb39f92019-07-04 16:05:14 +0200169// Xtended file mark: also has a file name
Bram Moolenaar071d4272004-06-13 20:20:40 +0000170typedef struct xfilemark
171{
172 fmark_T fmark;
Bram Moolenaar6cb39f92019-07-04 16:05:14 +0200173 char_u *fname; // file name, used when fnum == 0
Bram Moolenaar2d358992016-06-12 21:20:54 +0200174#ifdef FEAT_VIMINFO
Bram Moolenaarf4fba6d2016-06-26 16:44:24 +0200175 time_T time_set;
Bram Moolenaar2d358992016-06-12 21:20:54 +0200176#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000177} xfmark_T;
178
179/*
180 * The taggy struct is used to store the information about a :tag command.
181 */
182typedef struct taggy
183{
Bram Moolenaar45e18cb2019-04-28 18:05:35 +0200184 char_u *tagname; // tag name
185 fmark_T fmark; // cursor position BEFORE ":tag"
186 int cur_match; // match number
187 int cur_fnum; // buffer number used for cur_match
188 char_u *user_data; // used with tagfunc
Bram Moolenaar071d4272004-06-13 20:20:40 +0000189} taggy_T;
190
191/*
192 * Structure that contains all options that are local to a window.
193 * Used twice in a window: for the current buffer and for all buffers.
194 * Also used in wininfo_T.
195 */
196typedef struct
197{
198#ifdef FEAT_ARABIC
199 int wo_arab;
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200200# define w_p_arab w_onebuf_opt.wo_arab // 'arabic'
Bram Moolenaar071d4272004-06-13 20:20:40 +0000201#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +0200202#ifdef FEAT_LINEBREAK
203 int wo_bri;
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200204# define w_p_bri w_onebuf_opt.wo_bri // 'breakindent'
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +0200205 char_u *wo_briopt;
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200206# define w_p_briopt w_onebuf_opt.wo_briopt // 'breakindentopt'
Bram Moolenaar597a4222014-06-25 14:39:50 +0200207#endif
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200208 char_u *wo_wcr;
209# define w_p_wcr w_onebuf_opt.wo_wcr // 'wincolor'
Bram Moolenaar071d4272004-06-13 20:20:40 +0000210#ifdef FEAT_DIFF
211 int wo_diff;
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200212# define w_p_diff w_onebuf_opt.wo_diff // 'diff'
Bram Moolenaar071d4272004-06-13 20:20:40 +0000213#endif
Luuk van Baalb7147f82025-02-08 18:52:39 +0100214 char_u *wo_eiw;
215# define w_p_eiw w_onebuf_opt.wo_eiw // 'eventignorewin'
Bram Moolenaar071d4272004-06-13 20:20:40 +0000216#ifdef FEAT_FOLDING
217 long wo_fdc;
Bram Moolenaar6cb39f92019-07-04 16:05:14 +0200218# define w_p_fdc w_onebuf_opt.wo_fdc // 'foldcolumn'
Bram Moolenaara87aa802013-07-03 15:47:03 +0200219 int wo_fdc_save;
Bram Moolenaar6cb39f92019-07-04 16:05:14 +0200220# define w_p_fdc_save w_onebuf_opt.wo_fdc_save // 'foldenable' saved for diff mode
Bram Moolenaar071d4272004-06-13 20:20:40 +0000221 int wo_fen;
Bram Moolenaar6cb39f92019-07-04 16:05:14 +0200222# define w_p_fen w_onebuf_opt.wo_fen // 'foldenable'
Bram Moolenaara87aa802013-07-03 15:47:03 +0200223 int wo_fen_save;
Bram Moolenaar6cb39f92019-07-04 16:05:14 +0200224# define w_p_fen_save w_onebuf_opt.wo_fen_save // 'foldenable' saved for diff mode
Bram Moolenaar071d4272004-06-13 20:20:40 +0000225 char_u *wo_fdi;
Bram Moolenaar6cb39f92019-07-04 16:05:14 +0200226# define w_p_fdi w_onebuf_opt.wo_fdi // 'foldignore'
Bram Moolenaar071d4272004-06-13 20:20:40 +0000227 long wo_fdl;
Bram Moolenaar6cb39f92019-07-04 16:05:14 +0200228# define w_p_fdl w_onebuf_opt.wo_fdl // 'foldlevel'
Bram Moolenaara87aa802013-07-03 15:47:03 +0200229 int wo_fdl_save;
Bram Moolenaar6cb39f92019-07-04 16:05:14 +0200230# define w_p_fdl_save w_onebuf_opt.wo_fdl_save // 'foldlevel' state saved for diff mode
Bram Moolenaar071d4272004-06-13 20:20:40 +0000231 char_u *wo_fdm;
Bram Moolenaar6cb39f92019-07-04 16:05:14 +0200232# define w_p_fdm w_onebuf_opt.wo_fdm // 'foldmethod'
Bram Moolenaara87aa802013-07-03 15:47:03 +0200233 char_u *wo_fdm_save;
Bram Moolenaar6cb39f92019-07-04 16:05:14 +0200234# define w_p_fdm_save w_onebuf_opt.wo_fdm_save // 'fdm' saved for diff mode
Bram Moolenaar071d4272004-06-13 20:20:40 +0000235 long wo_fml;
Bram Moolenaar6cb39f92019-07-04 16:05:14 +0200236# define w_p_fml w_onebuf_opt.wo_fml // 'foldminlines'
Bram Moolenaar071d4272004-06-13 20:20:40 +0000237 long wo_fdn;
Bram Moolenaar6cb39f92019-07-04 16:05:14 +0200238# define w_p_fdn w_onebuf_opt.wo_fdn // 'foldnestmax'
Bram Moolenaar071d4272004-06-13 20:20:40 +0000239# ifdef FEAT_EVAL
240 char_u *wo_fde;
Bram Moolenaar6cb39f92019-07-04 16:05:14 +0200241# define w_p_fde w_onebuf_opt.wo_fde // 'foldexpr'
Bram Moolenaar071d4272004-06-13 20:20:40 +0000242 char_u *wo_fdt;
Bram Moolenaar6cb39f92019-07-04 16:05:14 +0200243# define w_p_fdt w_onebuf_opt.wo_fdt // 'foldtext'
Bram Moolenaar071d4272004-06-13 20:20:40 +0000244# endif
245 char_u *wo_fmr;
Bram Moolenaar6cb39f92019-07-04 16:05:14 +0200246# define w_p_fmr w_onebuf_opt.wo_fmr // 'foldmarker'
Bram Moolenaar071d4272004-06-13 20:20:40 +0000247#endif
248#ifdef FEAT_LINEBREAK
249 int wo_lbr;
Bram Moolenaar6cb39f92019-07-04 16:05:14 +0200250# define w_p_lbr w_onebuf_opt.wo_lbr // 'linebreak'
Bram Moolenaar071d4272004-06-13 20:20:40 +0000251#endif
252 int wo_list;
Bram Moolenaar6cb39f92019-07-04 16:05:14 +0200253#define w_p_list w_onebuf_opt.wo_list // 'list'
Bram Moolenaareed9d462021-02-15 20:38:25 +0100254 char_u *wo_lcs;
255#define w_p_lcs w_onebuf_opt.wo_lcs // 'listchars'
Bram Moolenaar96ba25a2022-07-04 17:34:33 +0100256 char_u *wo_fcs;
257#define w_p_fcs w_onebuf_opt.wo_fcs // 'fillchars'
Bram Moolenaar071d4272004-06-13 20:20:40 +0000258 int wo_nu;
Bram Moolenaar6cb39f92019-07-04 16:05:14 +0200259#define w_p_nu w_onebuf_opt.wo_nu // 'number'
Bram Moolenaar64486672010-05-16 15:46:46 +0200260 int wo_rnu;
Bram Moolenaar6cb39f92019-07-04 16:05:14 +0200261#define w_p_rnu w_onebuf_opt.wo_rnu // 'relativenumber'
Gary Johnson51ad8502021-08-03 18:33:08 +0200262 char_u *wo_ve;
263#define w_p_ve w_onebuf_opt.wo_ve // 'virtualedit'
264 unsigned wo_ve_flags;
265#define w_ve_flags w_onebuf_opt.wo_ve_flags // flags for 'virtualedit'
Bram Moolenaar592e0a22004-07-03 16:05:59 +0000266#ifdef FEAT_LINEBREAK
267 long wo_nuw;
Bram Moolenaar6cb39f92019-07-04 16:05:14 +0200268# define w_p_nuw w_onebuf_opt.wo_nuw // 'numberwidth'
Bram Moolenaar592e0a22004-07-03 16:05:59 +0000269#endif
Colin Kennedy21570352024-03-03 16:16:47 +0100270 int wo_wfb;
271#define w_p_wfb w_onebuf_opt.wo_wfb // 'winfixbuf'
Bram Moolenaar071d4272004-06-13 20:20:40 +0000272 int wo_wfh;
Bram Moolenaar6cb39f92019-07-04 16:05:14 +0200273# define w_p_wfh w_onebuf_opt.wo_wfh // 'winfixheight'
Bram Moolenaar97b2ad32006-03-18 21:40:56 +0000274 int wo_wfw;
Bram Moolenaar6cb39f92019-07-04 16:05:14 +0200275# define w_p_wfw w_onebuf_opt.wo_wfw // 'winfixwidth'
Bram Moolenaar4033c552017-09-16 20:54:51 +0200276#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000277 int wo_pvw;
Bram Moolenaar6cb39f92019-07-04 16:05:14 +0200278# define w_p_pvw w_onebuf_opt.wo_pvw // 'previewwindow'
64-bitman88d41ab2025-04-06 17:20:39 +0200279 long wo_lhi;
280# define w_p_lhi w_onebuf_opt.wo_lhi // 'lhistory'
Bram Moolenaar071d4272004-06-13 20:20:40 +0000281#endif
282#ifdef FEAT_RIGHTLEFT
283 int wo_rl;
Bram Moolenaar6cb39f92019-07-04 16:05:14 +0200284# define w_p_rl w_onebuf_opt.wo_rl // 'rightleft'
Bram Moolenaar071d4272004-06-13 20:20:40 +0000285 char_u *wo_rlc;
Bram Moolenaar6cb39f92019-07-04 16:05:14 +0200286# define w_p_rlc w_onebuf_opt.wo_rlc // 'rightleftcmd'
Bram Moolenaar071d4272004-06-13 20:20:40 +0000287#endif
288 long wo_scr;
Bram Moolenaar6cb39f92019-07-04 16:05:14 +0200289#define w_p_scr w_onebuf_opt.wo_scr // 'scroll'
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100290 int wo_sms;
291#define w_p_sms w_onebuf_opt.wo_sms // 'smoothscroll'
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000292#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +0000293 int wo_spell;
Bram Moolenaar6cb39f92019-07-04 16:05:14 +0200294# define w_p_spell w_onebuf_opt.wo_spell // 'spell'
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000295#endif
Martin Tournoijba43e762022-10-13 22:12:15 +0100296#if defined(FEAT_SYN_HL) || defined(FEAT_FOLDING) || defined(FEAT_DIFF)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000297 int wo_cuc;
Bram Moolenaar6cb39f92019-07-04 16:05:14 +0200298# define w_p_cuc w_onebuf_opt.wo_cuc // 'cursorcolumn'
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000299 int wo_cul;
Bram Moolenaar6cb39f92019-07-04 16:05:14 +0200300# define w_p_cul w_onebuf_opt.wo_cul // 'cursorline'
Bram Moolenaar410e98a2019-09-09 22:05:49 +0200301 char_u *wo_culopt;
302# define w_p_culopt w_onebuf_opt.wo_culopt // 'cursorlineopt'
Bram Moolenaar1a384422010-07-14 19:53:30 +0200303 char_u *wo_cc;
Bram Moolenaar6cb39f92019-07-04 16:05:14 +0200304# define w_p_cc w_onebuf_opt.wo_cc // 'colorcolumn'
Bram Moolenaar217ad922005-03-20 22:37:15 +0000305#endif
Bram Moolenaaree857022019-11-09 23:26:40 +0100306#ifdef FEAT_LINEBREAK
307 char_u *wo_sbr;
308#define w_p_sbr w_onebuf_opt.wo_sbr // 'showbreak'
309#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +0000310#ifdef FEAT_STL_OPT
311 char_u *wo_stl;
Bram Moolenaar6cb39f92019-07-04 16:05:14 +0200312#define w_p_stl w_onebuf_opt.wo_stl // 'statusline'
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +0000313#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000314 int wo_scb;
Bram Moolenaar6cb39f92019-07-04 16:05:14 +0200315#define w_p_scb w_onebuf_opt.wo_scb // 'scrollbind'
316 int wo_diff_saved; // options were saved for starting diff mode
Bram Moolenaar8a3bb562018-03-04 20:14:14 +0100317#define w_p_diff_saved w_onebuf_opt.wo_diff_saved
Bram Moolenaar6cb39f92019-07-04 16:05:14 +0200318 int wo_scb_save; // 'scrollbind' saved for diff mode
Bram Moolenaar8a3bb562018-03-04 20:14:14 +0100319#define w_p_scb_save w_onebuf_opt.wo_scb_save
Bram Moolenaar071d4272004-06-13 20:20:40 +0000320 int wo_wrap;
Bram Moolenaar6cb39f92019-07-04 16:05:14 +0200321#define w_p_wrap w_onebuf_opt.wo_wrap // 'wrap'
Bram Moolenaara87aa802013-07-03 15:47:03 +0200322#ifdef FEAT_DIFF
Bram Moolenaar6cb39f92019-07-04 16:05:14 +0200323 int wo_wrap_save; // 'wrap' state saved for diff mode
Bram Moolenaara87aa802013-07-03 15:47:03 +0200324# define w_p_wrap_save w_onebuf_opt.wo_wrap_save
325#endif
Bram Moolenaar860cae12010-06-05 23:22:07 +0200326#ifdef FEAT_CONCEAL
Bram Moolenaar6cb39f92019-07-04 16:05:14 +0200327 char_u *wo_cocu; // 'concealcursor'
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200328# define w_p_cocu w_onebuf_opt.wo_cocu
Bram Moolenaar6cb39f92019-07-04 16:05:14 +0200329 long wo_cole; // 'conceallevel'
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200330# define w_p_cole w_onebuf_opt.wo_cole
Bram Moolenaar860cae12010-06-05 23:22:07 +0200331#endif
Bram Moolenaar860cae12010-06-05 23:22:07 +0200332 int wo_crb;
Bram Moolenaar6cb39f92019-07-04 16:05:14 +0200333#define w_p_crb w_onebuf_opt.wo_crb // 'cursorbind'
334 int wo_crb_save; // 'cursorbind' state saved for diff mode
Bram Moolenaar8a3bb562018-03-04 20:14:14 +0100335#define w_p_crb_save w_onebuf_opt.wo_crb_save
Bram Moolenaar95ec9d62016-08-12 18:29:59 +0200336#ifdef FEAT_SIGNS
337 char_u *wo_scl;
Bram Moolenaar6cb39f92019-07-04 16:05:14 +0200338# define w_p_scl w_onebuf_opt.wo_scl // 'signcolumn'
Bram Moolenaar95ec9d62016-08-12 18:29:59 +0200339#endif
Christian Brabandt4a8eb6e2023-08-13 19:43:42 +0200340 long wo_siso;
341# define w_p_siso w_onebuf_opt.wo_siso // 'sidescrolloff' local value
342 long wo_so;
343# define w_p_so w_onebuf_opt.wo_so // 'scrolloff' local value
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200344#ifdef FEAT_TERMINAL
Bram Moolenaare1fc5152018-04-21 19:49:08 +0200345 char_u *wo_twk;
Bram Moolenaar6cb39f92019-07-04 16:05:14 +0200346# define w_p_twk w_onebuf_opt.wo_twk // 'termwinkey'
Bram Moolenaare1fc5152018-04-21 19:49:08 +0200347 char_u *wo_tws;
Bram Moolenaar6cb39f92019-07-04 16:05:14 +0200348# define w_p_tws w_onebuf_opt.wo_tws // 'termwinsize'
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200349#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000350
351#ifdef FEAT_EVAL
Bram Moolenaar6cb39f92019-07-04 16:05:14 +0200352 sctx_T wo_script_ctx[WV_COUNT]; // SCTXs for window-local options
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200353# define w_p_script_ctx w_onebuf_opt.wo_script_ctx
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000354#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000355} winopt_T;
356
357/*
358 * Window info stored with a buffer.
359 *
360 * Two types of info are kept for a buffer which are associated with a
361 * specific window:
362 * 1. Each window can have a different line number associated with a buffer.
363 * 2. The window-local options for a buffer work in a similar way.
364 * The window-info is kept in a list at b_wininfo. It is kept in
365 * most-recently-used order.
366 */
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +0000367struct wininfo_S
Bram Moolenaar071d4272004-06-13 20:20:40 +0000368{
Bram Moolenaar6cb39f92019-07-04 16:05:14 +0200369 wininfo_T *wi_next; // next entry or NULL for last entry
370 wininfo_T *wi_prev; // previous entry or NULL for first entry
371 win_T *wi_win; // pointer to window that did set wi_fpos
372 pos_T wi_fpos; // last cursor position in the file
Bram Moolenaar6cb39f92019-07-04 16:05:14 +0200373 winopt_T wi_opt; // local window options
Dominique Pelle3276f582021-08-07 12:44:41 +0200374 int wi_optset; // TRUE when wi_opt has useful values
Bram Moolenaar071d4272004-06-13 20:20:40 +0000375#ifdef FEAT_FOLDING
Bram Moolenaar6cb39f92019-07-04 16:05:14 +0200376 int wi_fold_manual; // copy of w_fold_manual
377 garray_T wi_folds; // clone of w_folds
Bram Moolenaar071d4272004-06-13 20:20:40 +0000378#endif
LemonBoydb0ea7f2022-04-10 17:59:26 +0100379 int wi_changelistidx; // copy of w_changelistidx
Bram Moolenaar071d4272004-06-13 20:20:40 +0000380};
381
382/*
383 * Info used to pass info about a fold from the fold-detection code to the
384 * code that displays the foldcolumn.
385 */
386typedef struct foldinfo
387{
Bram Moolenaar6cb39f92019-07-04 16:05:14 +0200388 int fi_level; // level of the fold; when this is zero the
389 // other fields are invalid
390 int fi_lnum; // line number where fold starts
391 int fi_low_level; // lowest fold level that starts in the same
392 // line
Bram Moolenaar071d4272004-06-13 20:20:40 +0000393} foldinfo_T;
394
Bram Moolenaar6cb39f92019-07-04 16:05:14 +0200395/*
396 * Structure to store info about the Visual area.
397 */
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000398typedef struct
399{
Bram Moolenaar6cb39f92019-07-04 16:05:14 +0200400 pos_T vi_start; // start pos of last VIsual
401 pos_T vi_end; // end position of last VIsual
402 int vi_mode; // VIsual_mode of last VIsual
403 colnr_T vi_curswant; // MAXCOL from w_curswant
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000404} visualinfo_T;
405
Bram Moolenaar071d4272004-06-13 20:20:40 +0000406/*
Bram Moolenaar335437b2007-05-10 18:32:52 +0000407 * structures used for undo
Bram Moolenaar071d4272004-06-13 20:20:40 +0000408 */
409
Bram Moolenaarccae4672019-01-04 15:09:57 +0100410// One line saved for undo. After the NUL terminated text there might be text
411// properties, thus ul_len can be larger than STRLEN(ul_line) + 1.
412typedef struct {
413 char_u *ul_line; // text of the line
414 long ul_len; // length of the line including NUL, plus text
415 // properties
John Marriottfd1a8382024-11-06 21:21:50 +0100416 colnr_T ul_textlen; // length of the line excluding NUL and any text
417 // properties
Bram Moolenaarccae4672019-01-04 15:09:57 +0100418} undoline_T;
419
Bram Moolenaar071d4272004-06-13 20:20:40 +0000420typedef struct u_entry u_entry_T;
421typedef struct u_header u_header_T;
422struct u_entry
423{
Bram Moolenaar6cb39f92019-07-04 16:05:14 +0200424 u_entry_T *ue_next; // pointer to next entry in list
425 linenr_T ue_top; // number of line above undo block
426 linenr_T ue_bot; // number of line below undo block
427 linenr_T ue_lcount; // linecount when u_save called
428 undoline_T *ue_array; // array of lines in undo block
429 long ue_size; // number of lines in ue_array
Bram Moolenaarfecb6602007-10-01 20:54:15 +0000430#ifdef U_DEBUG
Bram Moolenaar6cb39f92019-07-04 16:05:14 +0200431 int ue_magic; // magic number to check allocation
Bram Moolenaarfecb6602007-10-01 20:54:15 +0000432#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000433};
434
435struct u_header
436{
Bram Moolenaar6cb39f92019-07-04 16:05:14 +0200437 // The following have a pointer and a number. The number is used when
438 // reading the undo file in u_read_undo()
Bram Moolenaar83d09bb2010-06-01 19:58:08 +0200439 union {
Bram Moolenaar6cb39f92019-07-04 16:05:14 +0200440 u_header_T *ptr; // pointer to next undo header in list
Bram Moolenaar83d09bb2010-06-01 19:58:08 +0200441 long seq;
442 } uh_next;
443 union {
Bram Moolenaar6cb39f92019-07-04 16:05:14 +0200444 u_header_T *ptr; // pointer to previous header in list
Bram Moolenaar83d09bb2010-06-01 19:58:08 +0200445 long seq;
446 } uh_prev;
447 union {
Bram Moolenaar6cb39f92019-07-04 16:05:14 +0200448 u_header_T *ptr; // pointer to next header for alt. redo
Bram Moolenaar83d09bb2010-06-01 19:58:08 +0200449 long seq;
450 } uh_alt_next;
451 union {
Bram Moolenaar6cb39f92019-07-04 16:05:14 +0200452 u_header_T *ptr; // pointer to previous header for alt. redo
Bram Moolenaar83d09bb2010-06-01 19:58:08 +0200453 long seq;
454 } uh_alt_prev;
Bram Moolenaar6cb39f92019-07-04 16:05:14 +0200455 long uh_seq; // sequence number, higher == newer undo
456 int uh_walk; // used by undo_time()
457 u_entry_T *uh_entry; // pointer to first entry
458 u_entry_T *uh_getbot_entry; // pointer to where ue_bot must be set
459 pos_T uh_cursor; // cursor position before saving
Bram Moolenaar071d4272004-06-13 20:20:40 +0000460 long uh_cursor_vcol;
Bram Moolenaar6cb39f92019-07-04 16:05:14 +0200461 int uh_flags; // see below
462 pos_T uh_namedm[NMARKS]; // marks before undo/after redo
463 visualinfo_T uh_visual; // Visual areas before undo/after redo
464 time_T uh_time; // timestamp when the change was made
465 long uh_save_nr; // set when the file was saved after the
466 // changes in this block
Bram Moolenaarfecb6602007-10-01 20:54:15 +0000467#ifdef U_DEBUG
Bram Moolenaar6cb39f92019-07-04 16:05:14 +0200468 int uh_magic; // magic number to check allocation
Bram Moolenaarfecb6602007-10-01 20:54:15 +0000469#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000470};
471
Bram Moolenaar6cb39f92019-07-04 16:05:14 +0200472// values for uh_flags
473#define UH_CHANGED 0x01 // b_changed flag before undo/after redo
474#define UH_EMPTYBUF 0x02 // buffer was empty
Bram Moolenaar071d4272004-06-13 20:20:40 +0000475
476/*
Bram Moolenaar335437b2007-05-10 18:32:52 +0000477 * structures used in undo.c
Bram Moolenaar071d4272004-06-13 20:20:40 +0000478 */
Bram Moolenaar6cb39f92019-07-04 16:05:14 +0200479#define ALIGN_LONG // longword alignment and use filler byte
Bram Moolenaar30276f22019-01-24 17:59:39 +0100480#define ALIGN_SIZE (sizeof(long))
Bram Moolenaar071d4272004-06-13 20:20:40 +0000481
482#define ALIGN_MASK (ALIGN_SIZE - 1)
483
484typedef struct m_info minfo_T;
485
486/*
Bram Moolenaar2767c602010-05-16 13:56:06 +0200487 * structure used to link chunks in one of the free chunk lists.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000488 */
489struct m_info
490{
491#ifdef ALIGN_LONG
Bram Moolenaar6cb39f92019-07-04 16:05:14 +0200492 long_u m_size; // size of the chunk (including m_info)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000493#else
Bram Moolenaar6cb39f92019-07-04 16:05:14 +0200494 short_u m_size; // size of the chunk (including m_info)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000495#endif
Bram Moolenaar6cb39f92019-07-04 16:05:14 +0200496 minfo_T *m_next; // pointer to next free chunk in the list
Bram Moolenaar071d4272004-06-13 20:20:40 +0000497};
498
499/*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000500 * things used in memfile.c
501 */
502
503typedef struct block_hdr bhdr_T;
504typedef struct memfile memfile_T;
505typedef long blocknr_T;
506
507/*
Bram Moolenaarb05b10a2011-03-22 18:10:45 +0100508 * mf_hashtab_T is a chained hashtable with blocknr_T key and arbitrary
509 * structures as items. This is an intrusive data structure: we require
510 * that items begin with mf_hashitem_T which contains the key and linked
511 * list pointers. List of items in each bucket is doubly-linked.
512 */
513
514typedef struct mf_hashitem_S mf_hashitem_T;
515
516struct mf_hashitem_S
517{
518 mf_hashitem_T *mhi_next;
519 mf_hashitem_T *mhi_prev;
520 blocknr_T mhi_key;
521};
522
523#define MHT_INIT_SIZE 64
524
525typedef struct mf_hashtab_S
526{
Bram Moolenaar6cb39f92019-07-04 16:05:14 +0200527 long_u mht_mask; // mask used for hash value (nr of items
528 // in array is "mht_mask" + 1)
529 long_u mht_count; // nr of items inserted into hashtable
530 mf_hashitem_T **mht_buckets; // points to mht_small_buckets or
531 //dynamically allocated array
532 mf_hashitem_T *mht_small_buckets[MHT_INIT_SIZE]; // initial buckets
533 char mht_fixed; // non-zero value forbids growth
Bram Moolenaarb05b10a2011-03-22 18:10:45 +0100534} mf_hashtab_T;
535
536/*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000537 * for each (previously) used block in the memfile there is one block header.
538 *
539 * The block may be linked in the used list OR in the free list.
540 * The used blocks are also kept in hash lists.
541 *
542 * The used list is a doubly linked list, most recently used block first.
543 * The blocks in the used list have a block of memory allocated.
544 * mf_used_count is the number of pages in the used list.
545 * The hash lists are used to quickly find a block in the used list.
546 * The free list is a single linked list, not sorted.
547 * The blocks in the free list have no block of memory allocated and
548 * the contents of the block in the file (if any) is irrelevant.
549 */
550
551struct block_hdr
552{
Bram Moolenaar6cb39f92019-07-04 16:05:14 +0200553 mf_hashitem_T bh_hashitem; // header for hash table and key
554#define bh_bnum bh_hashitem.mhi_key // block number, part of bh_hashitem
Bram Moolenaarb05b10a2011-03-22 18:10:45 +0100555
Bram Moolenaar6cb39f92019-07-04 16:05:14 +0200556 bhdr_T *bh_next; // next block_hdr in free or used list
557 bhdr_T *bh_prev; // previous block_hdr in used list
558 char_u *bh_data; // pointer to memory (for used block)
559 int bh_page_count; // number of pages in this block
Bram Moolenaar071d4272004-06-13 20:20:40 +0000560
561#define BH_DIRTY 1
562#define BH_LOCKED 2
Bram Moolenaar6cb39f92019-07-04 16:05:14 +0200563 char bh_flags; // BH_DIRTY or BH_LOCKED
Bram Moolenaar071d4272004-06-13 20:20:40 +0000564};
565
566/*
567 * when a block with a negative number is flushed to the file, it gets
568 * a positive number. Because the reference to the block is still the negative
569 * number, we remember the translation to the new positive number in the
570 * double linked trans lists. The structure is the same as the hash lists.
571 */
572typedef struct nr_trans NR_TRANS;
573
574struct nr_trans
575{
Bram Moolenaar6cb39f92019-07-04 16:05:14 +0200576 mf_hashitem_T nt_hashitem; // header for hash table and key
577#define nt_old_bnum nt_hashitem.mhi_key // old, negative, number
Bram Moolenaarb05b10a2011-03-22 18:10:45 +0100578
Bram Moolenaar6cb39f92019-07-04 16:05:14 +0200579 blocknr_T nt_new_bnum; // new, positive, number
Bram Moolenaar071d4272004-06-13 20:20:40 +0000580};
581
Bram Moolenaar0a36fec2014-02-11 15:10:43 +0100582
583typedef struct buffblock buffblock_T;
584typedef struct buffheader buffheader_T;
585
Bram Moolenaar071d4272004-06-13 20:20:40 +0000586/*
587 * structure used to store one block of the stuff/redo/recording buffers
588 */
589struct buffblock
590{
Bram Moolenaar6cb39f92019-07-04 16:05:14 +0200591 buffblock_T *b_next; // pointer to next buffblock
John Marriotte7a1bbf2024-11-11 20:40:33 +0100592 size_t b_strlen; // length of b_str, excluding the NUL
Bram Moolenaar6cb39f92019-07-04 16:05:14 +0200593 char_u b_str[1]; // contents (actually longer)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000594};
595
596/*
597 * header used for the stuff buffer and the redo buffer
598 */
599struct buffheader
600{
Bram Moolenaar6cb39f92019-07-04 16:05:14 +0200601 buffblock_T bh_first; // first (dummy) block of list
602 buffblock_T *bh_curr; // buffblock for appending
603 int bh_index; // index for reading
604 int bh_space; // space in bh_curr for appending
John Marriotte7a1bbf2024-11-11 20:40:33 +0100605 int bh_create_newblock; // create a new block?
Bram Moolenaar071d4272004-06-13 20:20:40 +0000606};
607
Bram Moolenaard4863aa2017-04-07 19:50:12 +0200608typedef struct
609{
610 buffheader_T sr_redobuff;
611 buffheader_T sr_old_redobuff;
612} save_redo_T;
613
Bram Moolenaar048d9d22023-05-06 22:21:11 +0100614typedef enum {
615 XP_PREFIX_NONE, // prefix not used
616 XP_PREFIX_NO, // "no" prefix for bool option
617 XP_PREFIX_INV, // "inv" prefix for bool option
618} xp_prefix_T;
619
Yee Cheng Chin6d113472023-10-02 21:38:39 +0200620/*
621 * :set operator types
622 */
Yee Cheng Chin6ee7b522023-10-01 09:13:22 +0200623typedef enum {
624 OP_NONE = 0,
625 OP_ADDING, // "opt+=arg"
626 OP_PREPENDING, // "opt^=arg"
627 OP_REMOVING, // "opt-=arg"
628} set_op_T;
629
Bram Moolenaar071d4272004-06-13 20:20:40 +0000630/*
631 * used for completion on the command line
632 */
633typedef struct expand
634{
Yee Cheng Chin989426b2023-10-14 11:46:51 +0200635 char_u *xp_pattern; // start of item to expand, guaranteed
636 // to be part of xp_line
Bram Moolenaard6beab02019-11-10 15:07:19 +0100637 int xp_context; // type of expansion
Bram Moolenaar6cb39f92019-07-04 16:05:14 +0200638 int xp_pattern_len; // bytes in xp_pattern before cursor
Bram Moolenaar048d9d22023-05-06 22:21:11 +0100639 xp_prefix_T xp_prefix;
Bram Moolenaar0a52df52019-08-18 22:26:31 +0200640#if defined(FEAT_EVAL)
Bram Moolenaar6cb39f92019-07-04 16:05:14 +0200641 char_u *xp_arg; // completion function
642 sctx_T xp_script_ctx; // SCTX for completion function
Bram Moolenaar071d4272004-06-13 20:20:40 +0000643#endif
Bram Moolenaar6cb39f92019-07-04 16:05:14 +0200644 int xp_backslash; // one of the XP_BS_ values
Bram Moolenaar8ada17c2006-01-19 22:16:24 +0000645#ifndef BACKSLASH_IN_FILENAME
Bram Moolenaar6cb39f92019-07-04 16:05:14 +0200646 int xp_shell; // TRUE for a shell command, more
647 // characters need to be escaped
Bram Moolenaar8ada17c2006-01-19 22:16:24 +0000648#endif
Bram Moolenaar6cb39f92019-07-04 16:05:14 +0200649 int xp_numfiles; // number of files found by
650 // file name completion
Bram Moolenaard6beab02019-11-10 15:07:19 +0100651 int xp_col; // cursor position in line
zeertzjqe9ef3472023-08-17 23:57:05 +0200652 int xp_selected; // selected index in completion
zeertzjq28a23602023-09-29 19:58:35 +0200653 char_u *xp_orig; // originally expanded string
Bram Moolenaar6cb39f92019-07-04 16:05:14 +0200654 char_u **xp_files; // list of files
655 char_u *xp_line; // text being completed
Bram Moolenaar5ff595d2022-08-26 22:36:41 +0100656#define EXPAND_BUF_LEN 256
657 char_u xp_buf[EXPAND_BUF_LEN]; // buffer for returned match
Bram Moolenaar071d4272004-06-13 20:20:40 +0000658} expand_T;
659
Bram Moolenaar6cb39f92019-07-04 16:05:14 +0200660/*
661 * values for xp_backslash
662 */
663#define XP_BS_NONE 0 // nothing special for backslashes
Yee Cheng Chin54844852023-10-09 18:12:31 +0200664#define XP_BS_ONE 0x1 // uses one backslash before a space
665#define XP_BS_THREE 0x2 // uses three backslashes before a space
666#define XP_BS_COMMA 0x4 // commas need to be escaped with a backslash
Bram Moolenaar071d4272004-06-13 20:20:40 +0000667
668/*
Bram Moolenaar66b51422019-08-18 21:44:12 +0200669 * Variables shared between getcmdline(), redrawcmdline() and others.
670 * These need to be saved when using CTRL-R |, that's why they are in a
671 * structure.
672 */
673typedef struct
674{
Bram Moolenaar4aea03e2019-09-25 22:37:17 +0200675 char_u *cmdbuff; // pointer to command line buffer
676 int cmdbufflen; // length of cmdbuff
677 int cmdlen; // number of chars in command line
678 int cmdpos; // current cursor position
679 int cmdspos; // cursor column on screen
680 int cmdfirstc; // ':', '/', '?', '=', '>' or NUL
681 int cmdindent; // number of spaces before cmdline
682 char_u *cmdprompt; // message in front of cmdline
683 int cmdattr; // attributes for prompt
684 int overstrike; // Typing mode on the command line. Shared by
685 // getcmdline() and put_on_cmdline().
686 expand_T *xpc; // struct being used for expansion, xp_pattern
687 // may point into cmdbuff
688 int xp_context; // type of expansion
Bram Moolenaar66b51422019-08-18 21:44:12 +0200689# ifdef FEAT_EVAL
Bram Moolenaar4aea03e2019-09-25 22:37:17 +0200690 char_u *xp_arg; // user-defined expansion arg
691 int input_fn; // when TRUE Invoked for input() function
Bram Moolenaar66b51422019-08-18 21:44:12 +0200692# endif
693} cmdline_info_T;
694
695/*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000696 * Command modifiers ":vertical", ":browse", ":confirm" and ":hide" set a flag.
697 * This needs to be saved for recursive commands, put them in a structure for
698 * easy manipulation.
699 */
700typedef struct
701{
Bram Moolenaare1004402020-10-24 20:49:43 +0200702 int cmod_flags; // CMOD_ flags
703#define CMOD_SANDBOX 0x0001 // ":sandbox"
704#define CMOD_SILENT 0x0002 // ":silent"
705#define CMOD_ERRSILENT 0x0004 // ":silent!"
706#define CMOD_UNSILENT 0x0008 // ":unsilent"
707#define CMOD_NOAUTOCMD 0x0010 // ":noautocmd"
708#define CMOD_HIDE 0x0020 // ":hide"
709#define CMOD_BROWSE 0x0040 // ":browse" - invoke file dialog
710#define CMOD_CONFIRM 0x0080 // ":confirm" - invoke yes/no dialog
711#define CMOD_KEEPALT 0x0100 // ":keepalt"
712#define CMOD_KEEPMARKS 0x0200 // ":keepmarks"
713#define CMOD_KEEPJUMPS 0x0400 // ":keepjumps"
714#define CMOD_LOCKMARKS 0x0800 // ":lockmarks"
715#define CMOD_KEEPPATTERNS 0x1000 // ":keeppatterns"
716#define CMOD_NOSWAPFILE 0x2000 // ":noswapfile"
Bram Moolenaar39f3b142021-02-14 12:57:36 +0100717#define CMOD_VIM9CMD 0x4000 // ":vim9cmd"
Bram Moolenaar96cf4ba2021-04-24 14:15:41 +0200718#define CMOD_LEGACY 0x8000 // ":legacy"
Bram Moolenaare1004402020-10-24 20:49:43 +0200719
720 int cmod_split; // flags for win_split()
721 int cmod_tab; // > 0 when ":tab" was used
722 regmatch_T cmod_filter_regmatch; // set by :filter /pat/
723 int cmod_filter_force; // set for :filter!
Bram Moolenaar5661ed62020-10-24 17:19:16 +0200724
zeertzjqcd749632022-06-14 13:30:35 +0100725 int cmod_verbose; // 0 if not set, > 0 to set 'verbose'
726 // to cmod_verbose - 1
Bram Moolenaar5661ed62020-10-24 17:19:16 +0200727
728 // values for undo_cmdmod()
729 char_u *cmod_save_ei; // saved value of 'eventignore'
730#ifdef HAVE_SANDBOX
731 int cmod_did_sandbox; // set when "sandbox" was incremented
732#endif
733 long cmod_verbose_save; // if 'verbose' was set: value of
734 // p_verbose plus one
735 int cmod_save_msg_silent; // if non-zero: saved value of
736 // msg_silent + 1
Bram Moolenaare1004402020-10-24 20:49:43 +0200737 int cmod_save_msg_scroll; // for restoring msg_scroll
Bram Moolenaar5661ed62020-10-24 17:19:16 +0200738 int cmod_did_esilent; // incremented when emsg_silent is
Bram Moolenaar071d4272004-06-13 20:20:40 +0000739} cmdmod_T;
740
Bram Moolenaar3a2a60c2023-05-27 18:02:55 +0100741typedef enum {
742 MF_DIRTY_NO = 0, // no dirty blocks
743 MF_DIRTY_YES, // there are dirty blocks
744 MF_DIRTY_YES_NOSYNC, // there are dirty blocks, do not sync yet
745} mfdirty_T;
746
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +0200747#define MF_SEED_LEN 8
Bram Moolenaar071d4272004-06-13 20:20:40 +0000748
749struct memfile
750{
Bram Moolenaarb58a4b92019-05-27 23:36:21 +0200751 char_u *mf_fname; // name of the file
752 char_u *mf_ffname; // idem, full path
753 int mf_fd; // file descriptor
754 int mf_flags; // flags used when opening this memfile
755 int mf_reopen; // mf_fd was closed, retry opening
756 bhdr_T *mf_free_first; // first block_hdr in free list
757 bhdr_T *mf_used_first; // mru block_hdr in used list
758 bhdr_T *mf_used_last; // lru block_hdr in used list
759 unsigned mf_used_count; // number of pages in used list
760 unsigned mf_used_count_max; // maximum number of pages in memory
761 mf_hashtab_T mf_hash; // hash lists
762 mf_hashtab_T mf_trans; // trans lists
763 blocknr_T mf_blocknr_max; // highest positive block number + 1
764 blocknr_T mf_blocknr_min; // lowest negative block number - 1
765 blocknr_T mf_neg_count; // number of negative blocks numbers
766 blocknr_T mf_infile_count; // number of pages in the file
767 unsigned mf_page_size; // number of bytes in a page
Bram Moolenaar3a2a60c2023-05-27 18:02:55 +0100768 mfdirty_T mf_dirty;
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +0200769#ifdef FEAT_CRYPT
Bram Moolenaarb58a4b92019-05-27 23:36:21 +0200770 buf_T *mf_buffer; // buffer this memfile is for
771 char_u mf_seed[MF_SEED_LEN]; // seed for encryption
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +0200772
Bram Moolenaarb58a4b92019-05-27 23:36:21 +0200773 // Values for key, method and seed used for reading data blocks when
774 // updating for a newly set key or method. Only when mf_old_key != NULL.
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +0200775 char_u *mf_old_key;
776 int mf_old_cm;
777 char_u mf_old_seed[MF_SEED_LEN];
778#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000779};
780
781/*
782 * things used in memline.c
783 */
784/*
785 * When searching for a specific line, we remember what blocks in the tree
786 * are the branches leading to that block. This is stored in ml_stack. Each
787 * entry is a pointer to info in a block (may be data block or pointer block)
788 */
789typedef struct info_pointer
790{
Bram Moolenaar6cb39f92019-07-04 16:05:14 +0200791 blocknr_T ip_bnum; // block number
792 linenr_T ip_low; // lowest lnum in this block
793 linenr_T ip_high; // highest lnum in this block
794 int ip_index; // index for block with current lnum
795} infoptr_T; // block/index pair
Bram Moolenaar071d4272004-06-13 20:20:40 +0000796
797#ifdef FEAT_BYTEOFF
798typedef struct ml_chunksize
799{
800 int mlcs_numlines;
801 long mlcs_totalsize;
802} chunksize_T;
803
Bram Moolenaar6cb39f92019-07-04 16:05:14 +0200804/*
805 * Flags when calling ml_updatechunk()
806 */
807# define ML_CHNK_ADDLINE 1
808# define ML_CHNK_DELLINE 2
809# define ML_CHNK_UPDLINE 3
Bram Moolenaar071d4272004-06-13 20:20:40 +0000810#endif
811
812/*
813 * the memline structure holds all the information about a memline
814 */
815typedef struct memline
816{
Bram Moolenaar6cb39f92019-07-04 16:05:14 +0200817 linenr_T ml_line_count; // number of lines in the buffer
Bram Moolenaar071d4272004-06-13 20:20:40 +0000818
Bram Moolenaar6cb39f92019-07-04 16:05:14 +0200819 memfile_T *ml_mfp; // pointer to associated memfile
Bram Moolenaar071d4272004-06-13 20:20:40 +0000820
Bram Moolenaard6beab02019-11-10 15:07:19 +0100821 infoptr_T *ml_stack; // stack of pointer blocks (array of IPTRs)
822 int ml_stack_top; // current top of ml_stack
823 int ml_stack_size; // total number of entries in ml_stack
824
Bram Moolenaarfa4873c2022-06-30 22:13:59 +0100825#define ML_EMPTY 0x01 // empty buffer
826#define ML_LINE_DIRTY 0x02 // cached line was changed and allocated
827#define ML_LOCKED_DIRTY 0x04 // ml_locked was changed
828#define ML_LOCKED_POS 0x08 // ml_locked needs positive block number
829#define ML_ALLOCATED 0x10 // ml_line_ptr is an allocated copy
Bram Moolenaar071d4272004-06-13 20:20:40 +0000830 int ml_flags;
831
zeertzjq82e079d2024-03-10 08:55:42 +0100832 colnr_T ml_line_len; // length of the cached line + NUL + text properties
833 colnr_T ml_line_textlen;// length of the cached line + NUL, 0 if not known yet
Bram Moolenaar6cb39f92019-07-04 16:05:14 +0200834 linenr_T ml_line_lnum; // line number of cached line, 0 if not valid
835 char_u *ml_line_ptr; // pointer to cached line
Bram Moolenaar071d4272004-06-13 20:20:40 +0000836
Bram Moolenaar6cb39f92019-07-04 16:05:14 +0200837 bhdr_T *ml_locked; // block used by last ml_get
838 linenr_T ml_locked_low; // first line in ml_locked
839 linenr_T ml_locked_high; // last line in ml_locked
840 int ml_locked_lineadd; // number of lines inserted in ml_locked
Bram Moolenaar071d4272004-06-13 20:20:40 +0000841#ifdef FEAT_BYTEOFF
842 chunksize_T *ml_chunksize;
843 int ml_numchunks;
844 int ml_usedchunks;
845#endif
846} memline_T;
847
Bram Moolenaara9d4b842020-05-30 14:46:52 +0200848// Values for the flags argument of ml_delete_flags().
849#define ML_DEL_MESSAGE 1 // may give a "No lines in buffer" message
850#define ML_DEL_UNDO 2 // called from undo, do not update textprops
Bram Moolenaar4cd5c522021-06-27 13:04:00 +0200851#define ML_DEL_NOPROP 4 // splitting data block, do not update textprops
Bram Moolenaara9d4b842020-05-30 14:46:52 +0200852
853// Values for the flags argument of ml_append_int().
854#define ML_APPEND_NEW 1 // starting to edit a new file
855#define ML_APPEND_MARK 2 // mark the new line
856#define ML_APPEND_UNDO 4 // called from undo
Bram Moolenaar840f91f2021-05-26 22:32:10 +0200857#define ML_APPEND_NOPROP 8 // do not continue textprop from previous line
Bram Moolenaara9d4b842020-05-30 14:46:52 +0200858
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100859
860/*
861 * Structure defining text properties. These stick with the text.
862 * When stored in memline they are after the text, ml_line_len is larger than
863 * STRLEN(ml_line_ptr) + 1.
864 */
865typedef struct textprop_S
866{
Bram Moolenaarb9c67a52019-01-01 19:49:20 +0100867 colnr_T tp_col; // start column (one based, in bytes)
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100868 colnr_T tp_len; // length in bytes, when tp_id is negative used
869 // for left padding plus one
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100870 int tp_id; // identifier
871 int tp_type; // property type
872 int tp_flags; // TP_FLAG_ values
Yegappan Lakshmanan171c5b92023-08-22 21:48:50 +0200873 int tp_padleft; // left padding between text line and virtual
874 // text
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100875} textprop_T;
876
Bram Moolenaar7f9969c2022-07-25 18:13:54 +0100877#define TP_FLAG_CONT_NEXT 0x1 // property continues in next line
878#define TP_FLAG_CONT_PREV 0x2 // property was continued from prev line
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100879
880// without these text is placed after the end of the line
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100881#define TP_FLAG_ALIGN_RIGHT 0x010 // virtual text is right-aligned
882#define TP_FLAG_ALIGN_ABOVE 0x020 // virtual text above the line
883#define TP_FLAG_ALIGN_BELOW 0x040 // virtual text on next screen line
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100884
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100885#define TP_FLAG_WRAP 0x080 // virtual text wraps - when missing
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100886 // text is truncated
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100887#define TP_FLAG_START_INCL 0x100 // "start_incl" copied from proptype
Bram Moolenaar28c9f892022-08-14 13:28:55 +0100888
dundargocc57b5bc2022-11-02 13:30:51 +0000889#define PROP_TEXT_MIN_CELLS 4 // minimum number of cells to use for
Bram Moolenaar398649e2022-08-04 15:03:48 +0100890 // the text, even when truncating
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100891
892/*
893 * Structure defining a property type.
894 */
895typedef struct proptype_S
896{
897 int pt_id; // value used for tp_id
898 int pt_type; // number used for tp_type
899 int pt_hl_id; // highlighting
900 int pt_priority; // priority
901 int pt_flags; // PT_FLAG_ values
902 char_u pt_name[1]; // property type name, actually longer
903} proptype_T;
904
905#define PT_FLAG_INS_START_INCL 1 // insert at start included in property
906#define PT_FLAG_INS_END_INCL 2 // insert at end included in property
Bram Moolenaarde24a872019-05-05 15:48:00 +0200907#define PT_FLAG_COMBINE 4 // combine with syntax highlight
Bram Moolenaarf4ba8bc2022-08-05 17:05:04 +0100908#define PT_FLAG_OVERRIDE 8 // override any highlight
Bram Moolenaar98aefe72018-12-13 22:20:09 +0100909
Bram Moolenaar7a2d9892018-12-24 20:23:49 +0100910// Sign group
911typedef struct signgroup_S
912{
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200913 int sg_next_sign_id; // next sign id for this group
914 short_u sg_refcount; // number of signs in this group
Bram Moolenaar47ed5532019-08-08 20:49:14 +0200915 char_u sg_name[1]; // sign group name, actually longer
Bram Moolenaar7a2d9892018-12-24 20:23:49 +0100916} signgroup_T;
917
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200918typedef struct sign_entry sign_entry_T;
919struct sign_entry
Bram Moolenaar071d4272004-06-13 20:20:40 +0000920{
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200921 int se_id; // unique identifier for each placed sign
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200922 int se_typenr; // typenr of sign
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200923 int se_priority; // priority for highlighting
Bram Moolenaard6beab02019-11-10 15:07:19 +0100924 linenr_T se_lnum; // line number which has this sign
925 signgroup_T *se_group; // sign group
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200926 sign_entry_T *se_next; // next entry in a list of signs
927 sign_entry_T *se_prev; // previous entry -- for easy reordering
Bram Moolenaar071d4272004-06-13 20:20:40 +0000928};
929
Bram Moolenaar4e038572019-07-04 18:28:35 +0200930/*
931 * Sign attributes. Used by the screen refresh routines.
932 */
933typedef struct sign_attrs_S {
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200934 int sat_typenr;
935 void *sat_icon;
936 char_u *sat_text;
937 int sat_texthl;
938 int sat_linehl;
Bram Moolenaare413ea02021-11-24 16:20:13 +0000939 int sat_culhl;
James McCoya80aad72021-12-22 19:45:28 +0000940 int sat_numhl;
Bram Moolenaar39f7aa32020-08-31 22:00:05 +0200941 int sat_priority;
Bram Moolenaar4e038572019-07-04 18:28:35 +0200942} sign_attrs_T;
943
Bram Moolenaarced198d2018-12-29 20:04:40 +0100944#if defined(FEAT_SIGNS) || defined(PROTO)
945// Macros to get the sign group structure from the group name
946#define SGN_KEY_OFF offsetof(signgroup_T, sg_name)
947#define HI2SG(hi) ((signgroup_T *)((hi)->hi_key - SGN_KEY_OFF))
948
Bram Moolenaar162b7142018-12-21 15:17:36 +0100949// Default sign priority for highlighting
950#define SIGN_DEF_PRIO 10
951
Bram Moolenaar071d4272004-06-13 20:20:40 +0000952#endif
953
954/*
955 * Argument list: Array of file names.
956 * Used for the global argument list and the argument lists local to a window.
957 */
958typedef struct arglist
959{
Bram Moolenaar6cb39f92019-07-04 16:05:14 +0200960 garray_T al_ga; // growarray with the array of file names
961 int al_refcount; // number of windows using this arglist
962 int id; // id of this arglist
Bram Moolenaar071d4272004-06-13 20:20:40 +0000963} alist_T;
964
965/*
966 * For each argument remember the file name as it was given, and the buffer
967 * number that contains the expanded file name (required for when ":cd" is
Bram Moolenaard6beab02019-11-10 15:07:19 +0100968 * used).
Bram Moolenaar071d4272004-06-13 20:20:40 +0000969 */
970typedef struct argentry
971{
Bram Moolenaar6cb39f92019-07-04 16:05:14 +0200972 char_u *ae_fname; // file name as specified
973 int ae_fnum; // buffer number with expanded file name
Bram Moolenaar071d4272004-06-13 20:20:40 +0000974} aentry_T;
975
Bram Moolenaar4033c552017-09-16 20:54:51 +0200976#define ALIST(win) (win)->w_alist
Bram Moolenaar071d4272004-06-13 20:20:40 +0000977#define GARGLIST ((aentry_T *)global_alist.al_ga.ga_data)
978#define ARGLIST ((aentry_T *)ALIST(curwin)->al_ga.ga_data)
979#define WARGLIST(wp) ((aentry_T *)ALIST(wp)->al_ga.ga_data)
980#define AARGLIST(al) ((aentry_T *)((al)->al_ga.ga_data))
981#define GARGCOUNT (global_alist.al_ga.ga_len)
982#define ARGCOUNT (ALIST(curwin)->al_ga.ga_len)
983#define WARGCOUNT(wp) (ALIST(wp)->al_ga.ga_len)
984
985/*
986 * A list used for saving values of "emsg_silent". Used by ex_try() to save the
987 * value of "emsg_silent" if it was non-zero. When this is done, the CSF_SILENT
988 * flag below is set.
989 */
990
991typedef struct eslist_elem eslist_T;
992struct eslist_elem
993{
Bram Moolenaar6cb39f92019-07-04 16:05:14 +0200994 int saved_emsg_silent; // saved value of "emsg_silent"
995 eslist_T *next; // next element on the list
Bram Moolenaar071d4272004-06-13 20:20:40 +0000996};
997
998/*
999 * For conditional commands a stack is kept of nested conditionals.
1000 * When cs_idx < 0, there is no conditional command.
1001 */
1002#define CSTACK_LEN 50
1003
Bram Moolenaarddef1292019-12-16 17:10:33 +01001004typedef struct {
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02001005 short cs_flags[CSTACK_LEN]; // CSF_ flags
1006 char cs_pending[CSTACK_LEN]; // CSTP_: what's pending in ":finally"
Bram Moolenaar071d4272004-06-13 20:20:40 +00001007 union {
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02001008 void *csp_rv[CSTACK_LEN]; // return typeval for pending return
1009 void *csp_ex[CSTACK_LEN]; // exception for pending throw
Bram Moolenaar071d4272004-06-13 20:20:40 +00001010 } cs_pend;
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02001011 void *cs_forinfo[CSTACK_LEN]; // info used by ":for"
1012 int cs_line[CSTACK_LEN]; // line nr of ":while"/":for" line
Bram Moolenaar8d739de2020-10-14 19:39:19 +02001013 int cs_block_id[CSTACK_LEN]; // block ID stack
Bram Moolenaarfcdc5d82020-10-10 19:07:09 +02001014 int cs_script_var_len[CSTACK_LEN]; // value of sn_var_vals.ga_len
1015 // when entering the block
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02001016 int cs_idx; // current entry, or -1 if none
1017 int cs_looplevel; // nr of nested ":while"s and ":for"s
1018 int cs_trylevel; // nr of nested ":try"s
1019 eslist_T *cs_emsg_silent_list; // saved values of "emsg_silent"
1020 char cs_lflags; // loop flags: CSL_ flags
Bram Moolenaarddef1292019-12-16 17:10:33 +01001021} cstack_T;
Bram Moolenaar12805862005-01-05 22:16:17 +00001022# define cs_rettv cs_pend.csp_rv
1023# define cs_exception cs_pend.csp_ex
Bram Moolenaar071d4272004-06-13 20:20:40 +00001024
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02001025// There is no CSF_IF, the lack of CSF_WHILE, CSF_FOR and CSF_TRY means ":if"
1026// was used.
1027# define CSF_TRUE 0x0001 // condition was TRUE
1028# define CSF_ACTIVE 0x0002 // current state is active
1029# define CSF_ELSE 0x0004 // ":else" has been passed
1030# define CSF_WHILE 0x0008 // is a ":while"
1031# define CSF_FOR 0x0010 // is a ":for"
Bram Moolenaar9becdf22020-10-10 21:33:48 +02001032# define CSF_BLOCK 0x0020 // is a "{" block
Bram Moolenaar12805862005-01-05 22:16:17 +00001033
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02001034# define CSF_TRY 0x0100 // is a ":try"
1035# define CSF_FINALLY 0x0200 // ":finally" has been passed
Bram Moolenaar41978282021-07-04 14:47:30 +02001036# define CSF_CATCH 0x0400 // ":catch" has been seen
1037# define CSF_THROWN 0x0800 // exception thrown to this try conditional
1038# define CSF_CAUGHT 0x1000 // exception caught by this try conditional
Bram Moolenaarf67d3fb2021-10-05 11:22:27 +01001039# define CSF_FINISHED 0x2000 // CSF_CAUGHT was handled by finish_exception()
1040# define CSF_SILENT 0x4000 // "emsg_silent" reset by ":try"
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02001041// Note that CSF_ELSE is only used when CSF_TRY and CSF_WHILE are unset
1042// (an ":if"), and CSF_SILENT is only used when CSF_TRY is set.
Bram Moolenaarf67d3fb2021-10-05 11:22:27 +01001043
1044# define CSF_FUNC_DEF 0x8000 // a function was defined in this block
Bram Moolenaar071d4272004-06-13 20:20:40 +00001045
1046/*
1047 * What's pending for being reactivated at the ":endtry" of this try
1048 * conditional:
1049 */
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02001050# define CSTP_NONE 0 // nothing pending in ":finally" clause
1051# define CSTP_ERROR 1 // an error is pending
1052# define CSTP_INTERRUPT 2 // an interrupt is pending
1053# define CSTP_THROW 4 // a throw is pending
1054# define CSTP_BREAK 8 // ":break" is pending
1055# define CSTP_CONTINUE 16 // ":continue" is pending
1056# define CSTP_RETURN 24 // ":return" is pending
1057# define CSTP_FINISH 32 // ":finish" is pending
Bram Moolenaar071d4272004-06-13 20:20:40 +00001058
1059/*
Bram Moolenaarddef1292019-12-16 17:10:33 +01001060 * Flags for the cs_lflags item in cstack_T.
Bram Moolenaar12805862005-01-05 22:16:17 +00001061 */
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02001062# define CSL_HAD_LOOP 1 // just found ":while" or ":for"
1063# define CSL_HAD_ENDLOOP 2 // just found ":endwhile" or ":endfor"
1064# define CSL_HAD_CONT 4 // just found ":continue"
1065# define CSL_HAD_FINA 8 // just found ":finally"
Bram Moolenaar12805862005-01-05 22:16:17 +00001066
1067/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00001068 * A list of error messages that can be converted to an exception. "throw_msg"
1069 * is only set in the first element of the list. Usually, it points to the
1070 * original message stored in that element, but sometimes it points to a later
Bram Moolenaar25e0f582020-05-25 22:36:50 +02001071 * message in the list. See cause_errthrow().
Bram Moolenaar071d4272004-06-13 20:20:40 +00001072 */
Bram Moolenaar25e0f582020-05-25 22:36:50 +02001073typedef struct msglist msglist_T;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001074struct msglist
1075{
Bram Moolenaare8c46602021-04-05 22:27:37 +02001076 msglist_T *next; // next of several messages in a row
Bram Moolenaar25e0f582020-05-25 22:36:50 +02001077 char *msg; // original message, allocated
1078 char *throw_msg; // msg to throw: usually original one
1079 char_u *sfile; // value from estack_sfile(), allocated
1080 long slnum; // line number for "sfile"
Bram Moolenaare8c46602021-04-05 22:27:37 +02001081 int msg_compiling; // saved value of estack_compiling
Bram Moolenaar071d4272004-06-13 20:20:40 +00001082};
1083
1084/*
Bram Moolenaar8a5883b2016-11-10 20:20:05 +01001085 * The exception types.
1086 */
1087typedef enum
1088{
Bram Moolenaarea3ece42018-04-17 20:14:39 +02001089 ET_USER, // exception caused by ":throw" command
1090 ET_ERROR, // error exception
1091 ET_INTERRUPT, // interrupt exception triggered by Ctrl-C
Bram Moolenaar8a5883b2016-11-10 20:20:05 +01001092} except_type_T;
1093
1094/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00001095 * Structure describing an exception.
1096 * (don't use "struct exception", it's used by the math library).
1097 */
1098typedef struct vim_exception except_T;
1099struct vim_exception
1100{
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02001101 except_type_T type; // exception type
1102 char *value; // exception value
1103 struct msglist *messages; // message(s) causing error exception
1104 char_u *throw_name; // name of the throw point
1105 linenr_T throw_lnum; // line number of the throw point
ichizok663d18d2025-01-02 18:06:00 +01001106 list_T *stacktrace; // stacktrace
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02001107 except_T *caught; // next exception on the caught stack
Bram Moolenaar071d4272004-06-13 20:20:40 +00001108};
1109
1110/*
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001111 * Structure to save the error/interrupt/exception state between calls to
1112 * enter_cleanup() and leave_cleanup(). Must be allocated as an automatic
1113 * variable by the (common) caller of these functions.
1114 */
1115typedef struct cleanup_stuff cleanup_T;
1116struct cleanup_stuff
1117{
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02001118 int pending; // error/interrupt/exception state
1119 except_T *exception; // exception value
Bram Moolenaarc0197e22004-09-13 20:26:32 +00001120};
Bram Moolenaar071d4272004-06-13 20:20:40 +00001121
Yegappan Lakshmananc59c1e02023-10-19 10:52:34 +02001122/*
1123 * Exception state that is saved and restored when calling timer callback
1124 * functions and deferred functions.
1125 */
1126typedef struct exception_state_S exception_state_T;
1127struct exception_state_S
1128{
1129 except_T *estate_current_exception;
1130 int estate_did_throw;
1131 int estate_need_rethrow;
1132 int estate_trylevel;
Yegappan Lakshmanan0ab500d2023-10-21 11:59:42 +02001133 int estate_did_emsg;
Yegappan Lakshmananc59c1e02023-10-19 10:52:34 +02001134};
1135
Bram Moolenaar071d4272004-06-13 20:20:40 +00001136#ifdef FEAT_SYN_HL
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02001137// struct passed to in_id_list()
Bram Moolenaar071d4272004-06-13 20:20:40 +00001138struct sp_syn
1139{
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02001140 int inc_tag; // ":syn include" unique tag
1141 short id; // highlight group ID of item
1142 short *cont_in_list; // cont.in group IDs, if non-zero
Bram Moolenaar071d4272004-06-13 20:20:40 +00001143};
1144
1145/*
1146 * Each keyword has one keyentry, which is linked in a hash list.
1147 */
1148typedef struct keyentry keyentry_T;
1149
1150struct keyentry
1151{
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02001152 keyentry_T *ke_next; // next entry with identical "keyword[]"
1153 struct sp_syn k_syn; // struct passed to in_id_list()
1154 short *next_list; // ID list for next match (if non-zero)
Bram Moolenaar860cae12010-06-05 23:22:07 +02001155 int flags;
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02001156 int k_char; // conceal substitute character
1157 char_u keyword[1]; // actually longer
Bram Moolenaar071d4272004-06-13 20:20:40 +00001158};
1159
1160/*
1161 * Struct used to store one state of the state stack.
1162 */
1163typedef struct buf_state
1164{
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02001165 int bs_idx; // index of pattern
1166 int bs_flags; // flags for pattern
Bram Moolenaar6e202e52010-07-28 18:14:45 +02001167#ifdef FEAT_CONCEAL
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02001168 int bs_seqnr; // stores si_seqnr
1169 int bs_cchar; // stores si_cchar
Bram Moolenaar6e202e52010-07-28 18:14:45 +02001170#endif
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02001171 reg_extmatch_T *bs_extmatch; // external matches from start pattern
Bram Moolenaar071d4272004-06-13 20:20:40 +00001172} bufstate_T;
1173
1174/*
1175 * syn_state contains the syntax state stack for the start of one line.
1176 * Used by b_sst_array[].
1177 */
1178typedef struct syn_state synstate_T;
1179
1180struct syn_state
1181{
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02001182 synstate_T *sst_next; // next entry in used or free list
1183 linenr_T sst_lnum; // line number for this state
Bram Moolenaar071d4272004-06-13 20:20:40 +00001184 union
1185 {
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02001186 bufstate_T sst_stack[SST_FIX_STATES]; // short state stack
1187 garray_T sst_ga; // growarray for long state stack
Bram Moolenaar071d4272004-06-13 20:20:40 +00001188 } sst_union;
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02001189 int sst_next_flags; // flags for sst_next_list
1190 int sst_stacksize; // number of states on the stack
1191 short *sst_next_list; // "nextgroup" list in this state
1192 // (this is a copy, don't free it!
1193 disptick_T sst_tick; // tick when last displayed
1194 linenr_T sst_change_lnum;// when non-zero, change in this line
1195 // may have made the state invalid
Bram Moolenaar071d4272004-06-13 20:20:40 +00001196};
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02001197#endif // FEAT_SYN_HL
Bram Moolenaar071d4272004-06-13 20:20:40 +00001198
Bram Moolenaarf9cc9f22019-07-14 21:29:22 +02001199#define MAX_HL_ID 20000 // maximum value for a highlight ID.
1200
1201/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00001202 * Structure shared between syntax.c, screen.c and gui_x11.c.
1203 */
1204typedef struct attr_entry
1205{
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02001206 short ae_attr; // HL_BOLD, etc.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001207 union
1208 {
1209 struct
1210 {
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02001211 char_u *start; // start escape sequence
1212 char_u *stop; // stop escape sequence
Bram Moolenaar071d4272004-06-13 20:20:40 +00001213 } term;
1214 struct
1215 {
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02001216 // These colors need to be > 8 bits to hold 256.
1217 short_u fg_color; // foreground color number
1218 short_u bg_color; // background color number
Bram Moolenaare023e882020-05-31 16:42:30 +02001219 short_u ul_color; // underline color number
PMuncha606f3a2023-11-15 15:35:49 +01001220 short_u font; // font number
Bram Moolenaar61be73b2016-04-29 22:59:22 +02001221# ifdef FEAT_TERMGUICOLORS
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02001222 guicolor_T fg_rgb; // foreground color RGB
1223 guicolor_T bg_rgb; // background color RGB
Bram Moolenaare023e882020-05-31 16:42:30 +02001224 guicolor_T ul_rgb; // underline color RGB
Bram Moolenaar8a633e32016-04-21 21:10:14 +02001225# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001226 } cterm;
1227# ifdef FEAT_GUI
1228 struct
1229 {
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02001230 guicolor_T fg_color; // foreground color handle
1231 guicolor_T bg_color; // background color handle
1232 guicolor_T sp_color; // special color handle
1233 GuiFont font; // font handle
Bram Moolenaar071d4272004-06-13 20:20:40 +00001234# ifdef FEAT_XFONTSET
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02001235 GuiFontset fontset; // fontset handle
Bram Moolenaar071d4272004-06-13 20:20:40 +00001236# endif
1237 } gui;
1238# endif
1239 } ae_u;
1240} attrentry_T;
1241
1242#ifdef USE_ICONV
1243# ifdef HAVE_ICONV_H
1244# include <iconv.h>
1245# else
1246# if defined(MACOS_X)
1247# include <sys/errno.h>
Bram Moolenaard0573012017-10-28 21:11:06 +02001248# ifndef EILSEQ
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02001249# define EILSEQ ENOENT // Early MacOS X does not have EILSEQ
Bram Moolenaard0573012017-10-28 21:11:06 +02001250# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001251typedef struct _iconv_t *iconv_t;
1252# else
Bram Moolenaard0573012017-10-28 21:11:06 +02001253# include <errno.h>
Bram Moolenaar071d4272004-06-13 20:20:40 +00001254# endif
1255typedef void *iconv_t;
1256# endif
1257#endif
1258
1259/*
1260 * Used for the typeahead buffer: typebuf.
1261 */
1262typedef struct
1263{
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02001264 char_u *tb_buf; // buffer for typed characters
1265 char_u *tb_noremap; // mapping flags for characters in tb_buf[]
1266 int tb_buflen; // size of tb_buf[]
1267 int tb_off; // current position in tb_buf[]
1268 int tb_len; // number of valid bytes in tb_buf[]
1269 int tb_maplen; // nr of mapped bytes in tb_buf[]
1270 int tb_silent; // nr of silently mapped bytes in tb_buf[]
1271 int tb_no_abbr_cnt; // nr of bytes without abbrev. in tb_buf[]
1272 int tb_change_cnt; // nr of time tb_buf was changed; never zero
Bram Moolenaar071d4272004-06-13 20:20:40 +00001273} typebuf_T;
1274
Bram Moolenaar9bf703d2019-11-30 19:44:38 +01001275// Struct to hold the saved typeahead for save_typeahead().
Bram Moolenaar071d4272004-06-13 20:20:40 +00001276typedef struct
1277{
1278 typebuf_T save_typebuf;
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02001279 int typebuf_valid; // TRUE when save_typebuf valid
Bram Moolenaar13df0fe2009-07-09 16:24:19 +00001280 int old_char;
1281 int old_mod_mask;
Bram Moolenaar0a36fec2014-02-11 15:10:43 +01001282 buffheader_T save_readbuf1;
1283 buffheader_T save_readbuf2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001284#ifdef USE_INPUT_BUF
1285 char_u *save_inputbuf;
1286#endif
1287} tasave_T;
1288
1289/*
1290 * Used for conversion of terminal I/O and script files.
1291 */
1292typedef struct
1293{
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02001294 int vc_type; // zero or one of the CONV_ values
1295 int vc_factor; // max. expansion factor
Bram Moolenaar4f974752019-02-17 17:44:42 +01001296# ifdef MSWIN
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02001297 int vc_cpfrom; // codepage to convert from (CONV_CODEPAGE)
1298 int vc_cpto; // codepage to convert to (CONV_CODEPAGE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001299# endif
1300# ifdef USE_ICONV
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02001301 iconv_t vc_fd; // for CONV_ICONV
Bram Moolenaar071d4272004-06-13 20:20:40 +00001302# endif
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02001303 int vc_fail; // fail for invalid char, don't use '?'
Bram Moolenaar071d4272004-06-13 20:20:40 +00001304} vimconv_T;
1305
1306/*
Bram Moolenaar5f32ece2019-07-21 21:51:59 +02001307 * Structure used for the command line history.
1308 */
1309typedef struct hist_entry
1310{
Bram Moolenaar4aea03e2019-09-25 22:37:17 +02001311 int hisnum; // identifying number
1312 int viminfo; // when TRUE hisstr comes from viminfo
1313 char_u *hisstr; // actual entry, separator char after the NUL
John Marriott8df07d02024-10-21 22:37:07 +02001314 size_t hisstrlen; // length of hisstr (excluding the NUL)
Bram Moolenaar4aea03e2019-09-25 22:37:17 +02001315 time_t time_set; // when it was typed, zero if unknown
Bram Moolenaar5f32ece2019-07-21 21:51:59 +02001316} histentry_T;
1317
Bram Moolenaar071d4272004-06-13 20:20:40 +00001318#define CONV_NONE 0
1319#define CONV_TO_UTF8 1
Bram Moolenaar3fdfa4a2004-10-07 21:02:47 +00001320#define CONV_9_TO_UTF8 2
1321#define CONV_TO_LATIN1 3
1322#define CONV_TO_LATIN9 4
1323#define CONV_ICONV 5
Bram Moolenaar4f974752019-02-17 17:44:42 +01001324#ifdef MSWIN
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02001325# define CONV_CODEPAGE 10 // codepage -> codepage
Bram Moolenaar071d4272004-06-13 20:20:40 +00001326#endif
1327#ifdef MACOS_X
Bram Moolenaar3fdfa4a2004-10-07 21:02:47 +00001328# define CONV_MAC_LATIN1 20
1329# define CONV_LATIN1_MAC 21
1330# define CONV_MAC_UTF8 22
1331# define CONV_UTF8_MAC 23
Bram Moolenaar071d4272004-06-13 20:20:40 +00001332#endif
1333
1334/*
1335 * Structure used for mappings and abbreviations.
1336 */
1337typedef struct mapblock mapblock_T;
1338struct mapblock
1339{
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02001340 mapblock_T *m_next; // next mapblock in list
zeertzjq9d997ad2024-07-29 21:10:07 +02001341 mapblock_T *m_alt; // pointer to mapblock of the same mapping
1342 // with an alternative form of m_keys, or NULL
1343 // if there is no such mapblock
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02001344 char_u *m_keys; // mapped from, lhs
1345 char_u *m_str; // mapped to, rhs
1346 char_u *m_orig_str; // rhs as entered by the user
1347 int m_keylen; // strlen(m_keys)
1348 int m_mode; // valid mode
Bram Moolenaar459fd782019-10-13 16:43:39 +02001349 int m_simplified; // m_keys was simplified, do not use this map
Bram Moolenaar47f1fdc2022-11-24 13:27:36 +00001350 // if key_protocol_enabled() returns TRUE
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02001351 int m_noremap; // if non-zero no re-mapping for m_str
1352 char m_silent; // <silent> used, don't echo commands
1353 char m_nowait; // <nowait> used
Bram Moolenaarae5bce12005-08-15 21:41:48 +00001354#ifdef FEAT_EVAL
Bram Moolenaar9b8d6222020-12-28 18:26:00 +01001355 char m_expr; // <expr> used, m_str is an expression
Dominique Pelle3276f582021-08-07 12:44:41 +02001356 sctx_T m_script_ctx; // SCTX where map was defined
Bram Moolenaar071d4272004-06-13 20:20:40 +00001357#endif
1358};
1359
Bram Moolenaar8133cc62020-10-26 21:05:27 +01001360
Bram Moolenaar071d4272004-06-13 20:20:40 +00001361/*
1362 * Used for highlighting in the status line.
1363 */
Bram Moolenaar8133cc62020-10-26 21:05:27 +01001364typedef struct
Bram Moolenaar071d4272004-06-13 20:20:40 +00001365{
1366 char_u *start;
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02001367 int userhl; // 0: no HL, 1-9: User HL, < 0 for syn ID
Bram Moolenaar8133cc62020-10-26 21:05:27 +01001368} stl_hlrec_T;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001369
Bram Moolenaar860cae12010-06-05 23:22:07 +02001370
1371/*
1372 * Syntax items - usually buffer-specific.
1373 */
1374
Bram Moolenaar9bf703d2019-11-30 19:44:38 +01001375/*
1376 * Item for a hashtable. "hi_key" can be one of three values:
Bram Moolenaardcaf10e2005-01-21 11:55:25 +00001377 * NULL: Never been used
1378 * HI_KEY_REMOVED: Entry was removed
1379 * Otherwise: Used item, pointer to the actual key; this usually is
1380 * inside the item, subtract an offset to locate the item.
1381 * This reduces the size of hashitem by 1/3.
1382 */
1383typedef struct hashitem_S
1384{
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02001385 long_u hi_hash; // cached hash number of hi_key
Bram Moolenaardcaf10e2005-01-21 11:55:25 +00001386 char_u *hi_key;
Bram Moolenaar8f999f12005-01-25 22:12:55 +00001387} hashitem_T;
Bram Moolenaardcaf10e2005-01-21 11:55:25 +00001388
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02001389// The address of "hash_removed" is used as a magic number for hi_key to
1390// indicate a removed item.
Bram Moolenaardcaf10e2005-01-21 11:55:25 +00001391#define HI_KEY_REMOVED &hash_removed
1392#define HASHITEM_EMPTY(hi) ((hi)->hi_key == NULL || (hi)->hi_key == &hash_removed)
1393
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02001394// Initial size for a hashtable. Our items are relatively small and growing
1395// is expensive, thus use 16 as a start. Must be a power of 2.
Bram Moolenaarac3150d2019-07-28 16:36:39 +02001396// This allows for storing 10 items (2/3 of 16) before a resize is needed.
Bram Moolenaardcaf10e2005-01-21 11:55:25 +00001397#define HT_INIT_SIZE 16
1398
Bram Moolenaaref2c3252022-11-25 16:31:51 +00001399// flags used for ht_flags
1400#define HTFLAGS_ERROR 0x01 // Set when growing failed, can't add more
1401 // items before growing works.
1402#define HTFLAGS_FROZEN 0x02 // Trying to add or remove an item will result
1403 // in an error message.
1404
Bram Moolenaardcaf10e2005-01-21 11:55:25 +00001405typedef struct hashtable_S
1406{
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02001407 long_u ht_mask; // mask used for hash value (nr of items in
1408 // array is "ht_mask" + 1)
1409 long_u ht_used; // number of items used
1410 long_u ht_filled; // number of items used + removed
Bram Moolenaar49fe0d62020-07-14 15:47:23 +02001411 int ht_changed; // incremented when adding or removing an item
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02001412 int ht_locked; // counter for hash_lock()
Bram Moolenaaref2c3252022-11-25 16:31:51 +00001413 int ht_flags; // HTFLAGS_ values
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02001414 hashitem_T *ht_array; // points to the array, allocated when it's
1415 // not "ht_smallarray"
1416 hashitem_T ht_smallarray[HT_INIT_SIZE]; // initial array
Bram Moolenaar8f999f12005-01-25 22:12:55 +00001417} hashtab_T;
1418
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02001419typedef long_u hash_T; // Type for hi_hash
Bram Moolenaar8f999f12005-01-25 22:12:55 +00001420
1421
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02001422// Use 64-bit Number.
Bram Moolenaar82f654e2020-02-17 22:12:50 +01001423#ifdef MSWIN
1424# ifdef PROTO
Bram Moolenaarf9706e92020-02-22 14:27:04 +01001425 // workaround for cproto that doesn't recognize __int64
1426 typedef long varnumber_T;
1427 typedef unsigned long uvarnumber_T;
1428# define VARNUM_MIN LONG_MIN
1429# define VARNUM_MAX LONG_MAX
1430# define UVARNUM_MAX ULONG_MAX
Bram Moolenaar82f654e2020-02-17 22:12:50 +01001431# else
Bram Moolenaarf9706e92020-02-22 14:27:04 +01001432 typedef __int64 varnumber_T;
1433 typedef unsigned __int64 uvarnumber_T;
1434# define VARNUM_MIN _I64_MIN
1435# define VARNUM_MAX _I64_MAX
1436# define UVARNUM_MAX _UI64_MAX
Bram Moolenaar22fcfad2016-07-01 18:17:26 +02001437# endif
Bram Moolenaarf9706e92020-02-22 14:27:04 +01001438#elif defined(HAVE_NO_LONG_LONG)
1439# if defined(HAVE_STDINT_H)
1440 typedef int64_t varnumber_T;
1441 typedef uint64_t uvarnumber_T;
1442# define VARNUM_MIN INT64_MIN
1443# define VARNUM_MAX INT64_MAX
1444# define UVARNUM_MAX UINT64_MAX
1445# else
1446 // this may cause trouble for code that depends on 64 bit ints
1447 typedef long varnumber_T;
1448 typedef unsigned long uvarnumber_T;
1449# define VARNUM_MIN LONG_MIN
1450# define VARNUM_MAX LONG_MAX
1451# define UVARNUM_MAX ULONG_MAX
1452# endif
Bram Moolenaar8f999f12005-01-25 22:12:55 +00001453#else
Bram Moolenaarf9706e92020-02-22 14:27:04 +01001454 typedef long long varnumber_T;
1455 typedef unsigned long long uvarnumber_T;
Bram Moolenaarc593bec2020-02-25 21:26:49 +01001456# ifdef LLONG_MIN
1457# define VARNUM_MIN LLONG_MIN
1458# define VARNUM_MAX LLONG_MAX
1459# define UVARNUM_MAX ULLONG_MAX
1460# else
1461# define VARNUM_MIN LONG_LONG_MIN
1462# define VARNUM_MAX LONG_LONG_MAX
1463# define UVARNUM_MAX ULONG_LONG_MAX
1464# endif
Bram Moolenaar8f999f12005-01-25 22:12:55 +00001465#endif
Bram Moolenaar22fcfad2016-07-01 18:17:26 +02001466
Bram Moolenaar3a97bb32019-06-01 13:28:35 +02001467// Struct that holds both a normal function name and a partial_T, as used for a
1468// callback argument.
1469// When used temporarily "cb_name" is not allocated. The refcounts to either
1470// the function or the partial are incremented and need to be decremented
1471// later with free_callback().
1472typedef struct {
1473 char_u *cb_name;
1474 partial_T *cb_partial;
1475 int cb_free_name; // cb_name was allocated
1476} callback_T;
1477
Bram Moolenaar20431c92020-03-20 18:39:46 +01001478typedef struct isn_S isn_T; // instruction
Bram Moolenaar8a7d6542020-01-26 15:56:19 +01001479typedef struct dfunc_S dfunc_T; // :def function
1480
Bram Moolenaar00b28d62022-12-08 15:32:33 +00001481typedef struct type_S type_T;
1482typedef struct ufunc_S ufunc_T;
1483
Bram Moolenaar835dc632016-02-07 14:27:38 +01001484typedef struct jobvar_S job_T;
Bram Moolenaar6463ca22016-02-13 17:04:46 +01001485typedef struct readq_S readq_T;
Bram Moolenaar97bd5e62017-08-18 20:50:30 +02001486typedef struct writeq_S writeq_T;
Bram Moolenaar6463ca22016-02-13 17:04:46 +01001487typedef struct jsonq_S jsonq_T;
1488typedef struct cbq_S cbq_T;
1489typedef struct channel_S channel_T;
Bram Moolenaar8a7d6542020-01-26 15:56:19 +01001490typedef struct cctx_S cctx_T;
Bram Moolenaarcd45ed02020-12-22 17:35:54 +01001491typedef struct ectx_S ectx_T;
Bram Moolenaarf18332f2021-05-07 17:55:55 +02001492typedef struct instr_S instr_T;
Bram Moolenaar00b28d62022-12-08 15:32:33 +00001493typedef struct class_S class_T;
1494typedef struct object_S object_T;
Yegappan Lakshmananec3cebb2023-10-27 19:35:26 +02001495typedef struct typealias_S typealias_T;
Bram Moolenaar8f999f12005-01-25 22:12:55 +00001496
Bram Moolenaara03f2332016-02-06 18:09:59 +01001497typedef enum
1498{
Bram Moolenaar4c683752020-04-05 21:38:23 +02001499 VAR_UNKNOWN = 0, // not set, any type or "void" allowed
1500 VAR_ANY, // used for "any" type
1501 VAR_VOID, // no value (function not returning anything)
Bram Moolenaar8a7d6542020-01-26 15:56:19 +01001502 VAR_BOOL, // "v_number" is used: VVAL_TRUE or VVAL_FALSE
1503 VAR_SPECIAL, // "v_number" is used: VVAL_NULL or VVAL_NONE
1504 VAR_NUMBER, // "v_number" is used
1505 VAR_FLOAT, // "v_float" is used
1506 VAR_STRING, // "v_string" is used
1507 VAR_BLOB, // "v_blob" is used
1508 VAR_FUNC, // "v_string" is function name
1509 VAR_PARTIAL, // "v_partial" is used
1510 VAR_LIST, // "v_list" is used
1511 VAR_DICT, // "v_dict" is used
1512 VAR_JOB, // "v_job" is used
1513 VAR_CHANNEL, // "v_channel" is used
Bram Moolenaarf18332f2021-05-07 17:55:55 +02001514 VAR_INSTR, // "v_instr" is used
Bram Moolenaar5bcd29b2023-01-05 20:14:43 +00001515 VAR_CLASS, // "v_class" is used (also used for interface)
Bram Moolenaar00b28d62022-12-08 15:32:33 +00001516 VAR_OBJECT, // "v_object" is used
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01001517 VAR_TYPEALIAS, // "v_typealias" is used
1518 VAR_TUPLE // "v_tuple" is used
Bram Moolenaara03f2332016-02-06 18:09:59 +01001519} vartype_T;
1520
Bram Moolenaar8a7d6542020-01-26 15:56:19 +01001521// A type specification.
Bram Moolenaar8a7d6542020-01-26 15:56:19 +01001522struct type_S {
1523 vartype_T tt_type;
Bram Moolenaar1378fbc2020-04-11 20:50:33 +02001524 int8_T tt_argcount; // for func, incl. vararg, -1 for unknown
James McCoy2e258bd2021-10-05 19:44:04 +01001525 int8_T tt_min_argcount; // number of non-optional arguments
1526 char_u tt_flags; // TTFLAG_ values
Bram Moolenaar8a7d6542020-01-26 15:56:19 +01001527 type_T *tt_member; // for list, dict, func return type
Bram Moolenaarb1e32ac2023-02-21 12:38:51 +00001528 class_T *tt_class; // for class and object
Bram Moolenaar5deeb3f2020-04-05 17:08:17 +02001529 type_T **tt_args; // func argument types, allocated
Bram Moolenaar8a7d6542020-01-26 15:56:19 +01001530};
1531
Bram Moolenaar078a4612022-01-04 15:17:03 +00001532typedef struct {
1533 type_T *type_curr; // current type, value type
1534 type_T *type_decl; // declared type or equal to type_current
1535} type2_T;
1536
Bram Moolenaarc6951a72022-12-29 20:56:24 +00001537#define TTFLAG_VARARGS 0x01 // func args ends with "..."
1538#define TTFLAG_BOOL_OK 0x02 // can be converted to bool
Bram Moolenaar47bba532023-01-20 18:49:46 +00001539#define TTFLAG_FLOAT_OK 0x04 // number can be used/converted to float
1540#define TTFLAG_NUMBER_OK 0x08 // number can be used for a float
1541#define TTFLAG_STATIC 0x10 // one of the static types, e.g. t_any
1542#define TTFLAG_CONST 0x20 // cannot be changed
1543#define TTFLAG_SUPER 0x40 // object from "super".
Bram Moolenaarc6951a72022-12-29 20:56:24 +00001544
Bram Moolenaar3d473ee2022-12-14 20:59:32 +00001545typedef enum {
Yegappan Lakshmanancd7293b2023-08-27 19:18:23 +02001546 VIM_ACCESS_PRIVATE, // read/write only inside the class
1547 VIM_ACCESS_READ, // read everywhere, write only inside the class
=?UTF-8?q?Ola=20S=C3=B6der?=d8742472023-03-05 13:12:32 +00001548 VIM_ACCESS_ALL // read/write everywhere
Bram Moolenaar3d473ee2022-12-14 20:59:32 +00001549} omacc_T;
1550
Yegappan Lakshmanane5437c52023-12-16 14:11:19 +01001551#define OCMFLAG_HAS_TYPE 0x01 // type specified explicitly
1552#define OCMFLAG_FINAL 0x02 // "final" object/class member
1553#define OCMFLAG_CONST 0x04 // "const" object/class member
1554
Bram Moolenaar00b28d62022-12-08 15:32:33 +00001555/*
Yegappan Lakshmanand3eae7b2024-03-03 16:26:58 +01001556 * Object methods called by builtin functions (e.g. string(), empty(), etc.)
1557 */
1558typedef enum {
1559 CLASS_BUILTIN_INVALID,
1560 CLASS_BUILTIN_STRING,
1561 CLASS_BUILTIN_EMPTY,
1562 CLASS_BUILTIN_LEN,
1563 CLASS_BUILTIN_MAX
1564} class_builtin_T;
1565
1566/*
Bram Moolenaard505d172022-12-18 21:42:55 +00001567 * Entry for an object or class member variable.
Bram Moolenaar00b28d62022-12-08 15:32:33 +00001568 */
1569typedef struct {
Yegappan Lakshmananfe7b20a2023-10-04 19:47:52 +02001570 char_u *ocm_name; // allocated
Bram Moolenaard505d172022-12-18 21:42:55 +00001571 omacc_T ocm_access;
1572 type_T *ocm_type;
Yegappan Lakshmanane5437c52023-12-16 14:11:19 +01001573 int ocm_flags;
Yegappan Lakshmananfe7b20a2023-10-04 19:47:52 +02001574 char_u *ocm_init; // allocated
Yegappan Lakshmanan16f2d3a2025-02-24 19:23:43 +01001575 sctx_T ocm_init_sctx; // script context of the initializer expression
Bram Moolenaard505d172022-12-18 21:42:55 +00001576} ocmember_T;
Bram Moolenaar00b28d62022-12-08 15:32:33 +00001577
Bram Moolenaard0200c82023-01-28 15:19:40 +00001578// used for the lookup table of a class member index and object method index
Bram Moolenaar29ac5df2023-01-16 19:43:47 +00001579typedef struct itf2class_S itf2class_T;
1580struct itf2class_S {
1581 itf2class_T *i2c_next;
1582 class_T *i2c_class;
Bram Moolenaard0200c82023-01-28 15:19:40 +00001583 int i2c_is_method; // TRUE for method indexes
Bram Moolenaar29ac5df2023-01-16 19:43:47 +00001584 // array with ints follows
1585};
1586
Yegappan Lakshmanan3164cf82024-03-28 10:36:42 +01001587#define CLASS_INTERFACE 0x1
1588#define CLASS_EXTENDED 0x2 // another class extends this one
1589#define CLASS_ABSTRACT 0x4 // abstract class
1590#define CLASS_ENUM 0x8 // enum
Bram Moolenaar5bcd29b2023-01-05 20:14:43 +00001591
Bram Moolenaar00b28d62022-12-08 15:32:33 +00001592// "class_T": used for v_class of typval of VAR_CLASS
Bram Moolenaar5bcd29b2023-01-05 20:14:43 +00001593// Also used for an interface (class_flags has CLASS_INTERFACE).
Bram Moolenaar00b28d62022-12-08 15:32:33 +00001594struct class_S
1595{
1596 char_u *class_name; // allocated
Bram Moolenaar5bcd29b2023-01-05 20:14:43 +00001597 int class_flags; // CLASS_ flags
1598
Bram Moolenaar00b28d62022-12-08 15:32:33 +00001599 int class_refcount;
Bram Moolenaarcf760d52023-01-05 13:16:04 +00001600 int class_copyID; // used by garbage collection
Yegappan Lakshmanane651e112023-09-04 07:51:01 +02001601 class_T *class_next_used; // for list headed by "first_class"
1602 class_T *class_prev_used; // for list headed by "first_class"
Bram Moolenaar00b28d62022-12-08 15:32:33 +00001603
Bram Moolenaar83677162023-01-08 19:54:10 +00001604 class_T *class_extends; // parent class or NULL
1605
Bram Moolenaar94674f22023-01-06 18:42:20 +00001606 // interfaces declared for the class
1607 int class_interface_count;
1608 char_u **class_interfaces; // allocated array of names
Bram Moolenaara94bd9d2023-01-12 15:01:32 +00001609 class_T **class_interfaces_cl; // interfaces (counts as reference)
Bram Moolenaar29ac5df2023-01-16 19:43:47 +00001610 itf2class_T *class_itf2class; // member index lookup tables
Bram Moolenaar94674f22023-01-06 18:42:20 +00001611
Bram Moolenaard505d172022-12-18 21:42:55 +00001612 // class members: "static varname"
1613 int class_class_member_count;
1614 ocmember_T *class_class_members; // allocated
1615 typval_T *class_members_tv; // allocated array of class member vals
Bram Moolenaar00b28d62022-12-08 15:32:33 +00001616
Bram Moolenaar6bafdd42023-01-01 12:58:33 +00001617 // class functions: "static def SomeMethod()"
Bram Moolenaar58b40092023-01-11 15:59:05 +00001618 int class_class_function_count; // total count
1619 int class_class_function_count_child; // count without "extends"
Bram Moolenaar6bafdd42023-01-01 12:58:33 +00001620 ufunc_T **class_class_functions; // allocated
Bram Moolenaard505d172022-12-18 21:42:55 +00001621
1622 // object members: "this.varname"
1623 int class_obj_member_count;
1624 ocmember_T *class_obj_members; // allocated
1625
1626 // object methods: "def SomeMethod()"
Bram Moolenaar58b40092023-01-11 15:59:05 +00001627 int class_obj_method_count; // total count
1628 int class_obj_method_count_child; // count without "extends"
Bram Moolenaar00b28d62022-12-08 15:32:33 +00001629 ufunc_T **class_obj_methods; // allocated
Bram Moolenaar00b28d62022-12-08 15:32:33 +00001630
Yegappan Lakshmanand3eae7b2024-03-03 16:26:58 +01001631 // index of builtin methods
1632 int class_builtin_methods[CLASS_BUILTIN_MAX];
1633
Bram Moolenaar00b28d62022-12-08 15:32:33 +00001634 garray_T class_type_list; // used for type pointers
Bram Moolenaard505d172022-12-18 21:42:55 +00001635 type_T class_type; // type used for the class
Bram Moolenaarffdaca92022-12-09 21:41:48 +00001636 type_T class_object_type; // same as class_type but VAR_OBJECT
Bram Moolenaar00b28d62022-12-08 15:32:33 +00001637};
1638
Yegappan Lakshmanan3164cf82024-03-28 10:36:42 +01001639#define IS_INTERFACE(cl) ((cl)->class_flags & CLASS_INTERFACE)
1640#define IS_ENUM(cl) ((cl)->class_flags & CLASS_ENUM)
1641
Bram Moolenaar00b28d62022-12-08 15:32:33 +00001642// Used for v_object of typval of VAR_OBJECT.
1643// The member variables follow in an array of typval_T.
Bram Moolenaarffdaca92022-12-09 21:41:48 +00001644struct object_S
1645{
Bram Moolenaard28d7b92022-12-08 20:42:00 +00001646 class_T *obj_class; // class this object is created for;
1647 // pointer adds to class_refcount
Bram Moolenaar00b28d62022-12-08 15:32:33 +00001648 int obj_refcount;
Bram Moolenaard28d7b92022-12-08 20:42:00 +00001649
1650 object_T *obj_next_used; // for list headed by "first_object"
1651 object_T *obj_prev_used; // for list headed by "first_object"
1652 int obj_copyID; // used by garbage collection
Bram Moolenaar00b28d62022-12-08 15:32:33 +00001653};
1654
Yegappan Lakshmananec3cebb2023-10-27 19:35:26 +02001655struct typealias_S
1656{
1657 int ta_refcount;
1658 type_T *ta_type;
1659 char_u *ta_name;
1660};
1661
Bram Moolenaar8f999f12005-01-25 22:12:55 +00001662/*
1663 * Structure to hold an internal variable without a name.
1664 */
Bram Moolenaard505d172022-12-18 21:42:55 +00001665struct typval_S
Bram Moolenaar8f999f12005-01-25 22:12:55 +00001666{
Bram Moolenaara03f2332016-02-06 18:09:59 +01001667 vartype_T v_type;
Bram Moolenaar2bb26582020-10-03 22:52:39 +02001668 char v_lock; // see below: VAR_LOCKED, VAR_FIXED
Bram Moolenaar8f999f12005-01-25 22:12:55 +00001669 union
1670 {
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02001671 varnumber_T v_number; // number value
Bram Moolenaar00b28d62022-12-08 15:32:33 +00001672 float_T v_float; // floating point number value
1673 char_u *v_string; // string value (can be NULL)
1674 list_T *v_list; // list value (can be NULL)
1675 dict_T *v_dict; // dict value (can be NULL)
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02001676 partial_T *v_partial; // closure: function with args
Bram Moolenaar509ce2a2016-03-11 22:52:15 +01001677#ifdef FEAT_JOB_CHANNEL
Bram Moolenaar00b28d62022-12-08 15:32:33 +00001678 job_T *v_job; // job value (can be NULL)
1679 channel_T *v_channel; // channel value (can be NULL)
Bram Moolenaar77073442016-02-13 23:23:53 +01001680#endif
Bram Moolenaar00b28d62022-12-08 15:32:33 +00001681 blob_T *v_blob; // blob value (can be NULL)
Bram Moolenaarf18332f2021-05-07 17:55:55 +02001682 instr_T *v_instr; // instructions to execute
Bram Moolenaar00b28d62022-12-08 15:32:33 +00001683 class_T *v_class; // class value (can be NULL)
1684 object_T *v_object; // object value (can be NULL)
Yegappan Lakshmananec3cebb2023-10-27 19:35:26 +02001685 typealias_T *v_typealias; // user-defined type name
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01001686 tuple_T *v_tuple; // tuple
Bram Moolenaar8f999f12005-01-25 22:12:55 +00001687 } vval;
Bram Moolenaard505d172022-12-18 21:42:55 +00001688};
Bram Moolenaar8f999f12005-01-25 22:12:55 +00001689
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02001690// Values for "dv_scope".
1691#define VAR_SCOPE 1 // a:, v:, s:, etc. scope dictionaries
1692#define VAR_DEF_SCOPE 2 // l:, g: scope dictionaries: here funcrefs are not
1693 // allowed to mask existing functions
Bram Moolenaarbdb62052012-07-16 17:31:53 +02001694
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02001695// Values for "v_lock".
Bram Moolenaar70c43d82022-01-26 21:01:15 +00001696#define VAR_LOCKED 1 // locked with lock(), can use unlock()
1697#define VAR_FIXED 2 // locked forever
1698#define VAR_ITEMS_LOCKED 4 // items of non-materialized list locked
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00001699
Bram Moolenaar8f999f12005-01-25 22:12:55 +00001700/*
1701 * Structure to hold an item of a list: an internal variable without a name.
1702 */
1703typedef struct listitem_S listitem_T;
1704
1705struct listitem_S
1706{
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02001707 listitem_T *li_next; // next item in list
1708 listitem_T *li_prev; // previous item in list
1709 typval_T li_tv; // type and value of the variable
Bram Moolenaar8f999f12005-01-25 22:12:55 +00001710};
1711
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02001712// Struct used by those that are using an item in a list.
Bram Moolenaar8f999f12005-01-25 22:12:55 +00001713typedef struct listwatch_S listwatch_T;
1714
1715struct listwatch_S
1716{
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02001717 listitem_T *lw_item; // item being watched
1718 listwatch_T *lw_next; // next watcher
Bram Moolenaar8f999f12005-01-25 22:12:55 +00001719};
1720
1721/*
1722 * Structure to hold info about a list.
Bram Moolenaar1a840242018-03-08 21:46:43 +01001723 * Order of members is optimized to reduce padding.
Bram Moolenaar8a7d6542020-01-26 15:56:19 +01001724 * When created by range() it will at first have special value:
1725 * lv_first == &range_list_item;
1726 * and use lv_start, lv_end, lv_stride.
Bram Moolenaar8f999f12005-01-25 22:12:55 +00001727 */
1728struct listvar_S
1729{
Bram Moolenaar70c43d82022-01-26 21:01:15 +00001730 listitem_T *lv_first; // first item, NULL if none, &range_list_item
1731 // for a non-materialized list
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02001732 listwatch_T *lv_watch; // first watcher, NULL if none
Bram Moolenaar8a7d6542020-01-26 15:56:19 +01001733 union {
1734 struct { // used for non-materialized range list:
1735 // "lv_first" is &range_list_item
1736 varnumber_T lv_start;
1737 varnumber_T lv_end;
1738 int lv_stride;
Bram Moolenaar0ff6aad2020-01-29 21:27:21 +01001739 } nonmat;
Bram Moolenaar8a7d6542020-01-26 15:56:19 +01001740 struct { // used for materialized list
1741 listitem_T *lv_last; // last item, NULL if none
1742 listitem_T *lv_idx_item; // when not NULL item at index "lv_idx"
1743 int lv_idx; // cached index of an item
Bram Moolenaar0ff6aad2020-01-29 21:27:21 +01001744 } mat;
1745 } lv_u;
Bram Moolenaar078a4612022-01-04 15:17:03 +00001746 type_T *lv_type; // current type, allocated by alloc_type()
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02001747 list_T *lv_copylist; // copied list used by deepcopy()
1748 list_T *lv_used_next; // next list in used lists list
1749 list_T *lv_used_prev; // previous list in used lists list
1750 int lv_refcount; // reference count
1751 int lv_len; // number of items
Bram Moolenaar8a7d6542020-01-26 15:56:19 +01001752 int lv_with_items; // number of items following this struct that
1753 // should not be freed
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02001754 int lv_copyID; // ID used by deepcopy()
1755 char lv_lock; // zero, VAR_LOCKED, VAR_FIXED
Bram Moolenaar8f999f12005-01-25 22:12:55 +00001756};
1757
1758/*
Bram Moolenaardf48fb42016-07-22 21:50:18 +02001759 * Static list with 10 items. Use init_static_list() to initialize.
1760 */
1761typedef struct {
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02001762 list_T sl_list; // must be first
Bram Moolenaardf48fb42016-07-22 21:50:18 +02001763 listitem_T sl_items[10];
1764} staticList10_T;
1765
1766/*
Bram Moolenaar8f999f12005-01-25 22:12:55 +00001767 * Structure to hold an item of a Dictionary.
1768 * Also used for a variable.
1769 * The key is copied into "di_key" to avoid an extra alloc/free for it.
1770 */
1771struct dictitem_S
1772{
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02001773 typval_T di_tv; // type and value of the variable
Bram Moolenaar8a7d6542020-01-26 15:56:19 +01001774 char_u di_flags; // DI_FLAGS_ flags (only used for variable)
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02001775 char_u di_key[1]; // key (actually longer!)
Bram Moolenaar8f999f12005-01-25 22:12:55 +00001776};
Bram Moolenaar8f999f12005-01-25 22:12:55 +00001777typedef struct dictitem_S dictitem_T;
1778
Bram Moolenaard7c96872019-06-15 17:12:48 +02001779/*
1780 * A dictitem with a 16 character key (plus NUL). This is an efficient way to
1781 * have a fixed-size dictitem.
1782 */
1783#define DICTITEM16_KEY_LEN 16
Bram Moolenaarbee6c0c2016-03-25 15:40:50 +01001784struct dictitem16_S
1785{
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02001786 typval_T di_tv; // type and value of the variable
Bram Moolenaar8a7d6542020-01-26 15:56:19 +01001787 char_u di_flags; // DI_FLAGS_ flags (only used for variable)
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02001788 char_u di_key[DICTITEM16_KEY_LEN + 1]; // key
Bram Moolenaarbee6c0c2016-03-25 15:40:50 +01001789};
1790typedef struct dictitem16_S dictitem16_T;
1791
Bram Moolenaar8a7d6542020-01-26 15:56:19 +01001792// Flags for "di_flags"
1793#define DI_FLAGS_RO 0x01 // read-only variable
1794#define DI_FLAGS_RO_SBX 0x02 // read-only in the sandbox
1795#define DI_FLAGS_FIX 0x04 // fixed: no :unlet or remove()
1796#define DI_FLAGS_LOCK 0x08 // locked variable
1797#define DI_FLAGS_ALLOC 0x10 // separately allocated
1798#define DI_FLAGS_RELOAD 0x20 // set when script sourced again
Bram Moolenaar8f999f12005-01-25 22:12:55 +00001799
1800/*
1801 * Structure to hold info about a Dictionary.
1802 */
1803struct dictvar_S
1804{
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02001805 char dv_lock; // zero, VAR_LOCKED, VAR_FIXED
1806 char dv_scope; // zero, VAR_SCOPE, VAR_DEF_SCOPE
1807 int dv_refcount; // reference count
1808 int dv_copyID; // ID used by deepcopy()
1809 hashtab_T dv_hashtab; // hashtab that refers to the items
Bram Moolenaar078a4612022-01-04 15:17:03 +00001810 type_T *dv_type; // current type, allocated by alloc_type()
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02001811 dict_T *dv_copydict; // copied dict used by deepcopy()
1812 dict_T *dv_used_next; // next dict in used dicts list
1813 dict_T *dv_used_prev; // previous dict in used dicts list
Bram Moolenaar8f999f12005-01-25 22:12:55 +00001814};
1815
Bram Moolenaar6e5ea8d2019-01-12 22:47:31 +01001816/*
1817 * Structure to hold info about a blob.
1818 */
1819struct blobvar_S
1820{
1821 garray_T bv_ga; // growarray with the data
1822 int bv_refcount; // reference count
1823 char bv_lock; // zero, VAR_LOCKED, VAR_FIXED
1824};
1825
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01001826/*
1827 * Structure to hold info about a tuple.
1828 */
1829struct tuplevar_S
1830{
1831 garray_T tv_items; // tuple items
1832 type_T *tv_type; // current type, allocated by alloc_type()
1833 tuple_T *tv_copytuple; // copied tuple used by deepcopy()
1834 tuple_T *tv_used_next; // next tuple in used tuples list
1835 tuple_T *tv_used_prev; // previous tuple in used tuples list
1836 int tv_refcount; // reference count
1837 int tv_copyID; // ID used by deepcopy()
1838 char tv_lock; // zero, VAR_LOCKED, VAR_FIXED
1839};
1840
Bram Moolenaar801ab062020-06-25 19:27:56 +02001841typedef int (*cfunc_T)(int argcount, typval_T *argvars, typval_T *rettv, void *state);
1842typedef void (*cfunc_free_T)(void *state);
1843
Bram Moolenaar20b23c62020-08-20 15:25:00 +02001844// type of getline() last argument
1845typedef enum {
1846 GETLINE_NONE, // do not concatenate any lines
Bram Moolenaar8242ebb2020-12-29 11:15:01 +01001847 GETLINE_CONCAT_CONT, // concatenate continuation lines with backslash
1848 GETLINE_CONCAT_CONTBAR, // concatenate continuation lines with \ and |
Bram Moolenaar20b23c62020-08-20 15:25:00 +02001849 GETLINE_CONCAT_ALL // concatenate continuation and Vim9 # comment lines
1850} getline_opt_T;
1851
Bram Moolenaar9b8d6222020-12-28 18:26:00 +01001852typedef struct svar_S svar_T;
1853
Bram Moolenaar437bafe2016-08-01 15:40:54 +02001854#if defined(FEAT_EVAL) || defined(PROTO)
Bram Moolenaar766ae5b2022-09-14 00:30:51 +01001855/*
1856 * Info used by a ":for" loop.
1857 */
1858typedef struct
1859{
1860 int fi_semicolon; // TRUE if ending in '; var]'
Bram Moolenaare8e369a2022-09-21 18:59:14 +01001861 int fi_varcount; // nr of variables in [] or zero
Bram Moolenaar766ae5b2022-09-14 00:30:51 +01001862 int fi_break_count; // nr of line breaks encountered
1863 listwatch_T fi_lw; // keep an eye on the item used.
1864 list_T *fi_list; // list being used
1865 int fi_bi; // index of blob
1866 blob_T *fi_blob; // blob being used
1867 char_u *fi_string; // copy of string being used
1868 int fi_byte_idx; // byte index in fi_string
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01001869 tuple_T *fi_tuple; // tuple being used
1870 int fi_tuple_idx; // tuple index in fi_tuple
Bram Moolenaar766ae5b2022-09-14 00:30:51 +01001871 int fi_cs_flags; // cs_flags or'ed together
1872} forinfo_T;
1873
Bram Moolenaar437bafe2016-08-01 15:40:54 +02001874typedef struct funccall_S funccall_T;
1875
Bram Moolenaarb2049902021-01-24 12:53:53 +01001876// values used for "uf_def_status"
Bram Moolenaar0cb5bcf2020-06-20 18:19:09 +02001877typedef enum {
Bram Moolenaar701cc6c2021-04-10 13:33:48 +02001878 UF_NOT_COMPILED, // executed with interpreter
1879 UF_TO_BE_COMPILED, // to be compiled before execution
1880 UF_COMPILING, // in compile_def_function()
1881 UF_COMPILED, // successfully compiled
1882 UF_COMPILE_ERROR // compilation error, cannot execute
Bram Moolenaar0cb5bcf2020-06-20 18:19:09 +02001883} def_status_T;
Bram Moolenaar822ba242020-05-24 23:00:18 +02001884
Bram Moolenaar437bafe2016-08-01 15:40:54 +02001885/*
1886 * Structure to hold info for a user function.
Bram Moolenaar8fa745e2022-09-16 19:04:24 +01001887 * When adding a field check copy_lambda_to_global_func().
Bram Moolenaar437bafe2016-08-01 15:40:54 +02001888 */
Bram Moolenaar00b28d62022-12-08 15:32:33 +00001889struct ufunc_S
Bram Moolenaar437bafe2016-08-01 15:40:54 +02001890{
Bram Moolenaar8a7d6542020-01-26 15:56:19 +01001891 int uf_varargs; // variable nr of arguments (old style)
1892 int uf_flags; // FC_ flags
Bram Moolenaar42ae78c2019-05-09 21:08:58 +02001893 int uf_calls; // nr of active calls
1894 int uf_cleared; // func_clear() was already called
Bram Moolenaar0cb5bcf2020-06-20 18:19:09 +02001895 def_status_T uf_def_status; // UF_NOT_COMPILED, UF_TO_BE_COMPILED, etc.
1896 int uf_dfunc_idx; // only valid if uf_def_status is UF_COMPILED
Bram Moolenaar00b28d62022-12-08 15:32:33 +00001897
Yegappan Lakshmananc30a90d2023-09-15 20:14:55 +02001898 class_T *uf_class; // for class/object method and constructor;
1899 // does not count for class_refcount.
1900 // class of the object which is invoking this
1901 // function.
1902 class_T *uf_defclass; // class where this function is defined.
Bram Moolenaar00b28d62022-12-08 15:32:33 +00001903
Bram Moolenaar5deeb3f2020-04-05 17:08:17 +02001904 garray_T uf_args; // arguments, including optional arguments
Bram Moolenaar42ae78c2019-05-09 21:08:58 +02001905 garray_T uf_def_args; // default argument expressions
Bram Moolenaare28d9b32021-07-03 18:56:53 +02001906 int uf_args_visible; // normally uf_args.ga_len, less when
1907 // compiling default argument expression.
Bram Moolenaar8a7d6542020-01-26 15:56:19 +01001908
1909 // for :def (for :function uf_ret_type is NULL)
1910 type_T **uf_arg_types; // argument types (count == uf_args.ga_len)
1911 type_T *uf_ret_type; // return type
1912 garray_T uf_type_list; // types used in arg and return types
Bram Moolenaarf112f302020-12-20 17:47:52 +01001913 partial_T *uf_partial; // for closure created inside :def function:
1914 // information about the context
1915
Bram Moolenaar8a7d6542020-01-26 15:56:19 +01001916 char_u *uf_va_name; // name from "...name" or NULL
1917 type_T *uf_va_type; // type from "...name: type" or NULL
Bram Moolenaar5deeb3f2020-04-05 17:08:17 +02001918 type_T *uf_func_type; // type of the function, &t_func_any if unknown
Bram Moolenaarfbbcd002020-10-15 12:46:44 +02001919 int uf_block_depth; // nr of entries in uf_block_ids
1920 int *uf_block_ids; // blocks a :def function is defined inside
Bram Moolenaar801ab062020-06-25 19:27:56 +02001921# if defined(FEAT_LUA)
1922 cfunc_T uf_cb; // callback function for cfunc
1923 cfunc_free_T uf_cb_free; // callback function to free cfunc
Bram Moolenaar6ed545e2022-05-09 20:09:23 +01001924 void *uf_cb_state; // state of uf_cb
Bram Moolenaar801ab062020-06-25 19:27:56 +02001925# endif
Bram Moolenaar8a7d6542020-01-26 15:56:19 +01001926
Bram Moolenaar42ae78c2019-05-09 21:08:58 +02001927 garray_T uf_lines; // function lines
Bram Moolenaar4f8f5422021-06-20 19:28:14 +02001928
1929 int uf_debug_tick; // when last checked for a breakpoint in this
1930 // function.
1931 int uf_has_breakpoint; // TRUE when a breakpoint has been set in
1932 // this function.
Bram Moolenaar27e80c82018-10-14 21:41:01 +02001933# ifdef FEAT_PROFILE
Bram Moolenaar42ae78c2019-05-09 21:08:58 +02001934 int uf_profiling; // TRUE when func is being profiled
Bram Moolenaarad648092018-06-30 18:28:03 +02001935 int uf_prof_initialized;
Ernie Rael21d32122023-09-02 15:09:18 +02001936 hash_T uf_hash; // hash for uf_name when profiling
Bram Moolenaar42ae78c2019-05-09 21:08:58 +02001937 // profiling the function as a whole
1938 int uf_tm_count; // nr of calls
1939 proftime_T uf_tm_total; // time spent in function + children
1940 proftime_T uf_tm_self; // time spent in function itself
1941 proftime_T uf_tm_children; // time spent in children this call
1942 // profiling the function per line
1943 int *uf_tml_count; // nr of times line was executed
1944 proftime_T *uf_tml_total; // time spent in a line + children
1945 proftime_T *uf_tml_self; // time spent in a line itself
1946 proftime_T uf_tml_start; // start time for current line
1947 proftime_T uf_tml_children; // time spent in children for this line
1948 proftime_T uf_tml_wait; // start wait time for current line
1949 int uf_tml_idx; // index of line being timed; -1 if none
1950 int uf_tml_execed; // line being timed was executed
Bram Moolenaar27e80c82018-10-14 21:41:01 +02001951# endif
Bram Moolenaar42ae78c2019-05-09 21:08:58 +02001952 sctx_T uf_script_ctx; // SCTX where function was defined,
Bram Moolenaarf9b2b492020-08-05 14:34:14 +02001953 // used for s: variables; sc_version changed
1954 // for :function
1955 int uf_script_ctx_version; // original sc_version of SCTX
Bram Moolenaar42ae78c2019-05-09 21:08:58 +02001956 int uf_refcount; // reference count, see func_name_refcount()
Bram Moolenaarc8cd2b32020-05-01 19:29:08 +02001957
Bram Moolenaar42ae78c2019-05-09 21:08:58 +02001958 funccall_T *uf_scoped; // l: local variables for closure
Bram Moolenaarc8cd2b32020-05-01 19:29:08 +02001959
Bram Moolenaar1a47ae32019-12-29 23:04:25 +01001960 char_u *uf_name_exp; // if "uf_name[]" starts with SNR the name with
1961 // "<SNR>" as a string, otherwise NULL
John Marriottb32800f2025-02-01 15:25:34 +01001962 size_t uf_namelen; // length of uf_name (excluding the NUL)
Bram Moolenaar6a12e332021-01-31 14:46:00 +01001963 char_u uf_name[4]; // name of function (actual size equals name);
1964 // can start with <SNR>123_ (<SNR> is K_SPECIAL
Bram Moolenaar42ae78c2019-05-09 21:08:58 +02001965 // KS_EXTRA KE_SNR)
Bram Moolenaar00b28d62022-12-08 15:32:33 +00001966};
Bram Moolenaar437bafe2016-08-01 15:40:54 +02001967
Bram Moolenaarc8cd2b32020-05-01 19:29:08 +02001968// flags used in uf_flags
1969#define FC_ABORT 0x01 // abort function on error
1970#define FC_RANGE 0x02 // function accepts range
1971#define FC_DICT 0x04 // Dict function, uses "self"
1972#define FC_CLOSURE 0x08 // closure, uses outer scope variables
1973#define FC_DELETED 0x10 // :delfunction used while uf_refcount > 0
1974#define FC_REMOVED 0x20 // function redefined while uf_refcount > 0
1975#define FC_SANDBOX 0x40 // function defined in the sandbox
1976#define FC_DEAD 0x80 // function kept only for reference to dfunc
1977#define FC_EXPORT 0x100 // "export def Func()"
1978#define FC_NOARGS 0x200 // no a: variables in lambda
Hirohito Higashifbe4a8f2025-04-27 15:28:30 +02001979#define FC_VIM9 0x400 // defined in Vim9 script file
Bram Moolenaar801ab062020-06-25 19:27:56 +02001980#define FC_CFUNC 0x800 // defined as Lua C func
Bram Moolenaar8fa745e2022-09-16 19:04:24 +01001981#define FC_COPY 0x1000 // copy of another function by
1982 // copy_lambda_to_global_func()
Bram Moolenaar38453522021-11-28 22:00:12 +00001983#define FC_LAMBDA 0x2000 // one line "return {expr}"
Bram Moolenaarc8cd2b32020-05-01 19:29:08 +02001984
Bram Moolenaar574950d2023-01-03 19:08:50 +00001985#define FC_OBJECT 0x4000 // object method
1986#define FC_NEW 0x8000 // constructor
Yegappan Lakshmanan7bcd25c2023-09-08 19:27:51 +02001987#define FC_ABSTRACT 0x10000 // abstract method
Bram Moolenaar00b28d62022-12-08 15:32:33 +00001988
Yegappan Lakshmanan1db15142023-09-19 20:34:05 +02001989// Is "ufunc" an object method?
1990#define IS_OBJECT_METHOD(ufunc) ((ufunc->uf_flags & FC_OBJECT) == FC_OBJECT)
1991// Is "ufunc" a class new() constructor method?
1992#define IS_CONSTRUCTOR_METHOD(ufunc) ((ufunc->uf_flags & FC_NEW) == FC_NEW)
1993// Is "ufunc" an abstract class method?
1994#define IS_ABSTRACT_METHOD(ufunc) ((ufunc->uf_flags & FC_ABSTRACT) == FC_ABSTRACT)
1995
Bram Moolenaar42ae78c2019-05-09 21:08:58 +02001996#define MAX_FUNC_ARGS 20 // maximum number of function arguments
1997#define VAR_SHORT_LEN 20 // short variable name length
1998#define FIXVAR_CNT 12 // number of fixed variables
Bram Moolenaar437bafe2016-08-01 15:40:54 +02001999
Bram Moolenaar9bf703d2019-11-30 19:44:38 +01002000/*
Bram Moolenaarbf67ea12020-05-02 17:52:42 +02002001 * Structure to hold info for a function that is currently being executed.
Bram Moolenaar9bf703d2019-11-30 19:44:38 +01002002 */
Bram Moolenaar437bafe2016-08-01 15:40:54 +02002003struct funccall_S
2004{
Bram Moolenaarca16c602022-09-06 18:57:08 +01002005 ufunc_T *fc_func; // function being called
2006 int fc_linenr; // next line to be executed
2007 int fc_returned; // ":return" used
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02002008 struct // fixed variables for arguments
Bram Moolenaar437bafe2016-08-01 15:40:54 +02002009 {
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02002010 dictitem_T var; // variable (without room for name)
2011 char_u room[VAR_SHORT_LEN]; // room for the name
Bram Moolenaarca16c602022-09-06 18:57:08 +01002012 } fc_fixvar[FIXVAR_CNT];
2013 dict_T fc_l_vars; // l: local function variables
2014 dictitem_T fc_l_vars_var; // variable for l: scope
2015 dict_T fc_l_avars; // a: argument variables
2016 dictitem_T fc_l_avars_var; // variable for a: scope
2017 list_T fc_l_varlist; // list for a:000
2018 listitem_T fc_l_listitems[MAX_FUNC_ARGS]; // listitems for a:000
2019 typval_T *fc_rettv; // return value
2020 linenr_T fc_breakpoint; // next line with breakpoint or zero
2021 int fc_dbg_tick; // debug_tick when breakpoint was set
2022 int fc_level; // top nesting level of executed function
Bram Moolenaar58779852022-09-06 18:31:14 +01002023
Bram Moolenaar1d84f762022-09-03 21:35:53 +01002024 garray_T fc_defer; // functions to be called on return
Bram Moolenaar58779852022-09-06 18:31:14 +01002025 ectx_T *fc_ectx; // execution context for :def function, NULL
2026 // otherwise
2027
Bram Moolenaar437bafe2016-08-01 15:40:54 +02002028#ifdef FEAT_PROFILE
Bram Moolenaarca16c602022-09-06 18:57:08 +01002029 proftime_T fc_prof_child; // time spent in a child
Bram Moolenaar437bafe2016-08-01 15:40:54 +02002030#endif
Bram Moolenaarca16c602022-09-06 18:57:08 +01002031 funccall_T *fc_caller; // calling function or NULL; or next funccal in
Bram Moolenaar22286892020-11-05 20:50:51 +01002032 // list pointed to by previous_funccal.
Bram Moolenaar437bafe2016-08-01 15:40:54 +02002033
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02002034 // for closure
2035 int fc_refcount; // number of user functions that reference this
2036 // funccal
2037 int fc_copyID; // for garbage collection
Bram Moolenaarca16c602022-09-06 18:57:08 +01002038 garray_T fc_ufuncs; // list of ufunc_T* which keep a reference to
zeertzjqe7d49462023-04-16 20:53:55 +01002039 // "fc_func"
Bram Moolenaar437bafe2016-08-01 15:40:54 +02002040};
2041
Bram Moolenaar1d84f762022-09-03 21:35:53 +01002042// structure used as item in "fc_defer"
2043typedef struct
2044{
2045 char_u *dr_name; // function name, allocated
2046 typval_T dr_argvars[MAX_FUNC_ARGS + 1];
2047 int dr_argcount;
2048} defer_T;
2049
Bram Moolenaar437bafe2016-08-01 15:40:54 +02002050/*
2051 * Struct used by trans_function_name()
2052 */
2053typedef struct
2054{
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02002055 dict_T *fd_dict; // Dictionary used
2056 char_u *fd_newkey; // new key in "dict" in allocated memory
2057 dictitem_T *fd_di; // Dictionary item used
Bram Moolenaar437bafe2016-08-01 15:40:54 +02002058} funcdict_T;
2059
Bram Moolenaar27e80c82018-10-14 21:41:01 +02002060typedef struct funccal_entry funccal_entry_T;
2061struct funccal_entry {
2062 void *top_funccal;
2063 funccal_entry_T *next;
2064};
2065
Bram Moolenaar9bf703d2019-11-30 19:44:38 +01002066// From user function to hashitem and back.
Bram Moolenaar660a10a2019-07-14 15:48:38 +02002067#define UF2HIKEY(fp) ((fp)->uf_name)
2068#define HIKEY2UF(p) ((ufunc_T *)((p) - offsetof(ufunc_T, uf_name)))
2069#define HI2UF(hi) HIKEY2UF((hi)->hi_key)
2070
Bram Moolenaar9bf703d2019-11-30 19:44:38 +01002071/*
Bram Moolenaar7ebcba62020-01-12 17:42:55 +01002072 * Holds the hashtab with variables local to each sourced script.
2073 * Each item holds a variable (nameless) that points to the dict_T.
2074 */
Bram Moolenaar8d739de2020-10-14 19:39:19 +02002075typedef struct {
Bram Moolenaar7ebcba62020-01-12 17:42:55 +01002076 dictitem_T sv_var;
2077 dict_T sv_dict;
2078} scriptvar_T;
2079
2080/*
Bram Moolenaar8d739de2020-10-14 19:39:19 +02002081 * Entry for "sn_all_vars". Contains the s: variables from sn_vars plus the
2082 * block-local ones.
2083 */
2084typedef struct sallvar_S sallvar_T;
2085struct sallvar_S {
2086 sallvar_T *sav_next; // var with same name but different block
2087 int sav_block_id; // block ID where declared
2088 int sav_var_vals_idx; // index in sn_var_vals
2089
2090 // So long as the variable is valid (block it was defined in is still
2091 // active) "sav_di" is used. It is set to NULL when leaving the block,
2092 // then sav_tv and sav_flags are used.
2093 dictitem_T *sav_di; // dictitem with di_key and di_tv
2094 typval_T sav_tv; // type and value of the variable
2095 char_u sav_flags; // DI_FLAGS_ flags (only used for variable)
2096 char_u sav_key[1]; // key (actually longer!)
2097};
2098
2099/*
2100 * In the sn_all_vars hashtab item "hi_key" points to "sav_key" in a sallvar_T.
2101 * This makes it possible to store and find the sallvar_T.
2102 * SAV2HIKEY() converts a sallvar_T pointer to a hashitem key pointer.
2103 * HIKEY2SAV() converts a hashitem key pointer to a sallvar_T pointer.
2104 * HI2SAV() converts a hashitem pointer to a sallvar_T pointer.
2105 */
2106#define SAV2HIKEY(sav) ((sav)->sav_key)
2107#define HIKEY2SAV(p) ((sallvar_T *)(p - offsetof(sallvar_T, sav_key)))
2108#define HI2SAV(hi) HIKEY2SAV((hi)->hi_key)
2109
Bram Moolenaaraa7d0c22022-04-05 21:40:38 +01002110#define SVFLAG_TYPE_ALLOCATED 1 // call free_type() for "sv_type"
2111#define SVFLAG_EXPORTED 2 // "export let var = val"
2112#define SVFLAG_ASSIGNED 4 // assigned a value
2113
Bram Moolenaar8d739de2020-10-14 19:39:19 +02002114/*
Bram Moolenaar8a7d6542020-01-26 15:56:19 +01002115 * Entry for "sn_var_vals". Used for script-local variables.
2116 */
Bram Moolenaar9b8d6222020-12-28 18:26:00 +01002117struct svar_S {
Bram Moolenaar8d739de2020-10-14 19:39:19 +02002118 char_u *sv_name; // points into "sn_all_vars" di_key
2119 typval_T *sv_tv; // points into "sn_vars" or "sn_all_vars" di_tv
Bram Moolenaar8a7d6542020-01-26 15:56:19 +01002120 type_T *sv_type;
Bram Moolenaaraa7d0c22022-04-05 21:40:38 +01002121 int sv_flags; // SVFLAG_ values above
Bram Moolenaar08251752021-01-11 21:20:18 +01002122 int sv_const; // 0, ASSIGN_CONST or ASSIGN_FINAL
Bram Moolenaar9b8d6222020-12-28 18:26:00 +01002123};
Bram Moolenaar8a7d6542020-01-26 15:56:19 +01002124
2125typedef struct {
2126 char_u *imp_name; // name imported as (allocated)
Bram Moolenaard5f400c2022-01-06 21:10:28 +00002127 scid_T imp_sid; // script ID of "from"
Bram Moolenaara6294952020-12-27 13:39:50 +01002128 int imp_flags; // IMP_FLAGS_ values
Bram Moolenaar8a7d6542020-01-26 15:56:19 +01002129} imported_T;
2130
Bram Moolenaara6294952020-12-27 13:39:50 +01002131#define IMP_FLAGS_RELOAD 2 // script reloaded, OK to redefine
Bram Moolenaardc4451d2022-01-09 21:36:37 +00002132#define IMP_FLAGS_AUTOLOAD 4 // script still needs to be loaded
Bram Moolenaara6294952020-12-27 13:39:50 +01002133
Bram Moolenaar8a7d6542020-01-26 15:56:19 +01002134/*
dundargocc57b5bc2022-11-02 13:30:51 +00002135 * Info about an encountered script.
Dominique Pelleb49dfd02023-04-14 21:54:25 +01002136 * When sn_state has SN_STATE_NOT_LOADED, it has not been sourced yet.
Bram Moolenaar9bf703d2019-11-30 19:44:38 +01002137 */
Bram Moolenaar7ebcba62020-01-12 17:42:55 +01002138typedef struct
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +02002139{
Bram Moolenaarc0ceeeb2022-03-30 21:12:27 +01002140 char_u *sn_name; // full path of script file
Bram Moolenaar4aab88d2020-12-24 21:56:41 +01002141 int sn_script_seq; // latest sctx_T sc_seq value
Bram Moolenaar7ebcba62020-01-12 17:42:55 +01002142
Bram Moolenaar753885b2022-08-24 16:30:36 +01002143 // When non-zero the script ID of the actually sourced script. Used if a
2144 // script is used by a name which has a symlink, we list both names, but
2145 // only the linked-to script is actually sourced.
2146 int sn_sourced_sid;
2147
Bram Moolenaar8d739de2020-10-14 19:39:19 +02002148 // "sn_vars" stores the s: variables currently valid. When leaving a block
2149 // variables local to that block are removed.
2150 scriptvar_T *sn_vars;
2151
2152 // Specific for a Vim9 script.
2153 // "sn_all_vars" stores all script variables ever declared. So long as the
2154 // variable is still valid the value is in "sn_vars->sv_dict...di_tv".
2155 // When the block of a declaration is left the value is moved to
2156 // "sn_all_vars..sav_tv".
2157 // Variables with duplicate names are possible, the sav_block_id must be
2158 // used to check that which variable is valid.
2159 dict_T sn_all_vars; // all script variables, dict of sallvar_T
2160
2161 // Stores the same variables as in "sn_all_vars" as a list of svar_T, so
2162 // that they can be quickly found by index instead of a hash table lookup.
2163 // Also stores the type.
2164 garray_T sn_var_vals;
Bram Moolenaar8a7d6542020-01-26 15:56:19 +01002165
2166 garray_T sn_imports; // imported items, imported_T
Bram Moolenaar8a7d6542020-01-26 15:56:19 +01002167 garray_T sn_type_list; // keeps types used by variables
Bram Moolenaarfbbcd002020-10-15 12:46:44 +02002168 int sn_current_block_id; // ID for current block, 0 for outer
2169 int sn_last_block_id; // Unique ID for each script block
Bram Moolenaar8a7d6542020-01-26 15:56:19 +01002170
Bram Moolenaar7ebcba62020-01-12 17:42:55 +01002171 int sn_version; // :scriptversion
Bram Moolenaar2b327002020-12-26 15:39:31 +01002172 int sn_state; // SN_STATE_ values
Bram Moolenaar8a7d6542020-01-26 15:56:19 +01002173 char_u *sn_save_cpo; // 'cpo' value when :vim9script found
Bram Moolenaar71eb3ad2021-12-26 12:07:30 +00002174 char sn_is_vimrc; // .vimrc file, do not restore 'cpo'
Ernie Rael9a901792024-04-16 22:11:56 +02002175 char sn_syml_checked;// flag: this has been checked for sym link
Bram Moolenaarfe2ef0b2022-01-10 18:08:00 +00002176
Bram Moolenaarc0ceeeb2022-03-30 21:12:27 +01002177 // for a Vim9 script under "rtp/autoload/" this is "dir#scriptname#"
Bram Moolenaarfe2ef0b2022-01-10 18:08:00 +00002178 char_u *sn_autoload_prefix;
Bram Moolenaar7ebcba62020-01-12 17:42:55 +01002179
Bram Moolenaarc0ceeeb2022-03-30 21:12:27 +01002180 // TRUE for a script used with "import autoload './dirname/script.vim'"
Bram Moolenaarccbfd482022-03-31 16:18:23 +01002181 // For "../autoload/script.vim" sn_autoload_prefix is also set.
Bram Moolenaarc0ceeeb2022-03-30 21:12:27 +01002182 int sn_import_autoload;
2183
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +02002184# ifdef FEAT_PROFILE
Bram Moolenaar4aea03e2019-09-25 22:37:17 +02002185 int sn_prof_on; // TRUE when script is/was profiled
2186 int sn_pr_force; // forceit: profile functions in this script
2187 proftime_T sn_pr_child; // time set when going into first child
2188 int sn_pr_nest; // nesting for sn_pr_child
2189 // profiling the script as a whole
2190 int sn_pr_count; // nr of times sourced
2191 proftime_T sn_pr_total; // time spent in script + children
2192 proftime_T sn_pr_self; // time spent in script itself
2193 proftime_T sn_pr_start; // time at script start
2194 proftime_T sn_pr_children; // time in children after script start
2195 // profiling the script per line
2196 garray_T sn_prl_ga; // things stored for every line
2197 proftime_T sn_prl_start; // start time for current line
2198 proftime_T sn_prl_children; // time spent in children for this line
2199 proftime_T sn_prl_wait; // wait start time for current line
2200 int sn_prl_idx; // index of line being timed; -1 if none
2201 int sn_prl_execed; // line being timed was executed
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +02002202# endif
2203} scriptitem_T;
2204
Bram Moolenaar2b327002020-12-26 15:39:31 +01002205#define SN_STATE_NEW 0 // newly loaded script, nothing done
Bram Moolenaardc4451d2022-01-09 21:36:37 +00002206#define SN_STATE_NOT_LOADED 1 // script located but not loaded
2207#define SN_STATE_RELOAD 2 // script loaded before, nothing done
Bram Moolenaar2b327002020-12-26 15:39:31 +01002208#define SN_STATE_HAD_COMMAND 9 // a command was executed
2209
Bram Moolenaar5409f5d2020-06-24 18:37:35 +02002210// Struct passed through eval() functions.
2211// See EVALARG_EVALUATE for a fixed value with eval_flags set to EVAL_EVALUATE.
2212typedef struct {
Bram Moolenaarb7a78f72020-06-28 18:43:40 +02002213 int eval_flags; // EVAL_ flag values below
2214 int eval_break_count; // nr of line breaks consumed
Bram Moolenaar5409f5d2020-06-24 18:37:35 +02002215
2216 // copied from exarg_T when "getline" is "getsourceline". Can be NULL.
Bram Moolenaar66250c92020-08-20 15:02:42 +02002217 char_u *(*eval_getline)(int, void *, int, getline_opt_T);
Bram Moolenaarb7a78f72020-06-28 18:43:40 +02002218 void *eval_cookie; // argument for eval_getline()
Bram Moolenaarb171fb12020-06-24 20:34:03 +02002219
Bram Moolenaar7a4b8982020-07-08 17:36:21 +02002220 // used when compiling a :def function, NULL otherwise
2221 cctx_T *eval_cctx;
2222
Bram Moolenaar2eb6fc32021-07-25 14:13:53 +02002223 // used when executing commands from a script, NULL otherwise
2224 cstack_T *eval_cstack;
2225
Bram Moolenaare40fbc22020-06-27 18:06:45 +02002226 // Used to collect lines while parsing them, so that they can be
2227 // concatenated later. Used when "eval_ga.ga_itemsize" is not zero.
2228 // "eval_ga.ga_data" is a list of pointers to lines.
Bram Moolenaarecb66452021-05-18 15:09:18 +02002229 // "eval_freega" list pointers that need to be freed after concatenating.
Bram Moolenaare40fbc22020-06-27 18:06:45 +02002230 garray_T eval_ga;
Bram Moolenaarecb66452021-05-18 15:09:18 +02002231 garray_T eval_freega;
Bram Moolenaare40fbc22020-06-27 18:06:45 +02002232
Bram Moolenaar8e2730a2020-07-08 22:01:49 +02002233 // pointer to the last line obtained with getsourceline()
Bram Moolenaarb171fb12020-06-24 20:34:03 +02002234 char_u *eval_tofree;
Bram Moolenaar8e2730a2020-07-08 22:01:49 +02002235
Bram Moolenaar844fb642021-10-23 13:32:30 +01002236 // array with lines of an inline function
2237 garray_T eval_tofree_ga;
2238
2239 // set when "arg" points into the last entry of "eval_tofree_ga"
2240 int eval_using_cmdline;
Bram Moolenaar67da21a2021-03-21 22:12:34 +01002241
Bram Moolenaar8e2730a2020-07-08 22:01:49 +02002242 // pointer to the lines concatenated for a lambda.
2243 char_u *eval_tofree_lambda;
Bram Moolenaar5409f5d2020-06-24 18:37:35 +02002244} evalarg_T;
2245
zeertzjqb7f6f932023-04-13 22:12:50 +01002246// Flag for expression evaluation.
Bram Moolenaar5409f5d2020-06-24 18:37:35 +02002247#define EVAL_EVALUATE 1 // when missing don't actually evaluate
Bram Moolenaar5409f5d2020-06-24 18:37:35 +02002248
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +02002249# ifdef FEAT_PROFILE
Bram Moolenaar9bf703d2019-11-30 19:44:38 +01002250/*
2251 * Struct used in sn_prl_ga for every line of a script.
2252 */
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +02002253typedef struct sn_prl_S
2254{
Bram Moolenaar4aea03e2019-09-25 22:37:17 +02002255 int snp_count; // nr of times line was executed
2256 proftime_T sn_prl_total; // time spent in a line + children
2257 proftime_T sn_prl_self; // time spent in a line itself
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +02002258} sn_prl_T;
2259
2260# define PRL_ITEM(si, idx) (((sn_prl_T *)(si)->sn_prl_ga.ga_data)[(idx)])
Bram Moolenaarb2049902021-01-24 12:53:53 +01002261
2262typedef struct {
2263 int pi_started_profiling;
2264 proftime_T pi_wait_start;
2265 proftime_T pi_call_start;
2266} profinfo_T;
2267
Bram Moolenaarf002a412021-01-24 13:34:18 +01002268# else
2269typedef struct
2270{
2271 int dummy;
2272} profinfo_T;
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +02002273# endif
Bram Moolenaaracadbea2016-08-01 16:35:59 +02002274#else
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02002275// dummy typedefs for use in function prototypes
Bram Moolenaar83c43ab2022-12-08 16:10:01 +00002276struct ufunc_S
Bram Moolenaaracadbea2016-08-01 16:35:59 +02002277{
2278 int dummy;
Bram Moolenaar83c43ab2022-12-08 16:10:01 +00002279};
Bram Moolenaaracadbea2016-08-01 16:35:59 +02002280typedef struct
2281{
2282 int dummy;
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +02002283} funccall_T;
2284typedef struct
2285{
2286 int dummy;
Bram Moolenaaracadbea2016-08-01 16:35:59 +02002287} funcdict_T;
Bram Moolenaard95c3c22018-10-14 22:38:09 +02002288typedef struct
2289{
2290 int dummy;
2291} funccal_entry_T;
Bram Moolenaarfa55cfc2019-07-13 22:59:32 +02002292typedef struct
2293{
2294 int dummy;
2295} scriptitem_T;
Bram Moolenaar9d40c632020-06-24 19:05:29 +02002296typedef struct
2297{
2298 int dummy;
2299} evalarg_T;
Bram Moolenaar437bafe2016-08-01 15:40:54 +02002300#endif
2301
Bram Moolenaar505e43a2019-08-03 18:28:17 +02002302// Struct passed between functions dealing with function call execution.
2303//
zeertzjq48db5da2022-09-16 12:10:03 +01002304// "fe_argv_func", when not NULL, can be used to fill in arguments only when the
Bram Moolenaar505e43a2019-08-03 18:28:17 +02002305// invoked function uses them. It is called like this:
zeertzjq48db5da2022-09-16 12:10:03 +01002306// new_argcount = fe_argv_func(current_argcount, argv, partial_argcount,
2307// called_func)
Bram Moolenaar505e43a2019-08-03 18:28:17 +02002308//
2309typedef struct {
zeertzjq48db5da2022-09-16 12:10:03 +01002310 int (* fe_argv_func)(int, typval_T *, int, ufunc_T *);
Bram Moolenaar851f86b2021-12-13 14:26:44 +00002311 linenr_T fe_firstline; // first line of range
2312 linenr_T fe_lastline; // last line of range
2313 int *fe_doesrange; // if not NULL: return: function handled range
2314 int fe_evaluate; // actually evaluate expressions
Bram Moolenaar5ca05fa2023-06-10 16:45:13 +01002315 ufunc_T *fe_ufunc; // function to be called, when NULL lookup by
2316 // name
2317 partial_T *fe_partial; // for "dict" and extra arguments
Bram Moolenaar851f86b2021-12-13 14:26:44 +00002318 dict_T *fe_selfdict; // Dictionary for "self"
Bram Moolenaarffdaca92022-12-09 21:41:48 +00002319 object_T *fe_object; // object, e.g. for "this.Func()"
Bram Moolenaar851f86b2021-12-13 14:26:44 +00002320 typval_T *fe_basetv; // base for base->method()
2321 type_T *fe_check_type; // type from funcref or NULL
Bram Moolenaar2ef91562021-12-11 16:14:07 +00002322 int fe_found_var; // if the function is not found then give an
2323 // error that a variable is not callable.
Bram Moolenaar505e43a2019-08-03 18:28:17 +02002324} funcexe_T;
2325
Bram Moolenaarf7779c62020-05-03 15:38:16 +02002326/*
2327 * Structure to hold the context of a compiled function, used by closures
2328 * defined in that function.
2329 */
Bram Moolenaar7509ad82021-12-14 18:14:37 +00002330typedef struct funcstack_S funcstack_T;
Bram Moolenaar7509ad82021-12-14 18:14:37 +00002331struct funcstack_S
Bram Moolenaarf7779c62020-05-03 15:38:16 +02002332{
Bram Moolenaar7509ad82021-12-14 18:14:37 +00002333 funcstack_T *fs_next; // linked list at "first_funcstack"
2334 funcstack_T *fs_prev;
2335
Bram Moolenaarf7779c62020-05-03 15:38:16 +02002336 garray_T fs_ga; // contains the stack, with:
2337 // - arguments
2338 // - frame
2339 // - local variables
Bram Moolenaar85d5e2b2020-10-10 14:13:01 +02002340 int fs_var_offset; // count of arguments + frame size == offset to
2341 // local variables
Bram Moolenaarf7779c62020-05-03 15:38:16 +02002342
2343 int fs_refcount; // nr of closures referencing this funcstack
Bram Moolenaar85d5e2b2020-10-10 14:13:01 +02002344 int fs_min_refcount; // nr of closures on this funcstack
Bram Moolenaar0cdfb7c2022-09-17 15:44:52 +01002345 int fs_copyID; // for garbage collection
2346};
2347
2348/*
dundargocc57b5bc2022-11-02 13:30:51 +00002349 * Structure to hold the variables declared in a loop that are possibly used
Bram Moolenaar0cdfb7c2022-09-17 15:44:52 +01002350 * in a closure.
2351 */
2352typedef struct loopvars_S loopvars_T;
2353struct loopvars_S
2354{
2355 loopvars_T *lvs_next; // linked list at "first_loopvars"
2356 loopvars_T *lvs_prev;
2357
2358 garray_T lvs_ga; // contains the variables
2359 int lvs_refcount; // nr of closures referencing this loopvars
2360 int lvs_min_refcount; // nr of closures on this loopvars
2361 int lvs_copyID; // for garbage collection
Bram Moolenaar7509ad82021-12-14 18:14:37 +00002362};
Bram Moolenaarf7779c62020-05-03 15:38:16 +02002363
Bram Moolenaarcc341812022-09-19 15:54:34 +01002364// maximum nesting of :while and :for loops in a :def function
2365#define MAX_LOOP_DEPTH 10
2366
Bram Moolenaar0186e582021-01-10 18:33:11 +01002367typedef struct outer_S outer_T;
2368struct outer_S {
Bram Moolenaar8fa745e2022-09-16 19:04:24 +01002369 garray_T *out_stack; // stack from outer scope, or a copy
2370 // containing only arguments and local vars
Bram Moolenaar0186e582021-01-10 18:33:11 +01002371 int out_frame_idx; // index of stack frame in out_stack
2372 outer_T *out_up; // outer scope of outer scope or NULL
Bram Moolenaarc04f2a42021-06-09 19:30:03 +02002373 partial_T *out_up_partial; // partial owning out_up or NULL
Bram Moolenaar8fa745e2022-09-16 19:04:24 +01002374
Bram Moolenaarcc341812022-09-19 15:54:34 +01002375 struct {
2376 garray_T *stack; // stack from outer scope, or a copy
Bram Moolenaar8fa745e2022-09-16 19:04:24 +01002377 // containing only vars inside the loop
Bram Moolenaarcc341812022-09-19 15:54:34 +01002378 short var_idx; // first variable defined in a loop in
2379 // out_loop_stack
2380 short var_count; // number of variables defined in a loop
2381 } out_loop[MAX_LOOP_DEPTH];
Bram Moolenaar6d313be2022-09-22 16:36:25 +01002382 int out_loop_size; // nr of used entries in out_loop[]
Bram Moolenaar0186e582021-01-10 18:33:11 +01002383};
2384
Bram Moolenaar1735bc92016-03-14 23:05:14 +01002385struct partial_S
2386{
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02002387 int pt_refcount; // reference count
Dominique Pelle3276f582021-08-07 12:44:41 +02002388 int pt_auto; // when TRUE the partial was created for using
2389 // dict.member in handle_subscript()
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02002390 char_u *pt_name; // function name; when NULL use
2391 // pt_func->uf_name
2392 ufunc_T *pt_func; // function pointer; when NULL lookup function
2393 // with pt_name
Bram Moolenaarf7779c62020-05-03 15:38:16 +02002394
Bram Moolenaar0186e582021-01-10 18:33:11 +01002395 // For a compiled closure: the arguments and local variables scope
2396 outer_T pt_outer;
2397
Bram Moolenaar7aca5ca2022-02-07 19:56:43 +00002398 // For a partial of a partial: use pt_outer values of this partial.
2399 partial_T *pt_outer_partial;
2400
Bram Moolenaar0186e582021-01-10 18:33:11 +01002401 funcstack_T *pt_funcstack; // copy of stack, used after context
2402 // function returns
Bram Moolenaarcc341812022-09-19 15:54:34 +01002403 loopvars_T *(pt_loopvars[MAX_LOOP_DEPTH]);
2404 // copy of loop variables, used after loop
Bram Moolenaar0cdfb7c2022-09-17 15:44:52 +01002405 // block ends
Bram Moolenaarf7779c62020-05-03 15:38:16 +02002406
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02002407 typval_T *pt_argv; // arguments in allocated array
Dominique Pelle3276f582021-08-07 12:44:41 +02002408 int pt_argc; // number of arguments
Bram Moolenaarf7779c62020-05-03 15:38:16 +02002409
Bram Moolenaarb68b3462020-05-06 21:06:30 +02002410 int pt_copyID; // funcstack may contain pointer to partial
Dominique Pelle3276f582021-08-07 12:44:41 +02002411 dict_T *pt_dict; // dict for "self"
Yegappan Lakshmanan29bb67f2023-10-14 11:18:50 +02002412 object_T *pt_obj; // object method
Bram Moolenaar1735bc92016-03-14 23:05:14 +01002413};
2414
Bram Moolenaarcc341812022-09-19 15:54:34 +01002415typedef struct {
2416 short lvi_depth; // current nested loop depth
2417 struct {
2418 short var_idx; // index of first variable inside loop
2419 short var_count; // number of variables inside loop
2420 } lvi_loop[MAX_LOOP_DEPTH];
2421} loopvarinfo_T;
2422
LemonBoyeca7c602022-04-14 15:39:43 +01002423typedef struct AutoPatCmd_S AutoPatCmd_T;
Bram Moolenaar1a47ae32019-12-29 23:04:25 +01002424
2425/*
2426 * Entry in the execution stack "exestack".
2427 */
2428typedef enum {
2429 ETYPE_TOP, // toplevel
Bram Moolenaar6ed545e2022-05-09 20:09:23 +01002430 ETYPE_SCRIPT, // sourcing script, use es_info.sctx
2431 ETYPE_UFUNC, // user function, use es_info.ufunc
2432 ETYPE_AUCMD, // autocomand, use es_info.aucmd
2433 ETYPE_MODELINE, // modeline, use es_info.sctx
2434 ETYPE_EXCEPT, // exception, use es_info.exception
2435 ETYPE_ARGS, // command line argument
2436 ETYPE_ENV, // environment variable
2437 ETYPE_INTERNAL, // internal operation
2438 ETYPE_SPELL, // loading spell file
Bram Moolenaar1a47ae32019-12-29 23:04:25 +01002439} etype_T;
2440
2441typedef struct {
2442 long es_lnum; // replaces "sourcing_lnum"
2443 char_u *es_name; // replaces "sourcing_name"
2444 etype_T es_type;
2445 union {
2446 sctx_T *sctx; // script and modeline info
2447#if defined(FEAT_EVAL)
2448 ufunc_T *ufunc; // function info
2449#endif
LemonBoyeca7c602022-04-14 15:39:43 +01002450 AutoPatCmd_T *aucmd; // autocommand info
Bram Moolenaar1a47ae32019-12-29 23:04:25 +01002451 except_T *except; // exception info
2452 } es_info;
Bram Moolenaarc620c052020-07-08 15:16:19 +02002453#if defined(FEAT_EVAL)
Bram Moolenaarc70fe462021-04-17 17:59:19 +02002454 sctx_T es_save_sctx; // saved current_sctx when calling function
Bram Moolenaarc620c052020-07-08 15:16:19 +02002455#endif
Bram Moolenaar1a47ae32019-12-29 23:04:25 +01002456} estack_T;
2457
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02002458// Information returned by get_tty_info().
Bram Moolenaar6b93b0e2017-08-13 20:28:53 +02002459typedef struct {
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02002460 int backspace; // what the Backspace key produces
2461 int enter; // what the Enter key produces
2462 int interrupt; // interrupt character
2463 int nl_does_cr; // TRUE when a NL is expanded to CR-NL on output
Bram Moolenaar6b93b0e2017-08-13 20:28:53 +02002464} ttyinfo_T;
2465
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02002466// Status of a job. Order matters!
Bram Moolenaar835dc632016-02-07 14:27:38 +01002467typedef enum
2468{
2469 JOB_FAILED,
2470 JOB_STARTED,
Bram Moolenaarea3ece42018-04-17 20:14:39 +02002471 JOB_ENDED, // detected job done
2472 JOB_FINISHED, // job done and cleanup done
Bram Moolenaar835dc632016-02-07 14:27:38 +01002473} jobstatus_T;
2474
2475/*
2476 * Structure to hold info about a Job.
2477 */
2478struct jobvar_S
2479{
Bram Moolenaar65edff82016-02-21 16:40:11 +01002480 job_T *jv_next;
2481 job_T *jv_prev;
Bram Moolenaar835dc632016-02-07 14:27:38 +01002482#ifdef UNIX
2483 pid_t jv_pid;
Bram Moolenaar835dc632016-02-07 14:27:38 +01002484#endif
Bram Moolenaar4f974752019-02-17 17:44:42 +01002485#ifdef MSWIN
Bram Moolenaar76467df2016-02-12 19:30:26 +01002486 PROCESS_INFORMATION jv_proc_info;
Bram Moolenaar14207f42016-10-27 21:13:10 +02002487 HANDLE jv_job_object;
Bram Moolenaar835dc632016-02-07 14:27:38 +01002488#endif
Dominique Pelle3276f582021-08-07 12:44:41 +02002489 jobstatus_T jv_status;
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02002490 char_u *jv_tty_in; // controlling tty input, allocated
2491 char_u *jv_tty_out; // controlling tty output, allocated
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02002492 char_u *jv_stoponexit; // allocated
Bram Moolenaarb3051ce2019-01-31 15:52:11 +01002493#ifdef UNIX
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02002494 char_u *jv_termsig; // allocated
Bram Moolenaarb3051ce2019-01-31 15:52:11 +01002495#endif
Bram Moolenaar4f974752019-02-17 17:44:42 +01002496#ifdef MSWIN
Bram Moolenaarc6ddce32019-02-08 12:47:03 +01002497 char_u *jv_tty_type; // allocated
2498#endif
Bram Moolenaareab089d2016-02-21 19:32:02 +01002499 int jv_exitval;
Bram Moolenaar3a97bb32019-06-01 13:28:35 +02002500 callback_T jv_exit_cb;
Bram Moolenaar835dc632016-02-07 14:27:38 +01002501
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02002502 buf_T *jv_in_buf; // buffer from "in-name"
Bram Moolenaar014069a2016-03-03 22:51:40 +01002503
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02002504 int jv_refcount; // reference count
Bram Moolenaar107e1ee2016-04-08 17:07:19 +02002505 int jv_copyID;
2506
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02002507 channel_T *jv_channel; // channel for I/O, reference counted
2508 char **jv_argv; // command line used to start the job
Bram Moolenaar835dc632016-02-07 14:27:38 +01002509};
2510
Bram Moolenaar6463ca22016-02-13 17:04:46 +01002511/*
2512 * Structures to hold info about a Channel.
2513 */
2514struct readq_S
2515{
Bram Moolenaar77073442016-02-13 23:23:53 +01002516 char_u *rq_buffer;
Bram Moolenaar9ed96ef2016-06-04 17:17:11 +02002517 long_u rq_buflen;
Bram Moolenaar77073442016-02-13 23:23:53 +01002518 readq_T *rq_next;
2519 readq_T *rq_prev;
Bram Moolenaar6463ca22016-02-13 17:04:46 +01002520};
2521
Bram Moolenaar97bd5e62017-08-18 20:50:30 +02002522struct writeq_S
2523{
2524 garray_T wq_ga;
2525 writeq_T *wq_next;
2526 writeq_T *wq_prev;
2527};
2528
Bram Moolenaar6463ca22016-02-13 17:04:46 +01002529struct jsonq_S
2530{
Bram Moolenaar77073442016-02-13 23:23:53 +01002531 typval_T *jq_value;
2532 jsonq_T *jq_next;
2533 jsonq_T *jq_prev;
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02002534 int jq_no_callback; // TRUE when no callback was found
Bram Moolenaar6463ca22016-02-13 17:04:46 +01002535};
2536
2537struct cbq_S
2538{
Bram Moolenaar3a97bb32019-06-01 13:28:35 +02002539 callback_T cq_callback;
Bram Moolenaar77073442016-02-13 23:23:53 +01002540 int cq_seq_nr;
2541 cbq_T *cq_next;
2542 cbq_T *cq_prev;
Bram Moolenaar6463ca22016-02-13 17:04:46 +01002543};
2544
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02002545// mode for a channel
Bram Moolenaar6463ca22016-02-13 17:04:46 +01002546typedef enum
2547{
Bram Moolenaarac4174e2022-05-07 16:38:24 +01002548 CH_MODE_NL = 0,
2549 CH_MODE_RAW,
2550 CH_MODE_JSON,
2551 CH_MODE_JS,
2552 CH_MODE_LSP // Language Server Protocol (http + json)
Bram Moolenaar6463ca22016-02-13 17:04:46 +01002553} ch_mode_T;
2554
Bram Moolenaar580984e2016-03-20 21:17:13 +01002555typedef enum {
Bram Moolenaarea3ece42018-04-17 20:14:39 +02002556 JIO_PIPE, // default
Bram Moolenaar580984e2016-03-20 21:17:13 +01002557 JIO_NULL,
2558 JIO_FILE,
2559 JIO_BUFFER,
2560 JIO_OUT
2561} job_io_T;
2562
Bram Moolenaar7c9aec42017-08-03 13:51:25 +02002563#define CH_PART_FD(part) ch_part[part].ch_fd
2564
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02002565// Ordering matters, it is used in for loops: IN is last, only SOCK/OUT/ERR
2566// are polled.
Bram Moolenaardc0ccae2016-10-09 17:28:01 +02002567typedef enum {
2568 PART_SOCK = 0,
Bram Moolenaar7c9aec42017-08-03 13:51:25 +02002569#define CH_SOCK_FD CH_PART_FD(PART_SOCK)
Bram Moolenaar509ce2a2016-03-11 22:52:15 +01002570#ifdef FEAT_JOB_CHANNEL
Bram Moolenaardc0ccae2016-10-09 17:28:01 +02002571 PART_OUT,
Bram Moolenaar7c9aec42017-08-03 13:51:25 +02002572# define CH_OUT_FD CH_PART_FD(PART_OUT)
Bram Moolenaardc0ccae2016-10-09 17:28:01 +02002573 PART_ERR,
Bram Moolenaar7c9aec42017-08-03 13:51:25 +02002574# define CH_ERR_FD CH_PART_FD(PART_ERR)
Bram Moolenaardc0ccae2016-10-09 17:28:01 +02002575 PART_IN,
Bram Moolenaar7c9aec42017-08-03 13:51:25 +02002576# define CH_IN_FD CH_PART_FD(PART_IN)
Bram Moolenaar7b3ca762016-02-14 19:13:43 +01002577#endif
Bram Moolenaarea3ece42018-04-17 20:14:39 +02002578 PART_COUNT,
Bram Moolenaardc0ccae2016-10-09 17:28:01 +02002579} ch_part_T;
2580
2581#define INVALID_FD (-1)
Bram Moolenaar7b3ca762016-02-14 19:13:43 +01002582
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02002583// The per-fd info for a channel.
Bram Moolenaar7b3ca762016-02-14 19:13:43 +01002584typedef struct {
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02002585 sock_T ch_fd; // socket/stdin/stdout/stderr, -1 if not used
Bram Moolenaar7b3ca762016-02-14 19:13:43 +01002586
2587# if defined(UNIX) && !defined(HAVE_SELECT)
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02002588 int ch_poll_idx; // used by channel_poll_setup()
Bram Moolenaar7b3ca762016-02-14 19:13:43 +01002589# endif
2590
2591#ifdef FEAT_GUI_X11
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02002592 XtInputId ch_inputHandler; // Cookie for input
Bram Moolenaar7b3ca762016-02-14 19:13:43 +01002593#endif
2594#ifdef FEAT_GUI_GTK
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02002595 gint ch_inputHandler; // Cookie for input
Bram Moolenaar7b3ca762016-02-14 19:13:43 +01002596#endif
Bram Moolenaar42d38a22016-02-20 18:18:59 +01002597
2598 ch_mode_T ch_mode;
Bram Moolenaar580984e2016-03-20 21:17:13 +01002599 job_io_T ch_io;
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02002600 int ch_timeout; // request timeout in msec
Bram Moolenaar42d38a22016-02-20 18:18:59 +01002601
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02002602 readq_T ch_head; // header for circular raw read queue
2603 jsonq_T ch_json_head; // header for circular json read queue
2604 garray_T ch_block_ids; // list of IDs that channel_read_json_block()
2605 // is waiting for
2606 // When ch_wait_len is non-zero use ch_deadline to wait for incomplete
2607 // message to be complete. The value is the length of the incomplete
2608 // message when the deadline was set. If it gets longer (something was
2609 // received) the deadline is reset.
Bram Moolenaar88989cc2017-02-06 21:56:09 +01002610 size_t ch_wait_len;
Bram Moolenaar4f974752019-02-17 17:44:42 +01002611#ifdef MSWIN
Bram Moolenaarba61ac02016-03-20 16:40:37 +01002612 DWORD ch_deadline;
2613#else
2614 struct timeval ch_deadline;
2615#endif
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02002616 int ch_block_write; // for testing: 0 when not used, -1 when write
2617 // does not block, 1 simulate blocking
2618 int ch_nonblocking; // write() is non-blocking
2619 writeq_T ch_writeque; // header for write queue
Bram Moolenaar42d38a22016-02-20 18:18:59 +01002620
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02002621 cbq_T ch_cb_head; // dummy node for per-request callbacks
2622 callback_T ch_callback; // call when a msg is not handled
Bram Moolenaar014069a2016-03-03 22:51:40 +01002623
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02002624 bufref_T ch_bufref; // buffer to read from or write to
2625 int ch_nomodifiable; // TRUE when buffer can be 'nomodifiable'
2626 int ch_nomod_error; // TRUE when e_modifiable was given
2627 int ch_buf_append; // write appended lines instead top-bot
2628 linenr_T ch_buf_top; // next line to send
2629 linenr_T ch_buf_bot; // last line to send
Bram Moolenaar42d38a22016-02-20 18:18:59 +01002630} chanpart_T;
Bram Moolenaar7b3ca762016-02-14 19:13:43 +01002631
Bram Moolenaar6463ca22016-02-13 17:04:46 +01002632struct channel_S {
Bram Moolenaar77073442016-02-13 23:23:53 +01002633 channel_T *ch_next;
2634 channel_T *ch_prev;
2635
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02002636 int ch_id; // ID of the channel
2637 int ch_last_msg_id; // ID of the last message
Bram Moolenaar77073442016-02-13 23:23:53 +01002638
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02002639 chanpart_T ch_part[PART_COUNT]; // info for socket, out, err and in
2640 int ch_write_text_mode; // write buffer lines with CR, not NL
Bram Moolenaar6463ca22016-02-13 17:04:46 +01002641
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02002642 char *ch_hostname; // only for socket, allocated
2643 int ch_port; // only for socket
Bram Moolenaar580984e2016-03-20 21:17:13 +01002644
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02002645 int ch_to_be_closed; // bitset of readable fds to be closed.
2646 // When all readable fds have been closed,
2647 // set to (1 << PART_COUNT).
2648 int ch_to_be_freed; // When TRUE channel must be freed when it's
2649 // safe to invoke callbacks.
2650 int ch_error; // When TRUE an error was reported. Avoids
2651 // giving pages full of error messages when
2652 // the other side has exited, only mention the
2653 // first error until the connection works
2654 // again.
Bram Moolenaar16eb4f82016-02-14 23:02:34 +01002655
Bram Moolenaar4e221c92016-02-23 13:20:22 +01002656 void (*ch_nb_close_cb)(void);
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02002657 // callback for Netbeans when channel is
2658 // closed
Bram Moolenaar6463ca22016-02-13 17:04:46 +01002659
Bram Moolenaar4f974752019-02-17 17:44:42 +01002660#ifdef MSWIN
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02002661 int ch_named_pipe; // using named pipe instead of pty
Bram Moolenaar2dc9d262017-09-08 14:39:30 +02002662#endif
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02002663 callback_T ch_callback; // call when any msg is not handled
2664 callback_T ch_close_cb; // call when channel is closed
Bram Moolenaar958dc692016-12-01 15:34:12 +01002665 int ch_drop_never;
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02002666 int ch_keep_open; // do not close on read error
Bram Moolenaar0b146882018-09-06 16:27:24 +02002667 int ch_nonblock;
Bram Moolenaar6463ca22016-02-13 17:04:46 +01002668
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01002669 job_T *ch_job; // Job that uses this channel; this does not
2670 // count as a reference to avoid a circular
2671 // reference, the job refers to the channel.
2672 int ch_job_killed; // TRUE when there was a job and it was killed
2673 // or we know it died.
2674 int ch_anonymous_pipe; // ConPTY
2675 int ch_killing; // TerminateJobObject() was called
Bram Moolenaar77073442016-02-13 23:23:53 +01002676
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01002677 int ch_refcount; // reference count
Bram Moolenaar107e1ee2016-04-08 17:07:19 +02002678 int ch_copyID;
Bram Moolenaar6463ca22016-02-13 17:04:46 +01002679};
2680
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02002681#define JO_MODE 0x0001 // channel mode
2682#define JO_IN_MODE 0x0002 // stdin mode
2683#define JO_OUT_MODE 0x0004 // stdout mode
2684#define JO_ERR_MODE 0x0008 // stderr mode
2685#define JO_CALLBACK 0x0010 // channel callback
2686#define JO_OUT_CALLBACK 0x0020 // stdout callback
2687#define JO_ERR_CALLBACK 0x0040 // stderr callback
2688#define JO_CLOSE_CALLBACK 0x0080 // "close_cb"
2689#define JO_WAITTIME 0x0100 // only for ch_open()
2690#define JO_TIMEOUT 0x0200 // all timeouts
2691#define JO_OUT_TIMEOUT 0x0400 // stdout timeouts
2692#define JO_ERR_TIMEOUT 0x0800 // stderr timeouts
2693#define JO_PART 0x1000 // "part"
2694#define JO_ID 0x2000 // "id"
2695#define JO_STOPONEXIT 0x4000 // "stoponexit"
2696#define JO_EXIT_CB 0x8000 // "exit_cb"
2697#define JO_OUT_IO 0x10000 // "out_io"
2698#define JO_ERR_IO 0x20000 // "err_io" (JO_OUT_IO << 1)
2699#define JO_IN_IO 0x40000 // "in_io" (JO_OUT_IO << 2)
2700#define JO_OUT_NAME 0x80000 // "out_name"
2701#define JO_ERR_NAME 0x100000 // "err_name" (JO_OUT_NAME << 1)
2702#define JO_IN_NAME 0x200000 // "in_name" (JO_OUT_NAME << 2)
2703#define JO_IN_TOP 0x400000 // "in_top"
2704#define JO_IN_BOT 0x800000 // "in_bot"
2705#define JO_OUT_BUF 0x1000000 // "out_buf"
2706#define JO_ERR_BUF 0x2000000 // "err_buf" (JO_OUT_BUF << 1)
2707#define JO_IN_BUF 0x4000000 // "in_buf" (JO_OUT_BUF << 2)
2708#define JO_CHANNEL 0x8000000 // "channel"
2709#define JO_BLOCK_WRITE 0x10000000 // "block_write"
2710#define JO_OUT_MODIFIABLE 0x20000000 // "out_modifiable"
2711#define JO_ERR_MODIFIABLE 0x40000000 // "err_modifiable" (JO_OUT_ << 1)
Bram Moolenaar8b877ac2016-03-28 19:16:20 +02002712#define JO_ALL 0x7fffffff
Bram Moolenaar40ea1da2016-02-19 22:33:35 +01002713
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02002714#define JO2_OUT_MSG 0x0001 // "out_msg"
2715#define JO2_ERR_MSG 0x0002 // "err_msg" (JO_OUT_ << 1)
2716#define JO2_TERM_NAME 0x0004 // "term_name"
2717#define JO2_TERM_FINISH 0x0008 // "term_finish"
2718#define JO2_ENV 0x0010 // "env"
2719#define JO2_CWD 0x0020 // "cwd"
2720#define JO2_TERM_ROWS 0x0040 // "term_rows"
2721#define JO2_TERM_COLS 0x0080 // "term_cols"
2722#define JO2_VERTICAL 0x0100 // "vertical"
2723#define JO2_CURWIN 0x0200 // "curwin"
2724#define JO2_HIDDEN 0x0400 // "hidden"
2725#define JO2_TERM_OPENCMD 0x0800 // "term_opencmd"
2726#define JO2_EOF_CHARS 0x1000 // "eof_chars"
2727#define JO2_NORESTORE 0x2000 // "norestore"
2728#define JO2_TERM_KILL 0x4000 // "term_kill"
2729#define JO2_ANSI_COLORS 0x8000 // "ansi_colors"
2730#define JO2_TTY_TYPE 0x10000 // "tty_type"
2731#define JO2_BUFNR 0x20000 // "bufnr"
Bram Moolenaard2842ea2019-09-26 23:08:54 +02002732#define JO2_TERM_API 0x40000 // "term_api"
Bram Moolenaar83d47902020-03-26 20:34:00 +01002733#define JO2_TERM_HIGHLIGHT 0x80000 // "highlight"
Bram Moolenaar169ebb02016-09-07 23:32:23 +02002734
Bram Moolenaarb6b52522016-02-20 23:30:07 +01002735#define JO_MODE_ALL (JO_MODE + JO_IN_MODE + JO_OUT_MODE + JO_ERR_MODE)
Bram Moolenaar4e221c92016-02-23 13:20:22 +01002736#define JO_CB_ALL \
2737 (JO_CALLBACK + JO_OUT_CALLBACK + JO_ERR_CALLBACK + JO_CLOSE_CALLBACK)
Bram Moolenaarb6b52522016-02-20 23:30:07 +01002738#define JO_TIMEOUT_ALL (JO_TIMEOUT + JO_OUT_TIMEOUT + JO_ERR_TIMEOUT)
2739
Bram Moolenaar9a6e33a2016-02-16 19:25:12 +01002740/*
Bram Moolenaar910b8aa2016-02-16 21:03:07 +01002741 * Options for job and channel commands.
Bram Moolenaar9a6e33a2016-02-16 19:25:12 +01002742 */
2743typedef struct
2744{
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02002745 int jo_set; // JO_ bits for values that were set
2746 int jo_set2; // JO2_ bits for values that were set
Bram Moolenaar40ea1da2016-02-19 22:33:35 +01002747
2748 ch_mode_T jo_mode;
Bram Moolenaarb6b52522016-02-20 23:30:07 +01002749 ch_mode_T jo_in_mode;
2750 ch_mode_T jo_out_mode;
2751 ch_mode_T jo_err_mode;
Bram Moolenaar0b146882018-09-06 16:27:24 +02002752 int jo_noblock;
Bram Moolenaar187db502016-02-27 14:44:26 +01002753
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02002754 job_io_T jo_io[4]; // PART_OUT, PART_ERR, PART_IN
Bram Moolenaar187db502016-02-27 14:44:26 +01002755 char_u jo_io_name_buf[4][NUMBUFLEN];
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02002756 char_u *jo_io_name[4]; // not allocated!
Bram Moolenaar29fd0382016-03-09 23:14:07 +01002757 int jo_io_buf[4];
Bram Moolenaar5a1feb82017-07-22 18:04:08 +02002758 int jo_pty;
Bram Moolenaar9f5842e2016-05-29 16:17:08 +02002759 int jo_modifiable[4];
Bram Moolenaar169ebb02016-09-07 23:32:23 +02002760 int jo_message[4];
Bram Moolenaarde279892016-03-11 22:19:44 +01002761 channel_T *jo_channel;
Bram Moolenaar187db502016-02-27 14:44:26 +01002762
Bram Moolenaar014069a2016-03-03 22:51:40 +01002763 linenr_T jo_in_top;
2764 linenr_T jo_in_bot;
2765
Bram Moolenaar3a97bb32019-06-01 13:28:35 +02002766 callback_T jo_callback;
2767 callback_T jo_out_cb;
2768 callback_T jo_err_cb;
2769 callback_T jo_close_cb;
2770 callback_T jo_exit_cb;
Bram Moolenaar958dc692016-12-01 15:34:12 +01002771 int jo_drop_never;
Bram Moolenaar40ea1da2016-02-19 22:33:35 +01002772 int jo_waittime;
2773 int jo_timeout;
Bram Moolenaarb6b52522016-02-20 23:30:07 +01002774 int jo_out_timeout;
2775 int jo_err_timeout;
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02002776 int jo_block_write; // for testing only
Bram Moolenaar6f3a5442016-02-20 19:56:13 +01002777 int jo_part;
2778 int jo_id;
Bram Moolenaar21109272020-01-30 16:27:20 +01002779 char_u jo_stoponexit_buf[NUMBUFLEN];
Bram Moolenaar65edff82016-02-21 16:40:11 +01002780 char_u *jo_stoponexit;
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02002781 dict_T *jo_env; // environment variables
Bram Moolenaar05aafed2017-08-11 19:12:11 +02002782 char_u jo_cwd_buf[NUMBUFLEN];
2783 char_u *jo_cwd;
Bram Moolenaar58556cd2017-07-20 23:04:46 +02002784
2785#ifdef FEAT_TERMINAL
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02002786 // when non-zero run the job in a terminal window of this size
Bram Moolenaar58556cd2017-07-20 23:04:46 +02002787 int jo_term_rows;
2788 int jo_term_cols;
Bram Moolenaar08d384f2017-08-11 21:51:23 +02002789 int jo_vertical;
Bram Moolenaarda43b612017-08-11 22:27:50 +02002790 int jo_curwin;
Bram Moolenaar87abab92019-06-03 21:14:59 +02002791 buf_T *jo_bufnr_buf;
Bram Moolenaar8cad9302017-08-12 14:32:32 +02002792 int jo_hidden;
Bram Moolenaar4d8bac82018-03-09 21:33:34 +01002793 int jo_term_norestore;
Bram Moolenaar21109272020-01-30 16:27:20 +01002794 char_u jo_term_name_buf[NUMBUFLEN];
Bram Moolenaar78712a72017-08-05 14:50:12 +02002795 char_u *jo_term_name;
Bram Moolenaar21109272020-01-30 16:27:20 +01002796 char_u jo_term_opencmd_buf[NUMBUFLEN];
Bram Moolenaar37c45832017-08-12 16:01:04 +02002797 char_u *jo_term_opencmd;
Bram Moolenaardd693ce2017-08-10 23:15:19 +02002798 int jo_term_finish;
Bram Moolenaar21109272020-01-30 16:27:20 +01002799 char_u jo_eof_chars_buf[NUMBUFLEN];
Bram Moolenaar3346cc42017-09-02 14:54:21 +02002800 char_u *jo_eof_chars;
Bram Moolenaar21109272020-01-30 16:27:20 +01002801 char_u jo_term_kill_buf[NUMBUFLEN];
Bram Moolenaar25cdd9c2018-03-10 20:28:12 +01002802 char_u *jo_term_kill;
Bram Moolenaarf59c6e82018-04-10 15:59:11 +02002803# if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS)
2804 long_u jo_ansi_colors[16];
2805# endif
Bram Moolenaar83d47902020-03-26 20:34:00 +01002806 char_u jo_term_highlight_buf[NUMBUFLEN];
2807 char_u *jo_term_highlight;
Bram Moolenaarc6ddce32019-02-08 12:47:03 +01002808 int jo_tty_type; // first character of "tty_type"
Bram Moolenaard2842ea2019-09-26 23:08:54 +02002809 char_u jo_term_api_buf[NUMBUFLEN];
Bram Moolenaar21109272020-01-30 16:27:20 +01002810 char_u *jo_term_api;
Bram Moolenaar58556cd2017-07-20 23:04:46 +02002811#endif
Bram Moolenaar9a6e33a2016-02-16 19:25:12 +01002812} jobopt_T;
2813
Bram Moolenaar6d2399b2019-05-11 19:14:16 +02002814#ifdef FEAT_EVAL
2815/*
2816 * Structure used for listeners added with listener_add().
2817 */
2818typedef struct listener_S listener_T;
2819struct listener_S
2820{
2821 listener_T *lr_next;
2822 int lr_id;
Bram Moolenaar3a97bb32019-06-01 13:28:35 +02002823 callback_T lr_callback;
Bram Moolenaar6d2399b2019-05-11 19:14:16 +02002824};
2825#endif
Bram Moolenaar6463ca22016-02-13 17:04:46 +01002826
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02002827/*
2828 * structure used for explicit stack while garbage collecting hash tables
2829 */
Bram Moolenaar2459a5e2015-02-03 12:55:18 +01002830typedef struct ht_stack_S
2831{
2832 hashtab_T *ht;
2833 struct ht_stack_S *prev;
2834} ht_stack_T;
2835
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02002836/*
2837 * structure used for explicit stack while garbage collecting lists
2838 */
Bram Moolenaar2459a5e2015-02-03 12:55:18 +01002839typedef struct list_stack_S
2840{
2841 list_T *list;
2842 struct list_stack_S *prev;
2843} list_stack_T;
2844
Bram Moolenaar45e18cb2019-04-28 18:05:35 +02002845/*
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01002846 * structure used for explicit stack while garbage collecting tuples
2847 */
2848typedef struct tuple_stack_S
2849{
2850 tuple_T *tuple;
2851 struct tuple_stack_S *prev;
2852} tuple_stack_T;
2853
2854/*
Bram Moolenaar45e18cb2019-04-28 18:05:35 +02002855 * Structure used for iterating over dictionary items.
2856 * Initialize with dict_iterate_start().
2857 */
2858typedef struct
2859{
2860 long_u dit_todo;
2861 hashitem_T *dit_hi;
2862} dict_iterator_T;
2863
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02002864// values for b_syn_spell: what to do with toplevel text
2865#define SYNSPL_DEFAULT 0 // spell check if @Spell not defined
2866#define SYNSPL_TOP 1 // spell check toplevel text
2867#define SYNSPL_NOTOP 2 // don't spell check toplevel text
Bram Moolenaarce0842a2005-07-18 21:58:11 +00002868
Bram Moolenaare35a52a2020-05-31 19:48:53 +02002869// values for b_syn_foldlevel: how to compute foldlevel on a line
2870#define SYNFLD_START 0 // use level of item at start of line
2871#define SYNFLD_MINIMUM 1 // use lowest local minimum level on line
2872
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02002873// avoid #ifdefs for when b_spell is not available
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002874#ifdef FEAT_SPELL
Bram Moolenaar4770d092006-01-12 23:22:24 +00002875# define B_SPELL(buf) ((buf)->b_spell)
2876#else
2877# define B_SPELL(buf) (0)
2878#endif
2879
Bram Moolenaard12f5c12006-01-25 22:10:52 +00002880typedef struct qf_info_S qf_info_T;
Bram Moolenaardcaf10e2005-01-21 11:55:25 +00002881
Bram Moolenaarf7512552013-06-06 14:55:19 +02002882#ifdef FEAT_PROFILE
Bram Moolenaar8a7f5a22013-06-06 14:01:46 +02002883/*
2884 * Used for :syntime: timing of executing a syntax pattern.
2885 */
2886typedef struct {
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02002887 proftime_T total; // total time used
2888 proftime_T slowest; // time of slowest call
2889 long count; // nr of times used
2890 long match; // nr of times matched
Bram Moolenaar8a7f5a22013-06-06 14:01:46 +02002891} syn_time_T;
2892#endif
2893
Bram Moolenaar51fe3b12019-05-26 20:10:06 +02002894typedef struct timer_S timer_T;
2895struct timer_S
2896{
2897 long tr_id;
2898#ifdef FEAT_TIMERS
2899 timer_T *tr_next;
2900 timer_T *tr_prev;
Bram Moolenaar3a97bb32019-06-01 13:28:35 +02002901 proftime_T tr_due; // when the callback is to be invoked
2902 char tr_firing; // when TRUE callback is being called
2903 char tr_paused; // when TRUE callback is not invoked
Bram Moolenaar9198de32022-08-27 21:30:03 +01002904 char tr_keep; // when TRUE keep timer after it fired
Bram Moolenaar3a97bb32019-06-01 13:28:35 +02002905 int tr_repeat; // number of times to repeat, -1 forever
2906 long tr_interval; // msec
2907 callback_T tr_callback;
Bram Moolenaar51fe3b12019-05-26 20:10:06 +02002908 int tr_emsg_count;
2909#endif
2910};
2911
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02002912#ifdef FEAT_CRYPT
2913/*
2914 * Structure to hold the type of encryption and the state of encryption or
2915 * decryption.
2916 */
2917typedef struct {
2918 int method_nr;
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02002919 void *method_state; // method-specific state information
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02002920} cryptstate_T;
2921
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02002922// values for method_nr
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02002923# define CRYPT_M_ZIP 0
2924# define CRYPT_M_BF 1
2925# define CRYPT_M_BF2 2
Christian Brabandtf573c6e2021-06-20 14:02:16 +02002926# define CRYPT_M_SOD 3
Christian Brabandtaae58342023-04-23 17:50:22 +01002927# define CRYPT_M_SOD2 4
2928# define CRYPT_M_COUNT 5 // number of crypt methods
Bram Moolenaar987411d2019-01-18 22:48:34 +01002929
2930// Currently all crypt methods work inplace. If one is added that isn't then
2931// define this.
Christian Brabandtf573c6e2021-06-20 14:02:16 +02002932# define CRYPT_NOT_INPLACE 1
Christian Brabandtaae58342023-04-23 17:50:22 +01002933
2934// Struct for passing arguments down to the crypt_init functions
2935typedef struct {
2936 char_u *cat_salt;
2937 int cat_salt_len;
2938 char_u *cat_seed;
2939 int cat_seed_len;
2940 char_u *cat_add;
2941 int cat_add_len;
2942 int cat_init_from_file;
2943} crypt_arg_T;
2944
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02002945#endif
2946
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01002947#ifdef FEAT_PROP_POPUP
Bram Moolenaarac1f1bc2019-05-30 21:24:26 +02002948typedef enum {
2949 POPPOS_BOTLEFT,
2950 POPPOS_TOPLEFT,
2951 POPPOS_BOTRIGHT,
2952 POPPOS_TOPRIGHT,
Bram Moolenaar4dd8fe02019-11-09 15:33:31 +01002953 POPPOS_CENTER,
Bram Moolenaar37fef162022-08-29 18:16:32 +01002954 POPPOS_BOTTOM, // bottom of popup just above the command line
Bram Moolenaar4dd8fe02019-11-09 15:33:31 +01002955 POPPOS_NONE
Bram Moolenaarac1f1bc2019-05-30 21:24:26 +02002956} poppos_T;
Bram Moolenaar6c009a32019-06-08 16:06:28 +02002957
Bram Moolenaar2e62b562019-06-30 18:07:00 +02002958typedef enum {
2959 POPCLOSE_NONE,
2960 POPCLOSE_BUTTON,
2961 POPCLOSE_CLICK
2962} popclose_T;
2963
Bram Moolenaar68d48f42019-06-12 22:42:41 +02002964# define POPUPWIN_DEFAULT_ZINDEX 50
2965# define POPUPMENU_ZINDEX 100
Bram Moolenaara42d9452019-06-15 21:46:30 +02002966# define POPUPWIN_DIALOG_ZINDEX 200
2967# define POPUPWIN_NOTIFICATION_ZINDEX 300
Bram Moolenaarac1f1bc2019-05-30 21:24:26 +02002968#endif
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02002969
Bram Moolenaar362ce482012-06-06 19:02:45 +02002970/*
2971 * These are items normally related to a buffer. But when using ":ownsyntax"
2972 * a window may have its own instance.
2973 */
Bram Moolenaar860cae12010-06-05 23:22:07 +02002974typedef struct {
2975#ifdef FEAT_SYN_HL
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02002976 hashtab_T b_keywtab; // syntax keywords hash table
2977 hashtab_T b_keywtab_ic; // idem, ignore case
2978 int b_syn_error; // TRUE when error occurred in HL
Bram Moolenaar06f1ed22017-06-18 22:41:03 +02002979# ifdef FEAT_RELTIME
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02002980 int b_syn_slow; // TRUE when 'redrawtime' reached
Bram Moolenaar06f1ed22017-06-18 22:41:03 +02002981# endif
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02002982 int b_syn_ic; // ignore case for :syn cmds
Bram Moolenaare35a52a2020-05-31 19:48:53 +02002983 int b_syn_foldlevel; // how to compute foldlevel on a line
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02002984 int b_syn_spell; // SYNSPL_ values
2985 garray_T b_syn_patterns; // table for syntax patterns
2986 garray_T b_syn_clusters; // table for syntax clusters
2987 int b_spell_cluster_id; // @Spell cluster ID or 0
2988 int b_nospell_cluster_id; // @NoSpell cluster ID or 0
2989 int b_syn_containedin; // TRUE when there is an item with a
2990 // "containedin" argument
2991 int b_syn_sync_flags; // flags about how to sync
2992 short b_syn_sync_id; // group to sync on
2993 long b_syn_sync_minlines; // minimal sync lines offset
2994 long b_syn_sync_maxlines; // maximal sync lines offset
2995 long b_syn_sync_linebreaks; // offset for multi-line pattern
2996 char_u *b_syn_linecont_pat; // line continuation pattern
2997 regprog_T *b_syn_linecont_prog; // line continuation program
Bram Moolenaarf7512552013-06-06 14:55:19 +02002998#ifdef FEAT_PROFILE
Bram Moolenaar8a7f5a22013-06-06 14:01:46 +02002999 syn_time_T b_syn_linecont_time;
3000#endif
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003001 int b_syn_linecont_ic; // ignore-case flag for above
3002 int b_syn_topgrp; // for ":syntax include"
Bram Moolenaar860cae12010-06-05 23:22:07 +02003003# ifdef FEAT_CONCEAL
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003004 int b_syn_conceal; // auto-conceal for :syn cmds
Bram Moolenaar860cae12010-06-05 23:22:07 +02003005# endif
3006# ifdef FEAT_FOLDING
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003007 int b_syn_folditems; // number of patterns with the HL_FOLD
3008 // flag set
Bram Moolenaar860cae12010-06-05 23:22:07 +02003009# endif
Bram Moolenaar8765a4a2010-07-27 22:41:43 +02003010 /*
3011 * b_sst_array[] contains the state stack for a number of lines, for the
3012 * start of that line (col == 0). This avoids having to recompute the
3013 * syntax state too often.
3014 * b_sst_array[] is allocated to hold the state for all displayed lines,
3015 * and states for 1 out of about 20 other lines.
3016 * b_sst_array pointer to an array of synstate_T
3017 * b_sst_len number of entries in b_sst_array[]
3018 * b_sst_first pointer to first used entry in b_sst_array[] or NULL
3019 * b_sst_firstfree pointer to first free entry in b_sst_array[] or NULL
3020 * b_sst_freecount number of free entries in b_sst_array[]
3021 * b_sst_check_lnum entries after this lnum need to be checked for
3022 * validity (MAXLNUM means no check needed)
3023 */
Bram Moolenaar860cae12010-06-05 23:22:07 +02003024 synstate_T *b_sst_array;
3025 int b_sst_len;
3026 synstate_T *b_sst_first;
3027 synstate_T *b_sst_firstfree;
3028 int b_sst_freecount;
3029 linenr_T b_sst_check_lnum;
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003030 short_u b_sst_lasttick; // last display tick
3031#endif // FEAT_SYN_HL
Bram Moolenaar860cae12010-06-05 23:22:07 +02003032
3033#ifdef FEAT_SPELL
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003034 // for spell checking
3035 garray_T b_langp; // list of pointers to slang_T, see spell.c
3036 char_u b_spell_ismw[256]; // flags: is midword char
3037 char_u *b_spell_ismw_mb; // multi-byte midword chars
3038 char_u *b_p_spc; // 'spellcapcheck'
3039 regprog_T *b_cap_prog; // program for 'spellcapcheck'
3040 char_u *b_p_spf; // 'spellfile'
3041 char_u *b_p_spl; // 'spelllang'
Bram Moolenaar215f49c2020-06-10 22:12:04 +02003042 char_u *b_p_spo; // 'spelloptions'
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003043 int b_cjk; // all CJK letters as OK
Bram Moolenaar860cae12010-06-05 23:22:07 +02003044#endif
Bram Moolenaar8765a4a2010-07-27 22:41:43 +02003045#if !defined(FEAT_SYN_HL) && !defined(FEAT_SPELL)
3046 int dummy;
3047#endif
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003048 char_u b_syn_chartab[32]; // syntax iskeyword option
3049 char_u *b_syn_isk; // iskeyword option
Bram Moolenaar860cae12010-06-05 23:22:07 +02003050} synblock_T;
3051
3052
Bram Moolenaar071d4272004-06-13 20:20:40 +00003053/*
3054 * buffer: structure that holds information about one file
3055 *
3056 * Several windows can share a single Buffer
3057 * A buffer is unallocated if there is no memfile for it.
3058 * A buffer is new if the associated file has never been loaded yet.
3059 */
3060
Bram Moolenaar071d4272004-06-13 20:20:40 +00003061struct file_buffer
3062{
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003063 memline_T b_ml; // associated memline (also contains line
3064 // count)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003065
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003066 buf_T *b_next; // links in list of buffers
Bram Moolenaar071d4272004-06-13 20:20:40 +00003067 buf_T *b_prev;
3068
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003069 int b_nwindows; // nr of windows open on this buffer
Bram Moolenaar071d4272004-06-13 20:20:40 +00003070
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003071 int b_flags; // various BF_ flags
3072 int b_locked; // Buffer is being closed or referenced, don't
3073 // let autocommands wipe it out.
Bram Moolenaar983d83f2021-02-07 12:12:43 +01003074 int b_locked_split; // Buffer is being closed, don't allow opening
Sean Dewar6cb1c822025-05-03 18:37:27 +02003075 // it in more windows.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003076
3077 /*
3078 * b_ffname has the full path of the file (NULL for no name).
3079 * b_sfname is the name as the user typed it (or NULL).
3080 * b_fname is the same as b_sfname, unless ":cd" has been done,
3081 * then it is the same as b_ffname (NULL for no name).
3082 */
Bram Moolenaar3d6014f2018-10-11 19:27:47 +02003083 char_u *b_ffname; // full path file name, allocated
3084 char_u *b_sfname; // short file name, allocated, may be equal to
3085 // b_ffname
3086 char_u *b_fname; // current file name, points to b_ffname or
3087 // b_sfname
Bram Moolenaar071d4272004-06-13 20:20:40 +00003088
3089#ifdef UNIX
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003090 int b_dev_valid; // TRUE when b_dev has a valid number
3091 dev_t b_dev; // device number
3092 ino_t b_ino; // inode number
Bram Moolenaar071d4272004-06-13 20:20:40 +00003093#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003094#ifdef VMS
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003095 char b_fab_rfm; // Record format
3096 char b_fab_rat; // Record attribute
3097 unsigned int b_fab_mrs; // Max record size
Bram Moolenaar071d4272004-06-13 20:20:40 +00003098#endif
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003099 int b_fnum; // buffer number for this file.
Bram Moolenaar480778b2016-07-14 22:09:39 +02003100 char_u b_key[VIM_SIZEOF_INT * 2 + 1];
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003101 // key used for buf_hashtab, holds b_fnum as
3102 // hex string
Bram Moolenaar071d4272004-06-13 20:20:40 +00003103
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003104 int b_changed; // 'modified': Set to TRUE if something in the
3105 // file has been changed and not written out.
3106 dictitem16_T b_ct_di; // holds the b:changedtick value in
3107 // b_ct_di.di_tv.vval.v_number;
3108 // incremented for each change, also for undo
Bram Moolenaar95c526e2017-02-25 14:59:34 +01003109#define CHANGEDTICK(buf) ((buf)->b_ct_di.di_tv.vval.v_number)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003110
Christian Brabandtdb3b4462021-10-16 11:58:55 +01003111 varnumber_T b_last_changedtick; // b:changedtick when TextChanged was
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003112 // last triggered.
Christian Brabandtdb3b4462021-10-16 11:58:55 +01003113 varnumber_T b_last_changedtick_pum; // b:changedtick for TextChangedP
3114 varnumber_T b_last_changedtick_i; // b:changedtick for TextChangedI
Bram Moolenaar5a093432018-02-10 18:15:19 +01003115
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003116 int b_saving; // Set to TRUE if we are in the middle of
3117 // saving the buffer.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003118
3119 /*
3120 * Changes to a buffer require updating of the display. To minimize the
3121 * work, remember changes made and update everything at once.
3122 */
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003123 int b_mod_set; // TRUE when there are changes since the last
3124 // time the display was updated
3125 linenr_T b_mod_top; // topmost lnum that was changed
3126 linenr_T b_mod_bot; // lnum below last changed line, AFTER the
3127 // change
3128 long b_mod_xlines; // number of extra buffer lines inserted;
3129 // negative when lines were deleted
Bram Moolenaar071d4272004-06-13 20:20:40 +00003130
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003131 wininfo_T *b_wininfo; // list of last used info for each window
Bram Moolenaar071d4272004-06-13 20:20:40 +00003132
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003133 long b_mtime; // last change time of original file
Leah Neukirchen0a7984a2021-10-14 21:27:55 +01003134 long b_mtime_ns; // nanoseconds of last change time
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003135 long b_mtime_read; // last change time when reading
Leah Neukirchen0a7984a2021-10-14 21:27:55 +01003136 long b_mtime_read_ns; // nanoseconds of last read time
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003137 off_T b_orig_size; // size of original file in bytes
3138 int b_orig_mode; // mode of original file
Bram Moolenaarab9c89b2016-07-03 17:47:26 +02003139#ifdef FEAT_VIMINFO
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003140 time_T b_last_used; // time when the buffer was last used; used
3141 // for viminfo
Bram Moolenaarab9c89b2016-07-03 17:47:26 +02003142#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003143
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003144 pos_T b_namedm[NMARKS]; // current named marks (mark.c)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003145
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003146 // These variables are set when VIsual_active becomes FALSE
Bram Moolenaara23ccb82006-02-27 00:08:02 +00003147 visualinfo_T b_visual;
Bram Moolenaarf7ff6e82014-03-23 15:13:05 +01003148#ifdef FEAT_EVAL
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003149 int b_visual_mode_eval; // b_visual.vi_mode for visualmode()
Bram Moolenaar071d4272004-06-13 20:20:40 +00003150#endif
3151
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003152 pos_T b_last_cursor; // cursor position when last unloading this
3153 // buffer
3154 pos_T b_last_insert; // where Insert mode was left
3155 pos_T b_last_change; // position of last change: '. mark
Bram Moolenaar071d4272004-06-13 20:20:40 +00003156
Bram Moolenaar071d4272004-06-13 20:20:40 +00003157 /*
3158 * the changelist contains old change positions
3159 */
3160 pos_T b_changelist[JUMPLISTSIZE];
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003161 int b_changelistlen; // number of active entries
3162 int b_new_change; // set by u_savecommon()
Bram Moolenaar071d4272004-06-13 20:20:40 +00003163
3164 /*
3165 * Character table, only used in charset.c for 'iskeyword'
3166 * 32 bytes of 8 bits: 1 bit per character 0-255.
3167 */
3168 char_u b_chartab[32];
3169
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003170 // Table used for mappings local to a buffer.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003171 mapblock_T *(b_maphash[256]);
3172
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003173 // First abbreviation local to a buffer.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003174 mapblock_T *b_first_abbr;
Bram Moolenaarb66bab32019-08-01 14:28:24 +02003175
Bram Moolenaarac9fb182019-04-27 13:04:13 +02003176 // User commands local to the buffer.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003177 garray_T b_ucmds;
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003178 // start and end of an operator, also used for '[ and ']
Bram Moolenaar071d4272004-06-13 20:20:40 +00003179 pos_T b_op_start;
Bram Moolenaar4aea03e2019-09-25 22:37:17 +02003180 pos_T b_op_start_orig; // used for Insstart_orig
Bram Moolenaar071d4272004-06-13 20:20:40 +00003181 pos_T b_op_end;
3182
3183#ifdef FEAT_VIMINFO
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003184 int b_marks_read; // Have we read viminfo marks yet?
Bram Moolenaar071d4272004-06-13 20:20:40 +00003185#endif
3186
zeertzjq5bf6c212024-03-31 18:41:27 +02003187 int b_modified_was_set; // did ":set modified"
3188 int b_did_filetype; // FileType event found
3189 int b_keep_filetype; // value for did_filetype when starting
3190 // to execute autocommands
3191
3192 // Set by the apply_autocmds_group function if the given event is equal to
3193 // EVENT_FILETYPE. Used by the readfile function in order to determine if
3194 // EVENT_BUFREADPOST triggered the EVENT_FILETYPE.
3195 //
3196 // Relying on this value requires one to reset it prior calling
3197 // apply_autocmds_group().
3198 int b_au_did_filetype;
3199
Bram Moolenaar071d4272004-06-13 20:20:40 +00003200 /*
3201 * The following only used in undo.c.
3202 */
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003203 u_header_T *b_u_oldhead; // pointer to oldest header
3204 u_header_T *b_u_newhead; // pointer to newest header; may not be valid
3205 // if b_u_curhead is not NULL
3206 u_header_T *b_u_curhead; // pointer to current header
3207 int b_u_numhead; // current number of headers
3208 int b_u_synced; // entry lists are synced
3209 long b_u_seq_last; // last used undo sequence number
3210 long b_u_save_nr_last; // counter for last file write
Bram Moolenaar1d84f762022-09-03 21:35:53 +01003211 long b_u_seq_cur; // uh_seq of header below which we are now
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003212 time_T b_u_time_cur; // uh_time of header below which we are now
3213 long b_u_save_nr_cur; // file write nr after which we are now
Bram Moolenaar071d4272004-06-13 20:20:40 +00003214
3215 /*
3216 * variables for "U" command in undo.c
3217 */
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003218 undoline_T b_u_line_ptr; // saved line for "U" command
3219 linenr_T b_u_line_lnum; // line number of line in u_line
3220 colnr_T b_u_line_colnr; // optional column number
Bram Moolenaar071d4272004-06-13 20:20:40 +00003221
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003222 int b_scanned; // ^N/^P have scanned this buffer
Bram Moolenaar071d4272004-06-13 20:20:40 +00003223
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003224 // flags for use of ":lmap" and IM control
3225 long b_p_iminsert; // input mode for insert
3226 long b_p_imsearch; // input mode for search
kylo2529dac9b12022-03-27 20:05:17 +01003227#define B_IMODE_USE_INSERT (-1) // Use b_p_iminsert value for search
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003228#define B_IMODE_NONE 0 // Input via none
3229#define B_IMODE_LMAP 1 // Input via langmap
3230#define B_IMODE_IM 2 // Input via input method
Bram Moolenaar6315a9a2017-11-25 15:20:02 +01003231#define B_IMODE_LAST 2
Bram Moolenaar071d4272004-06-13 20:20:40 +00003232
3233#ifdef FEAT_KEYMAP
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003234 short b_kmap_state; // using "lmap" mappings
3235# define KEYMAP_INIT 1 // 'keymap' was set, call keymap_init()
3236# define KEYMAP_LOADED 2 // 'keymap' mappings have been loaded
3237 garray_T b_kmap_ga; // the keymap table
Bram Moolenaar071d4272004-06-13 20:20:40 +00003238#endif
3239
3240 /*
3241 * Options local to a buffer.
3242 * They are here because their value depends on the type of file
3243 * or contents of the file being edited.
3244 */
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003245 int b_p_initialized; // set when options initialized
Bram Moolenaar071d4272004-06-13 20:20:40 +00003246
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003247#ifdef FEAT_EVAL
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003248 sctx_T b_p_script_ctx[BV_COUNT]; // SCTXs for buffer-local options
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003249#endif
3250
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003251 int b_p_ai; // 'autoindent'
3252 int b_p_ai_nopaste; // b_p_ai saved for paste mode
3253 char_u *b_p_bkc; // 'backupcopy'
3254 unsigned b_bkc_flags; // flags for 'backupcopy'
3255 int b_p_ci; // 'copyindent'
3256 int b_p_bin; // 'binary'
3257 int b_p_bomb; // 'bomb'
3258 char_u *b_p_bh; // 'bufhidden'
3259 char_u *b_p_bt; // 'buftype'
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02003260#ifdef FEAT_QUICKFIX
Bram Moolenaarc1542742016-07-20 21:44:37 +02003261#define BUF_HAS_QF_ENTRY 1
3262#define BUF_HAS_LL_ENTRY 2
Bram Moolenaar2f095a42016-06-03 19:05:49 +02003263 int b_has_qf_entry;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003264#endif
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003265 int b_p_bl; // 'buflisted'
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003266 int b_p_cin; // 'cindent'
3267 char_u *b_p_cino; // 'cinoptions'
3268 char_u *b_p_cink; // 'cinkeys'
Tom Praschan3506cf32022-04-07 12:39:08 +01003269 char_u *b_p_cinsd; // 'cinscopedecls'
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003270 char_u *b_p_cinw; // 'cinwords'
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003271 char_u *b_p_com; // 'comments'
Bram Moolenaar071d4272004-06-13 20:20:40 +00003272#ifdef FEAT_FOLDING
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003273 char_u *b_p_cms; // 'commentstring'
Bram Moolenaar071d4272004-06-13 20:20:40 +00003274#endif
zeertzjq529b9ad2024-06-05 20:27:06 +02003275 char_u *b_p_cot; // 'completeopt' local value
3276 unsigned b_cot_flags; // flags for 'completeopt'
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003277 char_u *b_p_cpt; // 'complete'
Bram Moolenaarac3150d2019-07-28 16:36:39 +02003278#ifdef BACKSLASH_IN_FILENAME
3279 char_u *b_p_csl; // 'completeslash'
3280#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003281#ifdef FEAT_COMPL_FUNC
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003282 char_u *b_p_cfu; // 'completefunc'
Yegappan Lakshmanan8658c752021-12-03 11:09:29 +00003283 callback_T b_cfu_cb; // 'completefunc' callback
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003284 char_u *b_p_ofu; // 'omnifunc'
Yegappan Lakshmanan8658c752021-12-03 11:09:29 +00003285 callback_T b_ofu_cb; // 'omnifunc' callback
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00003286#endif
Bram Moolenaar45e18cb2019-04-28 18:05:35 +02003287#ifdef FEAT_EVAL
Yegappan Lakshmanan19916a82021-11-24 16:32:55 +00003288 char_u *b_p_tfu; // 'tagfunc' option value
3289 callback_T b_tfu_cb; // 'tagfunc' callback
Yegappan Lakshmanana13f3a42024-11-02 18:40:10 +01003290 char_u *b_p_ffu; // 'findfunc' option value
3291 callback_T b_ffu_cb; // 'findfunc' callback
Bram Moolenaar45e18cb2019-04-28 18:05:35 +02003292#endif
Bram Moolenaarfb0cf232022-10-22 11:25:19 +01003293 int b_p_eof; // 'endoffile'
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003294 int b_p_eol; // 'endofline'
3295 int b_p_fixeol; // 'fixendofline'
3296 int b_p_et; // 'expandtab'
3297 int b_p_et_nobin; // b_p_et saved for binary mode
3298 int b_p_et_nopaste; // b_p_et saved for paste mode
3299 char_u *b_p_fenc; // 'fileencoding'
3300 char_u *b_p_ff; // 'fileformat'
3301 char_u *b_p_ft; // 'filetype'
3302 char_u *b_p_fo; // 'formatoptions'
3303 char_u *b_p_flp; // 'formatlistpat'
3304 int b_p_inf; // 'infercase'
glepnirbcd59952025-04-24 21:48:35 +02003305 char_u *b_p_ise; // 'isexpand' local value
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003306 char_u *b_p_isk; // 'iskeyword'
Bram Moolenaar071d4272004-06-13 20:20:40 +00003307#ifdef FEAT_FIND_ID
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003308 char_u *b_p_def; // 'define' local value
3309 char_u *b_p_inc; // 'include'
Bram Moolenaar071d4272004-06-13 20:20:40 +00003310# ifdef FEAT_EVAL
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003311 char_u *b_p_inex; // 'includeexpr'
3312 long_u b_p_inex_flags; // flags for 'includeexpr'
Bram Moolenaar071d4272004-06-13 20:20:40 +00003313# endif
3314#endif
Bram Moolenaar8e145b82022-05-21 20:17:31 +01003315#if defined(FEAT_EVAL)
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003316 char_u *b_p_inde; // 'indentexpr'
3317 long_u b_p_inde_flags; // flags for 'indentexpr'
3318 char_u *b_p_indk; // 'indentkeys'
Bram Moolenaar071d4272004-06-13 20:20:40 +00003319#endif
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003320 char_u *b_p_fp; // 'formatprg'
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00003321#if defined(FEAT_EVAL)
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003322 char_u *b_p_fex; // 'formatexpr'
3323 long_u b_p_fex_flags; // flags for 'formatexpr'
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00003324#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003325#ifdef FEAT_CRYPT
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003326 char_u *b_p_key; // 'key'
Bram Moolenaar071d4272004-06-13 20:20:40 +00003327#endif
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003328 char_u *b_p_kp; // 'keywordprg'
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003329 int b_p_lisp; // 'lisp'
Bram Moolenaar4b082c42022-10-15 16:25:27 +01003330 char_u *b_p_lop; // 'lispoptions'
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003331 char_u *b_p_menc; // 'makeencoding'
3332 char_u *b_p_mps; // 'matchpairs'
3333 int b_p_ml; // 'modeline'
3334 int b_p_ml_nobin; // b_p_ml saved for binary mode
3335 int b_p_ma; // 'modifiable'
3336 char_u *b_p_nf; // 'nrformats'
3337 int b_p_pi; // 'preserveindent'
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003338 char_u *b_p_qe; // 'quoteescape'
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003339 int b_p_ro; // 'readonly'
3340 long b_p_sw; // 'shiftwidth'
3341 int b_p_sn; // 'shortname'
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003342 int b_p_si; // 'smartindent'
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003343 long b_p_sts; // 'softtabstop'
3344 long b_p_sts_nopaste; // b_p_sts saved for paste mode
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003345 char_u *b_p_sua; // 'suffixesadd'
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003346 int b_p_swf; // 'swapfile'
Bram Moolenaar071d4272004-06-13 20:20:40 +00003347#ifdef FEAT_SYN_HL
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003348 long b_p_smc; // 'synmaxcol'
3349 char_u *b_p_syn; // 'syntax'
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003350#endif
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003351 long b_p_ts; // 'tabstop'
3352 int b_p_tx; // 'textmode'
3353 long b_p_tw; // 'textwidth'
3354 long b_p_tw_nobin; // b_p_tw saved for binary mode
3355 long b_p_tw_nopaste; // b_p_tw saved for paste mode
3356 long b_p_wm; // 'wrapmargin'
3357 long b_p_wm_nobin; // b_p_wm saved for binary mode
3358 long b_p_wm_nopaste; // b_p_wm saved for paste mode
Bram Moolenaar04958cb2018-06-23 19:23:02 +02003359#ifdef FEAT_VARTABS
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003360 char_u *b_p_vsts; // 'varsofttabstop'
3361 int *b_p_vsts_array; // 'varsofttabstop' in internal format
3362 char_u *b_p_vsts_nopaste; // b_p_vsts saved for paste mode
3363 char_u *b_p_vts; // 'vartabstop'
3364 int *b_p_vts_array; // 'vartabstop' in internal format
Bram Moolenaar04958cb2018-06-23 19:23:02 +02003365#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003366#ifdef FEAT_KEYMAP
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003367 char_u *b_p_keymap; // 'keymap'
Bram Moolenaar071d4272004-06-13 20:20:40 +00003368#endif
3369
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003370 /*
3371 * local values for options which are normally global
3372 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003373#ifdef FEAT_QUICKFIX
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003374 char_u *b_p_gp; // 'grepprg' local value
3375 char_u *b_p_mp; // 'makeprg' local value
3376 char_u *b_p_efm; // 'errorformat' local value
Bram Moolenaar071d4272004-06-13 20:20:40 +00003377#endif
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003378 char_u *b_p_ep; // 'equalprg' local value
3379 char_u *b_p_path; // 'path' local value
3380 int b_p_ar; // 'autoread' local value
3381 char_u *b_p_tags; // 'tags' local value
3382 char_u *b_p_tc; // 'tagcase' local value
3383 unsigned b_tc_flags; // flags for 'tagcase'
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003384 char_u *b_p_dict; // 'dictionary' local value
3385 char_u *b_p_tsr; // 'thesaurus' local value
Bram Moolenaarf4d8b762021-10-17 14:13:09 +01003386#ifdef FEAT_COMPL_FUNC
3387 char_u *b_p_tsrfu; // 'thesaurusfunc' local value
Yegappan Lakshmanan8658c752021-12-03 11:09:29 +00003388 callback_T b_tsrfu_cb; // 'thesaurusfunc' callback
Bram Moolenaarf4d8b762021-10-17 14:13:09 +01003389#endif
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003390 long b_p_ul; // 'undolevels' local value
Bram Moolenaar55debbe2010-05-23 23:34:36 +02003391#ifdef FEAT_PERSISTENT_UNDO
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003392 int b_p_udf; // 'undofile'
Bram Moolenaar55debbe2010-05-23 23:34:36 +02003393#endif
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003394 char_u *b_p_lw; // 'lispwords' local value
Bram Moolenaare1fc5152018-04-21 19:49:08 +02003395#ifdef FEAT_TERMINAL
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003396 long b_p_twsl; // 'termwinscroll'
Bram Moolenaare1fc5152018-04-21 19:49:08 +02003397#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003398
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003399 /*
3400 * end of buffer options
3401 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003402
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003403 // values set from b_p_cino
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01003404 int b_ind_level;
3405 int b_ind_open_imag;
3406 int b_ind_no_brace;
3407 int b_ind_first_open;
3408 int b_ind_open_extra;
3409 int b_ind_close_extra;
3410 int b_ind_open_left_imag;
3411 int b_ind_jump_label;
3412 int b_ind_case;
3413 int b_ind_case_code;
3414 int b_ind_case_break;
3415 int b_ind_param;
3416 int b_ind_func_type;
3417 int b_ind_comment;
3418 int b_ind_in_comment;
3419 int b_ind_in_comment2;
3420 int b_ind_cpp_baseclass;
3421 int b_ind_continuation;
3422 int b_ind_unclosed;
3423 int b_ind_unclosed2;
3424 int b_ind_unclosed_noignore;
3425 int b_ind_unclosed_wrapped;
3426 int b_ind_unclosed_whiteok;
3427 int b_ind_matching_paren;
3428 int b_ind_paren_prev;
3429 int b_ind_maxparen;
3430 int b_ind_maxcomment;
3431 int b_ind_scopedecl;
3432 int b_ind_scopedecl_code;
3433 int b_ind_java;
3434 int b_ind_js;
3435 int b_ind_keep_case_label;
3436 int b_ind_hash_comment;
3437 int b_ind_cpp_namespace;
3438 int b_ind_if_for_while;
Bram Moolenaar7720ba82017-03-08 22:19:26 +01003439 int b_ind_cpp_extern_c;
Bram Moolenaard881b512020-05-31 17:49:30 +02003440 int b_ind_pragma;
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01003441
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003442 linenr_T b_no_eol_lnum; // non-zero lnum when last line of next binary
3443 // write should not have an end-of-line
Bram Moolenaarcab35ad2011-02-15 17:39:22 +01003444
Bram Moolenaar15775372022-10-29 20:01:52 +01003445 int b_start_eof; // last line had eof (CTRL-Z) when it was read
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003446 int b_start_eol; // last line had eol when it was read
3447 int b_start_ffc; // first char of 'ff' when edit started
3448 char_u *b_start_fenc; // 'fileencoding' when edit started or NULL
3449 int b_bad_char; // "++bad=" argument when edit started or 0
3450 int b_start_bomb; // 'bomb' when it was read
Bram Moolenaar071d4272004-06-13 20:20:40 +00003451
3452#ifdef FEAT_EVAL
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003453 dictitem_T b_bufvar; // variable for "b:" Dictionary
3454 dict_T *b_vars; // internal variables, local to buffer
Bram Moolenaar6d2399b2019-05-11 19:14:16 +02003455
3456 listener_T *b_listener;
Bram Moolenaardda41442019-05-16 22:11:47 +02003457 list_T *b_recorded_changes;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003458#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01003459#ifdef FEAT_PROP_POPUP
Bram Moolenaarb413d2e2018-12-25 23:15:46 +01003460 int b_has_textprop; // TRUE when text props were added
3461 hashtab_T *b_proptypes; // text property types local to buffer
Bram Moolenaare44336b2022-08-07 18:20:08 +01003462 proptype_T **b_proparray; // entries of b_proptypes sorted on tp_id
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01003463 garray_T b_textprop_text; // stores text for props, index by (-id - 1)
Bram Moolenaar98aefe72018-12-13 22:20:09 +01003464#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003465
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00003466#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003467 char_u *b_p_bexpr; // 'balloonexpr' local value
3468 long_u b_p_bexpr_flags;// flags for 'balloonexpr'
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00003469#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02003470#ifdef FEAT_CRYPT
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003471 char_u *b_p_cm; // 'cryptmethod'
Bram Moolenaar49771f42010-07-20 17:32:38 +02003472#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00003473
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003474 // When a buffer is created, it starts without a swap file. b_may_swap is
3475 // then set to indicate that a swap file may be opened later. It is reset
3476 // if a swap file could not be opened.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003477 int b_may_swap;
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003478 int b_did_warn; // Set to 1 if user has been warned on first
3479 // change of a read-only file
Bram Moolenaar4770d092006-01-12 23:22:24 +00003480
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003481 // Two special kinds of buffers:
3482 // help buffer - used for help files, won't use a swap file.
3483 // spell buffer - used for spell info, never displayed and doesn't have a
3484 // file name.
3485 int b_help; // TRUE for help file buffer (when set b_p_bt
3486 // is "help")
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003487#ifdef FEAT_SPELL
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003488 int b_spell; // TRUE for a spell file buffer, most fields
3489 // are not used! Use the B_SPELL macro to
3490 // access b_spell without #ifdef.
Bram Moolenaar4770d092006-01-12 23:22:24 +00003491#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003492
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003493 int b_shortname; // this file has an 8.3 file name
Bram Moolenaar071d4272004-06-13 20:20:40 +00003494
Bram Moolenaarf2732452018-06-03 14:47:35 +02003495#ifdef FEAT_JOB_CHANNEL
Bram Moolenaar3a97bb32019-06-01 13:28:35 +02003496 char_u *b_prompt_text; // set by prompt_setprompt()
3497 callback_T b_prompt_callback; // set by prompt_setcallback()
3498 callback_T b_prompt_interrupt; // set by prompt_setinterrupt()
3499 int b_prompt_insert; // value for restart_edit when entering
3500 // a prompt buffer window.
Bram Moolenaarf2732452018-06-03 14:47:35 +02003501#endif
Bram Moolenaar325b7a22004-07-05 15:58:32 +00003502#ifdef FEAT_MZSCHEME
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003503 void *b_mzscheme_ref; // The MzScheme reference to this buffer
Bram Moolenaar325b7a22004-07-05 15:58:32 +00003504#endif
3505
Bram Moolenaar071d4272004-06-13 20:20:40 +00003506#ifdef FEAT_PERL
Bram Moolenaare344bea2005-09-01 20:46:49 +00003507 void *b_perl_private;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003508#endif
3509
3510#ifdef FEAT_PYTHON
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003511 void *b_python_ref; // The Python reference to this buffer
Bram Moolenaar071d4272004-06-13 20:20:40 +00003512#endif
3513
Bram Moolenaarbd5e15f2010-07-17 21:19:38 +02003514#ifdef FEAT_PYTHON3
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003515 void *b_python3_ref; // The Python3 reference to this buffer
Bram Moolenaarbd5e15f2010-07-17 21:19:38 +02003516#endif
3517
Bram Moolenaar071d4272004-06-13 20:20:40 +00003518#ifdef FEAT_TCL
Bram Moolenaare344bea2005-09-01 20:46:49 +00003519 void *b_tcl_ref;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003520#endif
3521
3522#ifdef FEAT_RUBY
Bram Moolenaare344bea2005-09-01 20:46:49 +00003523 void *b_ruby_ref;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003524#endif
3525
Bram Moolenaar860cae12010-06-05 23:22:07 +02003526#if defined(FEAT_SYN_HL) || defined(FEAT_SPELL)
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003527 synblock_T b_s; // Info related to syntax highlighting. w_s
3528 // normally points to this, but some windows
3529 // may use a different synblock_T.
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003530#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003531
3532#ifdef FEAT_SIGNS
Bram Moolenaar6656c2e2019-10-24 15:00:04 +02003533 sign_entry_T *b_signlist; // list of placed signs
Bram Moolenaar3b7b8362015-03-20 18:11:48 +01003534# ifdef FEAT_NETBEANS_INTG
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003535 int b_has_sign_column; // Flag that is set when a first sign is
3536 // added and remains set until the end of
3537 // the netbeans session.
Bram Moolenaar3b7b8362015-03-20 18:11:48 +01003538# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003539#endif
3540
3541#ifdef FEAT_NETBEANS_INTG
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003542 int b_netbeans_file; // TRUE when buffer is owned by NetBeans
3543 int b_was_netbeans_file;// TRUE if b_netbeans_file was once set
Bram Moolenaar071d4272004-06-13 20:20:40 +00003544#endif
Bram Moolenaar509ce2a2016-03-11 22:52:15 +01003545#ifdef FEAT_JOB_CHANNEL
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003546 int b_write_to_channel; // TRUE when appended lines are written to
3547 // a channel.
Bram Moolenaar99ef0622016-03-06 20:22:25 +01003548#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003549
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02003550#ifdef FEAT_CRYPT
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003551 cryptstate_T *b_cryptstate; // Encryption state while reading or writing
3552 // the file. NULL when not using encryption.
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02003553#endif
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003554 int b_mapped_ctrl_c; // modes where CTRL-C is mapped
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02003555
Bram Moolenaare4f25e42017-07-07 11:54:15 +02003556#ifdef FEAT_TERMINAL
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003557 term_T *b_term; // When not NULL this buffer is for a terminal
3558 // window.
Bram Moolenaare4f25e42017-07-07 11:54:15 +02003559#endif
Bram Moolenaare828b762018-09-10 17:51:58 +02003560#ifdef FEAT_DIFF
3561 int b_diff_failed; // internal diff failed for this buffer
3562#endif
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003563}; // file_buffer
Bram Moolenaar071d4272004-06-13 20:20:40 +00003564
Bram Moolenaar997fb4b2006-02-17 21:53:23 +00003565
3566#ifdef FEAT_DIFF
3567/*
3568 * Stuff for diff mode.
3569 */
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003570# define DB_COUNT 8 // up to eight buffers can be diff'ed
Bram Moolenaar997fb4b2006-02-17 21:53:23 +00003571
3572/*
3573 * Each diffblock defines where a block of lines starts in each of the buffers
3574 * and how many lines it occupies in that buffer. When the lines are missing
3575 * in the buffer the df_count[] is zero. This is all counted in
3576 * buffer lines.
Yee Cheng Chin9943d472025-03-26 19:41:02 +01003577 * There is always at least one unchanged line in between the diffs (unless
3578 * linematch is used). Otherwise it would have been included in the diff above
3579 * or below it.
Bram Moolenaar997fb4b2006-02-17 21:53:23 +00003580 * df_lnum[] + df_count[] is the lnum below the change. When in one buffer
3581 * lines have been inserted, in the other buffer df_lnum[] is the line below
3582 * the insertion and df_count[] is zero. When appending lines at the end of
3583 * the buffer, df_lnum[] is one beyond the end!
3584 * This is using a linked list, because the number of differences is expected
3585 * to be reasonable small. The list is sorted on lnum.
Yee Cheng Chin9943d472025-03-26 19:41:02 +01003586 * Each diffblock also contains a cached list of inline diff of changes within
3587 * the block, used for highlighting.
Bram Moolenaar997fb4b2006-02-17 21:53:23 +00003588 */
3589typedef struct diffblock_S diff_T;
3590struct diffblock_S
3591{
3592 diff_T *df_next;
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003593 linenr_T df_lnum[DB_COUNT]; // line number in buffer
3594 linenr_T df_count[DB_COUNT]; // nr of inserted/changed lines
Jonathon7c7a4e62025-01-12 09:58:00 +01003595 int is_linematched; // has the linematch algorithm ran on this diff hunk to divide it into
3596 // smaller diff hunks?
Yee Cheng Chin9943d472025-03-26 19:41:02 +01003597
3598 int has_changes; // has cached list of inline changes
3599 garray_T df_changes; // list of inline changes (diffline_change_T)
3600};
3601
3602/*
3603 * Each entry stores a single inline change within a diff block. Line numbers
3604 * are recorded as relative offsets, and columns are byte offsets, not
3605 * character counts.
3606 * Ranges are [start,end), with the end being exclusive.
3607 */
3608typedef struct diffline_change_S diffline_change_T;
3609struct diffline_change_S
3610{
3611 colnr_T dc_start[DB_COUNT]; // byte offset of start of range in the line
zeertzjq5a307c32025-03-28 19:01:32 +01003612 colnr_T dc_end[DB_COUNT]; // 1 past byte offset of end of range in line
Yee Cheng Chin9943d472025-03-26 19:41:02 +01003613 int dc_start_lnum_off[DB_COUNT]; // starting line offset
3614 int dc_end_lnum_off[DB_COUNT]; // end line offset
3615};
3616
3617/*
3618 * Describes a single line's list of inline changes. Use diff_change_parse() to
3619 * parse this.
3620 */
3621typedef struct diffline_S diffline_T;
3622struct diffline_S
3623{
3624 diffline_change_T *changes;
3625 int num_changes;
3626 int bufidx;
3627 int lineoff;
Bram Moolenaar997fb4b2006-02-17 21:53:23 +00003628};
3629#endif
3630
Bram Moolenaar746ebd32009-06-16 14:01:43 +00003631#define SNAP_HELP_IDX 0
Christian Brabandte7d6dbc2022-05-06 12:21:04 +01003632#define SNAP_AUCMD_IDX 1
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01003633#define SNAP_COUNT 2
Bram Moolenaar746ebd32009-06-16 14:01:43 +00003634
Bram Moolenaar997fb4b2006-02-17 21:53:23 +00003635/*
3636 * Tab pages point to the top frame of each tab page.
3637 * Note: Most values are NOT valid for the current tab page! Use "curwin",
3638 * "firstwin", etc. for that. "tp_topframe" is always valid and can be
3639 * compared against "topframe" to find the current tab page.
3640 */
3641typedef struct tabpage_S tabpage_T;
3642struct tabpage_S
3643{
Bram Moolenaar4d784b22019-05-25 19:51:39 +02003644 tabpage_T *tp_next; // next tabpage or NULL
3645 frame_T *tp_topframe; // topframe for the windows
3646 win_T *tp_curwin; // current window in this Tab page
3647 win_T *tp_prevwin; // previous window in this Tab page
3648 win_T *tp_firstwin; // first window in this Tab page
3649 win_T *tp_lastwin; // last window in this Tab page
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01003650#ifdef FEAT_PROP_POPUP
Bram Moolenaar4d784b22019-05-25 19:51:39 +02003651 win_T *tp_first_popupwin; // first popup window in this Tab page
3652#endif
3653 long tp_old_Rows; // Rows when Tab page was left
Bram Moolenaarb7118142021-12-10 13:40:08 +00003654 long tp_old_Columns; // Columns when Tab page was left, -1 when
3655 // calling shell_new_columns() postponed
Bram Moolenaar4d784b22019-05-25 19:51:39 +02003656 long tp_ch_used; // value of 'cmdheight' when frame size
3657 // was set
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00003658#ifdef FEAT_GUI
3659 int tp_prev_which_scrollbars[3];
Bram Moolenaar4d784b22019-05-25 19:51:39 +02003660 // previous value of which_scrollbars
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00003661#endif
Bram Moolenaar00aa0692019-04-27 20:37:57 +02003662
3663 char_u *tp_localdir; // absolute path of local directory or
3664 // NULL
Bram Moolenaar002bc792020-06-05 22:33:42 +02003665 char_u *tp_prevdir; // previous directory
3666
Bram Moolenaar997fb4b2006-02-17 21:53:23 +00003667#ifdef FEAT_DIFF
3668 diff_T *tp_first_diff;
3669 buf_T *(tp_diffbuf[DB_COUNT]);
Bram Moolenaare3521d92018-09-16 14:10:31 +02003670 int tp_diff_invalid; // list of diffs is outdated
3671 int tp_diff_update; // update diffs before redrawing
Bram Moolenaar997fb4b2006-02-17 21:53:23 +00003672#endif
Bram Moolenaar4d784b22019-05-25 19:51:39 +02003673 frame_T *(tp_snapshot[SNAP_COUNT]); // window layout snapshots
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003674#ifdef FEAT_EVAL
Bram Moolenaar4d784b22019-05-25 19:51:39 +02003675 dictitem_T tp_winvar; // variable for "t:" Dictionary
3676 dict_T *tp_vars; // internal variables, local to tab page
Bram Moolenaar910f66f2006-04-05 20:41:53 +00003677#endif
Bram Moolenaar5e538ec2013-05-15 15:12:29 +02003678
3679#ifdef FEAT_PYTHON
Bram Moolenaar4d784b22019-05-25 19:51:39 +02003680 void *tp_python_ref; // The Python value for this tab page
Bram Moolenaar5e538ec2013-05-15 15:12:29 +02003681#endif
3682
3683#ifdef FEAT_PYTHON3
Bram Moolenaar4d784b22019-05-25 19:51:39 +02003684 void *tp_python3_ref; // The Python value for this tab page
Bram Moolenaar5e538ec2013-05-15 15:12:29 +02003685#endif
Bram Moolenaar997fb4b2006-02-17 21:53:23 +00003686};
3687
Bram Moolenaar071d4272004-06-13 20:20:40 +00003688/*
3689 * Structure to cache info for displayed lines in w_lines[].
3690 * Each logical line has one entry.
3691 * The entry tells how the logical line is currently displayed in the window.
3692 * This is updated when displaying the window.
3693 * When the display is changed (e.g., when clearing the screen) w_lines_valid
3694 * is changed to exclude invalid entries.
3695 * When making changes to the buffer, wl_valid is reset to indicate wl_size
3696 * may not reflect what is actually in the buffer. When wl_valid is FALSE,
3697 * the entries can only be used to count the number of displayed lines used.
3698 * wl_lnum and wl_lastlnum are invalid too.
3699 */
3700typedef struct w_line
3701{
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003702 linenr_T wl_lnum; // buffer line number for logical line
3703 short_u wl_size; // height in screen lines
3704 char wl_valid; // TRUE values are valid for text in buffer
Bram Moolenaar071d4272004-06-13 20:20:40 +00003705#ifdef FEAT_FOLDING
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003706 char wl_folded; // TRUE when this is a range of folded lines
3707 linenr_T wl_lastlnum; // last buffer line number for logical line
Bram Moolenaar071d4272004-06-13 20:20:40 +00003708#endif
3709} wline_T;
3710
3711/*
3712 * Windows are kept in a tree of frames. Each frame has a column (FR_COL)
3713 * or row (FR_ROW) layout or is a leaf, which has a window.
3714 */
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00003715struct frame_S
Bram Moolenaar071d4272004-06-13 20:20:40 +00003716{
Bram Moolenaarcce713d2019-03-04 11:40:12 +01003717 char fr_layout; // FR_LEAF, FR_COL or FR_ROW
Bram Moolenaar071d4272004-06-13 20:20:40 +00003718 int fr_width;
Bram Moolenaarcce713d2019-03-04 11:40:12 +01003719 int fr_newwidth; // new width used in win_equal_rec()
Bram Moolenaar071d4272004-06-13 20:20:40 +00003720 int fr_height;
Bram Moolenaarcce713d2019-03-04 11:40:12 +01003721 int fr_newheight; // new height used in win_equal_rec()
3722 frame_T *fr_parent; // containing frame or NULL
3723 frame_T *fr_next; // frame right or below in same parent, NULL
3724 // for last
3725 frame_T *fr_prev; // frame left or above in same parent, NULL
3726 // for first
3727 // fr_child and fr_win are mutually exclusive
3728 frame_T *fr_child; // first contained frame
Christian Brabandte7d6dbc2022-05-06 12:21:04 +01003729 win_T *fr_win; // window that fills this frame; for a snapshot
3730 // set to the current window
Bram Moolenaar071d4272004-06-13 20:20:40 +00003731};
3732
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003733#define FR_LEAF 0 // frame is a leaf
3734#define FR_ROW 1 // frame with a row of windows
3735#define FR_COL 2 // frame with a column of windows
Bram Moolenaar071d4272004-06-13 20:20:40 +00003736
3737/*
Bram Moolenaar6ee10162007-07-26 20:58:42 +00003738 * Struct used for highlighting 'hlsearch' matches, matches defined by
3739 * ":match" and matches defined by match functions.
3740 * For 'hlsearch' there is one pattern for all windows. For ":match" and the
3741 * match functions there is a different pattern for each window.
3742 */
3743typedef struct
3744{
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003745 regmmatch_T rm; // points to the regexp program; contains last
3746 // found match (may continue in next line)
3747 buf_T *buf; // the buffer to search for a match
3748 linenr_T lnum; // the line to search for a match
3749 int attr; // attributes to be used for a match
3750 int attr_cur; // attributes currently active in win_line()
3751 linenr_T first_lnum; // first lnum to search for multi-line pat
3752 colnr_T startcol; // in win_line() points to char where HL starts
3753 colnr_T endcol; // in win_line() points to char where HL ends
Bram Moolenaar693ccd12022-04-16 12:04:37 +01003754 char is_addpos; // position specified directly by
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003755 // matchaddpos(). TRUE/FALSE
Bram Moolenaar693ccd12022-04-16 12:04:37 +01003756 char has_cursor; // TRUE if the cursor is inside the match, used for
3757 // CurSearch
Bram Moolenaar6ee10162007-07-26 20:58:42 +00003758} match_T;
3759
Bram Moolenaarb3414592014-06-17 17:48:32 +02003760/*
3761 * Same as lpos_T, but with additional field len.
3762 */
3763typedef struct
3764{
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003765 linenr_T lnum; // line number
3766 colnr_T col; // column number
3767 int len; // length: 0 - to the end of line
Bram Moolenaarb3414592014-06-17 17:48:32 +02003768} llpos_T;
3769
3770/*
Bram Moolenaar50faf022022-09-29 12:50:17 +01003771 * matchitem_T provides a linked list for storing match items for ":match",
3772 * matchadd() and matchaddpos().
Bram Moolenaar6ee10162007-07-26 20:58:42 +00003773 */
3774typedef struct matchitem matchitem_T;
3775struct matchitem
3776{
Bram Moolenaar50faf022022-09-29 12:50:17 +01003777 matchitem_T *mit_next;
3778 int mit_id; // match ID
3779 int mit_priority; // match priority
3780
3781 // Either a pattern is defined (mit_pattern is not NUL) or a list of
3782 // positions is given (mit_pos is not NULL and mit_pos_count > 0).
3783 char_u *mit_pattern; // pattern to highlight
3784 regmmatch_T mit_match; // regexp program for pattern
3785
3786 llpos_T *mit_pos_array; // array of positions
3787 int mit_pos_count; // nr of entries in mit_pos
3788 int mit_pos_cur; // internal position counter
3789 linenr_T mit_toplnum; // top buffer line
3790 linenr_T mit_botlnum; // bottom buffer line
3791
3792 match_T mit_hl; // struct for doing the actual highlighting
3793 int mit_hlg_id; // highlight group ID
Bram Moolenaar6561d522015-07-21 15:48:27 +02003794#ifdef FEAT_CONCEAL
Bram Moolenaar50faf022022-09-29 12:50:17 +01003795 int mit_conceal_char; // cchar for Conceal highlighting
Bram Moolenaar6561d522015-07-21 15:48:27 +02003796#endif
Bram Moolenaar6ee10162007-07-26 20:58:42 +00003797};
3798
Bram Moolenaara68e5952019-04-25 22:22:01 +02003799// Structure to store last cursor position and topline. Used by check_lnums()
3800// and reset_lnums().
3801typedef struct
3802{
3803 int w_topline_save; // original topline value
3804 int w_topline_corr; // corrected topline value
3805 pos_T w_cursor_save; // original cursor position
3806 pos_T w_cursor_corr; // corrected cursor position
3807} pos_save_T;
3808
Bram Moolenaar1b9645d2017-09-17 23:03:31 +02003809#ifdef FEAT_MENU
3810typedef struct {
3811 int wb_startcol;
3812 int wb_endcol;
3813 vimmenu_T *wb_menu;
3814} winbar_item_T;
3815#endif
3816
Bram Moolenaar6ee10162007-07-26 20:58:42 +00003817/*
Bram Moolenaareed9d462021-02-15 20:38:25 +01003818 * Characters from the 'listchars' option
3819 */
3820typedef struct
3821{
3822 int eol;
3823 int ext;
3824 int prec;
3825 int nbsp;
3826 int space;
3827 int tab1;
3828 int tab2;
3829 int tab3;
3830 int trail;
3831 int lead;
zeertzjqf14b8ba2021-09-10 16:58:30 +02003832 int *multispace;
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01003833 int *leadmultispace;
Bram Moolenaareed9d462021-02-15 20:38:25 +01003834#ifdef FEAT_CONCEAL
3835 int conceal;
3836#endif
3837} lcs_chars_T;
3838
3839/*
Bram Moolenaar96ba25a2022-07-04 17:34:33 +01003840 * Characters from the 'fillchars' option
3841 */
3842typedef struct
3843{
3844 int stl;
3845 int stlnc;
3846 int vert;
3847 int fold;
3848 int foldopen;
3849 int foldclosed;
3850 int foldsep;
3851 int diff;
3852 int eob;
Bram Moolenaar4ba5f1d2022-10-04 14:36:29 +01003853 int lastline;
glepnirb8762042025-04-07 20:57:14 +02003854 int trunc;
glepnird4dbf822025-04-12 18:35:34 +02003855 int truncrl;
Bram Moolenaar96ba25a2022-07-04 17:34:33 +01003856} fill_chars_T;
3857
3858/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00003859 * Structure which contains all information that belongs to a window
3860 *
3861 * All row numbers are relative to the start of the window, except w_winrow.
3862 */
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00003863struct window_S
Bram Moolenaar071d4272004-06-13 20:20:40 +00003864{
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003865 int w_id; // unique window ID
Bram Moolenaar86edef62016-03-13 18:07:30 +01003866
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003867 buf_T *w_buffer; // buffer we are a window into
Bram Moolenaar4d784b22019-05-25 19:51:39 +02003868
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003869 win_T *w_prev; // link to previous window
3870 win_T *w_next; // link to next window
Bram Moolenaar071d4272004-06-13 20:20:40 +00003871
Bram Moolenaar860cae12010-06-05 23:22:07 +02003872#if defined(FEAT_SYN_HL) || defined(FEAT_SPELL)
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003873 synblock_T *w_s; // for :ownsyntax
Bram Moolenaar860cae12010-06-05 23:22:07 +02003874#endif
3875
zeertzjqbc11f6d2024-08-16 21:11:31 +02003876 int w_locked; // don't let autocommands close the window
Bram Moolenaar071d4272004-06-13 20:20:40 +00003877
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003878 frame_T *w_frame; // frame containing this window
Bram Moolenaar071d4272004-06-13 20:20:40 +00003879
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003880 pos_T w_cursor; // cursor position in buffer
Bram Moolenaar071d4272004-06-13 20:20:40 +00003881
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003882 colnr_T w_curswant; // The column we'd like to be at. This is
3883 // used to try to stay in the same column
3884 // for up/down cursor motions.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003885
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003886 int w_set_curswant; // If set, then update w_curswant the next
3887 // time through cursupdate() to the
3888 // current virtual column
Bram Moolenaar071d4272004-06-13 20:20:40 +00003889
Bram Moolenaar4a5abbd2018-10-02 18:26:10 +02003890#ifdef FEAT_SYN_HL
3891 linenr_T w_last_cursorline; // where last time 'cursorline' was drawn
3892#endif
3893
Bram Moolenaar071d4272004-06-13 20:20:40 +00003894 /*
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003895 * the next seven are used to update the Visual highlighting
Bram Moolenaar071d4272004-06-13 20:20:40 +00003896 */
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003897 char w_old_visual_mode; // last known VIsual_mode
3898 linenr_T w_old_cursor_lnum; // last known end of visual part
3899 colnr_T w_old_cursor_fcol; // first column for block visual part
3900 colnr_T w_old_cursor_lcol; // last column for block visual part
3901 linenr_T w_old_visual_lnum; // last known start of visual part
3902 colnr_T w_old_visual_col; // last known start of visual part
3903 colnr_T w_old_curswant; // last known value of Curswant
Bram Moolenaar071d4272004-06-13 20:20:40 +00003904
Lewis Russell16246392022-03-29 11:38:17 +01003905 linenr_T w_last_cursor_lnum_rnu; // cursor lnum when 'rnu' was last
3906 // redrawn
3907
Bram Moolenaareed9d462021-02-15 20:38:25 +01003908 lcs_chars_T w_lcs_chars; // 'listchars' characters
Bram Moolenaar96ba25a2022-07-04 17:34:33 +01003909 fill_chars_T w_fill_chars; // 'fillchars' characters
Bram Moolenaareed9d462021-02-15 20:38:25 +01003910
Bram Moolenaar071d4272004-06-13 20:20:40 +00003911 /*
Bram Moolenaard4153d42008-11-15 15:06:17 +00003912 * "w_topline", "w_leftcol" and "w_skipcol" specify the offsets for
3913 * displaying the buffer.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003914 */
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003915 linenr_T w_topline; // buffer line number of the line at the
3916 // top of the window
3917 char w_topline_was_set; // flag set to TRUE when topline is set,
3918 // e.g. by winrestview()
Bram Moolenaar6a076442020-11-15 20:32:58 +01003919
3920 linenr_T w_botline; // number of the line below the bottom of
3921 // the window
3922
Bram Moolenaar071d4272004-06-13 20:20:40 +00003923#ifdef FEAT_DIFF
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003924 int w_topfill; // number of filler lines above w_topline
3925 int w_old_topfill; // w_topfill at last redraw
3926 int w_botfill; // TRUE when filler lines are actually
3927 // below w_topline (at end of file)
3928 int w_old_botfill; // w_botfill at last redraw
Bram Moolenaar071d4272004-06-13 20:20:40 +00003929#endif
Bram Moolenaarf6196f42022-10-02 21:29:55 +01003930 colnr_T w_leftcol; // screen column number of the left most
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003931 // character in the window; used when
3932 // 'wrap' is off
Bram Moolenaarf6196f42022-10-02 21:29:55 +01003933 colnr_T w_skipcol; // starting screen column for the first
3934 // line in the window; used when 'wrap' is
Bram Moolenaar856c5d22022-10-13 21:54:28 +01003935 // on; does not include win_col_off()
Bram Moolenaar071d4272004-06-13 20:20:40 +00003936
Bram Moolenaar6a076442020-11-15 20:32:58 +01003937 int w_empty_rows; // number of ~ rows in window
3938#ifdef FEAT_DIFF
3939 int w_filler_rows; // number of filler rows at the end of the
3940 // window
3941#endif
3942
Bram Moolenaar2e613452022-12-07 22:30:18 +00003943 // six fields that are only used when there is a WinScrolled autocommand
LemonBoy09371822022-04-08 15:18:45 +01003944 linenr_T w_last_topline; // last known value for w_topline
zeertzjq3fc84dc2022-12-07 09:17:59 +00003945#ifdef FEAT_DIFF
Bram Moolenaar2e613452022-12-07 22:30:18 +00003946 int w_last_topfill; // last known value for w_topfill
zeertzjq3fc84dc2022-12-07 09:17:59 +00003947#endif
LemonBoy09371822022-04-08 15:18:45 +01003948 colnr_T w_last_leftcol; // last known value for w_leftcol
zeertzjq670ab032022-08-28 19:16:15 +01003949 colnr_T w_last_skipcol; // last known value for w_skipcol
LemonBoy09371822022-04-08 15:18:45 +01003950 int w_last_width; // last known value for w_width
3951 int w_last_height; // last known value for w_height
3952
Bram Moolenaar071d4272004-06-13 20:20:40 +00003953 /*
3954 * Layout of the window in the screen.
3955 * May need to add "msg_scrolled" to "w_winrow" in rare situations.
3956 */
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003957 int w_winrow; // first row of window in screen
3958 int w_height; // number of rows in window, excluding
3959 // status/command/winbar line(s)
Luuk van Baal13ece2a2022-10-03 15:28:08 +01003960 int w_prev_winrow; // previous winrow used for 'splitkeep'
3961 int w_prev_height; // previous height used for 'splitkeep'
Bram Moolenaar6a076442020-11-15 20:32:58 +01003962
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003963 int w_status_height; // number of status lines (0 or 1)
3964 int w_wincol; // Leftmost column of window in screen.
3965 int w_width; // Width of window, excluding separation.
3966 int w_vsep_width; // Number of separator columns (0 or 1).
Bram Moolenaar6a076442020-11-15 20:32:58 +01003967
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02003968 pos_save_T w_save_cursor; // backup of cursor pos and topline
Luuk van Baal16af9132023-08-20 20:44:59 +02003969 int w_do_win_fix_cursor;// if TRUE cursor may be invalid
Bram Moolenaar6a076442020-11-15 20:32:58 +01003970
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01003971#ifdef FEAT_PROP_POPUP
Bram Moolenaarac1f1bc2019-05-30 21:24:26 +02003972 int w_popup_flags; // POPF_ values
Bram Moolenaarafe45b62019-11-13 22:35:19 +01003973 int w_popup_handled; // POPUP_HANDLE[0-9] flags
Bram Moolenaareb2310d2019-06-16 20:09:10 +02003974 char_u *w_popup_title;
Bram Moolenaarac1f1bc2019-05-30 21:24:26 +02003975 poppos_T w_popup_pos;
Bram Moolenaar042fb4b2019-06-02 14:49:56 +02003976 int w_popup_fixed; // do not shift popup to fit on screen
Bram Moolenaar12034e22019-08-25 22:25:02 +02003977 int w_popup_prop_type; // when not zero: textprop type ID
3978 win_T *w_popup_prop_win; // window to search for textprop
3979 int w_popup_prop_id; // when not zero: textprop ID
Bram Moolenaar4d784b22019-05-25 19:51:39 +02003980 int w_zindex;
Bram Moolenaar60cdb302019-05-27 21:54:10 +02003981 int w_minheight; // "minheight" for popup window
3982 int w_minwidth; // "minwidth" for popup window
Bram Moolenaar4d784b22019-05-25 19:51:39 +02003983 int w_maxheight; // "maxheight" for popup window
3984 int w_maxwidth; // "maxwidth" for popup window
Bram Moolenaarde2396f2020-07-18 21:40:41 +02003985 int w_maxwidth_opt; // maxwidth from option
Bram Moolenaar60cdb302019-05-27 21:54:10 +02003986 int w_wantline; // "line" for popup window
3987 int w_wantcol; // "col" for popup window
Bram Moolenaar8d241042019-06-12 23:40:01 +02003988 int w_firstline; // "firstline" for popup window
Bram Moolenaar75fb0852019-06-25 05:15:58 +02003989 int w_want_scrollbar; // when zero don't use a scrollbar
Bram Moolenaarf9c85f52019-06-29 07:41:35 +02003990 int w_has_scrollbar; // 1 if scrollbar displayed, 0 otherwise
Bram Moolenaar4cd583c2019-06-26 05:13:57 +02003991 char_u *w_scrollbar_highlight; // "scrollbarhighlight"
3992 char_u *w_thumb_highlight; // "thumbhighlight"
Bram Moolenaar2fd8e352019-06-01 20:16:48 +02003993 int w_popup_padding[4]; // popup padding top/right/bot/left
3994 int w_popup_border[4]; // popup border top/right/bot/left
Bram Moolenaar790498b2019-06-01 22:15:29 +02003995 char_u *w_border_highlight[4]; // popup border highlight
3996 int w_border_char[8]; // popup border characters
Bram Moolenaard529ba52019-07-02 23:13:53 +02003997
3998 int w_popup_leftoff; // columns left of the screen
3999 int w_popup_rightoff; // columns right of the screen
Bram Moolenaar12034e22019-08-25 22:25:02 +02004000 varnumber_T w_popup_last_changedtick; // b:changedtick of popup buffer
4001 // when position was computed
4002 varnumber_T w_popup_prop_changedtick; // b:changedtick of buffer with
4003 // w_popup_prop_type when position
4004 // was computed
4005 int w_popup_prop_topline; // w_topline of window with
4006 // w_popup_prop_type when position was
4007 // computed
Bram Moolenaar3d2a3cb2019-09-08 17:12:01 +02004008 linenr_T w_popup_last_curline; // last known w_cursor.lnum of window
4009 // with "cursorline" set
Bram Moolenaar9eaac892019-06-01 22:49:29 +02004010 callback_T w_close_cb; // popup close callback
Bram Moolenaarbf0eff02019-06-01 17:13:36 +02004011 callback_T w_filter_cb; // popup filter callback
Bram Moolenaar6defa7b2020-09-08 22:06:44 +02004012 int w_filter_errors; // popup filter error count
Bram Moolenaar581ba392019-09-03 22:08:33 +02004013 int w_filter_mode; // mode when filter callback is used
Bram Moolenaar3397f742019-06-02 18:40:06 +02004014
4015 win_T *w_popup_curwin; // close popup if curwin differs
4016 linenr_T w_popup_lnum; // close popup if cursor not on this line
4017 colnr_T w_popup_mincol; // close popup if cursor before this col
4018 colnr_T w_popup_maxcol; // close popup if cursor after this col
Bram Moolenaar56a63122019-07-07 18:38:34 +02004019 int w_popup_mouse_row; // close popup if mouse moves away
4020 int w_popup_mouse_mincol; // close popup if mouse moves away
4021 int w_popup_mouse_maxcol; // close popup if mouse moves away
Bram Moolenaar2e62b562019-06-30 18:07:00 +02004022 popclose_T w_popup_close; // allow closing the popup with the mouse
Bram Moolenaar3397f742019-06-02 18:40:06 +02004023
Bram Moolenaar4f0d0022019-07-26 22:20:03 +02004024 list_T *w_popup_mask; // list of lists for "mask"
4025 char_u *w_popup_mask_cells; // cached mask cells
4026 int w_popup_mask_height; // height of w_popup_mask_cells
4027 int w_popup_mask_width; // width of w_popup_mask_cells
Bram Moolenaar35d5af62019-05-26 20:44:10 +02004028# if defined(FEAT_TIMERS)
Bram Moolenaar51fe3b12019-05-26 20:10:06 +02004029 timer_T *w_popup_timer; // timer for closing popup window
Bram Moolenaar35d5af62019-05-26 20:44:10 +02004030# endif
Bram Moolenaara68e5952019-04-25 22:22:01 +02004031
Bram Moolenaar6a076442020-11-15 20:32:58 +01004032 int w_flags; // WFLAG_ flags
4033
4034# define WFLAG_WCOL_OFF_ADDED 1 // popup border and padding were added to
4035 // w_wcol
4036# define WFLAG_WROW_OFF_ADDED 2 // popup border and padding were added to
4037 // w_wrow
4038#endif
Bram Moolenaare0de17d2017-09-24 16:24:34 +02004039
Bram Moolenaar071d4272004-06-13 20:20:40 +00004040 /*
4041 * === start of cached values ====
4042 */
4043 /*
4044 * Recomputing is minimized by storing the result of computations.
4045 * Use functions in screen.c to check if they are valid and to update.
4046 * w_valid is a bitfield of flags, which indicate if specific values are
4047 * valid or need to be recomputed. See screen.c for values.
4048 */
4049 int w_valid;
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02004050 pos_T w_valid_cursor; // last known position of w_cursor, used
4051 // to adjust w_valid
4052 colnr_T w_valid_leftcol; // last known w_leftcol
Bram Moolenaar2fbabd22022-10-12 19:53:38 +01004053 colnr_T w_valid_skipcol; // last known w_skipcol
Bram Moolenaar071d4272004-06-13 20:20:40 +00004054
4055 /*
4056 * w_cline_height is the number of physical lines taken by the buffer line
4057 * that the cursor is on. We use this to avoid extra calls to plines().
4058 */
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02004059 int w_cline_height; // current size of cursor line
Bram Moolenaar071d4272004-06-13 20:20:40 +00004060#ifdef FEAT_FOLDING
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02004061 int w_cline_folded; // cursor line is folded
Bram Moolenaar071d4272004-06-13 20:20:40 +00004062#endif
4063
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02004064 int w_cline_row; // starting row of the cursor line
Bram Moolenaar071d4272004-06-13 20:20:40 +00004065
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02004066 colnr_T w_virtcol; // column number of the cursor in the
4067 // buffer line, as opposed to the column
4068 // number we're at on the screen. This
4069 // makes a difference on lines which span
4070 // more than one screen line or when
4071 // w_leftcol is non-zero
Bram Moolenaar071d4272004-06-13 20:20:40 +00004072
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01004073#ifdef FEAT_PROP_POPUP
4074 colnr_T w_virtcol_first_char; // offset for w_virtcol when there are
4075 // virtual text properties above the
4076 // line
4077#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004078 /*
4079 * w_wrow and w_wcol specify the cursor position in the window.
4080 * This is related to positions in the window, not in the display or
4081 * buffer, thus w_wrow is relative to w_winrow.
4082 */
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02004083 int w_wrow, w_wcol; // cursor position in window
Bram Moolenaar071d4272004-06-13 20:20:40 +00004084
Bram Moolenaar071d4272004-06-13 20:20:40 +00004085 /*
4086 * Info about the lines currently in the window is remembered to avoid
4087 * recomputing it every time. The allocated size of w_lines[] is Rows.
4088 * Only the w_lines_valid entries are actually valid.
4089 * When the display is up-to-date w_lines[0].wl_lnum is equal to w_topline
4090 * and w_lines[w_lines_valid - 1].wl_lnum is equal to w_botline.
4091 * Between changing text and updating the display w_lines[] represents
4092 * what is currently displayed. wl_valid is reset to indicated this.
4093 * This is used for efficient redrawing.
4094 */
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02004095 int w_lines_valid; // number of valid entries
Bram Moolenaar071d4272004-06-13 20:20:40 +00004096 wline_T *w_lines;
4097
4098#ifdef FEAT_FOLDING
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02004099 garray_T w_folds; // array of nested folds
4100 char w_fold_manual; // when TRUE: some folds are opened/closed
4101 // manually
4102 char w_foldinvalid; // when TRUE: folding needs to be
4103 // recomputed
Bram Moolenaar071d4272004-06-13 20:20:40 +00004104#endif
Bram Moolenaar592e0a22004-07-03 16:05:59 +00004105#ifdef FEAT_LINEBREAK
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02004106 int w_nrwidth; // width of 'number' and 'relativenumber'
4107 // column being used
Bram Moolenaar592e0a22004-07-03 16:05:59 +00004108#endif
Bram Moolenaar87fd0922021-11-20 13:47:45 +00004109#ifdef FEAT_TERMINAL
4110 termcellcolor_T w_term_wincolor; // cache for term color of 'wincolor'
4111#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004112
4113 /*
4114 * === end of cached values ===
4115 */
4116
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02004117 int w_redr_type; // type of redraw to be performed on win
4118 int w_upd_rows; // number of window lines to update when
Bram Moolenaara4d158b2022-08-14 14:17:45 +01004119 // w_redr_type is UPD_REDRAW_TOP
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02004120 linenr_T w_redraw_top; // when != 0: first line needing redraw
4121 linenr_T w_redraw_bot; // when != 0: last line needing redraw
4122 int w_redr_status; // if TRUE status line must be redrawn
Bram Moolenaar071d4272004-06-13 20:20:40 +00004123
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02004124 // remember what is shown in the ruler for this window (if 'ruler' set)
4125 pos_T w_ru_cursor; // cursor position shown in ruler
4126 colnr_T w_ru_virtcol; // virtcol shown in ruler
4127 linenr_T w_ru_topline; // topline shown in ruler
4128 linenr_T w_ru_line_count; // line count used for ruler
Martin Tournoijba43e762022-10-13 22:12:15 +01004129#ifdef FEAT_DIFF
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02004130 int w_ru_topfill; // topfill shown in ruler
Bram Moolenaar071d4272004-06-13 20:20:40 +00004131#endif
Martin Tournoijba43e762022-10-13 22:12:15 +01004132 char w_ru_empty; // TRUE if ruler shows 0-1 (empty line)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004133
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02004134 int w_alt_fnum; // alternate file (for # and CTRL-^)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004135
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02004136 alist_T *w_alist; // pointer to arglist for this window
4137 int w_arg_idx; // current index in argument list (can be
4138 // out of range!)
4139 int w_arg_idx_invalid; // editing another file than w_arg_idx
Bram Moolenaar071d4272004-06-13 20:20:40 +00004140
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02004141 char_u *w_localdir; // absolute path of local directory or
4142 // NULL
Bram Moolenaar002bc792020-06-05 22:33:42 +02004143 char_u *w_prevdir; // previous directory
Bram Moolenaar1b9645d2017-09-17 23:03:31 +02004144#ifdef FEAT_MENU
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02004145 vimmenu_T *w_winbar; // The root of the WinBar menu hierarchy.
4146 winbar_item_T *w_winbar_items; // list of items in the WinBar
4147 int w_winbar_height; // 1 if there is a window toolbar
Bram Moolenaar1b9645d2017-09-17 23:03:31 +02004148#endif
4149
Bram Moolenaar071d4272004-06-13 20:20:40 +00004150 /*
4151 * Options local to a window.
4152 * They are local because they influence the layout of the window or
4153 * depend on the window layout.
4154 * There are two values: w_onebuf_opt is local to the buffer currently in
4155 * this window, w_allbuf_opt is for all buffers in this window.
4156 */
4157 winopt_T w_onebuf_opt;
4158 winopt_T w_allbuf_opt;
Bram Moolenaare70dd112022-01-21 16:31:11 +00004159 // transform a pointer to a "onebuf" option into a "allbuf" option
kylo2529dac9b12022-03-27 20:05:17 +01004160#define GLOBAL_WO(p) ((char *)(p) + sizeof(winopt_T))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004161
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02004162 // A few options have local flags for P_INSECURE.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00004163#ifdef FEAT_STL_OPT
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02004164 long_u w_p_stl_flags; // flags for 'statusline'
Bram Moolenaard1f56e62006-02-22 21:25:37 +00004165#endif
4166#ifdef FEAT_EVAL
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02004167 long_u w_p_fde_flags; // flags for 'foldexpr'
4168 long_u w_p_fdt_flags; // flags for 'foldtext'
Bram Moolenaard1f56e62006-02-22 21:25:37 +00004169#endif
Martin Tournoijba43e762022-10-13 22:12:15 +01004170#if defined(FEAT_SIGNS) || defined(FEAT_FOLDING) || defined(FEAT_DIFF)
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02004171 int *w_p_cc_cols; // array of columns to highlight or NULL
Bram Moolenaar017ba072019-09-14 21:01:23 +02004172 char_u w_p_culopt_flags; // flags for cursorline highlighting
Bram Moolenaar1a384422010-07-14 19:53:30 +02004173#endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00004174
Bram Moolenaarb81f56f2020-02-23 15:29:46 +01004175#ifdef FEAT_LINEBREAK
4176 int w_briopt_min; // minimum width for breakindent
4177 int w_briopt_shift; // additional shift for breakindent
4178 int w_briopt_sbr; // sbr in 'briopt'
Christian Brabandt4a0b85a2021-07-14 20:00:27 +02004179 int w_briopt_list; // additional indent for lists
Christian Brabandte7d6dbc2022-05-06 12:21:04 +01004180 int w_briopt_vcol; // indent for specific column
Bram Moolenaarb81f56f2020-02-23 15:29:46 +01004181#endif
4182
Bram Moolenaar071d4272004-06-13 20:20:40 +00004183 long w_scbind_pos;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004184
4185#ifdef FEAT_EVAL
Bram Moolenaar4aea03e2019-09-25 22:37:17 +02004186 dictitem_T w_winvar; // variable for "w:" Dictionary
4187 dict_T *w_vars; // internal variables, local to window
Bram Moolenaar071d4272004-06-13 20:20:40 +00004188#endif
4189
Bram Moolenaar071d4272004-06-13 20:20:40 +00004190 /*
4191 * The w_prev_pcmark field is used to check whether we really did jump to
4192 * a new line after setting the w_pcmark. If not, then we revert to
4193 * using the previous w_pcmark.
4194 */
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02004195 pos_T w_pcmark; // previous context mark
4196 pos_T w_prev_pcmark; // previous w_pcmark
Bram Moolenaar071d4272004-06-13 20:20:40 +00004197
Bram Moolenaar071d4272004-06-13 20:20:40 +00004198 /*
4199 * the jumplist contains old cursor positions
4200 */
4201 xfmark_T w_jumplist[JUMPLISTSIZE];
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02004202 int w_jumplistlen; // number of active entries
4203 int w_jumplistidx; // current position
Bram Moolenaar071d4272004-06-13 20:20:40 +00004204
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02004205 int w_changelistidx; // current position in b_changelist
Bram Moolenaar071d4272004-06-13 20:20:40 +00004206
4207#ifdef FEAT_SEARCH_EXTRA
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02004208 matchitem_T *w_match_head; // head of match list
4209 int w_next_match_id; // next match ID
Bram Moolenaar071d4272004-06-13 20:20:40 +00004210#endif
4211
4212 /*
4213 * the tagstack grows from 0 upwards:
4214 * entry 0: older
4215 * entry 1: newer
4216 * entry 2: newest
4217 */
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02004218 taggy_T w_tagstack[TAGSTACKSIZE]; // the tag stack
4219 int w_tagstackidx; // idx just below active entry
4220 int w_tagstacklen; // number of tags on stack
Bram Moolenaar071d4272004-06-13 20:20:40 +00004221
4222 /*
4223 * w_fraction is the fractional row of the cursor within the window, from
4224 * 0 at the top row to FRACTION_MULT at the last row.
4225 * w_prev_fraction_row was the actual cursor row when w_fraction was last
4226 * calculated.
4227 */
4228 int w_fraction;
4229 int w_prev_fraction_row;
4230
4231#ifdef FEAT_GUI
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02004232 scrollbar_T w_scrollbars[2]; // vert. Scrollbars for this window
Bram Moolenaar071d4272004-06-13 20:20:40 +00004233#endif
Bram Moolenaar592e0a22004-07-03 16:05:59 +00004234#ifdef FEAT_LINEBREAK
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02004235 linenr_T w_nrwidth_line_count; // line count when ml_nrwidth_width
4236 // was computed.
4237 long w_nuw_cached; // 'numberwidth' option cached
4238 int w_nrwidth_width; // nr of chars to print line count.
Bram Moolenaar592e0a22004-07-03 16:05:59 +00004239#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004240
Bram Moolenaard12f5c12006-01-25 22:10:52 +00004241#ifdef FEAT_QUICKFIX
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02004242 qf_info_T *w_llist; // Location list for this window
Bram Moolenaard12f5c12006-01-25 22:10:52 +00004243 /*
4244 * Location list reference used in the location list window.
4245 * In a non-location list window, w_llist_ref is NULL.
4246 */
4247 qf_info_T *w_llist_ref;
4248#endif
4249
Bram Moolenaar325b7a22004-07-05 15:58:32 +00004250#ifdef FEAT_MZSCHEME
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02004251 void *w_mzscheme_ref; // The MzScheme value for this window
Bram Moolenaar325b7a22004-07-05 15:58:32 +00004252#endif
4253
Bram Moolenaar071d4272004-06-13 20:20:40 +00004254#ifdef FEAT_PERL
Bram Moolenaare344bea2005-09-01 20:46:49 +00004255 void *w_perl_private;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004256#endif
4257
4258#ifdef FEAT_PYTHON
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02004259 void *w_python_ref; // The Python value for this window
Bram Moolenaar071d4272004-06-13 20:20:40 +00004260#endif
4261
Bram Moolenaarbd5e15f2010-07-17 21:19:38 +02004262#ifdef FEAT_PYTHON3
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02004263 void *w_python3_ref; // The Python value for this window
Bram Moolenaarbd5e15f2010-07-17 21:19:38 +02004264#endif
4265
Bram Moolenaar071d4272004-06-13 20:20:40 +00004266#ifdef FEAT_TCL
Bram Moolenaare344bea2005-09-01 20:46:49 +00004267 void *w_tcl_ref;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004268#endif
4269
4270#ifdef FEAT_RUBY
Bram Moolenaare344bea2005-09-01 20:46:49 +00004271 void *w_ruby_ref;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004272#endif
4273};
4274
4275/*
4276 * Arguments for operators.
4277 */
Bram Moolenaare344bea2005-09-01 20:46:49 +00004278typedef struct oparg_S
Bram Moolenaar071d4272004-06-13 20:20:40 +00004279{
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02004280 int op_type; // current pending operator type
4281 int regname; // register to use for the operator
4282 int motion_type; // type of the current cursor motion
4283 int motion_force; // force motion type: 'v', 'V' or CTRL-V
4284 int use_reg_one; // TRUE if delete uses reg 1 even when not
4285 // linewise
4286 int inclusive; // TRUE if char motion is inclusive (only
Christian Brabandt544a38e2021-06-10 19:39:11 +02004287 // valid when motion_type is MCHAR)
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02004288 int end_adjusted; // backuped b_op_end one char (only used by
4289 // do_format())
4290 pos_T start; // start of the operator
4291 pos_T end; // end of the operator
4292 pos_T cursor_start; // cursor position before motion for "gw"
Bram Moolenaar071d4272004-06-13 20:20:40 +00004293
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02004294 long line_count; // number of lines from op_start to op_end
4295 // (inclusive)
4296 int empty; // op_start and op_end the same (only used by
4297 // do_change())
4298 int is_VIsual; // operator on Visual area
4299 int block_mode; // current operator is Visual block mode
4300 colnr_T start_vcol; // start col for block mode operator
4301 colnr_T end_vcol; // end col for block mode operator
4302 long prev_opcount; // ca.opcount saved for K_CURSORHOLD
4303 long prev_count0; // ca.count0 saved for K_CURSORHOLD
Christian Brabandt544a38e2021-06-10 19:39:11 +02004304 int excl_tr_ws; // exclude trailing whitespace for yank of a
4305 // block
Bram Moolenaar071d4272004-06-13 20:20:40 +00004306} oparg_T;
4307
4308/*
4309 * Arguments for Normal mode commands.
4310 */
Bram Moolenaare344bea2005-09-01 20:46:49 +00004311typedef struct cmdarg_S
Bram Moolenaar071d4272004-06-13 20:20:40 +00004312{
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02004313 oparg_T *oap; // Operator arguments
4314 int prechar; // prefix character (optional, always 'g')
4315 int cmdchar; // command character
4316 int nchar; // next command character (optional)
4317 int ncharC1; // first composing character (optional)
4318 int ncharC2; // second composing character (optional)
4319 int extra_char; // yet another character (optional)
4320 long opcount; // count before an operator
4321 long count0; // count before command, default 0
4322 long count1; // count before command, default 1
4323 int arg; // extra argument from nv_cmds[]
4324 int retval; // return: CA_* values
4325 char_u *searchbuf; // return: pointer to search pattern or NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +00004326} cmdarg_T;
4327
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02004328// values for retval:
4329#define CA_COMMAND_BUSY 1 // skip restarting edit() once
4330#define CA_NO_ADJ_OP_END 2 // don't adjust operator end
Bram Moolenaar071d4272004-06-13 20:20:40 +00004331
4332#ifdef CURSOR_SHAPE
4333/*
4334 * struct to store values from 'guicursor' and 'mouseshape'
4335 */
Bram Moolenaar9bf703d2019-11-30 19:44:38 +01004336// Indexes in shape_table[]
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02004337#define SHAPE_IDX_N 0 // Normal mode
4338#define SHAPE_IDX_V 1 // Visual mode
4339#define SHAPE_IDX_I 2 // Insert mode
4340#define SHAPE_IDX_R 3 // Replace mode
4341#define SHAPE_IDX_C 4 // Command line Normal mode
4342#define SHAPE_IDX_CI 5 // Command line Insert mode
4343#define SHAPE_IDX_CR 6 // Command line Replace mode
4344#define SHAPE_IDX_O 7 // Operator-pending mode
4345#define SHAPE_IDX_VE 8 // Visual mode with 'selection' exclusive
4346#define SHAPE_IDX_CLINE 9 // On command line
4347#define SHAPE_IDX_STATUS 10 // A status line
4348#define SHAPE_IDX_SDRAG 11 // dragging a status line
4349#define SHAPE_IDX_VSEP 12 // A vertical separator line
4350#define SHAPE_IDX_VDRAG 13 // dragging a vertical separator line
4351#define SHAPE_IDX_MORE 14 // Hit-return or More
4352#define SHAPE_IDX_MOREL 15 // Hit-return or More in last line
4353#define SHAPE_IDX_SM 16 // showing matching paren
Bram Moolenaar071d4272004-06-13 20:20:40 +00004354#define SHAPE_IDX_COUNT 17
4355
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02004356#define SHAPE_BLOCK 0 // block cursor
4357#define SHAPE_HOR 1 // horizontal bar cursor
4358#define SHAPE_VER 2 // vertical bar cursor
Bram Moolenaar071d4272004-06-13 20:20:40 +00004359
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02004360#define MSHAPE_NUMBERED 1000 // offset for shapes identified by number
4361#define MSHAPE_HIDE 1 // hide mouse pointer
Bram Moolenaar071d4272004-06-13 20:20:40 +00004362
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02004363#define SHAPE_MOUSE 1 // used for mouse pointer shape
4364#define SHAPE_CURSOR 2 // used for text cursor shape
Bram Moolenaar071d4272004-06-13 20:20:40 +00004365
4366typedef struct cursor_entry
4367{
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02004368 int shape; // one of the SHAPE_ defines
4369 int mshape; // one of the MSHAPE defines
4370 int percentage; // percentage of cell for bar
4371 long blinkwait; // blinking, wait time before blinking starts
4372 long blinkon; // blinking, on time
4373 long blinkoff; // blinking, off time
4374 int id; // highlight group ID
4375 int id_lm; // highlight group ID for :lmap mode
4376 char *name; // mode name (fixed)
4377 char used_for; // SHAPE_MOUSE and/or SHAPE_CURSOR
Bram Moolenaar071d4272004-06-13 20:20:40 +00004378} cursorentry_T;
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02004379#endif // CURSOR_SHAPE
Bram Moolenaar071d4272004-06-13 20:20:40 +00004380
4381#ifdef FEAT_MENU
4382
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02004383// Indices into vimmenu_T->strings[] and vimmenu_T->noremap[] for each mode
Bram Moolenaar071d4272004-06-13 20:20:40 +00004384#define MENU_INDEX_INVALID -1
4385#define MENU_INDEX_NORMAL 0
4386#define MENU_INDEX_VISUAL 1
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00004387#define MENU_INDEX_SELECT 2
4388#define MENU_INDEX_OP_PENDING 3
4389#define MENU_INDEX_INSERT 4
4390#define MENU_INDEX_CMDLINE 5
Bram Moolenaar4c5d8152018-10-19 22:36:53 +02004391#define MENU_INDEX_TERMINAL 6
4392#define MENU_INDEX_TIP 7
4393#define MENU_MODES 8
Bram Moolenaar071d4272004-06-13 20:20:40 +00004394
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02004395// Menu modes
Bram Moolenaar071d4272004-06-13 20:20:40 +00004396#define MENU_NORMAL_MODE (1 << MENU_INDEX_NORMAL)
4397#define MENU_VISUAL_MODE (1 << MENU_INDEX_VISUAL)
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00004398#define MENU_SELECT_MODE (1 << MENU_INDEX_SELECT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004399#define MENU_OP_PENDING_MODE (1 << MENU_INDEX_OP_PENDING)
4400#define MENU_INSERT_MODE (1 << MENU_INDEX_INSERT)
4401#define MENU_CMDLINE_MODE (1 << MENU_INDEX_CMDLINE)
Bram Moolenaar4c5d8152018-10-19 22:36:53 +02004402#define MENU_TERMINAL_MODE (1 << MENU_INDEX_TERMINAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004403#define MENU_TIP_MODE (1 << MENU_INDEX_TIP)
4404#define MENU_ALL_MODES ((1 << MENU_INDEX_TIP) - 1)
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02004405// note MENU_INDEX_TIP is not a 'real' mode
Bram Moolenaar071d4272004-06-13 20:20:40 +00004406
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02004407// Start a menu name with this to not include it on the main menu bar
Bram Moolenaar071d4272004-06-13 20:20:40 +00004408#define MNU_HIDDEN_CHAR ']'
4409
Bram Moolenaar071d4272004-06-13 20:20:40 +00004410struct VimMenu
4411{
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02004412 int modes; // Which modes is this menu visible for?
4413 int enabled; // for which modes the menu is enabled
4414 char_u *name; // Name of menu, possibly translated
4415 char_u *dname; // Displayed Name ("name" without '&')
Bram Moolenaar70b11cd2010-05-14 22:24:40 +02004416#ifdef FEAT_MULTI_LANG
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02004417 char_u *en_name; // "name" untranslated, NULL when "name"
4418 // was not translated
4419 char_u *en_dname; // "dname" untranslated, NULL when "dname"
4420 // was not translated
Bram Moolenaar70b11cd2010-05-14 22:24:40 +02004421#endif
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02004422 char_u *actext; // accelerator text (after TAB)
Dominique Pelle3276f582021-08-07 12:44:41 +02004423 int mnemonic; // mnemonic key (after '&')
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02004424 int priority; // Menu order priority
Bram Moolenaar071d4272004-06-13 20:20:40 +00004425#ifdef FEAT_GUI
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02004426 void (*cb)(vimmenu_T *); // Call-back function
Bram Moolenaar071d4272004-06-13 20:20:40 +00004427#endif
4428#ifdef FEAT_TOOLBAR
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02004429 char_u *iconfile; // name of file for icon or NULL
4430 int iconidx; // icon index (-1 if not set)
4431 int icon_builtin; // icon names is BuiltIn{nr}
Bram Moolenaar071d4272004-06-13 20:20:40 +00004432#endif
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02004433 char_u *strings[MENU_MODES]; // Mapped string for each mode
4434 int noremap[MENU_MODES]; // A REMAP_ flag for each mode
4435 char silent[MENU_MODES]; // A silent flag for each mode
4436 vimmenu_T *children; // Children of sub-menu
4437 vimmenu_T *parent; // Parent of menu
4438 vimmenu_T *next; // Next item in menu
Bram Moolenaar071d4272004-06-13 20:20:40 +00004439#ifdef FEAT_GUI_X11
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02004440 Widget id; // Manage this to enable item
4441 Widget submenu_id; // If this is submenu, add children here
Bram Moolenaar071d4272004-06-13 20:20:40 +00004442#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004443#ifdef FEAT_GUI_GTK
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02004444 GtkWidget *id; // Manage this to enable item
4445 GtkWidget *submenu_id; // If this is submenu, add children here
Bram Moolenaar98921892016-02-23 17:14:37 +01004446# if defined(GTK_CHECK_VERSION) && !GTK_CHECK_VERSION(3,4,0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004447 GtkWidget *tearoff_handle;
Bram Moolenaar98921892016-02-23 17:14:37 +01004448# endif
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02004449 GtkWidget *label; // Used by "set wak=" code.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004450#endif
4451#ifdef FEAT_GUI_MOTIF
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02004452 int sensitive; // turn button on/off
4453 char **xpm; // pixmap data
4454 char *xpm_fname; // file with pixmap data
Bram Moolenaar071d4272004-06-13 20:20:40 +00004455#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004456#ifdef FEAT_BEVAL_TIP
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02004457 BalloonEval *tip; // tooltip for this menu item
Bram Moolenaar071d4272004-06-13 20:20:40 +00004458#endif
Bram Moolenaar4f974752019-02-17 17:44:42 +01004459#ifdef FEAT_GUI_MSWIN
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02004460 UINT id; // Id of menu item
4461 HMENU submenu_id; // If this is submenu, add children here
4462 HWND tearoff_handle; // hWnd of tearoff if created
Bram Moolenaar071d4272004-06-13 20:20:40 +00004463#endif
Ken Takatab52600d2024-01-12 17:31:07 +01004464#ifdef FEAT_GUI_HAIKU
Bram Moolenaarb3f74062020-02-26 16:16:53 +01004465 BMenuItem *id; // Id of menu item
4466 BMenu *submenu_id; // If this is submenu, add children here
4467# ifdef FEAT_TOOLBAR
4468 BPictureButton *button;
4469# endif
4470#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004471#ifdef FEAT_GUI_PHOTON
4472 PtWidget_t *id;
4473 PtWidget_t *submenu_id;
4474#endif
4475};
4476#else
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02004477// For generating prototypes when FEAT_MENU isn't defined.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004478typedef int vimmenu_T;
4479
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02004480#endif // FEAT_MENU
Bram Moolenaar071d4272004-06-13 20:20:40 +00004481
4482/*
4483 * Struct to save values in before executing autocommands for a buffer that is
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01004484 * not the current buffer.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004485 */
4486typedef struct
4487{
Bram Moolenaare76062c2022-11-28 18:51:43 +00004488 int use_aucmd_win_idx; // index in aucmd_win[] if >= 0
Bram Moolenaarcbcd9cb2020-11-07 16:58:59 +01004489 int save_curwin_id; // ID of saved curwin
4490 int new_curwin_id; // ID of new curwin
4491 int save_prevwin_id; // ID of saved prevwin
4492 bufref_T new_curbuf; // new curbuf
zeertzjq9d956ee2024-04-07 18:16:10 +02004493 char_u *tp_localdir; // saved value of tp_localdir
Bram Moolenaarcbcd9cb2020-11-07 16:58:59 +01004494 char_u *globaldir; // saved value of globaldir
Bram Moolenaarcb1956d2022-01-07 15:45:18 +00004495 int save_VIsual_active; // saved VIsual_active
Bram Moolenaar05a627c2023-04-09 22:01:31 +01004496 int save_State; // saved State
zeertzjqf2678472024-01-17 21:22:59 +01004497#ifdef FEAT_JOB_CHANNEL
4498 int save_prompt_insert; // saved b_prompt_insert
4499#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004500} aco_save_T;
4501
4502/*
4503 * Generic option table item, only used for printer at the moment.
4504 */
4505typedef struct
4506{
4507 const char *name;
4508 int hasnum;
4509 long number;
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02004510 char_u *string; // points into option string
Bram Moolenaar071d4272004-06-13 20:20:40 +00004511 int strlen;
4512 int present;
4513} option_table_T;
4514
4515/*
4516 * Structure to hold printing color and font attributes.
4517 */
4518typedef struct
4519{
4520 long_u fg_color;
4521 long_u bg_color;
4522 int bold;
4523 int italic;
4524 int underline;
Bram Moolenaare2cc9702005-03-15 22:43:58 +00004525 int undercurl;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004526} prt_text_attr_T;
4527
4528/*
4529 * Structure passed back to the generic printer code.
4530 */
4531typedef struct
4532{
4533 int n_collated_copies;
4534 int n_uncollated_copies;
4535 int duplex;
4536 int chars_per_line;
4537 int lines_per_page;
4538 int has_color;
4539 prt_text_attr_T number;
4540#ifdef FEAT_SYN_HL
4541 int modec;
4542 int do_syntax;
4543#endif
4544 int user_abort;
4545 char_u *jobname;
4546#ifdef FEAT_POSTSCRIPT
4547 char_u *outfile;
4548 char_u *arguments;
4549#endif
4550} prt_settings_T;
4551
4552#define PRINT_NUMBER_WIDTH 8
Bram Moolenaar8b6144b2006-02-08 09:20:24 +00004553
4554/*
4555 * Used for popup menu items.
4556 */
4557typedef struct
4558{
glepnir0fe17f82024-10-08 22:26:44 +02004559 char_u *pum_text; // main menu text
4560 char_u *pum_kind; // extra kind text (may be truncated)
4561 char_u *pum_extra; // extra menu text (may be truncated)
4562 char_u *pum_info; // extra info
4563 int pum_score; // fuzzy match score
4564 int pum_idx; // index of item before sorting by score
glepnir7baa0142024-10-09 20:19:25 +02004565 int pum_user_abbr_hlattr; // highlight attribute for abbr
glepnir0fe17f82024-10-08 22:26:44 +02004566 int pum_user_kind_hlattr; // highlight attribute for kind
Bram Moolenaar8b6144b2006-02-08 09:20:24 +00004567} pumitem_T;
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004568
4569/*
4570 * Structure used for get_tagfname().
4571 */
4572typedef struct
4573{
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02004574 char_u *tn_tags; // value of 'tags' when starting
4575 char_u *tn_np; // current position in tn_tags
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004576 int tn_did_filefind_init;
4577 int tn_hf_idx;
4578 void *tn_search_ctx;
4579} tagname_T;
4580
Bram Moolenaar55debbe2010-05-23 23:34:36 +02004581typedef struct {
4582 UINT32_T total[2];
4583 UINT32_T state[8];
4584 char_u buffer[64];
4585} context_sha256_T;
Bram Moolenaar520e1e42016-01-23 19:46:28 +01004586
4587/*
Bram Moolenaarc6f9f732018-02-11 19:06:26 +01004588 * types for expressions.
4589 */
4590typedef enum
4591{
Bram Moolenaar87396072019-12-31 22:36:18 +01004592 EXPR_UNKNOWN = 0,
4593 EXPR_EQUAL, // ==
4594 EXPR_NEQUAL, // !=
4595 EXPR_GREATER, // >
4596 EXPR_GEQUAL, // >=
4597 EXPR_SMALLER, // <
4598 EXPR_SEQUAL, // <=
4599 EXPR_MATCH, // =~
4600 EXPR_NOMATCH, // !~
4601 EXPR_IS, // is
4602 EXPR_ISNOT, // isnot
Bram Moolenaar8a7d6542020-01-26 15:56:19 +01004603 // used with ISN_OPNR
4604 EXPR_ADD, // +
4605 EXPR_SUB, // -
4606 EXPR_MULT, // *
4607 EXPR_DIV, // /
4608 EXPR_REM, // %
Yegappan Lakshmanana061f342022-05-22 19:13:49 +01004609 EXPR_LSHIFT, // <<
4610 EXPR_RSHIFT, // >>
Bram Moolenaar07802042021-09-09 23:01:14 +02004611 // used with ISN_ADDLIST
4612 EXPR_COPY, // create new list
4613 EXPR_APPEND, // append to first list
Bram Moolenaar657137c2021-01-09 15:45:23 +01004614} exprtype_T;
Bram Moolenaarc6f9f732018-02-11 19:06:26 +01004615
4616/*
Bram Moolenaar520e1e42016-01-23 19:46:28 +01004617 * Structure used for reading in json_decode().
4618 */
Bram Moolenaar56ead342016-02-02 18:20:08 +01004619struct js_reader
Bram Moolenaar520e1e42016-01-23 19:46:28 +01004620{
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02004621 char_u *js_buf; // text to be decoded
4622 char_u *js_end; // NUL in js_buf
4623 int js_used; // bytes used from js_buf
Bram Moolenaar56ead342016-02-02 18:20:08 +01004624 int (*js_fill)(struct js_reader *);
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02004625 // function to fill the buffer or NULL;
4626 // return TRUE when the buffer was filled
4627 void *js_cookie; // can be used by js_fill
4628 int js_cookie_arg; // can be used by js_fill
Bram Moolenaar56ead342016-02-02 18:20:08 +01004629};
4630typedef struct js_reader js_read_T;
Bram Moolenaar975b5272016-03-15 23:10:59 +01004631
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02004632// Maximum number of commands from + or -c arguments.
Bram Moolenaar502ae4b2016-07-16 19:50:13 +02004633#define MAX_ARG_CMDS 10
4634
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02004635// values for "window_layout"
4636#define WIN_HOR 1 // "-o" horizontally split windows
4637#define WIN_VER 2 // "-O" vertically split windows
4638#define WIN_TABS 3 // "-p" windows on tab pages
Bram Moolenaar502ae4b2016-07-16 19:50:13 +02004639
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02004640// Struct for various parameters passed between main() and other functions.
Bram Moolenaar502ae4b2016-07-16 19:50:13 +02004641typedef struct
4642{
4643 int argc;
4644 char **argv;
4645
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02004646 char_u *fname; // first file to edit
Bram Moolenaara8e691d2016-08-07 15:19:26 +02004647
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02004648 int evim_mode; // started as "evim"
4649 char_u *use_vimrc; // vimrc from -u argument
4650 int clean; // --clean argument
Bram Moolenaar502ae4b2016-07-16 19:50:13 +02004651
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02004652 int n_commands; // no. of commands from + or -c
4653 char_u *commands[MAX_ARG_CMDS]; // commands from + or -c arg.
4654 char_u cmds_tofree[MAX_ARG_CMDS]; // commands that need free()
4655 int n_pre_commands; // no. of commands from --cmd
4656 char_u *pre_commands[MAX_ARG_CMDS]; // commands from --cmd argument
Bram Moolenaar502ae4b2016-07-16 19:50:13 +02004657
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02004658 int edit_type; // type of editing to do
4659 char_u *tagname; // tag from -t argument
Bram Moolenaar502ae4b2016-07-16 19:50:13 +02004660#ifdef FEAT_QUICKFIX
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02004661 char_u *use_ef; // 'errorfile' from -q argument
Bram Moolenaar502ae4b2016-07-16 19:50:13 +02004662#endif
4663
4664 int want_full_screen;
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02004665 int not_a_term; // no warning for missing term?
Bram Moolenaar2d12c252022-06-13 21:42:45 +01004666#ifdef FEAT_GUI
4667 char_u *gui_dialog_file; // file to write dialog text in
4668#endif
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02004669 int tty_fail; // exit if not a tty
4670 char_u *term; // specified terminal name
Bram Moolenaar502ae4b2016-07-16 19:50:13 +02004671#ifdef FEAT_CRYPT
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02004672 int ask_for_key; // -x argument
Bram Moolenaar502ae4b2016-07-16 19:50:13 +02004673#endif
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02004674 int no_swap_file; // "-n" argument used
Bram Moolenaar502ae4b2016-07-16 19:50:13 +02004675#ifdef FEAT_EVAL
4676 int use_debug_break_level;
4677#endif
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02004678 int window_count; // number of windows to use
4679 int window_layout; // 0, WIN_HOR, WIN_VER or WIN_TABS
Bram Moolenaar502ae4b2016-07-16 19:50:13 +02004680
4681#ifdef FEAT_CLIENTSERVER
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02004682 int serverArg; // TRUE when argument for a server
4683 char_u *serverName_arg; // cmdline arg for server name
4684 char_u *serverStr; // remote server command
4685 char_u *serverStrEnc; // encoding of serverStr
4686 char_u *servername; // allocated name for our server
Bram Moolenaar502ae4b2016-07-16 19:50:13 +02004687#endif
4688#if !defined(UNIX)
4689# define EXPAND_FILENAMES
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02004690 int literal; // don't expand file names
Bram Moolenaar502ae4b2016-07-16 19:50:13 +02004691#endif
4692#ifdef MSWIN
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02004693 int full_path; // file name argument was full path
Bram Moolenaar502ae4b2016-07-16 19:50:13 +02004694#endif
4695#ifdef FEAT_DIFF
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02004696 int diff_mode; // start with 'diff' set
Bram Moolenaar502ae4b2016-07-16 19:50:13 +02004697#endif
4698} mparm_T;
Bram Moolenaara9b579f2016-07-17 18:29:19 +02004699
4700/*
4701 * Structure returned by get_lval() and used by set_var_lval().
4702 * For a plain name:
4703 * "name" points to the variable name.
4704 * "exp_name" is NULL.
4705 * "tv" is NULL
4706 * For a magic braces name:
4707 * "name" points to the expanded variable name.
4708 * "exp_name" is non-NULL, to be freed later.
4709 * "tv" is NULL
4710 * For an index in a list:
4711 * "name" points to the (expanded) variable name.
4712 * "exp_name" NULL or non-NULL, to be freed later.
4713 * "tv" points to the (first) list item value
4714 * "li" points to the (first) list item
4715 * "range", "n1", "n2" and "empty2" indicate what items are used.
Ernie Rael9771b2a2023-10-07 22:05:40 +02004716 * For a plain class or object:
4717 * "name" points to the variable name.
4718 * "exp_name" is NULL.
4719 * "tv" points to the variable
4720 * "is_root" TRUE
4721 * For a variable in a class/object: (class is not NULL)
Ernie Raelee865f32023-09-29 19:53:55 +02004722 * "name" points to the (expanded) variable name.
4723 * "exp_name" NULL or non-NULL, to be freed later.
Ernie Rael9771b2a2023-10-07 22:05:40 +02004724 * "tv" May point to class/object variable.
4725 * "object" object containing variable, NULL if class variable
4726 * "class" class of object or class containing variable
4727 * "oi" index into class/object of tv
Bram Moolenaara9b579f2016-07-17 18:29:19 +02004728 * For an existing Dict item:
4729 * "name" points to the (expanded) variable name.
4730 * "exp_name" NULL or non-NULL, to be freed later.
4731 * "tv" points to the dict item value
4732 * "newkey" is NULL
4733 * For a non-existing Dict item:
4734 * "name" points to the (expanded) variable name.
4735 * "exp_name" NULL or non-NULL, to be freed later.
4736 * "tv" points to the Dictionary typval_T
4737 * "newkey" is the key for the new item.
4738 */
4739typedef struct lval_S
4740{
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02004741 char_u *ll_name; // start of variable name (can be NULL)
Bram Moolenaar8a7d6542020-01-26 15:56:19 +01004742 char_u *ll_name_end; // end of variable name (can be NULL)
4743 type_T *ll_type; // type of variable (can be NULL)
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02004744 char_u *ll_exp_name; // NULL or expanded name in allocated memory.
Bram Moolenaard5f400c2022-01-06 21:10:28 +00004745
4746 scid_T ll_sid; // for an imported item: the script ID it was
4747 // imported from; zero otherwise
4748
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02004749 typval_T *ll_tv; // Typeval of item being used. If "newkey"
4750 // isn't NULL it's the Dict to which to add
4751 // the item.
4752 listitem_T *ll_li; // The list item or NULL.
4753 list_T *ll_list; // The list or NULL.
4754 int ll_range; // TRUE when a [i:j] range was used
Bram Moolenaard6beab02019-11-10 15:07:19 +01004755 int ll_empty2; // Second index is empty: [i:]
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02004756 long ll_n1; // First index for list
4757 long ll_n2; // Second index for list range
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02004758 dict_T *ll_dict; // The Dictionary or NULL
4759 dictitem_T *ll_di; // The dictitem or NULL
4760 char_u *ll_newkey; // New key for Dict in alloc. mem or NULL.
Bram Moolenaar10c65862020-10-08 21:16:42 +02004761 type_T *ll_valtype; // type expected for the value or NULL
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02004762 blob_T *ll_blob; // The Blob or NULL
Yegappan Lakshmanan9cb865e2025-03-23 16:42:16 +01004763 tuple_T *ll_tuple; // tuple or NULL
Bram Moolenaar99a7c0d2023-02-21 19:55:14 +00004764 ufunc_T *ll_ufunc; // The function or NULL
Ernie Raelee865f32023-09-29 19:53:55 +02004765 object_T *ll_object; // The object or NULL, class is not NULL
4766 class_T *ll_class; // The class or NULL, object may be NULL
4767 int ll_oi; // The object/class member index
Ernie Rael9771b2a2023-10-07 22:05:40 +02004768 int ll_is_root; // TRUE if ll_tv is the lval_root, like a
4769 // plain object/class. ll_tv is variable.
Yegappan Lakshmanan92195ae2024-12-22 14:44:35 +01004770 garray_T ll_type_list; // list of pointers to allocated types
Bram Moolenaara9b579f2016-07-17 18:29:19 +02004771} lval_T;
Bram Moolenaara21a6a92017-09-23 16:33:50 +02004772
Ernie Rael64885642023-10-04 20:16:22 +02004773/**
Ernie Rael0f058d12023-10-14 11:25:04 +02004774 * This specifies optional parameters for get_lval(). Arguments may be NULL.
Ernie Rael64885642023-10-04 20:16:22 +02004775 */
4776typedef struct lval_root_S {
Ernie Rael0f058d12023-10-14 11:25:04 +02004777 typval_T *lr_tv; // Base typval.
4778 class_T *lr_cl_exec; // Executing class for access checking.
4779 int lr_is_arg; // name is an arg (not a member).
Ernie Rael64885642023-10-04 20:16:22 +02004780} lval_root_T;
4781
Bram Moolenaar6cb39f92019-07-04 16:05:14 +02004782// Structure used to save the current state. Used when executing Normal mode
4783// commands while in any other mode.
Bram Moolenaara21a6a92017-09-23 16:33:50 +02004784typedef struct {
4785 int save_msg_scroll;
4786 int save_restart_edit;
4787 int save_msg_didout;
4788 int save_State;
4789 int save_insertmode;
4790 int save_finish_op;
4791 int save_opcount;
Bram Moolenaarcce713d2019-03-04 11:40:12 +01004792 int save_reg_executing;
zeertzjq6d4e7252022-04-07 13:58:04 +01004793 int save_pending_end_reg_executing;
Bram Moolenaar4324d872020-12-01 20:12:24 +01004794 int save_script_version;
Bram Moolenaara21a6a92017-09-23 16:33:50 +02004795 tasave_T tabuf;
4796} save_state_T;
Bram Moolenaarb0f42ba2018-05-12 15:38:26 +02004797
4798typedef struct {
4799 varnumber_T vv_prevcount;
4800 varnumber_T vv_count;
4801 varnumber_T vv_count1;
4802} vimvars_save_T;
Bram Moolenaar1063f3d2019-05-07 22:06:52 +02004803
4804// Scope for changing directory
4805typedef enum {
4806 CDSCOPE_GLOBAL, // :cd
4807 CDSCOPE_TABPAGE, // :tcd
4808 CDSCOPE_WINDOW // :lcd
4809} cdscope_T;
Bram Moolenaar451d4b52019-06-12 20:22:27 +02004810
Bram Moolenaardefa0672019-07-21 19:25:37 +02004811// Variable flavor
4812typedef enum
4813{
Bram Moolenaar4aea03e2019-09-25 22:37:17 +02004814 VAR_FLAVOUR_DEFAULT, // doesn't start with uppercase
4815 VAR_FLAVOUR_SESSION, // starts with uppercase, some lower
4816 VAR_FLAVOUR_VIMINFO // all uppercase
Bram Moolenaardefa0672019-07-21 19:25:37 +02004817} var_flavour_T;
4818
Bram Moolenaar451d4b52019-06-12 20:22:27 +02004819// argument for mouse_find_win()
4820typedef enum {
4821 IGNORE_POPUP, // only check non-popup windows
4822 FIND_POPUP, // also find popup windows
4823 FAIL_POPUP // return NULL if mouse on popup window
4824} mouse_find_T;
Bram Moolenaarc3328162019-07-23 22:15:25 +02004825
4826// Symbolic names for some registers.
4827#define DELETION_REGISTER 36
4828#ifdef FEAT_CLIPBOARD
4829# define STAR_REGISTER 37
4830# ifdef FEAT_X11
4831# define PLUS_REGISTER 38
4832# else
4833# define PLUS_REGISTER STAR_REGISTER // there is only one
4834# endif
4835#endif
4836#ifdef FEAT_DND
4837# define TILDE_REGISTER (PLUS_REGISTER + 1)
4838#endif
4839
4840#ifdef FEAT_CLIPBOARD
4841# ifdef FEAT_DND
4842# define NUM_REGISTERS (TILDE_REGISTER + 1)
4843# else
4844# define NUM_REGISTERS (PLUS_REGISTER + 1)
4845# endif
4846#else
4847# define NUM_REGISTERS 37
4848#endif
4849
Bram Moolenaar4aea03e2019-09-25 22:37:17 +02004850// structure used by block_prep, op_delete and op_yank for blockwise operators
4851// also op_change, op_shift, op_insert, op_replace - AKelly
4852struct block_def
4853{
4854 int startspaces; // 'extra' cols before first char
4855 int endspaces; // 'extra' cols after last char
4856 int textlen; // chars in block
4857 char_u *textstart; // pointer to 1st char (partially) in block
4858 colnr_T textcol; // index of chars (partially) in block
4859 colnr_T start_vcol; // start col of 1st char wholly inside block
4860 colnr_T end_vcol; // start col of 1st char wholly after block
4861 int is_short; // TRUE if line is too short to fit in block
4862 int is_MAX; // TRUE if curswant==MAXCOL when starting
4863 int is_oneChar; // TRUE if block within one character
4864 int pre_whitesp; // screen cols of ws before block
4865 int pre_whitesp_c; // chars of ws before block
4866 colnr_T end_char_vcols; // number of vcols of post-block char
4867 colnr_T start_char_vcols; // number of vcols of pre-block char
4868};
4869
Bram Moolenaarc3328162019-07-23 22:15:25 +02004870// Each yank register has an array of pointers to lines.
4871typedef struct
4872{
John Marriott79f6ffd2024-10-31 10:06:54 +01004873 string_T *y_array; // pointer to array of string_T structs
Bram Moolenaarc3328162019-07-23 22:15:25 +02004874 linenr_T y_size; // number of lines in y_array
4875 char_u y_type; // MLINE, MCHAR or MBLOCK
4876 colnr_T y_width; // only set if y_type == MBLOCK
4877#ifdef FEAT_VIMINFO
4878 time_t y_time_set;
4879#endif
4880} yankreg_T;
4881
4882// The offset for a search command is store in a soff struct
4883// Note: only spats[0].off is really used
4884typedef struct soffset
4885{
4886 int dir; // search direction, '/' or '?'
4887 int line; // search has line offset
4888 int end; // search set cursor at end
4889 long off; // line or char offset
4890} soffset_T;
4891
4892// A search pattern and its attributes are stored in a spat struct
4893typedef struct spat
4894{
4895 char_u *pat; // the pattern (in allocated memory) or NULL
zeertzjq88c8c542024-05-30 19:27:25 +02004896 size_t patlen; // the length of the pattern (0 if pat is NULL)
Bram Moolenaarc3328162019-07-23 22:15:25 +02004897 int magic; // magicness of the pattern
4898 int no_scs; // no smartcase for this pattern
4899 soffset_T off;
4900} spat_T;
Bram Moolenaar473952e2019-09-28 16:30:04 +02004901
Bram Moolenaar92ea26b2019-10-18 20:53:34 +02004902/*
4903 * Optional extra arguments for searchit().
4904 */
4905typedef struct
4906{
4907 linenr_T sa_stop_lnum; // stop after this line number when != 0
4908#ifdef FEAT_RELTIME
Paul Ollis65745772022-06-05 16:55:54 +01004909 long sa_tm; // timeout limit or zero
Bram Moolenaar92ea26b2019-10-18 20:53:34 +02004910 int sa_timed_out; // set when timed out
4911#endif
4912 int sa_wrapped; // search wrapped around
4913} searchit_arg_T;
4914
Bram Moolenaar9567efa2021-01-11 22:16:30 +01004915/*
4916 * Cookie used by getsourceline().
4917 */
4918/*
4919 * Cookie used to store info for each sourced file.
4920 * It is shared between do_source() and getsourceline().
4921 * This is passed to do_cmdline().
4922 */
4923typedef struct {
4924 FILE *fp; // opened file for sourcing
4925 char_u *nextline; // if not NULL: line that was read ahead
4926 linenr_T sourcing_lnum; // line number of the source file
4927 int finished; // ":finish" used
Yegappan Lakshmanan85b43c62022-03-21 19:45:17 +00004928 int source_from_buf;// TRUE if sourcing from current buffer
4929 int buf_lnum; // line number in the current buffer
4930 garray_T buflines; // lines in the current buffer
Bram Moolenaar9567efa2021-01-11 22:16:30 +01004931#ifdef USE_CRNL
4932 int fileformat; // EOL_UNKNOWN, EOL_UNIX or EOL_DOS
4933 int error; // TRUE if LF found after CR-LF
4934#endif
4935#ifdef FEAT_EVAL
4936 linenr_T breakpoint; // next line with breakpoint or zero
4937 char_u *fname; // name of sourced file
4938 int dbg_tick; // debug_tick when breakpoint was set
4939 int level; // top nesting level of sourced file
4940#endif
4941 vimconv_T conv; // type of conversion
4942} source_cookie_T;
4943
Bram Moolenaaradc17a52020-06-06 18:37:51 +02004944
Bram Moolenaar473952e2019-09-28 16:30:04 +02004945#define WRITEBUFSIZE 8192 // size of normal write buffer
4946
4947#define FIO_LATIN1 0x01 // convert Latin1
4948#define FIO_UTF8 0x02 // convert UTF-8
4949#define FIO_UCS2 0x04 // convert UCS-2
4950#define FIO_UCS4 0x08 // convert UCS-4
4951#define FIO_UTF16 0x10 // convert UTF-16
4952#ifdef MSWIN
4953# define FIO_CODEPAGE 0x20 // convert MS-Windows codepage
4954# define FIO_PUT_CP(x) (((x) & 0xffff) << 16) // put codepage in top word
4955# define FIO_GET_CP(x) (((x)>>16) & 0xffff) // get codepage from top word
4956#endif
4957#ifdef MACOS_CONVERT
4958# define FIO_MACROMAN 0x20 // convert MacRoman
4959#endif
4960#define FIO_ENDIAN_L 0x80 // little endian
4961#define FIO_ENCRYPTED 0x1000 // encrypt written bytes
4962#define FIO_NOCONVERT 0x2000 // skip encoding conversion
4963#define FIO_UCSBOM 0x4000 // check for BOM at start of file
kylo2529dac9b12022-03-27 20:05:17 +01004964#define FIO_ALL (-1) // allow all formats
Bram Moolenaar473952e2019-09-28 16:30:04 +02004965
4966// When converting, a read() or write() may leave some bytes to be converted
4967// for the next call. The value is guessed...
4968#define CONV_RESTLEN 30
4969
4970// We have to guess how much a sequence of bytes may expand when converting
4971// with iconv() to be able to allocate a buffer.
4972#define ICONV_MULT 8
Bram Moolenaarf4e20992020-12-21 19:59:08 +01004973
Bram Moolenaard93a7fc2021-01-04 12:42:13 +01004974// Used for "magic_overruled".
Bram Moolenaarf4e20992020-12-21 19:59:08 +01004975typedef enum {
Bram Moolenaard93a7fc2021-01-04 12:42:13 +01004976 OPTION_MAGIC_NOT_SET, // p_magic not overruled
4977 OPTION_MAGIC_ON, // magic on inside regexp
4978 OPTION_MAGIC_OFF // magic off inside regexp
4979} optmagic_T;
4980
4981// Magicness of a pattern, used by regexp code.
4982// The order and values matter:
4983// magic <= MAGIC_OFF includes MAGIC_NONE
4984// magic >= MAGIC_ON includes MAGIC_ALL
4985typedef enum {
4986 MAGIC_NONE = 1, // "\V" very unmagic
4987 MAGIC_OFF = 2, // "\M" or 'magic' off
4988 MAGIC_ON = 3, // "\m" or 'magic'
4989 MAGIC_ALL = 4 // "\v" very magic
Bram Moolenaarf4e20992020-12-21 19:59:08 +01004990} magic_T;
Bram Moolenaarf785aa12021-02-11 21:19:34 +01004991
LemonBoyc5d27442023-08-19 13:02:35 +02004992typedef enum {
4993 WT_UNKNOWN = 0, // Unknown or unspecified location
4994 WT_ARGUMENT,
4995 WT_VARIABLE,
4996 WT_MEMBER,
Yegappan Lakshmananf3b68d42023-09-29 22:50:02 +02004997 WT_METHOD, // object method
4998 WT_METHOD_ARG, // object method argument type
LemonBoy50d48542024-07-04 17:03:17 +02004999 WT_METHOD_RETURN, // object method return type
5000 WT_CAST, // type cast
LemonBoyc5d27442023-08-19 13:02:35 +02005001} wherekind_T;
5002
Yegappan Lakshmananf3b68d42023-09-29 22:50:02 +02005003// Struct used to pass the location of a type check. Used in error messages to
5004// indicate where the error happened. Also used for doing covariance type
5005// check for object method return type and contra-variance type check for
5006// object method arguments.
Bram Moolenaarf785aa12021-02-11 21:19:34 +01005007typedef struct {
LemonBoyc5d27442023-08-19 13:02:35 +02005008 char *wt_func_name; // function name or NULL
5009 char wt_index; // argument or variable index, 0 means unknown
Yegappan Lakshmananf3b68d42023-09-29 22:50:02 +02005010 wherekind_T wt_kind; // type check location
Bram Moolenaarf785aa12021-02-11 21:19:34 +01005011} where_T;
5012
LemonBoyc5d27442023-08-19 13:02:35 +02005013#define WHERE_INIT {NULL, 0, WT_UNKNOWN}
Bram Moolenaar7a3fe3e2021-07-22 14:58:47 +02005014
Bram Moolenaar3075a452021-11-17 15:51:52 +00005015// Struct passed to get_v_event() and restore_v_event().
5016typedef struct {
5017 int sve_did_save;
5018 hashtab_T sve_hashtab;
5019} save_v_event_T;
Yegappan Lakshmananf973eeb2021-12-22 18:19:26 +00005020
Ernie Raele79e2072024-01-13 11:47:33 +01005021// Enum used by filter(), map(), mapnew() and foreach()
Yegappan Lakshmananf973eeb2021-12-22 18:19:26 +00005022typedef enum {
5023 FILTERMAP_FILTER,
5024 FILTERMAP_MAP,
Ernie Raele79e2072024-01-13 11:47:33 +01005025 FILTERMAP_MAPNEW,
5026 FILTERMAP_FOREACH
Yegappan Lakshmananf973eeb2021-12-22 18:19:26 +00005027} filtermap_T;
5028
Bram Moolenaar18f47402022-01-06 13:24:51 +00005029// Structure used by switch_win() to pass values to restore_win()
5030typedef struct {
5031 win_T *sw_curwin;
5032 tabpage_T *sw_curtab;
5033 int sw_same_win; // VIsual_active was not reset
5034 int sw_visual_active;
5035} switchwin_T;
Yegappan Lakshmanan38b85cb2022-02-24 13:28:41 +00005036
5037// Fuzzy matched string list item. Used for fuzzy match completion. Items are
5038// usually sorted by 'score'. The 'idx' member is used for stable-sort.
5039typedef struct {
5040 int idx;
5041 char_u *str;
5042 int score;
5043} fuzmatch_str_T;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01005044
5045// Argument for lbr_chartabsize().
5046typedef struct {
5047 win_T *cts_win;
zeertzjqb557f482023-08-22 22:07:34 +02005048 char_u *cts_line; // start of the line
5049 char_u *cts_ptr; // current position in line
zeertzjq5b0722b2024-01-17 20:42:53 +01005050#ifdef FEAT_LINEBREAK
5051 int cts_bri_size; // cached size of 'breakindent', or -1
5052 // if not computed yet
5053#endif
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01005054#ifdef FEAT_PROP_POPUP
Bram Moolenaar34a1f772022-07-26 11:20:48 +01005055 int cts_text_prop_count; // number of text props; when zero
5056 // cts_text_props is not used
5057 textprop_T *cts_text_props; // text props (allocated)
zeertzjqb557f482023-08-22 22:07:34 +02005058 char cts_has_prop_with_text; // TRUE if a property inserts text
5059 int cts_cur_text_width; // width of current inserted text
Bram Moolenaar55a27d82023-02-12 18:03:57 +00005060 int cts_prop_lines; // nr of properties above or below
Bram Moolenaar856c5d22022-10-13 21:54:28 +01005061 int cts_first_char; // width text props above the line
Bram Moolenaarb7963df2022-07-31 17:12:43 +01005062 int cts_with_trailing; // include size of trailing props with
5063 // last character
Bram Moolenaar28c9f892022-08-14 13:28:55 +01005064 int cts_start_incl; // prop has true "start_incl" arg
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01005065#endif
zeertzjqb557f482023-08-22 22:07:34 +02005066 int cts_vcol; // virtual column at current position
5067 int cts_max_head_vcol; // see win_lbr_chartabsize()
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01005068} chartabsize_T;
Yegappan Lakshmananaf936912023-02-20 12:16:39 +00005069
5070/*
5071 * Argument for the callback function (opt_did_set_cb_T) invoked after an
5072 * option value is modified.
5073 */
5074typedef struct
5075{
Yegappan Lakshmananc727b192023-03-03 12:26:15 +00005076 // Pointer to the option variable. The variable can be a long (numeric
5077 // option), an int (boolean option) or a char pointer (string option).
5078 char_u *os_varp;
5079 int os_idx;
Yegappan Lakshmananaf936912023-02-20 12:16:39 +00005080 int os_flags;
Yee Cheng Chin6ee7b522023-10-01 09:13:22 +02005081 set_op_T os_op;
Yegappan Lakshmananaf936912023-02-20 12:16:39 +00005082
5083 // old value of the option (can be a string, number or a boolean)
5084 union
5085 {
5086 long number;
5087 int boolean;
5088 char_u *string;
5089 } os_oldval;
5090
5091 // new value of the option (can be a string, number or a boolean)
5092 union
5093 {
5094 long number;
5095 int boolean;
5096 char_u *string;
5097 } os_newval;
5098
Yegappan Lakshmanan5da901b2023-02-27 12:47:47 +00005099 // Option value was checked to be safe, no need to set P_INSECURE
5100 // Used for the 'keymap', 'filetype' and 'syntax' options.
5101 int os_value_checked;
5102 // Option value changed. Used for the 'filetype' and 'syntax' options.
5103 int os_value_changed;
5104
5105 // Used by the 'isident', 'iskeyword', 'isprint' and 'isfname' options.
5106 // Set to TRUE if the character table is modified when processing the
5107 // option and need to be restored because of a failure.
5108 int os_restore_chartab;
5109
Yegappan Lakshmananc727b192023-03-03 12:26:15 +00005110#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
5111 // Used by the 't_xxx' terminal options on MS-Windows.
5112 int os_did_swaptcap;
5113#endif
5114
Yegappan Lakshmanan6d611de2023-02-25 11:59:33 +00005115 // If the value specified for an option is not valid and the error message
5116 // is parameterized, then the "os_errbuf" buffer is used to store the error
5117 // message (when it is not NULL).
5118 char *os_errbuf;
Christian Brabandtb39b2402023-11-29 11:34:05 +01005119 // length of the error buffer
Mike Williams620f0112023-12-05 15:36:06 +01005120 size_t os_errbuflen;
Yegappan Lakshmananaf936912023-02-20 12:16:39 +00005121} optset_T;
Luuk van Baal30805a12023-05-27 22:22:10 +01005122
5123/*
Yee Cheng Chin900894b2023-09-29 20:42:32 +02005124 * Argument for the callback function (opt_expand_cb_T) invoked after a string
5125 * option value is expanded for cmdline completion.
5126 */
5127typedef struct
5128{
5129 // Pointer to the option variable. It's always a string.
5130 char_u *oe_varp;
5131 // The original option value, escaped.
5132 char_u *oe_opt_value;
5133
5134 // TRUE if using set+= instead of set=
5135 int oe_append;
5136 // TRUE if we would like to add the original option value as the first
5137 // choice.
5138 int oe_include_orig_val;
5139
5140 // Regex from the cmdline, for matching potential options against.
5141 regmatch_T *oe_regmatch;
5142 // The expansion context.
5143 expand_T *oe_xp;
5144
5145 // The full argument passed to :set. For example, if the user inputs
5146 // ':set dip=icase,algorithm:my<Tab>', oe_xp->xp_pattern will only have
5147 // 'my', but oe_set_arg will contain the whole 'icase,algorithm:my'.
5148 char_u *oe_set_arg;
5149} optexpand_T;
5150
5151/*
Luuk van Baal30805a12023-05-27 22:22:10 +01005152 * Spell checking variables passed from win_update() to win_line().
5153 */
5154typedef struct {
5155 int spv_has_spell; // drawn window has spell checking
5156#ifdef FEAT_SPELL
5157 int spv_unchanged; // not updating for changed text
5158 int spv_checked_col; // column in "checked_lnum" up to
5159 // which there are no spell errors
5160 linenr_T spv_checked_lnum; // line number for "checked_col"
5161 int spv_cap_col; // column to check for Cap word
5162 linenr_T spv_capcol_lnum; // line number for "cap_col"
5163#endif
5164} spellvars_T;
John Marriott78d742a2024-04-02 20:26:01 +02005165
5166// Return the length of a string literal
5167#define STRLEN_LITERAL(s) (sizeof(s) - 1)
5168
John Marriott8d4477e2024-11-02 15:59:01 +01005169// Store a key/value (string) pair
John Marriott78d742a2024-04-02 20:26:01 +02005170typedef struct
5171{
5172 int key; // the key
John Marriott8d4477e2024-11-02 15:59:01 +01005173 string_T value; // the value
John Marriott78d742a2024-04-02 20:26:01 +02005174} keyvalue_T;
5175
5176#define KEYVALUE_ENTRY(k, v) \
John Marriott8d4477e2024-11-02 15:59:01 +01005177 {(k), {((char_u *)v), STRLEN_LITERAL(v)}}
mikoto2000a73dfc22024-11-18 21:12:21 +01005178
Zoltan Arpadffy7b12ac32024-12-29 09:50:20 +01005179#if defined(UNIX) || defined(MSWIN) || defined(VMS)
mikoto2000a73dfc22024-11-18 21:12:21 +01005180// Defined as signed, to return -1 on error
5181struct cellsize {
5182 int cs_xpixel;
5183 int cs_ypixel;
5184};
5185#endif