robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
6423657352
master
1#pragma once 2 3#include <stdbool.h> 4#include <stddef.h> 5#include <stdint.h> 6 7#include "nvim/api/private/defs.h" 8#include "nvim/types_defs.h" 9 10/// Readahead ("stuff") buffer: consumable queue of keys in typeahead encoding (K_SPECIAL 11/// escaped). add_buff() writes at `insert`, read_readbuf() consumes from `read`. 12typedef struct { 13StringBuilder keys ;///< Bytes; `[read, keys.size)` is unread. 14size_t read ;///< Read position: consumed up to here. Reset (keeping capacity) on drain. 15size_t insert ;///< Write position: `keys.size`, or the read position as of start_stuff() 16///< (newly stuffed keys drain before older readahead). 17}StuffBuf ; 18 19/// Represents any command. Projection of (`cmdarg_T`, `oparg_T`), which are stack-transient. 20/// 21/// Used two ways: 22/// - Capture (prep_redo()): the command appends its own bytes to the redo body; only `regname` 23/// and `count` are functional (the `["x][count]` prefix), the rest is CmdAtom metadata. 24/// - Reconstruction (atom_from_spec()): a "non-prepped" command ("u", motions) has no body, so 25/// atom_redo_keys() composes the keysequence fully from the spec. 26typedef struct { 27long count ;///< Effective count (0 = none) 28int regname ;///< Register (`"x` prefix; 0 = none) 29int op ;///< Operator char ('d'; 0 = none) 30int op_extra ;///< Second operator char ("g~" => '~'; 0 = none) 31int motion_force ;///< Forced motion type ('v'/'V'/CTRL-V; 0 = none) 32int cmd ;///< Command/motion char ('J', 'p', 'f', K_LEFT, …; 0 = none) 33int cmd2 ;///< Command char 2 (for two-char cmds: "gJ" => 'J'; 0 = none) 34int cmdarg ;///< Command operand ("fx" => 'x', "ma" => 'a'; 0 = none) 35StringBuilder body ;///< Captured cmd "body": keys without the `["x][count]` "prefix", updated 36///< as the cmd executes (redo_append_xx); redo_keys() prepends the prefix. 37///< Empty in spec-only contexts (i.e. not a "redo" buf). 38}CmdSpec ; 39 40/// Dot-repeat state: the pending change and the previous one. 41/// Also the "save" shape for preserving it across user code (save_redobuff()). 42typedef struct { 43CmdSpec cur ;///< Pending change: "." replays it (start_redo()). 44CmdSpec old ;///< Last-but-one change: an insert session's own prep moved the previous change 45///< here (redo_new()); "i_CTRL-O ." replays it. 46}RedoState ; 47 48/// Used for the typeahead buffer: typebuf. 49typedef struct { 50uint8_t * tb_buf ;///< buffer for typed characters 51uint8_t * tb_noremap ;///< mapping flags for characters in tb_buf[] 52int tb_buflen ;///< size of tb_buf[] 53int tb_off ;///< current position in tb_buf[] 54int tb_len ;///< number of valid bytes in tb_buf[] 55int tb_maplen ;///< nr of mapped bytes in tb_buf[] 56int tb_silent ;///< nr of silently mapped bytes in tb_buf[] 57int tb_no_abbr_cnt ;///< nr of bytes without abbrev. in tb_buf[] 58int tb_change_cnt ;///< nr of time tb_buf was changed; never zero 59}typebuf_T ; 60 61/// Char put back by vungetc() (`c == -1`: none), with the read state restored when it is re-read: 62/// a later input event must not leak its mod_mask/mouse coords into the ungot key. 63typedef struct { 64int c ;///< -1: none 65int mod_mask ; 66int mouse_grid ; 67int mouse_row ; 68int mouse_col ; 69bool stuffed ;///< `KeyStuffed` when ungotten. 70}UngotKey ; 71 72/// Struct to hold the saved typeahead for save_typeahead(). 73typedef struct { 74typebuf_T save_typebuf ; 75UngotKey ungot ; 76StuffBuf save_readbuf1 ; 77StuffBuf save_readbuf2 ; 78}tasave_T ; 79 80/// Values for "noremap" argument of ins_typebuf() 81/// 82/// Also used for map->m_noremap and menu->noremap[]. 83enum RemapValues { 84REMAP_YES = 0 ,///< Allow remapping. 85REMAP_NONE = -1 ,///< No remapping. 86REMAP_SCRIPT = -2 ,///< Remap script-local mappings only. 87REMAP_SKIP = -3 ,///< No remapping for first char. 88};