@@ -498,19 +498,22 @@ def getargspec(func):
498498# Same deal with the exceptions :(
499499 return None
500500
501+ is_bound_method = inspect .ismethod (f ) and f .im_self is not None
501502 try :
502503 if inspect .isclass (f ):
503504 argspec = inspect .getargspec (f .__init__ )
505+ is_bound_method = True
504506 else :
505507 argspec = inspect .getargspec (f )
506- self .argspec = [func , argspec ]
508+ self .argspec = [func , argspec , is_bound_method ]
507509 return True
508510
509511 except (NameError , TypeError , KeyError ):
510512 t = getpydocspec (f , func )
511513 if t is None :
512514 return None
513515 self .argspec = t
516+ self .argspec .append (is_bound_method )
514517 return True
515518 except AttributeError :
516519# This happens if no __init__ is found
@@ -519,24 +522,35 @@ def getargspec(func):
519522 if not OPTS .arg_spec :
520523 return False
521524
522- stack = ['' ]
525+ stack = [[ '' , 0 ] ]
523526 try :
524527 for (token , value ) in PythonLexer ().get_tokens (self .s ):
525528 if token is Token .Punctuation :
526529 if value == '(' :
527- stack .append ('' )
530+ stack .append ([ '' , 0 ] )
528531 elif value == ')' :
529532 stack .pop ()
533+ elif value == ',' :
534+ try :
535+ stack [- 1 ][1 ] += 1
536+ except TypeError :
537+ stack [- 1 ][1 ] = ''
530538 elif (token is Token .Name or token in Token .Name .subtypes or
531- token is Token .Operatir and value == '.' ):
532- stack [- 1 ] += value
539+ token is Token .Operator and value == '.' ):
540+ stack [- 1 ][0 ] += value
541+ elif token is Token .Operator and value == '=' :
542+ stack [- 1 ][1 ] = stack [- 1 ][0 ]
533543 else :
534- stack [- 1 ] = ''
535- func = stack .pop () or stack .pop ()
544+ stack [- 1 ][0 ] = ''
545+ _ , arg_number = stack .pop ()
546+ func , _ = stack .pop ()
536547 except IndexError :
537548 return False
538549
539- return getargspec (func )
550+ if getargspec (func ):
551+ self .argspec .append (arg_number )
552+ return True
553+ return False
540554
541555 def check (self ):
542556 """Check if paste mode should still be active and, if not, deactivate
@@ -755,6 +769,8 @@ def mkargspec(self, topline, down):
755769 kwargs = topline [1 ][3 ]
756770 _args = topline [1 ][1 ]
757771 _kwargs = topline [1 ][2 ]
772+ is_bound_method = topline [2 ]
773+ in_arg = topline [3 ]
758774 max_w = int (self .scr .getmaxyx ()[1 ] * 0.6 )
759775 self .list_win .erase ()
760776 self .list_win .resize (3 , max_w )
@@ -766,6 +782,9 @@ def mkargspec(self, topline, down):
766782 self .list_win .addstr (': (' , get_colpair ('name' ))
767783 maxh = self .scr .getmaxyx ()[0 ]
768784
785+ if is_bound_method :
786+ in_arg += 1
787+
769788 for k , i in enumerate (args ):
770789 y , x = self .list_win .getyx ()
771790 ln = len (str (i ))
@@ -793,7 +812,10 @@ def mkargspec(self, topline, down):
793812 else :
794813 color = get_colpair ('token' )
795814
796- self .list_win .addstr (str (i ), color | curses .A_BOLD )
815+ if k == in_arg or i == in_arg :
816+ color |= curses .A_BOLD
817+
818+ self .list_win .addstr (str (i ), color )
797819 if kw :
798820 self .list_win .addstr ('=' , get_colpair ('punctuation' ))
799821 self .list_win .addstr (kw , get_colpair ('token' ))
@@ -1282,6 +1304,9 @@ def p_key(self):
12821304
12831305 if self .c in (chr (127 ), 'KEY_BACKSPACE' ):
12841306 self .bs ()
1307+ # Redraw (as there might have been highlighted parens)
1308+ self .print_line ('' )
1309+ self .print_line (self .s )
12851310 self .complete ()
12861311 return ''
12871312
@@ -1352,7 +1377,7 @@ def p_key(self):
13521377 self .write2file ()
13531378 return ''
13541379
1355- elif self .c == key_dispatch [OPTS .pastebin_key ]:
1380+ elif self .c in key_dispatch [OPTS .pastebin_key ]:
13561381 self .pastebin ()
13571382 return ''
13581383
0 commit comments