mark.h
Go to the documentation of this file.
1 #ifndef NVIM_MARK_H
2 #define NVIM_MARK_H
3 
4 #include "nvim/macros.h"
5 #include "nvim/ascii.h"
6 #include "nvim/buffer_defs.h"
7 #include "nvim/func_attr.h"
8 #include "nvim/mark_defs.h"
9 #include "nvim/extmark_defs.h"
10 #include "nvim/memory.h"
11 #include "nvim/pos.h"
12 #include "nvim/os/time.h"
13 #include "nvim/ex_cmds_defs.h" // for exarg_T
14 
16 #define SET_FMARK(fmarkp_, mark_, fnum_) \
17  do { \
18  fmark_T *const fmarkp__ = fmarkp_; \
19  fmarkp__->mark = mark_; \
20  fmarkp__->fnum = fnum_; \
21  fmarkp__->timestamp = os_time(); \
22  fmarkp__->additional_data = NULL; \
23  } while (0)
24 
26 #define RESET_FMARK(fmarkp_, mark_, fnum_) \
27  do { \
28  fmark_T *const fmarkp___ = fmarkp_; \
29  free_fmark(*fmarkp___); \
30  SET_FMARK(fmarkp___, mark_, fnum_); \
31  } while (0)
32 
34 #define CLEAR_FMARK(fmarkp_) \
35  RESET_FMARK(fmarkp_, ((pos_T) { 0, 0, 0 }), 0)
36 
38 #define SET_XFMARK(xfmarkp_, mark_, fnum_, fname_) \
39  do { \
40  xfmark_T *const xfmarkp__ = xfmarkp_; \
41  xfmarkp__->fname = fname_; \
42  SET_FMARK(&(xfmarkp__->fmark), mark_, fnum_); \
43  } while (0)
44 
46 #define RESET_XFMARK(xfmarkp_, mark_, fnum_, fname_) \
47  do { \
48  xfmark_T *const xfmarkp__ = xfmarkp_; \
49  free_xfmark(*xfmarkp__); \
50  xfmarkp__->fname = fname_; \
51  SET_FMARK(&(xfmarkp__->fmark), mark_, fnum_); \
52  } while (0)
53 
55 static inline int mark_global_index(const char name)
57 {
58  return (ASCII_ISUPPER(name)
59  ? (name - 'A')
60  : (ascii_isdigit(name)
61  ? (NMARKS + (name - '0'))
62  : -1));
63 }
64 
66 static inline int mark_local_index(const char name)
68 {
69  return (ASCII_ISLOWER(name)
70  ? (name - 'a')
71  : (name == '"'
72  ? NMARKS
73  : (name == '^'
74  ? NMARKS + 1
75  : (name == '.'
76  ? NMARKS + 2
77  : -1))));
78 }
79 
81 static inline bool equalpos(pos_T, pos_T)
83 static inline bool ltoreq(pos_T, pos_T)
85 static inline void clearpos(pos_T *)
87 
89 static inline bool lt(pos_T a, pos_T b)
90 {
91  if (a.lnum != b.lnum) {
92  return a.lnum < b.lnum;
93  } else if (a.col != b.col) {
94  return a.col < b.col;
95  } else {
96  return a.coladd < b.coladd;
97  }
98 }
99 
101 static inline bool equalpos(pos_T a, pos_T b)
102 {
103  return (a.lnum == b.lnum) && (a.col == b.col) && (a.coladd == b.coladd);
104 }
105 
107 static inline bool ltoreq(pos_T a, pos_T b)
108 {
109  return lt(a, b) || equalpos(a, b);
110 }
111 
113 static inline void clearpos(pos_T *a)
114 {
115  a->lnum = 0;
116  a->col = 0;
117  a->coladd = 0;
118 }
119 
120 #ifdef INCLUDE_GENERATED_DECLARATIONS
121 # include "mark.h.generated.h"
122 #endif
123 #endif // NVIM_MARK_H
#define ASCII_ISUPPER(c)
Definition: macros.h:54
#define FUNC_ATTR_CONST
Definition: func_attr.h:241
#define NMARKS
Maximum possible number of letter marks.
Definition: mark_defs.h:17
colnr_T col
Definition: pos.h:27
#define ASCII_ISLOWER(c)
Definition: macros.h:53
colnr_T coladd
Definition: pos.h:28
linenr_T lnum
Definition: pos.h:26
#define REAL_FATTR_CONST
Definition: func_attr.h:167
static int REAL_FATTR_WARN_UNUSED_RESULT REAL_FATTR_ALWAYS_INLINE
Definition: typval_encode.c.h:258
char_u * name
Definition: userfunc.c:786
Definition: pos.h:25