Skip to content

Commit c71c95a

Browse files
committed
6.01 :
- Improved error handling. - Improved head match. - Use completefunc_complete if available. - Fixed trunk string. - Escape complete candidates. - Improved Windows pty support. - Improved password input. - Improved echo back. - Improved encoding. - Implemented next_prompt() in iexe. - Implemented arguments completion. - Set interactive option in Windows iexe. - Fixed force exit error.
1 parent 6f3bb99 commit c71c95a

File tree

5 files changed

+250
-144
lines changed

5 files changed

+250
-144
lines changed

autoload/vimshell/complete/helper.vim

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,5 +235,8 @@ endfunction"}}}
235235
function! vimshell#complete#helper#compare_rank(i1, i2)"{{{
236236
return a:i1.rank < a:i2.rank ? 1 : a:i1.rank == a:i2.rank ? 0 : -1
237237
endfunction"}}}
238+
function! vimshell#complete#helper#keyword_filter(list, cur_keyword_str)"{{{
239+
return filter(a:list, 'v:val =~ ' . string('^' . escape(a:cur_keyword_str, '~" \.^$[]*')))
240+
endfunction"}}}
238241

239242
" vim: foldmethod=marker
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
"=============================================================================
2+
" FILE: interactive_complete.vim
3+
" AUTHOR: Shougo Matsushita <[email protected]>
4+
" Last Modified: 03 Jun 2009
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#interactive_complete#complete()"{{{
28+
let &iminsert = 0
29+
let &imsearch = 0
30+
31+
" Interactive completion.
32+
33+
if exists(':NeoComplCacheDisable') && exists('*neocomplcache#complfunc#completefunc_complete#call_completefunc')
34+
return neocomplcache#complfunc#completefunc_complete#call_completefunc('vimshell#complete#interactive_complete#omnifunc')
35+
else
36+
" Set complete function.
37+
let &l:omnifunc = 'vimshell#complete#interactive_complete#omnifunc'
38+
39+
return "\<C-x>\<C-o>\<C-p>"
40+
endif
41+
endfunction"}}}
42+
43+
function! vimshell#complete#interactive_complete#omnifunc(findstart, base)"{{{
44+
if a:findstart
45+
let l:pos = mode() ==# 'i' ? 2 : 1
46+
let l:cur_text = col('.') < l:pos ? '' : getline('.')[: col('.') - l:pos]
47+
return match(l:cur_text, '\%([[:alnum:]_+~-]\|\\[ ]\)*$')
48+
endif
49+
50+
" Save option.
51+
let l:ignorecase_save = &ignorecase
52+
53+
" Complete.
54+
if g:VimShell_SmartCase && a:base =~ '\u'
55+
let &ignorecase = 0
56+
else
57+
let &ignorecase = g:VimShell_IgnoreCase
58+
endif
59+
60+
let l:complete_words = s:get_complete_candidates(a:base)
61+
62+
" Restore option.
63+
let &ignorecase = l:ignorecase_save
64+
if &l:omnifunc != ''
65+
let &l:omnifunc = ''
66+
endif
67+
68+
return l:complete_words
69+
endfunction"}}}
70+
71+
function! s:get_complete_candidates(cur_keyword_str)"{{{
72+
let l:list = []
73+
74+
" Do command completion.
75+
let l:in = getline('.')
76+
let l:prompt = l:in
77+
78+
if l:in == '...'
79+
let l:in = ''
80+
" Working
81+
elseif !exists('b:prompt_history')
82+
let l:in = ''
83+
elseif exists("b:prompt_history['".line('.')."']")
84+
let l:in = l:in[len(b:prompt_history[line('.')]) : ]
85+
endif
86+
87+
call b:vimproc_sub[0].write(l:in . "\<TAB>")
88+
89+
" Get output.
90+
let l:read = b:vimproc_sub[0].read(-1, 40)
91+
let l:output = ''
92+
while vimshell#head_match(split(l:output, '\r\n\|\n', 1)[-1], l:prompt)
93+
let l:output .= l:read
94+
let l:outputed = 1
95+
96+
let l:read = b:vimproc_sub[0].read(-1, 40)
97+
endwhile
98+
let l:candidates = split(l:output, '\r\n\|\n')[: -2]
99+
100+
return vimshell#complete#helper#keyword_filter(l:candidates, a:cur_keyword_str)
101+
endfunction"}}}
102+
103+
" vim: foldmethod=marker

autoload/vimshell/interactive.vim

Lines changed: 70 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"=============================================================================
22
" FILE: interactive.vim
33
" AUTHOR: Shougo Matsushita <[email protected]>
4-
" Last Modified: 25 Dec 2009
4+
" Last Modified: 03 Jun 2009
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
@@ -50,6 +50,12 @@ function! vimshell#interactive#execute_pty_inout(is_interactive)"{{{
5050
" Password input.
5151
set imsearch=0
5252
let l:in = inputsecret('Input Secret : ')
53+
54+
if &termencoding != '' && &encoding != &termencoding
55+
" Convert encoding.
56+
let l:in = iconv(l:in, &encoding, &termencoding)
57+
endif
58+
5359
call b:vimproc_sub[0].write(l:in . "\<NL>")
5460
let b:vimproc_is_secret = 0
5561
elseif !b:vimproc_sub[0].eof
@@ -98,13 +104,8 @@ function! vimshell#interactive#execute_pty_inout(is_interactive)"{{{
98104
" Still nothing? We give up.
99105
if l:prompt_search == 0
100106
echohl WarningMsg | echo "Invalid input." | echohl None
101-
"normal! G$
102-
"startinsert!
103-
"return
104107
endif
105108
endif
106-
" Delete input string for echoback.
107-
call setline(line('.'), getline('.')[: -(len(l:in)+1)])
108109

109110
" record command history
110111
if !exists('b:interactive_command_history')
@@ -116,33 +117,60 @@ function! vimshell#interactive#execute_pty_inout(is_interactive)"{{{
116117
let b:interactive_command_position = 0
117118

118119
try
120+
if &termencoding != '' && &encoding != &termencoding
121+
" Convert encoding.
122+
let l:in = iconv(l:in, &encoding, &termencoding)
123+
endif
124+
119125
if l:in =~ "$"
120126
" EOF.
121127
call b:vimproc_sub[0].write(l:in[:-2] . s:is_win ? "" : "")
128+
let b:skip_echoback = l:in[:-2]
122129
call vimshell#interactive#execute_pty_out()
123130

124131
call vimshell#interactive#exit()
125132
return
126133
elseif l:in =~ '\t$'
127134
" Completion.
128135
call b:vimproc_sub[0].write(l:in)
136+
let b:skip_echoback = l:in[: -1]
129137
elseif l:in != '...'
130-
if l:in =~ '^\.\.\.'
138+
if l:in =~ '^-> '
131139
" Delete ...
132140
let l:in = l:in[3:]
133141
endif
134142

135143
call b:vimproc_sub[0].write(l:in . "\<NL>")
144+
let b:skip_echoback = l:in
136145
endif
137146
catch
138147
call b:vimproc_sub[0].close()
139148
endtry
140149
endif
141150

142-
call append(line('$'), '...')
143-
normal! G$
151+
if getline('$') != '...'
152+
call append(line('$'), '...')
153+
normal! G$
154+
endif
144155

145156
call vimshell#interactive#execute_pty_out()
157+
158+
while b:vimproc_is_secret
159+
" Password input.
160+
set imsearch=0
161+
let l:in = inputsecret('Input Secret : ')
162+
163+
if &termencoding != '' && &encoding != &termencoding
164+
" Convert encoding.
165+
let l:in = iconv(l:in, &encoding, &termencoding)
166+
endif
167+
168+
call b:vimproc_sub[0].write(l:in . "\<NL>")
169+
let b:vimproc_is_secret = 0
170+
171+
call vimshell#interactive#execute_pty_out()
172+
endwhile
173+
146174
if getline(line('$')) =~ '^\s*$'
147175
call setline(line('$'), '...')
148176
endif
@@ -162,21 +190,30 @@ function! vimshell#interactive#execute_pty_out()"{{{
162190
let l:i = 0
163191
let l:submax = len(b:vimproc_sub) - 1
164192
let l:outputed = 0
193+
let l:output = ''
165194
for sub in b:vimproc_sub
166195
if !sub.eof
167196
let l:read = sub.read(-1, 40)
168197
while l:read != ''
169-
if l:i < l:submax
170-
" Write pipe.
171-
call b:vimproc_sub[l:i + 1].write(l:read)
172-
else
173-
call s:print_buffer(b:vimproc_fd, l:read)
174-
redraw
175-
endif
198+
let l:output .= l:read
199+
let l:outputed = 1
176200

177201
let l:read = sub.read(-1, 40)
178-
let l:outputed = 1
179202
endwhile
203+
204+
if l:output != ''
205+
if exists('b:skip_echoback')
206+
if vimshell#head_match(l:output, b:skip_echoback)
207+
let l:output = l:output[len(b:skip_echoback) :]
208+
else
209+
" Newline.
210+
let l:output = "\<NL>" . l:output
211+
endif
212+
endif
213+
214+
call s:print_buffer(b:vimproc_fd, l:output)
215+
redraw
216+
endif
180217
endif
181218

182219
let l:i += 1
@@ -186,6 +223,7 @@ function! vimshell#interactive#execute_pty_out()"{{{
186223
if !exists('b:prompt_history')
187224
let b:prompt_history = {}
188225
endif
226+
189227
if l:outputed
190228
let b:prompt_history[line('.')] = getline('.')
191229
endif
@@ -280,7 +318,7 @@ function! vimshell#interactive#force_exit()"{{{
280318
try
281319
" 15 == SIGTERM
282320
call sub.vp_kill(15)
283-
catch /No such process/
321+
catch
284322
endtry
285323
endfor
286324

@@ -330,11 +368,7 @@ function! vimshell#interactive#interrupt()"{{{
330368
endtry
331369
endfor
332370

333-
if has('win32') || has('win64')
334-
call vimshell#interactive#execute_pipe_out()
335-
else
336-
call vimshell#interactive#execute_pty_out()
337-
endif
371+
call vimshell#interactive#execute_pty_out()
338372
endfunction"}}}
339373

340374
function! vimshell#interactive#highlight_escape_sequence()"{{{
@@ -431,7 +465,11 @@ function! s:print_buffer(fd, string)"{{{
431465
return
432466
endif
433467

434-
if a:string =~ s:password_regex
468+
" Convert encoding.
469+
let l:string = (&termencoding != '' && &encoding != &termencoding) ?
470+
\ iconv(a:string, &termencoding, &encoding) : a:string
471+
472+
if l:string =~ s:password_regex
435473
" Set secret flag.
436474
let b:vimproc_is_secret = 1
437475
endif
@@ -441,23 +479,16 @@ function! s:print_buffer(fd, string)"{{{
441479
" Nothing.
442480
elseif a:fd.stdout == '/dev/clip'
443481
" Write to clipboard.
444-
let @+ .= a:string
482+
let @+ .= l:string
445483
else
446484
" Write file.
447-
let l:file = extend(readfile(a:fd.stdout), split(a:string, '\r\n\|\n'))
485+
let l:file = extend(readfile(a:fd.stdout), split(l:string, '\r\n\|\n'))
448486
call writefile(l:file, a:fd.stdout)
449487
endif
450488

451489
return
452490
endif
453491

454-
" Convert encoding for system().
455-
if has('win32') || has('win64')
456-
let l:string = iconv(a:string, 'cp932', &encoding)
457-
else
458-
let l:string = iconv(a:string, 'utf-8', &encoding)
459-
endif
460-
461492
" Strip <CR>.
462493
if getline(line('$')) == '...'
463494
$delete
@@ -480,28 +511,25 @@ function! s:error_buffer(fd, string)"{{{
480511
return
481512
endif
482513

514+
" Convert encoding.
515+
let l:string = (&termencoding != '' && &encoding != &termencoding) ?
516+
\ iconv(a:string, &termencoding, &encoding) : a:string
517+
483518
if a:fd.stderr != ''
484519
if a:fd.stderr == '/dev/null'
485520
" Nothing.
486521
elseif a:fd.stderr == '/dev/clip'
487522
" Write to clipboard.
488-
let @+ .= a:string
523+
let @+ .= l:string
489524
else
490525
" Write file.
491-
let l:file = extend(readfile(a:fd.stderr), split(a:string, '\r\n\|\n'))
526+
let l:file = extend(readfile(a:fd.stderr), split(l:string, '\r\n\|\n'))
492527
call writefile(l:file, a:fd.stderr)
493528
endif
494529

495530
return
496531
endif
497532

498-
" Convert encoding for system().
499-
if has('win32') || has('win64')
500-
let l:string = iconv(a:string, 'cp932', &encoding)
501-
else
502-
let l:string = iconv(a:string, 'utf-8', &encoding)
503-
endif
504-
505533
" Print buffer.
506534
" Strip <CR>.
507535
let l:last_line = getline(line('$'))

0 commit comments

Comments
 (0)