diff --git a/plugin/clang_complete.vim b/plugin/clang_complete.vim index 9717cb97..0d944c69 100644 --- a/plugin/clang_complete.vim +++ b/plugin/clang_complete.vim @@ -563,6 +563,11 @@ function! g:ClangUpdateQuickFix() return '' endfunction +function g:InsertModeTabHelper() + python insertModeTab() + return s:insertModeTabTmp +endfunction + function! g:ClangGotoDeclaration() call s:GotoDeclaration(0) return '' diff --git a/plugin/snippets/clang_complete.py b/plugin/snippets/clang_complete.py index 3c27e54c..b65b3294 100644 --- a/plugin/snippets/clang_complete.py +++ b/plugin/snippets/clang_complete.py @@ -9,8 +9,16 @@ def snippetsInit(): vim.command("syntax match placeHolderMark contained /\$`/ conceal") vim.command("syntax match placeHolderMark contained /`/ conceal") + # Check if there is a mapping for in insert mode (e.g. supertab) + vim.command("let oldmap=maparg(\"\", \"i\")") + oldmap = vim.eval("oldmap") + + # and only use insert mode mapping if there is none + if (len(oldmap) == 0): + vim.command("inoremap InsertModeTabHelper()") + # The two following function are performance sensitive, do _nothing_ -# more that the strict necessary. +# more than the strict necessary. def snippetsFormatPlaceHolder(word): return "$`%s`" % word @@ -44,4 +52,29 @@ def updateSnips(): isInclusive = vim.eval("&selection") == "inclusive" vim.command('call feedkeys("\v%dl\", "n")' % (end - start - isInclusive)) +def insertModeTab(): + line = vim.current.line + row, col = vim.current.window.cursor + + # look for argument completion strings (denoted by $` `) + r = re.compile('\$`[^`]*`') + result = r.search(line) + + if result is None: + # if none found, perform a normal tab or jump to the end of the line + # if the symbol under the cursor is a closing bracket + + # strange, we need +1 here if called as :python insertModeTab + # col = col + 1 + + # is the symbol under the cursor a closing bracket? + if col < len(line) and ( line[col] == ')' or line[col] == '>'): + # if so, jump to the end of the line + vim.command('let s:insertModeTabTmp="\A"') + else: + vim.command('let s:insertModeTabTmp="\"') + else: + # line contains argument completion strings, perform a normal-mode tab + vim.command('call feedkeys("\\")') + vim.command('let s:insertModeTabTmp=""') # vim: set ts=2 sts=2 sw=2 expandtab :