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