Skip to content

Commit 0cce3fc

Browse files
committed
👍 add AutocmdPattern type
1 parent 3a7a7be commit 0cce3fc

File tree

4 files changed

+27
-10
lines changed

4 files changed

+27
-10
lines changed

autocmd/_utils.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1-
import type { AutocmdEvent, DefineOptions, RemoveOptions } from "./types.ts";
1+
import type {
2+
AutocmdEvent,
3+
AutocmdPattern,
4+
DefineOptions,
5+
RemoveOptions,
6+
} from "./types.ts";
27

38
export function buildDefineExpr(
49
event: AutocmdEvent | readonly AutocmdEvent[],
5-
pat: string | readonly string[],
10+
pat: AutocmdPattern | readonly AutocmdPattern[],
611
cmd: string,
712
options: DefineOptions = {},
813
): string {
@@ -32,7 +37,7 @@ export function buildDefineExpr(
3237

3338
export function buildRemoveExpr(
3439
event?: "*" | AutocmdEvent | readonly AutocmdEvent[],
35-
pat?: string | readonly string[],
40+
pat?: AutocmdPattern | readonly AutocmdPattern[],
3641
options: RemoveOptions = {},
3742
): string {
3843
const terms = ["au!"];

autocmd/common.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { Denops } from "@denops/core";
22
import type {
33
AutocmdEvent,
4+
AutocmdPattern,
45
DefineOptions,
56
EmitOptions,
67
ListOptions,
@@ -42,7 +43,7 @@ import { buildDefineExpr, buildRemoveExpr } from "./_utils.ts";
4243
export async function define(
4344
denops: Denops,
4445
event: AutocmdEvent | readonly AutocmdEvent[],
45-
pat: string | readonly string[],
46+
pat: AutocmdPattern | readonly AutocmdPattern[],
4647
cmd: string,
4748
options: DefineOptions = {},
4849
): Promise<void> {
@@ -77,7 +78,7 @@ export async function define(
7778
export async function remove(
7879
denops: Denops,
7980
event?: "*" | AutocmdEvent | readonly AutocmdEvent[],
80-
pat?: string | readonly string[],
81+
pat?: AutocmdPattern | readonly AutocmdPattern[],
8182
options: RemoveOptions = {},
8283
): Promise<void> {
8384
const expr = buildRemoveExpr(event, pat, options);
@@ -109,7 +110,7 @@ export async function remove(
109110
export async function list(
110111
denops: Denops,
111112
event?: "*" | AutocmdEvent | readonly AutocmdEvent[],
112-
pat?: string | readonly string[],
113+
pat?: AutocmdPattern | readonly AutocmdPattern[],
113114
options: ListOptions = {},
114115
): Promise<unknown> {
115116
const terms = ["au"];
@@ -126,7 +127,7 @@ export async function list(
126127
if (Array.isArray(pat)) {
127128
terms.push(pat.join(","));
128129
} else {
129-
terms.push(pat as string);
130+
terms.push(pat as AutocmdPattern);
130131
}
131132
}
132133
}

autocmd/group.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import type { Denops } from "@denops/core";
22
import { execute } from "../helper/execute.ts";
3-
import type { AutocmdEvent, DefineOptions, RemoveOptions } from "./types.ts";
3+
import type {
4+
AutocmdEvent,
5+
AutocmdPattern,
6+
DefineOptions,
7+
RemoveOptions,
8+
} from "./types.ts";
49
import { buildDefineExpr, buildRemoveExpr } from "./_utils.ts";
510

611
export type GroupDefineOptions = Omit<DefineOptions, "group">;
@@ -73,7 +78,7 @@ class GroupHelper {
7378
*/
7479
define(
7580
event: AutocmdEvent | readonly AutocmdEvent[],
76-
pat: string | readonly string[],
81+
pat: AutocmdPattern | readonly AutocmdPattern[],
7782
cmd: string,
7883
options: GroupDefineOptions = {},
7984
): void {
@@ -85,7 +90,7 @@ class GroupHelper {
8590
*/
8691
remove(
8792
event?: "*" | AutocmdEvent | readonly AutocmdEvent[],
88-
pat?: string | readonly string[],
93+
pat?: AutocmdPattern | readonly AutocmdPattern[],
8994
options: GroupRemoveOptions = {},
9095
): void {
9196
this.#commands.push(buildRemoveExpr(event, pat, options));

autocmd/types.ts

+6
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,12 @@ export type AutocmdEvent =
119119
| "WinNew"
120120
| "WinScrolled";
121121

122+
export type AutocmdPattern =
123+
| AnyString
124+
| "<buffer>"
125+
| "<buffer=abuf>"
126+
| `<buffer=${number}>`;
127+
122128
interface CommonOptions {
123129
group?: string;
124130
}

0 commit comments

Comments
 (0)