Skip to content

feat: expose status getter#78

Open
Kaes3kuch3n wants to merge 1 commit intookuuva:mainfrom
Kaes3kuch3n:main
Open

feat: expose status getter#78
Kaes3kuch3n wants to merge 1 commit intookuuva:mainfrom
Kaes3kuch3n:main

Conversation

@Kaes3kuch3n
Copy link

When integrating auto-save functionality via this plugin's API, the only way to keep track of whether auto saving is enabled is by creating event listeners for the enable and disable event and tracking the state in an external field. To make state tracking a little easier, I've added an enabled() function for fetching the current state directly via the plugin's API.

Examle use case

Integration with snacks.toggle:

local autosave = require("auto-save")

require("snacks.toggle").new({
    name = "Auto Save",
    get = function()
       return autosave.enabled()
    end,
    set = function(state)
        if state then
            autosave.on()
        else
            autosave.off()
        end
    end,
}):map("<leader>uv")

@okuuva
Copy link
Owner

okuuva commented Mar 18, 2026

LGTM, thank you for the contribution! I think it would be good to include the snacks toggle example in the README. Can you add that as well?

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.

2 participants