Hooks sketch

This commit is contained in:
Krzosa Karol
2026-01-08 10:15:02 +01:00
parent 5fecc74193
commit de06ea05cc
2 changed files with 58 additions and 9 deletions

View File

@@ -28,6 +28,12 @@ struct Trigger {
}; };
}; };
struct CachedTrigger {
Trigger *trigger;
String key;
};
Array<CachedTrigger> CachedTriggers;
void Advance(Lexer *lex) { void Advance(Lexer *lex) {
if (lex->at < lex->end) { if (lex->at < lex->end) {
if (lex->at[0] == '\n') { if (lex->at[0] == '\n') {
@@ -168,12 +174,6 @@ Trigger *ParseKey(Allocator allocator, String key, char *debug_name) {
return result; return result;
} }
struct CachedTrigger {
Trigger *trigger;
String key;
};
Array<CachedTrigger> CachedTriggers;
Trigger *ParseKeyCached(String key) { Trigger *ParseKeyCached(String key) {
key = Trim(key); key = Trim(key);
if (key.len == 0) { if (key.len == 0) {

View File

@@ -7,6 +7,12 @@ struct WindowID { Int id; Window *o; };
union Range { struct { Int min; Int max; }; Int e[2]; }; union Range { struct { Int min; Int max; }; Int e[2]; };
struct Caret { union { Range range; Int pos[2]; }; Int ifront;}; struct Caret { union { Range range; Int pos[2]; }; Int ifront;};
struct XY { Int col; Int line; }; struct XY { Int col; Int line; };
typedef void Function();
struct FunctionData {
String name;
Function *function;
};
struct Edit { struct Edit {
Range range; Range range;
@@ -51,10 +57,53 @@ struct Buffer {
}; };
}; };
typedef void Function(); enum HookKind {
struct FunctionData { HookKind_Invalid,
HookKind_AppInit,
HookKind_AppUpdate,
HookKind_AppExit,
HookKind_Binding,
HookKind_BeforeLayoutWindow,
HookKind_HandleLayoutWindow,
HookKind_AfterLayoutWindow,
HookKind_BeforeRenderWindow,
HookKind_HandleRenderWindow,
HookKind_AfterRenderWindow,
HookKind_BeforeBufferSave,
HookKind_HandleBufferSave,
HookKind_AfterBufferSave,
HookKind_BeforeBufferOpen,
HookKind_HandleBufferOpen,
HookKind_AfterBufferOpen,
HookKind_ViewUpdate,
};
// Global hooks, per (window, view, buffer) hooks
struct HookParam {
struct Hook *hook;
Buffer *buffer;
View *view;
Window *window;
};
typedef void HookFunction(HookParam *param);
struct Hook {
HookKind kind;
String name; String name;
Function *function; String doc;
HookFunction *function;
// HookKind_Binding
String binding;
struct Trigger *trigger;
}; };
struct CommandData { struct CommandData {