better support for function display in strings

This commit is contained in:
David Halter
2012-10-12 21:48:26 +02:00
parent 7bc151be75
commit 15426a3d51
3 changed files with 34 additions and 11 deletions

View File

@@ -17,6 +17,19 @@ if g:jedi#show_function_definition == 1 && has('conceal')
hi jediFat term=bold,underline cterm=bold,underline gui=bold,underline ctermbg=0 guibg=Grey hi jediFat term=bold,underline cterm=bold,underline gui=bold,underline ctermbg=0 guibg=Grey
hi jediFunction term=NONE cterm=NONE ctermfg=6 guifg=Cyan gui=NONE ctermbg=0 guibg=Grey hi jediFunction term=NONE cterm=NONE ctermfg=6 guifg=Cyan gui=NONE ctermbg=0 guibg=Grey
" override defaults " override defaults (add jediFunction to contains)
syn match pythonComment "#.*$" contains=pythonTodo,@Spell,jediFunction syn match pythonComment "#.*$" contains=pythonTodo,@Spell,jediFunction
syn region pythonString
\ start=+[uU]\=\z(['"]\)+ end="\z1" skip="\\\\\|\\\z1"
\ contains=pythonEscape,@Spell,jediFunction
syn region pythonString
\ start=+[uU]\=\z('''\|"""\)+ end="\z1" keepend
\ contains=pythonEscape,pythonSpaceError,pythonDoctest,@Spell,jediFunction
syn region pythonRawString
\ start=+[uU]\=[rR]\z(['"]\)+ end="\z1" skip="\\\\\|\\\z1"
\ contains=@Spell,jediFunction
syn region pythonRawString
\ start=+[uU]\=[rR]\z('''\|"""\)+ end="\z1" keepend
\ contains=pythonSpaceError,pythonDoctest,@Spell,jediFunction
endif endif

View File

@@ -65,8 +65,8 @@ python << PYTHONEOF
if 1: if 1:
try: try:
show_func_def(get_script().get_in_function_call()) show_func_def(get_script().get_in_function_call())
except Exception as e: except Exception:
print e print(traceback.format_exc())
PYTHONEOF PYTHONEOF
return '' return ''
endfunction endfunction
@@ -77,12 +77,16 @@ python << PYTHONEOF
if 1: if 1:
cursor = vim.current.window.cursor cursor = vim.current.window.cursor
e = vim.eval('g:jedi#function_definition_escape') e = vim.eval('g:jedi#function_definition_escape')
regex = r'%sjedi=\([^%s]*\)%s.*%sjedi%s'.replace('%s', e) regex = r'%sjedi=([0-9]+), ([^%s]*)%s.*%sjedi%s'.replace('%s', e)
vim.command(r'try | %%s/%s/\1/g | catch | endtry' % regex) for i, line in enumerate(vim.current.buffer):
match = re.search(r'%s' % regex, line)
if match is not None:
vim_regex = r'\v' + regex.replace('=', r'\=') + '.{%s}' % int(match.group(1))
vim.command(r'try | %s,%ss/%s/\2/g | catch | endtry' % (i + 1, i + 1, vim_regex))
vim.command('call histdel("search", -1)')
vim.command('let @/ = histget("search", -1)')
vim.current.window.cursor = cursor vim.current.window.cursor = cursor
PYTHONEOF PYTHONEOF
call histdel("search", -1)
let @/ = histget("search", -1)
endfunction endfunction

View File

@@ -168,7 +168,8 @@ def show_func_def(call_def, completion_lines=0):
if column < 2 or row == 0: if column < 2 or row == 0:
return # edge cases, just ignore return # edge cases, just ignore
row_to_replace = row - 1 # TODO check if completion menu is above or below # TODO check if completion menu is above or below
row_to_replace = row - 1
line = vim.eval("getline(%s)" % row_to_replace) line = vim.eval("getline(%s)" % row_to_replace)
insert_column = column - 2 # because it has stuff at the beginning insert_column = column - 2 # because it has stuff at the beginning
@@ -185,9 +186,14 @@ def show_func_def(call_def, completion_lines=0):
# replace line before with cursor # replace line before with cursor
e = vim.eval('g:jedi#function_definition_escape') e = vim.eval('g:jedi#function_definition_escape')
regex = "xjedi=%sx%sxjedix".replace('x', e) regex = "xjedi=%sx%sxjedix".replace('x', e)
repl = ("%s" + regex + "%s") % (line[:insert_column],
line[insert_column:end_column], text, line[end_column:]) # check the replace stuff for strings, to append them (don't want to break the syntax)
vim.eval('setline(%s, "%s")' % (row_to_replace, repl)) replace = line[insert_column:end_column]
add = ''.join(re.findall('\\\\*["\']+', replace)) # add are all the strings
tup = '%s, %s' % (len(add), replace)
repl = ("%s" + regex + "%s") % (line[:insert_column], tup, text, add + line[end_column:])
vim.eval('setline(%s, %s)' % (row_to_replace, repr(PythonToVimStr(repl))))
PYTHONEOF PYTHONEOF
" vim: set et ts=4: " vim: set et ts=4: