2024-11-18 09:53:55 +00:00
|
|
|
#include "hook.h"
|
|
|
|
|
|
|
|
|
|
#include "line-ed.h"
|
|
|
|
|
|
|
|
|
|
void line_ed_add_hook(struct line_ed *ed, struct line_ed_hook *hook)
|
|
|
|
|
{
|
|
|
|
|
b_queue_push_back(&ed->l_hooks, &hook->hook_entry);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void line_ed_remove_hook(struct line_ed *ed, struct line_ed_hook *hook)
|
|
|
|
|
{
|
|
|
|
|
b_queue_delete(&ed->l_hooks, &hook->hook_entry);
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-20 22:14:35 +00:00
|
|
|
void hook_keypress(struct line_ed *ed, b_keycode key)
|
2024-11-18 09:53:55 +00:00
|
|
|
{
|
2025-11-06 10:39:08 +00:00
|
|
|
b_queue_entry *entry = b_queue_first(&ed->l_hooks);
|
|
|
|
|
while (entry) {
|
2024-11-18 09:53:55 +00:00
|
|
|
struct line_ed_hook *hook
|
2025-11-06 10:39:08 +00:00
|
|
|
= b_unbox(struct line_ed_hook, entry, hook_entry);
|
2024-11-18 09:53:55 +00:00
|
|
|
if (hook->hook_keypress) {
|
|
|
|
|
hook->hook_keypress(ed, hook, key);
|
|
|
|
|
}
|
2025-11-06 10:39:08 +00:00
|
|
|
|
|
|
|
|
entry = b_queue_next(entry);
|
2024-11-18 09:53:55 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void hook_buffer_modified(struct line_ed *ed)
|
|
|
|
|
{
|
2025-11-06 10:39:08 +00:00
|
|
|
b_queue_entry *entry = b_queue_first(&ed->l_hooks);
|
|
|
|
|
while (entry) {
|
2024-11-18 09:53:55 +00:00
|
|
|
struct line_ed_hook *hook
|
2025-11-06 10:39:08 +00:00
|
|
|
= b_unbox(struct line_ed_hook, entry, hook_entry);
|
2024-11-18 09:53:55 +00:00
|
|
|
if (hook->hook_buffer_modified) {
|
|
|
|
|
hook->hook_buffer_modified(ed, hook);
|
|
|
|
|
}
|
2025-11-06 10:39:08 +00:00
|
|
|
|
|
|
|
|
entry = b_queue_next(entry);
|
2024-11-18 09:53:55 +00:00
|
|
|
}
|
|
|
|
|
}
|