1
1
import type { Denops } from "https://deno.land/x/denops_core@v4.0.0/mod.ts" ;
2
2
import { execute } from "./execute.ts" ;
3
- import { batch } from "../batch/mod.ts" ;
4
3
import { generateUniqueString } from "../util.ts" ;
5
4
6
5
const cacheKey = Symbol ( "denops_std/helper/echo" ) ;
@@ -16,13 +15,15 @@ async function ensurePrerequisites(denops: Denops): Promise<string> {
16
15
let g:loaded_denops_std_helper_echo_${ suffix } = 1
17
16
let s:denops_std_helper_echo_timer = 0
18
17
19
- function! DenopsStdHelperEcho_${ suffix } (message) abort
18
+ function! DenopsStdHelperEcho_${ suffix } (message, highlight ) abort
20
19
call timer_stop(s:denops_std_helper_echo_timer)
21
- let s:denops_std_helper_echo_timer = timer_start(0, { -> s:DenopsStdHelperEchoInternal_${ suffix } (a:message) })
20
+ let s:denops_std_helper_echo_timer = timer_start(0, { -> s:DenopsStdHelperEchoInternal_${ suffix } (a:message, a:highlight ) })
22
21
endfunction
23
22
24
- function! s:DenopsStdHelperEchoInternal_${ suffix } (message) abort
23
+ function! s:DenopsStdHelperEchoInternal_${ suffix } (message, highlight) abort
24
+ if a:highlight !=# '' | execute 'echohl' a:highlight | endif
25
25
redraw | echo a:message
26
+ if a:highlight !=# '' | echohl None | endif
26
27
endfunction
27
28
` ;
28
29
await execute ( denops , script ) ;
@@ -201,11 +202,7 @@ export async function echoerr(
201
202
if ( denops . meta . mode === "test" ) {
202
203
return Promise . resolve ( ) ;
203
204
} else {
204
- await batch ( denops , async ( denops ) => {
205
- await denops . cmd ( "echohl ErrorMsg" ) ;
206
- await echoInternal ( denops , message ) ;
207
- await denops . cmd ( "echohl None" ) ;
208
- } ) ;
205
+ await echoInternal ( denops , message , "ErrorMsg" ) ;
209
206
}
210
207
}
211
208
@@ -250,7 +247,11 @@ export async function friendlyCall(
250
247
}
251
248
}
252
249
253
- async function echoInternal ( denops : Denops , message : string ) : Promise < void > {
250
+ async function echoInternal (
251
+ denops : Denops ,
252
+ message : string ,
253
+ highlight ?: string ,
254
+ ) : Promise < void > {
254
255
const suffix = await ensurePrerequisites ( denops ) ;
255
- await denops . call ( `DenopsStdHelperEcho_${ suffix } ` , message ) ;
256
+ await denops . call ( `DenopsStdHelperEcho_${ suffix } ` , message , highlight ?? "" ) ;
256
257
}
0 commit comments