Permalink
Browse files

Displaying of all possible choices

  • Loading branch information...
1 parent 49779e3 commit d297a6fdeca19f349c222547262648f6634de111 @adaszko committed Mar 4, 2013
Showing with 36 additions and 5 deletions.
  1. +36 −5 autoload/chbuf.vim
View
@@ -1,15 +1,46 @@
+" TODO: Truncate choices on &columns
+" TODO: Tab-completion of longest common prefix
+" TODO: Filter out current buffer in choices
+" TODO: Score expand('#') file highest and select it initially
+" TODO: Make Tab behave as enter when longest common prefix is unambiguous
+" TODO: Score higher subsequences occuring after directory separator
+" TODO: Make functions script-private once they are sufficiently tested
+" IDEA: Perhaps <S-Return> should also :lcd into file's directory
+
+
let s:save_cpo = &cpo
set cpo&vim
-function! BufferNameCallback(contents) " {{{
- let buffer = bufname(a:contents)
+function! ExistingBuffersNumbers() " {{{
+ return filter(range(bufnr('$')), 'bufexists(v:val)')
+endfunction " }}}
+
+
+function! ScoredBuffers() " {{{
+ let buffers = ExistingBuffersNumbers()
+ let listed = filter(copy(buffers), 'buflisted(v:val)')
+ let unlisted = filter(copy(buffers), '!buflisted(v:val)')
+ return extend(listed, unlisted)
+endfunction " }}}
+
+
+function! MatchBuffers(input) " {{{
+ let buffers = map(ScoredBuffers(), 'bufname(v:val)')
+ let result = filter(buffers, printf('v:val =~ "%s"', escape(a:input, '"')))
+ return result
+endfunction " }}}
+
+
+function! BufferNameCallback(input) " {{{
+ let buffers = MatchBuffers(a:input)
- if buffer == ''
+ if len(buffers) == 0
return ''
- else
- return '' . bufname(a:contents)
endif
+
+ let caption = join(buffers)
+ return '' . caption
endfunction " }}}

0 comments on commit d297a6f

Please sign in to comment.