-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: improve template helpers and state manager (#14)
## 📃 Summary While the template is still a pretty good starting point, improvements have been made on [my main plugin](https://github.com/shortcuts/no-neck-pain.nvim) for better developer experience, we can port them here.
- Loading branch information
Showing
13 changed files
with
271 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
YourPluginName.disable() neovim-plugin-boilerplate.txt /*YourPluginName.disable()* | ||
YourPluginName.enable() neovim-plugin-boilerplate.txt /*YourPluginName.enable()* | ||
YourPluginName.options neovim-plugin-boilerplate.txt /*YourPluginName.options* | ||
YourPluginName.setup() neovim-plugin-boilerplate.txt /*YourPluginName.setup()* | ||
YourPluginName.toggle() neovim-plugin-boilerplate.txt /*YourPluginName.toggle()* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,55 @@ | ||
local S = require("your-plugin-name.state") | ||
local D = require("your-plugin-name.util.debug") | ||
|
||
-- internal methods | ||
local YourPluginName = {} | ||
|
||
-- state | ||
local S = { | ||
-- Boolean determining if the plugin is enabled or not. | ||
enabled = false, | ||
} | ||
|
||
---Toggle the plugin by calling the `enable`/`disable` methods respectively. | ||
-- Toggle the plugin by calling the `enable`/`disable` methods respectively. | ||
-- | ||
--- @param scope string: internal identifier for logging purposes. | ||
---@private | ||
function YourPluginName.toggle() | ||
if S.enabled then | ||
return YourPluginName.disable() | ||
function YourPluginName.toggle(scope) | ||
if S.getEnabled(S) then | ||
return YourPluginName.disable(scope) | ||
end | ||
|
||
return YourPluginName.enable() | ||
return YourPluginName.enable(scope) | ||
end | ||
|
||
---Initializes the plugin. | ||
--- Initializes the plugin, sets event listeners and internal state. | ||
--- | ||
--- @param scope string: internal identifier for logging purposes. | ||
---@private | ||
function YourPluginName.enable() | ||
if S.enabled then | ||
return S | ||
function YourPluginName.enable(scope) | ||
if S.getEnabled(S) then | ||
D.log(scope, "Plugin is already enabled.") | ||
|
||
return | ||
end | ||
|
||
S.enabled = true | ||
-- sets the plugin as `enabled` | ||
S.setEnabled(S) | ||
|
||
return S | ||
-- saves the state globally to `_G.YourPluginName.state` | ||
S.save(S) | ||
end | ||
|
||
---Disables the plugin and reset the internal state. | ||
--- Disables the plugin for the given tab, clear highlight groups and autocmds, closes side buffers and resets the internal state. | ||
--- | ||
--- @param scope string: internal identifier for logging purposes. | ||
---@private | ||
function YourPluginName.disable() | ||
if not S.enabled then | ||
return S | ||
function YourPluginName.disable(scope) | ||
if not S.getEnabled(S) then | ||
D.log(scope, "Plugin is already disabled.") | ||
|
||
return | ||
end | ||
|
||
-- reset the state | ||
S = { | ||
enabled = false, | ||
} | ||
-- resets the state to its initial value | ||
S.init(S) | ||
|
||
return S | ||
-- saves the state globally to `_G.YourPluginName.state` | ||
S.save(S) | ||
end | ||
|
||
return YourPluginName |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
local D = require("your-plugin-name.util.debug") | ||
|
||
local State = { enabled = false } | ||
|
||
---Sets the state to its original value. | ||
--- | ||
---@private | ||
function State:init() | ||
self.enabled = false | ||
end | ||
|
||
---Saves the state in the global _G.YourPluginName.state object. | ||
--- | ||
---@private | ||
function State:save() | ||
D.log("state.save", "saving state globally to _G.YourPluginName.state") | ||
|
||
_G.YourPluginName.state = self | ||
end | ||
|
||
---Whether the YourPluginName is enabled or not. | ||
--- | ||
---@private | ||
function State:setEnabled() | ||
self.enabled = true | ||
end | ||
|
||
---Whether the YourPluginName is enabled or not. | ||
--- | ||
---@return boolean: the `enabled` state value. | ||
---@private | ||
function State:getEnabled() | ||
return self.enabled | ||
end | ||
|
||
return State |
Oops, something went wrong.