Skip to content

Commit

Permalink
more exam
Browse files Browse the repository at this point in the history
  • Loading branch information
lymslive committed Dec 25, 2018
1 parent 198acd1 commit 257dbb6
Show file tree
Hide file tree
Showing 9 changed files with 124 additions and 0 deletions.
17 changes: 17 additions & 0 deletions example/ch08/job_ls.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

function! OnWorking(job, msg)
echomsg 'well work doing:' . a:msg
let g:dir_list .= a:msg . "\n"
endfunction

function! DoneWork(job)
echomsg 'well work done:'
echomsg g:dir_list
" echo g:dir_list
endfunction

function! StartWork()
let g:dir_list = ''
let l:option = {'callback': 'OnWorking', 'close_cb': 'DoneWork'}
let g:job_ls = job_start('ls', l:option)
endfunction
9 changes: 9 additions & 0 deletions example/ch08/timerwork.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
function! SlowWork()
call timer_start(5*1000, 'DoneWork')
endfunction

function! DoneWork(timer)
echo "done!!"
endfunction

call SlowWork()
8 changes: 8 additions & 0 deletions example/ch09/catn.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#! /usr/bin/env perl
# 为文本行编号,按标准输入输出,适于 vim 过滤器
# 可选参数一指定分隔符,参数二指定间隔空白量(默认一个 tab)

my $sep = shift || "";
my $num = shift || 0;
$sep .= ($num > 0) ? (" " x $num) : "\t";
while (<>) { print "$.$sep$_"; }
19 changes: 19 additions & 0 deletions example/ch09/ifperl.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

function! s:execute(a:code) abort
let l:perl = 'perl ' . a:code
let l:ifstdout = ''
let v:errmsg = ''
redir => l:ifstdout
silent! execute l:perl
redir END
if v:errmsg
return ''
endif
return l:ifstdout
endfunction

function! s:call(func, ...) abort
let l:args = join(a:000, ',')
let l:code = printf('%s(%s);', a:func, l:args)
return s:execute(l:code)
endfunction
25 changes: 25 additions & 0 deletions example/ch09/perlfunc.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
if !has('perl')
finish
endif

function! PerlFunc()
if has('perl')
perl << EOF
print $^V; # 打印版本号
print "$_\n" for @INC; # 打印所有模块搜索路径
print "$_ = $ENV{$_}" for sort keys %ENV; # 打印所有环境变量
EOF
endif
endfunction

if has('perl')

function! PerlFunc1()
" todo
endfunction

function! PerlFunc2()
" todo
endfunction

endif
6 changes: 6 additions & 0 deletions example/ch10/autoload/vip/config.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
" let 命令定义默认变量值
" 用户可以在 ~/.vim 相应目录下提供自己的配置

function! vip#config#load()
return 1
endfunction
17 changes: 17 additions & 0 deletions example/ch10/autoload/vip/ftplugin.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
call vip#plugin#load()

function! vip#ftplugin#onft(filetype, ...)
if a:filetype ==? 'cpp'
return vip#ftplugin#onCPP()
endif
endfunction

function! vip#ftplugin#onCPP()
" setlocal ...
" map <buffer> ...
" command -beffur ...
endfunction

function! vip#ftplugin#load()
return 1
endfunction
14 changes: 14 additions & 0 deletions example/ch10/autoload/vip/plugin.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

call vip#config#load()

" map 映射定义
" command 命令定义,调用其他 vip# 函数

augroup VIP_FILETYPE
autocmd!
autocmd BufNewFile,BufRead *.vip,*.vip.txt setlocal filetype=vip
augroup END

function! vip#plugin#load()
return 1
endfunction
9 changes: 9 additions & 0 deletions example/ch10/optdef.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
if !exists('g:plugin_name_argument')
let g:plugin_name_argument = s:default_argument_value
endif

function! s:optdef(argument, default)
if !has_key(g:, a:argument)
let g:{a:argument} = a:default
end
endfunction

0 comments on commit 257dbb6

Please sign in to comment.