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

Document best practice on functions, naming and where (not) to use local #2

Closed
matu3ba opened this issue Aug 15, 2021 · 2 comments
Closed

Comments

@matu3ba
Copy link

matu3ba commented Aug 15, 2021

Nice idea to collect the stuff here @mfussenegger.

Copied from plans for an advanced nvim-lua-guide, since it fits better here:

  1. Always use local on functions and variables except in yourpluginname.lua or if the plugin template/upstream project you depend on instructs you to make functions available to the user.
  2. What should be used? local function a = bla() xor local a = function() xor function M.bla() ? Consistency please
  3. Do not use underscope-prefix functions They are reserved by neovim for internal functionality.
  4. If possible, provide initialisation functions inside your yourpluginname.lua to enable lazy-loading. This also prevents the lua-aware startup profiler to break: A Lua-aware startup time profiler wishlist#15 (comment)
@matu3ba
Copy link
Author

matu3ba commented Aug 15, 2021

kinda related are the code examples in #3, but I wanted to keep the reasoning separate.

@mfussenegger
Copy link
Collaborator

mfussenegger commented Aug 17, 2021

I think the "Things you should avoid" section may have been a mistake and bloated up the scope of this repository too much.

This isn't intended to become a "Lua plugin author guideline" or even authority in terms of what must be done and what not - but was merely intended as a starter template to make the setup a little easier and avoid having to deal with boilerplate.

I've pushed a change to the README to clarify that.

There's enough content already on how to write good Lua code. We don't need to replicate existing work, especially not in this repository.

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

No branches or pull requests

2 participants