Skip to content

Commit 51c8870

Browse files
author
skywind3000
committed
externalize program scripts
1 parent 352ad25 commit 51c8870

File tree

2 files changed

+51
-4
lines changed

2 files changed

+51
-4
lines changed

autoload/asyncrun/program/echo.vim

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
"======================================================================
2+
"
3+
" echo.vim -
4+
"
5+
" Created by skywind on 2021/12/18
6+
" Last Modified: 2021/12/18 04:17:39
7+
"
8+
"======================================================================
9+
10+
" echom "test load"
11+
12+
13+
function! asyncrun#program#echo#translate(opts)
14+
return 'echo (' . a:opts.cmd . ')'
15+
endfunc
16+
17+

plugin/runner_load.vim renamed to plugin/script_load.vim

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"======================================================================
22
"
3-
" runner_load.vim -
3+
" script_load.vim - load scripts in autoload/asyncrun/{runner,program}
44
"
55
" Created by skywind on 2021/12/15
66
" Last Modified: 2021/12/15 05:40:55
@@ -15,14 +15,15 @@
1515
"----------------------------------------------------------------------
1616
let g:asyncrun_event = get(g:, 'asyncrun_event', {})
1717
let g:asyncrun_runner = get(g:, 'asyncrun_runner', {})
18+
let g:asyncrun_program = get(g:, 'asyncrun_program', {})
1819
let s:script_time = {}
1920

2021

2122
"----------------------------------------------------------------------
2223
" find script
2324
"----------------------------------------------------------------------
24-
function! s:find_script(name)
25-
let test = 'autoload/asyncrun/runner/' . a:name . '.vim'
25+
function! s:find_script(where, name)
26+
let test = 'autoload/asyncrun/' . a:where . '/' . a:name . '.vim'
2627
let fn = findfile(test, &rtp)
2728
if fn == ''
2829
return ''
@@ -38,7 +39,7 @@ endfunc
3839
"----------------------------------------------------------------------
3940
function! s:load_runner(name)
4041
let name = a:name
41-
let load = s:find_script(name)
42+
let load = s:find_script('runner', name)
4243
let test = 'asyncrun#runner#' . name . '#run'
4344
if filereadable(load) && load != ''
4445
let mtime = getftime(load)
@@ -54,6 +55,27 @@ function! s:load_runner(name)
5455
endfunc
5556

5657

58+
"----------------------------------------------------------------------
59+
" load program
60+
"----------------------------------------------------------------------
61+
function! s:load_program(name)
62+
let name = a:name
63+
let load = s:find_script('program', name)
64+
let test = 'asyncrun#program#' . name . '#translate'
65+
if filereadable(load) && load != ''
66+
let mtime = getftime(load)
67+
let ltime = get(s:script_time, load, 0)
68+
if mtime > ltime
69+
exec 'source ' . fnameescape(load)
70+
let s:script_time[load] = mtime
71+
endif
72+
if exists('*' . test)
73+
let g:asyncrun_program[name] = test
74+
endif
75+
endif
76+
endfunc
77+
78+
5779
"----------------------------------------------------------------------
5880
" init runner
5981
"----------------------------------------------------------------------
@@ -63,3 +85,11 @@ endfunc
6385

6486

6587

88+
"----------------------------------------------------------------------
89+
" init program
90+
"----------------------------------------------------------------------
91+
function! g:asyncrun_event.program(name)
92+
call s:load_program(a:name)
93+
endfunc
94+
95+

0 commit comments

Comments
 (0)