diff options
Diffstat (limited to 'src/nvim/buffer_defs.h')
-rw-r--r-- | src/nvim/buffer_defs.h | 329 |
1 files changed, 188 insertions, 141 deletions
diff --git a/src/nvim/buffer_defs.h b/src/nvim/buffer_defs.h index b515c4e1e4..05688790c2 100644 --- a/src/nvim/buffer_defs.h +++ b/src/nvim/buffer_defs.h @@ -8,14 +8,24 @@ typedef struct file_buffer buf_T; // Forward declaration +// Reference to a buffer that stores the value of buf_free_count. +// bufref_valid() only needs to check "buf" when the count differs. +typedef struct { + buf_T *br_buf; + int br_fnum; + int br_buf_free_count; +} bufref_T; + // for garray_T #include "nvim/garray.h" +// for ScreenGrid +#include "nvim/grid_defs.h" +// for HLF_COUNT +#include "nvim/highlight_defs.h" // for pos_T, lpos_T and linenr_T #include "nvim/pos.h" // for the number window-local and buffer-local options #include "nvim/option_defs.h" -// for optional iconv support -#include "nvim/iconv.h" // for jump list and tag stack sizes in a buffer and mark types #include "nvim/mark_defs.h" // for u_header_T; needs buf_T. @@ -23,15 +33,18 @@ typedef struct file_buffer buf_T; // Forward declaration // for hashtab_T #include "nvim/hashtab.h" // for dict_T -#include "nvim/eval_defs.h" +#include "nvim/eval/typval.h" // for proftime_T #include "nvim/profile.h" // for String #include "nvim/api/private/defs.h" // for Map(K, V) #include "nvim/map.h" +// for kvec +#include "nvim/lib/kvec.h" -#define MODIFIABLE(buf) (!buf->terminal && buf->b_p_ma) +#define GETFILE_SUCCESS(x) ((x) <= 0) +#define MODIFIABLE(buf) (buf->b_p_ma) /* * Flags for w_valid. @@ -47,10 +60,10 @@ typedef struct file_buffer buf_T; // Forward declaration * functions that set or reset the flags. * * VALID_BOTLINE VALID_BOTLINE_AP - * on on w_botline valid - * off on w_botline approximated - * off off w_botline not valid - * on off not possible + * on on w_botline valid + * off on w_botline approximated + * off off w_botline not valid + * on off not possible */ #define VALID_WROW 0x01 /* w_wrow (window row) is valid */ #define VALID_WCOL 0x02 /* w_wcol (window col) is valid */ @@ -83,36 +96,24 @@ typedef struct file_buffer buf_T; // Forward declaration typedef struct window_S win_T; typedef struct wininfo_S wininfo_T; typedef struct frame_S frame_T; -typedef int scid_T; /* script ID */ +typedef uint16_t disptick_T; // display tick type // for struct memline (it needs memfile_T) #include "nvim/memline_defs.h" - // for struct memfile, bhdr_T, blocknr_T... (it needs buf_T) #include "nvim/memfile_defs.h" -/* - * This is here because regexp_defs.h needs win_T and buf_T. regprog_T is - * used below. - */ +// for regprog_T. Needs win_T and buf_T. #include "nvim/regexp_defs.h" - -// for synstate_T (needs reg_extmatch_T, win_T and buf_T) +// for synstate_T (needs reg_extmatch_T, win_T, buf_T) #include "nvim/syntax_defs.h" - // for signlist_T #include "nvim/sign_defs.h" - // for bufhl_*_T #include "nvim/bufhl_defs.h" -typedef Map(linenr_T, bufhl_vec_T) bufhl_info_T; - -// for FileID -#include "nvim/os/fs_defs.h" - -// for Terminal -#include "nvim/terminal.h" +#include "nvim/os/fs_defs.h" // for FileID +#include "nvim/terminal.h" // for Terminal /* * The taggy struct is used to store the information about a :tag command. @@ -145,6 +146,12 @@ struct buffheader { size_t bh_space; // space in bh_curr for appending }; +typedef struct +{ + buffheader_T sr_redobuff; + buffheader_T sr_old_redobuff; +} save_redo_T; + /* * Structure that contains all options that are local to a window. * Used twice in a window: for the current buffer and for all buffers. @@ -154,7 +161,7 @@ typedef struct { int wo_arab; # define w_p_arab w_onebuf_opt.wo_arab /* 'arabic' */ int wo_bri; -# define w_p_bri w_onebuf_opt.wo_bri /* 'breakindent' */ +# define w_p_bri w_onebuf_opt.wo_bri // 'breakindent' char_u *wo_briopt; # define w_p_briopt w_onebuf_opt.wo_briopt /* 'breakindentopt' */ int wo_diff; @@ -237,8 +244,12 @@ typedef struct { # define w_p_crb w_onebuf_opt.wo_crb /* 'cursorbind' */ int wo_crb_save; /* 'cursorbind' state saved for diff mode*/ # define w_p_crb_save w_onebuf_opt.wo_crb_save + char_u *wo_scl; +# define w_p_scl w_onebuf_opt.wo_scl // 'signcolumn' + char_u *wo_winhl; +# define w_p_winhl w_onebuf_opt.wo_winhl // 'winhighlight' - int wo_scriptID[WV_COUNT]; /* SIDs for window-local options */ + LastSet wo_scriptID[WV_COUNT]; // SIDs for window-local options # define w_p_scriptID w_onebuf_opt.wo_scriptID } winopt_T; @@ -323,25 +334,6 @@ typedef struct { } tasave_T; /* - * Used for conversion of terminal I/O and script files. - */ -typedef struct { - int vc_type; /* zero or one of the CONV_ values */ - int vc_factor; /* max. expansion factor */ -# ifdef USE_ICONV - iconv_t vc_fd; /* for CONV_ICONV */ -# endif - bool vc_fail; /* fail for invalid char, don't use '?' */ -} vimconv_T; - -#define CONV_NONE 0 -#define CONV_TO_UTF8 1 -#define CONV_9_TO_UTF8 2 -#define CONV_TO_LATIN1 3 -#define CONV_TO_LATIN9 4 -#define CONV_ICONV 5 - -/* * Structure used for mappings and abbreviations. */ typedef struct mapblock mapblock_T; @@ -422,13 +414,13 @@ typedef struct { * syntax state too often. * b_sst_array[] is allocated to hold the state for all displayed lines, * and states for 1 out of about 20 other lines. - * b_sst_array pointer to an array of synstate_T - * b_sst_len number of entries in b_sst_array[] - * b_sst_first pointer to first used entry in b_sst_array[] or NULL - * b_sst_firstfree pointer to first free entry in b_sst_array[] or NULL - * b_sst_freecount number of free entries in b_sst_array[] - * b_sst_check_lnum entries after this lnum need to be checked for - * validity (MAXLNUM means no check needed) + * b_sst_array pointer to an array of synstate_T + * b_sst_len number of entries in b_sst_array[] + * b_sst_first pointer to first used entry in b_sst_array[] or NULL + * b_sst_firstfree pointer to first free entry in b_sst_array[] or NULL + * b_sst_freecount number of free entries in b_sst_array[] + * b_sst_check_lnum entries after this lnum need to be checked for + * validity (MAXLNUM means no check needed) */ synstate_T *b_sst_array; int b_sst_len; @@ -436,7 +428,7 @@ typedef struct { synstate_T *b_sst_firstfree; int b_sst_freecount; linenr_T b_sst_check_lnum; - uint16_t b_sst_lasttick; /* last display tick */ + disptick_T b_sst_lasttick; // last display tick // for spell checking garray_T b_langp; // list of pointers to slang_T, see spell.c @@ -451,6 +443,16 @@ typedef struct { char_u *b_syn_isk; // iskeyword option } synblock_T; +/// Type used for changedtick_di member in buf_T +/// +/// Primary exists so that literals of relevant type can be made. +typedef TV_DICTITEM_STRUCT(sizeof("changedtick")) ChangedtickDictItem; + +#define BUF_HAS_QF_ENTRY 1 +#define BUF_HAS_LL_ENTRY 2 + +// Maximum number of maphash blocks we will have +#define MAX_MAPHASH 256 /* * buffer: structure that holds information about one file @@ -461,37 +463,45 @@ typedef struct { */ struct file_buffer { - uint64_t handle; // unique identifier for the buffer - memline_T b_ml; /* associated memline (also contains line - count) */ + handle_T handle; // unique id for the buffer (buffer number) +#define b_fnum handle + + memline_T b_ml; // associated memline (also contains line count buf_T *b_next; /* links in list of buffers */ buf_T *b_prev; int b_nwindows; /* nr of windows open on this buffer */ - int b_flags; /* various BF_ flags */ - bool b_closing; /* buffer is being closed, don't let - autocommands close it too. */ + int b_flags; // various BF_ flags + int b_locked; // Buffer is being closed or referenced, don't + // let autocommands wipe it out. - /* - * b_ffname has the full path of the file (NULL for no name). - * b_sfname is the name as the user typed it (or NULL). - * b_fname is the same as b_sfname, unless ":cd" has been done, - * then it is the same as b_ffname (NULL for no name). - */ - char_u *b_ffname; /* full path file name */ - char_u *b_sfname; /* short file name */ - char_u *b_fname; /* current file name */ + // + // b_ffname has the full path of the file (NULL for no name). + // b_sfname is the name as the user typed it (or NULL). + // b_fname is the same as b_sfname, unless ":cd" has been done, + // then it is the same as b_ffname (NULL for no name). + // + char_u *b_ffname; // full path file name + char_u *b_sfname; // short file name + char_u *b_fname; // current file name bool file_id_valid; FileID file_id; - int b_fnum; /* buffer number for this file. */ + int b_changed; // 'modified': Set to true if something in the + // file has been changed and not written out. - bool b_changed; /* 'modified': Set to true if something in the - file has been changed and not written out. */ - int b_changedtick; /* incremented for each change, also for undo */ + /// Change identifier incremented for each change, including undo + /// + /// This is a dictionary item used to store in b:changedtick. + ChangedtickDictItem changedtick_di; + + varnumber_T b_last_changedtick; // b:changedtick when TextChanged or + // TextChangedI was last triggered. + varnumber_T b_last_changedtick_pum; // b:changedtick when TextChangedP was + // last triggered. bool b_saving; /* Set to true if we are in the middle of saving the buffer. */ @@ -539,8 +549,8 @@ struct file_buffer { */ uint64_t b_chartab[4]; - /* Table used for mappings local to a buffer. */ - mapblock_T *(b_maphash[256]); + // Table used for mappings local to a buffer. + mapblock_T *(b_maphash[MAX_MAPHASH]); /* First abbreviation local to a buffer. */ mapblock_T *b_first_abbr; @@ -579,12 +589,12 @@ struct file_buffer { bool b_scanned; /* ^N/^P have scanned this buffer */ - /* flags for use of ":lmap" and IM control */ - long b_p_iminsert; /* input mode for insert */ - long b_p_imsearch; /* input mode for search */ -#define B_IMODE_USE_INSERT -1 /* Use b_p_iminsert value for search */ -#define B_IMODE_NONE 0 /* Input via none */ -#define B_IMODE_LMAP 1 /* Input via langmap */ + // flags for use of ":lmap" and IM control + long b_p_iminsert; // input mode for insert + long b_p_imsearch; // input mode for search +#define B_IMODE_USE_INSERT -1 // Use b_p_iminsert value for search +#define B_IMODE_NONE 0 // Input via none +#define B_IMODE_LMAP 1 // Input via langmap # define B_IMODE_LAST 1 short b_kmap_state; /* using "lmap" mappings */ @@ -599,7 +609,7 @@ struct file_buffer { */ bool b_p_initialized; /* set when options initialized */ - int b_p_scriptID[BV_COUNT]; /* SIDs for buffer-local options */ + LastSet b_p_scriptID[BV_COUNT]; // SIDs for buffer-local options int b_p_ai; ///< 'autoindent' int b_p_ai_nopaste; ///< b_p_ai saved for paste mode @@ -610,7 +620,9 @@ struct file_buffer { int b_p_bomb; ///< 'bomb' char_u *b_p_bh; ///< 'bufhidden' char_u *b_p_bt; ///< 'buftype' + int b_has_qf_entry; ///< quickfix exists for buffer int b_p_bl; ///< 'buflisted' + long b_p_channel; ///< 'channel' int b_p_cin; ///< 'cindent' char_u *b_p_cino; ///< 'cinoptions' char_u *b_p_cink; ///< 'cinkeys' @@ -639,10 +651,12 @@ struct file_buffer { char_u *b_p_inde; ///< 'indentexpr' uint32_t b_p_inde_flags; ///< flags for 'indentexpr' char_u *b_p_indk; ///< 'indentkeys' + char_u *b_p_fp; ///< 'formatprg' char_u *b_p_fex; ///< 'formatexpr' uint32_t b_p_fex_flags; ///< flags for 'formatexpr' char_u *b_p_kp; ///< 'keywordprg' int b_p_lisp; ///< 'lisp' + char_u *b_p_menc; ///< 'makeencoding' char_u *b_p_mps; ///< 'matchpairs' int b_p_ml; ///< 'modeline' int b_p_ml_nobin; ///< b_p_ml saved for binary mode @@ -652,11 +666,12 @@ struct file_buffer { char_u *b_p_qe; ///< 'quoteescape' int b_p_ro; ///< 'readonly' long b_p_sw; ///< 'shiftwidth' + long b_p_scbk; ///< 'scrollback' int b_p_si; ///< 'smartindent' long b_p_sts; ///< 'softtabstop' long b_p_sts_nopaste; ///< b_p_sts saved for paste mode char_u *b_p_sua; ///< 'suffixesadd' - bool b_p_swf; ///< 'swapfile' + int b_p_swf; ///< 'swapfile' long b_p_smc; ///< 'synmaxcol' char_u *b_p_syn; ///< 'syntax' long b_p_ts; ///< 'tabstop' @@ -722,6 +737,7 @@ struct file_buffer { int b_ind_hash_comment; int b_ind_cpp_namespace; int b_ind_if_for_while; + int b_ind_cpp_extern_c; linenr_T b_no_eol_lnum; /* non-zero lnum when last line of next binary * write should not have an end-of-line */ @@ -732,8 +748,8 @@ struct file_buffer { int b_bad_char; /* "++bad=" argument when edit started or 0 */ int b_start_bomb; /* 'bomb' when it was read */ - dictitem_T b_bufvar; /* variable for "b:" Dictionary */ - dict_T *b_vars; /* internal variables, local to buffer */ + ScopeDictDictItem b_bufvar; ///< Variable for "b:" Dictionary. + dict_T *b_vars; ///< b: scope dictionary. /* When a buffer is created, it starts without a swap file. b_may_swap is * then set to indicate that a swap file may be opened later. It is reset @@ -746,7 +762,7 @@ struct file_buffer { /* Two special kinds of buffers: * help buffer - used for help files, won't use a swap file. * spell buffer - used for spell info, never displayed and doesn't have a - * file name. + * file name. */ bool b_help; /* TRUE for help file buffer (when set b_p_bt is "help") */ @@ -766,13 +782,21 @@ struct file_buffer { int b_mapped_ctrl_c; // modes where CTRL-C is mapped - bufhl_info_T *b_bufhl_info; // buffer stored highlights + BufhlInfo b_bufhl_info; // buffer stored highlights + + kvec_t(BufhlLine *) b_bufhl_move_space; // temporary space for highlights + + // array of channelids which have asked to receive updates for this + // buffer. + kvec_t(uint64_t) update_channels; + + int b_diff_failed; // internal diff failed for this buffer }; /* * Stuff for diff mode. */ -# define DB_COUNT 4 /* up to four buffers can be diff'ed */ +# define DB_COUNT 8 // up to four buffers can be diff'ed /* * Each diffblock defines where a block of lines starts in each of the buffers @@ -799,33 +823,32 @@ struct diffblock_S { # define SNAP_AUCMD_IDX 1 # define SNAP_COUNT 2 -/* - * Tab pages point to the top frame of each tab page. - * Note: Most values are NOT valid for the current tab page! Use "curwin", - * "firstwin", etc. for that. "tp_topframe" is always valid and can be - * compared against "topframe" to find the current tab page. - */ +/// Tab pages point to the top frame of each tab page. +/// Note: Most values are NOT valid for the current tab page! Use "curwin", +/// "firstwin", etc. for that. "tp_topframe" is always valid and can be +/// compared against "topframe" to find the current tab page. typedef struct tabpage_S tabpage_T; struct tabpage_S { - uint64_t handle; - tabpage_T *tp_next; /* next tabpage or NULL */ - frame_T *tp_topframe; /* topframe for the windows */ - win_T *tp_curwin; /* current window in this Tab page */ - win_T *tp_prevwin; /* previous window in this Tab page */ - win_T *tp_firstwin; /* first window in this Tab page */ - win_T *tp_lastwin; /* last window in this Tab page */ - long tp_old_Rows; /* Rows when Tab page was left */ - long tp_old_Columns; /* Columns when Tab page was left */ - long tp_ch_used; /* value of 'cmdheight' when frame size - was set */ + handle_T handle; + tabpage_T *tp_next; ///< next tabpage or NULL + frame_T *tp_topframe; ///< topframe for the windows + win_T *tp_curwin; ///< current window in this Tab page + win_T *tp_prevwin; ///< previous window in this Tab page + win_T *tp_firstwin; ///< first window in this Tab page + win_T *tp_lastwin; ///< last window in this Tab page + long tp_old_Rows; ///< Rows when Tab page was left + long tp_old_Columns; ///< Columns when Tab page was left + long tp_ch_used; ///< value of 'cmdheight' when frame size + ///< was set + diff_T *tp_first_diff; buf_T *(tp_diffbuf[DB_COUNT]); - int tp_diff_invalid; ///< list of diffs is outdated */ + int tp_diff_invalid; ///< list of diffs is outdated + int tp_diff_update; ///< update diffs before redrawing frame_T *(tp_snapshot[SNAP_COUNT]); ///< window layout snapshots - dictitem_T tp_winvar; ///< variable for "t:" Dictionary - dict_T *tp_vars; ///< internal variables, local to tab page - char_u *localdir; ///< Absolute path of local directory or - ///< NULL + ScopeDictDictItem tp_winvar; ///< Variable for "t:" Dictionary. + dict_T *tp_vars; ///< Internal variables, local to tab page. + char_u *tp_localdir; ///< Absolute path of local cwd or NULL. }; /* @@ -879,16 +902,17 @@ struct frame_S { * match functions there is a different pattern for each window. */ typedef struct { - regmmatch_T rm; /* points to the regexp program; contains last found - match (may continue in next line) */ - buf_T *buf; /* the buffer to search for a match */ - linenr_T lnum; /* the line to search for a match */ - int attr; /* attributes to be used for a match */ - int attr_cur; /* attributes currently active in win_line() */ - linenr_T first_lnum; /* first lnum to search for multi-line pat */ - colnr_T startcol; /* in win_line() points to char where HL starts */ - colnr_T endcol; /* in win_line() points to char where HL ends */ - proftime_T tm; /* for a time limit */ + regmmatch_T rm; // points to the regexp program; contains last found + // match (may continue in next line) + buf_T *buf; // the buffer to search for a match + linenr_T lnum; // the line to search for a match + int attr; // attributes to be used for a match + int attr_cur; // attributes currently active in win_line() + linenr_T first_lnum; // first lnum to search for multi-line pat + colnr_T startcol; // in win_line() points to char where HL starts + colnr_T endcol; // in win_line() points to char where HL ends + bool is_addpos; // position specified directly by matchaddpos() + proftime_T tm; // for a time limit } match_T; /// number of positions supported by matchaddpos() @@ -897,9 +921,9 @@ typedef struct { /// Same as lpos_T, but with additional field len. typedef struct { - linenr_T lnum; ///< line number - colnr_T col; ///< column number - int len; ///< length: 0 - to the end of line + linenr_T lnum; ///< line number + colnr_T col; ///< column number + int len; ///< length: 0 - to the end of line } llpos_T; /// posmatch_T provides an array for storing match items for matchaddpos() @@ -907,10 +931,10 @@ typedef struct typedef struct posmatch posmatch_T; struct posmatch { - llpos_T pos[MAXPOSMATCH]; ///< array of positions - int cur; ///< internal position counter - linenr_T toplnum; ///< top buffer line - linenr_T botlnum; ///< bottom buffer line + llpos_T pos[MAXPOSMATCH]; ///< array of positions + int cur; ///< internal position counter + linenr_T toplnum; ///< top buffer line + linenr_T botlnum; ///< bottom buffer line }; /* @@ -936,12 +960,21 @@ struct matchitem { * All row numbers are relative to the start of the window, except w_winrow. */ struct window_S { - uint64_t handle; - buf_T *w_buffer; /* buffer we are a window into (used - often, keep it the first item!) */ + handle_T handle; ///< unique identifier for the window + + buf_T *w_buffer; ///< buffer we are a window into (used + ///< often, keep it the first item!) synblock_T *w_s; /* for :ownsyntax */ + int w_hl_id_normal; ///< 'winhighlight' normal id + int w_hl_attr_normal; ///< 'winhighlight' normal final attrs + + int w_hl_ids[HLF_COUNT]; ///< 'winhighlight' id + int w_hl_attrs[HLF_COUNT]; ///< 'winhighlight' final attrs + + int w_hl_needs_update; ///< attrs need to be recalculated + win_T *w_prev; /* link to previous window */ win_T *w_next; /* link to next window */ bool w_closing; /* window is being closed, don't let @@ -955,9 +988,11 @@ struct window_S { used to try to stay in the same column for up/down cursor motions. */ - int w_set_curswant; /* If set, then update w_curswant the next - time through cursupdate() to the - current virtual column */ + int w_set_curswant; // If set, then update w_curswant the next + // time through cursupdate() to the + // current virtual column + + linenr_T w_last_cursorline; ///< where last 'cursorline' was drawn // the next seven are used to update the visual part char w_old_visual_mode; ///< last known VIsual_mode @@ -1006,7 +1041,7 @@ struct window_S { * Recomputing is minimized by storing the result of computations. * Use functions in screen.c to check if they are valid and to update. * w_valid is a bitfield of flags, which indicate if specific values are - * valid or need to be recomputed. + * valid or need to be recomputed. */ int w_valid; pos_T w_valid_cursor; /* last known position of w_cursor, used @@ -1036,11 +1071,11 @@ struct window_S { */ int w_wrow, w_wcol; /* cursor position in window */ - linenr_T w_botline; /* number of the line below the bottom of - the screen */ - int w_empty_rows; /* number of ~ rows in window */ - int w_filler_rows; /* number of filler rows at the end of the - window */ + linenr_T w_botline; // number of the line below the bottom of + // the window + int w_empty_rows; // number of ~ rows in window + int w_filler_rows; // number of filler rows at the end of the + // window /* * Info about the lines currently in the window is remembered to avoid @@ -1115,8 +1150,8 @@ struct window_S { long w_scbind_pos; - dictitem_T w_winvar; /* variable for "w:" Dictionary */ - dict_T *w_vars; /* internal variables, local to window */ + ScopeDictDictItem w_winvar; ///< Variable for "w:" dictionary. + dict_T *w_vars; ///< Dictionary with w: variables. int w_farsi; /* for the window dependent Farsi functions */ @@ -1150,6 +1185,9 @@ struct window_S { int w_tagstackidx; /* idx just below active entry */ int w_tagstacklen; /* number of tags on stack */ + ScreenGrid w_grid; // the grid specific to the window + bool w_pos_changed; // true if window position changed + /* * w_fraction is the fractional row of the cursor within the window, from * 0 at the top row to FRACTION_MULT at the last row. @@ -1171,4 +1209,13 @@ struct window_S { qf_info_T *w_llist_ref; }; +static inline int win_hl_attr(win_T *wp, int hlf) +{ + return wp->w_hl_attrs[hlf]; +} + +/// Macros defined in Vim, but not in Neovim +#define CHANGEDTICK(buf) \ + (=== Include buffer.h & use buf_(get|set|inc)_changedtick ===) + #endif // NVIM_BUFFER_DEFS_H |