1 | #ifndef NVIM_BUFFER_DEFS_H |
2 | #define NVIM_BUFFER_DEFS_H |
3 | |
4 | #include <stdbool.h> |
5 | #include <stdint.h> |
6 | // for FILE |
7 | #include <stdio.h> |
8 | |
9 | typedef struct file_buffer buf_T; // Forward declaration |
10 | |
11 | // Reference to a buffer that stores the value of buf_free_count. |
12 | // bufref_valid() only needs to check "buf" when the count differs. |
13 | typedef struct { |
14 | buf_T *br_buf; |
15 | int br_fnum; |
16 | int br_buf_free_count; |
17 | } bufref_T; |
18 | |
19 | // for garray_T |
20 | #include "nvim/garray.h" |
21 | // for ScreenGrid |
22 | #include "nvim/grid_defs.h" |
23 | // for HLF_COUNT |
24 | #include "nvim/highlight_defs.h" |
25 | // for pos_T, lpos_T and linenr_T |
26 | #include "nvim/pos.h" |
27 | // for the number window-local and buffer-local options |
28 | #include "nvim/option_defs.h" |
29 | // for jump list and tag stack sizes in a buffer and mark types |
30 | #include "nvim/mark_defs.h" |
31 | // for u_header_T; needs buf_T. |
32 | #include "nvim/undo_defs.h" |
33 | // for hashtab_T |
34 | #include "nvim/hashtab.h" |
35 | // for dict_T |
36 | #include "nvim/eval/typval.h" |
37 | // for proftime_T |
38 | #include "nvim/profile.h" |
39 | // for String |
40 | #include "nvim/api/private/defs.h" |
41 | // for Map(K, V) |
42 | #include "nvim/map.h" |
43 | // for kvec |
44 | #include "nvim/lib/kvec.h" |
45 | |
46 | #define GETFILE_SUCCESS(x) ((x) <= 0) |
47 | #define MODIFIABLE(buf) (buf->b_p_ma) |
48 | |
49 | /* |
50 | * Flags for w_valid. |
51 | * These are set when something in a window structure becomes invalid, except |
52 | * when the cursor is moved. Call check_cursor_moved() before testing one of |
53 | * the flags. |
54 | * These are reset when that thing has been updated and is valid again. |
55 | * |
56 | * Every function that invalidates one of these must call one of the |
57 | * invalidate_* functions. |
58 | * |
59 | * w_valid is supposed to be used only in screen.c. From other files, use the |
60 | * functions that set or reset the flags. |
61 | * |
62 | * VALID_BOTLINE VALID_BOTLINE_AP |
63 | * on on w_botline valid |
64 | * off on w_botline approximated |
65 | * off off w_botline not valid |
66 | * on off not possible |
67 | */ |
68 | #define VALID_WROW 0x01 /* w_wrow (window row) is valid */ |
69 | #define VALID_WCOL 0x02 /* w_wcol (window col) is valid */ |
70 | #define VALID_VIRTCOL 0x04 /* w_virtcol (file col) is valid */ |
71 | #define VALID_CHEIGHT 0x08 /* w_cline_height and w_cline_folded valid */ |
72 | #define VALID_CROW 0x10 /* w_cline_row is valid */ |
73 | #define VALID_BOTLINE 0x20 /* w_botine and w_empty_rows are valid */ |
74 | #define VALID_BOTLINE_AP 0x40 /* w_botine is approximated */ |
75 | #define VALID_TOPLINE 0x80 /* w_topline is valid (for cursor position) */ |
76 | |
77 | // flags for b_flags |
78 | #define BF_RECOVERED 0x01 // buffer has been recovered |
79 | #define BF_CHECK_RO 0x02 // need to check readonly when loading file |
80 | // into buffer (set by ":e", may be reset by |
81 | // ":buf") |
82 | #define BF_NEVERLOADED 0x04 // file has never been loaded into buffer, |
83 | // many variables still need to be set |
84 | #define BF_NOTEDITED 0x08 // Set when file name is changed after |
85 | // starting to edit, reset when file is |
86 | // written out. |
87 | #define BF_NEW 0x10 // file didn't exist when editing started |
88 | #define BF_NEW_W 0x20 // Warned for BF_NEW and file created |
89 | #define BF_READERR 0x40 // got errors while reading the file |
90 | #define BF_DUMMY 0x80 // dummy buffer, only used internally |
91 | #define BF_PRESERVED 0x100 // ":preserve" was used |
92 | |
93 | /* Mask to check for flags that prevent normal writing */ |
94 | #define BF_WRITE_MASK (BF_NOTEDITED + BF_NEW + BF_READERR) |
95 | |
96 | typedef struct window_S win_T; |
97 | typedef struct wininfo_S wininfo_T; |
98 | typedef struct frame_S frame_T; |
99 | typedef uint16_t disptick_T; // display tick type |
100 | |
101 | // for struct memline (it needs memfile_T) |
102 | #include "nvim/memline_defs.h" |
103 | // for struct memfile, bhdr_T, blocknr_T... (it needs buf_T) |
104 | #include "nvim/memfile_defs.h" |
105 | |
106 | // for regprog_T. Needs win_T and buf_T. |
107 | #include "nvim/regexp_defs.h" |
108 | // for synstate_T (needs reg_extmatch_T, win_T, buf_T) |
109 | #include "nvim/syntax_defs.h" |
110 | // for signlist_T |
111 | #include "nvim/sign_defs.h" |
112 | // for bufhl_*_T |
113 | #include "nvim/bufhl_defs.h" |
114 | |
115 | #include "nvim/os/fs_defs.h" // for FileID |
116 | #include "nvim/terminal.h" // for Terminal |
117 | |
118 | /* |
119 | * The taggy struct is used to store the information about a :tag command. |
120 | */ |
121 | typedef struct taggy { |
122 | char_u *tagname; /* tag name */ |
123 | fmark_T fmark; /* cursor position BEFORE ":tag" */ |
124 | int cur_match; /* match number */ |
125 | int cur_fnum; /* buffer number used for cur_match */ |
126 | } taggy_T; |
127 | |
128 | typedef struct buffblock buffblock_T; |
129 | typedef struct buffheader ; |
130 | |
131 | /* |
132 | * structure used to store one block of the stuff/redo/recording buffers |
133 | */ |
134 | struct buffblock { |
135 | buffblock_T *b_next; // pointer to next buffblock |
136 | char_u b_str[1]; // contents (actually longer) |
137 | }; |
138 | |
139 | /* |
140 | * header used for the stuff buffer and the redo buffer |
141 | */ |
142 | struct { |
143 | buffblock_T ; // first (dummy) block of list |
144 | buffblock_T *; // buffblock for appending |
145 | size_t ; // index for reading |
146 | size_t ; // space in bh_curr for appending |
147 | }; |
148 | |
149 | typedef struct |
150 | { |
151 | buffheader_T sr_redobuff; |
152 | buffheader_T sr_old_redobuff; |
153 | } save_redo_T; |
154 | |
155 | /* |
156 | * Structure that contains all options that are local to a window. |
157 | * Used twice in a window: for the current buffer and for all buffers. |
158 | * Also used in wininfo_T. |
159 | */ |
160 | typedef struct { |
161 | int wo_arab; |
162 | # define w_p_arab w_onebuf_opt.wo_arab /* 'arabic' */ |
163 | int wo_bri; |
164 | # define w_p_bri w_onebuf_opt.wo_bri // 'breakindent' |
165 | char_u *wo_briopt; |
166 | # define w_p_briopt w_onebuf_opt.wo_briopt /* 'breakindentopt' */ |
167 | int wo_diff; |
168 | # define w_p_diff w_onebuf_opt.wo_diff /* 'diff' */ |
169 | long wo_fdc; |
170 | # define w_p_fdc w_onebuf_opt.wo_fdc /* 'foldcolumn' */ |
171 | int wo_fdc_save; |
172 | # define w_p_fdc_save w_onebuf_opt.wo_fdc_save /* 'foldenable' saved for diff mode */ |
173 | int wo_fen; |
174 | # define w_p_fen w_onebuf_opt.wo_fen /* 'foldenable' */ |
175 | int wo_fen_save; |
176 | # define w_p_fen_save w_onebuf_opt.wo_fen_save /* 'foldenable' saved for diff mode */ |
177 | char_u *wo_fdi; |
178 | # define w_p_fdi w_onebuf_opt.wo_fdi /* 'foldignore' */ |
179 | long wo_fdl; |
180 | # define w_p_fdl w_onebuf_opt.wo_fdl /* 'foldlevel' */ |
181 | int wo_fdl_save; |
182 | # define w_p_fdl_save w_onebuf_opt.wo_fdl_save /* 'foldlevel' state saved for diff mode */ |
183 | char_u *wo_fdm; |
184 | # define w_p_fdm w_onebuf_opt.wo_fdm /* 'foldmethod' */ |
185 | char_u *wo_fdm_save; |
186 | # define w_p_fdm_save w_onebuf_opt.wo_fdm_save /* 'fdm' saved for diff mode */ |
187 | long wo_fml; |
188 | # define w_p_fml w_onebuf_opt.wo_fml /* 'foldminlines' */ |
189 | long wo_fdn; |
190 | # define w_p_fdn w_onebuf_opt.wo_fdn /* 'foldnestmax' */ |
191 | char_u *wo_fde; |
192 | # define w_p_fde w_onebuf_opt.wo_fde /* 'foldexpr' */ |
193 | char_u *wo_fdt; |
194 | # define w_p_fdt w_onebuf_opt.wo_fdt /* 'foldtext' */ |
195 | char_u *wo_fmr; |
196 | # define w_p_fmr w_onebuf_opt.wo_fmr /* 'foldmarker' */ |
197 | int wo_lbr; |
198 | # define w_p_lbr w_onebuf_opt.wo_lbr /* 'linebreak' */ |
199 | int wo_list; |
200 | #define w_p_list w_onebuf_opt.wo_list /* 'list' */ |
201 | int wo_nu; |
202 | #define w_p_nu w_onebuf_opt.wo_nu /* 'number' */ |
203 | int wo_rnu; |
204 | #define w_p_rnu w_onebuf_opt.wo_rnu /* 'relativenumber' */ |
205 | long wo_nuw; |
206 | # define w_p_nuw w_onebuf_opt.wo_nuw /* 'numberwidth' */ |
207 | int wo_wfh; |
208 | # define w_p_wfh w_onebuf_opt.wo_wfh /* 'winfixheight' */ |
209 | int wo_wfw; |
210 | # define w_p_wfw w_onebuf_opt.wo_wfw /* 'winfixwidth' */ |
211 | int wo_pvw; |
212 | # define w_p_pvw w_onebuf_opt.wo_pvw /* 'previewwindow' */ |
213 | int wo_rl; |
214 | # define w_p_rl w_onebuf_opt.wo_rl /* 'rightleft' */ |
215 | char_u *wo_rlc; |
216 | # define w_p_rlc w_onebuf_opt.wo_rlc /* 'rightleftcmd' */ |
217 | long wo_scr; |
218 | #define w_p_scr w_onebuf_opt.wo_scr /* 'scroll' */ |
219 | int wo_spell; |
220 | # define w_p_spell w_onebuf_opt.wo_spell /* 'spell' */ |
221 | int wo_cuc; |
222 | # define w_p_cuc w_onebuf_opt.wo_cuc /* 'cursorcolumn' */ |
223 | int wo_cul; |
224 | # define w_p_cul w_onebuf_opt.wo_cul /* 'cursorline' */ |
225 | char_u *wo_cc; |
226 | # define w_p_cc w_onebuf_opt.wo_cc /* 'colorcolumn' */ |
227 | char_u *wo_stl; |
228 | #define w_p_stl w_onebuf_opt.wo_stl /* 'statusline' */ |
229 | int wo_scb; |
230 | # define w_p_scb w_onebuf_opt.wo_scb /* 'scrollbind' */ |
231 | int wo_diff_saved; /* options were saved for starting diff mode */ |
232 | # define w_p_diff_saved w_onebuf_opt.wo_diff_saved |
233 | int wo_scb_save; /* 'scrollbind' saved for diff mode*/ |
234 | # define w_p_scb_save w_onebuf_opt.wo_scb_save |
235 | int wo_wrap; |
236 | #define w_p_wrap w_onebuf_opt.wo_wrap /* 'wrap' */ |
237 | int wo_wrap_save; /* 'wrap' state saved for diff mode*/ |
238 | # define w_p_wrap_save w_onebuf_opt.wo_wrap_save |
239 | char_u *wo_cocu; /* 'concealcursor' */ |
240 | # define w_p_cocu w_onebuf_opt.wo_cocu |
241 | long wo_cole; /* 'conceallevel' */ |
242 | # define w_p_cole w_onebuf_opt.wo_cole |
243 | int wo_crb; |
244 | # define w_p_crb w_onebuf_opt.wo_crb /* 'cursorbind' */ |
245 | int wo_crb_save; /* 'cursorbind' state saved for diff mode*/ |
246 | # define w_p_crb_save w_onebuf_opt.wo_crb_save |
247 | char_u *wo_scl; |
248 | # define w_p_scl w_onebuf_opt.wo_scl // 'signcolumn' |
249 | char_u *wo_winhl; |
250 | # define w_p_winhl w_onebuf_opt.wo_winhl // 'winhighlight' |
251 | char_u *wo_fcs; |
252 | # define w_p_fcs w_onebuf_opt.wo_fcs // 'fillchars' |
253 | char_u *wo_lcs; |
254 | # define w_p_lcs w_onebuf_opt.wo_lcs // 'listchars' |
255 | long wo_winbl; |
256 | # define w_p_winbl w_onebuf_opt.wo_winbl // 'winblend' |
257 | |
258 | LastSet wo_script_ctx[WV_COUNT]; // SCTXs for window-local options |
259 | # define w_p_script_ctx w_onebuf_opt.wo_script_ctx |
260 | } winopt_T; |
261 | |
262 | /* |
263 | * Window info stored with a buffer. |
264 | * |
265 | * Two types of info are kept for a buffer which are associated with a |
266 | * specific window: |
267 | * 1. Each window can have a different line number associated with a buffer. |
268 | * 2. The window-local options for a buffer work in a similar way. |
269 | * The window-info is kept in a list at b_wininfo. It is kept in |
270 | * most-recently-used order. |
271 | */ |
272 | struct wininfo_S { |
273 | wininfo_T *wi_next; /* next entry or NULL for last entry */ |
274 | wininfo_T *wi_prev; /* previous entry or NULL for first entry */ |
275 | win_T *wi_win; /* pointer to window that did set wi_fpos */ |
276 | pos_T wi_fpos; /* last cursor position in the file */ |
277 | bool wi_optset; /* true when wi_opt has useful values */ |
278 | winopt_T wi_opt; /* local window options */ |
279 | bool wi_fold_manual; /* copy of w_fold_manual */ |
280 | garray_T wi_folds; /* clone of w_folds */ |
281 | }; |
282 | |
283 | /* |
284 | * Argument list: Array of file names. |
285 | * Used for the global argument list and the argument lists local to a window. |
286 | * |
287 | * TODO: move struct arglist to another header |
288 | */ |
289 | typedef struct arglist { |
290 | garray_T al_ga; /* growarray with the array of file names */ |
291 | int al_refcount; /* number of windows using this arglist */ |
292 | int id; ///< id of this arglist |
293 | } alist_T; |
294 | |
295 | /* |
296 | * For each argument remember the file name as it was given, and the buffer |
297 | * number that contains the expanded file name (required for when ":cd" is |
298 | * used. |
299 | * |
300 | * TODO: move aentry_T to another header |
301 | */ |
302 | typedef struct argentry { |
303 | char_u *ae_fname; /* file name as specified */ |
304 | int ae_fnum; /* buffer number with expanded file name */ |
305 | } aentry_T; |
306 | |
307 | # define ALIST(win) (win)->w_alist |
308 | #define GARGLIST ((aentry_T *)global_alist.al_ga.ga_data) |
309 | #define ARGLIST ((aentry_T *)ALIST(curwin)->al_ga.ga_data) |
310 | #define WARGLIST(wp) ((aentry_T *)ALIST(wp)->al_ga.ga_data) |
311 | #define AARGLIST(al) ((aentry_T *)((al)->al_ga.ga_data)) |
312 | #define GARGCOUNT (global_alist.al_ga.ga_len) |
313 | #define ARGCOUNT (ALIST(curwin)->al_ga.ga_len) |
314 | #define WARGCOUNT(wp) (ALIST(wp)->al_ga.ga_len) |
315 | |
316 | /* |
317 | * Used for the typeahead buffer: typebuf. |
318 | */ |
319 | typedef struct { |
320 | char_u *tb_buf; /* buffer for typed characters */ |
321 | char_u *tb_noremap; /* mapping flags for characters in tb_buf[] */ |
322 | int tb_buflen; /* size of tb_buf[] */ |
323 | int tb_off; /* current position in tb_buf[] */ |
324 | int tb_len; /* number of valid bytes in tb_buf[] */ |
325 | int tb_maplen; /* nr of mapped bytes in tb_buf[] */ |
326 | int tb_silent; /* nr of silently mapped bytes in tb_buf[] */ |
327 | int tb_no_abbr_cnt; /* nr of bytes without abbrev. in tb_buf[] */ |
328 | int tb_change_cnt; /* nr of time tb_buf was changed; never zero */ |
329 | } typebuf_T; |
330 | |
331 | /* Struct to hold the saved typeahead for save_typeahead(). */ |
332 | typedef struct { |
333 | typebuf_T save_typebuf; |
334 | int typebuf_valid; /* TRUE when save_typebuf valid */ |
335 | int old_char; |
336 | int old_mod_mask; |
337 | buffheader_T save_readbuf1; |
338 | buffheader_T save_readbuf2; |
339 | String save_inputbuf; |
340 | } tasave_T; |
341 | |
342 | /* |
343 | * Structure used for mappings and abbreviations. |
344 | */ |
345 | typedef struct mapblock mapblock_T; |
346 | struct mapblock { |
347 | mapblock_T *m_next; // next mapblock in list |
348 | char_u *m_keys; // mapped from, lhs |
349 | char_u *m_str; // mapped to, rhs |
350 | char_u *m_orig_str; // rhs as entered by the user |
351 | int m_keylen; // strlen(m_keys) |
352 | int m_mode; // valid mode |
353 | int m_noremap; // if non-zero no re-mapping for m_str |
354 | char m_silent; // <silent> used, don't echo commands |
355 | char m_nowait; // <nowait> used |
356 | char m_expr; // <expr> used, m_str is an expression |
357 | sctx_T m_script_ctx; // SCTX where map was defined |
358 | }; |
359 | |
360 | /* |
361 | * Used for highlighting in the status line. |
362 | */ |
363 | struct stl_hlrec { |
364 | char_u *start; |
365 | int userhl; /* 0: no HL, 1-9: User HL, < 0 for syn ID */ |
366 | }; |
367 | |
368 | /* values for b_syn_spell: what to do with toplevel text */ |
369 | #define SYNSPL_DEFAULT 0 /* spell check if @Spell not defined */ |
370 | #define SYNSPL_TOP 1 /* spell check toplevel text */ |
371 | #define SYNSPL_NOTOP 2 /* don't spell check toplevel text */ |
372 | |
373 | /* avoid #ifdefs for when b_spell is not available */ |
374 | # define B_SPELL(buf) ((buf)->b_spell) |
375 | |
376 | typedef struct qf_info_S qf_info_T; |
377 | |
378 | /* |
379 | * Used for :syntime: timing of executing a syntax pattern. |
380 | */ |
381 | typedef struct { |
382 | proftime_T total; /* total time used */ |
383 | proftime_T slowest; /* time of slowest call */ |
384 | long count; /* nr of times used */ |
385 | long match; /* nr of times matched */ |
386 | } syn_time_T; |
387 | |
388 | /* |
389 | * These are items normally related to a buffer. But when using ":ownsyntax" |
390 | * a window may have its own instance. |
391 | */ |
392 | typedef struct { |
393 | hashtab_T b_keywtab; // syntax keywords hash table |
394 | hashtab_T b_keywtab_ic; // idem, ignore case |
395 | int b_syn_error; // TRUE when error occurred in HL |
396 | bool b_syn_slow; // true when 'redrawtime' reached |
397 | int b_syn_ic; // ignore case for :syn cmds |
398 | int b_syn_spell; // SYNSPL_ values |
399 | garray_T b_syn_patterns; // table for syntax patterns |
400 | garray_T b_syn_clusters; // table for syntax clusters |
401 | int b_spell_cluster_id; // @Spell cluster ID or 0 |
402 | int b_nospell_cluster_id; // @NoSpell cluster ID or 0 |
403 | int b_syn_containedin; // TRUE when there is an item with a |
404 | // "containedin" argument |
405 | int b_syn_sync_flags; // flags about how to sync |
406 | int16_t b_syn_sync_id; // group to sync on |
407 | long b_syn_sync_minlines; // minimal sync lines offset |
408 | long b_syn_sync_maxlines; // maximal sync lines offset |
409 | long b_syn_sync_linebreaks; // offset for multi-line pattern |
410 | char_u *b_syn_linecont_pat; // line continuation pattern |
411 | regprog_T *b_syn_linecont_prog; // line continuation program |
412 | syn_time_T b_syn_linecont_time; |
413 | int b_syn_linecont_ic; /* ignore-case flag for above */ |
414 | int b_syn_topgrp; /* for ":syntax include" */ |
415 | int b_syn_conceal; /* auto-conceal for :syn cmds */ |
416 | int b_syn_folditems; /* number of patterns with the HL_FOLD |
417 | flag set */ |
418 | /* |
419 | * b_sst_array[] contains the state stack for a number of lines, for the |
420 | * start of that line (col == 0). This avoids having to recompute the |
421 | * syntax state too often. |
422 | * b_sst_array[] is allocated to hold the state for all displayed lines, |
423 | * and states for 1 out of about 20 other lines. |
424 | * b_sst_array pointer to an array of synstate_T |
425 | * b_sst_len number of entries in b_sst_array[] |
426 | * b_sst_first pointer to first used entry in b_sst_array[] or NULL |
427 | * b_sst_firstfree pointer to first free entry in b_sst_array[] or NULL |
428 | * b_sst_freecount number of free entries in b_sst_array[] |
429 | * b_sst_check_lnum entries after this lnum need to be checked for |
430 | * validity (MAXLNUM means no check needed) |
431 | */ |
432 | synstate_T *b_sst_array; |
433 | int b_sst_len; |
434 | synstate_T *b_sst_first; |
435 | synstate_T *b_sst_firstfree; |
436 | int b_sst_freecount; |
437 | linenr_T b_sst_check_lnum; |
438 | disptick_T b_sst_lasttick; // last display tick |
439 | |
440 | // for spell checking |
441 | garray_T b_langp; // list of pointers to slang_T, see spell.c |
442 | bool b_spell_ismw[256]; // flags: is midword char |
443 | char_u *b_spell_ismw_mb; // multi-byte midword chars |
444 | char_u *b_p_spc; // 'spellcapcheck' |
445 | regprog_T *b_cap_prog; // program for 'spellcapcheck' |
446 | char_u *b_p_spf; // 'spellfile' |
447 | char_u *b_p_spl; // 'spelllang' |
448 | int b_cjk; // all CJK letters as OK |
449 | char_u b_syn_chartab[32]; // syntax iskeyword option |
450 | char_u *b_syn_isk; // iskeyword option |
451 | } synblock_T; |
452 | |
453 | /// Type used for changedtick_di member in buf_T |
454 | /// |
455 | /// Primary exists so that literals of relevant type can be made. |
456 | typedef TV_DICTITEM_STRUCT(sizeof("changedtick" )) ChangedtickDictItem; |
457 | |
458 | typedef struct { |
459 | LuaRef on_lines; |
460 | LuaRef on_changedtick; |
461 | LuaRef on_detach; |
462 | bool utf_sizes; |
463 | } BufUpdateCallbacks; |
464 | #define BUF_UPDATE_CALLBACKS_INIT { LUA_NOREF, LUA_NOREF, LUA_NOREF, false } |
465 | |
466 | #define BUF_HAS_QF_ENTRY 1 |
467 | #define BUF_HAS_LL_ENTRY 2 |
468 | |
469 | // Maximum number of maphash blocks we will have |
470 | #define MAX_MAPHASH 256 |
471 | |
472 | /* |
473 | * buffer: structure that holds information about one file |
474 | * |
475 | * Several windows can share a single Buffer |
476 | * A buffer is unallocated if there is no memfile for it. |
477 | * A buffer is new if the associated file has never been loaded yet. |
478 | */ |
479 | |
480 | struct file_buffer { |
481 | handle_T handle; // unique id for the buffer (buffer number) |
482 | #define b_fnum handle |
483 | |
484 | memline_T b_ml; // associated memline (also contains line count |
485 | |
486 | buf_T *b_next; /* links in list of buffers */ |
487 | buf_T *b_prev; |
488 | |
489 | int b_nwindows; /* nr of windows open on this buffer */ |
490 | |
491 | int b_flags; // various BF_ flags |
492 | int b_locked; // Buffer is being closed or referenced, don't |
493 | // let autocommands wipe it out. |
494 | |
495 | // |
496 | // b_ffname has the full path of the file (NULL for no name). |
497 | // b_sfname is the name as the user typed it (or NULL). |
498 | // b_fname is the same as b_sfname, unless ":cd" has been done, |
499 | // then it is the same as b_ffname (NULL for no name). |
500 | // |
501 | char_u *b_ffname; // full path file name |
502 | char_u *b_sfname; // short file name |
503 | char_u *b_fname; // current file name |
504 | |
505 | bool file_id_valid; |
506 | FileID file_id; |
507 | |
508 | int b_changed; // 'modified': Set to true if something in the |
509 | // file has been changed and not written out. |
510 | |
511 | /// Change-identifier incremented for each change, including undo. |
512 | /// |
513 | /// This is a dictionary item used to store b:changedtick. |
514 | ChangedtickDictItem changedtick_di; |
515 | |
516 | varnumber_T b_last_changedtick; // b:changedtick when TextChanged or |
517 | // TextChangedI was last triggered. |
518 | varnumber_T b_last_changedtick_pum; // b:changedtick when TextChangedP was |
519 | // last triggered. |
520 | |
521 | bool b_saving; /* Set to true if we are in the middle of |
522 | saving the buffer. */ |
523 | |
524 | /* |
525 | * Changes to a buffer require updating of the display. To minimize the |
526 | * work, remember changes made and update everything at once. |
527 | */ |
528 | bool b_mod_set; /* true when there are changes since the last |
529 | time the display was updated */ |
530 | linenr_T b_mod_top; /* topmost lnum that was changed */ |
531 | linenr_T b_mod_bot; /* lnum below last changed line, AFTER the |
532 | change */ |
533 | long b_mod_xlines; /* number of extra buffer lines inserted; |
534 | negative when lines were deleted */ |
535 | |
536 | wininfo_T *b_wininfo; /* list of last used info for each window */ |
537 | |
538 | long b_mtime; /* last change time of original file */ |
539 | long b_mtime_read; /* last change time when reading */ |
540 | uint64_t b_orig_size; /* size of original file in bytes */ |
541 | int b_orig_mode; /* mode of original file */ |
542 | |
543 | fmark_T b_namedm[NMARKS]; /* current named marks (mark.c) */ |
544 | |
545 | /* These variables are set when VIsual_active becomes FALSE */ |
546 | visualinfo_T b_visual; |
547 | int b_visual_mode_eval; /* b_visual.vi_mode for visualmode() */ |
548 | |
549 | fmark_T b_last_cursor; // cursor position when last unloading this |
550 | // buffer |
551 | fmark_T b_last_insert; // where Insert mode was left |
552 | fmark_T b_last_change; // position of last change: '. mark |
553 | |
554 | /* |
555 | * the changelist contains old change positions |
556 | */ |
557 | fmark_T b_changelist[JUMPLISTSIZE]; |
558 | int b_changelistlen; /* number of active entries */ |
559 | bool b_new_change; /* set by u_savecommon() */ |
560 | |
561 | /* |
562 | * Character table, only used in charset.c for 'iskeyword' |
563 | * bitset with 4*64=256 bits: 1 bit per character 0-255. |
564 | */ |
565 | uint64_t b_chartab[4]; |
566 | |
567 | // Table used for mappings local to a buffer. |
568 | mapblock_T *(b_maphash[MAX_MAPHASH]); |
569 | |
570 | /* First abbreviation local to a buffer. */ |
571 | mapblock_T *b_first_abbr; |
572 | /* User commands local to the buffer. */ |
573 | garray_T b_ucmds; |
574 | /* |
575 | * start and end of an operator, also used for '[ and '] |
576 | */ |
577 | pos_T b_op_start; |
578 | pos_T b_op_start_orig; // used for Insstart_orig |
579 | pos_T b_op_end; |
580 | |
581 | bool b_marks_read; /* Have we read ShaDa marks yet? */ |
582 | |
583 | /* |
584 | * The following only used in undo.c. |
585 | */ |
586 | u_header_T *b_u_oldhead; /* pointer to oldest header */ |
587 | u_header_T *b_u_newhead; /* pointer to newest header; may not be valid |
588 | if b_u_curhead is not NULL */ |
589 | u_header_T *b_u_curhead; /* pointer to current header */ |
590 | int b_u_numhead; /* current number of headers */ |
591 | bool b_u_synced; /* entry lists are synced */ |
592 | long b_u_seq_last; /* last used undo sequence number */ |
593 | long b_u_save_nr_last; /* counter for last file write */ |
594 | long b_u_seq_cur; /* hu_seq of header below which we are now */ |
595 | time_t b_u_time_cur; /* uh_time of header below which we are now */ |
596 | long b_u_save_nr_cur; /* file write nr after which we are now */ |
597 | |
598 | /* |
599 | * variables for "U" command in undo.c |
600 | */ |
601 | char_u *b_u_line_ptr; /* saved line for "U" command */ |
602 | linenr_T b_u_line_lnum; /* line number of line in u_line */ |
603 | colnr_T b_u_line_colnr; /* optional column number */ |
604 | |
605 | bool b_scanned; /* ^N/^P have scanned this buffer */ |
606 | |
607 | // flags for use of ":lmap" and IM control |
608 | long b_p_iminsert; // input mode for insert |
609 | long b_p_imsearch; // input mode for search |
610 | #define B_IMODE_USE_INSERT -1 // Use b_p_iminsert value for search |
611 | #define B_IMODE_NONE 0 // Input via none |
612 | #define B_IMODE_LMAP 1 // Input via langmap |
613 | # define B_IMODE_LAST 1 |
614 | |
615 | short b_kmap_state; /* using "lmap" mappings */ |
616 | # define KEYMAP_INIT 1 /* 'keymap' was set, call keymap_init() */ |
617 | # define KEYMAP_LOADED 2 /* 'keymap' mappings have been loaded */ |
618 | garray_T b_kmap_ga; /* the keymap table */ |
619 | |
620 | /* |
621 | * Options local to a buffer. |
622 | * They are here because their value depends on the type of file |
623 | * or contents of the file being edited. |
624 | */ |
625 | bool b_p_initialized; // set when options initialized |
626 | |
627 | LastSet b_p_script_ctx[BV_COUNT]; // SCTXs for buffer-local options |
628 | |
629 | int b_p_ai; ///< 'autoindent' |
630 | int b_p_ai_nopaste; ///< b_p_ai saved for paste mode |
631 | char_u *b_p_bkc; ///< 'backupco |
632 | unsigned int b_bkc_flags; ///< flags for 'backupco |
633 | int b_p_ci; ///< 'copyindent' |
634 | int b_p_bin; ///< 'binary' |
635 | int b_p_bomb; ///< 'bomb' |
636 | char_u *b_p_bh; ///< 'bufhidden' |
637 | char_u *b_p_bt; ///< 'buftype' |
638 | int b_has_qf_entry; ///< quickfix exists for buffer |
639 | int b_p_bl; ///< 'buflisted' |
640 | long b_p_channel; ///< 'channel' |
641 | int b_p_cin; ///< 'cindent' |
642 | char_u *b_p_cino; ///< 'cinoptions' |
643 | char_u *b_p_cink; ///< 'cinkeys' |
644 | char_u *b_p_cinw; ///< 'cinwords' |
645 | char_u *b_p_com; ///< 'comments' |
646 | char_u *b_p_cms; ///< 'commentstring' |
647 | char_u *b_p_cpt; ///< 'complete' |
648 | char_u *b_p_cfu; ///< 'completefunc' |
649 | char_u *b_p_ofu; ///< 'omnifunc' |
650 | int b_p_eol; ///< 'endofline' |
651 | int b_p_fixeol; ///< 'fixendofline' |
652 | int b_p_et; ///< 'expandtab' |
653 | int b_p_et_nobin; ///< b_p_et saved for binary mode |
654 | int b_p_et_nopaste; ///< b_p_et saved for paste mode |
655 | char_u *b_p_fenc; ///< 'fileencoding' |
656 | char_u *b_p_ff; ///< 'fileformat' |
657 | char_u *b_p_ft; ///< 'filetype' |
658 | char_u *b_p_fo; ///< 'formatoptions' |
659 | char_u *b_p_flp; ///< 'formatlistpat' |
660 | int b_p_inf; ///< 'infercase' |
661 | char_u *b_p_isk; ///< 'iskeyword' |
662 | char_u *b_p_def; ///< 'define' local value |
663 | char_u *b_p_inc; ///< 'include' |
664 | char_u *b_p_inex; ///< 'includeexpr' |
665 | uint32_t b_p_inex_flags; ///< flags for 'includeexpr' |
666 | char_u *b_p_inde; ///< 'indentexpr' |
667 | uint32_t b_p_inde_flags; ///< flags for 'indentexpr' |
668 | char_u *b_p_indk; ///< 'indentkeys' |
669 | char_u *b_p_fp; ///< 'formatprg' |
670 | char_u *b_p_fex; ///< 'formatexpr' |
671 | uint32_t b_p_fex_flags; ///< flags for 'formatexpr' |
672 | char_u *b_p_kp; ///< 'keywordprg' |
673 | int b_p_lisp; ///< 'lisp' |
674 | char_u *b_p_menc; ///< 'makeencoding' |
675 | char_u *b_p_mps; ///< 'matchpairs' |
676 | int b_p_ml; ///< 'modeline' |
677 | int b_p_ml_nobin; ///< b_p_ml saved for binary mode |
678 | int b_p_ma; ///< 'modifiable' |
679 | char_u *b_p_nf; ///< 'nrformats' |
680 | int b_p_pi; ///< 'preserveindent' |
681 | char_u *b_p_qe; ///< 'quoteescape' |
682 | int b_p_ro; ///< 'readonly' |
683 | long b_p_sw; ///< 'shiftwidth' |
684 | long b_p_scbk; ///< 'scrollback' |
685 | int b_p_si; ///< 'smartindent' |
686 | long b_p_sts; ///< 'softtabstop' |
687 | long b_p_sts_nopaste; ///< b_p_sts saved for paste mode |
688 | char_u *b_p_sua; ///< 'suffixesadd' |
689 | int b_p_swf; ///< 'swapfile' |
690 | long b_p_smc; ///< 'synmaxcol' |
691 | char_u *b_p_syn; ///< 'syntax' |
692 | long b_p_ts; ///< 'tabstop' |
693 | long b_p_tw; ///< 'textwidth' |
694 | long b_p_tw_nobin; ///< b_p_tw saved for binary mode |
695 | long b_p_tw_nopaste; ///< b_p_tw saved for paste mode |
696 | long b_p_wm; ///< 'wrapmargin' |
697 | long b_p_wm_nobin; ///< b_p_wm saved for binary mode |
698 | long b_p_wm_nopaste; ///< b_p_wm saved for paste mode |
699 | char_u *b_p_keymap; ///< 'keymap' |
700 | |
701 | // local values for options which are normally global |
702 | char_u *b_p_gp; ///< 'grepprg' local value |
703 | char_u *b_p_mp; ///< 'makeprg' local value |
704 | char_u *b_p_efm; ///< 'errorformat' local value |
705 | char_u *b_p_ep; ///< 'equalprg' local value |
706 | char_u *b_p_path; ///< 'path' local value |
707 | int b_p_ar; ///< 'autoread' local value |
708 | char_u *b_p_tags; ///< 'tags' local value |
709 | char_u *b_p_tc; ///< 'tagcase' local value |
710 | unsigned b_tc_flags; ///< flags for 'tagcase' |
711 | char_u *b_p_dict; ///< 'dictionary' local value |
712 | char_u *b_p_tsr; ///< 'thesaurus' local value |
713 | long b_p_ul; ///< 'undolevels' local value |
714 | int b_p_udf; ///< 'undofile' |
715 | char_u *b_p_lw; ///< 'lispwords' local value |
716 | |
717 | /* end of buffer options */ |
718 | |
719 | /* values set from b_p_cino */ |
720 | int b_ind_level; |
721 | int b_ind_open_imag; |
722 | int b_ind_no_brace; |
723 | int b_ind_first_open; |
724 | int ; |
725 | int ; |
726 | int b_ind_open_left_imag; |
727 | int b_ind_jump_label; |
728 | int b_ind_case; |
729 | int b_ind_case_code; |
730 | int b_ind_case_break; |
731 | int b_ind_param; |
732 | int b_ind_func_type; |
733 | int ; |
734 | int ; |
735 | int ; |
736 | int b_ind_cpp_baseclass; |
737 | int b_ind_continuation; |
738 | int b_ind_unclosed; |
739 | int b_ind_unclosed2; |
740 | int b_ind_unclosed_noignore; |
741 | int b_ind_unclosed_wrapped; |
742 | int b_ind_unclosed_whiteok; |
743 | int b_ind_matching_paren; |
744 | int b_ind_paren_prev; |
745 | int b_ind_maxparen; |
746 | int ; |
747 | int b_ind_scopedecl; |
748 | int b_ind_scopedecl_code; |
749 | int b_ind_java; |
750 | int b_ind_js; |
751 | int b_ind_keep_case_label; |
752 | int ; |
753 | int b_ind_cpp_namespace; |
754 | int b_ind_if_for_while; |
755 | int b_ind_cpp_extern_c; |
756 | |
757 | linenr_T b_no_eol_lnum; /* non-zero lnum when last line of next binary |
758 | * write should not have an end-of-line */ |
759 | |
760 | int b_start_eol; /* last line had eol when it was read */ |
761 | int b_start_ffc; /* first char of 'ff' when edit started */ |
762 | char_u *b_start_fenc; /* 'fileencoding' when edit started or NULL */ |
763 | int b_bad_char; /* "++bad=" argument when edit started or 0 */ |
764 | int b_start_bomb; /* 'bomb' when it was read */ |
765 | |
766 | ScopeDictDictItem b_bufvar; ///< Variable for "b:" Dictionary. |
767 | dict_T *b_vars; ///< b: scope dictionary. |
768 | |
769 | /* When a buffer is created, it starts without a swap file. b_may_swap is |
770 | * then set to indicate that a swap file may be opened later. It is reset |
771 | * if a swap file could not be opened. |
772 | */ |
773 | bool b_may_swap; |
774 | bool b_did_warn; /* Set to true if user has been warned on first |
775 | change of a read-only file */ |
776 | |
777 | /* Two special kinds of buffers: |
778 | * help buffer - used for help files, won't use a swap file. |
779 | * spell buffer - used for spell info, never displayed and doesn't have a |
780 | * file name. |
781 | */ |
782 | bool b_help; // TRUE for help file buffer (when set b_p_bt |
783 | // is "help") |
784 | bool b_spell; // True for a spell file buffer, most fields |
785 | // are not used! Use the B_SPELL macro to |
786 | // access b_spell without #ifdef. |
787 | |
788 | synblock_T b_s; // Info related to syntax highlighting. w_s |
789 | // normally points to this, but some windows |
790 | // may use a different synblock_T. |
791 | |
792 | signlist_T *b_signlist; // list of signs to draw |
793 | int b_signcols_max; // cached maximum number of sign columns |
794 | int b_signcols; // last calculated number of sign columns |
795 | |
796 | Terminal *terminal; // Terminal instance associated with the buffer |
797 | |
798 | dict_T *additional_data; // Additional data from shada file if any. |
799 | |
800 | int b_mapped_ctrl_c; // modes where CTRL-C is mapped |
801 | |
802 | BufhlInfo b_bufhl_info; // buffer stored highlights |
803 | |
804 | kvec_t(BufhlLine *) b_bufhl_move_space; // temporary space for highlights |
805 | |
806 | // array of channel_id:s which have asked to receive updates for this |
807 | // buffer. |
808 | kvec_t(uint64_t) update_channels; |
809 | // array of lua callbacks for buffer updates. |
810 | kvec_t(BufUpdateCallbacks) update_callbacks; |
811 | |
812 | // whether an update callback has requested codepoint size of deleted regions. |
813 | bool update_need_codepoints; |
814 | |
815 | // Measurements of the deleted or replaced region since the last update |
816 | // event. Some consumers of buffer changes need to know the byte size (like |
817 | // tree-sitter) or the corresponding UTF-32/UTF-16 size (like LSP) of the |
818 | // deleted text. |
819 | size_t deleted_bytes; |
820 | size_t deleted_codepoints; |
821 | size_t deleted_codeunits; |
822 | |
823 | // The number for times the current line has been flushed in the memline. |
824 | int flush_count; |
825 | |
826 | int b_diff_failed; // internal diff failed for this buffer |
827 | }; |
828 | |
829 | /* |
830 | * Stuff for diff mode. |
831 | */ |
832 | # define DB_COUNT 8 // up to four buffers can be diff'ed |
833 | |
834 | /* |
835 | * Each diffblock defines where a block of lines starts in each of the buffers |
836 | * and how many lines it occupies in that buffer. When the lines are missing |
837 | * in the buffer the df_count[] is zero. This is all counted in |
838 | * buffer lines. |
839 | * There is always at least one unchanged line in between the diffs. |
840 | * Otherwise it would have been included in the diff above or below it. |
841 | * df_lnum[] + df_count[] is the lnum below the change. When in one buffer |
842 | * lines have been inserted, in the other buffer df_lnum[] is the line below |
843 | * the insertion and df_count[] is zero. When appending lines at the end of |
844 | * the buffer, df_lnum[] is one beyond the end! |
845 | * This is using a linked list, because the number of differences is expected |
846 | * to be reasonable small. The list is sorted on lnum. |
847 | */ |
848 | typedef struct diffblock_S diff_T; |
849 | struct diffblock_S { |
850 | diff_T *df_next; |
851 | linenr_T df_lnum[DB_COUNT]; /* line number in buffer */ |
852 | linenr_T df_count[DB_COUNT]; /* nr of inserted/changed lines */ |
853 | }; |
854 | |
855 | #define SNAP_HELP_IDX 0 |
856 | # define SNAP_AUCMD_IDX 1 |
857 | # define SNAP_COUNT 2 |
858 | |
859 | /// Tab pages point to the top frame of each tab page. |
860 | /// Note: Most values are NOT valid for the current tab page! Use "curwin", |
861 | /// "firstwin", etc. for that. "tp_topframe" is always valid and can be |
862 | /// compared against "topframe" to find the current tab page. |
863 | typedef struct tabpage_S tabpage_T; |
864 | struct tabpage_S { |
865 | handle_T handle; |
866 | tabpage_T *tp_next; ///< next tabpage or NULL |
867 | frame_T *tp_topframe; ///< topframe for the windows |
868 | win_T *tp_curwin; ///< current window in this Tab page |
869 | win_T *tp_prevwin; ///< previous window in this Tab page |
870 | win_T *tp_firstwin; ///< first window in this Tab page |
871 | win_T *tp_lastwin; ///< last window in this Tab page |
872 | long tp_old_Rows; ///< Rows when Tab page was left |
873 | long tp_old_Columns; ///< Columns when Tab page was left |
874 | long tp_ch_used; ///< value of 'cmdheight' when frame size |
875 | ///< was set |
876 | |
877 | diff_T *tp_first_diff; |
878 | buf_T *(tp_diffbuf[DB_COUNT]); |
879 | int tp_diff_invalid; ///< list of diffs is outdated |
880 | int tp_diff_update; ///< update diffs before redrawing |
881 | frame_T *(tp_snapshot[SNAP_COUNT]); ///< window layout snapshots |
882 | ScopeDictDictItem tp_winvar; ///< Variable for "t:" Dictionary. |
883 | dict_T *tp_vars; ///< Internal variables, local to tab page. |
884 | char_u *tp_localdir; ///< Absolute path of local cwd or NULL. |
885 | }; |
886 | |
887 | /* |
888 | * Structure to cache info for displayed lines in w_lines[]. |
889 | * Each logical line has one entry. |
890 | * The entry tells how the logical line is currently displayed in the window. |
891 | * This is updated when displaying the window. |
892 | * When the display is changed (e.g., when clearing the screen) w_lines_valid |
893 | * is changed to exclude invalid entries. |
894 | * When making changes to the buffer, wl_valid is reset to indicate wl_size |
895 | * may not reflect what is actually in the buffer. When wl_valid is FALSE, |
896 | * the entries can only be used to count the number of displayed lines used. |
897 | * wl_lnum and wl_lastlnum are invalid too. |
898 | */ |
899 | typedef struct w_line { |
900 | linenr_T wl_lnum; /* buffer line number for logical line */ |
901 | uint16_t wl_size; /* height in screen lines */ |
902 | char wl_valid; /* TRUE values are valid for text in buffer */ |
903 | char wl_folded; /* TRUE when this is a range of folded lines */ |
904 | linenr_T wl_lastlnum; /* last buffer line number for logical line */ |
905 | } wline_T; |
906 | |
907 | /* |
908 | * Windows are kept in a tree of frames. Each frame has a column (FR_COL) |
909 | * or row (FR_ROW) layout or is a leaf, which has a window. |
910 | */ |
911 | struct frame_S { |
912 | char fr_layout; /* FR_LEAF, FR_COL or FR_ROW */ |
913 | int fr_width; |
914 | int fr_newwidth; /* new width used in win_equal_rec() */ |
915 | int fr_height; |
916 | int fr_newheight; /* new height used in win_equal_rec() */ |
917 | frame_T *fr_parent; /* containing frame or NULL */ |
918 | frame_T *fr_next; /* frame right or below in same parent, NULL |
919 | for first */ |
920 | frame_T *fr_prev; /* frame left or above in same parent, NULL |
921 | for last */ |
922 | /* fr_child and fr_win are mutually exclusive */ |
923 | frame_T *fr_child; /* first contained frame */ |
924 | win_T *fr_win; /* window that fills this frame */ |
925 | }; |
926 | |
927 | #define FR_LEAF 0 /* frame is a leaf */ |
928 | #define FR_ROW 1 /* frame with a row of windows */ |
929 | #define FR_COL 2 /* frame with a column of windows */ |
930 | |
931 | /* |
932 | * Struct used for highlighting 'hlsearch' matches, matches defined by |
933 | * ":match" and matches defined by match functions. |
934 | * For 'hlsearch' there is one pattern for all windows. For ":match" and the |
935 | * match functions there is a different pattern for each window. |
936 | */ |
937 | typedef struct { |
938 | regmmatch_T rm; // points to the regexp program; contains last found |
939 | // match (may continue in next line) |
940 | buf_T *buf; // the buffer to search for a match |
941 | linenr_T lnum; // the line to search for a match |
942 | int attr; // attributes to be used for a match |
943 | int attr_cur; // attributes currently active in win_line() |
944 | linenr_T first_lnum; // first lnum to search for multi-line pat |
945 | colnr_T startcol; // in win_line() points to char where HL starts |
946 | colnr_T endcol; // in win_line() points to char where HL ends |
947 | bool is_addpos; // position specified directly by matchaddpos() |
948 | proftime_T tm; // for a time limit |
949 | } match_T; |
950 | |
951 | /// number of positions supported by matchaddpos() |
952 | #define MAXPOSMATCH 8 |
953 | |
954 | /// Same as lpos_T, but with additional field len. |
955 | typedef struct |
956 | { |
957 | linenr_T lnum; ///< line number |
958 | colnr_T col; ///< column number |
959 | int len; ///< length: 0 - to the end of line |
960 | } llpos_T; |
961 | |
962 | /// posmatch_T provides an array for storing match items for matchaddpos() |
963 | /// function. |
964 | typedef struct posmatch posmatch_T; |
965 | struct posmatch |
966 | { |
967 | llpos_T pos[MAXPOSMATCH]; ///< array of positions |
968 | int cur; ///< internal position counter |
969 | linenr_T toplnum; ///< top buffer line |
970 | linenr_T botlnum; ///< bottom buffer line |
971 | }; |
972 | |
973 | /* |
974 | * matchitem_T provides a linked list for storing match items for ":match" and |
975 | * the match functions. |
976 | */ |
977 | typedef struct matchitem matchitem_T; |
978 | struct matchitem { |
979 | matchitem_T *next; |
980 | int id; ///< match ID |
981 | int priority; ///< match priority |
982 | char_u *pattern; ///< pattern to highlight |
983 | int hlg_id; ///< highlight group ID |
984 | regmmatch_T match; ///< regexp program for pattern |
985 | posmatch_T pos; ///< position matches |
986 | match_T hl; ///< struct for doing the actual highlighting |
987 | int conceal_char; ///< cchar for Conceal highlighting |
988 | }; |
989 | |
990 | typedef int FloatAnchor; |
991 | |
992 | enum { |
993 | kFloatAnchorEast = 1, |
994 | kFloatAnchorSouth = 2, |
995 | }; |
996 | |
997 | // NW -> 0 |
998 | // NE -> kFloatAnchorEast |
999 | // SW -> kFloatAnchorSouth |
1000 | // SE -> kFloatAnchorSouth | kFloatAnchorEast |
1001 | EXTERN const char *const float_anchor_str[] INIT(= { "NW" , "NE" , "SW" , "SE" }); |
1002 | |
1003 | typedef enum { |
1004 | kFloatRelativeEditor = 0, |
1005 | kFloatRelativeWindow = 1, |
1006 | kFloatRelativeCursor = 2, |
1007 | } FloatRelative; |
1008 | |
1009 | EXTERN const char *const float_relative_str[] INIT(= { "editor" , "win" , |
1010 | "cursor" }); |
1011 | |
1012 | typedef enum { |
1013 | kWinStyleUnused = 0, |
1014 | kWinStyleMinimal, /// Minimal UI: no number column, eob markers, etc |
1015 | } WinStyle; |
1016 | |
1017 | typedef struct { |
1018 | Window window; |
1019 | lpos_T bufpos; |
1020 | int height, width; |
1021 | double row, col; |
1022 | FloatAnchor anchor; |
1023 | FloatRelative relative; |
1024 | bool external; |
1025 | bool focusable; |
1026 | WinStyle style; |
1027 | } FloatConfig; |
1028 | |
1029 | #define FLOAT_CONFIG_INIT ((FloatConfig){ .height = 0, .width = 0, \ |
1030 | .bufpos = { -1, 0 }, \ |
1031 | .row = 0, .col = 0, .anchor = 0, \ |
1032 | .relative = 0, .external = false, \ |
1033 | .focusable = true, \ |
1034 | .style = kWinStyleUnused }) |
1035 | |
1036 | // Structure to store last cursor position and topline. Used by check_lnums() |
1037 | // and reset_lnums(). |
1038 | typedef struct |
1039 | { |
1040 | int w_topline_save; // original topline value |
1041 | int w_topline_corr; // corrected topline value |
1042 | pos_T w_cursor_save; // original cursor position |
1043 | pos_T w_cursor_corr; // corrected cursor position |
1044 | } pos_save_T; |
1045 | |
1046 | /// Structure which contains all information that belongs to a window. |
1047 | /// |
1048 | /// All row numbers are relative to the start of the window, except w_winrow. |
1049 | struct window_S { |
1050 | handle_T handle; ///< unique identifier for the window |
1051 | |
1052 | buf_T *w_buffer; ///< buffer we are a window into (used |
1053 | ///< often, keep it the first item!) |
1054 | |
1055 | synblock_T *w_s; ///< for :ownsyntax |
1056 | |
1057 | int w_hl_id_normal; ///< 'winhighlight' normal id |
1058 | int w_hl_attr_normal; ///< 'winhighlight' normal final attrs |
1059 | |
1060 | int w_hl_ids[HLF_COUNT]; ///< 'winhighlight' id |
1061 | int w_hl_attrs[HLF_COUNT]; ///< 'winhighlight' final attrs |
1062 | |
1063 | int w_hl_needs_update; ///< attrs need to be recalculated |
1064 | |
1065 | win_T *w_prev; ///< link to previous window |
1066 | win_T *w_next; ///< link to next window |
1067 | bool w_closing; ///< window is being closed, don't let |
1068 | /// autocommands close it too. |
1069 | |
1070 | frame_T *w_frame; ///< frame containing this window |
1071 | |
1072 | pos_T w_cursor; ///< cursor position in buffer |
1073 | |
1074 | colnr_T w_curswant; ///< Column we want to be at. This is |
1075 | /// used to try to stay in the same column |
1076 | /// for up/down cursor motions. |
1077 | |
1078 | int w_set_curswant; // If set, then update w_curswant the next |
1079 | // time through cursupdate() to the |
1080 | // current virtual column |
1081 | |
1082 | linenr_T w_last_cursorline; ///< where last 'cursorline' was drawn |
1083 | pos_T w_last_cursormoved; ///< for CursorMoved event |
1084 | |
1085 | // the next seven are used to update the visual part |
1086 | char w_old_visual_mode; ///< last known VIsual_mode |
1087 | linenr_T w_old_cursor_lnum; ///< last known end of visual part |
1088 | colnr_T w_old_cursor_fcol; ///< first column for block visual part |
1089 | colnr_T w_old_cursor_lcol; ///< last column for block visual part |
1090 | linenr_T w_old_visual_lnum; ///< last known start of visual part |
1091 | colnr_T w_old_visual_col; ///< last known start of visual part |
1092 | colnr_T w_old_curswant; ///< last known value of Curswant |
1093 | |
1094 | // 'listchars' characters. Defaults set in set_chars_option(). |
1095 | struct { |
1096 | int eol; |
1097 | int ext; |
1098 | int prec; |
1099 | int nbsp; |
1100 | int space; |
1101 | int tab1; ///< first tab character |
1102 | int tab2; ///< second tab character |
1103 | int tab3; ///< third tab character |
1104 | int trail; |
1105 | int conceal; |
1106 | } w_p_lcs_chars; |
1107 | |
1108 | // 'fillchars' characters. Defaults set in set_chars_option(). |
1109 | struct { |
1110 | int stl; |
1111 | int stlnc; |
1112 | int vert; |
1113 | int fold; |
1114 | int diff; |
1115 | int msgsep; |
1116 | int eob; |
1117 | } w_p_fcs_chars; |
1118 | |
1119 | /* |
1120 | * "w_topline", "w_leftcol" and "w_skipcol" specify the offsets for |
1121 | * displaying the buffer. |
1122 | */ |
1123 | linenr_T w_topline; /* buffer line number of the line at the |
1124 | top of the window */ |
1125 | char w_topline_was_set; /* flag set to TRUE when topline is set, |
1126 | e.g. by winrestview() */ |
1127 | int w_topfill; /* number of filler lines above w_topline */ |
1128 | int w_old_topfill; /* w_topfill at last redraw */ |
1129 | bool w_botfill; /* true when filler lines are actually |
1130 | below w_topline (at end of file) */ |
1131 | bool w_old_botfill; /* w_botfill at last redraw */ |
1132 | colnr_T w_leftcol; /* window column number of the left most |
1133 | character in the window; used when |
1134 | 'wrap' is off */ |
1135 | colnr_T w_skipcol; /* starting column when a single line |
1136 | doesn't fit in the window */ |
1137 | |
1138 | // |
1139 | // Layout of the window in the screen. |
1140 | // May need to add "msg_scrolled" to "w_winrow" in rare situations. |
1141 | // |
1142 | int w_winrow; // first row of window in screen |
1143 | int w_height; // number of rows in window, excluding |
1144 | // status/command line(s) |
1145 | int w_status_height; // number of status lines (0 or 1) |
1146 | int w_wincol; // Leftmost column of window in screen. |
1147 | int w_width; // Width of window, excluding separation. |
1148 | int w_vsep_width; // Number of separator columns (0 or 1). |
1149 | pos_save_T w_save_cursor; // backup of cursor pos and topline |
1150 | |
1151 | // inner size of window, which can be overridden by external UI |
1152 | int w_height_inner; |
1153 | int w_width_inner; |
1154 | // external UI request. If non-zero, the inner size will use this. |
1155 | int w_height_request; |
1156 | int w_width_request; |
1157 | |
1158 | /* |
1159 | * === start of cached values ==== |
1160 | */ |
1161 | /* |
1162 | * Recomputing is minimized by storing the result of computations. |
1163 | * Use functions in screen.c to check if they are valid and to update. |
1164 | * w_valid is a bitfield of flags, which indicate if specific values are |
1165 | * valid or need to be recomputed. |
1166 | */ |
1167 | int w_valid; |
1168 | pos_T w_valid_cursor; /* last known position of w_cursor, used |
1169 | to adjust w_valid */ |
1170 | colnr_T w_valid_leftcol; /* last known w_leftcol */ |
1171 | |
1172 | /* |
1173 | * w_cline_height is the number of physical lines taken by the buffer line |
1174 | * that the cursor is on. We use this to avoid extra calls to plines(). |
1175 | */ |
1176 | int w_cline_height; /* current size of cursor line */ |
1177 | bool w_cline_folded; /* cursor line is folded */ |
1178 | |
1179 | int w_cline_row; /* starting row of the cursor line */ |
1180 | |
1181 | colnr_T w_virtcol; // column number of the cursor in the |
1182 | // buffer line, as opposed to the column |
1183 | // number we're at on the screen. This |
1184 | // makes a difference on lines which span |
1185 | // more than one screen line or when |
1186 | // w_leftcol is non-zero |
1187 | |
1188 | /* |
1189 | * w_wrow and w_wcol specify the cursor position in the window. |
1190 | * This is related to positions in the window, not in the display or |
1191 | * buffer, thus w_wrow is relative to w_winrow. |
1192 | */ |
1193 | int w_wrow, w_wcol; /* cursor position in window */ |
1194 | |
1195 | linenr_T w_botline; // number of the line below the bottom of |
1196 | // the window |
1197 | int w_empty_rows; // number of ~ rows in window |
1198 | int w_filler_rows; // number of filler rows at the end of the |
1199 | // window |
1200 | |
1201 | /* |
1202 | * Info about the lines currently in the window is remembered to avoid |
1203 | * recomputing it every time. The allocated size of w_lines[] is Rows. |
1204 | * Only the w_lines_valid entries are actually valid. |
1205 | * When the display is up-to-date w_lines[0].wl_lnum is equal to w_topline |
1206 | * and w_lines[w_lines_valid - 1].wl_lnum is equal to w_botline. |
1207 | * Between changing text and updating the display w_lines[] represents |
1208 | * what is currently displayed. wl_valid is reset to indicated this. |
1209 | * This is used for efficient redrawing. |
1210 | */ |
1211 | int w_lines_valid; /* number of valid entries */ |
1212 | wline_T *w_lines; |
1213 | |
1214 | garray_T w_folds; /* array of nested folds */ |
1215 | bool w_fold_manual; /* when true: some folds are opened/closed |
1216 | manually */ |
1217 | bool w_foldinvalid; /* when true: folding needs to be |
1218 | recomputed */ |
1219 | int w_nrwidth; /* width of 'number' and 'relativenumber' |
1220 | column being used */ |
1221 | |
1222 | /* |
1223 | * === end of cached values === |
1224 | */ |
1225 | |
1226 | int w_redr_type; /* type of redraw to be performed on win */ |
1227 | int w_upd_rows; /* number of window lines to update when |
1228 | w_redr_type is REDRAW_TOP */ |
1229 | linenr_T w_redraw_top; /* when != 0: first line needing redraw */ |
1230 | linenr_T w_redraw_bot; /* when != 0: last line needing redraw */ |
1231 | int w_redr_status; /* if TRUE status line must be redrawn */ |
1232 | |
1233 | /* remember what is shown in the ruler for this window (if 'ruler' set) */ |
1234 | pos_T w_ru_cursor; /* cursor position shown in ruler */ |
1235 | colnr_T w_ru_virtcol; /* virtcol shown in ruler */ |
1236 | linenr_T w_ru_topline; /* topline shown in ruler */ |
1237 | linenr_T w_ru_line_count; /* line count used for ruler */ |
1238 | int w_ru_topfill; /* topfill shown in ruler */ |
1239 | char w_ru_empty; /* TRUE if ruler shows 0-1 (empty line) */ |
1240 | |
1241 | int w_alt_fnum; /* alternate file (for # and CTRL-^) */ |
1242 | |
1243 | alist_T *w_alist; /* pointer to arglist for this window */ |
1244 | int w_arg_idx; /* current index in argument list (can be |
1245 | out of range!) */ |
1246 | int w_arg_idx_invalid; /* editing another file than w_arg_idx */ |
1247 | |
1248 | char_u *w_localdir; /* absolute path of local directory or |
1249 | NULL */ |
1250 | /* |
1251 | * Options local to a window. |
1252 | * They are local because they influence the layout of the window or |
1253 | * depend on the window layout. |
1254 | * There are two values: w_onebuf_opt is local to the buffer currently in |
1255 | * this window, w_allbuf_opt is for all buffers in this window. |
1256 | */ |
1257 | winopt_T w_onebuf_opt; |
1258 | winopt_T w_allbuf_opt; |
1259 | |
1260 | /* A few options have local flags for P_INSECURE. */ |
1261 | uint32_t w_p_stl_flags; /* flags for 'statusline' */ |
1262 | uint32_t w_p_fde_flags; /* flags for 'foldexpr' */ |
1263 | uint32_t w_p_fdt_flags; /* flags for 'foldtext' */ |
1264 | int *w_p_cc_cols; /* array of columns to highlight or NULL */ |
1265 | int w_p_brimin; /* minimum width for breakindent */ |
1266 | int w_p_brishift; /* additional shift for breakindent */ |
1267 | bool w_p_brisbr; /* sbr in 'briopt' */ |
1268 | |
1269 | /* transform a pointer to a "onebuf" option into a "allbuf" option */ |
1270 | #define GLOBAL_WO(p) ((char *)p + sizeof(winopt_T)) |
1271 | |
1272 | long w_scbind_pos; |
1273 | |
1274 | ScopeDictDictItem w_winvar; ///< Variable for "w:" dictionary. |
1275 | dict_T *w_vars; ///< Dictionary with w: variables. |
1276 | |
1277 | /* |
1278 | * The w_prev_pcmark field is used to check whether we really did jump to |
1279 | * a new line after setting the w_pcmark. If not, then we revert to |
1280 | * using the previous w_pcmark. |
1281 | */ |
1282 | pos_T w_pcmark; /* previous context mark */ |
1283 | pos_T w_prev_pcmark; /* previous w_pcmark */ |
1284 | |
1285 | /* |
1286 | * the jumplist contains old cursor positions |
1287 | */ |
1288 | xfmark_T w_jumplist[JUMPLISTSIZE]; |
1289 | int w_jumplistlen; /* number of active entries */ |
1290 | int w_jumplistidx; /* current position */ |
1291 | |
1292 | int w_changelistidx; /* current position in b_changelist */ |
1293 | |
1294 | matchitem_T *w_match_head; /* head of match list */ |
1295 | int w_next_match_id; /* next match ID */ |
1296 | |
1297 | /* |
1298 | * the tagstack grows from 0 upwards: |
1299 | * entry 0: older |
1300 | * entry 1: newer |
1301 | * entry 2: newest |
1302 | */ |
1303 | taggy_T w_tagstack[TAGSTACKSIZE]; /* the tag stack */ |
1304 | int w_tagstackidx; /* idx just below active entry */ |
1305 | int w_tagstacklen; /* number of tags on stack */ |
1306 | |
1307 | ScreenGrid w_grid; // the grid specific to the window |
1308 | bool w_pos_changed; // true if window position changed |
1309 | bool w_floating; ///< whether the window is floating |
1310 | FloatConfig w_float_config; |
1311 | |
1312 | /* |
1313 | * w_fraction is the fractional row of the cursor within the window, from |
1314 | * 0 at the top row to FRACTION_MULT at the last row. |
1315 | * w_prev_fraction_row was the actual cursor row when w_fraction was last |
1316 | * calculated. |
1317 | */ |
1318 | int w_fraction; |
1319 | int w_prev_fraction_row; |
1320 | |
1321 | linenr_T w_nrwidth_line_count; /* line count when ml_nrwidth_width |
1322 | * was computed. */ |
1323 | int w_nrwidth_width; /* nr of chars to print line count. */ |
1324 | |
1325 | qf_info_T *w_llist; /* Location list for this window */ |
1326 | /* |
1327 | * Location list reference used in the location list window. |
1328 | * In a non-location list window, w_llist_ref is NULL. |
1329 | */ |
1330 | qf_info_T *w_llist_ref; |
1331 | }; |
1332 | |
1333 | static inline int win_hl_attr(win_T *wp, int hlf) |
1334 | { |
1335 | return wp->w_hl_attrs[hlf]; |
1336 | } |
1337 | |
1338 | /// Macros defined in Vim, but not in Neovim |
1339 | #define CHANGEDTICK(buf) \ |
1340 | (=== Include buffer.h & use buf_(get|set|inc)_changedtick ===) |
1341 | |
1342 | #endif // NVIM_BUFFER_DEFS_H |
1343 | |