Very Popular
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175import { Denops } from "https://deno.land/x/denops_core@v3.0.1/mod.ts";import { AutocmdEvent } from "./types.ts";
type CommonOptions = { group?: string;};
export type DefineOptions = CommonOptions & { once?: boolean; nested?: boolean;};
export type RemoveOptions = CommonOptions;
export type ListOptions = CommonOptions;
export type EmitOptions = CommonOptions & { nomodeline?: boolean;};
export async function define( denops: Denops, event: AutocmdEvent | AutocmdEvent[], pat: string | string[], cmd: string, options: DefineOptions = {},): Promise<void> { const expr = buildDefineExpr(event, pat, cmd, options); await denops.cmd(expr);}
export async function remove( denops: Denops, event?: "*" | AutocmdEvent | AutocmdEvent[], pat?: string | string[], options: RemoveOptions = {},): Promise<void> { const expr = buildRemoveExpr(event, pat, options); await denops.cmd(expr);}
export async function list( denops: Denops, event?: "*" | AutocmdEvent | AutocmdEvent[], pat?: string | string[], options: ListOptions = {},): Promise<unknown> { const terms = ["au"]; if (options.group) { terms.push(options.group); } if (event) { if (Array.isArray(event)) { terms.push(event.join(",")); } else { terms.push(event); } if (pat) { if (Array.isArray(pat)) { terms.push(pat.join(",")); } else { terms.push(pat); } } } const expr = terms.join(" "); return await denops.call("execute", expr);}
export async function emit( denops: Denops, event: AutocmdEvent | AutocmdEvent[], fname?: string, options: EmitOptions = {},): Promise<unknown> { const terms = ["do"]; if (options.nomodeline) { terms.push("<nomodeline>"); } if (options.group) { terms.push(options.group); } if (Array.isArray(event)) { terms.push(event.join(",")); } else { terms.push(event); } if (fname) { terms.push(fname); } const expr = terms.join(" "); return await denops.cmd(expr);}
export async function emitAll( denops: Denops, event: AutocmdEvent | AutocmdEvent[], fname?: string, options: EmitOptions = {},): Promise<unknown> { const terms = ["doautoa"]; if (options.nomodeline) { terms.push("<nomodeline>"); } if (options.group) { terms.push(options.group); } if (Array.isArray(event)) { terms.push(event.join(",")); } else { terms.push(event); } if (fname) { terms.push(fname); } const expr = terms.join(" "); return await denops.cmd(expr);}
export function buildDefineExpr( event: AutocmdEvent | AutocmdEvent[], pat: string | string[], cmd: string, options: DefineOptions = {},): string { const terms = ["au"]; if (options.group) { terms.push(options.group); } if (Array.isArray(event)) { terms.push(event.join(",")); } else { terms.push(event); } if (Array.isArray(pat)) { terms.push(pat.join(",")); } else { terms.push(pat); } if (options.once) { terms.push("++once"); } if (options.nested) { terms.push("++nested"); } terms.push(cmd); return terms.join(" ");}
export function buildRemoveExpr( event?: "*" | AutocmdEvent | AutocmdEvent[], pat?: string | string[], options: RemoveOptions = {},): string { const terms = ["au!"]; if (options.group) { terms.push(options.group); } if (event) { if (Array.isArray(event)) { terms.push(event.join(",")); } else { terms.push(event); } if (pat) { if (Array.isArray(pat)) { terms.push(pat.join(",")); } else { terms.push(pat); } } } return terms.join(" ");}