neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

globals.h (37072B)


      1 #pragma once
      2 
      3 #include <inttypes.h>
      4 #include <stdbool.h>
      5 
      6 #include "nvim/arglist_defs.h"
      7 #include "nvim/ascii_defs.h"
      8 #include "nvim/event/loop.h"
      9 #include "nvim/ex_cmds_defs.h"
     10 #include "nvim/ex_eval_defs.h"
     11 #include "nvim/getchar_defs.h"
     12 #include "nvim/iconv_defs.h"
     13 #include "nvim/macros_defs.h"
     14 #include "nvim/menu_defs.h"
     15 #include "nvim/os/os_defs.h"
     16 #include "nvim/runtime_defs.h"
     17 #include "nvim/state_defs.h"
     18 #include "nvim/syntax_defs.h"
     19 #include "nvim/types_defs.h"
     20 
     21 #define IOSIZE         (1024 + 1)          // file I/O and sprintf buffer size
     22 
     23 #define MSG_BUF_LEN 480                 // length of buffer for small messages
     24 #define MSG_BUF_CLEN  (MSG_BUF_LEN / 6)  // cell length (worst case: utf-8
     25                                         // takes 6 bytes for one cell)
     26 
     27 // FILETYPE_FILE        used for file type detection
     28 // FTPLUGIN_FILE        used for loading filetype plugin files
     29 // INDENT_FILE          used for loading indent files
     30 // FTOFF_FILE           used for file type detection
     31 // FTPLUGOF_FILE        used for loading settings files
     32 // INDOFF_FILE          used for loading indent files
     33 
     34 #ifndef FILETYPE_FILE
     35 # define FILETYPE_FILE  "filetype.lua filetype.vim"
     36 #endif
     37 
     38 #ifndef FTPLUGIN_FILE
     39 # define FTPLUGIN_FILE  "ftplugin.vim"
     40 #endif
     41 
     42 #ifndef INDENT_FILE
     43 # define INDENT_FILE    "indent.vim"
     44 #endif
     45 
     46 #ifndef FTOFF_FILE
     47 # define FTOFF_FILE     "ftoff.vim"
     48 #endif
     49 
     50 #ifndef FTPLUGOF_FILE
     51 # define FTPLUGOF_FILE  "ftplugof.vim"
     52 #endif
     53 
     54 #ifndef INDOFF_FILE
     55 # define INDOFF_FILE    "indoff.vim"
     56 #endif
     57 
     58 #define DFLT_ERRORFILE  "errors.err"
     59 
     60 #ifndef SYS_VIMRC_FILE
     61 # define SYS_VIMRC_FILE "$VIM/sysinit.vim"
     62 #endif
     63 
     64 #ifndef DFLT_HELPFILE
     65 # define DFLT_HELPFILE  "$VIMRUNTIME/doc/help.txt"
     66 #endif
     67 
     68 #ifndef SYNTAX_FNAME
     69 # define SYNTAX_FNAME   "$VIMRUNTIME/syntax/%s.vim"
     70 #endif
     71 
     72 #ifndef EXRC_FILE
     73 # define EXRC_FILE      ".exrc"
     74 #endif
     75 
     76 #ifndef VIMRC_FILE
     77 # define VIMRC_FILE     ".nvimrc"
     78 #endif
     79 
     80 #ifndef VIMRC_LUA_FILE
     81 # define VIMRC_LUA_FILE ".nvim.lua"
     82 #endif
     83 
     84 EXTERN struct nvim_stats_s {
     85  int64_t fsync;
     86  int64_t redraw;
     87  int16_t log_skip;  // How many logs were tried and skipped before log_init.
     88 } g_stats INIT( = { 0, 0, 0 });
     89 
     90 // Values for "starting".
     91 #define NO_SCREEN       2       // no screen updating yet
     92 #define NO_BUFFERS      1       // not all buffers loaded yet
     93 //                      0          not starting anymore
     94 
     95 // Number of Rows and Columns in the screen.
     96 // Note: Use default_grid.rows and default_grid.cols to access items in
     97 // default_grid.chars[]. They may have different values when the screen
     98 // wasn't (re)allocated yet after setting Rows or Columns (e.g., when starting
     99 // up).
    100 #define DFLT_COLS       80              // default value for 'columns'
    101 #define DFLT_ROWS       24              // default value for 'lines'
    102 EXTERN int Rows INIT( = DFLT_ROWS);     // nr of rows in the screen
    103 EXTERN int Columns INIT( = DFLT_COLS);  // nr of columns in the screen
    104 
    105 // When vgetc() is called, it sets mod_mask to the set of modifiers that are
    106 // held down based on the MOD_MASK_* symbols that are read first.
    107 EXTERN int mod_mask INIT( = 0);  // current key modifiers
    108 
    109 // The value of "mod_mask" and the unmodified character in vgetc() after it has
    110 // called vgetorpeek() enough times.
    111 EXTERN int vgetc_mod_mask INIT( = 0);
    112 EXTERN int vgetc_char INIT( = 0);
    113 
    114 // Cmdline_row is the row where the command line starts, just below the
    115 // last window.
    116 // When the cmdline gets longer than the available space the screen gets
    117 // scrolled up. After a CTRL-D (show matches), after hitting ':' after
    118 // "hit return", and for the :global command, the command line is
    119 // temporarily moved.  The old position is restored with the next call to
    120 // update_screen().
    121 EXTERN int cmdline_row;
    122 
    123 EXTERN bool redraw_cmdline INIT( = false);          // cmdline must be redrawn
    124 EXTERN bool redraw_mode INIT( = false);             // mode must be redrawn
    125 EXTERN bool clear_cmdline INIT( = false);           // cmdline must be cleared
    126 EXTERN bool mode_displayed INIT( = false);          // mode is being displayed
    127 EXTERN int cmdline_star INIT( = 0);                 // cmdline is encrypted
    128 EXTERN bool redrawing_cmdline INIT( = false);       // cmdline is being redrawn
    129 EXTERN bool cmdline_was_last_drawn INIT( = false);  // cmdline was last drawn
    130 
    131 EXTERN bool exec_from_reg INIT( = false);         // executing register
    132 
    133 // When '$' is included in 'cpoptions' option set:
    134 // When a change command is given that deletes only part of a line, a dollar
    135 // is put at the end of the changed text. dollar_vcol is set to the virtual
    136 // column of this '$'.  -1 is used to indicate no $ is being displayed.
    137 EXTERN colnr_T dollar_vcol INIT( = -1);
    138 
    139 // Variables for Insert mode completion.
    140 
    141 EXTERN char *edit_submode INIT( = NULL);         // msg for CTRL-X submode
    142 EXTERN char *edit_submode_pre INIT( = NULL);     // prepended to edit_submode
    143 EXTERN char *edit_submode_extra INIT( = NULL);   // appended to edit_submode
    144 EXTERN hlf_T edit_submode_highl;                // highl. method for extra info
    145 
    146 // state for putting characters in the message area
    147 EXTERN bool cmdmsg_rl INIT( = false);  // cmdline is drawn right to left
    148 EXTERN int msg_col;
    149 EXTERN int msg_row;
    150 EXTERN int msg_scrolled;  ///< Number of screen lines that messages have scrolled.
    151 // when true don't set need_wait_return in msg_puts_attr()
    152 // when msg_scrolled is non-zero
    153 EXTERN bool msg_scrolled_ign INIT( = false);
    154 // Whether the screen is damaged due to scrolling. Sometimes msg_scrolled
    155 // is reset before the screen is redrawn, so we need to keep track of this.
    156 EXTERN bool msg_did_scroll INIT( = false);
    157 
    158 EXTERN char *keep_msg INIT( = NULL);         // msg to be shown after redraw
    159 EXTERN int keep_msg_hl_id INIT( = 0);        // highlight id for keep_msg
    160 EXTERN bool need_fileinfo INIT( = false);    // do fileinfo() after redraw
    161 EXTERN int msg_scroll INIT( = false);        // msg_start() will scroll
    162 EXTERN bool msg_didout INIT( = false);       // msg_outstr() was used in line
    163 EXTERN bool msg_didany INIT( = false);       // msg_outstr() was used at all
    164 EXTERN bool msg_nowait INIT( = false);       // don't wait for this msg
    165 EXTERN int emsg_off INIT( = 0);              // don't display errors for now,
    166                                             // unless 'debug' is set.
    167 EXTERN bool info_message INIT( = false);     // printing informative message
    168 EXTERN bool msg_hist_off INIT( = false);     // don't add messages to history
    169 EXTERN bool need_clr_eos INIT( = false);     // need to clear text before
    170                                             // displaying a message.
    171 EXTERN int emsg_skip INIT( = 0);             // don't display errors for
    172                                             // expression that is skipped
    173 EXTERN bool emsg_severe INIT( = false);      // use message of next of several
    174                                             //  emsg() calls for throw
    175 // used by assert_fails()
    176 EXTERN char *emsg_assert_fails_msg INIT( = NULL);
    177 EXTERN long emsg_assert_fails_lnum INIT( = 0);
    178 EXTERN char *emsg_assert_fails_context INIT( = NULL);
    179 
    180 EXTERN bool did_endif INIT( = false);        // just had ":endif"
    181 EXTERN int did_emsg;                        // incremented by emsg() when a
    182                                            // message is displayed or thrown
    183 EXTERN bool called_vim_beep;                // set if vim_beep() is called
    184 EXTERN bool did_emsg_syntax;                // did_emsg set because of a
    185                                            // syntax error
    186 EXTERN int called_emsg;                     // always incremented by emsg()
    187 EXTERN int ex_exitval INIT( = 0);            // exit value for ex mode
    188 EXTERN bool emsg_on_display INIT( = false);  // there is an error message
    189 EXTERN bool rc_did_emsg INIT( = false);      // vim_regcomp() called emsg()
    190 
    191 EXTERN int no_wait_return INIT( = 0);         // don't wait for return for now
    192 EXTERN bool need_wait_return INIT( = false);  // need to wait for return later
    193 EXTERN bool did_wait_return INIT( = false);   // wait_return() was used and
    194                                              // nothing written since then
    195 EXTERN bool need_maketitle INIT( = true);     // call maketitle() soon
    196 
    197 EXTERN bool quit_more INIT( = false);        // 'q' hit at "--more--" msg
    198 EXTERN int vgetc_busy INIT( = 0);            // when inside vgetc() then > 0
    199 
    200 EXTERN bool didset_vim INIT( = false);         // did set $VIM ourselves
    201 EXTERN bool didset_vimruntime INIT( = false);  // idem for $VIMRUNTIME
    202 
    203 /// Lines left before a "more" message.  Ex mode needs to be able to reset this
    204 /// after you type something.
    205 EXTERN int lines_left INIT( = -1);           // lines left for listing
    206 EXTERN bool msg_no_more INIT( = false);      // don't use more prompt, truncate
    207                                             // messages
    208 
    209 EXTERN int ex_nesting_level INIT( = 0);          // nesting level
    210 EXTERN int debug_break_level INIT( = -1);        // break below this level
    211 EXTERN bool debug_did_msg INIT( = false);        // did "debug mode" message
    212 EXTERN int debug_tick INIT( = 0);                // breakpoint change count
    213 EXTERN int debug_backtrace_level INIT( = 0);     // breakpoint backtrace level
    214 
    215 // Values for "do_profiling".
    216 #define PROF_NONE       0       ///< profiling not started
    217 #define PROF_YES        1       ///< profiling busy
    218 #define PROF_PAUSED     2       ///< profiling paused
    219 EXTERN int do_profiling INIT( = PROF_NONE);      ///< PROF_ values
    220 
    221 /// Exception currently being thrown.  Used to pass an exception to a different
    222 /// cstack.  Also used for discarding an exception before it is caught or made
    223 /// pending.  Only valid when did_throw is true.
    224 EXTERN except_T *current_exception;
    225 
    226 /// An exception is being thrown.  Reset when the exception is caught or as
    227 /// long as it is pending in a finally clause.
    228 EXTERN bool did_throw INIT( = false);
    229 
    230 /// Set when a throw that cannot be handled in do_cmdline() must be propagated
    231 /// to the cstack of the previously called do_cmdline().
    232 EXTERN bool need_rethrow INIT( = false);
    233 
    234 /// Set when a ":finish" or ":return" that cannot be handled in do_cmdline()
    235 /// must be propagated to the cstack of the previously called do_cmdline().
    236 EXTERN bool check_cstack INIT( = false);
    237 
    238 /// Number of nested try conditionals (across function calls and ":source"
    239 /// commands).
    240 EXTERN int trylevel INIT( = 0);
    241 
    242 /// When "force_abort" is true, always skip commands after an error message,
    243 /// even after the outermost ":endif", ":endwhile" or ":endfor" or for a
    244 /// function without the "abort" flag.  It is set to true when "trylevel" is
    245 /// non-zero (and ":silent!" was not used) or an exception is being thrown at
    246 /// the time an error is detected.  It is set to false when "trylevel" gets
    247 /// zero again and there was no error or interrupt or throw.
    248 EXTERN bool force_abort INIT( = false);
    249 
    250 /// "msg_list" points to a variable in the stack of do_cmdline() which keeps
    251 /// the list of arguments of several emsg() calls, one of which is to be
    252 /// converted to an error exception immediately after the failing command
    253 /// returns.  The message to be used for the exception value is pointed to by
    254 /// the "throw_msg" field of the first element in the list.  It is usually the
    255 /// same as the "msg" field of that element, but can be identical to the "msg"
    256 /// field of a later list element, when the "emsg_severe" flag was set when the
    257 /// emsg() call was made.
    258 EXTERN msglist_T **msg_list INIT( = NULL);
    259 
    260 /// When set, don't convert an error to an exception.  Used when displaying the
    261 /// interrupt message or reporting an exception that is still uncaught at the
    262 /// top level (which has already been discarded then).  Also used for the error
    263 /// message when no exception can be thrown.
    264 EXTERN bool suppress_errthrow INIT( = false);
    265 
    266 /// The stack of all caught and not finished exceptions.  The exception on the
    267 /// top of the stack is the one got by evaluation of v:exception.  The complete
    268 /// stack of all caught and pending exceptions is embedded in the various
    269 /// cstacks; the pending exceptions, however, are not on the caught stack.
    270 EXTERN except_T *caught_stack INIT( = NULL);
    271 
    272 ///
    273 /// Garbage collection can only take place when we are sure there are no Lists
    274 /// or Dictionaries being used internally.  This is flagged with
    275 /// "may_garbage_collect" when we are at the toplevel.
    276 /// "want_garbage_collect" is set by the garbagecollect() function, which means
    277 /// we do garbage collection before waiting for a char at the toplevel.
    278 /// "garbage_collect_at_exit" indicates garbagecollect(1) was called.
    279 ///
    280 EXTERN bool may_garbage_collect INIT( = false);
    281 EXTERN bool want_garbage_collect INIT( = false);
    282 EXTERN bool garbage_collect_at_exit INIT( = false);
    283 
    284 // Special values for current_SID.
    285 #define SID_MODELINE    (-1)      // when using a modeline
    286 #define SID_CMDARG      (-2)      // for "--cmd" argument
    287 #define SID_CARG        (-3)      // for "-c" argument
    288 #define SID_ENV         (-4)      // for sourcing environment variable
    289 #define SID_ERROR       (-5)      // option was reset because of an error
    290 #define SID_NONE        (-6)      // don't set scriptID
    291 #define SID_WINLAYOUT   (-7)      // changing window size
    292 #define SID_LUA         (-8)      // for Lua scripts/chunks
    293 #define SID_API_CLIENT  (-9)      // for API clients
    294 #define SID_STR         (-10)     // for sourcing a string with no script item
    295 
    296 // Script CTX being sourced or was sourced to define the current function.
    297 EXTERN sctx_T current_sctx INIT( = { 0, 0, 0, 0 });
    298 /// Last channel that invoked 'nvim_input` or got FocusGained.
    299 EXTERN uint64_t current_ui INIT( = 0);
    300 
    301 EXTERN bool did_source_packages INIT( = false);
    302 
    303 // Scope information for the code that indirectly triggered the current
    304 // provider function call
    305 EXTERN struct caller_scope {
    306  sctx_T script_ctx;
    307  estack_T es_entry;
    308  char *autocmd_fname, *autocmd_match;
    309  bool autocmd_fname_full;
    310  int autocmd_bufnr;
    311  void *funccalp;
    312 } provider_caller_scope;
    313 EXTERN int provider_call_nesting INIT( = 0);
    314 
    315 EXTERN int t_colors INIT( = 256);                // int value of T_CCO
    316 
    317 // Flags to indicate an additional string for highlight name completion.
    318 EXTERN int include_none INIT( = 0);     // when 1 include "None"
    319 EXTERN int include_default INIT( = 0);  // when 1 include "default"
    320 EXTERN int include_link INIT( = 0);     // when 2 include "link" and "clear"
    321 
    322 // When highlight_match is true, highlight a match, starting at the cursor
    323 // position.  Search_match_lines is the number of lines after the match (0 for
    324 // a match within one line), search_match_endcol the column number of the
    325 // character just after the match in the last line.
    326 EXTERN bool highlight_match INIT( = false);         // show search match pos
    327 EXTERN linenr_T search_match_lines;                // lines of matched string
    328 EXTERN colnr_T search_match_endcol;                // col nr of match end
    329 EXTERN linenr_T search_first_line INIT( = 0);       // for :{FIRST},{last}s/pat
    330 EXTERN linenr_T search_last_line INIT( = MAXLNUM);  // for :{first},{LAST}s/pat
    331 
    332 EXTERN bool no_smartcase INIT( = false);          // don't use 'smartcase' once
    333 
    334 EXTERN bool need_check_timestamps INIT( = false);  // need to check file
    335                                                   // timestamps asap
    336 EXTERN bool did_check_timestamps INIT( = false);   // did check timestamps
    337                                                   // recently
    338 EXTERN int no_check_timestamps INIT( = 0);         // Don't check timestamps
    339 
    340 // Mouse coordinates, set by handle_mouse_event()
    341 EXTERN int mouse_grid;
    342 EXTERN int mouse_row;
    343 EXTERN int mouse_col;
    344 EXTERN bool mouse_past_bottom INIT( = false);  // mouse below last line
    345 EXTERN bool mouse_past_eol INIT( = false);     // mouse right of line
    346 EXTERN int mouse_dragging INIT( = 0);          // extending Visual area with
    347                                               // mouse dragging
    348 
    349 // The root of the menu hierarchy.
    350 EXTERN vimmenu_T *root_menu INIT( = NULL);
    351 // While defining the system menu, sys_menu is true.  This avoids
    352 // overruling of menus that the user already defined.
    353 EXTERN bool sys_menu INIT( = false);
    354 
    355 // All windows are linked in a list. firstwin points to the first entry,
    356 // lastwin to the last entry (can be the same as firstwin) and curwin to the
    357 // currently active window.
    358 EXTERN win_T *firstwin;              // first window
    359 EXTERN win_T *lastwin;               // last window
    360 EXTERN win_T *prevwin INIT( = NULL);  // previous window (may equal curwin)
    361 #define ONE_WINDOW (firstwin == lastwin)
    362 #define FOR_ALL_FRAMES(frp, first_frame) \
    363  for ((frp) = first_frame; (frp) != NULL; (frp) = (frp)->fr_next)
    364 
    365 // When using this macro "break" only breaks out of the inner loop. Use "goto"
    366 // to break out of the tabpage loop.
    367 #define FOR_ALL_TAB_WINDOWS(tp, wp) \
    368  FOR_ALL_TABS(tp) \
    369  FOR_ALL_WINDOWS_IN_TAB(wp, tp)
    370 
    371 #define FOR_ALL_WINDOWS_IN_TAB(wp, tp) \
    372  for (win_T *wp = ((tp) == curtab) ? firstwin : (tp)->tp_firstwin; \
    373       wp != NULL; wp = wp->w_next)
    374 
    375 EXTERN win_T *curwin;        // currently active window
    376 
    377 // The window layout is kept in a tree of frames.  topframe points to the top
    378 // of the tree.
    379 EXTERN frame_T *topframe;      // top of the window frame tree
    380 
    381 // Tab pages are alternative topframes.  "first_tabpage" points to the first
    382 // one in the list, "curtab" is the current one. "lastused_tabpage" is the
    383 // last used one.
    384 EXTERN tabpage_T *first_tabpage;
    385 EXTERN tabpage_T *curtab;
    386 EXTERN tabpage_T *lastused_tabpage;
    387 EXTERN bool redraw_tabline INIT( = false);  // need to redraw tabline
    388 
    389 // Iterates over all tabs in the tab list
    390 #define FOR_ALL_TABS(tp) for (tabpage_T *(tp) = first_tabpage; (tp) != NULL; (tp) = (tp)->tp_next)
    391 
    392 // All buffers are linked in a list. 'firstbuf' points to the first entry,
    393 // 'lastbuf' to the last entry and 'curbuf' to the currently active buffer.
    394 EXTERN buf_T    *firstbuf INIT( = NULL);  // first buffer
    395 EXTERN buf_T *lastbuf INIT( = NULL);   // last buffer
    396 EXTERN buf_T *curbuf INIT( = NULL);    // currently active buffer
    397 
    398 // Iterates over all buffers in the buffer list.
    399 #define FOR_ALL_BUFFERS(buf) \
    400  for (buf_T *buf = firstbuf; buf != NULL; buf = buf->b_next)
    401 #define FOR_ALL_BUFFERS_BACKWARDS(buf) \
    402  for (buf_T *buf = lastbuf; buf != NULL; buf = buf->b_prev)
    403 
    404 // List of files being edited (global argument list).  curwin->w_alist points
    405 // to this when the window is using the global argument list.
    406 EXTERN alist_T global_alist;    // global argument list
    407 EXTERN int max_alist_id INIT( = 0);     ///< the previous argument list id
    408 EXTERN bool arg_had_last INIT( = false);     // accessed last file in
    409                                             // global_alist
    410 
    411 EXTERN int ru_col;              // column for ruler
    412 EXTERN int ru_wid;              // 'rulerfmt' width of ruler when non-zero
    413 EXTERN int sc_col;              // column for shown command
    414 
    415 // When starting or exiting some things are done differently (e.g. screen
    416 // updating).
    417 
    418 // First NO_SCREEN, then NO_BUFFERS, then 0 when startup finished.
    419 EXTERN int starting INIT( = NO_SCREEN);
    420 // Planning to exit. Might keep running if there is a changed buffer.
    421 EXTERN bool exiting INIT( = false);
    422 // Planning to restart.
    423 EXTERN bool restarting INIT( = false);
    424 // Internal value of v:dying
    425 EXTERN int v_dying INIT( = 0);
    426 // Is stdin a terminal?
    427 EXTERN bool stdin_isatty INIT( = true);
    428 // Is stdout a terminal?
    429 EXTERN bool stdout_isatty INIT( = true);
    430 // Is stderr a terminal?
    431 EXTERN bool stderr_isatty INIT( = true);
    432 
    433 /// Filedesc set by embedder for reading first buffer like `cmd | nvim -`.
    434 EXTERN int stdin_fd INIT( = -1);
    435 
    436 // true when doing full-screen output, otherwise only writing some messages.
    437 EXTERN bool full_screen INIT( = false);
    438 
    439 /// Non-zero when only "safe" commands are allowed
    440 EXTERN int secure INIT( = 0);
    441 
    442 /// Non-zero when changing text and jumping to another window or editing another buffer is not
    443 /// allowed.
    444 EXTERN int textlock INIT( = 0);
    445 
    446 /// Non-zero when no buffer name can be changed, no buffer can be deleted and
    447 /// current directory can't be changed. Used for SwapExists et al.
    448 EXTERN int allbuf_lock INIT( = 0);
    449 
    450 /// Non-zero when evaluating an expression in a "sandbox".  Several things are
    451 /// not allowed then.
    452 EXTERN int sandbox INIT( = 0);
    453 
    454 /// Batch-mode: "-es", "-Es", "-l" commandline argument was given.
    455 EXTERN bool silent_mode INIT( = false);
    456 
    457 /// Start position of active Visual selection.
    458 EXTERN pos_T VIsual;
    459 /// Whether Visual mode is active.
    460 EXTERN bool VIsual_active INIT( = false);
    461 /// Whether Select mode is active.
    462 EXTERN bool VIsual_select INIT( = false);
    463 /// Register name for Select mode
    464 EXTERN int VIsual_select_reg INIT( = 0);
    465 /// Whether incremented cursor during exclusive selection
    466 EXTERN bool VIsual_select_exclu_adj INIT( = false);
    467 /// Restart Select mode when next cmd finished
    468 EXTERN int restart_VIsual_select INIT( = 0);
    469 /// Whether to restart the selection after a Select-mode mapping or menu.
    470 EXTERN int VIsual_reselect;
    471 /// Type of Visual mode.
    472 EXTERN int VIsual_mode INIT( = 'v');
    473 /// true when redoing Visual.
    474 EXTERN bool redo_VIsual_busy INIT( = false);
    475 
    476 // The Visual area is remembered for reselection.
    477 EXTERN int resel_VIsual_mode INIT( = NUL);       // 'v', 'V', or Ctrl-V
    478 EXTERN linenr_T resel_VIsual_line_count;        // number of lines
    479 EXTERN colnr_T resel_VIsual_vcol;               // nr of cols or end col
    480 
    481 /// When pasting text with the middle mouse button in visual mode with
    482 /// restart_edit set, remember where it started so we can set Insstart.
    483 EXTERN pos_T where_paste_started;
    484 
    485 // This flag is used to make auto-indent work right on lines where only a
    486 // <RETURN> or <ESC> is typed. It is set when an auto-indent is done, and
    487 // reset when any other editing is done on the line. If an <ESC> or <RETURN>
    488 // is received, and did_ai is true, the line is truncated.
    489 EXTERN bool did_ai INIT( = false);
    490 
    491 // Column of first char after autoindent.  0 when no autoindent done.  Used
    492 // when 'backspace' is 0, to avoid backspacing over autoindent.
    493 EXTERN colnr_T ai_col INIT( = 0);
    494 
    495 // This is a character which will end a start-middle-end comment when typed as
    496 // the first character on a new line.  It is taken from the last character of
    497 // the "end" comment leader when the COM_AUTO_END flag is given for that
    498 // comment end in 'comments'.  It is only valid when did_ai is true.
    499 EXTERN int end_comment_pending INIT( = NUL);
    500 
    501 // This flag is set after a ":syncbind" to let the check_scrollbind() function
    502 // know that it should not attempt to perform scrollbinding due to the scroll
    503 // that was a result of the ":syncbind." (Otherwise, check_scrollbind() will
    504 // undo some of the work done by ":syncbind.")  -ralston
    505 EXTERN bool did_syncbind INIT( = false);
    506 
    507 // This flag is set when a smart indent has been performed. When the next typed
    508 // character is a '{' the inserted tab will be deleted again.
    509 EXTERN bool did_si INIT( = false);
    510 
    511 // This flag is set after an auto indent. If the next typed character is a '}'
    512 // one indent will be removed.
    513 EXTERN bool can_si INIT( = false);
    514 
    515 // This flag is set after an "O" command. If the next typed character is a '{'
    516 // one indent will be removed.
    517 EXTERN bool can_si_back INIT( = false);
    518 
    519 EXTERN int old_indent INIT( = 0);  ///< for ^^D command in insert mode
    520 
    521 // w_cursor before formatting text.
    522 EXTERN pos_T saved_cursor INIT( = { 0, 0, 0 });
    523 
    524 // Stuff for insert mode.
    525 EXTERN pos_T Insstart;                  // This is where the latest
    526                                        // insert/append mode started.
    527 
    528 // This is where the latest insert/append mode started. In contrast to
    529 // Insstart, this won't be reset by certain keys and is needed for
    530 // op_insert(), to detect correctly where inserting by the user started.
    531 EXTERN pos_T Insstart_orig;
    532 
    533 // Stuff for MODE_VREPLACE state.
    534 EXTERN linenr_T orig_line_count INIT( = 0);       // Line count when "gR" started
    535 EXTERN int vr_lines_changed INIT( = 0);      // #Lines changed by "gR" so far
    536 
    537 // increase around internal delete/replace
    538 EXTERN int inhibit_delete_count INIT( = 0);
    539 
    540 // These flags are set based upon 'fileencoding'.
    541 // The characters are internally stored as UTF-8
    542 // to avoid trouble with NUL bytes.
    543 #define DBCS_JPN       932     // japan
    544 #define DBCS_JPNU      9932    // euc-jp
    545 #define DBCS_KOR       949     // korea
    546 #define DBCS_KORU      9949    // euc-kr
    547 #define DBCS_CHS       936     // chinese
    548 #define DBCS_CHSU      9936    // euc-cn
    549 #define DBCS_CHT       950     // taiwan
    550 #define DBCS_CHTU      9950    // euc-tw
    551 #define DBCS_2BYTE     1       // 2byte-
    552 #define DBCS_DEBUG     (-1)
    553 
    554 /// Encoding used when 'fencs' is set to "default"
    555 EXTERN char *fenc_default INIT( = NULL);
    556 
    557 /// "State" is the main state of Vim.
    558 /// There are other variables that modify the state:
    559 ///    Visual_mode:    When State is MODE_NORMAL or MODE_INSERT.
    560 ///    finish_op  :    When State is MODE_NORMAL, after typing the operator and
    561 ///                    before typing the motion command.
    562 ///    motion_force:   Last motion_force from do_pending_operator()
    563 ///    debug_mode:     Debug mode
    564 EXTERN int State INIT( = MODE_NORMAL);
    565 
    566 EXTERN bool debug_mode INIT( = false);
    567 EXTERN bool finish_op INIT( = false);    // true while an operator is pending
    568 EXTERN int opcount INIT( = 0);           // count for pending operator
    569 EXTERN int motion_force INIT( = 0);      // motion force for pending operator
    570 
    571 // Ex Mode (Q) state
    572 EXTERN bool exmode_active INIT( = false);  // true if Ex mode is active
    573 
    574 /// Flag set when normal_check() should return 0 when entering Ex mode.
    575 EXTERN bool pending_exmode_active INIT( = false);
    576 
    577 EXTERN bool ex_no_reprint INIT( = false);   // No need to print after z or p.
    578 
    579 // 'inccommand' command preview state
    580 EXTERN bool cmdpreview INIT( = false);
    581 
    582 EXTERN int reg_recording INIT( = 0);     // register for recording  or zero
    583 EXTERN int reg_executing INIT( = 0);     // register being executed or zero
    584 // Flag set when peeking a character and found the end of executed register
    585 EXTERN bool pending_end_reg_executing INIT( = false);
    586 EXTERN int reg_recorded INIT( = 0);      // last recorded register or zero
    587 
    588 EXTERN int no_mapping INIT( = 0);        // currently no mapping allowed
    589 EXTERN int no_zero_mapping INIT( = 0);   // mapping zero not allowed
    590 EXTERN int allow_keys INIT( = 0);        // allow key codes when no_mapping is set
    591 EXTERN int no_u_sync INIT( = 0);         // Don't call u_sync()
    592 EXTERN int u_sync_once INIT( = 0);       // Call u_sync() once when evaluating
    593                                         // an expression.
    594 
    595 EXTERN bool force_restart_edit INIT( = false);  // force restart_edit after
    596                                                // ex_normal returns
    597 EXTERN int restart_edit INIT( = 0);      // call edit when next cmd finished
    598 EXTERN bool arrow_used;                  // Normally false, set to true after
    599                                         // hitting cursor key in insert mode.
    600                                         // Used by vgetorpeek() to decide when
    601                                         // to call u_sync()
    602 EXTERN bool ins_at_eol INIT( = false);   // put cursor after eol when
    603                                         // restarting edit after CTRL-O
    604 
    605 EXTERN bool no_abbr INIT( = true);       // true when no abbreviations loaded
    606 
    607 EXTERN int mapped_ctrl_c INIT( = 0);  // Modes where CTRL-C is mapped.
    608 EXTERN bool ctrl_c_interrupts INIT( = true);  // CTRL-C sets got_int
    609 
    610 EXTERN cmdmod_T cmdmod;                 // Ex command modifiers
    611 
    612 EXTERN int msg_silent INIT( = 0);         // don't print messages
    613 EXTERN int emsg_silent INIT( = 0);        // don't print error messages
    614 EXTERN bool emsg_noredir INIT( = false);  // don't redirect error messages
    615 EXTERN bool cmd_silent INIT( = false);    // don't echo the command line
    616 
    617 EXTERN bool in_assert_fails INIT( = false);  // assert_fails() active
    618 
    619 // Values for swap_exists_action: what to do when swap file already exists
    620 #define SEA_NONE        0       // don't use dialog
    621 #define SEA_DIALOG      1       // use dialog when possible
    622 #define SEA_QUIT        2       // quit editing the file
    623 #define SEA_RECOVER     3       // recover the file
    624 #define SEA_READONLY    4       // no dialog, mark buffer as read-only
    625 
    626 EXTERN int swap_exists_action INIT( = SEA_NONE);  ///< For dialog when swap file already exists.
    627 EXTERN bool swap_exists_did_quit INIT( = false);  ///< Selected "quit" at the dialog.
    628 
    629 EXTERN char IObuff[IOSIZE];                 ///< Buffer for sprintf, I/O, etc.
    630 EXTERN char NameBuff[MAXPATHL];             ///< Buffer for expanding file names
    631 EXTERN char msg_buf[MSG_BUF_LEN];           ///< Small buffer for messages
    632 EXTERN char os_buf[                         ///< Buffer for the os/ layer
    633 #if MAXPATHL > IOSIZE
    634                                            MAXPATHL
    635 #else
    636                                            IOSIZE
    637 #endif
    638 ];
    639 
    640 // When non-zero, postpone redrawing.
    641 EXTERN int RedrawingDisabled INIT( = 0);
    642 
    643 EXTERN bool readonlymode INIT( = false);      // Set to true for "view"
    644 EXTERN bool recoverymode INIT( = false);      // Set to true for "-r" option
    645 
    646 // typeahead buffer
    647 EXTERN typebuf_T typebuf INIT( = { NULL, NULL, 0, 0, 0, 0, 0, 0, 0 });
    648 
    649 /// Flag used to indicate that vgetorpeek() returned a char like Esc when the
    650 /// :normal argument was exhausted.
    651 EXTERN bool typebuf_was_empty INIT( = false);
    652 
    653 EXTERN int ex_normal_busy INIT( = 0);      // recursiveness of ex_normal()
    654 EXTERN int expr_map_lock INIT( = 0);       // running expr mapping, prevent use of ex_normal() and text changes
    655 EXTERN bool ignore_script INIT( = false);  // ignore script input
    656 EXTERN bool stop_insert_mode;              // for ":stopinsert"
    657 EXTERN bool KeyTyped;                      // true if user typed current char
    658 EXTERN int KeyStuffed;                     // true if current char from stuffbuf
    659 EXTERN int maptick INIT( = 0);             // tick for each non-mapped char
    660 
    661 EXTERN int must_redraw INIT( = 0);           // type of redraw necessary
    662 EXTERN bool skip_redraw INIT( = false);      // skip redraw once
    663 EXTERN bool do_redraw INIT( = false);        // extra redraw once
    664 EXTERN bool must_redraw_pum INIT( = false);  // redraw pum. NB: must_redraw
    665                                             // should also be set.
    666 
    667 EXTERN bool need_highlight_changed INIT( = true);
    668 
    669 EXTERN FILE *scriptout INIT( = NULL);  ///< Write input to this file ("nvim -w").
    670 
    671 // Note that even when handling SIGINT, volatile is not necessary because the
    672 // callback is not called directly from the signal handlers.
    673 EXTERN bool got_int INIT( = false);          // set to true when interrupt signal occurred
    674 EXTERN bool bangredo INIT( = false);         // set to true with ! command
    675 EXTERN int searchcmdlen;                    // length of previous search cmd
    676 EXTERN int reg_do_extmatch INIT( = 0);       // Used when compiling regexp:
    677                                             // REX_SET to allow \z\(...\),
    678                                             // REX_USE to allow \z\1 et al.
    679 // Used by vim_regexec(): strings for \z\1...\z\9
    680 EXTERN reg_extmatch_T *re_extmatch_in INIT( = NULL);
    681 // Set by vim_regexec() to store \z\(...\) matches
    682 EXTERN reg_extmatch_T *re_extmatch_out INIT( = NULL);
    683 
    684 EXTERN bool did_outofmem_msg INIT( = false);  ///< set after out of memory msg
    685 EXTERN bool did_swapwrite_msg INIT( = false);  ///< set after swap write error msg
    686 EXTERN int global_busy INIT( = 0);           ///< set when :global is executing
    687 EXTERN bool listcmd_busy INIT( = false);     ///< set when :argdo, :windo or :bufdo is executing
    688 EXTERN bool need_start_insertmode INIT( = false);  ///< start insert mode soon
    689 
    690 #define MODE_MAX_LENGTH 4       // max mode length returned in get_mode(),
    691                                // including the terminating NUL
    692 
    693 EXTERN char last_mode[MODE_MAX_LENGTH] INIT( = "n");
    694 EXTERN char *last_cmdline INIT( = NULL);        // last command line (for ":)
    695 EXTERN char *repeat_cmdline INIT( = NULL);      // command line for "."
    696 EXTERN char *new_last_cmdline INIT( = NULL);    // new value for last_cmdline
    697 
    698 EXTERN int postponed_split INIT( = 0);        // for CTRL-W CTRL-] command
    699 EXTERN int postponed_split_flags INIT( = 0);  // args for win_split()
    700 EXTERN int postponed_split_tab INIT( = 0);    // cmdmod.cmod_tab
    701 EXTERN int g_do_tagpreview INIT( = 0);  // for tag preview commands:
    702                                        // height of preview window
    703 EXTERN bool g_tag_at_cursor INIT( = false);  // whether the tag command comes
    704                                             // from the command line (0) or was
    705                                             // invoked as a normal command (1)
    706 
    707 EXTERN int replace_offset INIT( = 0);        // offset for replace_push()
    708 
    709 EXTERN char *escape_chars INIT( = " \t\\\"|");  // need backslash in cmd line
    710 
    711 EXTERN bool keep_help_flag INIT( = false);  // doing :ta from help file
    712 
    713 EXTERN bool redir_off INIT( = false);        // no redirection for a moment
    714 EXTERN FILE *redir_fd INIT( = NULL);         // message redirection file
    715 EXTERN int redir_reg INIT( = 0);             // message redirection register
    716 EXTERN bool redir_vname INIT( = false);      // message redirection variable
    717 EXTERN garray_T *capture_ga INIT( = NULL);   // captured output for execute()
    718 
    719 EXTERN uint8_t langmap_mapchar[256];     // mapping for language keys
    720 
    721 EXTERN int save_p_ls INIT( = -1);        // Save 'laststatus' setting
    722 EXTERN int save_p_wmh INIT( = -1);       // Save 'winminheight' setting
    723 EXTERN int wild_menu_showing INIT( = 0);
    724 enum {
    725  WM_SHOWN = 1,     ///< wildmenu showing
    726  WM_SCROLLED = 2,  ///< wildmenu showing with scroll
    727 };
    728 
    729 // When a window has a local directory, the absolute path of the global
    730 // current directory is stored here (in allocated memory).  If the current
    731 // directory is not a local directory, globaldir is NULL.
    732 EXTERN char *globaldir INIT( = NULL);
    733 
    734 EXTERN char *last_chdir_reason INIT( = NULL);
    735 
    736 // Whether 'keymodel' contains "stopsel" and "startsel".
    737 EXTERN bool km_stopsel INIT( = false);
    738 EXTERN bool km_startsel INIT( = false);
    739 
    740 EXTERN int cmdwin_type INIT( = 0);    ///< type of cmdline window or 0
    741 EXTERN int cmdwin_result INIT( = 0);  ///< result of cmdline window or 0
    742 EXTERN int cmdwin_level INIT( = 0);   ///< cmdline recursion level
    743 EXTERN buf_T *cmdwin_buf INIT( = NULL);  ///< buffer of cmdline window or NULL
    744 EXTERN win_T *cmdwin_win INIT( = NULL);  ///< window of cmdline window or NULL
    745 EXTERN win_T *cmdwin_old_curwin INIT( = NULL);  ///< curwin before opening cmdline window or NULL
    746 EXTERN win_T *cmdline_win INIT( = NULL);  ///< window in use by ext_cmdline
    747 
    748 EXTERN char no_lines_msg[] INIT( = N_("--No lines in buffer--"));
    749 
    750 // When ":global" is used to number of substitutions and changed lines is
    751 // accumulated until it's finished.
    752 // Also used for ":spellrepall".
    753 EXTERN int sub_nsubs;        // total number of substitutions
    754 EXTERN linenr_T sub_nlines;  // total number of lines changed
    755 
    756 // table to store parsed 'wildmode'
    757 EXTERN uint8_t wim_flags[4];
    758 
    759 // whether titlestring and iconstring contains statusline syntax
    760 #define STL_IN_ICON    1
    761 #define STL_IN_TITLE   2
    762 EXTERN int stl_syntax INIT( = 0);
    763 
    764 // don't use 'hlsearch' temporarily
    765 EXTERN bool no_hlsearch INIT( = false);
    766 
    767 EXTERN bool typebuf_was_filled INIT( = false);     // received text from client
    768                                                   // or from feedkeys()
    769 
    770 #ifdef BACKSLASH_IN_FILENAME
    771 EXTERN char psepc INIT( = '\\');            // normal path separator character
    772 EXTERN char psepcN INIT( = '/');            // abnormal path separator character
    773 EXTERN char pseps[2] INIT( = { '\\', 0 });  // normal path separator string
    774 #endif
    775 
    776 // Set to kTrue when an operator is being executed with virtual editing
    777 // kNone when no operator is being executed, kFalse otherwise.
    778 EXTERN TriState virtual_op INIT( = kNone);
    779 
    780 // Display tick, incremented for each call to update_screen()
    781 EXTERN disptick_T display_tick INIT( = 0);
    782 
    783 // Line in which spell checking wasn't highlighted because it touched the
    784 // cursor position in Insert mode.
    785 EXTERN linenr_T spell_redraw_lnum INIT( = 0);
    786 
    787 EXTERN FILE *time_fd INIT( = NULL);  // Where to write --startuptime report.
    788 
    789 // Some compilers warn for not using a return value, but in some situations we
    790 // can't do anything useful with the value.  Assign to this variable to avoid
    791 // the warning.
    792 EXTERN int vim_ignored;
    793 
    794 // stdio is an RPC channel (--embed).
    795 EXTERN bool embedded_mode INIT( = false);
    796 // Do not start UI (--headless, -l) nor read/write to stdio (unless embedding).
    797 EXTERN bool headless_mode INIT( = false);
    798 
    799 /// Only filled for Win32.
    800 EXTERN char windowsVersion[20] INIT( = { 0 });
    801 
    802 /// While executing a regexp and set to OPTION_MAGIC_ON or OPTION_MAGIC_OFF this
    803 /// overrules p_magic.  Otherwise set to OPTION_MAGIC_NOT_SET.
    804 EXTERN optmagic_T magic_overruled INIT( = OPTION_MAGIC_NOT_SET);
    805 
    806 /// Skip win_fix_cursor() call for 'splitkeep' when cmdwin is closed.
    807 EXTERN bool skip_win_fix_cursor INIT( = false);
    808 /// Skip win_fix_scroll() call for 'splitkeep' when closing tab page.
    809 EXTERN bool skip_win_fix_scroll INIT( = false);
    810 /// Skip update_topline() call while executing win_fix_scroll().
    811 EXTERN bool skip_update_topline INIT( = false);