summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2015-04-16 21:16:10 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2015-04-16 21:20:25 +0200
commit75b2fc1da23df41d501f5b2d2e2a9bacc71e445b (patch)
treed9e6c042db4cf0eef274997f1984d642a043c002
parent0c96563545a1ea8ec484af0a1bfea84b57c0889b (diff)
downloadxK-75b2fc1da23df41d501f5b2d2e2a9bacc71e445b.tar.gz
xK-75b2fc1da23df41d501f5b2d2e2a9bacc71e445b.tar.xz
xK-75b2fc1da23df41d501f5b2d2e2a9bacc71e445b.zip
degesch: factor out buffer_goto()
And make M-[0-9] ding if there's no such buffer.
-rw-r--r--degesch.c24
1 files changed, 16 insertions, 8 deletions
diff --git a/degesch.c b/degesch.c
index db07059..f65292a 100644
--- a/degesch.c
+++ b/degesch.c
@@ -938,6 +938,20 @@ buffer_activate (struct app_context *ctx, struct buffer *buffer)
refresh_prompt (ctx);
}
+/// Activate the n-th buffer, counting from one
+static bool
+buffer_goto (struct app_context *ctx, int n)
+{
+ int i = 0;
+ LIST_FOR_EACH (struct buffer, iter, ctx->buffers)
+ if (++i == n)
+ {
+ buffer_activate (ctx, iter);
+ return true;
+ }
+ return false;
+}
+
static void
init_buffers (struct app_context *ctx)
{
@@ -1328,15 +1342,9 @@ on_readline_goto_buffer (int count, int key)
if (n == 0)
n = 10;
- // Activate the n-th buffer
- int i = 0;
struct app_context *ctx = g_ctx;
- LIST_FOR_EACH (struct buffer, iter, ctx->buffers)
- if (++i == n)
- {
- buffer_activate (ctx, iter);
- break;
- }
+ if (!buffer_goto (ctx, n))
+ rl_ding ();
return 0;
}