From 6414a73d6235a9260d4b1e98877e84d3b1e0a3c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=99emysl=20Janouch?= Date: Fri, 8 May 2015 07:46:32 +0200 Subject: [PATCH] degesch: factor out jump_to_buffer() --- degesch.c | 46 +++++++++++++++++++++------------------------- 1 file changed, 21 insertions(+), 25 deletions(-) diff --git a/degesch.c b/degesch.c index 1a54a95..4e67558 100644 --- a/degesch.c +++ b/degesch.c @@ -5435,6 +5435,24 @@ redraw_screen (struct app_context *ctx) return true; } +static bool +jump_to_buffer (struct app_context *ctx, int n) +{ + if (n < 0 || n > 9) + return false; + + // There's no buffer zero + if (n == 0) + n = 10; + + if (ctx->last_buffer && buffer_get_index (ctx, ctx->current_buffer) == n) + // Fast switching between two buffers + buffer_activate (ctx, ctx->last_buffer); + else if (!buffer_goto (ctx, n)) + return false; + return true; +} + static void bind_common_keys (struct app_context *ctx) { @@ -5464,20 +5482,9 @@ on_readline_goto_buffer (int count, int key) { (void) count; - int n = UNMETA (key) - '0'; - if (n < 0 || n > 9) - return 0; - - // There's no buffer zero - if (n == 0) - n = 10; - struct app_context *ctx = g_ctx; - if (ctx->last_buffer && buffer_get_index (ctx, ctx->current_buffer) == n) - // Fast switching between two buffers - buffer_activate (ctx, ctx->last_buffer); - else if (!buffer_goto (ctx, n)) - input_ding (self); + if (!jump_to_buffer (ctx, UNMETA (key) - '0')) + input_ding (&ctx->input); return 0; } @@ -5610,19 +5617,8 @@ on_editline_goto_buffer (EditLine *editline, int key) { (void) editline; - int n = key - '0'; - if (n < 0 || n > 9) - return CC_ERROR; - - // There's no buffer zero - if (n == 0) - n = 10; - struct app_context *ctx = g_ctx; - if (ctx->last_buffer && buffer_get_index (ctx, ctx->current_buffer) == n) - // Fast switching between two buffers - buffer_activate (ctx, ctx->last_buffer); - else if (!buffer_goto (ctx, n)) + if (!jump_to_buffer (ctx, key - '0')) return CC_ERROR; return CC_NORM; }