robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
aa1d8a2702
master
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 { 17kMarkMoveSuccess = 1 ,///< Successful move. 18kMarkMoveFailed = 2 ,///< Failed to move. 19kMarkSwitchedBuf = 4 ,///< Switched curbuf. 20kMarkChangedCol = 8 ,///< Changed the cursor col. 21kMarkChangedLine = 16 ,///< Changed the cursor line. 22kMarkChangedCursor = 32 ,///< Changed the cursor. 23kMarkChangedView = 64 ,///< Changed the view. 24}MarkMoveRes ; 25 26/// Flags to configure the movement to a mark. 27typedef enum { 28kMarkBeginLine = 1 ,///< Move cursor to the beginning of the line. 29kMarkContext = 2 ,///< Leave context mark when moving the cursor. 30KMarkNoContext = 4 ,///< Don't leave a context mark. 31kMarkSetView = 8 ,///< Set the mark view after moving 32kMarkJumpList = 16 ,///< Special case, don't leave context mark when switching buffer 33}MarkMove ; 34 35/// Options when getting a mark 36typedef enum { 37kMarkBufLocal ,///< Only return marks that belong to the buffer. 38kMarkAll ,///< Return all types of marks. 39kMarkAllNoResolve ,///< Return all types of marks but don't resolve fnum (global marks). 40}MarkGet ; 41 42/// Options when adjusting marks 43typedef enum { 44kMarkAdjustNormal ,///< Normal mode commands, etc. 45kMarkAdjustApi ,///< Changing lines from the API 46kMarkAdjustTerm ,///< 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 { 75linenr_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. 77colnr_T skipcol ; 78}fmarkv_T ; 79 80#define INIT_FMARKV { MAXLNUM, 0 } 81 82/// Structure defining single local mark 83typedef struct { 84pos_T mark ;///< Cursor position. 85int fnum ;///< File number. 86Timestamp timestamp ;///< Time when this mark was last set. 87fmarkv_T view ;///< View the mark was created on 88AdditionalData * 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 { 95fmark_T fmark ;///< Actual mark. 96char * 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 ) 103FUNC_ATTR_CONST FUNC_ATTR_ALWAYS_INLINE 104{ 105if (a .lnum != b .lnum ) { 106return a .lnum < b .lnum ; 107 }else if (a .col != b .col ) { 108return a .col < b .col ; 109 }else { 110return a .coladd < b .coladd ; 111 } 112} 113 114static inline bool equalpos (pos_T a ,pos_T b ) 115FUNC_ATTR_CONST FUNC_ATTR_ALWAYS_INLINE 116{ 117return (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 ) 122FUNC_ATTR_CONST FUNC_ATTR_ALWAYS_INLINE 123{ 124return lt (a ,b )|| equalpos (a ,b ); 125} 126 127static inline void clearpos (pos_T * a ) 128FUNC_ATTR_ALWAYS_INLINE 129{ 130a -> lnum = 0 ; 131a -> col = 0 ; 132a -> coladd = 0 ; 133}