Skip to content

Commit 4f7c871

Browse files
committed
add quick int types
1 parent 2bc761c commit 4f7c871

File tree

2 files changed

+54
-16
lines changed

2 files changed

+54
-16
lines changed

README.md

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ ls.setup({
2828

2929
## Snippets
3030

31-
Snippets which trigger ends with "!" are `autosnippet`.
32-
3331
<details>
3432
<summary>All</summary>
3533

@@ -48,20 +46,33 @@ Snippets which trigger ends with "!" are `autosnippet`.
4846

4947
#### Normal Snippets
5048

51-
| Trig | Desc | Context Required |
52-
| :--------: | ------------------------------------------------------------------------------------------------ | :---------------------------: |
53-
| `ctor!` | Expand to default constructor | In Class |
54-
| `dtor!` | Expand to default destructor | In Class |
55-
| `cc!` | Expand to default copy constructor | In Class |
56-
| `mv!` | Expand to default move constructor | In Class |
57-
| `ncc!` | Expand to delete copy constructor | In Class |
58-
| `nmv!` | Expand to delete move constructor | In Class |
59-
| `ncm!` | Expand to delete copy and move constructor | In Class |
60-
| `fn` | Expand to lambda function in argument list or function body, otherwise expand to normal function | No |
61-
| `\|trans` | Expand to ranges::views::transform pipe. | No |
62-
| `\|filter` | Expand to ranges::views::filter pipe. | No |
63-
| `cpo` | Expand to customize point object. | No |
64-
| `once` | Expand to `pragma once` marker at the front of the file. | All lines before are comments |
49+
| Trig | Desc | Context Required |
50+
| :--------: | ------------------------------------------------------------------------------------------------ | :--------------: |
51+
| `fn` | Expand to lambda function in argument list or function body, otherwise expand to normal function | No |
52+
| `\|trans` | Expand to ranges::views::transform pipe. | No |
53+
| `\|filter` | Expand to ranges::views::filter pipe. | No |
54+
| `cpo` | Expand to customize point object. | No |
55+
56+
#### Auto-snippets
57+
58+
| Trig | Desc | Context Required |
59+
| :-----: | -------------------------------------------------------- | :---------------------------: |
60+
| `ctor!` | Expand to default constructor | In Class |
61+
| `dtor!` | Expand to default destructor | In Class |
62+
| `cc!` | Expand to default copy constructor | In Class |
63+
| `mv!` | Expand to default move constructor | In Class |
64+
| `ncc!` | Expand to delete copy constructor | In Class |
65+
| `nmv!` | Expand to delete move constructor | In Class |
66+
| `ncm!` | Expand to delete copy and move constructor | In Class |
67+
| `once` | Expand to `pragma once` marker at the front of the file. | All lines before are comments |
68+
| `u8` | Expand to `uint8_t`. | No |
69+
| `u16` | Expand to `uint16_t`. | No |
70+
| `u32` | Expand to `uint32_t`. | No |
71+
| `u64` | Expand to `uint64_t`. | No |
72+
| `i8` | Expand to `int8_t`. | No |
73+
| `i16` | Expand to `int16_t`. | No |
74+
| `i32` | Expand to `int32_t`. | No |
75+
| `i64` | Expand to `int64_t`. | No |
6576

6677
#### Postfix Snippets
6778

lua/luasnip-snippets/snippets/cpp/default.lua

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,23 @@ local function cpo_snippet()
4747
}
4848
end
4949

50+
---@param bits number
51+
---@param unsigned boolean
52+
local function int_type_snippet(bits, unsigned)
53+
local prefix = unsigned and "u" or ""
54+
local trig = (unsigned and "u" or "i") .. bits
55+
local expand = ("%sint%s_t"):format(prefix, bits)
56+
return snippet {
57+
trig,
58+
name = ("(%s) %s"):format(trig, expand),
59+
desc = ("Expands to %s"):format(expand),
60+
mode = "wA",
61+
nodes = {
62+
t(expand),
63+
},
64+
}
65+
end
66+
5067
---@param trig string
5168
---@param func string
5269
local function ranges_views_snippet(trig, func)
@@ -95,4 +112,14 @@ return {
95112
t { "#pragma once // NOLINT(build/header_guard)", "" },
96113
},
97114
},
115+
116+
-- fast int types
117+
int_type_snippet(8, true),
118+
int_type_snippet(8, false),
119+
int_type_snippet(16, true),
120+
int_type_snippet(16, false),
121+
int_type_snippet(32, true),
122+
int_type_snippet(32, false),
123+
int_type_snippet(64, true),
124+
int_type_snippet(64, false),
98125
}

0 commit comments

Comments
 (0)