Permalink
Browse files

Got rid of (most) Press ENTER messages

  • Loading branch information...
1 parent 5621485 commit 6328060037ee975fc231a630fa7e84fedc00e092 @adaszko committed Mar 10, 2013
Showing with 41 additions and 10 deletions.
  1. +30 −5 autoload/chbuf.vim
  2. +11 −5 autoload/getline.vim
View
@@ -1,5 +1,7 @@
" DONE Show only path basenames as suggestions
-" TODO Truncate choices on &columns
+" DONE Get rid of "Press ENTER..." message
+" DONE Truncate choices on &columns
+" TODO There may be two buffers of the same name --- pick the first one
" TODO Tab-completion of longest common prefix
" TODO Filter out current buffer in choices
" TODO Score expand('#') file highest and select it initially
@@ -46,8 +48,28 @@ function! MatchBuffers(input) " {{{
endfunction " }}}
+function! LongestPrefixFitting(elems, length) " {{{
+ let curlen = 0
+
+ for i in range(len(a:elems))
+ let curlen += strlen(a:elems[i])
+ if curlen > a:length
+ if i == 0
+ return []
+ else
+ return a:elems[:i-1]
+ endif
+ endif
+ endfor
+
+ return a:elems
+endfunction " }}}
+
+
function! BufferNameCallback(input) " {{{
let buffers = MatchBuffers(a:input)
+ let cols = &columns - len(buffers) - 1 - 1
+ let buffers = LongestPrefixFitting(buffers, cols)
if len(buffers) == 0
return ''
@@ -58,10 +80,13 @@ function! BufferNameCallback(input) " {{{
endfunction " }}}
-function! chbuf#PromptBuffer() " {{{
- let name = getline#GetLine('', 'BufferNameCallback')
- execute 'silent' 'buffer' name
- return name
+function! PromptBuffer() " {{{
+ return getline#GetLine('', 'BufferNameCallback')
+endfunction " }}}
+
+
+function! chbuf#SwitchBuffer() " {{{
+ execute 'silent' 'buffer' PromptBuffer()
endfunction " }}}
View
@@ -2,8 +2,14 @@ let s:save_cpo = &cpo
set cpo&vim
+function! s:Echo(line)
+ echon strpart(a:line, 0, &columns-1)
+endfunction
+
+
function! s:ClearLine(contents) " {{{
- echon "\r" . repeat(' ', strlen(a:contents)) . "\r"
+ let rubber = "\r" . repeat(' ', strlen(a:contents)) . "\r"
+ call s:Echo(rubber)
endfunction! " }}}
@@ -23,8 +29,8 @@ function! getline#GetLine(prompt, get_status) " {{{
let status = call(a:get_status, [line])
let displayed = a:prompt . line . status
- echon displayed
- echon "\r" . strpart(displayed, 0, strlen(a:prompt) + strlen(line))
+ call s:Echo(displayed)
+ call s:Echo("\r" . strpart(displayed, 0, strlen(a:prompt) + strlen(line)))
while 1
let c = getchar()
@@ -58,8 +64,8 @@ function! getline#GetLine(prompt, get_status) " {{{
call s:ClearLine(displayed)
let status = call(a:get_status, [line])
let displayed = a:prompt . line . status
- echon "\r" . displayed
- echon "\r" . strpart(displayed, 0, strlen(a:prompt) + strlen(line))
+ call s:Echo("\r" . displayed)
+ call s:Echo("\r" . strpart(displayed, 0, strlen(a:prompt) + strlen(line)))
endwhile
call s:ClearLine(displayed)

0 comments on commit 6328060

Please sign in to comment.