Skip to content

Commit ce1aecf

Browse files
committed
- Improved detect for mac in open.
- Improved filtype and update in bg. - Reimplemented vimshell#internal#iexe#vimshell_iexe(). - Added :VimShellExecute and :VimShellInteractive commands. - Implemented bg and iexe and sudo completions.
1 parent 4b2c0b7 commit ce1aecf

File tree

13 files changed

+225
-53
lines changed

13 files changed

+225
-53
lines changed

autoload/vimshell.vim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
" FILE: vimshell.vim
33
" AUTHOR: Janakiraman .S <[email protected]>(Original)
44
" Shougo Matsushita <[email protected]>(Modified)
5-
" Last Modified: 28 Jun 2010
5+
" Last Modified: 02 Feb 2010
66
" License: MIT license {{{
77
" Permission is hereby granted, free of charge, to any person obtaining
88
" a copy of this software and associated documentation files (the
@@ -119,7 +119,7 @@ endfunction"}}}
119119
function! vimshell#create_shell(split_flag, directory)"{{{
120120
let l:bufname = '[1]vimshell'
121121
let l:cnt = 2
122-
while bufexists(l:bufname)
122+
while buflisted(l:bufname)
123123
let l:bufname = printf('[%d]vimshell', l:cnt)
124124
let l:cnt += 1
125125
endwhile

autoload/vimshell/complete/args_complete.vim

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,7 @@ function! vimshell#complete#args_complete#omnifunc(findstart, base)"{{{
8888
endif
8989

9090
" Get complete words.
91-
if has_key(s:special_funcs, l:command)
92-
let l:complete_words = call(s:special_funcs[l:command] . 'get_complete_words', [l:args[1:]])
93-
elseif has_key(s:internal_funcs, l:command)
94-
let l:complete_words = call(s:internal_funcs[l:command] . 'get_complete_words', [l:args[1:]])
95-
elseif has_key(s:command_funcs, l:command)
96-
let l:complete_words = call(s:command_funcs[l:command] . 'get_complete_words', [l:args[1:]])
97-
else
98-
let l:complete_words = vimshell#complete#helper#files(l:args[-1])
99-
endif
91+
let l:complete_words = vimshell#complete#args_complete#get_complete_words(l:command, l:args[1:])
10092

10193
" Restore option.
10294
let &ignorecase = l:ignorecase_save
@@ -111,4 +103,17 @@ function! vimshell#complete#args_complete#omnifunc(findstart, base)"{{{
111103
return l:complete_words
112104
endfunction"}}}
113105

106+
function! vimshell#complete#args_complete#get_complete_words(command, args)"{{{
107+
" Get complete words.
108+
if has_key(s:special_funcs, a:command)
109+
let l:complete_words = call(s:special_funcs[a:command] . 'get_complete_words', [a:args])
110+
elseif has_key(s:internal_funcs, a:command)
111+
let l:complete_words = call(s:internal_funcs[a:command] . 'get_complete_words', [a:args])
112+
elseif has_key(s:command_funcs, a:command)
113+
let l:complete_words = call(s:command_funcs[a:command] . 'get_complete_words', [a:args])
114+
else
115+
let l:complete_words = vimshell#complete#helper#files(a:args[-1])
116+
endif
117+
return l:complete_words
118+
endfunction"}}}
114119
" vim: foldmethod=marker

autoload/vimshell/complete/helper.vim

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,16 @@ function! vimshell#complete#helper#buffers(cur_keyword_str)"{{{
241241

242242
return l:ret
243243
endfunction"}}}
244+
function! vimshell#complete#helper#command_args(args)"{{{
245+
" command args...
246+
if len(a:args) == 1
247+
" Commands.
248+
return vimshell#complete#helper#commands(a:args[0])
249+
else
250+
" Args.
251+
return vimshell#complete#args_complete#get_complete_words(a:args[0], a:args[1:])
252+
endif
253+
endfunction"}}}
244254

245255
function! vimshell#complete#helper#compare_rank(i1, i2)"{{{
246256
return a:i1.rank < a:i2.rank ? 1 : a:i1.rank == a:i2.rank ? 0 : -1
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"=============================================================================
2+
" FILE: bg.vim
3+
" AUTHOR: Shougo Matsushita <[email protected]>
4+
" Last Modified: 05 Feb 2010
5+
" License: MIT license {{{
6+
" Permission is hereby granted, free of charge, to any person obtaining
7+
" a copy of this software and associated documentation files (the
8+
" "Software"), to deal in the Software without restriction, including
9+
" without limitation the rights to use, copy, modify, merge, publish,
10+
" distribute, sublicense, and/or sell copies of the Software, and to
11+
" permit persons to whom the Software is furnished to do so, subject to
12+
" the following conditions:
13+
"
14+
" The above copyright notice and this permission notice shall be included
15+
" in all copies or substantial portions of the Software.
16+
"
17+
" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18+
" OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19+
" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20+
" IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21+
" CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22+
" TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23+
" SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24+
" }}}
25+
"=============================================================================
26+
27+
function! vimshell#complete#internal#bg#get_complete_words(args)"{{{
28+
return vimshell#complete#helper#command_args(a:args)
29+
endfunction"}}}
30+
" vim: foldmethod=marker
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"=============================================================================
2+
" FILE: iexe.vim
3+
" AUTHOR: Shougo Matsushita <[email protected]>
4+
" Last Modified: 05 Feb 2010
5+
" License: MIT license {{{
6+
" Permission is hereby granted, free of charge, to any person obtaining
7+
" a copy of this software and associated documentation files (the
8+
" "Software"), to deal in the Software without restriction, including
9+
" without limitation the rights to use, copy, modify, merge, publish,
10+
" distribute, sublicense, and/or sell copies of the Software, and to
11+
" permit persons to whom the Software is furnished to do so, subject to
12+
" the following conditions:
13+
"
14+
" The above copyright notice and this permission notice shall be included
15+
" in all copies or substantial portions of the Software.
16+
"
17+
" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18+
" OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19+
" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20+
" IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21+
" CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22+
" TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23+
" SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24+
" }}}
25+
"=============================================================================
26+
27+
function! vimshell#complete#internal#iexe#get_complete_words(args)"{{{
28+
return vimshell#complete#helper#command_args(a:args)
29+
endfunction"}}}
30+
" vim: foldmethod=marker
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"=============================================================================
2+
" FILE: sudo.vim
3+
" AUTHOR: Shougo Matsushita <[email protected]>
4+
" Last Modified: 05 Feb 2010
5+
" License: MIT license {{{
6+
" Permission is hereby granted, free of charge, to any person obtaining
7+
" a copy of this software and associated documentation files (the
8+
" "Software"), to deal in the Software without restriction, including
9+
" without limitation the rights to use, copy, modify, merge, publish,
10+
" distribute, sublicense, and/or sell copies of the Software, and to
11+
" permit persons to whom the Software is furnished to do so, subject to
12+
" the following conditions:
13+
"
14+
" The above copyright notice and this permission notice shall be included
15+
" in all copies or substantial portions of the Software.
16+
"
17+
" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18+
" OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19+
" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20+
" IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21+
" CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22+
" TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23+
" SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24+
" }}}
25+
"=============================================================================
26+
27+
function! vimshell#complete#internal#sudo#get_complete_words(args)"{{{
28+
return vimshell#complete#helper#command_args(a:args)
29+
endfunction"}}}
30+
" vim: foldmethod=marker
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
"=============================================================================
2+
" FILE: vimshell_execute_complete.vim
3+
" AUTHOR: Shougo Matsushita <[email protected]>
4+
" Last Modified: 05 Feb 2010
5+
" License: MIT license {{{
6+
" Permission is hereby granted, free of charge, to any person obtaining
7+
" a copy of this software and associated documentation files (the
8+
" "Software"), to deal in the Software without restriction, including
9+
" without limitation the rights to use, copy, modify, merge, publish,
10+
" distribute, sublicense, and/or sell copies of the Software, and to
11+
" permit persons to whom the Software is furnished to do so, subject to
12+
" the following conditions:
13+
"
14+
" The above copyright notice and this permission notice shall be included
15+
" in all copies or substantial portions of the Software.
16+
"
17+
" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18+
" OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19+
" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20+
" IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21+
" CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22+
" TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23+
" SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24+
" }}}
25+
"=============================================================================
26+
27+
function! vimshell#complete#vimshell_execute_complete#completefunc(arglead, cmdline, cursorpos)"{{{
28+
" Get complete words.
29+
let l:complete_words = {}
30+
" Get command name.
31+
let l:args = vimshell#parser#split_args(a:cmdline)
32+
if a:cmdline =~ '\s\+$'
33+
" Add blank argument.
34+
call add(l:args, '')
35+
endif
36+
for l:dict in vimshell#complete#internal#iexe#get_complete_words(l:args[1:])
37+
if !has_key(l:complete_words, l:dict.word)
38+
let l:complete_words[l:dict.word] = 1
39+
endif
40+
endfor
41+
42+
return keys(l:complete_words)
43+
endfunction"}}}
44+
" vim: foldmethod=marker

autoload/vimshell/interactive.vim

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ let s:character_regex = ''
3838

3939
let s:is_win = has('win32') || has('win64')
4040

41+
augroup VimShellInteractive
42+
autocmd!
43+
autocmd CursorHold * call s:check_output()
44+
augroup END
45+
4146

4247
function! vimshell#interactive#get_cur_text()"{{{
4348
if getline('.') == '...'
@@ -696,31 +701,32 @@ function! s:on_exit()"{{{
696701
call vimshell#interactive#exit()
697702
endfunction"}}}
698703

699-
" Arguments completion by neocomplcache.
700-
function! s:complete_words(arglead, cmdline, cursorpos)"{{{
701-
" Caching.
702-
call neocomplcache#keyword_complete#word_caching_current_line()
703-
704-
let l:pattern = '\v%(' . neocomplcache#keyword_complete#current_keyword_pattern() . ')$'
705-
let l:cur_keyword_str = matchstr(a:cmdline[: a:cursorpos], l:pattern)
706-
let l:complete_words = neocomplcache#get_complete_words(l:cur_keyword_str)
707-
let l:match = match(a:cmdline[: a:cursorpos], l:pattern)
708-
if l:cur_keyword_str != ''
709-
if l:match > 0
710-
let l:cmdline = a:cmdline[: l:match-1]
711-
else
712-
let l:cmdline = ''
704+
" Autocmd functions.
705+
function! s:check_output()"{{{
706+
let l:bufnr = 1
707+
while l:bufnr <= bufnr('$')
708+
if l:bufnr != bufnr('%') && buflisted(l:bufnr) && type(getbufvar(l:bufnr, 'vimproc_sub')) != type('')
709+
" Check output.
710+
let l:filetype = getbufvar(l:bufnr, '&filetype')
711+
if l:filetype == 'background' || l:filetype =~ '^int_'
712+
let l:pos = getpos('.')
713+
714+
execute 'buffer' l:bufnr
715+
716+
if l:filetype == 'background'
717+
" Background execute.
718+
call vimshell#interactive#execute_pipe_out()
719+
else
720+
" Interactive execute.
721+
call vimshell#interactive#execute_pty_out()
722+
endif
723+
724+
buffer #
725+
endif
713726
endif
714-
else
715-
let l:cmdline = a:cmdline[: a:cursorpos]
716-
endif
717727

718-
let l:list = []
719-
for l:word in l:complete_words
720-
call add(l:list, l:cmdline.l:word.word)
721-
endfor
722-
723-
return l:list
728+
let l:bufnr += 1
729+
endwhile
724730
endfunction"}}}
725731

726732
" vim: foldmethod=marker

autoload/vimshell/internal/bg.vim

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"=============================================================================
22
" FILE: bg.vim
33
" AUTHOR: Shougo Matsushita <[email protected]>
4-
" Last Modified: 25 Dec 2009
4+
" Last Modified: 05 Feb 2010
55
" License: MIT license {{{
66
" Permission is hereby granted, free of charge, to any person obtaining
77
" a copy of this software and associated documentation files (the
@@ -22,9 +22,13 @@
2222
" TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
2323
" SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2424
" }}}
25-
" Version: 1.15, for Vim 7.0
25+
" Version: 1.16, for Vim 7.0
2626
"-----------------------------------------------------------------------------
2727
" ChangeLog: "{{{
28+
" 1.16:
29+
" - Improved filetype.
30+
" - Improved update.
31+
"
2832
" 1.15:
2933
" - Improved kill processes.
3034
" - Use vimproc.vim.
@@ -113,7 +117,7 @@ function! vimshell#internal#bg#execute(program, args, fd, other_info)"{{{
113117
endfunction"}}}
114118

115119
function! vimshell#internal#bg#vimshell_bg(args)"{{{
116-
call vimshell#internal#bg#execute('bg', a:args, {'stdin' : '', 'stdout' : '', 'stderr' : ''}, {'is_interactive' : 0, 'is_background' : 1})
120+
call vimshell#internal#bg#execute('bg', vimshell#parser#split_args(a:args), {'stdin' : '', 'stdout' : '', 'stderr' : ''}, {'is_interactive' : 0, 'is_background' : 1})
117121
endfunction"}}}
118122

119123
function! s:init_bg(fd, args, is_interactive)"{{{
@@ -175,7 +179,7 @@ function! s:init_bg(fd, args, is_interactive)"{{{
175179
setlocal buftype=nofile
176180
setlocal noswapfile
177181
setlocal nowrap
178-
execute 'setfiletype ' . a:args[0]
182+
setfiletype background
179183

180184
" Set syntax.
181185
syn region VimShellError start=+!!!+ end=+!!!+ contains=VimShellErrorHidden oneline
@@ -197,8 +201,7 @@ function! s:init_bg(fd, args, is_interactive)"{{{
197201
endif
198202
endif
199203

200-
autocmd vimshell_bg BufUnload <buffer> call <SID>on_exit()
201-
autocmd vimshell_bg CursorHold <buffer> call <SID>on_execute()
204+
autocmd vimshell_bg BufUnload <buffer> call s:on_exit()
202205
nnoremap <buffer><silent><C-c> :<C-u>call vimshell#interactive#interrupt()<CR>
203206
inoremap <buffer><silent><C-c> <ESC>:<C-u>call <SID>on_exit()<CR>
204207
nnoremap <buffer><silent><CR> :<C-u>call <SID>on_execute()<CR>
@@ -216,7 +219,6 @@ endfunction
216219

217220
function! s:on_exit()
218221
augroup vimshell_bg
219-
autocmd! CursorHold <buffer>
220222
autocmd! BufUnload <buffer>
221223
augroup END
222224

autoload/vimshell/internal/iexe.vim

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"=============================================================================
22
" FILE: iexe.vim
33
" AUTHOR: Shougo Matsushita <[email protected]>
4-
" Last Modified: 28 Jun 2010
4+
" Last Modified: 05 Feb 2010
55
" License: MIT license {{{
66
" Permission is hereby granted, free of charge, to any person obtaining
77
" a copy of this software and associated documentation files (the
@@ -22,9 +22,12 @@
2222
" TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
2323
" SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2424
" }}}
25-
" Version: 1.21, for Vim 7.0
25+
" Version: 1.22, for Vim 7.0
2626
"-----------------------------------------------------------------------------
2727
" ChangeLog: "{{{
28+
" 1.22:
29+
" - Reimplemented vimshell#internal#iexe#vimshell_iexe().
30+
"
2831
" 1.21:
2932
" - Implemented auto update.
3033
" - Splited mappings functions.
@@ -186,6 +189,10 @@ function! vimshell#internal#iexe#execute(program, args, fd, other_info)"{{{
186189
return 1
187190
endfunction"}}}
188191

192+
function! vimshell#internal#iexe#vimshell_iexe(args)"{{{
193+
call vimshell#internal#iexe#execute('iexe', vimshell#parser#split_args(a:args), {'stdin' : '', 'stdout' : '', 'stderr' : ''}, {'is_interactive' : 0, 'is_background' : 1})
194+
endfunction"}}}
195+
189196
function! vimshell#internal#iexe#default_settings()"{{{
190197
setlocal buftype=nofile
191198
setlocal noswapfile
@@ -308,7 +315,7 @@ if vimshell#iswin()
308315
" Windows only.
309316
let s:interactive_option = {
310317
\ 'bash' : '-i', 'bc' : '-i', 'irb' : '--inf-ruby-mode',
311-
\ 'gosh' : '-i', 'python' : '-i',
318+
\ 'gosh' : '-i', 'python' : '-i', 'zsh' : '-i',
312319
\ 'powershell' : '-Command -',
313320
\ 'termtter' : '--monochrome'
314321
\}

0 commit comments

Comments
 (0)