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