robin/laufey

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

zeertzjqMerge pull request #39741 from zeertzjq/vim-9.2.0470228e6ca32a

master
2.2 KiB85 linesraw
1#pragma once
2
3#include "nvim/ascii_defs.h"
4#include "nvim/ex_cmds_defs.h"  // IWYU pragma: keep
5#include "nvim/macros_defs.h"
6#include "nvim/register_defs.h"
7
8/// Used by TextPutPost/TextPutPre autocommands for the '.' register. If
9/// "add_last_insert" is == 1, then "stuff_inserted" will add the last inserted
10/// text to "last_insert_ga".
11EXTERN garray_T last_insert_ga INIT( = { 0, 0, 1, 64, NULL });
12EXTERN int add_last_insert INIT( = 0);
13
14#include "register.h.generated.h"
15#include "register.h.inline.generated.h"
16
17/// @see get_yank_register
18/// @return  true when register should be inserted literally
19/// (selection or clipboard)
20static inline bool is_literal_register(const int regname)
21  FUNC_ATTR_CONST
22{
23  return regname == '*' || regname == '+' || ASCII_ISALNUM(regname);
24}
25
26/// Convert register name into register index
27///
28/// @param[in]  regname  Register name.
29///
30/// @return Index in y_regs array or -1 if register name was not recognized.
31static inline int op_reg_index(const int regname)
32  FUNC_ATTR_CONST
33{
34  if (ascii_isdigit(regname)) {
35    return regname - '0';
36  } else if (ASCII_ISLOWER(regname)) {
37    return CHAR_ORD_LOW(regname) + 10;
38  } else if (ASCII_ISUPPER(regname)) {
39    return CHAR_ORD_UP(regname) + 10;
40  } else if (regname == '-') {
41    return DELETION_REGISTER;
42  } else if (regname == '*') {
43    return STAR_REGISTER;
44  } else if (regname == '+') {
45    return PLUS_REGISTER;
46  } else {
47    return -1;
48  }
49}
50
51static inline bool is_append_register(int regname)
52  FUNC_ATTR_CONST
53{
54  return ASCII_ISUPPER(regname);
55}
56
57/// @return  the character name of the register with the given number
58static inline int get_register_name(int num)
59  FUNC_ATTR_CONST
60{
61  if (num == -1) {
62    return '"';
63  } else if (num < 10) {
64    return num + '0';
65  } else if (num == DELETION_REGISTER) {
66    return '-';
67  } else if (num == STAR_REGISTER) {
68    return '*';
69  } else if (num == PLUS_REGISTER) {
70    return '+';
71  } else {
72    return num + 'a' - 10;
73  }
74}
75
76/// Check whether register is empty
77static inline bool reg_empty(const yankreg_T *const reg)
78  FUNC_ATTR_PURE
79{
80  return (reg->y_array == NULL
81          || reg->y_size == 0
82          || (reg->y_size == 1
83              && reg->y_type == kMTCharWise
84              && reg->y_array[0].size == 0));
85}