-
Notifications
You must be signed in to change notification settings - Fork 123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Use function name for decorators #335
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
*.egg-info/ | ||
__pycache__ | ||
.pytest_cache/ | ||
neovim/ui/screen.c | ||
neovim/ui/screen.so | ||
build/ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,11 +42,16 @@ def dec(f): | |
return dec | ||
|
||
|
||
def command(name, nargs=0, complete=None, range=None, count=None, bang=False, | ||
register=False, sync=False, allow_nested=False, eval=None): | ||
def command(name=None, nargs=0, complete=None, range=None, | ||
count=None, bang=False, register=False, sync=False, | ||
allow_nested=False, eval=None): | ||
"""Tag a function or plugin method as a Nvim command handler.""" | ||
def dec(f): | ||
f._nvim_rpc_method_name = 'command:{}'.format(name) | ||
if not name: | ||
command_name = capitalize_name(f.__name__) | ||
else: | ||
command_name = name | ||
f._nvim_rpc_method_name = 'command:{}'.format(command_name) | ||
f._nvim_rpc_sync = sync | ||
f._nvim_bind = True | ||
f._nvim_prefix_plugin_path = True | ||
|
@@ -80,18 +85,22 @@ def dec(f): | |
|
||
f._nvim_rpc_spec = { | ||
'type': 'command', | ||
'name': name, | ||
'name': command_name, | ||
'sync': rpc_sync, | ||
'opts': opts | ||
} | ||
return f | ||
return dec | ||
|
||
|
||
def autocmd(name, pattern='*', sync=False, allow_nested=False, eval=None): | ||
def autocmd(name=None, pattern='*', sync=False, allow_nested=False, eval=None): | ||
"""Tag a function or plugin method as a Nvim autocommand handler.""" | ||
def dec(f): | ||
f._nvim_rpc_method_name = 'autocmd:{}:{}'.format(name, pattern) | ||
if not name: | ||
autocmd_name = capitalize_name(f.__name__) | ||
else: | ||
autocmd_name = name | ||
f._nvim_rpc_method_name = 'autocmd:{}:{}'.format(autocmd_name, pattern) | ||
f._nvim_rpc_sync = sync | ||
f._nvim_bind = True | ||
f._nvim_prefix_plugin_path = True | ||
|
@@ -110,18 +119,23 @@ def dec(f): | |
|
||
f._nvim_rpc_spec = { | ||
'type': 'autocmd', | ||
'name': name, | ||
'name': autocmd_name, | ||
'sync': rpc_sync, | ||
'opts': opts | ||
} | ||
return f | ||
return dec | ||
|
||
|
||
def function(name, range=False, sync=False, allow_nested=False, eval=None): | ||
def function(name=None, range=False, sync=False, | ||
allow_nested=False, eval=None): | ||
"""Tag a function or plugin method as a Nvim function handler.""" | ||
def dec(f): | ||
f._nvim_rpc_method_name = 'function:{}'.format(name) | ||
if not name: | ||
function_name = capitalize_name(f.__name__) | ||
else: | ||
function_name = name | ||
f._nvim_rpc_method_name = 'function:{}'.format(function_name) | ||
f._nvim_rpc_sync = sync | ||
f._nvim_bind = True | ||
f._nvim_prefix_plugin_path = True | ||
|
@@ -141,14 +155,23 @@ def dec(f): | |
|
||
f._nvim_rpc_spec = { | ||
'type': 'function', | ||
'name': name, | ||
'name': function_name, | ||
'sync': rpc_sync, | ||
'opts': opts | ||
} | ||
return f | ||
return dec | ||
|
||
|
||
def capitalize_name(name): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do not like this kind of magic. For plugins that use this, it would be better to break python conventions and name the implementation function literally what the vimL side name is. Also, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, a matter of style I think. I would no like to have a function/command named There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Referential transparency is more important than style. If an rplugin defines |
||
words = [ | ||
word[0].upper() + word[1:] | ||
for word in name.split('_') | ||
if word | ||
] | ||
return ''.join(words) | ||
|
||
|
||
def shutdown_hook(f): | ||
"""Tag a function or method as a shutdown hook.""" | ||
f._nvim_shutdown_hook = True | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ deps= | |
pytest | ||
pytest-xdist | ||
pyuv: pyuv | ||
commands=python -m pytest -s | ||
commands=python -m pytest -s {posargs} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm adding this so I can do |
||
|
||
[testenv:checkqa] | ||
deps = | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can be a concern that a plugin potentially can have multiple implementations of the autocmd with disjoint patterns. At least there should be a warning in the docs. (python doesn't give a warning on method shadowing, though we could hack it with a metaclass).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't sure about the autocmd, it doesn't have much sense here I guess.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe the parameter should be named
event
, that's why I was confused here.