Skip to content

Commit 3944ddc

Browse files
committed
5.35 : - Added help file(constructing).
- Improved open behaivior. - Fixed completion column bug. - Implemented <Plug>(vimshell_move_end_argument). - Fixed environment variables parse bug. - Accept null wildcard. - Substitute modifier. - Added VimShellCreate command. - Save prompt variables when vimshell is initialized. - Implemented vimshell#push_and_execute() function.
1 parent 598aebc commit 3944ddc

File tree

4 files changed

+678
-95
lines changed

4 files changed

+678
-95
lines changed

autoload/vimshell.vim

+73-35
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: 05 Oct 2009
5+
" Last Modified: 12 Oct 2009
66
" Usage: Just source this file.
77
" License: MIT license {{{
88
" Permission is hereby granted, free of charge, to any person obtaining
@@ -27,12 +27,26 @@
2727
" Version: 5.35, for Vim 7.0
2828
"=============================================================================
2929

30+
if !exists('g:VimShell_Prompt')
31+
let s:prompt = 'vimshell% '
32+
else
33+
let s:prompt = g:VimShell_Prompt
34+
endif
35+
if !exists('g:VimShell_SecondaryPrompt')
36+
let s:secondary_prompt = '%% '
37+
else
38+
let s:secondary_prompt = g:VimShell_SecondaryPrompt
39+
endif
3040
if !exists('g:VimShell_UserPrompt')
3141
let s:user_prompt = ''
3242
else
3343
let s:user_prompt = g:VimShell_UserPrompt
3444
endif
3545

46+
if !exists('g:VimShell_ExecuteFileList')
47+
let g:VimShell_ExecuteFileList = {}
48+
endif
49+
3650
" Helper functions.
3751
function! vimshell#set_execute_file(exts, program)"{{{
3852
for ext in split(a:exts, ',')
@@ -196,12 +210,12 @@ function! vimshell#execute_command(program, args, fd, other_info)"{{{
196210
return 0
197211
endfunction"}}}
198212
function! vimshell#process_enter()"{{{
199-
if getline('.') !~ vimshell#escape_match(g:VimShell_Prompt)
213+
if getline('.') !~ vimshell#escape_match(s:prompt)
200214
" Prompt not found
201215

202-
if match(getline('$'), vimshell#escape_match(g:VimShell_Prompt)) < 0
216+
if match(getline('$'), vimshell#escape_match(s:prompt)) < 0
203217
" Create prompt line.
204-
call append(line('$'), g:VimShell_Prompt)
218+
call append(line('$'), s:prompt)
205219
endif
206220

207221
" Search cursor file.
@@ -213,15 +227,15 @@ function! vimshell#process_enter()"{{{
213227
normal! G$
214228
" Execute cursor file.
215229
if isdirectory(l:filename)
216-
call setline(line('$'), g:VimShell_Prompt . l:filename)
230+
call setline(line('$'), s:prompt . l:filename)
217231
else
218-
call setline(line('$'), g:VimShell_Prompt . 'vim ' . l:filename)
232+
call setline(line('$'), s:prompt . 'vim ' . l:filename)
219233
endif
220234
endif
221235

222236
if line('.') != line('$')
223237
" History execution.
224-
if match(getline('$'), vimshell#escape_match(g:VimShell_Prompt)) < 0
238+
if match(getline('$'), vimshell#escape_match(s:prompt)) < 0
225239
" Insert prompt line.
226240
call append(line('$'), getline('.'))
227241
else
@@ -236,7 +250,7 @@ function! vimshell#process_enter()"{{{
236250
endif
237251

238252
" Delete prompt string.
239-
let l:line = substitute(getline('.'), '^' . g:VimShell_Prompt, '', '')
253+
let l:line = substitute(getline('.'), '^' . s:prompt, '', '')
240254

241255
" Delete comment.
242256
let l:line = substitute(l:line, '#.*$', '', '')
@@ -254,7 +268,7 @@ function! vimshell#process_enter()"{{{
254268
let l:line = substitute(l:line, '^\s\+', '', '')
255269
if l:line =~ '^\s*$'
256270
if g:VimShell_EnableAutoLs
257-
call setline(line('.'), g:VimShell_Prompt . 'ls')
271+
call setline(line('.'), s:prompt . 'ls')
258272
call vimshell#execute_internal_command('ls', [], {}, {})
259273

260274
call vimshell#print_prompt()
@@ -263,7 +277,7 @@ function! vimshell#process_enter()"{{{
263277
call vimshell#start_insert()
264278
else
265279
" Ignore empty command line.
266-
call setline(line('.'), g:VimShell_Prompt)
280+
call setline(line('.'), s:prompt)
267281

268282
call vimshell#start_insert()
269283
endif
@@ -407,7 +421,7 @@ function! vimshell#print_prompt()"{{{
407421
let b:vimshell_commandline_stack = []
408422
endif
409423
if empty(b:vimshell_commandline_stack)
410-
let l:new_prompt = g:VimShell_Prompt
424+
let l:new_prompt = s:prompt
411425
else
412426
let l:new_prompt = b:vimshell_commandline_stack[-1]
413427
call remove(b:vimshell_commandline_stack, -1)
@@ -495,46 +509,67 @@ endfunction"}}}
495509
" VimShell key-mappings functions."{{{
496510
function! vimshell#push_current_line()"{{{
497511
" Check current line.
498-
if match(getline('.'), vimshell#escape_match(g:VimShell_Prompt)) < 0
512+
if match(getline('.'), vimshell#escape_match(s:prompt)) < 0
499513
return
500514
endif
501515

502516
call add(b:vimshell_commandline_stack, getline('.'))
503517

504518
" Set prompt line.
505-
call setline(line('.'), g:VimShell_Prompt)
519+
call setline(line('.'), s:prompt)
506520

507521
startinsert!
508522
endfunction"}}}
523+
function! vimshell#push_and_execute(command)"{{{
524+
" Check current line.
525+
if match(getline('.'), vimshell#escape_match(s:prompt)) < 0
526+
return
527+
endif
528+
529+
call add(b:vimshell_commandline_stack, getline('.'))
530+
531+
" Set prompt line.
532+
call setline(line('.'), s:prompt . a:command)
533+
534+
call vimshell#process_enter()
535+
endfunction"}}}
509536

510537
function! vimshell#previous_prompt()"{{{
511-
call search('^' . vimshell#escape_match(g:VimShell_Prompt), 'bWe')
538+
call search('^' . vimshell#escape_match(s:prompt), 'bWe')
512539
endfunction"}}}
513540
function! vimshell#next_prompt()"{{{
514-
call search('^' . vimshell#escape_match(g:VimShell_Prompt), 'We')
541+
call search('^' . vimshell#escape_match(s:prompt), 'We')
515542
endfunction"}}}
516-
function! vimshell#switch_shell(split_flag)"{{{
543+
function! vimshell#switch_shell(split_flag, directory)"{{{
517544
if &filetype == 'vimshell'
518545
if winnr('$') != 1
519546
close
520547
else
521548
buffer #
522549
endif
523550

551+
if a:directory != ''
552+
" Change current directory.
553+
lcd `=fnamemodify(a:directory, ':p')`
554+
call vimshell#print_prompt()
555+
endif
556+
call vimshell#start_insert()
524557
return
525558
endif
526559

527560
" Search VimShell window.
528561
let l:cnt = 1
529562
while l:cnt <= winnr('$')
530563
if getwinvar(l:cnt, '&filetype') == 'vimshell'
531-
let l:current = getcwd()
532564

533565
execute l:cnt . 'wincmd w'
534566

535-
" Change current directory.
536-
let b:vimshell_save_dir = l:current
537-
lcd `=fnamemodify(l:current, ':p')`
567+
if a:directory != ''
568+
" Change current directory.
569+
lcd `=fnamemodify(a:directory, ':p')`
570+
call vimshell#print_prompt()
571+
endif
572+
call vimshell#start_insert()
538573
return
539574
endif
540575

@@ -545,29 +580,30 @@ function! vimshell#switch_shell(split_flag)"{{{
545580
let l:cnt = 1
546581
while l:cnt <= bufnr('$')
547582
if getbufvar(l:cnt, '&filetype') == 'vimshell'
548-
let l:current = getcwd()
549-
550583
if a:split_flag
551584
execute 'sbuffer' . l:cnt
552585
execute 'resize' . winheight(0)*g:VimShell_SplitHeight / 100
553586
else
554587
execute 'buffer' . l:cnt
555588
endif
556589

557-
" Change current directory.
558-
let b:vimshell_save_dir = l:current
559-
lcd `=fnamemodify(l:current, ':p')`
590+
if a:directory != ''
591+
" Change current directory.
592+
lcd `=fnamemodify(a:directory, ':p')`
593+
call vimshell#print_prompt()
594+
endif
595+
call vimshell#start_insert()
560596
return
561597
endif
562598

563599
let l:cnt += 1
564600
endwhile
565601

566602
" Create window.
567-
call vimshell#create_shell(a:split_flag)
603+
call vimshell#create_shell(a:split_flag, a:directory)
568604
endfunction"}}}
569605
function! vimshell#delete_previous_output()"{{{
570-
let l:prompt = vimshell#escape_match(g:VimShell_Prompt)
606+
let l:prompt = vimshell#escape_match(s:prompt)
571607
if s:user_prompt != ''
572608
let l:nprompt = '^\[%\] '
573609
else
@@ -609,13 +645,13 @@ function! vimshell#insert_last_word()"{{{
609645
startinsert!
610646
endfunction"}}}
611647
function! vimshell#run_help()"{{{
612-
if match(getline('.'), vimshell#escape_match(g:VimShell_Prompt)) < 0
648+
if match(getline('.'), vimshell#escape_match(s:prompt)) < 0
613649
startinsert!
614650
return
615651
endif
616652

617653
" Delete prompt string.
618-
let l:line = substitute(getline('.'), '^' . vimshell#escape_match(g:VimShell_Prompt), '', '')
654+
let l:line = substitute(getline('.'), '^' . vimshell#escape_match(s:prompt), '', '')
619655
if l:line =~ '^\s*$'
620656
startinsert!
621657
return
@@ -640,11 +676,11 @@ function! vimshell#run_help()"{{{
640676
startinsert!
641677
endfunction"}}}
642678
function! vimshell#paste_prompt()"{{{
643-
if match(getline('.'), vimshell#escape_match(g:VimShell_Prompt)) < 0
679+
if match(getline('.'), vimshell#escape_match(s:prompt)) < 0
644680
return
645681
endif
646682

647-
if match(getline('$'), vimshell#escape_match(g:VimShell_Prompt)) < 0
683+
if match(getline('$'), vimshell#escape_match(s:prompt)) < 0
648684
" Insert prompt line.
649685
call append(line('$'), getline('.'))
650686
else
@@ -654,7 +690,7 @@ function! vimshell#paste_prompt()"{{{
654690
normal! G
655691
endfunction"}}}
656692
function! vimshell#move_head()"{{{
657-
call search(vimshell#escape_match(g:VimShell_Prompt), 'be', line('.'))
693+
call search(vimshell#escape_match(s:prompt), 'be', line('.'))
658694
if col('.') != col('$')-1
659695
normal! l
660696
endif
@@ -663,7 +699,7 @@ endfunction"}}}
663699
function! vimshell#delete_line()"{{{
664700
let l:col = col('.')
665701
let l:mcol = col('$')
666-
call setline(line('.'), g:VimShell_Prompt . getline('.')[l:col :])
702+
call setline(line('.'), s:prompt . getline('.')[l:col :])
667703
call vimshell#move_head()
668704
if l:col == l:mcol-1
669705
startinsert!
@@ -698,7 +734,7 @@ function! vimshell#clear()"{{{
698734
endif
699735
endfunction"}}}
700736

701-
function! vimshell#create_shell(split_flag)"{{{
737+
function! vimshell#create_shell(split_flag, directory)"{{{
702738
let l:bufname = 'vimshell'
703739
let l:cnt = 2
704740
while bufexists(l:bufname)
@@ -718,8 +754,10 @@ function! vimshell#create_shell(split_flag)"{{{
718754
setlocal bufhidden=hide
719755
let &l:omnifunc = 'vimshell#complete#history_complete'
720756

721-
" Save current directory.
757+
" Change current directory.
722758
let b:vimshell_save_dir = getcwd()
759+
let l:current = (a:directory != '')? a:directory : getcwd()
760+
lcd `=fnamemodify(l:current, ':p')`
723761

724762
" Load history.
725763
if !filereadable(g:VimShell_HistoryPath)

0 commit comments

Comments
 (0)