neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

marktree.h (4308B)


      1 #pragma once
      2 
      3 #include <stdbool.h>
      4 #include <stddef.h>  // IWYU pragma: keep
      5 #include <stdint.h>
      6 
      7 #include "nvim/decoration_defs.h"
      8 #include "nvim/marktree_defs.h"  // IWYU pragma: keep
      9 #include "nvim/pos_defs.h"  // IWYU pragma: keep
     10 // only for debug functions:
     11 #include "nvim/api/private/defs.h"  // IWYU pragma: keep
     12 
     13 #define MT_INVALID_KEY (MTKey) { { -1, -1 }, 0, 0, 0, { .hl = DECOR_HIGHLIGHT_INLINE_INIT } }
     14 
     15 #define MT_FLAG_REAL (((uint16_t)1) << 0)
     16 #define MT_FLAG_END (((uint16_t)1) << 1)
     17 #define MT_FLAG_PAIRED (((uint16_t)1) << 2)
     18 // orphaned: the other side of this paired mark was deleted. this mark must be deleted very soon!
     19 #define MT_FLAG_ORPHANED (((uint16_t)1) << 3)
     20 #define MT_FLAG_NO_UNDO (((uint16_t)1) << 4)
     21 #define MT_FLAG_INVALIDATE (((uint16_t)1) << 5)
     22 #define MT_FLAG_INVALID (((uint16_t)1) << 6)
     23 // discriminant for union
     24 #define MT_FLAG_DECOR_EXT (((uint16_t)1) << 7)
     25 
     26 // TODO(bfredl): flags for decorations. These cover the cases where we quickly needs
     27 // to skip over irrelevant marks internally. When we refactor this more, also make all info
     28 // for ExtmarkType included here
     29 #define MT_FLAG_DECOR_HL (((uint16_t)1) << 8)
     30 #define MT_FLAG_DECOR_SIGNTEXT (((uint16_t)1) << 9)
     31 // TODO(bfredl): for now this means specifically number_hl, line_hl, cursorline_hl
     32 // needs to clean up the name.
     33 #define MT_FLAG_DECOR_SIGNHL (((uint16_t)1) << 10)
     34 #define MT_FLAG_DECOR_VIRT_LINES (((uint16_t)1) << 11)
     35 #define MT_FLAG_DECOR_VIRT_TEXT_INLINE (((uint16_t)1) << 12)
     36 #define MT_FLAG_DECOR_CONCEAL_LINES (((uint16_t)1) << 13)
     37 
     38 // These _must_ be last to preserve ordering of marks
     39 #define MT_FLAG_RIGHT_GRAVITY (((uint16_t)1) << 14)
     40 #define MT_FLAG_LAST (((uint16_t)1) << 15)
     41 
     42 #define MT_FLAG_DECOR_MASK  (MT_FLAG_DECOR_EXT| MT_FLAG_DECOR_HL | MT_FLAG_DECOR_SIGNTEXT \
     43                             | MT_FLAG_DECOR_SIGNHL | MT_FLAG_DECOR_VIRT_LINES \
     44                             | MT_FLAG_DECOR_VIRT_TEXT_INLINE)
     45 
     46 #define MT_FLAG_EXTERNAL_MASK (MT_FLAG_DECOR_MASK | MT_FLAG_NO_UNDO | MT_FLAG_INVALIDATE \
     47                               | MT_FLAG_INVALID | MT_FLAG_DECOR_CONCEAL_LINES)
     48 
     49 // this is defined so that start and end of the same range have adjacent ids
     50 #define MARKTREE_END_FLAG ((uint64_t)1)
     51 static inline uint64_t mt_lookup_id(uint32_t ns, uint32_t id, bool enda)
     52 {
     53  return (uint64_t)ns << 33 | (id <<1) | (enda ? MARKTREE_END_FLAG : 0);
     54 }
     55 
     56 static inline uint64_t mt_lookup_key_side(MTKey key, bool end)
     57 {
     58  return mt_lookup_id(key.ns, key.id, end);
     59 }
     60 
     61 static inline uint64_t mt_lookup_key(MTKey key)
     62 {
     63  return mt_lookup_id(key.ns, key.id, key.flags & MT_FLAG_END);
     64 }
     65 
     66 static inline bool mt_paired(MTKey key)
     67 {
     68  return key.flags & MT_FLAG_PAIRED;
     69 }
     70 
     71 static inline bool mt_end(MTKey key)
     72 {
     73  return key.flags & MT_FLAG_END;
     74 }
     75 
     76 static inline bool mt_start(MTKey key)
     77 {
     78  return mt_paired(key) && !mt_end(key);
     79 }
     80 
     81 static inline bool mt_right(MTKey key)
     82 {
     83  return key.flags & MT_FLAG_RIGHT_GRAVITY;
     84 }
     85 
     86 static inline bool mt_no_undo(MTKey key)
     87 {
     88  return key.flags & MT_FLAG_NO_UNDO;
     89 }
     90 
     91 static inline bool mt_invalidate(MTKey key)
     92 {
     93  return key.flags & MT_FLAG_INVALIDATE;
     94 }
     95 
     96 static inline bool mt_invalid(MTKey key)
     97 {
     98  return key.flags & MT_FLAG_INVALID;
     99 }
    100 
    101 static inline bool mt_decor_any(MTKey key)
    102 {
    103  return key.flags & MT_FLAG_DECOR_MASK;
    104 }
    105 
    106 static inline bool mt_decor_sign(MTKey key)
    107 {
    108  return key.flags & (MT_FLAG_DECOR_SIGNTEXT | MT_FLAG_DECOR_SIGNHL);
    109 }
    110 
    111 static inline bool mt_conceal_lines(MTKey key)
    112 {
    113  return key.flags & MT_FLAG_DECOR_CONCEAL_LINES;
    114 }
    115 
    116 static inline uint16_t mt_flags(bool right_gravity, bool no_undo, bool invalidate, bool decor_ext)
    117 {
    118  return (uint16_t)((right_gravity ? MT_FLAG_RIGHT_GRAVITY : 0)
    119                    | (no_undo ? MT_FLAG_NO_UNDO : 0)
    120                    | (invalidate ? MT_FLAG_INVALIDATE : 0)
    121                    | (decor_ext ? MT_FLAG_DECOR_EXT : 0));
    122 }
    123 
    124 static inline MTPair mtpair_from(MTKey start, MTKey end)
    125 {
    126  return (MTPair){ .start = start, .end_pos = end.pos, .end_right_gravity = mt_right(end) };
    127 }
    128 
    129 static inline DecorInline mt_decor(MTKey key)
    130 {
    131  return (DecorInline){ .ext = key.flags & MT_FLAG_DECOR_EXT, .data = key.decor_data };
    132 }
    133 
    134 static inline DecorVirtText *mt_decor_virt(MTKey mark)
    135 {
    136  return (mark.flags & MT_FLAG_DECOR_EXT) ? mark.decor_data.ext.vt : NULL;
    137 }
    138 
    139 #include "marktree.h.generated.h"