@@ -22,8 +22,8 @@ def ask(self, prompt, default=None, starting=None):
22
22
if starting is None :
23
23
starting = ''
24
24
if default is not None :
25
- prompt = prompt + ( '[%s ] '% default )
26
- result = call ('input("%s ", "%s ")' % (prompt ,starting ))
25
+ prompt = prompt + '[{0} ] '. format ( default )
26
+ result = call ('input("{0} ", "{1} ")' . format (prompt ,starting ))
27
27
if default is not None and result == '' :
28
28
return default
29
29
return result
@@ -33,11 +33,14 @@ def ask_values(self, prompt, values, default=None,
33
33
if show_values or (show_values is None and len (values )< 14 ):
34
34
self ._print_values (values )
35
35
if default is not None :
36
- prompt = prompt + ( '[%s ] '% default )
36
+ prompt = prompt + '[{0} ] '. format ( default )
37
37
starting = starting or ''
38
38
_completer .values = values
39
- answer = call ('input("%s", "%s", "customlist,RopeValueCompleter")' %
40
- (prompt ,starting ))
39
+ answer = call (
40
+ 'input("{0}", "{1}", "customlist,RopeValueCompleter")' .format (
41
+ prompt ,starting
42
+ )
43
+ )
41
44
if answer is None :
42
45
if 'cancel' in values :
43
46
return 'cancel'
@@ -55,14 +58,14 @@ def _print_values(self, values):
55
58
echo ('\n ' .join (numbered )+ '\n ' )
56
59
57
60
def ask_directory (self ,prompt ,default = None ,starting = None ):
58
- return call ('input("%s ", ".", "dir")' % prompt )
61
+ return call ('input("{0} ", ".", "dir")' . format ( prompt ) )
59
62
60
63
def _update_proposals (self ,values ):
61
64
self .completeopt = vim .eval ('&completeopt' )
62
65
self .preview = 'preview' in self .completeopt
63
66
64
67
if not self .get ('extended_complete' ):
65
- return u',' .join (u"'%s'" % self ._completion_text (proposal )
68
+ return u',' .join (u"'{0}'" . format ( self ._completion_text (proposal ) )
66
69
for proposal in values )
67
70
68
71
return u',' .join (self ._extended_completion (proposal )
@@ -79,7 +82,7 @@ def ask_completion(self, prompt, values, starting=None):
79
82
col = int (call ('col(".")' ))
80
83
if starting :
81
84
col -= len (starting )
82
- self ._command (u'call complete(%s , [%s ])' % (col ,proposals ),
85
+ self ._command (u'call complete({0} , [{1} ])' . format (col ,proposals ),
83
86
encode = True )
84
87
return None
85
88
@@ -96,8 +99,8 @@ def y_or_n(self, prompt):
96
99
return self .yes_or_no (prompt )
97
100
98
101
def get (self ,name ,default = None ):
99
- vimname = 'g:pymode_rope_%s' % name
100
- if str (vim .eval ('exists("%s ")' % vimname ))== '0' :
102
+ vimname = 'g:pymode_rope_{0}' . format ( name )
103
+ if str (vim .eval ('exists("{0} ")' . format ( vimname ) ))== '0' :
101
104
return default
102
105
result = vim .eval (vimname )
103
106
if isinstance (result ,str )and result .isdigit ():
@@ -262,8 +265,9 @@ def _writedefs(self, locations, filename):
262
265
263
266
def show_doc (self ,docs ,altview = False ):
264
267
if docs :
265
- cmd = 'call pymode#ShowStr("%s")' % str (docs .replace ('"' ,'\\ "' ))
266
- vim .command (cmd )
268
+ vim .command (
269
+ 'call pymode#ShowStr("{0}")' .format (docs .replace ('"' ,'\\ "' ))
270
+ )
267
271
268
272
def preview_changes (self ,diffs ):
269
273
echo (diffs )
@@ -282,23 +286,33 @@ def add_hook(self, name, callback, hook):
282
286
'after_save' :'FileWritePost,BufWritePost' ,
283
287
'exit' :'VimLeave' }
284
288
self ._add_function (name ,callback )
285
- vim .command ('autocmd %s *.py call %s()' %
286
- (mapping [hook ],_vim_name (name )))
289
+ vim .command (
290
+ 'autocmd {0} *.py call {1}()' .format (
291
+ mapping [hook ],_vim_name (name )
292
+ )
293
+ )
287
294
288
295
def _add_command (self ,name ,callback ,key ,prefix ,prekey ):
289
296
self ._add_function (name ,callback ,prefix )
290
- vim .command ('command! -range %s call %s()' %
291
- (_vim_name (name ),_vim_name (name )))
297
+ vim .command (
298
+ 'command! -range {0} call {1}()' .format (
299
+ _vim_name (name ),_vim_name (name )
300
+ )
301
+ )
292
302
if key is not None :
293
303
key = prekey + key .replace (' ' ,'' )
294
- vim .command ('noremap %s :call %s()<cr>' % (key ,_vim_name (name )))
304
+ vim .command (
305
+ 'noremap {0} :call {1}()<cr>' .format (key ,_vim_name (name ))
306
+ )
295
307
296
308
def _add_function (self ,name ,callback ,prefix = False ):
297
309
globals ()[name ]= callback
298
310
arg = 'None' if prefix else ''
299
- vim .command ('function! %s()\n ' % _vim_name (name )+
300
- 'python ropevim.%s(%s)\n ' % (name ,arg )+
301
- 'endfunction\n ' )
311
+ vim .command (
312
+ 'function! {0}()\n '
313
+ 'python ropevim.{1}({2})\n '
314
+ 'endfunction\n ' .format (_vim_name (name ),name ,arg )
315
+ )
302
316
303
317
def _completion_data (self ,proposal ):
304
318
return proposal
@@ -318,7 +332,7 @@ def _extended_completion(self, proposal):
318
332
319
333
if proposal .scope == 'parameter_keyword' :
320
334
default = proposal .get_default ()
321
- ci ["menu" ]+= '*' if default is None else '=%s' % default
335
+ ci ["menu" ]+= '*' if default is None else '={0}' . format ( default )
322
336
323
337
if self .preview and not ci ['menu' ]:
324
338
doc = proposal .get_doc ()
@@ -329,9 +343,9 @@ def _extended_completion(self, proposal):
329
343
def _conv (self ,obj ):
330
344
if isinstance (obj ,dict ):
331
345
return u'{' + u',' .join ([
332
- u"%s:%s" % (self ._conv (key ),self ._conv (value ))
346
+ u"{0}:{1}" . format (self ._conv (key ),self ._conv (value ))
333
347
for key ,value in obj .iteritems ()])+ u'}'
334
- return u'"%s"' % str (obj ).replace (u'"' ,u'\\ "' )
348
+ return u'"{0}"' . format ( str (obj ).replace (u'"' ,u'\\ "' ) )
335
349
336
350
337
351
def _vim_name (name ):
@@ -345,19 +359,21 @@ class VimProgress(object):
345
359
def __init__ (self ,name ):
346
360
self .name = name
347
361
self .last = 0
348
- status ('%s ... ' % self .name )
362
+ status ('{0} ... ' . format ( self .name ) )
349
363
350
364
def update (self ,percent ):
351
365
try :
352
366
vim .eval ('getchar(0)' )
353
367
except vim .error :
354
- raise KeyboardInterrupt ('Task %s was interrupted!' % self .name )
368
+ raise KeyboardInterrupt (
369
+ 'Task {0} was interrupted!' .format (self .name )
370
+ )
355
371
if percent > self .last + 4 :
356
- status ('%s ...%s%%' % (self .name ,percent ))
372
+ status ('{0} ...{1}%' . format (self .name ,percent ))
357
373
self .last = percent
358
374
359
375
def done (self ):
360
- status ('%s ... done' % self .name )
376
+ status ('{0} ... done' . format ( self .name ) )
361
377
362
378
363
379
def echo (message ):
@@ -369,7 +385,7 @@ def echo(message):
369
385
def status (message ):
370
386
if isinstance (message ,unicode ):
371
387
message = message .encode (vim .eval ('&encoding' ))
372
- vim .command ('redraw | echon "%s"' % message )
388
+ vim .command ('redraw | echon "{0}"' . format ( message ) )
373
389
374
390
375
391
def call (command ):
@@ -396,7 +412,7 @@ def __call__(self, arg_lead, cmd_line, cursor_pos):
396
412
else :
397
413
result = [proposal for proposal in self .values
398
414
if proposal .startswith (arg_lead )]
399
- vim .command ('let s:completions =%s' % result )
415
+ vim .command ('let s:completions ={0}' . format ( result ) )
400
416
401
417
402
418
class RopeMode (interface .RopeMode ):