aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/globals.h
blob: a473180349921084c5c74b81129ef3800409459e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
#pragma once

#include <inttypes.h>
#include <stdbool.h>

#include "nvim/arglist_defs.h"
#include "nvim/ascii_defs.h"
#include "nvim/event/loop.h"
#include "nvim/ex_cmds_defs.h"
#include "nvim/ex_eval_defs.h"
#include "nvim/getchar_defs.h"
#include "nvim/iconv_defs.h"
#include "nvim/macros_defs.h"
#include "nvim/menu_defs.h"
#include "nvim/os/os_defs.h"
#include "nvim/runtime_defs.h"
#include "nvim/state_defs.h"
#include "nvim/syntax_defs.h"
#include "nvim/types_defs.h"

#define IOSIZE         (1024 + 1)          // file I/O and sprintf buffer size

#define MSG_BUF_LEN 480                 // length of buffer for small messages
#define MSG_BUF_CLEN  (MSG_BUF_LEN / 6)  // cell length (worst case: utf-8
                                         // takes 6 bytes for one cell)

// FILETYPE_FILE        used for file type detection
// FTPLUGIN_FILE        used for loading filetype plugin files
// INDENT_FILE          used for loading indent files
// FTOFF_FILE           used for file type detection
// FTPLUGOF_FILE        used for loading settings files
// INDOFF_FILE          used for loading indent files

#ifndef FILETYPE_FILE
# define FILETYPE_FILE  "filetype.lua filetype.vim"
#endif

#ifndef FTPLUGIN_FILE
# define FTPLUGIN_FILE  "ftplugin.vim"
#endif

#ifndef INDENT_FILE
# define INDENT_FILE    "indent.vim"
#endif

#ifndef FTOFF_FILE
# define FTOFF_FILE     "ftoff.vim"
#endif

#ifndef FTPLUGOF_FILE
# define FTPLUGOF_FILE  "ftplugof.vim"
#endif

#ifndef INDOFF_FILE
# define INDOFF_FILE    "indoff.vim"
#endif

#define DFLT_ERRORFILE  "errors.err"

#ifndef SYS_VIMRC_FILE
# define SYS_VIMRC_FILE "$VIM/sysinit.vim"
#endif

#ifndef DFLT_HELPFILE
# define DFLT_HELPFILE  "$VIMRUNTIME/doc/help.txt"
#endif

#ifndef SYNTAX_FNAME
# define SYNTAX_FNAME   "$VIMRUNTIME/syntax/%s.vim"
#endif

#ifndef EXRC_FILE
# define EXRC_FILE      ".exrc"
#endif

#ifndef VIMRC_FILE
# define VIMRC_FILE     ".nvimrc"
#endif

#ifndef VIMRC_LUA_FILE
# define VIMRC_LUA_FILE ".nvim.lua"
#endif

EXTERN struct nvim_stats_s {
  int64_t fsync;
  int64_t redraw;
  int16_t log_skip;  // How many logs were tried and skipped before log_init.
} g_stats INIT( = { 0, 0, 0 });

// Values for "starting".
#define NO_SCREEN       2       // no screen updating yet
#define NO_BUFFERS      1       // not all buffers loaded yet
//                      0          not starting anymore

// Number of Rows and Columns in the screen.
// Note: Use default_grid.rows and default_grid.cols to access items in
// default_grid.chars[]. They may have different values when the screen
// wasn't (re)allocated yet after setting Rows or Columns (e.g., when starting
// up).
#define DFLT_COLS       80              // default value for 'columns'
#define DFLT_ROWS       24              // default value for 'lines'
EXTERN int Rows INIT( = DFLT_ROWS);     // nr of rows in the screen
EXTERN int Columns INIT( = DFLT_COLS);  // nr of columns in the screen

// When vgetc() is called, it sets mod_mask to the set of modifiers that are
// held down based on the MOD_MASK_* symbols that are read first.
EXTERN int mod_mask INIT( = 0);  // current key modifiers

// The value of "mod_mask" and the unmodified character in vgetc() after it has
// called vgetorpeek() enough times.
EXTERN int vgetc_mod_mask INIT( = 0);
EXTERN int vgetc_char INIT( = 0);

// Cmdline_row is the row where the command line starts, just below the
// last window.
// When the cmdline gets longer than the available space the screen gets
// scrolled up. After a CTRL-D (show matches), after hitting ':' after
// "hit return", and for the :global command, the command line is
// temporarily moved.  The old position is restored with the next call to
// update_screen().
EXTERN int cmdline_row;

EXTERN bool redraw_cmdline INIT( = false);          // cmdline must be redrawn
EXTERN bool redraw_mode INIT( = false);             // mode must be redrawn
EXTERN bool clear_cmdline INIT( = false);           // cmdline must be cleared
EXTERN bool mode_displayed INIT( = false);          // mode is being displayed
EXTERN int cmdline_star INIT( = 0);                 // cmdline is encrypted
EXTERN bool redrawing_cmdline INIT( = false);       // cmdline is being redrawn
EXTERN bool cmdline_was_last_drawn INIT( = false);  // cmdline was last drawn

EXTERN bool exec_from_reg INIT( = false);         // executing register

// When '$' is included in 'cpoptions' option set:
// When a change command is given that deletes only part of a line, a dollar
// is put at the end of the changed text. dollar_vcol is set to the virtual
// column of this '$'.  -1 is used to indicate no $ is being displayed.
EXTERN colnr_T dollar_vcol INIT( = -1);

// Variables for Insert mode completion.

EXTERN char *edit_submode INIT( = NULL);         // msg for CTRL-X submode
EXTERN char *edit_submode_pre INIT( = NULL);     // prepended to edit_submode
EXTERN char *edit_submode_extra INIT( = NULL);   // appended to edit_submode
EXTERN hlf_T edit_submode_highl;                // highl. method for extra info

// state for putting characters in the message area
EXTERN bool cmdmsg_rl INIT( = false);  // cmdline is drawn right to left
EXTERN int msg_col;
EXTERN int msg_row;
EXTERN int msg_scrolled;  ///< Number of screen lines that messages have scrolled.
// when true don't set need_wait_return in msg_puts_attr()
// when msg_scrolled is non-zero
EXTERN bool msg_scrolled_ign INIT( = false);
// Whether the screen is damaged due to scrolling. Sometimes msg_scrolled
// is reset before the screen is redrawn, so we need to keep track of this.
EXTERN bool msg_did_scroll INIT( = false);

EXTERN char *keep_msg INIT( = NULL);         // msg to be shown after redraw
EXTERN int keep_msg_hl_id INIT( = 0);        // highlight id for keep_msg
EXTERN bool need_fileinfo INIT( = false);    // do fileinfo() after redraw
EXTERN int msg_scroll INIT( = false);        // msg_start() will scroll
EXTERN bool msg_didout INIT( = false);       // msg_outstr() was used in line
EXTERN bool msg_didany INIT( = false);       // msg_outstr() was used at all
EXTERN bool msg_nowait INIT( = false);       // don't wait for this msg
EXTERN int emsg_off INIT( = 0);              // don't display errors for now,
                                             // unless 'debug' is set.
EXTERN bool info_message INIT( = false);     // printing informative message
EXTERN bool msg_hist_off INIT( = false);     // don't add messages to history
EXTERN bool need_clr_eos INIT( = false);     // need to clear text before
                                             // displaying a message.
EXTERN int emsg_skip INIT( = 0);             // don't display errors for
                                             // expression that is skipped
EXTERN bool emsg_severe INIT( = false);      // use message of next of several
                                             //  emsg() calls for throw
// used by assert_fails()
EXTERN char *emsg_assert_fails_msg INIT( = NULL);
EXTERN long emsg_assert_fails_lnum INIT( = 0);
EXTERN char *emsg_assert_fails_context INIT( = NULL);

EXTERN bool did_endif INIT( = false);        // just had ":endif"
EXTERN dict_T vimvardict;                   // Dict with v: variables
EXTERN dict_T globvardict;                  // Dict with g: variables
/// g: value
#define globvarht globvardict.dv_hashtab
EXTERN int did_emsg;                        // incremented by emsg() when a
                                            // message is displayed or thrown
EXTERN bool called_vim_beep;                // set if vim_beep() is called
EXTERN bool did_emsg_syntax;                // did_emsg set because of a
                                            // syntax error
EXTERN int called_emsg;                     // always incremented by emsg()
EXTERN int ex_exitval INIT( = 0);            // exit value for ex mode
EXTERN bool emsg_on_display INIT( = false);  // there is an error message
EXTERN bool rc_did_emsg INIT( = false);      // vim_regcomp() called emsg()

EXTERN int no_wait_return INIT( = 0);         // don't wait for return for now
EXTERN bool need_wait_return INIT( = false);  // need to wait for return later
EXTERN bool did_wait_return INIT( = false);   // wait_return() was used and
                                              // nothing written since then
EXTERN bool need_maketitle INIT( = true);     // call maketitle() soon

EXTERN bool quit_more INIT( = false);        // 'q' hit at "--more--" msg
EXTERN int vgetc_busy INIT( = 0);            // when inside vgetc() then > 0

EXTERN bool didset_vim INIT( = false);         // did set $VIM ourselves
EXTERN bool didset_vimruntime INIT( = false);  // idem for $VIMRUNTIME

/// Lines left before a "more" message.  Ex mode needs to be able to reset this
/// after you type something.
EXTERN int lines_left INIT( = -1);           // lines left for listing
EXTERN bool msg_no_more INIT( = false);      // don't use more prompt, truncate
                                             // messages

EXTERN int ex_nesting_level INIT( = 0);          // nesting level
EXTERN int debug_break_level INIT( = -1);        // break below this level
EXTERN bool debug_did_msg INIT( = false);        // did "debug mode" message
EXTERN int debug_tick INIT( = 0);                // breakpoint change count
EXTERN int debug_backtrace_level INIT( = 0);     // breakpoint backtrace level

// Values for "do_profiling".
#define PROF_NONE       0       ///< profiling not started
#define PROF_YES        1       ///< profiling busy
#define PROF_PAUSED     2       ///< profiling paused
EXTERN int do_profiling INIT( = PROF_NONE);      ///< PROF_ values

/// Exception currently being thrown.  Used to pass an exception to a different
/// cstack.  Also used for discarding an exception before it is caught or made
/// pending.  Only valid when did_throw is true.
EXTERN except_T *current_exception;

/// An exception is being thrown.  Reset when the exception is caught or as
/// long as it is pending in a finally clause.
EXTERN bool did_throw INIT( = false);

/// Set when a throw that cannot be handled in do_cmdline() must be propagated
/// to the cstack of the previously called do_cmdline().
EXTERN bool need_rethrow INIT( = false);

/// Set when a ":finish" or ":return" that cannot be handled in do_cmdline()
/// must be propagated to the cstack of the previously called do_cmdline().
EXTERN bool check_cstack INIT( = false);

/// Number of nested try conditionals (across function calls and ":source"
/// commands).
EXTERN int trylevel INIT( = 0);

/// When "force_abort" is true, always skip commands after an error message,
/// even after the outermost ":endif", ":endwhile" or ":endfor" or for a
/// function without the "abort" flag.  It is set to true when "trylevel" is
/// non-zero (and ":silent!" was not used) or an exception is being thrown at
/// the time an error is detected.  It is set to false when "trylevel" gets
/// zero again and there was no error or interrupt or throw.
EXTERN bool force_abort INIT( = false);

/// "msg_list" points to a variable in the stack of do_cmdline() which keeps
/// the list of arguments of several emsg() calls, one of which is to be
/// converted to an error exception immediately after the failing command
/// returns.  The message to be used for the exception value is pointed to by
/// the "throw_msg" field of the first element in the list.  It is usually the
/// same as the "msg" field of that element, but can be identical to the "msg"
/// field of a later list element, when the "emsg_severe" flag was set when the
/// emsg() call was made.
EXTERN msglist_T **msg_list INIT( = NULL);

/// When set, don't convert an error to an exception.  Used when displaying the
/// interrupt message or reporting an exception that is still uncaught at the
/// top level (which has already been discarded then).  Also used for the error
/// message when no exception can be thrown.
EXTERN bool suppress_errthrow INIT( = false);

/// The stack of all caught and not finished exceptions.  The exception on the
/// top of the stack is the one got by evaluation of v:exception.  The complete
/// stack of all caught and pending exceptions is embedded in the various
/// cstacks; the pending exceptions, however, are not on the caught stack.
EXTERN except_T *caught_stack INIT( = NULL);

///
/// Garbage collection can only take place when we are sure there are no Lists
/// or Dictionaries being used internally.  This is flagged with
/// "may_garbage_collect" when we are at the toplevel.
/// "want_garbage_collect" is set by the garbagecollect() function, which means
/// we do garbage collection before waiting for a char at the toplevel.
/// "garbage_collect_at_exit" indicates garbagecollect(1) was called.
///
EXTERN bool may_garbage_collect INIT( = false);
EXTERN bool want_garbage_collect INIT( = false);
EXTERN bool garbage_collect_at_exit INIT( = false);

// Special values for current_SID.
#define SID_MODELINE    (-1)      // when using a modeline
#define SID_CMDARG      (-2)      // for "--cmd" argument
#define SID_CARG        (-3)      // for "-c" argument
#define SID_ENV         (-4)      // for sourcing environment variable
#define SID_ERROR       (-5)      // option was reset because of an error
#define SID_NONE        (-6)      // don't set scriptID
#define SID_WINLAYOUT   (-7)      // changing window size
#define SID_LUA         (-8)      // for Lua scripts/chunks
#define SID_API_CLIENT  (-9)      // for API clients
#define SID_STR         (-10)     // for sourcing a string with no script item

// Script CTX being sourced or was sourced to define the current function.
EXTERN sctx_T current_sctx INIT( = { 0, 0, 0 });
// ID of the current channel making a client API call
EXTERN uint64_t current_channel_id INIT( = 0);

EXTERN bool did_source_packages INIT( = false);

// Scope information for the code that indirectly triggered the current
// provider function call
EXTERN struct caller_scope {
  sctx_T script_ctx;
  estack_T es_entry;
  char