From 412cad9328ec3cd7f1e918a98a7e1df5c0aed97d Mon Sep 17 00:00:00 2001 From: Přemysl Janouch Date: Mon, 27 Apr 2015 22:51:40 +0200 Subject: degesch: add fast buffer switching When the user tries to M-n the same buffer, it switches to the last. --- degesch.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) 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; } -- cgit v1.2.3-70-g09d2