Skip to content
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

Closed
wants to merge 4 commits into from
Closed

[WIP] Use function name for decorators #335

wants to merge 4 commits into from

Conversation

stsewd
Copy link
Contributor

@stsewd stsewd commented Apr 28, 2018

Sometimes is kind of redundant to write the function/command/autocmd name on each decorator. Also, this can help with cases like #334.

Please, let me know if you want this feature so, I can continue :), thanks

What is missing?

  • Update docs

@@ -8,7 +8,7 @@ deps=
pytest
pytest-xdist
pyuv: pyuv
commands=python -m pytest -s
commands=python -m pytest -s {posargs}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm adding this so I can do tox -e py36 test/test_decorators.py

'sync': rpc_sync,
'opts': opts
}
return f
return dec


def capitalize_name(name):
Copy link
Member

Choose a reason for hiding this comment

The 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, _ is not forbidden in vimL.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 My_function_something, and you can still pass a name if people want that name.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Referential transparency is more important than style. If an rplugin defines MySpecialCommand to users, I would expect to find that name literally in the source, much more often than not.

'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):
Copy link
Member

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).

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

@justinmk
Copy link
Member

justinmk commented Apr 7, 2024

neovim/neovim#27949 will greatly simplify the implementation and interface of remote plugins, and will remove the need for decorators (which are just sugar to do things that can/should be done in the plain Lua part of a remote plugin).

@justinmk justinmk closed this Apr 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants