aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2015-04-27 22:51:40 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2015-04-27 22:51:40 +0200
commit412cad9328ec3cd7f1e918a98a7e1df5c0aed97d (patch)
tree1215daa330e187f12f6da5530893b20d05cfc70c
parentcdb1d8198269ab5efc676fa30b7f55dcb9a28de3 (diff)
downloadxK-412cad9328ec3cd7f1e918a98a7e1df5c0aed97d.tar.gz
xK-412cad9328ec3cd7f1e918a98a7e1df5c0aed97d.tar.xz
xK-412cad9328ec3cd7f1e918a98a7e1df5c0aed97d.zip
degesch: add fast buffer switching
When the user tries to M-n the same buffer, it switches to the last.
-rw-r--r--degesch.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/degesch.c b/degesch.c
index f6827ed..1d5e3ee 100644
--- a/degesch.c
+++ b/degesch.c
@@ -482,6 +482,8 @@ struct app_context
struct buffer *buffers; ///< All our buffers in order
struct buffer *buffers_tail; ///< The tail of our buffers
+ struct buffer *last_buffer; ///< Last used buffer
+
// XXX: when we go multiserver, there will be collisions
// TODO: make buffer names unique like weechat does
struct str_map buffers_by_name; ///< Excludes GLOBAL and SERVER
@@ -1425,6 +1427,9 @@ buffer_remove (struct app_context *ctx, struct buffer *buffer)
LIST_UNLINK_WITH_TAIL (ctx->buffers, ctx->buffers_tail, buffer);
buffer_destroy (buffer);
+ if (buffer == ctx->last_buffer)
+ ctx->last_buffer = NULL;
+
// It's not a good idea to remove these buffers, but it's even a worse
// one to leave the pointers point to invalid memory
if (buffer == ctx->global_buffer)
@@ -1515,6 +1520,7 @@ buffer_activate (struct app_context *ctx, struct buffer *buffer)
}
// Now at last we can switch the pointers
+ ctx->last_buffer = ctx->current_buffer;
ctx->current_buffer = buffer;
refresh_prompt (ctx);
@@ -2178,8 +2184,15 @@ on_readline_goto_buffer (int count, int key)
if (n < 0 || n > 9)
return 0;
+ // There's no buffer zero
+ if (n == 0)
+ n = 10;
+
struct app_context *ctx = g_ctx;
- if (!buffer_goto (ctx, n == 0 ? 10 : n))
+ 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 == 0 ? 10 : n))
rl_ding ();
return 0;
}