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

Commit0271137

Browse files
committed
Update ropevim
1 parent14aa358 commit0271137

File tree

1 file changed

+34
-38
lines changed

1 file changed

+34
-38
lines changed

‎pylibs/ropevim.py

Lines changed: 34 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -29,28 +29,30 @@ def ask(self, prompt, default=None, starting=None):
2929

3030
defask_values(self,prompt,values,default=None,
3131
starting=None,show_values=None):
32-
3332
ifshow_valuesor (show_valuesisNoneandlen(values)<14):
3433
self._print_values(values)
35-
3634
ifdefaultisnotNone:
3735
prompt=prompt+ ('[%s] '%default)
38-
3936
starting=startingor''
4037
_completer.values=values
4138
answer=call('input("%s", "%s", "customlist,RopeValueCompleter")'%
4239
(prompt,starting))
4340
ifanswerisNone:
44-
return'cancel'if'cancel'invalueselseNone
45-
41+
if'cancel'invalues:
42+
return'cancel'
43+
return
4644
ifdefaultisnotNoneandnotanswer:
4745
returndefault
48-
4946
ifanswer.isdigit()and0<=int(answer)<len(values):
5047
returnvalues[int(answer)]
51-
5248
returnanswer
5349

50+
def_print_values(self,values):
51+
numbered= []
52+
forindex,valueinenumerate(values):
53+
numbered.append('%s. %s'% (index,str(value)))
54+
echo('\n'.join(numbered)+'\n')
55+
5456
defask_directory(self,prompt,default=None,starting=None):
5557
returncall('input("%s", ".", "dir")'%prompt)
5658

@@ -86,21 +88,16 @@ def ask_completion(self, prompt, values, starting=None):
8688
defmessage(self,message):
8789
echo(message)
8890

89-
@staticmethod
90-
def_print_values(values):
91-
numbered= []
92-
forindex,valueinenumerate(values):
93-
numbered.append('%s. %s'% (index,str(value)))
94-
echo('\n'.join(numbered)+'\n')
95-
9691
defyes_or_no(self,prompt):
9792
returnself.ask_values(prompt, ['yes','no'])=='yes'
9893

9994
defy_or_n(self,prompt):
10095
returnself.yes_or_no(prompt)
10196

102-
defget(self,name):
97+
defget(self,name,default=None):
10398
vimname='g:pymode_rope_%s'%name
99+
ifstr(vim.eval('exists("%s")'%vimname))=='0':
100+
returndefault
104101
result=vim.eval(vimname)
105102
ifisinstance(result,str)andresult.isdigit():
106103
returnint(result)
@@ -121,20 +118,24 @@ def _decode_line(self, line):
121118
returnline.decode(self._get_encoding())
122119

123120
def_position_to_offset(self,lineno,colno):
124-
result=min(colno,len(vim.current.buffer[lineno-1])+1)
125-
forlineinvim.current.buffer[:lineno-1]:
121+
result=min(colno,len(self.buffer[lineno-1])+1)
122+
forlineinself.buffer[:lineno-1]:
126123
line=self._decode_line(line)
127124
result+=len(line)+1
128125
returnresult
129126

130127
defget_text(self):
131-
returnself._decode_line('\n'.join(vim.current.buffer))+u'\n'
128+
returnself._decode_line('\n'.join(self.buffer))+u'\n'
132129

133130
defget_region(self):
134-
start=self._position_to_offset(*vim.current.buffer.mark('<'))
135-
end=self._position_to_offset(*vim.current.buffer.mark('>'))
131+
start=self._position_to_offset(*self.buffer.mark('<'))
132+
end=self._position_to_offset(*self.buffer.mark('>'))
136133
returnstart,end
137134

135+
@property
136+
defbuffer(self):
137+
returnvim.current.buffer
138+
138139
def_get_cursor(self):
139140
lineno,col=vim.current.window.cursor
140141
line=self._decode_line(vim.current.line[:col])
@@ -155,7 +156,7 @@ def get_cur_dir():
155156
returnvim.eval('getcwd()')
156157

157158
deffilename(self):
158-
returnvim.current.buffer.name
159+
returnself.buffer.name
159160

160161
defis_modified(self):
161162
returnvim.eval('&modified')
@@ -164,21 +165,21 @@ def goto_line(self, lineno):
164165
self.cursor= (lineno,0)
165166

166167
definsert_line(self,line,lineno):
167-
vim.current.buffer[lineno-1:lineno-1]= [line]
168+
self.buffer[lineno-1:lineno-1]= [line]
168169

169170
definsert(self,text):
170171
lineno,colno=self.cursor
171-
line=vim.current.buffer[lineno-1]
172-
vim.current.buffer[lineno-1]=line[:colno]+text+line[colno:]
172+
line=self.buffer[lineno-1]
173+
self.buffer[lineno-1]=line[:colno]+text+line[colno:]
173174
self.cursor= (lineno,colno+len(text))
174175

175176
defdelete(self,start,end):
176177
lineno1,colno1=self._offset_to_position(start-1)
177178
lineno2,colno2=self._offset_to_position(end-1)
178179
lineno,colno=self.cursor
179180
iflineno1==lineno2:
180-
line=vim.current.buffer[lineno1-1]
181-
vim.current.buffer[lineno1-1]=line[:colno1]+line[colno2:]
181+
line=self.buffer[lineno1-1]
182+
self.buffer[lineno1-1]=line[:colno1]+line[colno2:]
182183
iflineno==lineno1andcolno>=colno1:
183184
diff=colno2-colno1
184185
self.cursor= (lineno,max(0,colno-diff))
@@ -194,17 +195,15 @@ def _offset_to_position(self, offset):
194195

195196
deffilenames(self):
196197
result= []
197-
forbinvim.buffers:
198-
ifb.name:
199-
result.append(b.name)
198+
forbufferinvim.buffers:
199+
ifbuffer.name:
200+
result.append(buffer.name)
200201
returnresult
201202

202203
defsave_files(self,filenames):
203204
vim.command('wall')
204205

205-
defreload_files(self,filenames,moves=None):
206-
ifmovesisNone:
207-
moves=dict()
206+
defreload_files(self,filenames,moves={}):
208207
initial=self.filename()
209208
forfilenameinfilenames:
210209
self.find_file(moves.get(filename,filename),force=True)
@@ -249,21 +248,20 @@ def _quickfixdefs(self, locations):
249248
finally:
250249
os.remove(filename)
251250

252-
@staticmethod
253-
def_writedefs(locations,filename):
251+
def_writedefs(self,locations,filename):
254252
tofile=open(filename,'w')
255253
try:
256254
forlocationinlocations:
257255
err='%s:%d: - %s\n'% (location.filename,
258256
location.lineno,location.note)
257+
echo(err)
259258
tofile.write(err)
260259
finally:
261260
tofile.close()
262261

263262
defshow_doc(self,docs,altview=False):
264263
ifdocs:
265264
cmd='call pymode#ShowStr("%s")'%str(docs.replace('"','\\"'))
266-
printcmd
267265
vim.command(cmd)
268266

269267
defpreview_changes(self,diffs):
@@ -294,8 +292,7 @@ def _add_command(self, name, callback, key, prefix, prekey):
294292
key=prekey+key.replace(' ','')
295293
vim.command('noremap %s :call %s()<cr>'% (key,_vim_name(name)))
296294

297-
@staticmethod
298-
def_add_function(name,callback,prefix=False):
295+
def_add_function(self,name,callback,prefix=False):
299296
globals()[name]=callback
300297
arg='None'ifprefixelse''
301298
vim.command('function! %s()\n'%_vim_name(name)+
@@ -306,7 +303,6 @@ def _completion_data(self, proposal):
306303
returnproposal
307304

308305
_docstring_re=re.compile('^[\s\t\n]*([^\n]*)')
309-
310306
def_extended_completion(self,proposal):
311307
# we are using extended complete and return dicts instead of strings.
312308
# `ci` means "completion item". see `:help complete-items`

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp