Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit681a182

Browse files
committed
Use python's string.format() instead of string substitution.
1 parentf135021 commit681a182

File tree

1 file changed

+45
-29
lines changed

1 file changed

+45
-29
lines changed

‎pylibs/ropevim.py

Lines changed: 45 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ def ask(self, prompt, default=None, starting=None):
2222
ifstartingisNone:
2323
starting=''
2424
ifdefaultisnotNone:
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))
2727
ifdefaultisnotNoneandresult=='':
2828
returndefault
2929
returnresult
@@ -33,11 +33,14 @@ def ask_values(self, prompt, values, default=None,
3333
ifshow_valuesor (show_valuesisNoneandlen(values)<14):
3434
self._print_values(values)
3535
ifdefaultisnotNone:
36-
prompt=prompt+('[%s] '%default)
36+
prompt=prompt+'[{0}] '.format(default)
3737
starting=startingor''
3838
_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+
)
4144
ifanswerisNone:
4245
if'cancel'invalues:
4346
return'cancel'
@@ -55,14 +58,14 @@ def _print_values(self, values):
5558
echo('\n'.join(numbered)+'\n')
5659

5760
defask_directory(self,prompt,default=None,starting=None):
58-
returncall('input("%s", ".", "dir")'%prompt)
61+
returncall('input("{0}", ".", "dir")'.format(prompt))
5962

6063
def_update_proposals(self,values):
6164
self.completeopt=vim.eval('&completeopt')
6265
self.preview='preview'inself.completeopt
6366

6467
ifnotself.get('extended_complete'):
65-
returnu','.join(u"'%s'"%self._completion_text(proposal)
68+
returnu','.join(u"'{0}'".format(self._completion_text(proposal))
6669
forproposalinvalues)
6770

6871
returnu','.join(self._extended_completion(proposal)
@@ -79,7 +82,7 @@ def ask_completion(self, prompt, values, starting=None):
7982
col=int(call('col(".")'))
8083
ifstarting:
8184
col-=len(starting)
82-
self._command(u'call complete(%s, [%s])'%(col,proposals),
85+
self._command(u'call complete({0}, [{1}])'.format(col,proposals),
8386
encode=True)
8487
returnNone
8588

@@ -96,8 +99,8 @@ def y_or_n(self, prompt):
9699
returnself.yes_or_no(prompt)
97100

98101
defget(self,name,default=None):
99-
vimname='g:pymode_rope_%s'%name
100-
ifstr(vim.eval('exists("%s")'%vimname))=='0':
102+
vimname='g:pymode_rope_{0}'.format(name)
103+
ifstr(vim.eval('exists("{0}")'.format(vimname)))=='0':
101104
returndefault
102105
result=vim.eval(vimname)
103106
ifisinstance(result,str)andresult.isdigit():
@@ -262,8 +265,9 @@ def _writedefs(self, locations, filename):
262265

263266
defshow_doc(self,docs,altview=False):
264267
ifdocs:
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+
)
267271

268272
defpreview_changes(self,diffs):
269273
echo(diffs)
@@ -282,23 +286,33 @@ def add_hook(self, name, callback, hook):
282286
'after_save':'FileWritePost,BufWritePost',
283287
'exit':'VimLeave'}
284288
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+
)
287294

288295
def_add_command(self,name,callback,key,prefix,prekey):
289296
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+
)
292302
ifkeyisnotNone:
293303
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+
)
295307

296308
def_add_function(self,name,callback,prefix=False):
297309
globals()[name]=callback
298310
arg='None'ifprefixelse''
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+
)
302316

303317
def_completion_data(self,proposal):
304318
returnproposal
@@ -318,7 +332,7 @@ def _extended_completion(self, proposal):
318332

319333
ifproposal.scope=='parameter_keyword':
320334
default=proposal.get_default()
321-
ci["menu"]+='*'ifdefaultisNoneelse'=%s'%default
335+
ci["menu"]+='*'ifdefaultisNoneelse'={0}'.format(default)
322336

323337
ifself.previewandnotci['menu']:
324338
doc=proposal.get_doc()
@@ -329,9 +343,9 @@ def _extended_completion(self, proposal):
329343
def_conv(self,obj):
330344
ifisinstance(obj,dict):
331345
returnu'{'+u','.join([
332-
u"%s:%s"%(self._conv(key),self._conv(value))
346+
u"{0}:{1}".format(self._conv(key),self._conv(value))
333347
forkey,valueinobj.iteritems()])+u'}'
334-
returnu'"%s"'%str(obj).replace(u'"',u'\\"')
348+
returnu'"{0}"'.format(str(obj).replace(u'"',u'\\"'))
335349

336350

337351
def_vim_name(name):
@@ -345,19 +359,21 @@ class VimProgress(object):
345359
def__init__(self,name):
346360
self.name=name
347361
self.last=0
348-
status('%s ... '%self.name)
362+
status('{0} ... '.format(self.name))
349363

350364
defupdate(self,percent):
351365
try:
352366
vim.eval('getchar(0)')
353367
exceptvim.error:
354-
raiseKeyboardInterrupt('Task %s was interrupted!'%self.name)
368+
raiseKeyboardInterrupt(
369+
'Task {0} was interrupted!'.format(self.name)
370+
)
355371
ifpercent>self.last+4:
356-
status('%s ...%s%%'%(self.name,percent))
372+
status('{0} ...{1}%'.format(self.name,percent))
357373
self.last=percent
358374

359375
defdone(self):
360-
status('%s ... done'%self.name)
376+
status('{0} ... done'.format(self.name))
361377

362378

363379
defecho(message):
@@ -369,7 +385,7 @@ def echo(message):
369385
defstatus(message):
370386
ifisinstance(message,unicode):
371387
message=message.encode(vim.eval('&encoding'))
372-
vim.command('redraw | echon "%s"'%message)
388+
vim.command('redraw | echon "{0}"'.format(message))
373389

374390

375391
defcall(command):
@@ -396,7 +412,7 @@ def __call__(self, arg_lead, cmd_line, cursor_pos):
396412
else:
397413
result= [proposalforproposalinself.values
398414
ifproposal.startswith(arg_lead)]
399-
vim.command('let s:completions =%s'%result)
415+
vim.command('let s:completions ={0}'.format(result))
400416

401417

402418
classRopeMode(interface.RopeMode):

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp