summaryrefslogtreecommitdiff
path: root/src/hook_manager.hh
blob: 93a67ef7113782b8c3b899d47fc23e8089cdee68 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#ifndef hook_manager_hh_INCLUDED
#define hook_manager_hh_INCLUDED

#include "id_map.hh"

#include <unordered_map>

namespace Kakoune
{

class Context;
using HookFunc = std::function<void (StringView, Context&)>;

class HookManager
{
public:
    HookManager(HookManager& parent) : m_parent(&parent) {}

    void add_hook(const String& hook_name, String group, HookFunc hook);
    void remove_hooks(StringView group);
    CandidateList complete_hook_group(StringView prefix, ByteCount pos_in_token);
    void run_hook(const String& hook_name, StringView param,
                  Context& context) const;

private:
    HookManager()
        : m_parent(nullptr) {}
    // the only one allowed to construct a root hook manager
    friend class Scope;

    HookManager* m_parent;
    std::unordered_map<String, id_map<HookFunc>> m_hook;
};

}

#endif // hook_manager_hh_INCLUDED