Skip to content

Commit dcb0551

Browse files
nicoraffovim-scripts
authored andcommitted
Version 0.5
* Various performance enhancements and bugfixes. * Rewritten escape sequence processing
1 parent 04ab2a3 commit dcb0551

File tree

7 files changed

+506
-392
lines changed

7 files changed

+506
-392
lines changed

README.orig

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
Conque - Interactive shell buffer for Vim
33

44
author: nico raffo <nicoraffo@gmail.com>
5-
modified: 2009-10-29
6-
version: 0.4
5+
modified: 2009-12-01
6+
version: 0.5
77
info: http://code.google.com/p/conque/
88

99
== REQUIREMENTS ==
@@ -20,6 +20,7 @@ $HOME/.vim/syntax/conque.vim
2020
$HOME/.vim/autoload/conque.vim
2121
$HOME/.vim/autoload/subprocess.vim
2222
$HOME/.vim/autoload/subprocess/proc_py.vim
23+
$HOME/.vim/autoload/subprocess/shell_translate.vim
2324

2425
== USAGE ==
2526

@@ -34,7 +35,7 @@ To open Conque in a new horizontal or vertical buffer use:
3435
:ConqueSplit <command>
3536
:ConqueVSplit <command>
3637

37-
Use insert mode to send commands to the shell. Use the <Tab> key to get more output from the shell. Conque is set to only a 40 milisecond timeout by default, so you will likely need to use the <Tab> key frequently.
38+
Use insert mode to send commands to the shell. Use the <Tab> key to get more output from the shell. Conque is set to a 40 milisecond timeout by default, so you will likely need to use the <Tab> key frequently.
3839

3940
== CONFIG OPTIONS ==
4041

@@ -48,15 +49,15 @@ let g:Conque_Read_Timeout = 40
4849
let g:Conque_Syntax = 'conque'
4950

5051
" Terminal identification
51-
" Leaving this value as "dumb" may make the terminal slightly faster.
52+
" Leaving this value as "dumb" will cause the fewest formatting errors, and may make the terminal slightly faster.
5253
" Setting it to "xterm" will enable more features.
5354
let g:Conque_TERM = 'dumb'
5455

5556
== KNOWN ISSUES ==
5657

57-
* Conque does not continuously poll your program for new output. If you are expecting more output but nothing is happening, press <Tab> to get more.
58-
* Tab completion and history navigation may start to break down when your command is longer than the width of the screen. Setting g:Conque_TERM = 'xterm' in your .vimrc will usually correct this issue.
5958
* Most complex, full-screen applications will not work in Conque. You will not be able to launch programs such as alpine using Conque.
59+
* Conque does not continuously poll your program for new output. If you are expecting more output but nothing is happening, press <Tab> to get more.
60+
* Tab completion and history navigation may start to break down when your command is longer than the width of the screen. This will get fixed in a future version. Tab completion is generally squirrely in zsh for some reason, and it may require you to use TERM=xterm in (t)csh.
6061
* Some Ubuntu users have been able to load Conque on the terminal Vim, but not using graphical GVim. Two Ubuntu and one Kubuntu install later I haven't been able to reproduce this. If it happens to you, please send me an email with your :version output and operating system version.
6162

6263
== TROUBLESHOOTING ==
@@ -77,6 +78,10 @@ Most installations of Vim 7+ these days come built with Python.
7778

7879
== CHANGELOG ==
7980

81+
-0.5 / 2009-12-01
82+
* rewritten, faster escape sequece proecessing
83+
* bugfixes
84+
8085
- 0.4 / 2009-10-29
8186
* Improved history and tab completion
8287
* Fix escape sequence formatting and improve highlighting
@@ -86,7 +91,7 @@ Most installations of Vim 7+ these days come built with Python.
8691
* Add key mappings for <C-p> <C-n> <C-l> <C-j>
8792
* Various bugfixes
8893

89-
- 0.3 / 2009-10-13
94+
- 0.3 / 2009-10-13 -
9095
* Apply escape sequence coloring to output, e.g. ls --color
9196
* Clean up syntax files for portability
9297
* Fix several Vim 7.1 bugs

autoload/conque.vim

Lines changed: 99 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
" FILE: autoload/conque.vim
22
" AUTHOR: Nico Raffo <nicoraffo@gmail.com>
3-
" Shougo Matsushita <Shougo.Matsu@gmail.com> (original VimShell)
4-
" Yukihiro Nakadaira (vimproc)
5-
" MODIFIED: 2009-10-29
6-
" VERSION: 0.4, for Vim 7.0
3+
" MODIFIED: 2009-12-01
4+
" VERSION: 0.5, for Vim 7.0
75
" LICENSE: {{{
86
" Conque - pty interaction in Vim
97
" Copyright (C) 2009 Nico Raffo
@@ -73,6 +71,7 @@ function! conque#open(...) "{{{
7371

7472
" init variables.
7573
let b:prompt_history = {}
74+
let b:auto_wrapped = 0
7675
let b:current_command = ''
7776
let b:write_clear = 0
7877

@@ -94,18 +93,18 @@ endfunction "}}}
9493
function! s:set_buffer_settings(command, pre_hooks) "{{{
9594
" optional hooks to execute, e.g. 'split'
9695
for h in a:pre_hooks
97-
execute h
96+
silent execute h
9897
endfor
9998

100-
execute "edit " . substitute(a:command, ' ', '\\ ', 'g') . "\\ -\\ " . g:Conque_Idx
99+
silent execute "edit " . substitute(a:command, ' ', '\\ ', 'g') . "\\ -\\ " . g:Conque_Idx
101100
setlocal buftype=nofile " this buffer is not a file, you can't save it
102101
setlocal nonumber " hide line numbers
103102
setlocal foldcolumn=0 " reasonable left margin
104103
setlocal nowrap " default to no wrap (esp with MySQL)
105104
setlocal noswapfile " don't bother creating a .swp file
106105
set scrolloff=0 " don't use buffer lines. it makes the 'clear' command not work as expected
107106
setfiletype conque " useful
108-
execute "setlocal syntax=".g:Conque_Syntax
107+
silent execute "setlocal syntax=".g:Conque_Syntax
109108
setlocal foldmethod=manual
110109

111110
" run the current command
@@ -158,6 +157,12 @@ function! conque#run() "{{{
158157

159158

160159

160+
" if we are not at the current active command line, don't execute
161+
if line('.') < max(keys(b:prompt_history)) && line('.') != line('$')
162+
execute "normal j^"
163+
return
164+
endif
165+
161166
" check if subprocess still exists
162167
if !exists('b:subprocess')
163168
return
@@ -216,7 +221,13 @@ function! conque#write(add_newline) "{{{
216221
" record command history
217222
let b:current_command = l:in
218223

219-
normal! G$
224+
" clear out our command
225+
if exists("b:prompt_history['".line('.')."']")
226+
227+
call setline(line('.'), b:prompt_history[line('.')])
228+
endif
229+
230+
normal! $
220231

221232

222233
return 1
@@ -240,55 +251,71 @@ endfunction "}}}
240251
" also manages multi-line commands.
241252
function! s:get_command() "{{{
242253

243-
let l:in = getline('.')
244-
245-
if l:in == ''
246-
" Do nothing.
247-
248-
elseif exists("b:prompt_history['".line('.')."']")
249-
let l:in = l:in[len(b:prompt_history[line('.')]) : ]
250-
251-
else
252-
" Maybe line numbering got disrupted, search for a matching prompt.
253-
let l:prompt_search = 0
254-
for pnr in reverse(sort(keys(b:prompt_history)))
255-
let l:prompt_length = len(b:prompt_history[pnr])
256-
" In theory 0 length or ' ' prompt shouldn't exist, but still...
257-
if l:prompt_length > 0 && b:prompt_history[pnr] != ' '
258-
" Does the current line have this prompt?
259-
if l:in[0 : l:prompt_length - 1] == b:prompt_history[pnr]
260-
let l:in = l:in[l:prompt_length : ]
261-
let l:prompt_search = pnr
254+
let l:in = getline('.')
255+
256+
if l:in == ''
257+
" Do nothing.
258+
259+
elseif exists("b:prompt_history['".line('.')."']")
260+
261+
let l:in = l:in[len(b:prompt_history[line('.')]) : ]
262+
263+
else
264+
" Maybe line numbering got disrupted, search for a matching prompt.
265+
let l:prompt_search = 0
266+
if line('.') == line('$')
267+
for pnr in reverse(sort(keys(b:prompt_history)))
268+
let l:prompt_length = len(b:prompt_history[pnr])
269+
" In theory 0 length or ' ' prompt shouldn't exist, but still...
270+
if l:prompt_length > 0 && b:prompt_history[pnr] != ' '
271+
" Does the current line have this prompt?
272+
if l:in[0 : l:prompt_length - 1] == b:prompt_history[pnr]
273+
" found a matching prompt in history
274+
275+
let b:prompt_history[line('.')] = b:prompt_history[pnr]
276+
let l:in = l:in[l:prompt_length : ]
277+
let l:prompt_search = pnr
278+
endif
279+
endif
280+
endfor
262281
endif
263-
endif
264-
endfor
265282

266-
" Still nothing? Maybe a multi-line command was pasted in.
267-
let l:max_prompt = max(keys(b:prompt_history)) " Only count once.
268-
if l:prompt_search == 0 && l:max_prompt < line('$')
269-
for i in range(l:max_prompt, line('$'))
270-
if i == l:max_prompt
271-
let l:in = getline(i)
272-
let l:in = l:in[len(b:prompt_history[i]) : ]
273-
else
274-
let l:in = l:in . "\n" . getline(i)
275-
endif
276-
endfor
277-
let l:prompt_search = l:max_prompt
278-
endif
283+
" Still nothing? Maybe a multi-line command was pasted in.
284+
let l:max_prompt = max(keys(b:prompt_history)) " Only count once.
285+
if l:prompt_search == 0 && l:max_prompt < line('$')
286+
287+
for i in range(l:max_prompt, line('$'))
288+
if i == l:max_prompt
289+
let l:in = getline(i)
290+
let l:in = l:in[len(b:prompt_history[i]) : ]
291+
else
292+
293+
" detect if multi-line command was a product of command editing functions
294+
if b:auto_wrapped == 1
295+
let l:in = l:in . getline(i)
296+
else
297+
let l:in = l:in . "\n" . getline(i)
298+
endif
299+
endif
300+
endfor
301+
call cursor(l:max_prompt, len(b:prompt_history[l:max_prompt]))
302+
let l:prompt_search = l:max_prompt
303+
304+
" delete extra lines
305+
execute (l:prompt_search + 1) . ',' . line('$') . 'd'
306+
endif
279307

280-
" Still nothing? We give up.
281-
if l:prompt_search == 0
308+
" Still nothing? We give up.
309+
if l:prompt_search == 0
282310

283-
echohl WarningMsg | echo "Invalid input." | echohl None
284-
normal! G$
285-
startinsert!
286-
return
311+
echohl WarningMsg | echo "Invalid input." | echohl None
312+
startinsert!
313+
return
314+
endif
287315
endif
288-
endif
289316

290317

291-
return l:in
318+
return l:in
292319
endfunction "}}}
293320

294321
" read from pty and write to buffer
@@ -315,9 +342,6 @@ function! conque#read(timeout) "{{{
315342

316343

317344

318-
" ready to insert now
319-
normal! G$
320-
321345
" record prompt used on this line
322346
let b:prompt_history[line('.')] = getline('.')
323347

@@ -349,31 +373,8 @@ endfunction "}}}
349373
" parse output from pty and update buffer
350374
function! s:print_buffer(read_lines) "{{{
351375

352-
" clear out our command
353-
if exists("b:prompt_history['".line('$')."']")
354-
355-
call setline(line('$'), b:prompt_history[line('$')])
356-
endif
357-
358-
" maybe put this in config later
359-
let l:pos = 1
360-
for eline in a:read_lines
361-
" write to buffer
362376

363-
if l:pos == 1
364-
"let eline = substitute(eline, '^\b\+', '', 'g')
365-
call setline(line('$'), getline(line('$')) . eline)
366-
else
367-
call append(line('$'), eline)
368-
endif
369-
370-
" translate terminal escape sequences
371-
normal! G$
372-
call subprocess#shell_translate#process_current_line()
373-
374-
let l:pos += 1
375-
normal G
376-
endfor
377+
call subprocess#shell_translate#process_input(line('.'), len(getline('.')) + 1, a:read_lines, 0)
377378

378379
redraw
379380

@@ -458,7 +459,9 @@ endfunction "}}}
458459

459460
" process command editing key strokes. History and tab completion being the most common.
460461
function! s:process_command_edit(char) "{{{
461-
let l:prompt = b:prompt_history[line('$')]
462+
463+
let l:prompt_line = max(keys(b:prompt_history))
464+
let l:prompt = b:prompt_history[l:prompt_line]
462465
let l:working_line = getline('.')
463466
let l:working_command = l:working_line[len(l:prompt) : len(l:working_line)]
464467

@@ -467,35 +470,26 @@ function! s:process_command_edit(char) "{{{
467470
elseif b:write_clear == 0
468471

469472
call b:subprocess.write(l:working_command . a:char)
470-
call setline(line('$'), l:prompt)
473+
call setline(line('.'), l:prompt)
471474
elseif l:working_command[0 : len(b:edit_command) - 1] == b:edit_command
472475

473476
call b:subprocess.write(l:working_command[len(b:edit_command) : ] . a:char)
474-
call setline(line('$'), l:prompt . b:edit_command)
477+
call setline(line('.'), l:prompt . b:edit_command)
475478
else
476479

477480

478481
call b:subprocess.write("\<C-u>" . l:working_command . a:char)
479-
call setline(line('$'), l:prompt . b:edit_command)
482+
call setline(line('.'), l:prompt . b:edit_command)
480483
endif
481484
let l:resp = conque#read_return_raw(g:Conque_Tab_Timeout)
482485

483486

484-
for i in range(0, len(l:resp) - 1)
487+
call subprocess#shell_translate#process_input(line('.'), len(getline('.')) + 1, l:resp, 1)
485488

486-
if i > 0
487-
call setline(line('.') + 1, getline(line('.') + 1) . l:resp[i])
488-
normal! j
489-
else
490-
call setline(line('.'), getline(line('.')) . l:resp[i])
491-
endif
492-
call subprocess#shell_translate#process_current_line()
493-
endfor
494489

495490

496491

497-
498-
let b:prompt_history[line('$')] = l:prompt
492+
"let b:prompt_history[l:prompt_line] = l:prompt
499493

500494
let l:working_line = getline('.')
501495
let b:edit_command = l:working_line[len(l:prompt) : ]
@@ -559,9 +553,15 @@ function! conque#kill_line() "{{{
559553
let l:hopefully_just_backspaces = conque#read_return_raw(g:Conque_Tab_Timeout)
560554

561555
" restore empty prompt
562-
call setline(line('.'), b:prompt_history[max(keys(b:prompt_history))])
563-
normal! G$
564-
startinsert!
556+
let l:max_prompt = max(keys(b:prompt_history))
557+
call setline(l:max_prompt, b:prompt_history[l:max_prompt])
558+
if line('$') > l:max_prompt
559+
for i in range(l:max_prompt + 1, line('$'))
560+
call setline(i, '')
561+
endfor
562+
endif
563+
"normal! G$
564+
"startinsert!
565565
endfunction "}}}
566566

567567
" implement <C-c>
@@ -658,13 +658,13 @@ function! conque#special(command) "{{{
658658
if a:command =~ '^man '
659659
let split_cmd = "split " . substitute(a:command, '\W', '_', 'g')
660660

661-
execute split_cmd
661+
silent execute split_cmd
662662
setlocal buftype=nofile
663663
setlocal nonumber
664664
setlocal noswapfile
665665
let cmd = 'read !' . substitute(a:command, '^man ', 'man -P cat ', '')
666666

667-
execute cmd
667+
silent execute cmd
668668

669669
" strip backspaces out of output
670670
try
@@ -680,7 +680,7 @@ function! conque#special(command) "{{{
680680
let filename = b:subprocess.get_env_var('PWD') . '/' . filename
681681
let split_cmd = "split " . filename
682682

683-
execute split_cmd
683+
silent execute split_cmd
684684
endif
685685
endfunction "}}}
686686

@@ -694,7 +694,7 @@ function! conque#inject(type, execute) "{{{
694694
let @@ = substitute(@@, '^[\r\n]*', '', '')
695695
let @@ = substitute(@@, '[\r\n]*$', '', '')
696696

697-
execute ":sb " . g:Conque_BufName
697+
silent execute ":sb " . g:Conque_BufName
698698
normal! G$p
699699
normal! G$
700700
startinsert!

0 commit comments

Comments
 (0)