robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

robinmerge: 1dc9728daa1d8a2702

master
61.3 KiB1415 linesraw
1#pragma once
2
3#include <stdbool.h>
4#include <stdint.h>
5#include <stdio.h>
6
7#include "nvim/arglist_defs.h"
8#include "nvim/grid_defs.h"
9#include "nvim/mapping_defs.h"
10#include "nvim/marktree_defs.h"
11#include "nvim/memline_defs.h"
12#include "nvim/normal_defs.h"
13#include "nvim/option_defs.h"
14#include "nvim/os/fs_defs.h"
15#include "nvim/statusline_defs.h"
16#include "nvim/types_defs.h"
17#include "nvim/undo_defs.h"
18
19/// Reference to a buffer that stores the value of buf_free_count.
20/// bufref_valid() only needs to check "buf" when the count differs.
21typedef struct {
22  buf_T *br_buf;
23  int br_fnum;
24  int br_buf_free_count;
25} bufref_T;
26
27#define GETFILE_SUCCESS(x)    ((x) <= 0)
28#define MODIFIABLE(buf) (buf->b_p_ma)
29
30// Flags for w_valid.
31// These are set when something in a window structure becomes invalid, except
32// when the cursor is moved.  Call check_cursor_moved() before testing one of
33// the flags.
34// These are reset when that thing has been updated and is valid again.
35//
36// Every function that invalidates one of these must call one of the
37// invalidate_* functions.
38//
39// w_valid is supposed to be used only in screen.c.  From other files, use the
40// functions that set or reset the flags.
41//
42// VALID_BOTLINE    VALID_BOTLINE_AP
43//     on       on      w_botline valid
44//     off      on      w_botline approximated
45//     off      off     w_botline not valid
46//     on       off     not possible
47#define VALID_WROW      0x01    // w_wrow (window row) is valid
48#define VALID_WCOL      0x02    // w_wcol (window col) is valid
49#define VALID_VIRTCOL   0x04    // w_virtcol (file col) is valid
50#define VALID_CHEIGHT   0x08    // w_cline_height and w_cline_folded valid
51#define VALID_CROW      0x10    // w_cline_row is valid
52#define VALID_BOTLINE   0x20    // w_botline and w_empty_rows are valid
53#define VALID_BOTLINE_AP 0x40   // w_botline is approximated
54#define VALID_TOPLINE   0x80    // w_topline is valid (for cursor position)
55
56// flags for b_flags
57#define BF_RECOVERED    0x01    // buffer has been recovered
58#define BF_CHECK_RO     0x02    // need to check readonly when loading file
59                                // into buffer (set by ":e", may be reset by
60                                // ":buf")
61#define BF_NEVERLOADED  0x04    // file has never been loaded into buffer,
62                                // many variables still need to be set
63#define BF_NOTEDITED    0x08    // Set when file name is changed after
64                                // starting to edit, reset when file is
65                                // written out.
66#define BF_NEW          0x10    // file didn't exist when editing started
67#define BF_NEW_W        0x20    // Warned for BF_NEW and file created
68#define BF_READERR      0x40    // got errors while reading the file
69#define BF_DUMMY        0x80    // Internal-only dummy buffer.
70#define BF_SYN_SET      0x200   // 'syntax' option was set
71
72// Mask to check for flags that prevent normal writing
73#define BF_WRITE_MASK   (BF_NOTEDITED + BF_NEW + BF_READERR)
74
75typedef struct wininfo_S WinInfo;
76typedef struct frame_S frame_T;
77typedef uint64_t disptick_T;  // display tick type
78
79// The taggy struct is used to store the information about a :tag command.
80typedef struct {
81  char *tagname;                // tag name
82  fmark_T fmark;                // cursor position BEFORE ":tag"
83  int cur_match;                // match number
84  int cur_fnum;                 // buffer number used for cur_match
85  char *user_data;              // used with tagfunc
86} taggy_T;
87
88// Structure that contains all options that are local to a window.
89// Used twice in a window: for the current buffer and for all buffers.
90// Also used in WinInfo.
91typedef struct {
92  int wo_arab;
93#define w_p_arab w_onebuf_opt.wo_arab  // 'arabic'
94  int wo_bri;
95#define w_p_bri w_onebuf_opt.wo_bri    // 'breakindent'
96  char *wo_briopt;
97#define w_p_briopt w_onebuf_opt.wo_briopt  // 'breakindentopt'
98  int wo_diff;
99#define w_p_diff w_onebuf_opt.wo_diff  // 'diff'
100  char *wo_fdc;
101#define w_p_eiw w_onebuf_opt.wo_eiw  // 'eventignorewin'
102  char *wo_eiw;
103#define w_p_fdc w_onebuf_opt.wo_fdc    // 'foldcolumn'
104  char *wo_fdc_save;
105#define w_p_fdc_save w_onebuf_opt.wo_fdc_save  // 'fdc' saved for diff mode
106  int wo_fen;
107#define w_p_fen w_onebuf_opt.wo_fen    // 'foldenable'
108  int wo_fen_save;
109  // 'foldenable' saved for diff mode
110#define w_p_fen_save w_onebuf_opt.wo_fen_save
111  char *wo_fdi;
112#define w_p_fdi w_onebuf_opt.wo_fdi    // 'foldignore'
113  OptInt wo_fdl;
114#define w_p_fdl w_onebuf_opt.wo_fdl    // 'foldlevel'
115  OptInt wo_fdl_save;
116  // 'foldlevel' state saved for diff mode
117#define w_p_fdl_save w_onebuf_opt.wo_fdl_save
118  char *wo_fdm;
119#define w_p_fdm w_onebuf_opt.wo_fdm    // 'foldmethod'
120  char *wo_fdm_save;
121#define w_p_fdm_save w_onebuf_opt.wo_fdm_save  // 'fdm' saved for diff mode
122  OptInt wo_fml;
123#define w_p_fml w_onebuf_opt.wo_fml    // 'foldminlines'
124  OptInt wo_fdn;
125#define w_p_fdn w_onebuf_opt.wo_fdn    // 'foldnestmax'
126  Callback wo_fde;
127#define w_p_fde w_onebuf_opt.wo_fde    // 'foldexpr'
128  Callback wo_fdt;
129#define w_p_fdt w_onebuf_opt.wo_fdt   // 'foldtext'
130  char *wo_fmr;
131#define w_p_fmr w_onebuf_opt.wo_fmr    // 'foldmarker'
132  int wo_lbr;
133#define w_p_lbr w_onebuf_opt.wo_lbr    // 'linebreak'
134  int wo_list;
135#define w_p_list w_onebuf_opt.wo_list   // 'list'
136  int wo_nu;
137#define w_p_nu w_onebuf_opt.wo_nu       // 'number'
138  int wo_rnu;
139#define w_p_rnu w_onebuf_opt.wo_rnu     // 'relativenumber'
140  char *wo_ve;
141#define w_p_ve w_onebuf_opt.wo_ve       // 'virtualedit'
142  unsigned wo_ve_flags;
143#define w_ve_flags w_onebuf_opt.wo_ve_flags  // flags for 'virtualedit'
144  OptInt wo_nuw;
145#define w_p_nuw w_onebuf_opt.wo_nuw    // 'numberwidth'
146  int wo_wfb;
147#define w_p_wfb w_onebuf_opt.wo_wfb    // 'winfixbuf'
148  int wo_wfh;
149#define w_p_wfh w_onebuf_opt.wo_wfh    // 'winfixheight'
150  int wo_wfw;
151#define w_p_wfw w_onebuf_opt.wo_wfw    // 'winfixwidth'
152  int wo_wp;
153#define w_p_wp w_onebuf_opt.wo_wp    // 'winpinned'
154  int wo_pvw;
155#define w_p_pvw w_onebuf_opt.wo_pvw    // 'previewwindow'
156  OptInt wo_lhi;
157#define w_p_lhi w_onebuf_opt.wo_lhi    // 'lhistory'
158  int wo_rl;
159#define w_p_rl w_onebuf_opt.wo_rl      // 'rightleft'
160  char *wo_rlc;
161#define w_p_rlc w_onebuf_opt.wo_rlc    // 'rightleftcmd'
162  OptInt wo_scr;
163#define w_p_scr w_onebuf_opt.wo_scr     // 'scroll'
164  int wo_sms;
165#define w_p_sms w_onebuf_opt.wo_sms     // 'smoothscroll'
166  int wo_spell;
167#define w_p_spell w_onebuf_opt.wo_spell  // 'spell'
168  int wo_cuc;
169#define w_p_cuc w_onebuf_opt.wo_cuc    // 'cursorcolumn'
170  int wo_cul;
171#define w_p_cul w_onebuf_opt.wo_cul    // 'cursorline'
172  char *wo_culopt;
173#define w_p_culopt w_onebuf_opt.wo_culopt  // 'cursorlineopt'
174  char *wo_cc;
175#define w_p_cc w_onebuf_opt.wo_cc      // 'colorcolumn'
176  char *wo_sbr;
177#define w_p_sbr w_onebuf_opt.wo_sbr    // 'showbreak'
178  char *wo_stc;
179#define w_p_stc w_onebuf_opt.wo_stc     // 'statuscolumn'
180  char *wo_stl;
181#define w_p_stl w_onebuf_opt.wo_stl     // 'statusline'
182  char *wo_wbr;
183#define w_p_wbr w_onebuf_opt.wo_wbr   // 'winbar'
184  int wo_scb;
185#define w_p_scb w_onebuf_opt.wo_scb    // 'scrollbind'
186  int wo_diff_saved;           // options were saved for starting diff mode
187#define w_p_diff_saved w_onebuf_opt.wo_diff_saved
188  int wo_scb_save;              // 'scrollbind' saved for diff mode
189#define w_p_scb_save w_onebuf_opt.wo_scb_save
190  int wo_wrap;
191#define w_p_wrap w_onebuf_opt.wo_wrap   // 'wrap'
192  int wo_wrap_save;             // 'wrap' state saved for diff mode
193#define w_p_wrap_save w_onebuf_opt.wo_wrap_save
194  char *wo_cocu;                 // 'concealcursor'
195#define w_p_cocu w_onebuf_opt.wo_cocu
196  OptInt wo_cole;                         // 'conceallevel'
197#define w_p_cole w_onebuf_opt.wo_cole
198  int wo_crb;
199#define w_p_crb w_onebuf_opt.wo_crb    // 'cursorbind'
200  int wo_crb_save;              // 'cursorbind' state saved for diff mode
201#define w_p_crb_save w_onebuf_opt.wo_crb_save
202  char *wo_scl;
203#define w_p_scl w_onebuf_opt.wo_scl    // 'signcolumn'
204  OptInt wo_siso;
205#define w_p_siso w_onebuf_opt.wo_siso  // 'sidescrolloff' local value
206  OptInt wo_so;
207#define w_p_so w_onebuf_opt.wo_so      // 'scrolloff' local value
208  OptInt wo_sop;
209#define w_p_sop w_onebuf_opt.wo_sop    // 'scrolloffpad' local value
210  char *wo_winhl;
211#define w_p_winhl w_onebuf_opt.wo_winhl    // 'winhighlight'
212  char *wo_lcs;
213#define w_p_lcs w_onebuf_opt.wo_lcs    // 'listchars'
214  char *wo_fcs;
215#define w_p_fcs w_onebuf_opt.wo_fcs    // 'fillchars'
216  OptInt wo_winbl;
217#define w_p_winbl w_onebuf_opt.wo_winbl  // 'winblend'
218
219  // A few options have local flags for kOptFlagInsecure.
220  uint32_t wo_wrap_flags;               // flags for 'wrap'
221#define w_p_wrap_flags w_onebuf_opt.wo_wrap_flags
222  uint32_t wo_stl_flags;                // flags for 'statusline'
223#define w_p_stl_flags w_onebuf_opt.wo_stl_flags
224  uint32_t wo_wbr_flags;                // flags for 'winbar'
225#define w_p_wbr_flags w_onebuf_opt.wo_wbr_flags
226  uint32_t wo_fde_flags;                // flags for 'foldexpr'
227#define w_p_fde_flags w_onebuf_opt.wo_fde_flags
228  uint32_t wo_fdt_flags;                // flags for 'foldtext'
229#define w_p_fdt_flags w_onebuf_opt.wo_fdt_flags
230
231  sctx_T wo_script_ctx[kWinOptCount];  // SCTXs for window-local options
232#define w_p_script_ctx w_onebuf_opt.wo_script_ctx
233} winopt_T;
234
235// Window info stored with a buffer.
236//
237// Two types of info are kept for a buffer which are associated with a
238// specific window:
239// 1. Each window can have a different line number associated with a buffer.
240// 2. The window-local options for a buffer work in a similar way.
241// The window-info is kept in a list at b_wininfo.  It is kept in
242// most-recently-used order.
243struct wininfo_S {
244  win_T *wi_win;          // pointer to window that did set wi_mark
245  fmark_T wi_mark;                // last cursor mark in the file
246  bool wi_optset;               // true when wi_opt has useful values
247  winopt_T wi_opt;              // local window options
248  bool wi_fold_manual;          // copy of w_fold_manual
249  garray_T wi_folds;            // clone of w_folds
250  int wi_changelistidx;         // copy of w_changelistidx
251};
252
253#define ALIST(win)      (win)->w_alist
254#define GARGLIST        ((aentry_T *)global_alist.al_ga.ga_data)
255#define ARGLIST         ((aentry_T *)ALIST(curwin)->al_ga.ga_data)
256#define WARGLIST(wp)    ((aentry_T *)ALIST(wp)->al_ga.ga_data)
257#define AARGLIST(al)    ((aentry_T *)((al)->al_ga.ga_data))
258#define GARGCOUNT       (global_alist.al_ga.ga_len)
259#define ARGCOUNT        (ALIST(curwin)->al_ga.ga_len)
260#define WARGCOUNT(wp)   (ALIST(wp)->al_ga.ga_len)
261
262// values for b_syn_spell: what to do with toplevel text
263#define SYNSPL_DEFAULT  0       // spell check if @Spell not defined
264#define SYNSPL_TOP      1       // spell check toplevel text
265#define SYNSPL_NOTOP    2       // don't spell check toplevel text
266
267// values for b_syn_foldlevel: how to compute foldlevel on a line
268#define SYNFLD_START    0       // use level of item at start of line
269#define SYNFLD_MINIMUM  1       // use lowest local minimum level on line
270
271typedef struct qf_info_S qf_info_T;
272
273// Used for :syntime: timing of executing a syntax pattern.
274typedef struct {
275  proftime_T total;             // total time used
276  proftime_T slowest;           // time of slowest call
277  int count;                    // nr of times used
278  int match;                    // nr of times matched
279} syn_time_T;
280
281// These are items normally related to a buffer.  But when using ":ownsyntax"
282// a window may have its own instance.
283typedef struct {
284  hashtab_T b_keywtab;                  // syntax keywords hash table
285  hashtab_T b_keywtab_ic;               // idem, ignore case
286  bool b_syn_error;                     // true when error occurred in HL
287  bool b_syn_slow;                      // true when 'redrawtime' reached
288  int b_syn_ic;                         // ignore case for :syn cmds
289  int b_syn_foldlevel;                  // how to compute foldlevel on a line
290  int b_syn_spell;                      // SYNSPL_ values
291  garray_T b_syn_patterns;              // table for syntax patterns
292  garray_T b_syn_clusters;              // table for syntax clusters
293  int b_spell_cluster_id;               // @Spell cluster ID or 0
294  int b_nospell_cluster_id;             // @NoSpell cluster ID or 0
295  int b_syn_containedin;                // true when there is an item with a
296                                        // "containedin" argument
297  int b_syn_sync_flags;                 // flags about how to sync
298  int16_t b_syn_sync_id;                // group to sync on
299  linenr_T b_syn_sync_minlines;         // minimal sync lines offset
300  linenr_T b_syn_sync_maxlines;         // maximal sync lines offset
301  linenr_T b_syn_sync_linebreaks;       // offset for multi-line pattern
302  char *b_syn_linecont_pat;             // line continuation pattern
303  regprog_T *b_syn_linecont_prog;       // line continuation program
304  syn_time_T b_syn_linecont_time;
305  int b_syn_linecont_ic;                // ignore-case flag for above
306  int b_syn_topgrp;                     // for ":syntax include"
307  int b_syn_conceal;                    // auto-conceal for :syn cmds
308  int b_syn_folditems;                  // number of patterns with the HL_FOLD
309                                        // flag set
310  // b_sst_array[] contains the state stack for a number of lines, for the
311  // start of that line (col == 0).  This avoids having to recompute the
312  // syntax state too often.
313  // b_sst_array[] is allocated to hold the state for all displayed lines,
314  // and states for 1 out of about 20 other lines.
315  // b_sst_array        pointer to an array of synstate_T
316  // b_sst_len          number of entries in b_sst_array[]
317  // b_sst_first        pointer to first used entry in b_sst_array[] or NULL
318  // b_sst_search       cached entry near the last accessed line, used as a
319  //                    start point for forward lookups, or NULL
320  // b_sst_firstfree    pointer to first free entry in b_sst_array[] or NULL
321  // b_sst_freecount    number of free entries in b_sst_array[]
322  // b_sst_check_lnum   entries after this lnum need to be checked for
323  //                    validity (MAXLNUM means no check needed)
324  synstate_T *b_sst_array;
325  int b_sst_len;
326  synstate_T *b_sst_first;
327  synstate_T *b_sst_search;
328  synstate_T *b_sst_firstfree;
329  int b_sst_freecount;
330  linenr_T b_sst_check_lnum;
331  disptick_T b_sst_lasttick;    // last display tick
332
333  // Cache for in_id_list(); see idl_cache_T in syntax.c.
334  void *b_idlist_cache;
335
336  // for spell checking
337  garray_T b_langp;           // list of pointers to slang_T, see spell.c
338  bool b_spell_ismw[256];     // flags: is midword char
339  char *b_spell_ismw_mb;      // multi-byte midword chars
340  char *b_p_spc;              // 'spellcapcheck'
341  regprog_T *b_cap_prog;      // program for 'spellcapcheck'
342  char *b_p_spf;              // 'spellfile'
343  char *b_p_spl;              // 'spelllang'
344  char *b_p_spo;              // 'spelloptions'
345  unsigned b_p_spo_flags;      // 'spelloptions' flags
346  int b_cjk;                  // all CJK letters as OK
347  uint64_t b_syn_chartab[4];  // syntax iskeyword option
348  char *b_syn_isk;            // iskeyword option
349} synblock_T;
350
351/// Type used for changedtick_di member in buf_T
352///
353/// Primary exists so that literals of relevant type can be made.
354typedef TV_DICTITEM_STRUCT(sizeof("changedtick")) ChangedtickDictItem;
355
356typedef struct {
357  LuaRef on_lines;
358  LuaRef on_bytes;
359  LuaRef on_changedtick;
360  LuaRef on_detach;
361  LuaRef on_reload;
362  bool utf_sizes;
363  bool preview;
364} BufUpdateCallbacks;
365#define BUF_UPDATE_CALLBACKS_INIT { LUA_NOREF, LUA_NOREF, LUA_NOREF, \
366                                    LUA_NOREF, LUA_NOREF, false, false }
367
368#define BUF_HAS_QF_ENTRY 1
369#define BUF_HAS_LL_ENTRY 2
370
371// Maximum number of maphash blocks we will have
372#define MAX_MAPHASH 256
373
374// buffer: structure that holds information about one file
375//
376// Several windows can share a single Buffer
377// A buffer is unallocated if there is no memfile for it.
378// A buffer is new if the associated file has never been loaded yet.
379
380struct file_buffer {
381  handle_T handle;              // unique id for the buffer (buffer number)
382#define b_fnum handle
383
384  memline_T b_ml;               // associated memline (also contains line count
385
386  buf_T *b_next;          // links in list of buffers
387  buf_T *b_prev;
388
389  int b_nwindows;               // nr of windows open on this buffer
390
391  int b_flags;                  // various BF_ flags
392  int b_locked;                 // Buffer is being closed or referenced, don't
393                                // let autocommands wipe it out.
394  int b_locked_split;           // Buffer is being closed, don't allow opening
395                                // it in more windows.
396  int b_ro_locked;              // Non-zero when the buffer can't be changed.
397                                // Used for FileChangedRO
398
399  // b_ffname   has the full path of the file (NULL for no name).
400  // b_sfname   is the name as the user typed it (or NULL).
401  // b_fname    is the same as b_sfname, unless ":cd" has been done,
402  //            then it is the same as b_ffname (NULL for no name).
403  char *b_ffname;          // full path file name, allocated
404  char *b_sfname;          // short file name, allocated, may be equal to
405                           // b_ffname
406  char *b_fname;           // current file name, points to b_ffname or
407                           // b_sfname
408
409  bool file_id_valid;
410  FileID file_id;
411
412  int b_changed;                // 'modified': Set to true if something in the
413                                // file has been changed and not written out.
414
415  /// Change-identifier incremented for each change, including undo.
416  ///
417  /// This is a dict item used to store b:changedtick.
418  ChangedtickDictItem changedtick_di;
419
420  varnumber_T b_last_changedtick;       // b:changedtick when TextChanged was
421                                        // last triggered.
422  varnumber_T b_last_changedtick_i;     // b:changedtick for TextChangedI/T
423  varnumber_T b_last_changedtick_pum;   // b:changedtick for TextChangedP
424
425  bool b_saving;                // Set to true if we are in the middle of
426                                // saving the buffer.
427
428  // Changes to a buffer require updating of the display.  To minimize the
429  // work, remember changes made and update everything at once.
430  bool b_mod_set;               // true when there are changes since the last
431                                // time the display was updated
432  linenr_T b_mod_top;           // topmost lnum that was changed
433  linenr_T b_mod_bot;           // lnum below last changed line, AFTER the
434                                // change
435  linenr_T b_mod_xlines;        // number of extra buffer lines inserted;
436                                // negative when lines were deleted
437  kvec_t(WinInfo *) b_wininfo;  // list of last used info for each window
438  disptick_T b_mod_tick_syn;    // last display tick syntax was updated
439  disptick_T b_mod_tick_decor;  // last display tick decoration providers were invoked
440
441  int64_t b_mtime;              // last change time of original file
442  int64_t b_mtime_ns;           // nanoseconds of last change time
443  int64_t b_mtime_read;         // last change time when reading
444  int64_t b_mtime_read_ns;      // nanoseconds of last read time
445  uint64_t b_orig_size;         // size of original file in bytes
446  int b_orig_mode;              // mode of original file
447  time_t b_last_used;           // time when the buffer was last used; used
448                                // for viminfo
449
450  fmark_T b_namedm[NMARKS];     // current named marks (mark.c)
451
452  // These variables are set when Visual.active becomes false
453  visualinfo_T b_visual;
454  int b_visual_mode_eval;            // b_visual.vi_mode for visualmode()
455
456  fmark_T b_last_cursor;        // cursor position when last unloading this
457                                // buffer
458  fmark_T b_last_insert;        // where Insert mode was left
459  fmark_T b_last_change;        // position of last change: '. mark
460
461  // the changelist contains old change positions
462  fmark_T b_changelist[JUMPLISTSIZE];
463  int b_changelistlen;                  // number of active entries
464  bool b_new_change;                    // set by u_savecommon()
465
466  // Character table, only used in charset.c for 'iskeyword'
467  // bitset with 4*64=256 bits: 1 bit per character 0-255.
468  uint64_t b_chartab[4];
469
470  // Buffer-local mappings.
471  mapblock_T *(b_maphash[MAX_MAPHASH]);
472  // Buffer-local abbreviations.
473  mapblock_T *b_first_abbr;
474  // Buffer-local user commands.
475  garray_T b_ucmds;
476
477  // start and end of an operator, also used for '[ and ']
478  pos_T b_op_start;
479  pos_T b_op_start_orig;  // used for Ins.start_orig
480  pos_T b_op_end;
481
482  bool b_marks_read;            // Have we read ShaDa marks yet?
483
484  bool b_modified_was_set;  ///< did ":set modified"
485  bool b_did_filetype;      ///< FileType event found
486  bool b_keep_filetype;     ///< value for did_filetype when starting
487                            ///< to execute autocommands
488
489  /// Set by the apply_autocmds_group function if the given event is equal to
490  /// EVENT_FILETYPE. Used by readfile() to determine whether read autocommands
491  /// triggered EVENT_FILETYPE.
492  ///
493  /// Relying on this value requires one to reset it prior calling
494  /// apply_autocmds_group().
495  bool b_au_did_filetype;
496
497  // The following only used in undo.c.
498  u_header_T *b_u_oldhead;     // pointer to oldest header
499  u_header_T *b_u_newhead;     // pointer to newest header; may not be valid
500                               // if b_u_curhead is not NULL
501  u_header_T *b_u_curhead;     // pointer to current header
502  int b_u_numhead;             // current number of headers
503  bool b_u_synced;             // entry lists are synced
504  int b_u_seq_last;            // last used undo sequence number
505  int b_u_save_nr_last;        // counter for last file write
506  int b_u_seq_cur;             // uh_seq of header below which we are now
507  time_t b_u_time_cur;         // uh_time of header below which we are now
508  int b_u_save_nr_cur;         // file write nr after which we are now
509
510  // variables for "U" command in undo.c
511  char *b_u_line_ptr;           // saved line for "U" command
512  linenr_T b_u_line_lnum;       // line number of line in u_line
513  colnr_T b_u_line_colnr;       // optional column number
514
515  bool b_scanned;               // ^N/^P have scanned this buffer
516
517  // flags for use of ":lmap" and IM control
518  OptInt b_p_iminsert;          // input mode for insert
519  OptInt b_p_imsearch;          // input mode for search
520#define B_IMODE_USE_INSERT (-1)  //  Use b_p_iminsert value for search
521#define B_IMODE_NONE 0          //  Input via none
522#define B_IMODE_LMAP 1          //  Input via langmap
523#define B_IMODE_LAST 1
524
525  int16_t b_kmap_state;         // using "lmap" mappings
526#define KEYMAP_INIT    1       // 'keymap' was set, call keymap_init()
527#define KEYMAP_LOADED  2       // 'keymap' mappings have been loaded
528  garray_T b_kmap_ga;           // the keymap table
529
530  // Options local to a buffer.
531  // They are here because their value depends on the type of file
532  // or contents of the file being edited.
533  bool b_p_initialized;                 // set when options initialized
534
535  sctx_T b_p_script_ctx[kBufOptCount];  // SCTXs for buffer-local options
536
537  int b_p_ac;                   ///< 'autocomplete'
538  int b_p_ai;                   ///< 'autoindent'
539  int b_p_ai_nopaste;           ///< b_p_ai saved for paste mode
540  char *b_p_bkc;                ///< 'backupco
541  unsigned b_bkc_flags;     ///< flags for 'backupco
542  int b_p_ci;                   ///< 'copyindent'
543  int b_p_bin;                  ///< 'binary'
544  int b_p_bomb;                 ///< 'bomb'
545  char *b_p_bh;                 ///< 'bufhidden'
546  char *b_p_bt;                 ///< 'buftype'
547  OptInt b_p_busy;              ///< 'busy'
548  int b_has_qf_entry;           ///< quickfix exists for buffer
549  int b_p_bl;                   ///< 'buflisted'
550  OptInt b_p_channel;           ///< 'channel'
551  int b_p_cin;                  ///< 'cindent'
552  char *b_p_cino;               ///< 'cinoptions'
553  char *b_p_cink;               ///< 'cinkeys'
554  char *b_p_cinw;               ///< 'cinwords'
555  char *b_p_cinsd;              ///< 'cinscopedecls'
556  char *b_p_com;                ///< 'comments'
557  char *b_p_cms;                ///< 'commentstring'
558  char *b_p_cot;                ///< 'completeopt' local value
559  unsigned b_cot_flags;         ///< flags for 'completeopt'
560  char *b_p_cpt;                ///< 'complete'
561#ifdef BACKSLASH_IN_FILENAME
562  char *b_p_csl;                ///< 'completeslash'
563#endif
564  uint32_t b_p_cpt_flags;       ///< flags for 'complete'
565  Callback *b_p_cpt_cb;         ///< F{func} in 'complete' callback
566  int b_p_cpt_count;            ///< Count of values in 'complete'
567  Callback b_p_cfu;             ///< 'completefunc'
568  Callback b_p_ofu;             ///< 'omnifunc'
569  Callback b_p_tfu;             ///< 'tagfunc'
570  Callback b_p_ffu;             ///< 'findfunc'
571  int b_p_eof;                  ///< 'endoffile'
572  int b_p_eol;                  ///< 'endofline'
573  int b_p_fixeol;               ///< 'fixendofline'
574  int b_p_et;                   ///< 'expandtab'
575  int b_p_et_nobin;             ///< b_p_et saved for binary mode
576  int b_p_et_nopaste;           ///< b_p_et saved for paste mode
577  char *b_p_fenc;               ///< 'fileencoding'
578  char *b_p_ff;                 ///< 'fileformat'
579  char *b_p_ft;                 ///< 'filetype'
580  int b_p_follow;               ///< 'follow'
581  char *b_p_fo;                 ///< 'formatoptions'
582  char *b_p_flp;                ///< 'formatlistpat'
583  int b_p_inf;                  ///< 'infercase'
584  char *b_p_isk;                ///< 'iskeyword'
585  char *b_p_def;                ///< 'define' local value
586  char *b_p_inc;                ///< 'include'
587  Callback b_p_inex;            ///< 'includeexpr'
588  uint32_t b_p_inex_flags;      ///< flags for 'includeexpr'
589  Callback b_p_inde;            ///< 'indentexpr'
590  uint32_t b_p_inde_flags;      ///< flags for 'indentexpr'
591  char *b_p_indk;               ///< 'indentkeys'
592  char *b_p_fp;                 ///< 'formatprg'
593  Callback b_p_fex;             ///< 'formatexpr'
594  uint32_t b_p_fex_flags;       ///< flags for 'formatexpr'
595  int b_p_fs;                   ///< 'fsync'
596  char *b_p_kp;                 ///< 'keywordprg'
597  int b_p_lisp;                 ///< 'lisp'
598  char *b_p_lop;                ///< 'lispoptions'
599  char *b_p_menc;               ///< 'makeencoding'
600  char *b_p_mps;                ///< 'matchpairs'
601  int b_p_ml;                   ///< 'modeline'
602  int b_p_ml_nobin;             ///< b_p_ml saved for binary mode
603  int b_p_ma;                   ///< 'modifiable'
604  char *b_p_nf;                 ///< 'nrformats'
605  int b_p_pi;                   ///< 'preserveindent'
606  char *b_p_qe;                 ///< 'quoteescape'
607  int b_p_ro;                   ///< 'readonly'
608  OptInt b_p_sw;                ///< 'shiftwidth'
609  OptInt b_p_scbk;              ///< 'scrollback'
610  int b_p_si;                   ///< 'smartindent'
611  OptInt b_p_sts;               ///< 'softtabstop'
612  OptInt b_p_sts_nopaste;       ///< b_p_sts saved for paste mode
613  char *b_p_sua;                ///< 'suffixesadd'
614  int b_p_swf;                  ///< 'swapfile'
615  OptInt b_p_smc;               ///< 'synmaxcol'
616  char *b_p_syn;                ///< 'syntax'
617  OptInt b_p_ts;                ///< 'tabstop'
618  OptInt b_p_tw;                ///< 'textwidth'
619  OptInt b_p_tw_nobin;          ///< b_p_tw saved for binary mode
620  OptInt b_p_tw_nopaste;        ///< b_p_tw saved for paste mode
621  OptInt b_p_wm;                ///< 'wrapmargin'
622  OptInt b_p_wm_nobin;          ///< b_p_wm saved for binary mode
623  OptInt b_p_wm_nopaste;        ///< b_p_wm saved for paste mode
624  char *b_p_vsts;               ///< 'varsofttabstop'
625  colnr_T *b_p_vsts_array;      ///< 'varsofttabstop' in internal format
626  char *b_p_vsts_nopaste;       ///< b_p_vsts saved for paste mode
627  char *b_p_vts;                ///< 'vartabstop'
628  colnr_T *b_p_vts_array;       ///< 'vartabstop' in internal format
629  char *b_p_keymap;             ///< 'keymap'
630
631  // local values for options which are normally global
632  char *b_p_gefm;               ///< 'grepformat' local value
633  char *b_p_gp;                 ///< 'grepprg' local value
634  char *b_p_mp;                 ///< 'makeprg' local value
635  char *b_p_efm;                ///< 'errorformat' local value
636  char *b_p_ep;                 ///< 'equalprg' local value
637  char *b_p_path;               ///< 'path' local value
638  int b_p_ar;                   ///< 'autoread' local value
639  char *b_p_tags;               ///< 'tags' local value
640  char *b_p_tc;                 ///< 'tagcase' local value
641  unsigned b_tc_flags;          ///< flags for 'tagcase'
642  char *b_p_dict;               ///< 'dictionary' local value
643  char *b_p_dia;                ///< 'diffanchors' local value
644  char *b_p_tsr;                ///< 'thesaurus' local value
645  Callback b_p_tsrfu;           ///< 'thesaurusfunc' local value
646  OptInt b_p_ul;                ///< 'undolevels' local value
647  int b_p_udf;                  ///< 'undofile'
648  char *b_p_lw;                 ///< 'lispwords' local value
649
650  // end of buffer options
651
652  // values set from b_p_cino
653  int b_ind_level;
654  int b_ind_open_imag;
655  int b_ind_no_brace;
656  int b_ind_first_open;
657  int b_ind_open_extra;
658  int b_ind_close_extra;
659  int b_ind_open_left_imag;
660  int b_ind_jump_label;
661  int b_ind_case;
662  int b_ind_case_code;
663  int b_ind_case_break;
664  int b_ind_param;
665  int b_ind_func_type;
666  int b_ind_comment;
667  int b_ind_in_comment;
668  int b_ind_in_comment2;
669  int b_ind_cpp_baseclass;
670  int b_ind_continuation;
671  int b_ind_unclosed;
672  int b_ind_unclosed2;
673  int b_ind_unclosed_noignore;
674  int b_ind_unclosed_wrapped;
675  int b_ind_unclosed_whiteok;
676  int b_ind_matching_paren;
677  int b_ind_paren_prev;
678  int b_ind_maxparen;
679  int b_ind_maxcomment;
680  int b_ind_scopedecl;
681  int b_ind_scopedecl_code;
682  int b_ind_java;
683  int b_ind_js;
684  int b_ind_keep_case_label;
685  int b_ind_hash_comment;
686  int b_ind_cpp_namespace;
687  int b_ind_if_for_while;
688  int b_ind_cpp_extern_c;
689  int b_ind_pragma;
690
691  linenr_T b_no_eol_lnum;       // non-zero lnum when last line of next binary
692                                // write should not have an end-of-line
693
694  int b_start_eof;              // last line had eof (CTRL-Z) when it was read
695  int b_start_eol;              // last line had eol when it was read
696  int b_start_ffc;              // first char of 'ff' when edit started
697  char *b_start_fenc;           // 'fileencoding' when edit started or NULL
698  int b_bad_char;               // "++bad=" argument when edit started or 0
699  int b_start_bomb;             // 'bomb' when it was read
700
701  ScopeDictDictItem b_bufvar;  ///< Variable for "b:" Dict.
702  dict_T *b_vars;  ///< b: scope Dict.
703
704  // When a buffer is created, it starts without a swap file.  b_may_swap is
705  // then set to indicate that a swap file may be opened later.  It is reset
706  // if a swap file could not be opened.
707  bool b_may_swap;
708  bool b_did_warn;              // Set to true if user has been warned on first
709                                // change of a read-only file
710
711  // Two special kinds of buffers:
712  // help buffer  - used for help files, won't use a swap file.
713  // spell buffer - used for spell info, never displayed and doesn't have a
714  //                file name.
715  bool b_help;                  // true for help file buffer (when set b_p_bt
716                                // is "help")
717  bool b_spell;                 // True for a spell file buffer, most fields
718                                // are not used!
719
720  char *b_prompt_text;          // set by prompt_setprompt()
721  Callback b_prompt_callback;   // set by prompt_setcallback()
722  Callback b_prompt_interrupt;  // set by prompt_setinterrupt()
723  bool b_prompt_append_new_line;  // prompt_appendlines() should start a newline
724  int b_prompt_insert;          // value for restart_edit when entering
725                                // a prompt buffer window.
726  fmark_T b_prompt_start;       // Start of the editable area of a prompt buffer.
727
728  synblock_T b_s;               // Info related to syntax highlighting.  w_s
729                                // normally points to this, but some windows
730                                // may use a different synblock_T.
731
732  struct {
733    int max;                    // maximum number of signs on a single line
734    int last_max;               // value of max when the buffer was last drawn
735    int count[SIGN_SHOW_MAX];   // number of lines with number of signs
736    bool autom;                 // whether 'signcolumn' is displayed in "auto:n>1"
737                                // configured window. "b_signcols" calculation
738                                // is skipped if false.
739  } b_signcols;
740
741  Terminal *terminal;           // Terminal instance associated with the buffer
742
743  AdditionalData *additional_data;      // Additional data from shada file if any.
744
745  int b_mapped_ctrl_c;          // modes where CTRL-C is mapped
746
747  MarkTree b_marktree[1];
748  Map(uint32_t, uint32_t) b_extmark_ns[1];         // extmark namespaces
749
750  // Store the line count as it was before appending or inserting lines.
751  // Used to determine a valid range before splicing marks, when the line
752  // count has already changed.
753  int b_prev_line_count;
754
755  // array of channel_id:s which have asked to receive updates for this
756  // buffer.
757  kvec_t(uint64_t) update_channels;
758  // array of lua callbacks for buffer updates.
759  kvec_t(BufUpdateCallbacks) update_callbacks;
760
761  // whether an update callback has requested codepoint size of deleted regions.
762  bool update_need_codepoints;
763
764  // Measurements of the deleted or replaced region since the last update
765  // event. Some consumers of buffer changes need to know the byte size (like
766  // treesitter) or the corresponding UTF-32/UTF-16 size (like LSP) of the
767  // deleted text.
768  size_t deleted_bytes;
769  size_t deleted_bytes2;
770  size_t deleted_codepoints;
771  size_t deleted_codeunits;
772
773  // The number for times the current line has been flushed in the memline.
774  int flush_count;
775
776  char *b_localdir;       ///< Absolute path of local cwd or NULL.
777  char *b_prevdir;        ///< Previous directory.
778};
779
780// Stuff for diff mode.
781#define DB_COUNT 8     // up to four buffers can be diff'ed
782
783/// Each diffblock defines where a block of lines starts in each of the buffers
784/// and how many lines it occupies in that buffer.  When the lines are missing
785/// in the buffer the df_count[] is zero.  This is all counted in
786/// buffer lines.
787/// Usually there is always at least one unchanged line in between the diffs as
788/// otherwise it would have been included in the diff above or below it.  When
789/// linematch or diff anchors are used, this is no longer guaranteed, and we may
790/// have adjacent diff blocks.  In all cases they will not overlap, although it
791/// is possible to have multiple 0-count diff blocks at the same line.
792/// df_lnum[] + df_count[] is the lnum below the change.  When in one buffer
793/// lines have been inserted, in the other buffer df_lnum[] is the line below
794/// the insertion and df_count[] is zero.  When appending lines at the end of
795/// the buffer, df_lnum[] is one beyond the end!
796/// This is using a linked list, because the number of differences is expected
797/// to be reasonable small.  The list is sorted on lnum.
798/// Each diffblock also contains a cached list of inline diff of changes within
799/// the block, used for highlighting.
800typedef struct diffblock_S diff_T;
801struct diffblock_S {
802  diff_T *df_next;
803  linenr_T df_lnum[DB_COUNT];           // line number in buffer
804  linenr_T df_count[DB_COUNT];          // nr of inserted/changed lines
805  bool is_linematched;  // has the linematch algorithm ran on this diff hunk to divide it into
806                        // smaller diff hunks?
807
808  bool has_changes;     ///< has cached list of inline changes
809  garray_T df_changes;  ///< list of inline changes (diffline_change_T)
810};
811
812/// Each entry stores a single inline change within a diff block. Line numbers
813/// are recorded as relative offsets, and columns are byte offsets, not
814/// character counts.
815/// Ranges are [start,end), with the end being exclusive.
816typedef struct diffline_change_S diffline_change_T;
817struct diffline_change_S {
818  colnr_T dc_start[DB_COUNT];       ///< byte offset of start of range in the line
819  colnr_T dc_end[DB_COUNT];         ///< 1 past byte offset of end of range in line
820  int dc_start_lnum_off[DB_COUNT];  ///< starting line offset
821  int dc_end_lnum_off[DB_COUNT];    ///< end line offset
822};
823
824/// Describes a single line's list of inline changes. Use diff_change_parse() to
825/// parse this.
826typedef struct diffline_S diffline_T;
827struct diffline_S {
828  diffline_change_T *changes;
829  int num_changes;
830  int bufidx;
831  int lineoff;
832};
833
834#define SNAP_HELP_IDX       0
835#define SNAP_AUCMD_IDX      1
836#define SNAP_QUICKFIX_IDX   2
837#define SNAP_COUNT          3
838
839/// Tab pages point to the top frame of each tab page.
840/// Note: Most values are NOT valid for the current tab page!  Use "curwin",
841/// "firstwin", etc. for that.  "tp_topframe" is always valid and can be
842/// compared against "topframe" to find the current tab page.
843typedef struct tabpage_S tabpage_T;
844struct tabpage_S {
845  handle_T handle;
846  tabpage_T *tp_next;         ///< next tabpage or NULL
847  frame_T *tp_topframe;       ///< topframe for the windows
848  win_T *tp_curwin;           ///< current window in this Tab page
849  win_T *tp_prevwin;          ///< previous window in this Tab page
850  win_T *tp_firstwin;         ///< first window in this Tab page
851  win_T *tp_lastwin;          ///< last window in this Tab page
852  int64_t tp_old_Rows_avail;  ///< ROWS_AVAIL when Tab page was left
853  int64_t tp_old_Columns;     ///< Columns when Tab page was left, -1 when
854                              ///< calling win_new_screen_cols() postponed
855  OptInt tp_ch_used;          ///< value of 'cmdheight' when frame size was set
856  bool tp_did_tabclosedpre;   ///< whether TabClosedPre was triggered
857
858  diff_T *tp_first_diff;
859  buf_T *(tp_diffbuf[DB_COUNT]);
860  int tp_diff_invalid;              ///< list of diffs is outdated
861  int tp_diff_update;               ///< update diffs before redrawing
862  frame_T *(tp_snapshot[SNAP_COUNT]);    ///< window layout snapshots
863  ScopeDictDictItem tp_winvar;      ///< Variable for "t:" Dict.
864  dict_T *tp_vars;         ///< Internal variables, local to tab page.
865  char *tp_localdir;       ///< Absolute path of local cwd or NULL.
866  char *tp_prevdir;        ///< Previous directory.
867};
868
869// Structure to cache info for displayed lines in w_lines[].
870// Each logical line has one entry.
871// The entry tells how the logical line is currently displayed in the window.
872// This is updated when displaying the window.
873// When the display is changed (e.g., when clearing the screen) w_lines_valid
874// is changed to exclude invalid entries.
875// When making changes to the buffer, wl_valid is reset to indicate wl_size
876// may not reflect what is actually in the buffer.  When wl_valid is false,
877// the entries can only be used to count the number of displayed lines used.
878// wl_lnum and wl_lastlnum are invalid too.
879typedef struct {
880  linenr_T wl_lnum;             // buffer line number for logical line
881  uint16_t wl_size;             // height in screen lines
882  bool wl_valid;                // true values are valid for text in buffer
883  bool wl_folded;               // true when this is a range of folded lines
884  linenr_T wl_foldend;          // last buffer line number for folded line
885  linenr_T wl_lastlnum;         // last buffer line number for logical line
886} wline_T;
887
888// Windows are kept in a tree of frames.  Each frame has a column (FR_COL)
889// or row (FR_ROW) layout or is a leaf, which has a window.
890struct frame_S {
891  char fr_layout;               // FR_LEAF, FR_COL or FR_ROW
892  int fr_width;
893  int fr_newwidth;              // new width used in win_equal_rec()
894  int fr_height;
895  int fr_newheight;             // new height used in win_equal_rec()
896  frame_T *fr_parent;       // containing frame or NULL
897  frame_T *fr_next;         // frame right or below in same parent, NULL
898                            // for last
899  frame_T *fr_prev;         // frame left or above in same parent, NULL
900                            // for first
901  // fr_child and fr_win are mutually exclusive
902  frame_T *fr_child;        // first contained frame
903  win_T *fr_win;        // window that fills this frame; for a snapshot
904                        // set to the current window
905};
906
907#define FR_LEAF 0       // frame is a leaf
908#define FR_ROW  1       // frame with a row of windows
909#define FR_COL  2       // frame with a column of windows
910
911// Struct used for highlighting 'hlsearch' matches, matches defined by
912// ":match" and matches defined by match functions.
913// For 'hlsearch' there is one pattern for all windows.  For ":match" and the
914// match functions there is a different pattern for each window.
915typedef struct {
916  regmmatch_T rm;       // points to the regexp program; contains last found
917                        // match (may continue in next line)
918  buf_T *buf;     // the buffer to search for a match
919  linenr_T lnum;        // the line to search for a match
920  int attr;             // attributes to be used for a match
921  int attr_cur;         // attributes currently active in win_line()
922  linenr_T first_lnum;  // first lnum to search for multi-line pat
923  colnr_T startcol;     // in win_line() points to char where HL starts
924  colnr_T endcol;       // in win_line() points to char where HL ends
925  bool is_addpos;       // position specified directly by matchaddpos()
926  bool has_cursor;      // true if the cursor is inside the match, used for CurSearch
927  proftime_T tm;        // for a time limit
928} match_T;
929
930/// Same as lpos_T, but with additional field len.
931typedef struct {
932  linenr_T lnum;   ///< line number
933  colnr_T col;    ///< column number
934  int len;    ///< length: 0 - to the end of line
935} llpos_T;
936
937/// matchitem_T provides a linked list for storing match items for ":match",
938/// matchadd() and matchaddpos().
939typedef struct matchitem matchitem_T;
940struct matchitem {
941  matchitem_T *mit_next;
942  int mit_id;              ///< match ID
943  int mit_priority;        ///< match priority
944
945  // Either a pattern is defined (mit_pattern is not NUL) or a list of
946  // positions is given (mit_pos is not NULL and mit_pos_count > 0).
947  char *mit_pattern;       ///< pattern to highlight
948  regmmatch_T mit_match;   ///< regexp program for pattern
949
950  llpos_T *mit_pos_array;  ///< array of positions
951  int mit_pos_count;       ///< nr of entries in mit_pos
952  int mit_pos_cur;         ///< internal position counter
953  linenr_T mit_toplnum;    ///< top buffer line
954  linenr_T mit_botlnum;    ///< bottom buffer line
955
956  match_T mit_hl;          ///< struct for doing the actual highlighting
957  int mit_hlg_id;          ///< highlight group ID
958  int mit_conceal_char;    ///< cchar for Conceal highlighting
959};
960
961typedef int FloatAnchor;
962
963enum {
964  kFloatAnchorEast  = 1,
965  kFloatAnchorSouth = 2,
966};
967
968/// Keep in sync with float_relative_str[] in nvim_win_get_config()
969typedef enum {
970  kFloatRelativeEditor = 0,
971  kFloatRelativeWindow = 1,
972  kFloatRelativeCursor = 2,
973  kFloatRelativeMouse = 3,
974  kFloatRelativeTabline = 4,
975  kFloatRelativeLaststatus = 5,
976} FloatRelative;
977
978typedef enum {
979  kWinNormal = 0,  ///< Non-special window (split or float).
980  kWinInfo,        ///< Completion-menu "info" popup.
981  kWinPreview,     ///< 'previewpopup' window.
982} WinKind;
983
984/// Keep in sync with win_split_str[] in nvim_win_get_config() (api/win_config.c)
985typedef enum {
986  kWinSplitLeft = 0,
987  kWinSplitRight = 1,
988  kWinSplitAbove = 2,
989  kWinSplitBelow = 3,
990} WinSplit;
991
992typedef enum {
993  kWinStyleUnused = 0,
994  kWinStyleMinimal,  ///< Minimal UI: no number column, eob markers, etc
995} WinStyle;
996
997typedef enum {
998  kAlignLeft   = 0,
999  kAlignCenter = 1,
1000  kAlignRight  = 2,
1001} AlignTextPos;
1002
1003typedef enum {
1004  kBorderTextTitle = 0,
1005  kBorderTextFooter = 1,
1006} BorderTextType;
1007
1008/// See ":help nvim_open_win()" for documentation.
1009typedef struct {
1010  Window window;
1011  lpos_T bufpos;
1012  int height, width;
1013  double row, col;
1014  FloatAnchor anchor;
1015  FloatRelative relative;
1016  bool external;
1017  bool focusable;
1018  bool mouse;
1019  WinSplit split;
1020  int zindex;
1021  WinStyle style;
1022  bool border;
1023  bool shadow;
1024  char border_chars[8][MAX_SCHAR_SIZE];
1025  int border_hl_ids[8];
1026  int border_attr[8];
1027  bool title;
1028  AlignTextPos title_pos;
1029  VirtText title_chunks;
1030  int title_width;
1031  bool footer;
1032  AlignTextPos footer_pos;
1033  VirtText footer_chunks;
1034  int footer_width;
1035  bool noautocmd;
1036  bool fixed;
1037  bool hide;
1038  int _cmdline_offset;
1039} WinConfig;
1040
1041#define WIN_CONFIG_INIT ((WinConfig){ .height = 0, .width = 0, \
1042                                      .bufpos = { -1, 0 }, \
1043                                      .row = 0, .col = 0, .anchor = 0, \
1044                                      .relative = 0, .external = false, \
1045                                      .focusable = true, \
1046                                      .mouse = true, \
1047                                      .split = 0, \
1048                                      .zindex = kZIndexFloatDefault, \
1049                                      .style = kWinStyleUnused, \
1050                                      .noautocmd = false, \
1051                                      .hide = false, \
1052                                      .fixed = false, \
1053                                      ._cmdline_offset = INT_MAX })
1054
1055// Structure to store last cursor position and topline.  Used by check_lnums()
1056// and reset_lnums().
1057typedef struct {
1058  int w_topline_save;   // original topline value
1059  int w_topline_corr;   // corrected topline value
1060  pos_T w_cursor_save;  // original cursor position
1061  pos_T w_cursor_corr;  // corrected cursor position
1062} pos_save_T;
1063
1064/// Characters from the 'listchars' option.
1065typedef struct {
1066  schar_T eol;
1067  schar_T ext;
1068  schar_T prec;
1069  schar_T nbsp;
1070  schar_T space;
1071  schar_T tab1;  ///< first tab character
1072  schar_T tab2;  ///< second tab character
1073  schar_T tab3;  ///< third tab character
1074  schar_T leadtab1;
1075  schar_T leadtab2;
1076  schar_T leadtab3;
1077  schar_T lead;
1078  schar_T trail;
1079  schar_T *multispace;
1080  schar_T *leadmultispace;
1081  schar_T conceal;
1082} lcs_chars_T;
1083
1084/// Characters from the 'fillchars' option.
1085typedef struct {
1086  schar_T stl;
1087  schar_T stlnc;
1088  schar_T wbr;
1089  schar_T horiz;
1090  schar_T horizup;
1091  schar_T horizdown;
1092  schar_T vert;
1093  schar_T vertleft;
1094  schar_T vertright;
1095  schar_T verthoriz;
1096  schar_T fold;
1097  schar_T foldopen;    ///< when fold is open
1098  schar_T foldclosed;  ///< when fold is closed
1099  schar_T foldsep;     ///< continuous fold marker
1100  schar_T foldinner;
1101  schar_T diff;
1102  schar_T msgsep;
1103  schar_T eob;
1104  schar_T lastline;
1105  schar_T trunc;
1106  schar_T truncrl;
1107} fcs_chars_T;
1108
1109/// Structure which contains all information that belongs to a window.
1110///
1111/// All row numbers are relative to the start of the window, except w_winrow.
1112struct window_S {
1113  handle_T handle;                  ///< unique identifier for the window
1114
1115  buf_T *w_buffer;            ///< buffer we are a window into (used
1116                              ///< often, keep it the first item!)
1117
1118  synblock_T *w_s;                 ///< for :ownsyntax
1119
1120  int w_ns_hl;
1121  int w_ns_hl_winhl;
1122  int w_ns_hl_active;
1123  int *w_ns_hl_attr;
1124
1125  Set(uint32_t) w_ns_set;
1126
1127  int w_hl_id_normal;               ///< 'winhighlight' normal id
1128  int w_hl_attr_normal;             ///< 'winhighlight' normal final attrs
1129  int w_hl_attr_normalnc;           ///< 'winhighlight' NormalNC final attrs
1130
1131  int w_hl_needs_update;            ///< attrs need to be recalculated
1132
1133  win_T *w_prev;              ///< link to previous window
1134  win_T *w_next;              ///< link to next window
1135  int w_locked;                     ///< don't let autocommands close the window
1136
1137  frame_T *w_frame;             ///< frame containing this window
1138
1139  pos_T w_cursor;                   ///< cursor position in buffer
1140
1141  colnr_T w_curswant;               ///< Column we want to be at.  This is
1142                                    ///< used to try to stay in the same column
1143                                    ///< for up/down cursor motions.
1144
1145  bool w_set_curswant;              // If set, then update w_curswant the next
1146                                    // time through cursupdate() to the
1147                                    // current virtual column
1148
1149  linenr_T w_cursorline;            ///< Where 'cursorline' should be drawn,
1150                                    ///< can be different from w_cursor.lnum
1151                                    ///< for closed folds.
1152  linenr_T w_last_cursorline;       ///< where last 'cursorline' was drawn
1153
1154  // the next seven are used to update the visual part
1155  char w_old_visual_mode;           ///< last known Visual.mode
1156  linenr_T w_old_cursor_lnum;       ///< last known end of visual part
1157  colnr_T w_old_cursor_fcol;        ///< first column for block visual part
1158  colnr_T w_old_cursor_lcol;        ///< last column for block visual part
1159  linenr_T w_old_visual_lnum;       ///< last known start of visual part
1160  colnr_T w_old_visual_col;         ///< last known start of visual part
1161  colnr_T w_old_curswant;           ///< last known value of Curswant
1162
1163  linenr_T w_last_cursor_lnum_rnu;  ///< cursor lnum when 'rnu' was last redrawn
1164
1165  /// 'listchars' characters. Defaults set in set_chars_option().
1166  lcs_chars_T w_p_lcs_chars;
1167
1168  /// 'fillchars' characters. Defaults set in set_chars_option().
1169  fcs_chars_T w_p_fcs_chars;
1170
1171  // "w_topline", "w_leftcol" and "w_skipcol" specify the offsets for
1172  // displaying the buffer.
1173  linenr_T w_topline;               // buffer line number of the line at the
1174                                    // top of the window
1175  bool w_topline_was_set;           // flag set to true when topline is set,
1176                                    // e.g. by winrestview()
1177  int w_topfill;                    // number of filler lines above w_topline
1178  int w_old_topfill;                // w_topfill at last redraw
1179  bool w_botfill;                   // true when filler lines are actually
1180                                    // below w_topline (at end of file)
1181  bool w_old_botfill;               // w_botfill at last redraw
1182  colnr_T w_leftcol;                // screen column number of the left most
1183                                    // character in the window; used when
1184                                    // 'wrap' is off
1185  colnr_T w_skipcol;                // starting screen column for the first
1186                                    // line in the window; used when 'wrap' is
1187                                    // on; does not include win_col_off()
1188
1189  // six fields that are only used when there is a WinScrolled autocommand
1190  linenr_T w_last_topline;          ///< last known value for w_topline
1191  int w_last_topfill;               ///< last known value for w_topfill
1192  colnr_T w_last_leftcol;           ///< last known value for w_leftcol
1193  colnr_T w_last_skipcol;           ///< last known value for w_skipcol
1194  int w_last_width;                 ///< last known value for w_width
1195  int w_last_height;                ///< last known value for w_height
1196
1197  //
1198  // Layout of the window in the screen.
1199  // May need to add "msg_scrolled" to "w_winrow" in rare situations.
1200  //
1201  int w_winrow;                     // first row of window in screen
1202  int w_height;                     // number of rows in window, excluding
1203                                    // status/command line(s)
1204  int w_prev_winrow;                // previous winrow used for 'splitkeep'
1205  int w_prev_height;                // previous height used for 'splitkeep'
1206  int w_status_height;              // number of status lines (0 or 1)
1207  int w_winbar_height;              // number of window bars (0 or 1)
1208  int w_wincol;                     // Leftmost column of window in screen.
1209  int w_width;                      // Width of window, excluding separation.
1210  int w_hsep_height;                // Number of horizontal separator rows (0 or 1)
1211  int w_vsep_width;                 // Number of vertical separator columns (0 or 1).
1212  pos_save_T w_save_cursor;         // backup of cursor pos and topline
1213  bool w_do_win_fix_cursor;         // if true cursor may be invalid
1214
1215  // Screen pos 'previewpopup' anchors to (original cursor pos). Separate from WinConfig because
1216  // win_float_update_preview() re-autosizes as content updates, and re-decides the flip
1217  // above/below. WinConfig.row/col hold the placed (offset, flipped, clamped) result.
1218  int w_wantline;
1219  int w_wantcol;
1220
1221  int w_winrow_off;  ///< offset from winrow to the inner window area
1222  int w_wincol_off;  ///< offset from wincol to the inner window area
1223                     ///< this includes float border but excludes special columns
1224                     ///< implemented in win_line() (i.e. signs, folds, numbers)
1225
1226  // Size of the window viewport. This is the area usable to draw columns and buffer contents
1227  int w_view_height;
1228  int w_view_width;
1229  // external UI request. If non-zero, the inner size will use this.
1230  int w_height_request;
1231  int w_width_request;
1232
1233  int w_border_adj[4];  // top, right, bottom, left
1234  // outer size of window grid, including border
1235  int w_height_outer;
1236  int w_width_outer;
1237
1238  // === start of cached values ====
1239
1240  // Recomputing is minimized by storing the result of computations.
1241  // Use functions in screen.c to check if they are valid and to update.
1242  // w_valid is a bitfield of flags, which indicate if specific values are
1243  // valid or need to be recomputed.
1244  int w_valid;
1245  pos_T w_valid_cursor;             // last known position of w_cursor, used to adjust w_valid
1246  colnr_T w_valid_leftcol;          // last known w_leftcol
1247  colnr_T w_valid_skipcol;          // last known w_skipcol
1248
1249  bool w_viewport_invalid;
1250  linenr_T w_viewport_last_topline;  // topline when the viewport was last updated
1251  linenr_T w_viewport_last_botline;  // botline when the viewport was last updated
1252  linenr_T w_viewport_last_topfill;  // topfill when the viewport was last updated
1253  linenr_T w_viewport_last_skipcol;  // skipcol when the viewport was last updated
1254
1255  // w_cline_height is the number of physical lines taken by the buffer line
1256  // that the cursor is on.  We use this to avoid extra calls to plines_win().
1257  int w_cline_height;               // current size of cursor line
1258  bool w_cline_folded;              // cursor line is folded
1259
1260  int w_cline_row;                  // starting row of the cursor line
1261
1262  colnr_T w_virtcol;                // column number of the cursor in the
1263                                    // buffer line, as opposed to the column
1264                                    // number we're at on the screen.  This
1265                                    // makes a difference on lines which span
1266                                    // more than one screen line or when
1267                                    // w_leftcol is non-zero
1268
1269  // w_wrow and w_wcol specify the cursor position in the window.
1270  // This is related to positions in the window, not in the display or
1271  // buffer, thus w_wrow is relative to w_winrow.
1272  int w_wrow, w_wcol;               // cursor position in window
1273  int w_wcol_conceal_off;           // screen cells concealed before w_wcol on
1274                                    // the cursor's screen line, set by win_line()
1275
1276  linenr_T w_botline;               // number of the line below the bottom of
1277                                    // the window
1278  int w_empty_rows;                 // number of ~ rows in window
1279  int w_filler_rows;                // number of filler rows at the end of the
1280                                    // window
1281
1282  // Info about the lines currently in the window is remembered to avoid
1283  // recomputing it every time.  The allocated size of w_lines[] is Rows.
1284  // Only the w_lines_valid entries are actually valid.
1285  // When the display is up-to-date w_lines[0].wl_lnum is equal to w_topline
1286  // and w_lines[w_lines_valid - 1].wl_lnum is equal to w_botline.
1287  // Between changing text and updating the display w_lines[] represents
1288  // what is currently displayed.  wl_valid is reset to indicated this.
1289  // This is used for efficient redrawing.
1290  int w_lines_valid;                // number of valid entries
1291  wline_T *w_lines;
1292  int w_lines_size;
1293
1294  garray_T w_folds;                 // array of nested folds
1295  bool w_fold_manual;               // when true: some folds are opened/closed
1296                                    // manually
1297  bool w_foldinvalid;               // when true: folding needs to be
1298                                    // recomputed
1299  int w_nrwidth;                    // width of 'number' and 'relativenumber'
1300                                    // column being used
1301  int w_scwidth;                    // width of 'signcolumn'
1302  int w_minscwidth;                 // minimum 'signcolumn' width, or SCL_NO/SCL_NUM
1303  int w_maxscwidth;                 // maximum 'signcolumn' width, or SCL_NO/SCL_NUM
1304
1305  // === end of cached values ===
1306
1307  int w_redr_type;                  // type of redraw to be performed on win
1308  int w_upd_rows;                   // number of window lines to update when
1309                                    // w_redr_type is UPD_REDRAW_TOP
1310  linenr_T w_redraw_top;            // when != 0: first line needing redraw
1311  linenr_T w_redraw_bot;            // when != 0: last line needing redraw
1312  bool w_redr_status;               // if true statusline/winbar must be redrawn
1313  bool w_redr_border;               // if true border must be redrawn
1314  bool w_redr_statuscol;            // if true 'statuscolumn' must be redrawn
1315  disptick_T w_display_tick;        // when window was last drawn.
1316
1317  // remember what is shown in the 'statusline'-format elements
1318  pos_T w_stl_cursor;                // cursor position when last redrawn
1319  colnr_T w_stl_virtcol;             // virtcol when last redrawn
1320  linenr_T w_stl_topline;            // topline when last redrawn
1321  linenr_T w_stl_line_count;         // line count when last redrawn
1322  int w_stl_topfill;                 // topfill when last redrawn
1323  char w_stl_empty;                  // true if elements show 0-1 (empty line)
1324  int w_stl_recording;               // reg_recording when last redrawn
1325  int w_stl_state;                   // get_real_state() when last redrawn
1326  int w_stl_visual_mode;             // Visual.mode when last redrawn
1327  pos_T w_stl_visual_pos;            // Visual.start when last redrawn
1328
1329  int w_alt_fnum;                   // alternate file (for # and CTRL-^)
1330
1331  alist_T *w_alist;             // pointer to arglist for this window
1332  int w_arg_idx;                    // current index in argument list (can be
1333                                    // out of range!)
1334  bool w_arg_idx_invalid;           // editing another file than w_arg_idx
1335
1336  char *w_localdir;            // absolute path of local directory or NULL
1337  char *w_prevdir;             // previous directory
1338  // Options local to a window.
1339  // They are local because they influence the layout of the window or
1340  // depend on the window layout.
1341  // There are two values: w_onebuf_opt is local to the buffer currently in
1342  // this window, w_allbuf_opt is for all buffers in this window.
1343  winopt_T w_onebuf_opt;
1344  winopt_T w_allbuf_opt;
1345  // transform a pointer to a "onebuf" option into a "allbuf" option
1346#define GLOBAL_WO(p)    ((char *)(p) + sizeof(winopt_T))
1347
1348  int *w_p_cc_cols;                 // array of columns to highlight or NULL
1349  uint8_t w_p_culopt_flags;         // flags for cursorline highlighting
1350
1351  int w_briopt_min;                 // minimum width for breakindent
1352  int w_briopt_shift;               // additional shift for breakindent
1353  bool w_briopt_sbr;                // sbr in 'briopt'
1354  int w_briopt_list;                // additional indent for lists
1355  int w_briopt_vcol;                // indent for specific column
1356
1357  int w_scbind_pos;
1358
1359  ScopeDictDictItem w_winvar;       ///< Variable for "w:" dict.
1360  dict_T *w_vars;                   ///< Dict with w: variables.
1361
1362  // The w_prev_pcmark field is used to check whether we really did jump to
1363  // a new line after setting the w_pcmark.  If not, then we revert to
1364  // using the previous w_pcmark.
1365  pos_T w_pcmark;               // previous context mark
1366  pos_T w_prev_pcmark;          // previous w_pcmark
1367
1368  // the jumplist contains old cursor positions
1369  xfmark_T w_jumplist[JUMPLISTSIZE];
1370  int w_jumplistlen;                    // number of active entries
1371  int w_jumplistidx;                    // current position
1372
1373  int w_changelistidx;                  // current position in b_changelist
1374
1375  matchitem_T *w_match_head;            // head of match list
1376  int w_next_match_id;                  // next match ID
1377
1378  // the tagstack grows from 0 upwards:
1379  // entry 0: older
1380  // entry 1: newer
1381  // entry 2: newest
1382  taggy_T w_tagstack[TAGSTACKSIZE];     // the tag stack
1383  int w_tagstackidx;                    // idx just below active entry
1384  int w_tagstacklen;                    // number of tags on stack
1385
1386  GridView w_grid;                      // area to draw on, excluding borders and winbar
1387  ScreenGrid w_grid_alloc;              // the grid specific to the window
1388  bool w_pos_changed;                   // true if window position changed
1389  bool w_floating;                      ///< whether the window is floating
1390  WinKind w_kind;                       ///< mutually-exclusive window role
1391  WinConfig w_config;
1392
1393  // w_fraction is the fractional row of the cursor within the window, from
1394  // 0 at the top row to FRACTION_MULT at the last row.
1395  // w_prev_fraction_row was the actual cursor row when w_fraction was last
1396  // calculated.
1397  int w_fraction;
1398  int w_prev_fraction_row;
1399
1400  linenr_T w_nrwidth_line_count;        // line count when ml_nrwidth_width was computed.
1401  linenr_T w_statuscol_line_count;      // line count when 'statuscolumn' width was computed.
1402  int w_nrwidth_width;                  // nr of chars to print line count.
1403
1404  qf_info_T *w_llist;                   // Location list for this window
1405  // Location list reference used in the location list window.
1406  // In a non-location list window, w_llist_ref is NULL.
1407  qf_info_T *w_llist_ref;
1408
1409  StlClickDefinition *w_status_click_defs;      // Status line click definitions
1410  size_t w_status_click_defs_size;              // Size of the w_status_click_defs array
1411  StlClickDefinition *w_winbar_click_defs;      // Window bar click definitions
1412  size_t w_winbar_click_defs_size;              // Size of the w_winbar_click_defs array
1413  // Map of statuscolumn click definitions, indexed by v:lnum and v:virtnum.
1414  Map(int, StcClicks) w_statuscol_click_defs[1];
1415};