summaryrefslogtreecommitdiff
path: root/src/main/completion.h
diff options
context:
space:
mode:
authorAlbert Cervin <albert@acervin.com>2023-11-26 23:08:06 +0100
committerAlbert Cervin <albert@acervin.com>2024-01-15 10:39:56 +0100
commit64d6816a36567274551dd4f067fe4d05b1445cc0 (patch)
tree50f8dc895d363ab391d30226f665870d8ce263b5 /src/main/completion.h
parentc87888f10dfb54590c5aae8311b7aff887193d9a (diff)
downloaddged-64d6816a36567274551dd4f067fe4d05b1445cc0.tar.gz
dged-64d6816a36567274551dd4f067fe4d05b1445cc0.tar.xz
dged-64d6816a36567274551dd4f067fe4d05b1445cc0.zip
Completion rework
- Add support for building with clang Also fix some annoying bugs: - Visual column was wrong when using tabs - Add shift-tab for inserting an actual tab - Fix minibuffer sometimes having dot above it
Diffstat (limited to 'src/main/completion.h')
-rw-r--r--src/main/completion.h83
1 files changed, 83 insertions, 0 deletions
diff --git a/src/main/completion.h b/src/main/completion.h
new file mode 100644
index 0000000..751d152
--- /dev/null
+++ b/src/main/completion.h
@@ -0,0 +1,83 @@
+#ifndef _COMPLETION_H
+#define _COMPLETION_H
+
+#include "dged/location.h"
+
+struct buffer;
+struct buffers;
+
+struct completion {
+ const char *display;
+ const char *insert;
+ bool complete;
+};
+
+struct completion_context {
+ struct buffer *buffer;
+ const struct location location;
+ const uint32_t max_ncompletions;
+ struct completion *completions;
+};
+
+typedef uint32_t (*completion_fn)(struct completion_context ctx,
+ void *userdata);
+
+struct completion_provider {
+ char name[16];
+ completion_fn complete;
+ void *userdata;
+};
+
+enum completion_trigger_kind {
+ CompletionTrigger_Input = 0,
+ CompletionTrigger_Char = 1,
+};
+
+struct completion_trigger {
+ enum completion_trigger_kind kind;
+ union {
+ uint32_t c;
+ uint32_t nchars;
+ };
+};
+
+void init_completion(struct buffers *buffers);
+void destroy_completion();
+
+typedef void (*insert_cb)();
+
+/**
+ * Enable completions in the buffer @ref source.
+ *
+ * @param source [in] The buffer to provide completions for.
+ * @param trigger [in] The completion trigger to use for this completion.
+ * @param providers [in] The completion providers to use.
+ * @param nproviders [in] The number of providers in @ref providers.
+ */
+void enable_completion(struct buffer *source, struct completion_trigger trigger,
+ struct completion_provider *providers,
+ uint32_t nproviders, insert_cb on_completion_inserted);
+
+struct completion_provider path_provider();
+struct completion_provider buffer_provider();
+
+/**
+ * Abort any active completion.
+ */
+void abort_completion();
+
+/**
+ * Is a completion currently showing?
+ *
+ * @returns True if the completion window is showing completions.
+ */
+bool completion_active();
+
+/**
+ * Disable completion for @ref buffer.
+ *
+ * @param buffer [in] Buffer to disable completions for.
+ */
+void disable_completion(struct buffer *buffer);
+
+#endif