11import type { Denops } from "https://deno.land/x/[email protected] /mod.ts" ; 22import { execute } from "./execute.ts" ;
3- import { batch } from "../batch/mod.ts" ;
43import { generateUniqueString } from "../util.ts" ;
54
65const cacheKey = Symbol ( "denops_std/helper/echo" ) ;
@@ -16,13 +15,15 @@ async function ensurePrerequisites(denops: Denops): Promise<string> {
1615 let g:loaded_denops_std_helper_echo_${ suffix } = 1
1716 let s:denops_std_helper_echo_timer = 0
1817
19- function! DenopsStdHelperEcho_${ suffix } (message) abort
18+ function! DenopsStdHelperEcho_${ suffix } (message, highlight ) abort
2019 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 ) })
2221 endfunction
2322
24- function! s:DenopsStdHelperEchoInternal_${ suffix } (message) abort
23+ function! s:DenopsStdHelperEchoInternal_${ suffix } (message, highlight) abort
24+ if a:highlight !=# '' | execute 'echohl' a:highlight | endif
2525 redraw | echo a:message
26+ if a:highlight !=# '' | echohl None | endif
2627 endfunction
2728 ` ;
2829 await execute ( denops , script ) ;
@@ -201,11 +202,7 @@ export async function echoerr(
201202 if ( denops . meta . mode === "test" ) {
202203 return Promise . resolve ( ) ;
203204 } 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" ) ;
209206 }
210207}
211208
@@ -250,7 +247,11 @@ export async function friendlyCall(
250247 }
251248}
252249
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 > {
254255 const suffix = await ensurePrerequisites ( denops ) ;
255- await denops . call ( `DenopsStdHelperEcho_${ suffix } ` , message ) ;
256+ await denops . call ( `DenopsStdHelperEcho_${ suffix } ` , message , highlight ?? "" ) ;
256257}
0 commit comments