1 #ifndef NVIM_MARK_H
2 #define NVIM_MARK_H
3
4 #include "nvim/ascii.h"
5 #include "nvim/buffer_defs.h"
6 #include "nvim/ex_cmds_defs.h" // for exarg_T
7 #include "nvim/extmark_defs.h"
8 #include "nvim/func_attr.h"
9 #include "nvim/macros.h"
10 #include "nvim/mark_defs.h"
11 #include "nvim/memory.h"
12 #include "nvim/os/time.h"
13 #include "nvim/pos.h"
14
15 /// Set fmark using given value
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
25 /// Free and set fmark using given value
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
33 /// Clear given fmark
34 #define CLEAR_FMARK(fmarkp_) \
35 RESET_FMARK(fmarkp_, ((pos_T) { 0, 0, 0 }), 0)
36
37 /// Set given extended mark (regular mark + file name)
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
45 /// Free and set given extended mark (regular mark + file name)
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
54 /// Convert mark name to the offset
mark_global_index(const char name)55 static inline int mark_global_index(const char name)
56 FUNC_ATTR_CONST
57 {
58 return (ASCII_ISUPPER(name)
59 ? (name - 'A')
60 : (ascii_isdigit(name)
61 ? (NMARKS + (name - '0'))
62 : -1));
63 }
64
65 /// Convert local mark name to the offset
mark_local_index(const char name)66 static inline int mark_local_index(const char name)
67 FUNC_ATTR_CONST
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
80 static inline bool lt(pos_T, pos_T) REAL_FATTR_CONST REAL_FATTR_ALWAYS_INLINE;
81 static inline bool equalpos(pos_T, pos_T)
82 REAL_FATTR_CONST REAL_FATTR_ALWAYS_INLINE;
83 static inline bool ltoreq(pos_T, pos_T)
84 REAL_FATTR_CONST REAL_FATTR_ALWAYS_INLINE;
85 static inline void clearpos(pos_T *)
86 REAL_FATTR_ALWAYS_INLINE;
87
88 /// Return true if position a is before (less than) position b.
lt(pos_T a,pos_T b)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
100 /// Return true if position a and b are equal.
equalpos(pos_T a,pos_T b)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
106 /// Return true if position a is less than or equal to b.
ltoreq(pos_T a,pos_T b)107 static inline bool ltoreq(pos_T a, pos_T b)
108 {
109 return lt(a, b) || equalpos(a, b);
110 }
111
112 /// Clear the pos_T structure pointed to by a.
clearpos(pos_T * a)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
124