Skip to content

Commit 40c2c13

Browse files
committed
Working on pymode.
1 parent 7235933 commit 40c2c13

File tree

7 files changed

+82
-5
lines changed

7 files changed

+82
-5
lines changed

autoload/pymode/lint.vim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ fun! pymode#lint#check() "{{{
5656
let errors = getqflist()
5757
if empty(errors)
5858
call pymode#wide_message('Code checking is completed. No errors found.')
59+
return
5960
endif
6061

6162
if g:pymode_lint_cwindow

autoload/pymode/rope.vim

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,13 @@ fun! pymode#rope#move() "{{{
139139
PymodePython rope.MoveRefactoring().run()
140140
endfunction "}}}
141141

142+
fun! pymode#rope#signature() "{{{
143+
if !pymode#save()
144+
return 0
145+
endif
146+
PymodePython rope.ChangeSignatureRefactoring().run()
147+
endfunction "}}}
148+
142149
fun! pymode#rope#use_function() "{{{
143150
if !pymode#save()
144151
return 0

doc/pymode.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ Load modules to autoimport by default *'g:pymode_rope_autoimport_modules'*
397397
398398
Offer to unresolved import object after completion.
399399
>
400-
let g:pymode_rope_autoimport_import_after_complete = 1
400+
let g:pymode_rope_autoimport_import_after_complete = 0
401401
402402
403403
------------------------------------------------------------------------------
@@ -441,7 +441,8 @@ Keymap for rename current module *'g:pymode_rope_rename_module_bind'*
441441
442442
Imports ~
443443

444-
Organize imports in current file (drop unused imports, sort imports)
444+
Organize imports sorts imports, too. It does that according to PEP8. Unused
445+
imports will be dropped.
445446
Keymap *'g:pymode_rope_organize_imports_bind'*
446447
>
447448
let g:pymode_rope_organize_imports_bind = '<C-c>ro'
@@ -494,6 +495,10 @@ afterwards.
494495
>
495496
let g:pymode_rope_move_bind = '<C-c>rv'
496497
498+
Change function signature ~
499+
>
500+
let g:pymode_rope_change_signature_bind = '<C-c>rs'
501+
497502
498503
------------------------------------------------------------------------------
499504
4.4 Undo/Redo changes ~

ftplugin/python/pymode.vim

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,10 @@ if g:pymode_rope
137137
exe "noremap <silent> <buffer> " . g:pymode_rope_move_bind . " :call pymode#rope#move()<CR>"
138138
end
139139

140+
if g:pymode_rope_change_signature_bind != ""
141+
exe "noremap <silent> <buffer> " . g:pymode_rope_change_signature_bind . " :call pymode#rope#signature()<CR>"
142+
end
143+
140144
if g:pymode_rope_use_function_bind != ""
141145
exe "noremap <silent> <buffer> " . g:pymode_rope_use_function_bind . " :call pymode#rope#use_function()<CR>"
142146
end

plugin/pymode.vim

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,8 @@ call pymode#default('g:pymode_rope_completion', 1)
151151
" Enable autoimport used modules
152152
call pymode#default('g:pymode_rope_autoimport', 1)
153153

154-
" Import object after complete (if that not be imported before)
155-
call pymode#default('g:pymode_rope_autoimport_import_after_complete', 1)
154+
" Offer to import object after complete (if that not be imported before)
155+
call pymode#default('g:pymode_rope_autoimport_import_after_complete', 0)
156156

157157
" Autoimported modules
158158
call pymode#default('g:pymode_rope_autoimport_modules', ['os', 'shutil', 'datetime'])
@@ -202,6 +202,9 @@ call pymode#default('g:pymode_rope_inline_bind', '<C-c>ri')
202202
" Move refactoring
203203
call pymode#default('g:pymode_rope_move_bind', '<C-c>rv')
204204

205+
" Change signature
206+
call pymode#default('g:pymode_rope_change_signature_bind', '<C-c>rs')
207+
205208
" Tries to find the places in which a function can be used and changes the
206209
" code to call it instead
207210
call pymode#default('g:pymode_rope_use_function_bind', '<C-c>ru')

pymode/lint.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
""" Pylama integration. """
22

33
import vim # noqa
4+
from .utils import pymode_message
5+
46
import os.path
57

68

@@ -24,5 +26,10 @@ def code_check():
2426
if root:
2527
path = os.path.relpath(path, root)
2628

29+
if options.skip and any(p.match(path) for p in options.skip):
30+
pymode_message('Skip code checking.')
31+
vim.command('return')
32+
return False
33+
2734
errors = check_path(path, options=options)
2835
vim.command('call setqflist(%s)' % json.dumps(errors))

pymode/rope.py

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from rope.base import project, libutils, exceptions, change, worder # noqa
2222
from rope.base.fscommands import FileSystemCommands # noqa
2323
from rope.contrib import autoimport as rope_autoimport, codeassist, findit # noqa
24-
from rope.refactor import ModuleToPackage, ImportOrganizer, rename, extract, inline, usefunction, move # noqa
24+
from rope.refactor import ModuleToPackage, ImportOrganizer, rename, extract, inline, usefunction, move, change_signature # noqa
2525
from rope.base.taskhandle import TaskHandle # noqa
2626

2727

@@ -706,6 +706,56 @@ def get_refactor(ctx):
706706
return move.create_move(ctx.project, ctx.resource, offset)
707707

708708

709+
class ChangeSignatureRefactoring(Refactoring):
710+
711+
""" Change function signature (add/remove/sort arguments). """
712+
713+
@staticmethod
714+
def get_input_str(refactor, ctx):
715+
""" Get destination.
716+
717+
:return str:
718+
719+
"""
720+
args = refactor.get_args()
721+
default = ', '.join(a[0] for a in args)
722+
return pymode_input('Change the signature:', udefault=default)
723+
724+
@staticmethod
725+
def get_refactor(ctx):
726+
""" Function description.
727+
728+
:return Rename:
729+
730+
"""
731+
_, offset = get_assist_params()
732+
return change_signature.ChangeSignature(
733+
ctx.project, ctx.resource, offset)
734+
735+
def get_changes(self, refactor, input_string):
736+
""" Function description. """
737+
738+
args = re.sub(r'[\s\(\)]+', '', input_string).split(',')
739+
olds = [arg[0] for arg in refactor.get_args()]
740+
741+
changers = []
742+
for arg in [a for a in olds if not a in args]:
743+
changers.append(change_signature.ArgumentRemover(olds.index(arg)))
744+
olds.remove(arg)
745+
746+
order = []
747+
for index, arg in enumerate(args):
748+
if arg not in olds:
749+
changers.append(change_signature.ArgumentAdder(index, arg))
750+
olds.insert(index, arg)
751+
order.append(olds.index(arg))
752+
753+
changers.append(change_signature.ArgumentReorderer(
754+
order, autodef='None'))
755+
756+
return refactor.get_changes(changers)
757+
758+
709759
def reload_changes(changes):
710760
""" Reload changed buffers. """
711761

0 commit comments

Comments
 (0)