neovim

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

mark_defs.h (3965B)


      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.
     16 typedef 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.
     27 typedef 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
     36 typedef 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
     43 typedef 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
     74 typedef 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 } fmarkv_T;
     78 
     79 #define INIT_FMARKV { MAXLNUM }
     80 
     81 /// Structure defining single local mark
     82 typedef struct {
     83  pos_T mark;           ///< Cursor position.
     84  int fnum;             ///< File number.
     85  Timestamp timestamp;  ///< Time when this mark was last set.
     86  fmarkv_T view;  ///< View the mark was created on
     87  AdditionalData *additional_data;  ///< Additional data from ShaDa file.
     88 } fmark_T;
     89 
     90 #define INIT_FMARK { { 0, 0, 0 }, 0, 0, INIT_FMARKV, NULL }
     91 
     92 /// Structure defining extended mark (mark with file name attached)
     93 typedef struct {
     94  fmark_T fmark;       ///< Actual mark.
     95  char *fname;  ///< File name, used when fnum == 0.
     96 } xfmark_T;
     97 
     98 #define INIT_XFMARK { INIT_FMARK, NULL }
     99 
    100 /// Return true if position a is before (less than) position b.
    101 static inline bool lt(pos_T a, pos_T b)
    102  FUNC_ATTR_CONST FUNC_ATTR_ALWAYS_INLINE
    103 {
    104  if (a.lnum != b.lnum) {
    105    return a.lnum < b.lnum;
    106  } else if (a.col != b.col) {
    107    return a.col < b.col;
    108  } else {
    109    return a.coladd < b.coladd;
    110  }
    111 }
    112 
    113 static inline bool equalpos(pos_T a, pos_T b)
    114  FUNC_ATTR_CONST FUNC_ATTR_ALWAYS_INLINE
    115 {
    116  return (a.lnum == b.lnum) && (a.col == b.col) && (a.coladd == b.coladd);
    117 }
    118 
    119 static inline bool ltoreq(pos_T a, pos_T b)
    120  FUNC_ATTR_CONST FUNC_ATTR_ALWAYS_INLINE
    121 {
    122  return lt(a, b) || equalpos(a, b);
    123 }
    124 
    125 static inline void clearpos(pos_T *a)
    126  FUNC_ATTR_ALWAYS_INLINE
    127 {
    128  a->lnum = 0;
    129  a->col = 0;
    130  a->coladd = 0;
    131 }