#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_IM 2		/*	Input via input method */
# define B_IMODE_LAST 2

#define CHANGEDTICK(buf) ((buf)->b_ct_di.di_tv.vval.v_number)

struct file_buffer
{
    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 */

    /*
     * 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 */

    int		b_fnum;		/* buffer number for this file. */
    char_u	b_key[VIM_SIZEOF_INT * 2 + 1];
				/* key used for buf_hashtab, holds b_fnum as
				   hex string */

    int		b_changed;	/* 'modified': Set to TRUE if something in the
				   file has been changed and not written out. */
    dictitem16_T b_ct_di;	/* holds the b:changedtick value in
				   b_ct_di.di_tv.vval.v_number;
				   incremented for each change, also for undo */
  int		b_saving;	/* Set to TRUE if we are in the middle of
				   saving the buffer. */
    /*
     * Changes to a buffer require updating of the display.  To minimize the
     * work, remember changes made and update everything at once.
     */
    int		b_mod_set;	/* TRUE when there are changes since the last
				   time the display was updated */
    linenr_T	b_mod_top;	/* topmost lnum that was changed */
    linenr_T	b_mod_bot;	/* lnum below last changed line, AFTER the
				   change */
    long	b_mod_xlines;	/* number of extra buffer lines inserted;
				   negative when lines were deleted */

    wininfo_T	*b_wininfo;	/* list of last used info for each window */

    long	b_mtime;	/* last change time of original file */
    long	b_mtime_read;	/* last change time when reading */
    off_T	b_orig_size;	/* size of original file in bytes */
    int		b_orig_mode;	/* mode of original file */

    pos_T	b_namedm[NMARKS]; /* current named marks (mark.c) */

    /* These variables are set when VIsual_active becomes FALSE */
    visualinfo_T b_visual;

    pos_T	b_last_cursor;	/* cursor position when last unloading this
				   buffer */
    pos_T	b_last_insert;	/* where Insert mode was left */
    pos_T	b_last_change;	/* position of last change: '. mark */


    /*
     * Character table, only used in charset.c for 'iskeyword'
     * 32 bytes of 8 bits: 1 bit per character 0-255.
     */
    char_u	b_chartab[32];

    /*
     * start and end of an operator, also used for '[ and ']
     */
    pos_T	b_op_start;
    pos_T	b_op_start_orig;  /* used for Insstart_orig */
    pos_T	b_op_end;

    /*
     * The following only used in undo.c.
     */
    u_header_T	*b_u_oldhead;	/* pointer to oldest header */
    u_header_T	*b_u_newhead;	/* pointer to newest header; may not be valid
				   if b_u_curhead is not NULL */
    u_header_T	*b_u_curhead;	/* pointer to current header */
    int		b_u_numhead;	/* current number of headers */
    int		b_u_synced;	/* entry lists are synced */
    long	b_u_seq_last;	/* last used undo sequence number */
    long	b_u_save_nr_last; /* counter for last file write */
    long	b_u_seq_cur;	/* hu_seq of header below which we are now */
    time_T	b_u_time_cur;	/* uh_time of header below which we are now */
    long	b_u_save_nr_cur; /* file write nr after which we are now */

    /*
     * variables for "U" command in undo.c
     */
    char_u	*b_u_line_ptr;	/* saved line for "U" command */
    linenr_T	b_u_line_lnum;	/* line number of line in u_line */
    colnr_T	b_u_line_colnr;	/* optional column number */


    /* flags for use of ":lmap" and IM control */
    long	b_p_iminsert;	/* input mode for insert */
    long	b_p_imsearch;	/* input mode for search */

    /*
     * Options local to a buffer.
     * They are here because their value depends on the type of file
     * or contents of the file being edited.
     */
    int		b_p_initialized;	/* set when options initialized */

    int		b_p_ai;		/* 'autoindent' */
    int		b_p_ai_nopaste;	/* b_p_ai saved for paste mode */
    char_u	*b_p_bkc;	/* 'backupcopy' */
    unsigned	b_bkc_flags;    /* flags for 'backupcopy' */
    int		b_p_ci;		/* 'copyindent' */
    int		b_p_bin;	/* 'binary' */
    int		b_p_bl;		/* 'buflisted' */

    int		b_p_eol;	/* 'endofline' */
    int		b_p_fixeol;	/* 'fixendofline' */
    int		b_p_et;		/* 'expandtab' */
    int		b_p_et_nobin;	/* b_p_et saved for binary mode */
    int	        b_p_et_nopaste; /* b_p_et saved for paste mode */

    char_u	*b_p_fo;	/* 'formatoptions' */
    char_u	*b_p_flp;	/* 'formatlistpat' */
    int		b_p_inf;	/* 'infercase' */
    char_u	*b_p_isk;	/* 'iskeyword' */
    char_u	*b_p_fp;	/* 'formatprg' */

    char_u	*b_p_kp;	/* 'keywordprg' */
    char_u	*b_p_mps;	/* 'matchpairs' */
    int		b_p_ml;		/* 'modeline' */
    int		b_p_ml_nobin;	/* b_p_ml saved for binary mode */
    int		b_p_ma;		/* 'modifiable' */
    char_u	*b_p_nf;	/* 'nrformats' */
    int		b_p_pi;		/* 'preserveindent' */
    int		b_p_ro;		/* 'readonly' */
    long	b_p_sw;		/* 'shiftwidth' */
    int		b_p_sn;		/* 'shortname' */
    long	b_p_sts;	/* 'softtabstop' */
    long	b_p_sts_nopaste; /* b_p_sts saved for paste mode */
    int		b_p_swf;	/* 'swapfile' */
    long	b_p_ts;		/* 'tabstop' */
    int		b_p_tx;		/* 'textmode' */
    long	b_p_tw;		/* 'textwidth' */
    long	b_p_tw_nobin;	/* b_p_tw saved for binary mode */
    long	b_p_tw_nopaste;	/* b_p_tw saved for paste mode */
    long	b_p_wm;		/* 'wrapmargin' */
    long	b_p_wm_nobin;	/* b_p_wm saved for binary mode */
    long	b_p_wm_nopaste;	/* b_p_wm saved for paste mode */

    /* local values for options which are normally global */
    char_u	*b_p_ep;	/* 'equalprg' local value */
    char_u	*b_p_path;	/* 'path' local value */
    int		b_p_ar;		/* 'autoread' local value */
    char_u	*b_p_tags;	/* 'tags' local value */
    char_u	*b_p_tc;	/* 'tagcase' local value */
    unsigned	b_tc_flags;     /* flags for 'tagcase' */

    long	b_p_ul;		/* 'undolevels' local value */

    /* end of buffer options */

    linenr_T	b_no_eol_lnum;	/* non-zero lnum when last line of next binary
				 * write should not have an end-of-line */
    int		b_start_eol;	/* last line had eol when it was read */
    int		b_start_ffc;	/* first char of 'ff' when edit started */


    /* 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
     * if a swap file could not be opened.
     */
    int		b_may_swap;
    int		b_did_warn;	/* Set to 1 if user has been warned on first
				   change of a read-only file */

    /* 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.
     */
    int		b_help;		/* TRUE for help file buffer (when set b_p_bt
				   is "help") */
    int		b_shortname;	/* this file has an 8.3 file name */
    int		b_mapped_ctrl_c; /* modes where CTRL-C is mapped */
}; /* file_buffer */
