summaryrefslogtreecommitdiff
path: root/src/main/bindings.c
diff options
context:
space:
mode:
authorAlbert Cervin <albert@acervin.com>2024-09-17 08:47:03 +0200
committerAlbert Cervin <albert@acervin.com>2025-11-01 22:11:14 +0100
commit4459b8b3aa9d73895391785a99dcc87134e80601 (patch)
treea5204f447a0b2b05f63504c7fe958ef9bbf1918a /src/main/bindings.c
parent4689f3f38277bb64981fc960e8e384e2d065d659 (diff)
downloaddged-4459b8b3aa9d73895391785a99dcc87134e80601.tar.gz
dged-4459b8b3aa9d73895391785a99dcc87134e80601.tar.xz
dged-4459b8b3aa9d73895391785a99dcc87134e80601.zip
More lsp support
This makes the LSP support complete for now: - Completion - Diagnostics - Goto implementation/declaration - Rename - Documentation - Find references
Diffstat (limited to 'src/main/bindings.c')
-rw-r--r--src/main/bindings.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/main/bindings.c b/src/main/bindings.c
index 889c32b..db6c924 100644
--- a/src/main/bindings.c
+++ b/src/main/bindings.c
@@ -8,6 +8,11 @@
static struct keymap g_global_keymap, g_ctrlx_map, g_windows_keymap,
g_buffer_default_keymap;
+HOOK_IMPL(buffer_keymaps, buffer_keymaps_cb);
+
+static buffer_keymaps_hook_vec g_buffer_keymaps_hooks;
+uint32_t g_buffer_keymaps_hook_id = 0;
+
struct buffer_keymap {
buffer_keymap_id id;
struct buffer *buffer;
@@ -17,6 +22,8 @@ struct buffer_keymap {
static VEC(struct buffer_keymap) g_buffer_keymaps;
static buffer_keymap_id g_current_keymap_id;
+struct keymap *buffer_default_keymap(void) { return &g_buffer_default_keymap; }
+
void set_default_buffer_bindings(struct keymap *keymap) {
struct binding buffer_bindings[] = {
BINDING(Ctrl, 'B', "backward-char"),
@@ -144,6 +151,8 @@ void init_bindings(void) {
VEC_INIT(&g_buffer_keymaps, 32);
g_current_keymap_id = 0;
+ VEC_INIT(&g_buffer_keymaps_hooks, 16);
+
/* Minibuffer binds.
* This map is actually never removed so forget about the id.
*/
@@ -204,6 +213,14 @@ uint32_t buffer_keymaps(struct buffer *buffer, struct keymap *keymaps[],
}
}
+ // hooks
+ VEC_FOR_EACH(&g_buffer_keymaps_hooks, struct buffer_keymaps_hook * hook) {
+ if (nkeymaps < max_nkeymaps) {
+ nkeymaps += hook->callback(buffer, &keymaps[nkeymaps],
+ max_nkeymaps - nkeymaps, hook->userdata);
+ }
+ }
+
return nkeymaps;
}
@@ -219,3 +236,11 @@ void destroy_bindings(void) {
VEC_DESTROY(&g_buffer_keymaps);
}
+
+uint32_t buffer_add_keymaps_hook(buffer_keymaps_cb callback, void *userdata) {
+ return insert_buffer_keymaps_hook(
+ &g_buffer_keymaps_hooks, &g_buffer_keymaps_hook_id, callback, userdata);
+}
+void buffer_remove_keymaps_hook(uint32_t id, remove_hook_cb callback) {
+ remove_buffer_keymaps_hook(&g_buffer_keymaps_hooks, id, callback);
+}