33" or selection and redirects output to a new buffer
44" Author: Alexander Skachko <alexander.skachko@gmail.com>
55" Homepage: https://github.com/lucerion/vim-executor
6- " Version: 0.1
6+ " Version: 0.2
77" Licence: BSD-3-Clause
88" ===========================================================================
99
1010let s: previous_buffer = ' '
1111
12- func ! executor#exec (start_line, end_line, count , ... )
12+ func ! executor#exec (start_line, end_line, ... )
1313 if ! exists (' g:loaded_buffr' )
1414 call s: show_error (' Please, install vim-buffr plugin first' ) | return
1515 endif
1616
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 )
3219
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 )
3724 end
38-
39- return g: executor_default_command
4025endfunc
4126
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
5432endfunc
5533
56- func ! s: open_result (result, buffer_name)
34+ func ! s: open_buffer ( buffer_name)
5735 let l: buffer_name = a: buffer_name
5836
5937 if g: executor_reuse_buffer
@@ -64,25 +42,23 @@ func! s:open_result(result, buffer_name)
6442 endif
6543
6644 call buffr#open_or_create_buffer ({
67- \ ' position' : g: executor_position ,
45+ \ ' position' : ' bottom ' ,
6846 \ ' name' : l: buffer_name
6947 \ })
7048 call s: set_buffer_defaults ()
7149
7250 if g: executor_reuse_buffer
7351 silent exec ' edit ' . escape (s: previous_buffer , ' ' )
7452 endif
75-
76- call append (0 , split (a: result , " \n " ))
77- silent exec ' normal! Gdd'
7853endfunc
7954
8055func ! 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 , ' |' )
8460
85- return escape ( l: buffer_name , ' | ' )
61+ return l: name
8662endfunc
8763
8864func ! s: set_buffer_defaults ()
0 commit comments