2012-04-03 14:01:01 +02:00
|
|
|
#ifndef hook_manager_hh_INCLUDED
|
|
|
|
#define hook_manager_hh_INCLUDED
|
2011-11-25 15:26:29 +01:00
|
|
|
|
2017-03-07 02:12:37 +01:00
|
|
|
#include "hash_map.hh"
|
2014-12-23 14:54:09 +01:00
|
|
|
#include "completion.hh"
|
2016-05-15 11:37:42 +02:00
|
|
|
#include "safe_ptr.hh"
|
2018-10-22 23:15:53 +02:00
|
|
|
#include "meta.hh"
|
|
|
|
#include "enum.hh"
|
2011-11-25 15:26:29 +01:00
|
|
|
|
2019-01-24 11:02:07 +01:00
|
|
|
#include <memory>
|
|
|
|
|
2011-11-25 15:26:29 +01:00
|
|
|
namespace Kakoune
|
|
|
|
{
|
|
|
|
|
2013-11-11 20:10:49 +01:00
|
|
|
class Context;
|
2017-10-02 08:20:36 +02:00
|
|
|
class Regex;
|
2011-11-25 15:26:29 +01:00
|
|
|
|
2018-10-22 23:15:53 +02:00
|
|
|
enum class Hook
|
|
|
|
{
|
|
|
|
BufCreate,
|
|
|
|
BufNewFile,
|
|
|
|
BufOpenFile,
|
|
|
|
BufClose,
|
|
|
|
BufWritePost,
|
|
|
|
BufReload,
|
|
|
|
BufWritePre,
|
|
|
|
BufOpenFifo,
|
|
|
|
BufCloseFifo,
|
|
|
|
BufReadFifo,
|
|
|
|
BufSetOption,
|
2019-04-08 13:58:12 +02:00
|
|
|
ClientCreate,
|
|
|
|
ClientClose,
|
2018-10-22 23:15:53 +02:00
|
|
|
InsertChar,
|
|
|
|
InsertDelete,
|
|
|
|
InsertIdle,
|
|
|
|
InsertKey,
|
|
|
|
InsertMove,
|
|
|
|
InsertCompletionHide,
|
|
|
|
InsertCompletionShow,
|
|
|
|
KakBegin,
|
|
|
|
KakEnd,
|
|
|
|
FocusIn,
|
|
|
|
FocusOut,
|
|
|
|
GlobalSetOption,
|
|
|
|
RuntimeError,
|
|
|
|
PromptIdle,
|
|
|
|
NormalIdle,
|
2020-02-27 16:36:15 +01:00
|
|
|
NextKeyIdle,
|
2018-10-22 23:15:53 +02:00
|
|
|
NormalKey,
|
|
|
|
ModeChange,
|
|
|
|
RawKey,
|
2020-07-19 04:56:55 +02:00
|
|
|
RegisterModified,
|
2018-10-22 23:15:53 +02:00
|
|
|
WinClose,
|
|
|
|
WinCreate,
|
|
|
|
WinDisplay,
|
|
|
|
WinResize,
|
2019-03-13 20:46:53 +01:00
|
|
|
WinSetOption,
|
2020-07-04 05:48:10 +02:00
|
|
|
ModuleLoaded,
|
|
|
|
User
|
2018-10-22 23:15:53 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
constexpr auto enum_desc(Meta::Type<Hook>)
|
|
|
|
{
|
2019-10-17 13:48:22 +02:00
|
|
|
return make_array<EnumDesc<Hook>>({
|
2018-10-22 23:15:53 +02:00
|
|
|
{Hook::BufCreate, "BufCreate"},
|
|
|
|
{Hook::BufNewFile, "BufNewFile"},
|
|
|
|
{Hook::BufOpenFile, "BufOpenFile"},
|
|
|
|
{Hook::BufClose, "BufClose"},
|
|
|
|
{Hook::BufWritePost, "BufWritePost"},
|
|
|
|
{Hook::BufReload, "BufReload"},
|
|
|
|
{Hook::BufWritePre, "BufWritePre"},
|
|
|
|
{Hook::BufOpenFifo, "BufOpenFifo"},
|
|
|
|
{Hook::BufCloseFifo, "BufCloseFifo"},
|
|
|
|
{Hook::BufReadFifo, "BufReadFifo"},
|
|
|
|
{Hook::BufSetOption, "BufSetOption"},
|
2019-04-08 13:58:12 +02:00
|
|
|
{Hook::ClientCreate, "ClientCreate"},
|
|
|
|
{Hook::ClientClose, "ClientClose"},
|
2018-10-22 23:15:53 +02:00
|
|
|
{Hook::InsertChar, "InsertChar"},
|
|
|
|
{Hook::InsertDelete, "InsertDelete"},
|
|
|
|
{Hook::InsertIdle, "InsertIdle"},
|
|
|
|
{Hook::InsertKey, "InsertKey"},
|
|
|
|
{Hook::InsertMove, "InsertMove"},
|
|
|
|
{Hook::InsertCompletionHide, "InsertCompletionHide"},
|
|
|
|
{Hook::InsertCompletionShow, "InsertCompletionShow"},
|
|
|
|
{Hook::KakBegin, "KakBegin"},
|
|
|
|
{Hook::KakEnd, "KakEnd"},
|
|
|
|
{Hook::FocusIn, "FocusIn"},
|
|
|
|
{Hook::FocusOut, "FocusOut"},
|
|
|
|
{Hook::GlobalSetOption, "GlobalSetOption"},
|
|
|
|
{Hook::RuntimeError, "RuntimeError"},
|
|
|
|
{Hook::PromptIdle, "PromptIdle"},
|
|
|
|
{Hook::NormalIdle, "NormalIdle"},
|
2020-02-27 16:36:15 +01:00
|
|
|
{Hook::NextKeyIdle, "NextKeyIdle"},
|
2018-10-22 23:15:53 +02:00
|
|
|
{Hook::NormalKey, "NormalKey"},
|
|
|
|
{Hook::ModeChange, "ModeChange"},
|
|
|
|
{Hook::RawKey, "RawKey"},
|
2020-07-19 04:56:55 +02:00
|
|
|
{Hook::RegisterModified, "RegisterModified"},
|
2018-10-22 23:15:53 +02:00
|
|
|
{Hook::WinClose, "WinClose"},
|
|
|
|
{Hook::WinCreate, "WinCreate"},
|
|
|
|
{Hook::WinDisplay, "WinDisplay"},
|
|
|
|
{Hook::WinResize, "WinResize"},
|
|
|
|
{Hook::WinSetOption, "WinSetOption"},
|
2020-07-04 05:48:10 +02:00
|
|
|
{Hook::ModuleLoaded, "ModuleLoaded"},
|
|
|
|
{Hook::User, "User"}
|
2018-10-22 23:15:53 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-04-17 00:27:09 +02:00
|
|
|
enum class HookFlags
|
|
|
|
{
|
|
|
|
None = 0,
|
2018-08-02 11:52:48 +02:00
|
|
|
Always = 1 << 0,
|
|
|
|
Once = 1 << 1
|
2018-04-17 00:27:09 +02:00
|
|
|
};
|
|
|
|
constexpr bool with_bit_ops(Meta::Type<HookFlags>) { return true; }
|
|
|
|
|
2016-05-15 11:37:42 +02:00
|
|
|
class HookManager : public SafeCountable
|
2011-11-25 15:26:29 +01:00
|
|
|
{
|
|
|
|
public:
|
2017-10-02 08:20:36 +02:00
|
|
|
HookManager(HookManager& parent);
|
|
|
|
~HookManager();
|
2012-06-07 15:29:44 +02:00
|
|
|
|
2018-10-22 23:15:53 +02:00
|
|
|
void add_hook(Hook hook, String group, HookFlags flags,
|
2018-04-17 00:27:09 +02:00
|
|
|
Regex filter, String commands);
|
2018-09-12 13:24:38 +02:00
|
|
|
void remove_hooks(const Regex& regex);
|
2014-07-21 22:14:32 +02:00
|
|
|
CandidateList complete_hook_group(StringView prefix, ByteCount pos_in_token);
|
2018-10-22 23:15:53 +02:00
|
|
|
void run_hook(Hook hook, StringView param, Context& context);
|
2011-11-25 15:26:29 +01:00
|
|
|
|
|
|
|
private:
|
2017-10-02 08:20:36 +02:00
|
|
|
HookManager();
|
2012-06-07 15:29:44 +02:00
|
|
|
// the only one allowed to construct a root hook manager
|
2014-10-30 15:00:42 +01:00
|
|
|
friend class Scope;
|
2012-06-07 15:29:44 +02:00
|
|
|
|
2018-10-22 23:15:53 +02:00
|
|
|
struct HookData;
|
2017-06-07 10:34:07 +02:00
|
|
|
|
2016-05-15 11:37:42 +02:00
|
|
|
SafePtr<HookManager> m_parent;
|
2018-10-22 23:15:53 +02:00
|
|
|
Array<Vector<std::unique_ptr<HookData>, MemoryDomain::Hooks>, enum_desc(Meta::Type<Hook>{}).size()> m_hooks;
|
2017-06-07 13:15:16 +02:00
|
|
|
|
2018-10-22 23:15:53 +02:00
|
|
|
mutable Vector<std::pair<Hook, StringView>, MemoryDomain::Hooks> m_running_hooks;
|
|
|
|
mutable Vector<std::unique_ptr<HookData>, MemoryDomain::Hooks> m_hooks_trash;
|
2011-11-25 15:26:29 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-04-03 14:01:01 +02:00
|
|
|
#endif // hook_manager_hh_INCLUDED
|