buffer.h
Go to the documentation of this file.
1 #ifndef NVIM_BUFFER_H
2 #define NVIM_BUFFER_H
3 
4 #include "nvim/vim.h"
5 #include "nvim/window.h"
6 #include "nvim/pos.h" // for linenr_T
7 #include "nvim/ex_cmds_defs.h" // for exarg_T
8 #include "nvim/screen.h" // for StlClickRecord
9 #include "nvim/func_attr.h"
10 #include "nvim/eval.h"
11 #include "nvim/macros.h"
12 
13 // Values for buflist_getfile()
15  GETF_SETMARK = 0x01, // set pcmark before jumping
16  GETF_ALT = 0x02, // jumping to alternate file (not buf num)
17  GETF_SWITCH = 0x04, // respect 'switchbuf' settings when jumping
18 };
19 
20 // Return values of getfile()
22  GETFILE_ERROR = 1, // normal error
23  GETFILE_NOT_WRITTEN = 2, // "not written" error
24  GETFILE_SAME_FILE = 0, // success, same file
25  GETFILE_OPEN_OTHER = -1, // success, opened another file
27 };
28 
29 // Values for buflist_new() flags
30 enum bln_values {
31  BLN_CURBUF = 1, // May re-use curbuf for new buffer
32  BLN_LISTED = 2, // Put new buffer in buffer list
33  BLN_DUMMY = 4, // Allocating dummy buffer
34  // TODO(mhinz): merge patch that introduces BLN_NEW
35  BLN_NOOPT = 16, // Don't copy options to existing buffer
36 };
37 
38 // Values for action argument for do_buffer()
40  DOBUF_GOTO = 0, // go to specified buffer
41  DOBUF_SPLIT = 1, // split window and go to specified buffer
42  DOBUF_UNLOAD = 2, // unload specified buffer(s)
43  DOBUF_DEL = 3, // delete specified buffer(s) from buflist
44  DOBUF_WIPE = 4, // delete specified buffer(s) really
45 };
46 
47 // Values for start argument for do_buffer()
49  DOBUF_CURRENT = 0, // "count" buffer from current buffer
50  DOBUF_FIRST = 1, // "count" buffer from first buffer
51  DOBUF_LAST = 2, // "count" buffer from last buffer
52  DOBUF_MOD = 3, // "count" mod. buffer from current buffer
53 };
54 
55 // flags for buf_freeall()
56 enum bfa_values {
57  BFA_DEL = 1, // buffer is going to be deleted
58  BFA_WIPE = 2, // buffer is going to be wiped out
59  BFA_KEEP_UNDO = 4, // do not free undo information
60 };
61 
62 #ifdef INCLUDE_GENERATED_DECLARATIONS
63 # include "buffer.h.generated.h"
64 #endif
65 
66 // Find a window that contains "buf" and switch to it.
67 // If there is no such window, use the current window and change "curbuf".
68 // Caller must initialize save_curbuf to NULL.
69 // restore_win_for_buf() MUST be called later!
70 static inline void switch_to_win_for_buf(buf_T *buf,
71  win_T **save_curwinp,
72  tabpage_T **save_curtabp,
73  bufref_T *save_curbuf)
74 {
75  win_T *wp;
76  tabpage_T *tp;
77 
78  if (!find_win_for_buf(buf, &wp, &tp)
79  || switch_win(save_curwinp, save_curtabp, wp, tp, true) == FAIL) {
80  switch_buffer(save_curbuf, buf);
81  }
82 }
83 
84 static inline void restore_win_for_buf(win_T *save_curwin,
85  tabpage_T *save_curtab,
86  bufref_T *save_curbuf)
87 {
88  if (save_curbuf->br_buf == NULL) {
89  restore_win(save_curwin, save_curtab, true);
90  } else {
91  restore_buffer(save_curbuf);
92  }
93 }
94 
95 static inline void buf_set_changedtick(buf_T *const buf,
96  const varnumber_T changedtick)
98 
103 static inline void buf_set_changedtick(buf_T *const buf,
104  const varnumber_T changedtick)
105 {
106 #ifndef NDEBUG
107  dictitem_T *const changedtick_di = tv_dict_find(
108  buf->b_vars, S_LEN("changedtick"));
109  assert(changedtick_di != NULL);
110  assert(changedtick_di->di_tv.v_type == VAR_NUMBER);
111  assert(changedtick_di->di_tv.v_lock == VAR_FIXED);
112  // For some reason formatc does not like the below.
113 # ifndef UNIT_TESTING_LUA_PREPROCESSING
114  assert(changedtick_di->di_flags == (DI_FLAGS_RO|DI_FLAGS_FIX));
115 # endif
116  assert(changedtick_di == (dictitem_T *)&buf->changedtick_di);
117 #endif
118  buf->changedtick_di.di_tv.vval.v_number = changedtick;
119 }
120 
121 static inline varnumber_T buf_get_changedtick(const buf_T *const buf)
124 
130 static inline varnumber_T buf_get_changedtick(const buf_T *const buf)
131 {
132  return buf->changedtick_di.di_tv.vval.v_number;
133 }
134 
135 static inline void buf_inc_changedtick(buf_T *const buf)
137 
143 static inline void buf_inc_changedtick(buf_T *const buf)
144 {
145  buf_set_changedtick(buf, buf_get_changedtick(buf) + 1);
146 }
147 
148 #define WITH_BUFFER(b, code) \
149  do { \
150  win_T *save_curwin = NULL; \
151  tabpage_T *save_curtab = NULL; \
152  bufref_T save_curbuf = { NULL, 0, 0 }; \
153  switch_to_win_for_buf(b, &save_curwin, &save_curtab, &save_curbuf); \
154  code; \
155  restore_win_for_buf(save_curwin, save_curtab, &save_curbuf); \
156  } while (0)
157 
158 
159 #endif // NVIM_BUFFER_H
dobuf_start_values
Definition: buffer.h:48
Definition: buffer.h:17
Definition: buffer.h:44
Definition: buffer_defs.h:831
Definition: buffer.h:57
getf_retvalues
Definition: buffer.h:21
Definition: coverity-model.c:65
Definition: buffer.h:31
#define S_LEN(s)
Definition: macros.h:29
ChangedtickDictItem changedtick_di
Definition: buffer_defs.h:499
Definition: buffer.h:40
return NULL
Definition: eval.c:22198
Definition: buffer.h:43
getf_values
Definition: buffer.h:14
dict_T * b_vars
b: scope dictionary.
Definition: buffer_defs.h:752
Definition: buffer.h:35
bln_values
Definition: buffer.h:30
Definition: buffer.h:24
Read-only value.
Definition: typval.h:225
Number, .v_number is used.
Definition: typval.h:113
void restore_win(win_T *save_curwin, tabpage_T *save_curtab, bool no_display)
Definition: window.c:5612
static int REAL_FATTR_WARN_UNUSED_RESULT
Definition: typval_encode.c.h:295
Definition: buffer.h:26
#define REAL_FATTR_NONNULL_ALL
Definition: func_attr.h:183
dobuf_action_values
Definition: buffer.h:39
Definition: buffer.h:59
Definition: buffer.h:50
Definition: buffer.h:42
bool find_win_for_buf(buf_T *buf, win_T **wp, tabpage_T **tp)
Definition: buffer.c:4994
assert(len >=0)
Definition: buffer_defs.h:465
Definition: buffer.h:33
char *const buf
Definition: encode.c:235
Definition: buffer.h:49
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:1410
#define FAIL
Definition: vim.h:93
Definition: buffer.h:32
Definition: buffer.h:58
Definition: buffer_defs.h:13
Definition: buffer.h:41
Definition: buffer_defs.h:962
void restore_buffer(bufref_T *save_curbuf)
Restore the current buffer after using switch_buffer().
Definition: window.c:5646
Definition: buffer.h:22
Definition: buffer.h:51
static int REAL_FATTR_WARN_UNUSED_RESULT REAL_FATTR_ALWAYS_INLINE
Definition: typval_encode.c.h:258
int switch_win(win_T **save_curwin, tabpage_T **save_curtab, win_T *win, tabpage_T *tp, int no_display)
Definition: window.c:5586
int64_t varnumber_T
Type used for VimL VAR_NUMBER values.
Definition: typval.h:28
buf_T * br_buf
Definition: buffer_defs.h:14
bfa_values
Definition: buffer.h:56
Definition: buffer.h:16
#define REAL_FATTR_PURE
Definition: func_attr.h:163
Locked forever.
Definition: typval.h:107
Definition: buffer.h:52
Definition: buffer.h:15
void switch_buffer(bufref_T *save_curbuf, buf_T *buf)
Definition: window.c:5635
Fixed value: cannot be :unlet or remove()d.
Definition: typval.h:227
Definition: buffer.h:25
Definition: buffer.h:23