Skip to content

Commit 0271137

Browse files
committed
Update ropevim
1 parent 14aa358 commit 0271137

1 file changed

Lines changed: 34 additions & 38 deletions

File tree

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
def ask_values(self, prompt, values, default=None,
3131
starting=None, show_values=None):
32-
3332
if show_values or (show_values is None and len(values) < 14):
3433
self._print_values(values)
35-
3634
if default is not None:
3735
prompt = prompt + ('[%s] ' % default)
38-
3936
starting = starting or ''
4037
_completer.values = values
4138
answer = call('input("%s", "%s", "customlist,RopeValueCompleter")' %
4239
(prompt, starting))
4340
if answer is None:
44-
return 'cancel' if 'cancel' in values else None
45-
41+
if 'cancel' in values:
42+
return 'cancel'
43+
return
4644
if default is not None and not answer:
4745
return default
48-
4946
if answer.isdigit() and 0 <= int(answer) < len(values):
5047
return values[int(answer)]
51-
5248
return answer
5349

50+
def _print_values(self, values):
51+
numbered = []
52+
for index, value in enumerate(values):
53+
numbered.append('%s. %s' % (index, str(value)))
54+
echo('\n'.join(numbered) + '\n')
55+
5456
def ask_directory(self, prompt, default=None, starting=None):
5557
return call('input("%s", ".", "dir")' % prompt)
5658

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

89-
@staticmethod
90-
def _print_values(values):
91-
numbered = []
92-
for index, value in enumerate(values):
93-
numbered.append('%s. %s' % (index, str(value)))
94-
echo('\n'.join(numbered) + '\n')
95-
9691
def yes_or_no(self, prompt):
9792
return self.ask_values(prompt, ['yes', 'no']) == 'yes'
9893

9994
def y_or_n(self, prompt):
10095
return self.yes_or_no(prompt)
10196

102-
def get(self, name):
97+
def get(self, name, default=None):
10398
vimname = 'g:pymode_rope_%s' % name
99+
if str(vim.eval('exists("%s")' % vimname)) == '0':
100+
return default
104101
result = vim.eval(vimname)
105102
if isinstance(result, str) and result.isdigit():
106103
return int(result)
@@ -121,20 +118,24 @@ def _decode_line(self, line):
121118
return line.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-
for line in vim.current.buffer[:lineno - 1]:
121+
result = min(colno, len(self.buffer[lineno -1]) + 1)
122+
for line in self.buffer[:lineno-1]:
126123
line = self._decode_line(line)
127124
result += len(line) + 1
128125
return result
129126

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

133130
def get_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
return start, end
137134

135+
@property
136+
def buffer(self):
137+
return vim.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
return vim.eval('getcwd()')
156157

157158
def filename(self):
158-
return vim.current.buffer.name
159+
return self.buffer.name
159160

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

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

169170
def insert(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
def delete(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
if lineno1 == 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
if lineno == lineno1 and colno >= 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
def filenames(self):
196197
result = []
197-
for b in vim.buffers:
198-
if b.name:
199-
result.append(b.name)
198+
for buffer in vim.buffers:
199+
if buffer.name:
200+
result.append(buffer.name)
200201
return result
201202

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

205-
def reload_files(self, filenames, moves=None):
206-
if moves is None:
207-
moves = dict()
206+
def reload_files(self, filenames, moves={}):
208207
initial = self.filename()
209208
for filename in filenames:
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
for location in locations:
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
def show_doc(self, docs, altview=False):
264263
if docs:
265264
cmd = 'call pymode#ShowStr("%s")' % str(docs.replace('"', '\\"'))
266-
print cmd
267265
vim.command(cmd)
268266

269267
def preview_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' if prefix else ''
301298
vim.command('function! %s()\n' % _vim_name(name) +
@@ -306,7 +303,6 @@ def _completion_data(self, proposal):
306303
return proposal
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)