Skip to content

Commit caeade8

Browse files
committed
Fix auto jumping and key insertion when clang complete snippet jump is not the default ...
When g:clang_complete_snippet_jump_map is not the default then two things broke: - snippet jumping after completion and - using mapped key when there is nothing to jump to (there is nothing to replace) This commit fixes that.
1 parent cd9ff88 commit caeade8

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

plugin/snippets/clang_complete.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
import re
22
import vim
33

4-
def snippetsInit():
4+
def getClangSnippetJumpKey(escapeForFeedkeys):
55
snippet_jump_map = vim.eval("g:clang_complete_snippet_jump_map")
6+
if escapeForFeedkeys:
7+
snippet_jump_map = snippet_jump_map.replace('<', r'\<').replace('"', r'\"')
8+
return snippet_jump_map
9+
10+
def snippetsInit():
11+
python_cmd = vim.eval('s:py_cmd')
12+
vim.command("noremap <silent> <buffer> <Plug>ClangSnippetJumpN :{} updateSnips()<CR>".format(python_cmd))
13+
vim.command("snoremap <silent> <buffer> <Plug>ClangSnippetJumpS <ESC>:{} updateSnips()<CR>".format(python_cmd))
14+
snippet_jump_map = getClangSnippetJumpKey(False)
615
if "" != snippet_jump_map:
7-
python_cmd = vim.eval('s:py_cmd')
8-
vim.command("noremap <silent> <buffer> {} :{} updateSnips()<CR>".format(snippet_jump_map, python_cmd))
9-
vim.command("snoremap <silent> <buffer> {} <ESC>:{} updateSnips()<CR>".format(snippet_jump_map, python_cmd))
16+
vim.command("map <silent> <buffer> {} <Plug>ClangSnippetJumpN".format(snippet_jump_map))
17+
vim.command("smap <silent> <buffer> {} <Plug>ClangSnippetJumpS".format(snippet_jump_map))
1018
if int(vim.eval("g:clang_conceal_snippets")) == 1:
1119
vim.command("syntax match placeHolder /\$`[^`]*`/ contains=placeHolderMark")
1220
vim.command("syntax match placeHolderMark contained /\$`/ conceal")
@@ -26,7 +34,8 @@ def snippetsAddSnippet(fullname, word, abbr):
2634
def snippetsTrigger():
2735
if r.search(vim.current.line) is None:
2836
return
29-
vim.command('call feedkeys("\<esc>^\<tab>")')
37+
# Using the Plug here works even if g:clang_complete_snippet_jump_map is empty.
38+
vim.command('call feedkeys("\<esc>^\<Plug>ClangSnippetJumpN")')
3039

3140
def snippetsReset():
3241
pass
@@ -39,7 +48,9 @@ def updateSnips():
3948
if result is None:
4049
result = r.search(line)
4150
if result is None:
42-
vim.command('call feedkeys("\<c-i>", "n")')
51+
snippet_jump_map = getClangSnippetJumpKey(True)
52+
if "" != snippet_jump_map:
53+
vim.command('call feedkeys("{}", "n")'.format(snippet_jump_map))
4354
return
4455

4556
start, end = result.span()

0 commit comments

Comments
 (0)