Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compatibility Fix for insert-mode Tab mapping #411

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions plugin/clang_complete.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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 ''
Expand Down
35 changes: 34 additions & 1 deletion plugin/snippets/clang_complete.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <tab> in insert mode (e.g. supertab)
vim.command("let oldmap=maparg(\"<tab>\", \"i\")")
oldmap = vim.eval("oldmap")

# and only use insert mode <tab> mapping if there is none
if (len(oldmap) == 0):
vim.command("inoremap <expr> <silent> <buffer> <tab> 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
Expand Down Expand Up @@ -44,4 +52,29 @@ def updateSnips():
isInclusive = vim.eval("&selection") == "inclusive"
vim.command('call feedkeys("\<ESC>v%dl\<C-G>", "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="\<ESC>A"')
else:
vim.command('let s:insertModeTabTmp="\<TAB>"')
else:
# line contains argument completion strings, perform a normal-mode tab
vim.command('call feedkeys("\<ESC>\<TAB>")')
vim.command('let s:insertModeTabTmp=""')
# vim: set ts=2 sts=2 sw=2 expandtab :