diff options
author | Přemysl Janouch <p.janouch@gmail.com> | 2016-03-10 00:07:59 +0100 |
---|---|---|
committer | Přemysl Janouch <p.janouch@gmail.com> | 2016-03-10 00:07:59 +0100 |
commit | 42d88f87f554c7133193972e0b6b92e9a9537c88 (patch) | |
tree | 6c1fde1bd3474038256883fd29842a77a8048fa8 /degesch.c | |
parent | a1c4a1ef3a974bb89f53532ac561a3e4cea5b82c (diff) | |
download | xK-42d88f87f554c7133193972e0b6b92e9a9537c88.tar.gz xK-42d88f87f554c7133193972e0b6b92e9a9537c88.tar.xz xK-42d88f87f554c7133193972e0b6b92e9a9537c88.zip |
degesch: add unbound commands for buffer movement
Diffstat (limited to 'degesch.c')
-rw-r--r-- | degesch.c | 86 |
1 files changed, 58 insertions, 28 deletions
@@ -3929,6 +3929,29 @@ buffer_goto (struct app_context *ctx, int n) } static int +buffer_count (struct app_context *ctx) +{ + int total = 0; + LIST_FOR_EACH (struct buffer, iter, ctx->buffers) + total++; + return total; +} + +static void +buffer_move (struct app_context *ctx, struct buffer *buffer, int n) +{ + hard_assert (n >= 1 && n <= buffer_count (ctx)); + LIST_UNLINK_WITH_TAIL (ctx->buffers, ctx->buffers_tail, buffer); + + struct buffer *following = ctx->buffers; + while (--n && following) + following = following->next; + + LIST_INSERT_WITH_TAIL (ctx->buffers, ctx->buffers_tail, buffer, following); + refresh_prompt (ctx); +} + +static int buffer_get_index (struct app_context *ctx, struct buffer *buffer) { int index = 1; @@ -9612,27 +9635,13 @@ handle_buffer_move (struct app_context *ctx, struct handler_args *a) if (!xstrtoul (&request, a->arguments, 10)) return false; - unsigned long total = 0; - LIST_FOR_EACH (struct buffer, iter, ctx->buffers) - total++; - - if (request == 0 || request > total) + if (request == 0 || request > (unsigned long) buffer_count (ctx)) { log_global_error (ctx, "#s: #s", "Can't move buffer", "requested position is out of range"); return true; } - - struct buffer *buffer = a->buffer; - LIST_UNLINK_WITH_TAIL (ctx->buffers, ctx->buffers_tail, buffer); - - struct buffer *following = ctx->buffers; - while (--request && following) - following = following->next; - - LIST_INSERT_WITH_TAIL (ctx->buffers, ctx->buffers_tail, buffer, following); - - refresh_prompt (ctx); + buffer_move (ctx, a->buffer, request); return true; } @@ -11803,6 +11812,25 @@ on_goto_activity (int count, int key, void *user_data) } static bool +on_move_buffer_left (int count, int key, void *user_data) +{ + (void) key; + + struct app_context *ctx = user_data; + int total = buffer_count (ctx); + int n = buffer_get_index (ctx, ctx->current_buffer) - count; + if (n <= 0) n += total * (1 + -n / total); + buffer_move (ctx, ctx->current_buffer, (n - 1) % total + 1); + return true; +} + +static bool +on_move_buffer_right (int count, int key, void *user_data) +{ + return on_move_buffer_left (-count, key, user_data); +} + +static bool on_redraw_screen (int count, int key, void *user_data) { (void) count; @@ -11839,18 +11867,20 @@ input_add_functions (void *user_data) { struct app_context *ctx = user_data; #define XX(...) CALL_ (ctx->input, register_fn, __VA_ARGS__, ctx); - XX ("previous-buffer", "Previous buffer", on_previous_buffer) - XX ("next-buffer", "Next buffer", on_next_buffer) - XX ("goto-buffer", "Go to buffer", on_goto_buffer) - XX ("switch-buffer", "Switch buffer", on_switch_buffer) - XX ("goto-highlight", "Go to highlight", on_goto_highlight) - XX ("goto-activity", "Go to activity", on_goto_activity) - XX ("display-backlog", "Show backlog", on_display_backlog) - XX ("display-full-log", "Show full log", on_display_full_log) - XX ("edit-input", "Edit input", on_edit_input) - XX ("redraw-screen", "Redraw screen", on_redraw_screen) - XX ("insert-attribute", "mIRC formatting", on_insert_attribute) - XX ("start-paste-mode", "Bracketed paste", on_start_paste_mode) + XX ("previous-buffer", "Previous buffer", on_previous_buffer) + XX ("next-buffer", "Next buffer", on_next_buffer) + XX ("goto-buffer", "Go to buffer", on_goto_buffer) + XX ("switch-buffer", "Switch buffer", on_switch_buffer) + XX ("goto-highlight", "Go to highlight", on_goto_highlight) + XX ("goto-activity", "Go to activity", on_goto_activity) + XX ("move-buffer-left", "Move buffer left", on_move_buffer_left) + XX ("move-buffer-right", "Move buffer right", on_move_buffer_right) + XX ("display-backlog", "Show backlog", on_display_backlog) + XX ("display-full-log", "Show full log", on_display_full_log) + XX ("edit-input", "Edit input", on_edit_input) + XX ("redraw-screen", "Redraw screen", on_redraw_screen) + XX ("insert-attribute", "mIRC formatting", on_insert_attribute) + XX ("start-paste-mode", "Bracketed paste", on_start_paste_mode) #undef XX } |