-
Notifications
You must be signed in to change notification settings - Fork 0
State Tracking
Typewriter.nvim now includes robust state tracking functionality, allowing users and other plugins to easily check and manipulate the Typewriter mode's state. This feature enhances the plugin's flexibility and integration capabilities.
This function allows you to check whether Typewriter mode is currently active.
Usage:
local utils = require("typewriter.utils")
if utils.is_typewriter_active() then
print("Typewriter mode is active")
else
print("Typewriter mode is inactive")
end
Use this function to explicitly set the state of Typewriter mode.
Usage:
local utils = require("typewriter.utils")
utils.set_typewriter_active(true) -- Enables Typewriter mode
utils.set_typewriter_active(false) -- Disables Typewriter mode
This function toggles the state of Typewriter mode and returns the new state.
Usage:
local utils = require("typewriter.utils")
local new_state = utils.toggle_typewriter_active()
print("Typewriter mode is now: " .. (new_state and "active" or "inactive"))
Whenever the state of Typewriter mode changes (either through the API or via user commands), a TypewriterStateChanged
event is triggered. You can use this event to perform actions in response to state changes.
Example: Updating statusline when Typewriter mode changes
vim.api.nvim_create_autocmd("User", {
pattern = "TypewriterStateChanged",
callback = function()
-- Update your statusline here
require('lualine').refresh()
end
})
You can use the state tracking to display the current state of Typewriter mode in your statusline:
require('lualine').setup {
sections = {
lualine_x = {
{
function()
return require("typewriter.utils").is_typewriter_active() and "TW" or ""
end,
color = { fg = "#ff9e64" }
}
}
}
}
You can create custom keybindings that react to the current state:
vim.api.nvim_set_keymap('n', '<leader>tw', function()
if require("typewriter.utils").is_typewriter_active() then
-- Do something when Typewriter is active
else
-- Do something else when it's inactive
end
end, { noremap = true, silent = true })
- Always use the provided API functions to check or change the state, rather than trying to access or modify the state directly.
- If you're creating a plugin that interacts with Typewriter.nvim, consider using the
TypewriterStateChanged
event to react to state changes, rather than polling the state continuously. - When toggling the state programmatically, use
toggle_typewriter_active()
rather than checking the state and then setting it manually, as this ensures that all necessary side effects (like triggering the state changed event) occur.
By leveraging these state tracking features, you can create more dynamic and responsive integrations with Typewriter.nvim, enhancing your Neovim editing experience.
Thank you for exploring the Typewriter.nvim documentation. We hope you find this plugin enhances your writing and coding experience in Neovim. If you have any questions, suggestions, or contributions, please feel free to reach out or submit an issue on our GitHub repository.
Stay Connected:
Crafted with care by Josh Peterson.