3
3
" or selection and redirects output to a new buffer
4
4
" Author: Alexander Skachko <[email protected] >
5
5
" Homepage: https://github.com/lucerion/vim-executor
6
- " Version: 0.1
6
+ " Version: 0.2
7
7
" Licence: BSD-3-Clause
8
8
" ===========================================================================
9
9
10
10
let s: previous_buffer = ' '
11
11
12
- func ! executor#exec (start_line, end_line, count , ... )
12
+ func ! executor#exec (start_line, end_line, ... )
13
13
if ! exists (' g:loaded_buffr' )
14
14
call s: show_error (' Please, install vim-buffr plugin first' ) | return
15
15
endif
16
16
17
- call s: execute (a: start_line , a: end_line , a: count , a: 000 )
18
- endfunc
19
-
20
- func ! s: execute (start_line, end_line, count , command )
21
- let l: selection = s: selection (a: start_line , a: end_line )
22
- let l: command = s: command (a: command )
23
- let l: result = s: result (l: command , l: selection , a: count )
24
- let l: buffer_name = s: buffer_name (l: command )
25
-
26
- call s: open_result (l: result , l: buffer_name )
27
- endfunc
28
-
29
- func ! s: selection (start_line, end_line)
30
- return getline (a: start_line , a: end_line )
31
- endfunc
17
+ let l: command = join (a: 000 )
18
+ let l: selection = getline (a: start_line , a: end_line )
32
19
33
- func ! s: command ( command )
34
- let l: command = join ( a : command )
35
- if len ( substitute ( l: command , ' ' , ' ' , ' g ' ))
36
- return l: command
20
+ if g: executor_exec_async && ( v: version >= 800 )
21
+ call executor#async#exec ( l : command, l: selection )
22
+ else
23
+ call executor#default#exec ( l: command, l: selection )
37
24
end
38
-
39
- return g: executor_default_command
40
25
endfunc
41
26
42
- func ! s: result (command , selection , count )
43
- if len (a: selection ) == 1
44
- let l: command = a: command . ' ' . a: selection [0 ]
45
- return system (l: command )
46
- endif
47
-
48
- if a: count
49
- let l: selection = join (a: selection , " \n " ) . " \n "
50
- return system (a: command , l: selection )
51
- endif
52
-
53
- return system (a: command )
27
+ func ! executor#open_result (result, command )
28
+ let l: buffer_name = s: buffer_name (a: command )
29
+ call s: open_buffer (l: buffer_name )
30
+ call append (0 , a: result )
31
+ silent normal ! Gddgg
54
32
endfunc
55
33
56
- func ! s: open_result (result, buffer_name)
34
+ func ! s: open_buffer ( buffer_name)
57
35
let l: buffer_name = a: buffer_name
58
36
59
37
if g: executor_reuse_buffer
@@ -64,25 +42,23 @@ func! s:open_result(result, buffer_name)
64
42
endif
65
43
66
44
call buffr#open_or_create_buffer ({
67
- \ ' position' : g: executor_position ,
45
+ \ ' position' : ' bottom ' ,
68
46
\ ' name' : l: buffer_name
69
47
\ })
70
48
call s: set_buffer_defaults ()
71
49
72
50
if g: executor_reuse_buffer
73
51
silent exec ' edit ' . escape (s: previous_buffer , ' ' )
74
52
endif
75
-
76
- call append (0 , split (a: result , " \n " ))
77
- silent exec ' normal! Gdd'
78
53
endfunc
79
54
80
55
func ! s: buffer_name (command )
81
- let l: buffer_name = g: executor_buffer_name
82
- let l: buffer_name = substitute (l: buffer_name , ' {command}' , a: command , ' g' )
83
- let l: buffer_name = substitute (l: buffer_name , ' {filename}' , expand (' %:t' ), ' g' )
56
+ let l: name = g: executor_buffer_name
57
+ let l: name = substitute (l: name , ' {command}' , a: command , ' g' )
58
+ let l: name = substitute (l: name , ' {filename}' , expand (' %:t' ), ' g' )
59
+ let l: name = escape (l: name , ' |' )
84
60
85
- return escape ( l: buffer_name , ' | ' )
61
+ return l: name
86
62
endfunc
87
63
88
64
func ! s: set_buffer_defaults ()
0 commit comments