robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
aa1d8a2702
master
1#pragma once 2 3#include <stdbool.h> 4 5#include "klib/kvec.h" 6#include "nvim/buffer_defs.h" 7#include "nvim/eval/typval_defs.h" 8#include "nvim/input_defs.h" 9 10// Concepts (see :help dev-cmdatom): 11// - atom, span, composite (atom with subatoms) 12// - insert-session, insertion 13// - payload 14// - replay, cascade, insert-cascade 15 16typedef enum CmdAtomType { 17kAComp ,///< Composite: complex mapping/macro. >=2 subatoms, or 0 (captured nothing). 18kAExcmd ,///< Ex command (":cnext<CR>"): the typed cmdline is the payload. 19kAInsert ,///< Insert session: entry command + text + <Esc>. 20kAInsertSpan ,///< Span (chunk) of an ongoing insert-session, cascaded mid-session. 21kAJump ,///< Cursor movement by absolute/shared navigation (jumplist, marks, `*`): 22///< not followable (its target would collapse cursors onto one position). 23kAMotion ,///< Motion (cascades in "q=" follow-motion mode). 24kAMouse ,///< Mouse action: emit-only (not replayable). 25kANormal ,///< Normal-mode command that is not a motion or jump ("u", CTRL-R, "za", …). 26///< Never cascades, except as part of a mapping's composite. 27kAOperator ,///< Operator+motion, or a self-contained edit command. 28kAScroll ,///< Scroll (CTRL-Y/D/…, wheel): emit-only, like kAMouse. 29kAVisual ,///< Visual-mode sequence ("viwee" + operator). Captures subatoms. 30kAVisualSpan ,///< Span (chunk) of an ongoing Visual session, cascaded mid-session. 31}CmdAtomType ; 32 33/// State gathered at start of a command, composite, or insert. For calculating the "delta" at end. 34typedef struct { 35bufref_T buf ;///< Buffer. 36const win_T * win ;///< Window. 37pos_T pos ;///< Primary cursor position at the start (`win.w_cursor` moves after). 38uint32_t mcursor ;///< Mcursor overlapping primary at `pos` (mark id, 0: none). Not replayed. 39varnumber_T tick ;///< b:changedtick. 40int maptick ;///< Advances on typed input (globals.h:maptick). 41}CmdOrigin ; 42 43/// How an insert-session was entered from Visual mode. 44typedef enum { 45kVInsNone ,///< Not entered from Visual mode. 46kVInsKeys ,///< (Replayable) Redo opens with the selection's captured keys. 47kVInsMotion ,///< (Replayable) Motion selected the region: Ex/Lua omap ("c" + Lua textobj), "gn". 48kVInsOther ,///< Redo without captured keys: forced motion, "gv", or "1v" fixed-size fallback. 49}VisualIns ; 50 51/// The insert-session delimited by atom_ins_start()/atom_ins_end(). 52typedef struct { 53CmdOrigin origin ;///< State at start. 54bool typed ;///< Session is user input (typed, or via mapping/macro). 55VisualIns vis ;///< Session was entered from Visual mode. 56char * vsel ;///< Visual keys ("gv…"); supplants redo's "1v" in atom+cascade. Owned. 57}InsSession ; 58 59typedef struct CmdAtom CmdAtom ; 60typedef kvec_t (CmdAtom )CmdAtomVec ; 61 62/// One repeatable operation. `keys` is the replay bytes; `spec` is the structured form. 63struct CmdAtom { 64CmdAtomType type ; 65CmdSpec spec ;///< Structured fields. 66CmdOrigin origin ;///< Pre-command state. 67CmdAtomVec atoms ;///< Composite (multi-command mapping, Visual sequence): its subatoms, 68///< in order; their keys concatenate to `keys`. Empty: non-composite. 69char * keys ;///< Resolved keysequence (typeahead encoding), including `["x][count]` prefix 70///< (unlike `CmdSpec.body`, the raw unprefixed form). 71char * text ;///< Insert-session text, or Ex/search cmdline payload. 72char * lhs ;///< Unresolved user input: mapping LHS, macro ("@q"), Visual op, or translation 73///< ("x" => "dl"). NULL: untranslated, same as `keys`. 74int undoseq ;///< Undo state at settlement. Not monotonic (decreases on undo). 75bool changed ;///< The command changed the buffer. 76bool moved ;///< The command moved the cursor. 77bool remap ;///< True if `keys` cannot replay (lossy/empty capture). Replay `lhs` instead. 78bool cascaded ;///< This atom already cascaded as spans: emit-only. 79}; 80 81/// Key classes (atom_key_class()). 82/// Flags, bc same char can mean different things per mode (CTRL-T: tag-jump vs i_CTRL-T indent). 83enum { 84kKeyOpaque = 1 <<0 ,///< Cmds not reified from subatoms (<Cmd>, K_LUA), plus kKeySynthetic. 85///< The cmd itself is the atom, else its only trace is its effect. 86kKeySynthetic = 1 <<1 ,///< Not a user keystroke (K_EVENT, K_IGNORE): unlike <Cmd>/K_LUA, never 87///< reaches us from a mapping. 88kKeyPayload = 1 <<2 ,///< Interactively-typed payload (/, ?, :, !). 89kKeyScrollMove = 1 <<3 ,///< Scroll may move cursor (C-D/…): viewport-dependent, unreplayable. 90kKeyScrollView = 1 <<4 ,///< Viewport-only scroll (C-Y,wheel): cursor stays, unless 'scrolloff'. 91kKeyJump = 1 <<5 ,///< Absolute motion (multiplexed "gg", "g;", …), see NV_JUMP. 92kKeyMotion = 1 <<6 ,///< Cursor-relative motion (multiplexed, special keys), see NV_MOTION. 93kKeyInsFlush = 1 <<7 ,///< Insert-mode cmd a literal preview cannot represent: 94///< - deletions/indent-shifts (<Del>, CTRL-W, …) may edit text 95///< outside the tracked region by per-cursor amounts; 96///< - cursor-moves (start_arrow()) move the insertion point itself. 97kKeyMouse = 1 <<8 ,///< Mouse button press (<LeftMouse>, …). Drag/release/move are the 98///< press's continuation: no class, invisible to capture. 99};