summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/dged/buffers.c7
-rw-r--r--src/main/cmds.c5
-rw-r--r--src/main/completion.c14
-rw-r--r--src/main/main.c5
4 files changed, 27 insertions, 4 deletions
diff --git a/src/dged/buffers.c b/src/dged/buffers.c
index f6d197d..e19b82e 100644
--- a/src/dged/buffers.c
+++ b/src/dged/buffers.c
@@ -143,10 +143,13 @@ bool buffers_remove(struct buffers *buffers, const char *name) {
size_t namelen = strlen(name);
while (chunk != NULL) {
for (uint32_t i = 0; i < buffers->chunk_size; ++i) {
+ if (!chunk->entries[i].occupied) {
+ continue;
+ }
+
struct buffer *b = &chunk->entries[i].buffer;
size_t bnamelen = strlen(b->name);
- if (chunk->entries[i].occupied && namelen == bnamelen &&
- memcmp(name, b->name, bnamelen) == 0) {
+ if (namelen == bnamelen && memcmp(name, b->name, bnamelen) == 0) {
buf_entry = &chunk->entries[i];
goto found;
}
diff --git a/src/main/cmds.c b/src/main/cmds.c
index 989f28e..a7b509d 100644
--- a/src/main/cmds.c
+++ b/src/main/cmds.c
@@ -334,7 +334,10 @@ int32_t buflist_refresh_cmd(struct command_ctx ctx, int argc,
const char *argv[]) {
(void)argc;
(void)argv;
- buflist_refresh(window_buffer(ctx.active_window), ctx.buffers);
+ struct buffer *b = buffers_find(ctx.buffers, "*buffers*");
+ if (b != NULL) {
+ buflist_refresh(b, ctx.buffers);
+ }
return 0;
}
diff --git a/src/main/completion.c b/src/main/completion.c
index 7c5de47..23b3a58 100644
--- a/src/main/completion.c
+++ b/src/main/completion.c
@@ -140,7 +140,10 @@ COMMAND_FN("prev-completion", prev_completion, goto_prev_completion, NULL)
COMMAND_FN("insert-completion", insert_completion, insert_completion, NULL)
static void clear_completions(struct completion_state *state) {
- buffer_clear(state->completions_buffer);
+ if (g_state.completions_buffer != NULL) {
+ buffer_clear(state->completions_buffer);
+ }
+
VEC_FOR_EACH(&state->completions, struct completion_item * item) {
if (item->completion.cleanup != NULL) {
item->completion.cleanup(item->completion.data);
@@ -326,6 +329,12 @@ static void on_buffer_delete(struct buffer *buffer, struct edit_location edit,
on_buffer_changed(buffer, edit, true, userdata);
}
+static void completions_buffer_deleted(struct buffer *buffer, void *userdata) {
+ (void)buffer;
+ struct completion_state *state = (struct completion_state *)userdata;
+ state->completions_buffer = NULL;
+}
+
void init_completion(struct buffers *buffers) {
if (g_state.completions_buffer == NULL) {
struct buffer b = buffer_create("*completions*");
@@ -340,6 +349,9 @@ void init_completion(struct buffers *buffers) {
buffer_add_update_hook(g_state.completions_buffer, update_comp_buffer,
&g_state);
+ buffer_add_destroy_hook(g_state.completions_buffer,
+ completions_buffer_deleted, &g_state);
+
g_state.keymap_id = (uint64_t)-1;
g_state.target = NULL;
diff --git a/src/main/main.c b/src/main/main.c
index 2e2df58..70c62a3 100644
--- a/src/main/main.c
+++ b/src/main/main.c
@@ -391,6 +391,11 @@ int main(int argc, char *argv[]) {
needs_render = true;
}
+ if (buffers_num_buffers(&buflist) == 0) {
+ running = false;
+ continue;
+ }
+
// TODO: maybe this should be hidden behind something
// The placement is correct though.
buffers_for_each(&buflist, clear_buffer_props, NULL);