buffer.h
Go to the documentation of this file.
1 #ifndef NVIM_BUFFER_H
2 #define NVIM_BUFFER_H
3 
4 #include "nvim/eval.h"
5 #include "nvim/func_attr.h"
6 #include "nvim/macros.h"
7 #include "nvim/memline.h"
8 #include "nvim/pos.h" // for linenr_T
9 #include "nvim/screen.h" // for StlClickRecord
10 
11 // Values for buflist_getfile()
13  GETF_SETMARK = 0x01, // set pcmark before jumping
14  GETF_ALT = 0x02, // jumping to alternate file (not buf num)
15  GETF_SWITCH = 0x04, // respect 'switchbuf' settings when jumping
16 };
17 
18 // Return values of getfile()
20  GETFILE_ERROR = 1, // normal error
21  GETFILE_NOT_WRITTEN = 2, // "not written" error
22  GETFILE_SAME_FILE = 0, // success, same file
23  GETFILE_OPEN_OTHER = (-1), // success, opened another file
25 };
26 
27 // Values for buflist_new() flags
28 enum bln_values {
29  BLN_CURBUF = 1, // May re-use curbuf for new buffer
30  BLN_LISTED = 2, // Put new buffer in buffer list
31  BLN_DUMMY = 4, // Allocating dummy buffer
32  BLN_NEW = 8, // create a new buffer
33  BLN_NOOPT = 16, // Don't copy options to existing buffer
34  // BLN_DUMMY_OK = 32, // also find an existing dummy buffer
35  // BLN_REUSE = 64, // may re-use number from buf_reuse
36  BLN_NOCURWIN = 128, // buffer is not associated with curwin
37 };
38 
39 // Values for action argument for do_buffer()
41  DOBUF_GOTO = 0, // go to specified buffer
42  DOBUF_SPLIT = 1, // split window and go to specified buffer
43  DOBUF_UNLOAD = 2, // unload specified buffer(s)
44  DOBUF_DEL = 3, // delete specified buffer(s) from buflist
45  DOBUF_WIPE = 4, // delete specified buffer(s) really
46 };
47 
48 // Values for start argument for do_buffer()
50  DOBUF_CURRENT = 0, // "count" buffer from current buffer
51  DOBUF_FIRST = 1, // "count" buffer from first buffer
52  DOBUF_LAST = 2, // "count" buffer from last buffer
53  DOBUF_MOD = 3, // "count" mod. buffer from current buffer
54 };
55 
56 // flags for buf_freeall()
57 enum bfa_values {
58  BFA_DEL = 1, // buffer is going to be deleted
59  BFA_WIPE = 2, // buffer is going to be wiped out
60  BFA_KEEP_UNDO = 4, // do not free undo information
61  BFA_IGNORE_ABORT = 8, // do not abort for aborting()
62 };
63 
64 #ifdef INCLUDE_GENERATED_DECLARATIONS
65 # include "buffer.h.generated.h"
66 #endif
67 
68 static inline void buf_set_changedtick(buf_T *const buf,
69  const varnumber_T changedtick)
71 
76 static inline void buf_set_changedtick(buf_T *const buf, const varnumber_T changedtick)
77 {
78  typval_T old_val = buf->changedtick_di.di_tv;
79 
80 #ifndef NDEBUG
81  dictitem_T *const changedtick_di = tv_dict_find(buf->b_vars, S_LEN("changedtick"));
82  assert(changedtick_di != NULL);
83  assert(changedtick_di->di_tv.v_type == VAR_NUMBER);
84  assert(changedtick_di->di_tv.v_lock == VAR_FIXED);
85  // For some reason formatc does not like the below.
86 # ifndef UNIT_TESTING_LUA_PREPROCESSING
87  assert(changedtick_di->di_flags == (DI_FLAGS_RO|DI_FLAGS_FIX));
88 # endif
89  assert(changedtick_di == (dictitem_T *)&buf->changedtick_di);
90 #endif
91  buf->changedtick_di.di_tv.vval.v_number = changedtick;
92 
93  if (tv_dict_is_watched(buf->b_vars)) {
95  (char *)buf->changedtick_di.di_key,
96  &buf->changedtick_di.di_tv,
97  &old_val);
98  }
99 }
100 
101 static inline varnumber_T buf_get_changedtick(const buf_T *const buf)
104 
110 static inline varnumber_T buf_get_changedtick(const buf_T *const buf)
111 {
112  return buf->changedtick_di.di_tv.vval.v_number;
113 }
114 
115 static inline void buf_inc_changedtick(buf_T *const buf)
117 
123 static inline void buf_inc_changedtick(buf_T *const buf)
124 {
125  buf_set_changedtick(buf, buf_get_changedtick(buf) + 1);
126 }
127 
128 static inline bool buf_is_empty(buf_T *buf)
129 {
130  return buf->b_ml.ml_line_count == 1
131  && *ml_get_buf(buf, (linenr_T)1, false) == '\0';
132 }
133 
134 #endif // NVIM_BUFFER_H
bln_values
bln_values
Definition: buffer.h:28
BLN_CURBUF
@ BLN_CURBUF
Definition: buffer.h:29
DOBUF_LAST
@ DOBUF_LAST
Definition: buffer.h:52
typval_T
Structure that holds an internal variable value.
Definition: typval.h:135
DOBUF_GOTO
@ DOBUF_GOTO
Definition: buffer.h:41
DOBUF_FIRST
@ DOBUF_FIRST
Definition: buffer.h:51
DOBUF_MOD
@ DOBUF_MOD
Definition: buffer.h:53
BLN_NOOPT
@ BLN_NOOPT
Definition: buffer.h:33
DOBUF_WIPE
@ DOBUF_WIPE
Definition: buffer.h:45
screen.h
VAR_FIXED
@ VAR_FIXED
Locked forever.
Definition: typval.h:115
BFA_DEL
@ BFA_DEL
Definition: buffer.h:58
DI_FLAGS_FIX
@ DI_FLAGS_FIX
Fixed value: cannot be :unlet or remove()d.
Definition: typval.h:241
macros.h
GETFILE_OPEN_OTHER
@ GETFILE_OPEN_OTHER
Definition: buffer.h:23
BLN_LISTED
@ BLN_LISTED
Definition: buffer.h:30
BFA_KEEP_UNDO
@ BFA_KEEP_UNDO
Definition: buffer.h:60
BLN_DUMMY
@ BLN_DUMMY
Definition: buffer.h:31
DOBUF_UNLOAD
@ DOBUF_UNLOAD
Definition: buffer.h:43
GETF_SETMARK
@ GETF_SETMARK
Definition: buffer.h:13
getf_retvalues
getf_retvalues
Definition: buffer.h:19
REAL_FATTR_NONNULL_ALL
#define REAL_FATTR_NONNULL_ALL
Definition: func_attr.h:183
bfa_values
bfa_values
Definition: buffer.h:57
tv_dict_find
dictitem_T * tv_dict_find(const dict_T *const d, const char *const key, const ptrdiff_t len) FUNC_ATTR_NONNULL_ARG(2) FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
Definition: typval.c:1540
DOBUF_SPLIT
@ DOBUF_SPLIT
Definition: buffer.h:42
GETFILE_UNUSED
@ GETFILE_UNUSED
Definition: buffer.h:24
DOBUF_CURRENT
@ DOBUF_CURRENT
Definition: buffer.h:50
BLN_NOCURWIN
@ BLN_NOCURWIN
Definition: buffer.h:36
GETFILE_ERROR
@ GETFILE_ERROR
Definition: buffer.h:20
GETF_SWITCH
@ GETF_SWITCH
Definition: buffer.h:15
tv_dict_watcher_notify
void tv_dict_watcher_notify(dict_T *const dict, const char *const key, typval_T *const newtv, typval_T *const oldtv) FUNC_ATTR_NONNULL_ARG(1
memline.h
buf
char *const buf
Definition: encode.c:234
eval.h
VAR_NUMBER
@ VAR_NUMBER
Number, .v_number is used.
Definition: typval.h:121
assert
assert(len >=0)
varnumber_T
int64_t varnumber_T
Type used for VimL VAR_NUMBER values.
Definition: typval.h:26
BFA_WIPE
@ BFA_WIPE
Definition: buffer.h:59
DI_FLAGS_RO
@ DI_FLAGS_RO
Read-only value.
Definition: typval.h:239
ml_get_buf
char_u * ml_get_buf(buf_T *buf, linenr_T lnum, bool will_change) FUNC_ATTR_NONNULL_ALL
Definition: memline.c:1832
dobuf_start_values
dobuf_start_values
Definition: buffer.h:49
BFA_IGNORE_ABORT
@ BFA_IGNORE_ABORT
Definition: buffer.h:61
dictitem_T
Definition: coverity-model.c:39
S_LEN
#define S_LEN(s)
Definition: macros.h:32
GETFILE_SAME_FILE
@ GETFILE_SAME_FILE
Definition: buffer.h:22
dobuf_action_values
dobuf_action_values
Definition: buffer.h:40
DOBUF_DEL
@ DOBUF_DEL
Definition: buffer.h:44
file_buffer
Definition: buffer_defs.h:521
REAL_FATTR_PURE
#define REAL_FATTR_PURE
Definition: func_attr.h:163
func_attr.h
REAL_FATTR_ALWAYS_INLINE
static int REAL_FATTR_WARN_UNUSED_RESULT REAL_FATTR_ALWAYS_INLINE
Definition: typval_encode.c.h:265
linenr_T
long linenr_T
Line number type.
Definition: pos.h:5
GETFILE_NOT_WRITTEN
@ GETFILE_NOT_WRITTEN
Definition: buffer.h:21
NULL
return NULL
Definition: eval.c:9968
REAL_FATTR_WARN_UNUSED_RESULT
static int REAL_FATTR_WARN_UNUSED_RESULT
Definition: typval_encode.c.h:300
BLN_NEW
@ BLN_NEW
Definition: buffer.h:32
pos.h
GETF_ALT
@ GETF_ALT
Definition: buffer.h:14
getf_values
getf_values
Definition: buffer.h:12