Permalink
Browse files

Merge remote-tracking branch 'ervandew/master'

  • Loading branch information...
2 parents 8e4ccb7 + 5a38ce8 commit bc0ef1ffe562412f2c4d81dba3f5c71f273beb3d @juanpabloaj committed Mar 18, 2012
Showing with 112 additions and 2 deletions.
  1. +42 −1 doc/supertab.txt
  2. +70 −1 plugin/supertab.vim
View
@@ -30,6 +30,9 @@ Supertab *supertab*
Inserting true tabs |supertab-mappingtabliteral|
Enhanced longest match support |supertab-longestenhanced|
Preselecting the first entry |supertab-longesthighlight|
+ Mapping <cr> to end completion |supertab-crmapping|
+ Auto close the preview window |supertab-closepreviewonpopupclose|
+ Completion Chaining |supertab-completionchaining|
==============================================================================
1. Introduction *supertab-intro*
@@ -304,13 +307,51 @@ g:SuperTabCrMapping (default value: 1)
When enabled, <cr> will cancel completion mode preserving the current text.
+Compatibility with other plugins:
+ - endwise: compatible
+ - delimitMate: not compatible (disabled if the delimitMate <cr> mapping is
+ detected.)
-Close the preview window on <cr> *supertab-rclosepreviewonpopupclose*
+
+Auto close the preview window *supertab-closepreviewonpopupclose*
*g:SuperTabClosePreviewOnPopupClose*
g:SuperTabClosePreviewOnPopupClose (default value: 0)
When enabled, supertab will attempt to close vim's completion preview window
when the completion popup closes (completion is finished or canceled).
+Completion Chaining *supertab-completionchaining*
+
+Note: Experimental
+
+SuperTab provides the ability to chain one of the completion functions
+(|completefunc| or |omnifunc|) together with a one of the default vim
+completion key sequences (|ins-completion|), giving you the ability to attempt
+completion with the first, and upon no results, fall back to the second.
+
+To utilize this feature you need to call the SuperTabChain function where
+the first argument is the name of a vim compatible |complete-function| and the
+second is one of vim's insert completion (|ins-completion|) key bindings
+(<c-p>, <c-n>, <c-x><c-]>, etc). Calling this function will set the current
+buffer's |completefunc| option to a supertab provided implementation which
+utilizes the supplied arguments to perform the completion. Since the
+|completefunc| option is being set, this feature works best when also
+setting |g:SuperTabDefaultCompletionType| to either "context" or "<c-x><c-u>".
+
+Here is an example that can be added to your .vimrc which will setup the
+supertab chaining for any filetype that has a provided |omnifunc| to first
+try that, then fall back to supertab's default, <c-p>, completion:
+
+ autocmd FileType *
+ \ if &omnifunc != '' |
+ \ call SuperTabChain(&omnifunc, "<c-p>") |
+ \ call SuperTabSetDefaultCompletionType("<c-x><c-u>") |
+ \ endif
+
+Note that this feature does not support chaining any other combination of
+completions (2 or more completion functions, 2 or more key bindings, etc.). It
+can only support 1 completion function followed by 1 key binding. This is due
+to limitations imposed by vim's code completion implementation.
+
vim:tw=78:ts=8:ft=help:norl:
View
@@ -675,6 +675,71 @@ function! s:ExpandMap(map) " {{{
return map
endfunction " }}}
+function! SuperTabDelayedCommand(command, ...) " {{{
+ echom 'delay: ' . a:command
+ let uid = fnamemodify(tempname(), ':t:r')
+ if &updatetime > 1
+ exec 'let g:delayed_updatetime_save' . uid . ' = &updatetime'
+ endif
+ exec 'let g:delayed_command' . uid . ' = a:command'
+ let &updatetime = len(a:000) ? a:000[0] : 1
+ exec 'augroup delayed_command' . uid
+ exec 'autocmd CursorHoldI * ' .
+ \ ' if exists("g:delayed_updatetime_save' . uid . '") | ' .
+ \ ' let &updatetime = g:delayed_updatetime_save' . uid . ' | ' .
+ \ ' unlet g:delayed_updatetime_save' . uid . ' | ' .
+ \ ' endif | ' .
+ \ ' exec g:delayed_command' . uid . ' | ' .
+ \ ' unlet g:delayed_command' . uid . ' | ' .
+ \ ' autocmd! delayed_command' . uid
+ " just in case user leaves insert mode before CursorHoldI fires
+ exec 'autocmd CursorHold * ' .
+ \ ' if exists("g:delayed_updatetime_save' . uid . '") | ' .
+ \ ' let &updatetime = g:delayed_updatetime_save' . uid . ' | ' .
+ \ ' unlet g:delayed_updatetime_save' . uid . ' | ' .
+ \ ' endif | ' .
+ \ ' autocmd! delayed_command' . uid
+ exec 'augroup END'
+endfunction " }}}
+
+function! SuperTabChain(completefunc, completekeys) " {{{
+ let b:SuperTabChain = [a:completefunc, a:completekeys]
+ setlocal completefunc=SuperTabCodeComplete
+endfunction " }}}
+
+function! SuperTabCodeComplete(findstart, base) " {{{
+ if !exists('b:SuperTabChain')
+ echoe 'No completion chain has been set.'
+ return -2
+ endif
+
+ if len(b:SuperTabChain) != 2
+ echoe 'Completion chain can only be used with 1 completion function ' .
+ \ 'and 1 fallback completion key binding.'
+ return -2
+ endif
+
+ let Func = function(b:SuperTabChain[0])
+ let keys = escape(b:SuperTabChain[1], '<')
+
+ if a:findstart
+ let start = Func(a:findstart, a:base)
+ if start >= 0
+ return start
+ endif
+
+ return col('.') - 1
+ endif
+
+ let results = Func(a:findstart, a:base)
+ if len(results)
+ return results
+ endif
+
+ call SuperTabDelayedCommand('call feedkeys("' . keys . '", "nt")')
+ return []
+endfunction " }}}
+
" Autocmds {{{
if g:SuperTabClosePreviewOnPopupClose
augroup supertab_close_preview
@@ -721,7 +786,11 @@ endfunction " }}}
endfunction
if g:SuperTabCrMapping
- if maparg('<CR>','i') =~ '<CR>'
+ if maparg('<CR>','i') =~ '<Plug>delimitMateCR'
+ " Not compatible w/ delimitMate since it doesn't play well with others
+ " and will always return a <cr> which we don't when selecting a
+ " completion.
+ elseif maparg('<CR>','i') =~ '<CR>'
let map = maparg('<cr>', 'i')
let cr = (map =~? '\(^\|[^)]\)<cr>')
let map = s:ExpandMap(map)

0 comments on commit bc0ef1f

Please sign in to comment.