root/dotfiles/vim/from_kyushu/.vim/autoload/vimshell/internal/iexe.vim @ 34001

Revision 34001, 4.5 kB (checked in by from_kyushu, 4 years ago)

update VimShell?

Line 
1"=============================================================================
2" FILE: iexe.vim
3" AUTHOR: Shougo Matsushita <Shougo.Matsu@gmail.com>
4" Last Modified: 05 Jun 2009
5" Usage: Just source this file.
6" License: MIT license  {{{
7"     Permission is hereby granted, free of charge, to any person obtaining
8"     a copy of this software and associated documentation files (the
9"     "Software"), to deal in the Software without restriction, including
10"     without limitation the rights to use, copy, modify, merge, publish,
11"     distribute, sublicense, and/or sell copies of the Software, and to
12"     permit persons to whom the Software is furnished to do so, subject to
13"     the following conditions:
14"
15"     The above copyright notice and this permission notice shall be included
16"     in all copies or substantial portions of the Software.
17"
18"     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19"     OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20"     MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21"     IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
22"     CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23"     TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24"     SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25" }}}
26" Version: 1.6, for Vim 7.0
27"-----------------------------------------------------------------------------
28" ChangeLog: "{{{
29"   1.6: Use interactive.
30"
31"   1.5: Improved autocmd.
32"
33"   1.4: Split nicely.
34"
35"   1.3:
36"     - Use g:VimShell_EnableInteractive option.
37"     - Use utls/process.vim.
38"
39"   1.2: Implemented background execution.
40"
41"   1.1: Use vimproc.
42"
43"   1.0: Initial version.
44""}}}
45"-----------------------------------------------------------------------------
46" TODO: "{{{
47"     - Nothing.
48""}}}
49" Bugs"{{{
50"     -
51""}}}
52"=============================================================================
53
54function! vimshell#internal#iexe#execute(program, args, fd, other_info)"{{{
55    " Interactive execute command.
56    if !g:VimShell_EnableInteractive
57        " Error.
58        call vimshell#error_line('Must use vimproc plugin.')
59        return 0
60    endif
61
62    if empty(a:args)
63        return 0
64    endif
65
66    " Initialize.
67    let l:proc = proc#import()
68
69    try
70        if has('win32') || has('win64')
71            let l:sub = l:proc.popen2(a:args)
72        else
73            let l:sub = l:proc.ptyopen(a:args)
74        endif
75    catch
76        if a:other_info.is_interactive
77            call vimshell#error_line(printf('File: "%s" is not found.', a:args[0]))
78        else
79            echohl WarningMsg | echo printf('File: "%s" is not found.', a:args[0]) | echohl None
80        endif
81
82        return
83    endtry
84
85    if a:other_info.is_background
86        call s:init_bg(l:proc, l:sub, a:args, a:other_info.is_interactive)
87        call interactive#execute_inout(0)
88
89        return 1
90    else
91        " Set variables.
92        let b:vimproc = l:proc
93        let b:subproc = l:sub
94
95        while exists('b:subproc')
96            call interactive#execute_out()
97            call interactive#execute_inout(1)
98        endwhile
99
100        return 0
101    endif
102endfunction"}}}
103
104function! vimshell#internal#iexe#vimshell_iexe(args)"{{{
105    call vimshell#internal#iexe#execute('iexe', a:args, {}, {'is_interactive' : 0, 'is_background' : 1})
106endfunction"}}}
107
108function! s:init_bg(proc, sub, args, is_interactive)"{{{
109    " Init buffer.
110    if a:is_interactive
111        call vimshell#print_prompt()
112    endif
113    " Split nicely.
114    if winheight(0) > &winheight
115        split
116    else
117        vsplit
118    endif
119    edit `=join(a:args).'@'.(bufnr('$')+1)`
120    setlocal buftype=nofile
121    setlocal noswapfile
122
123    " Set variables.
124    let b:vimproc = a:proc
125    let b:subproc = a:sub
126
127    nnoremap <buffer><silent><CR>       :<C-u>call interactive#execute_inout(0)<CR>
128    inoremap <buffer><silent><CR>       <ESC>:<C-u>call interactive#execute_inout(0)<CR>
129    nnoremap <buffer><silent><C-c>       :<C-u>call <sid>on_exit()<CR>
130    inoremap <buffer><silent><C-c>       <ESC>:<C-u>call <sid>on_exit()<CR>
131    augroup vimshell_iexe
132        autocmd BufDelete <buffer>   call s:on_exit()
133        autocmd CursorHold <buffer>  call interactive#execute_out()
134    augroup END
135
136    call interactive#execute_out()
137    call interactive#execute_out()
138
139    return 1
140endfunction"}}}
141
142function! s:on_exit()
143    augroup vimshell_iexe
144        autocmd! * <buffer>
145    augroup END
146
147    call interactive#exit()
148endfunction
149
Note: See TracBrowser for help on using the browser.