summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2015-05-08 07:46:32 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2015-05-08 07:46:32 +0200
commit6414a73d6235a9260d4b1e98877e84d3b1e0a3c0 (patch)
tree3645ea9efea69f964424fc7e46d770541a6c7685
parent102df84cfc1d04f5806735da3acd42387396e618 (diff)
downloadxK-6414a73d6235a9260d4b1e98877e84d3b1e0a3c0.tar.gz
xK-6414a73d6235a9260d4b1e98877e84d3b1e0a3c0.tar.xz
xK-6414a73d6235a9260d4b1e98877e84d3b1e0a3c0.zip
degesch: factor out jump_to_buffer()
-rw-r--r--degesch.c46
1 files 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;
}