@@ -445,23 +445,16 @@ def clear_call_signatures():
445
445
vim_command ('echo ""' )
446
446
return
447
447
cursor = vim .current .window .cursor
448
- e = vim_eval ('g:jedi#call_signature_escape' )
449
- # We need two turns here to search and replace certain lines:
450
- # 1. Search for a line with a call signature and save the appended
451
- # characters
452
- # 2. Actually replace the line and redo the status quo.
453
- py_regex = r'%sjedi=([0-9]+), (.*?)%s.*?%sjedi%s' .replace (
454
- '%s' , re .escape (e ))
455
- for i , line in enumerate (vim .current .buffer ):
456
- match = re .search (py_regex , line )
457
- if match is not None :
458
- # Some signs were added to minimize syntax changes due to call
459
- # signatures. We have to remove them again. The number of them is
460
- # specified in `match.group(1)`.
461
- after = line [match .end () + int (match .group (1 )):]
462
- line = line [:match .start ()] + match .group (2 ) + after
463
- vim .current .buffer [i ] = line
464
- vim .current .window .cursor = cursor
448
+
449
+ if not int (vim_eval ("exists('b:_jedi_callsig_orig')" )):
450
+ return
451
+ for linenr , line in vim_eval ('b:_jedi_callsig_orig' ).items ():
452
+ # Check that the line would be reset, helps with keeping a single
453
+ # undochain.
454
+ if line != vim .current .buffer [int (linenr )- 1 ]:
455
+ vim_command ('silent! undojoin' )
456
+ vim .current .buffer [int (linenr )- 1 ] = line
457
+ vim_command ('unlet b:_jedi_callsig_orig' )
465
458
466
459
467
460
@_check_jedi_availability (show_error = False )
@@ -481,6 +474,7 @@ def show_call_signatures(signatures=()):
481
474
return cmdline_call_signatures (signatures )
482
475
483
476
seen_sigs = []
477
+ set_lines = []
484
478
for i , signature in enumerate (signatures ):
485
479
line , column = signature .bracket_start
486
480
# signatures are listed above each other
@@ -541,7 +535,17 @@ def show_call_signatures(signatures=()):
541
535
tup = '%s, %s' % (len (add ), replace )
542
536
repl = prefix + (regex % (tup , text )) + add + line [end_column :]
543
537
544
- vim_eval ('setline(%s, %s)' % (line_to_replace , repr (PythonToVimStr (repl ))))
538
+ set_lines .append ((line_to_replace , repl ))
539
+
540
+ if not set_lines :
541
+ return
542
+
543
+ orig_lines = {}
544
+ for linenr , line in set_lines :
545
+ orig_lines [linenr ] = vim .current .buffer [linenr - 1 ]
546
+ vim_command ('silent! undojoin' )
547
+ vim .current .buffer [int (linenr )- 1 ] = line
548
+ vim_command ("let b:_jedi_callsig_orig = {!r}" .format (orig_lines ))
545
549
546
550
547
551
@catch_and_print_exceptions
0 commit comments