From 6f966d4aeebd07d5118a62102a2bc5b878903a9e Mon Sep 17 00:00:00 2001 From: Přemysl Janouch Date: Tue, 14 Jul 2015 06:11:14 +0200 Subject: degesch: factor out buffer_remove_safe() --- degesch.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/degesch.c b/degesch.c index e0c75ab..929e43c 100644 --- a/degesch.c +++ b/degesch.c @@ -3129,6 +3129,16 @@ buffer_get_index (struct app_context *ctx, struct buffer *buffer) return -1; } +static void +buffer_remove_safe (struct app_context *ctx, struct buffer *buffer) +{ + if (buffer == ctx->current_buffer) + buffer_activate (ctx, ctx->last_buffer + ? ctx->last_buffer + : buffer_next (ctx, 1)); + buffer_remove (ctx, buffer); +} + static void init_global_buffer (struct app_context *ctx) { @@ -6718,12 +6728,7 @@ handle_buffer_close (struct app_context *ctx, struct handler_args *a) // The user would be unable to recreate the buffer otherwise if (buffer->type == BUFFER_CHANNEL) part_channel (buffer->server, buffer->channel->name, ""); - - if (buffer == ctx->current_buffer) - buffer_activate (ctx, ctx->last_buffer - ? ctx->last_buffer - : buffer_next (ctx, 1)); - buffer_remove (ctx, buffer); + buffer_remove_safe (ctx, buffer); } } -- cgit v1.2.3-70-g09d2