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

[FEATURE] Register hook mechanism #246

Open
AbaoFromCUG opened this issue Aug 2, 2023 · 1 comment
Open

[FEATURE] Register hook mechanism #246

AbaoFromCUG opened this issue Aug 2, 2023 · 1 comment
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@AbaoFromCUG
Copy link
Contributor

Is your feature request related to a problem? Please describe.
I deep use auto-session for a long time, this is an convenient plugin in moust time, a little touble is about command hook usage, we have write all hook function in setup() config

require('auto-session').setup {
   {hook_name}_cmds = {"{hook_command1}", "{hook_command2}"}
   save_extra_cmds = {
       function()
           return [[echo "hello world"]]
       end
   }
}
EOF

which couple other plugin with auto-session.setup(), which may be affected by the order of plugin setup()

Describe the solution you'd like
Can we provide a register hook mechanism, e.g.

require("auto-session").register_pre_save_hook("my_hook_identifier", function()
      -- do something
end)

Other plugin/config can register hook anywhere, with it identifier, plugin/config can update the hook function if they what

Of couse, the name of api just example, we should have a contract in api design, which is controllerd by auto-session's maintainer

Additional context
Some extend ability via register function examples:

I will be pleasure to implement the feature with API contract

@AbaoFromCUG AbaoFromCUG added the enhancement New feature or request label Aug 2, 2023
@rmagatti rmagatti added this to the v2.1.0 milestone Nov 21, 2023
@rmagatti
Copy link
Owner

Good feature request! I believe the API should look something like:

require("auto-session").register_hook_action(<hook_name>, <string | function>)

This should add the action to a list of actions. That list should be initialized on setup and appended to when calling this register function.
The hook when fired should then loop over all the actions calling them one by one as it does today.

Note: hook_name is as per defined in the readme currently.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants