From 74bed4bc02ef08ef3cb71f8179f9f398f91b2a02 Mon Sep 17 00:00:00 2001
From: Přemysl Janouch
Date: Thu, 31 Dec 2015 03:55:32 +0100
Subject: degesch: Alt-Tab switch to the last buffer
---
NEWS | 2 ++
degesch.c | 31 +++++++++++++++++++++++++++++++
2 files changed, 33 insertions(+)
diff --git a/NEWS b/NEWS
index 8c4fb3b..8c01cbc 100644
--- a/NEWS
+++ b/NEWS
@@ -13,6 +13,8 @@
* degesch: added capability to edit the input line using VISUAL/EDITOR
+ * degesch: added Meta-Tab to switch to the last used buffer
+
* degesch: correctly respond to stopping and resuming (SIGTSTP)
* degesch: fixed decoding of text formatting
diff --git a/degesch.c b/degesch.c
index 5dce5a9..b7adad7 100644
--- a/degesch.c
+++ b/degesch.c
@@ -10655,6 +10655,7 @@ bind_common_keys (struct app_context *ctx)
for (int i = 0; i <= 9; i++)
input_bind_meta (self, '0' + i, "goto-buffer");
+ input_bind_meta (self, '\t', "switch-buffer");
input_bind_meta (self, 'm', "insert-attribute");
input_bind_meta (self, 'h', "display-full-log");
input_bind_meta (self, 'e', "edit-input");
@@ -10707,6 +10708,20 @@ on_readline_next_buffer (int count, int key)
return 0;
}
+static int
+on_readline_switch_buffer (int count, int key)
+{
+ (void) count;
+ (void) key;
+
+ struct app_context *ctx = g_ctx;
+ if (ctx->last_buffer)
+ buffer_activate (ctx, ctx->last_buffer);
+ else
+ input_ding (&ctx->input);
+ return 0;
+}
+
static int
on_readline_display_backlog (int count, int key)
{
@@ -10843,6 +10858,7 @@ app_readline_init (void)
rl_add_defun ("previous-buffer", on_readline_previous_buffer, -1);
rl_add_defun ("next-buffer", on_readline_next_buffer, -1);
rl_add_defun ("goto-buffer", on_readline_goto_buffer, -1);
+ rl_add_defun ("switch-buffer", on_readline_switch_buffer, -1);
rl_add_defun ("display-backlog", on_readline_display_backlog, -1);
rl_add_defun ("display-full-log", on_readline_display_full_log, -1);
rl_add_defun ("edit-input", on_readline_edit_input, -1);
@@ -10906,6 +10922,20 @@ on_editline_next_buffer (EditLine *editline, int key)
return CC_NORM;
}
+static unsigned char
+on_editline_switch_buffer (EditLine *editline, int key)
+{
+ (void) editline;
+ (void) key;
+
+ struct app_context *ctx = g_ctx;
+ if (ctx->last_buffer)
+ buffer_activate (ctx, ctx->last_buffer);
+ else
+ input_ding (&ctx->input);
+ return CC_NORM;
+}
+
static unsigned char
on_editline_display_backlog (EditLine *editline, int key)
{
@@ -11062,6 +11092,7 @@ app_editline_init (struct input *self)
{ "goto-buffer", "Go to buffer", on_editline_goto_buffer },
{ "previous-buffer", "Previous buffer", on_editline_previous_buffer },
{ "next-buffer", "Next buffer", on_editline_next_buffer },
+ { "switch-buffer", "Switch buffer", on_editline_switch_buffer },
{ "display-backlog", "Show backlog", on_editline_display_backlog },
{ "display-full-log", "Show full log", on_editline_display_full_log },
{ "edit-input", "Edit input", on_editline_edit_input },
--
cgit v1.2.3-70-g09d2