Skip to content

Commit ba82f78

Browse files
committed
👍 Add echoerr to helper module
1 parent cee661d commit ba82f78

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

denops_std/helper/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
## Usage
88

9-
### echo
9+
### echo / echoerr
1010

1111
Use `echo()` to show messages on the cmdline area. It is required while Vim
1212
won't show messages reported from channel commands and it won't pause multi-line
@@ -18,10 +18,11 @@ properly show multi-line messages with `echomsg` from asynchronous context.
1818

1919
```typescript
2020
import { Denops } from "https://deno.land/x/denops_std/mod.ts";
21-
import { echo } from "https://deno.land/x/denops_std/helper/mod.ts";
21+
import { echo, echoerr } from "https://deno.land/x/denops_std/helper/mod.ts";
2222

2323
export async function main(denops: Denops): Promise<void> {
2424
await echo(denops, "Hello\nWorld!");
25+
await echoerr(denops, "This is error message");
2526
}
2627
```
2728

denops_std/helper/echo.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { deferred, Denops } from "../deps.ts";
22
import * as anonymous from "../anonymous/mod.ts";
3+
import { batch } from "../batch/mod.ts";
34
import { load } from "./load.ts";
45

56
/**
@@ -23,6 +24,20 @@ export function echo(denops: Denops, message: string): Promise<void> {
2324
}
2425
}
2526

27+
/**
28+
* Echo message as an error message.
29+
*
30+
* Note that this function just use ErrorMsg highlight and is not equivalent
31+
* to `echoerr` command in Vim/Neovim.
32+
*/
33+
export async function echoerr(denops: Denops, message: string): Promise<void> {
34+
await batch(denops, async (denops) => {
35+
await denops.cmd("echohl ErrorMsg");
36+
await echo(denops, message);
37+
await denops.cmd("echohl None");
38+
});
39+
}
40+
2641
async function echoVim(denops: Denops, message: string): Promise<void> {
2742
await load(denops, new URL("./echo.vim", import.meta.url));
2843
const waiter = deferred<void>();

0 commit comments

Comments
 (0)