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

Code examples for best practice #3

Closed
matu3ba opened this issue Aug 15, 2021 · 1 comment
Closed

Code examples for best practice #3

matu3ba opened this issue Aug 15, 2021 · 1 comment

Comments

@matu3ba
Copy link

matu3ba commented Aug 15, 2021

Always check existence of dependencies (except for transitive dependencies) of upstream project you depend on:

local has_telescope, telescope = pcall(require, 'telescope')
if not has_telescope then
  error('This plugins requires nvim-telescope/telescope.nvim')
end

If possible, provide a setup function for the user in your $GIT_ROOT/lua/yourpluginname.lua:

-- your imports
...
local M = {}
function M.setup()
-- plugin setup code
...
end
...
return M
-- The user can then use it (for example with packer)
use { 'yourname/yourpluginname.nvim', config = function() require('yourpluginname').setup() end }
-- or alternatively somewhere in the lua or vim config
require('yourpluginname').setup()

Using M for all members of a file (variables and functions) is best practice.

@mfussenegger
Copy link
Collaborator

See #2 (comment)

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