robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

robinmerge: 1dc9728daa1d8a2702

master
3.9 KiB133 linesraw
1#pragma once
2
3#include <stdbool.h>
4
5#include "nvim/func_attr.h"
6#include "nvim/os/time_defs.h"
7#include "nvim/pos_defs.h"
8#include "nvim/types_defs.h"
9
10#include "mark_defs.h.inline.generated.h"
11
12// marks: positions in a file
13// (a normal mark is a lnum/col pair, the same as a file position)
14
15/// Flags for outcomes when moving to a mark.
16typedef enum {
17  kMarkMoveSuccess = 1,  ///< Successful move.
18  kMarkMoveFailed = 2,  ///< Failed to move.
19  kMarkSwitchedBuf = 4,  ///< Switched curbuf.
20  kMarkChangedCol = 8,   ///< Changed the cursor col.
21  kMarkChangedLine = 16,  ///< Changed the cursor line.
22  kMarkChangedCursor = 32,  ///< Changed the cursor.
23  kMarkChangedView = 64,  ///< Changed the view.
24} MarkMoveRes;
25
26/// Flags to configure the movement to a mark.
27typedef enum {
28  kMarkBeginLine = 1,  ///< Move cursor to the beginning of the line.
29  kMarkContext = 2,  ///< Leave context mark when moving the cursor.
30  KMarkNoContext = 4,  ///< Don't leave a context mark.
31  kMarkSetView = 8,  ///< Set the mark view after moving
32  kMarkJumpList = 16,  ///< Special case, don't leave context mark when switching buffer
33} MarkMove;
34
35/// Options when getting a mark
36typedef enum {
37  kMarkBufLocal,  ///< Only return marks that belong to the buffer.
38  kMarkAll,  ///< Return all types of marks.
39  kMarkAllNoResolve,  ///< Return all types of marks but don't resolve fnum (global marks).
40} MarkGet;
41
42/// Options when adjusting marks
43typedef enum {
44  kMarkAdjustNormal,  ///< Normal mode commands, etc.
45  kMarkAdjustApi,     ///< Changing lines from the API
46  kMarkAdjustTerm,    ///< Terminal scrollback
47} MarkAdjustMode;
48
49/// Number of possible numbered global marks
50#define EXTRA_MARKS     ('9' - '0' + 1)
51
52/// Maximum possible number of letter marks
53#define NMARKS          ('z' - 'a' + 1)
54
55/// Total possible number of global marks
56#define NGLOBALMARKS    (NMARKS + EXTRA_MARKS)
57
58/// Total possible number of local marks
59///
60/// That are uppercase marks plus '"', '^' and '.'. There are other local marks,
61/// but they are not saved in ShaDa files.
62#define NLOCALMARKS     (NMARKS + 3)
63
64/// Max value of local mark
65#define NMARK_LOCAL_MAX 126  // Index of '~'
66
67/// Maximum number of marks in jump list
68#define JUMPLISTSIZE    100
69
70/// Maximum number of tags in tag stack
71#define TAGSTACKSIZE    20
72
73/// Represents view in which the mark was created
74typedef struct {
75  linenr_T topline_offset;  ///< Amount of lines from the mark lnum to the top of the window.
76                            ///< Use MAXLNUM to indicate that the mark does not have a view.
77  colnr_T skipcol;
78} fmarkv_T;
79
80#define INIT_FMARKV { MAXLNUM, 0 }
81
82/// Structure defining single local mark
83typedef struct {
84  pos_T mark;           ///< Cursor position.
85  int fnum;             ///< File number.
86  Timestamp timestamp;  ///< Time when this mark was last set.
87  fmarkv_T view;  ///< View the mark was created on
88  AdditionalData *additional_data;  ///< Additional data from ShaDa file.
89} fmark_T;
90
91#define INIT_FMARK { { 0, 0, 0 }, 0, 0, INIT_FMARKV, NULL }
92
93/// Structure defining extended mark (mark with file name attached)
94typedef struct {
95  fmark_T fmark;       ///< Actual mark.
96  char *fname;  ///< File name, used when fnum == 0.
97} xfmark_T;
98
99#define INIT_XFMARK { INIT_FMARK, NULL }
100
101/// Return true if position a is before (less than) position b.
102static inline bool lt(pos_T a, pos_T b)
103  FUNC_ATTR_CONST FUNC_ATTR_ALWAYS_INLINE
104{
105  if (a.lnum != b.lnum) {
106    return a.lnum < b.lnum;
107  } else if (a.col != b.col) {
108    return a.col < b.col;
109  } else {
110    return a.coladd < b.coladd;
111  }
112}
113
114static inline bool equalpos(pos_T a, pos_T b)
115  FUNC_ATTR_CONST FUNC_ATTR_ALWAYS_INLINE
116{
117  return (a.lnum == b.lnum) && (a.col == b.col) && (a.coladd == b.coladd);
118}
119
120/// "Less than or equal to".
121static inline bool ltoreq(pos_T a, pos_T b)
122  FUNC_ATTR_CONST FUNC_ATTR_ALWAYS_INLINE
123{
124  return lt(a, b) || equalpos(a, b);
125}
126
127static inline void clearpos(pos_T *a)
128  FUNC_ATTR_ALWAYS_INLINE
129{
130  a->lnum = 0;
131  a->col = 0;
132  a->coladd = 0;
133}