robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

robinmerge: 1dc9728daa1d8a2702

master
5.8 KiB123 linesraw
1#pragma once
2
3#include <stdbool.h>
4
5#include "nvim/pos_defs.h"
6#include "nvim/types_defs.h"
7
8// Values for cmd_flags.
9#define NV_NCH      0x01            // May need to get a second char.
10#define NV_NCH_NOP  (0x02|NV_NCH)   // Get second char when no operator pending.
11#define NV_NCH_ALW  (0x04|NV_NCH)   // Always get a second char.
12#define NV_LANG     0x08            // Second char needs language adjustment.
13#define NV_SS       0x10            // May start selection.
14#define NV_SSS      0x20            // May start selection with shift modifier.
15#define NV_STS      0x40            // May stop selection without shift modif.
16#define NV_RL       0x80            // 'rightleft' modifies command.
17#define NV_KEEPREG  0x100           // Don't clear regname.
18#define NV_NCW      0x200           // Not allowed in command-line window.
19#define NV_NCH_ARG  0x400           // Second char is a typed operand (mark/reg name), not part of
20                                    // the name (see NV_LANG for f/t/r).
21#define NV_MOTION   0x800           // Cursor-relative motion.
22#define NV_JUMP     0x1000          // Absolute motion, target independent of the cursor ("G").
23
24/// Motion types, used for operators and for yank/delete registers.
25///
26/// The three valid numerical values must not be changed, as they
27/// are used in external communication and serialization.
28typedef enum {
29  kMTCharWise = 0,     ///< character-wise movement/register
30  kMTLineWise = 1,     ///< line-wise movement/register
31  kMTBlockWise = 2,    ///< block-wise movement/register
32  kMTUnknown = -1,     ///< Unknown or invalid motion type
33} MotionType;
34
35/// Arguments for operators.
36typedef struct {
37  int op_type;             ///< current pending operator type
38  int regname;             ///< register to use for the operator
39  MotionType motion_type;  ///< type of the current cursor motion
40  int motion_force;        ///< force motion type: 'v', 'V' or CTRL-V
41  bool use_reg_one;        ///< true if delete uses reg 1 even when not
42                           ///< linewise
43  bool inclusive;          ///< true if char motion is inclusive (only
44                           ///< valid when motion_type is kMTCharWise)
45  bool end_adjusted;       ///< backuped b_op_end one char (only used by
46                           ///< do_format())
47  pos_T start;             ///< start of the operator
48  pos_T end;               ///< end of the operator
49  pos_T cursor_start;      ///< cursor position before motion for "gw"
50  bool restore_cursor;     ///< restore cursor after yank
51
52  linenr_T line_count;     ///< number of lines from op_start to op_end (inclusive)
53  bool empty;              ///< op_start and op_end the same (only used by op_change())
54  bool is_VIsual;          ///< operator on Visual area
55  bool from_visual;        ///< Started in Visual. For "zq" (which ends Visual, to accept a motion).
56  colnr_T start_vcol;      ///< start col for block mode operator
57  colnr_T end_vcol;        ///< end col for block mode operator
58  int prev_opcount;        ///< ca.opcount saved for K_EVENT
59  int prev_count0;         ///< ca.count0 saved for K_EVENT
60  bool excl_tr_ws;         ///< exclude trailing whitespace for yank of a block
61} oparg_T;
62
63/// Arguments for Normal mode commands.
64typedef struct {
65  oparg_T *oap;     ///< Operator arguments
66  int prechar;      ///< prefix character (optional, always 'g')
67  int cmdchar;      ///< command character
68  int nchar;        ///< next command character (optional)
69  char nchar_composing[MAX_SCHAR_SIZE];  ///< next char with composing chars (optional)
70  int nchar_len;    ///< len of nchar_composing (when zero, use nchar instead)
71  int extra_char;   ///< yet another character (optional)
72  int opcount;      ///< count before an operator
73  int count0;       ///< count before command, default 0
74  int count1;       ///< count before command, default 1
75  int arg;          ///< extra argument from nv_cmds[]
76  int retval;       ///< return: CA_* values
77  char *searchbuf;  ///< return: pointer to search pattern or NULL
78} cmdarg_T;
79
80/// values for retval:
81enum {
82  CA_COMMAND_BUSY  = 1,  ///< skip restarting edit() once
83  CA_NO_ADJ_OP_END = 2,  ///< don't adjust operator end
84};
85
86/// A Visual selection's mode and extent (line/column span, not absolute positions), so an
87/// equal-sized region can be re-applied starting at the cursor: {count}v reselect.
88typedef struct {
89  int mode;             ///< 'v', 'V', or Ctrl-V
90  linenr_T line_count;  ///< number of lines
91  colnr_T vcol;         ///< number of cols or end column (MAXCOL: to end of line)
92} VisualExtent;
93
94/// Visual/Select mode state, as one global "group" (Visual).
95typedef struct {
96  pos_T start;            ///< Start position of the active Visual selection.
97  bool active;            ///< Whether Visual mode is active.
98  bool select;            ///< Whether Select mode is active.
99  int select_reg;         ///< Register name for Select mode.
100  bool select_exclu_adj;  ///< Cursor was incremented during exclusive selection.
101  int restart_select;     ///< Restart Select mode when next cmd finished.
102  bool need_end;          ///< End Visual mode when the cmd finishes.
103  int reselect;           ///< Restart the selection after a Select-mode mapping or menu.
104  int mode;               ///< Type of Visual mode: 'v', 'V', Ctrl-V.
105  VisualExtent resel;     ///< Previous Visual area's extent, for {count}v reselect.
106} VisualState;
107
108/// Visual area. The region when Visual mode ended, or the active region (visualinfo()).
109typedef struct {
110  pos_T vi_start;       ///< Start pos.
111  pos_T vi_end;         ///< End position.
112  int vi_mode;          ///< Visual.mode.
113  colnr_T vi_curswant;  ///< MAXCOL from w_curswant.
114} visualinfo_T;
115
116/// Replacement for nchar used by nv_replace().
117enum {
118  REPLACE_CR_NCHAR  = -1,
119  REPLACE_NL_NCHAR  = -2,
120};
121
122enum { SHOWCMD_COLS = 10, };  ///< columns needed by shown command
123enum { SHOWCMD_BUFLEN = SHOWCMD_COLS + 1 + 30, };