# HG changeset patch # User Mikael Berthe # Date 1173904397 -3600 # Node ID 03a38b7ad2e0d1c4ed25a4e31cbc26e2b65c426a # Parent 29f805d8412fd43c92337328312a40c54070984c Add a collection of commands for key bindings (Lego12239) This patch gives more flexibility to customize the key bindings, by adding a /iline command. diff -r 29f805d8412f -r 03a38b7ad2e0 mcabber/src/commands.c --- a/mcabber/src/commands.c Mon Feb 26 21:13:54 2007 +0100 +++ b/mcabber/src/commands.c Wed Mar 14 21:33:17 2007 +0100 @@ -70,6 +70,7 @@ static void do_event(char *arg); static void do_help(char *arg); static void do_pgp(char *arg); +static void do_iline(char *arg); // Global variable for the commands list static GSList *Commands; @@ -132,6 +133,7 @@ cmd_add("status_to", "Show or set your status for one recipient", COMPL_JID, COMPL_STATUS, &do_status_to); cmd_add("version", "Show mcabber version", 0, 0, &do_version); + cmd_add("iline", "Manipulate input buffer", 0, 0, &do_iline); // Status category compl_add_category_word(COMPL_STATUS, "online"); @@ -2715,6 +2717,43 @@ free_arg_lst(paramlst); } +static void do_iline(char *arg) +{ + if (!strcasecmp(arg, "fword")) { + readline_forward_word(); + } else if (!strcasecmp(arg, "bword")) { + readline_backward_word(); + } else if (!strcasecmp(arg, "word_fdel")) { + readline_forward_kill_word(); + } else if (!strcasecmp(arg, "word_bdel")) { + readline_backward_kill_word(); + } else if (!strcasecmp(arg, "fchar")) { + readline_forward_char(); + } else if (!strcasecmp(arg, "bchar")) { + readline_backward_char(); + } else if (!strcasecmp(arg, "char_fdel")) { + readline_forward_kill_char(); + } else if (!strcasecmp(arg, "char_bdel")) { + readline_backward_kill_char(); + } else if (!strcasecmp(arg, "char_swp")) { + readline_transpose_chars(); + } else if (!strcasecmp(arg, "hist_prev")) { + readline_hist_prev(); + } else if (!strcasecmp(arg, "hist_next")) { + readline_hist_next(); + } else if (!strcasecmp(arg, "iline_start")) { + readline_iline_start(); + } else if (!strcasecmp(arg, "iline_end")) { + readline_iline_end(); + } else if (!strcasecmp(arg, "iline_fdel")) { + readline_forward_kill_iline(); + } else if (!strcasecmp(arg, "iline_bdel")) { + readline_backward_kill_iline(); + } else if (!strcasecmp(arg, "send_multiline")) { + readline_send_multiline(); + } +} + static void do_connect(char *arg) { mcabber_connect(); diff -r 29f805d8412f -r 03a38b7ad2e0 mcabber/src/compl.h diff -r 29f805d8412f -r 03a38b7ad2e0 mcabber/src/screen.c --- a/mcabber/src/screen.c Mon Feb 26 21:13:54 2007 +0100 +++ b/mcabber/src/screen.c Wed Mar 14 21:33:17 2007 +0100 @@ -2256,6 +2256,28 @@ } } +void readline_forward_kill_word(void) +{ + char *c, *old = ptr_inputline; + int spaceallowed = 1; + + if (! *ptr_inputline) return; + + for (c = ptr_inputline ; *c ; c = next_char(c)) { + if (!iswalnum(get_char(c))) { + if (iswblank(get_char(c))) { + if (!spaceallowed) break; + } else spaceallowed = 0; + } else spaceallowed = 0; + } + + // Modify the line + for (;;) { + *old = *c++; + if (!*old++) break; + } +} + // readline_backward_kill_word() // Kill the word before the cursor, in input line void readline_backward_kill_word(void) @@ -2332,6 +2354,89 @@ check_offset(1); } +void readline_backward_char(void) +{ + if (ptr_inputline == (char*)&inputLine) return; + + ptr_inputline = prev_char(ptr_inputline, inputLine); + check_offset(-1); +} + +void readline_forward_char(void) +{ + if (!*ptr_inputline) return; + + ptr_inputline = next_char(ptr_inputline); + check_offset(1); +} + +void readline_hist_prev(void) +{ + const char *l = scr_cmdhisto_prev(inputLine, ptr_inputline-inputLine); + if (l) strcpy(inputLine, l); +} + +void readline_hist_next(void) +{ + const char *l = scr_cmdhisto_next(inputLine, ptr_inputline-inputLine); + if (l) strcpy(inputLine, l); +} + +void readline_backward_kill_char(void) +{ + char *src, *c; + + if (ptr_inputline == (char*)&inputLine) + return; + + src = ptr_inputline; + c = prev_char(ptr_inputline, inputLine); + ptr_inputline = c; + for ( ; *src ; ) + *c++ = *src++; + *c = 0; + check_offset(-1); +} + +void readline_forward_kill_char(void) +{ + if (!*ptr_inputline) + return; + + strcpy(ptr_inputline, next_char(ptr_inputline)); +} + +void readline_iline_start(void) +{ + ptr_inputline = inputLine; + inputline_offset = 0; +} + +void readline_iline_end(void) +{ + for (; *ptr_inputline; ptr_inputline++) ; + check_offset(1); +} + +void readline_backward_kill_iline(void) +{ + strcpy(inputLine, ptr_inputline); + ptr_inputline = inputLine; + inputline_offset = 0; +} + +void readline_forward_kill_iline(void) +{ + *ptr_inputline = 0; +} + +void readline_send_multiline(void) +{ + // Validate current multi-line + if (scr_get_multimode()) + process_command(mkcmdstr("msay send")); +} + // which_row() // Tells which row our cursor is in, in the command line. // -2 -> normal text @@ -2552,13 +2657,6 @@ refresh_inputline(); } -static void scr_handle_CtrlD(void) -{ - // Validate current multi-line - if (scr_get_multimode()) - process_command(mkcmdstr("msay send")); -} - static void add_keyseq(char *seqstr, guint mkeycode, gint value) { keyseq *ks; @@ -2805,30 +2903,16 @@ case 8: // Ctrl-h case 127: // Backspace too case KEY_BACKSPACE: - if (ptr_inputline != (char*)&inputLine) { - char *src = ptr_inputline; - char *c = prev_char(ptr_inputline, inputLine); - ptr_inputline = c; - for ( ; *src ; ) - *c++ = *src++; - *c = 0; - check_offset(-1); - } + readline_backward_kill_char(); break; case KEY_DC:// Del - if (*ptr_inputline) - strcpy(ptr_inputline, next_char(ptr_inputline)); + readline_forward_kill_char(); break; case KEY_LEFT: - if (ptr_inputline != (char*)&inputLine) { - ptr_inputline = prev_char(ptr_inputline, inputLine); - check_offset(-1); - } + readline_backward_char(); break; case KEY_RIGHT: - if (*ptr_inputline) - ptr_inputline = next_char(ptr_inputline); - check_offset(1); + readline_forward_char(); break; case 7: // Ctrl-g scr_cancel_current_completion(); @@ -2876,18 +2960,10 @@ } break; case KEY_UP: - { - const char *l = scr_cmdhisto_prev(inputLine, - ptr_inputline-inputLine); - if (l) strcpy(inputLine, l); - } + readline_hist_prev(); break; case KEY_DOWN: - { - const char *l = scr_cmdhisto_next(inputLine, - ptr_inputline-inputLine); - if (l) strcpy(inputLine, l); - } + readline_hist_next(); break; case KEY_PPAGE: scr_CheckAutoAway(TRUE); @@ -2898,29 +2974,20 @@ scr_RosterDown(); break; case KEY_HOME: - case 1: - ptr_inputline = inputLine; - inputline_offset = 0; + readline_iline_start(); break; case 3: // Ctrl-C scr_handle_CtrlC(); break; - case 4: // Ctrl-D - scr_handle_CtrlD(); - break; case KEY_END: - case 5: - for (; *ptr_inputline; ptr_inputline++) ; - check_offset(1); + readline_iline_end(); break; case 21: // Ctrl-u - strcpy(inputLine, ptr_inputline); - ptr_inputline = inputLine; - inputline_offset = 0; + readline_backward_kill_iline(); break; case KEY_EOL: case 11: // Ctrl-k - *ptr_inputline = 0; + readline_forward_kill_iline(); break; case 16: // Ctrl-p scr_BufferScrollUpDown(-1, 0); diff -r 29f805d8412f -r 03a38b7ad2e0 mcabber/src/screen.h --- a/mcabber/src/screen.h Mon Feb 26 21:13:54 2007 +0100 +++ b/mcabber/src/screen.h Wed Mar 14 21:33:17 2007 +0100 @@ -127,6 +127,23 @@ void scr_RosterJumpAlternate(void); void scr_BufferScrollUpDown(int updown, unsigned int nblines); +void readline_transpose_chars(void); +void readline_forward_kill_word(void); +void readline_backward_kill_word(void); +void readline_backward_word(void); +void readline_forward_word(void); +void readline_backward_char(void); +void readline_forward_char(void); +void readline_hist_prev(void); +void readline_hist_next(void); +void readline_backward_kill_char(void); +void readline_forward_kill_char(void); +void readline_iline_start(void); +void readline_iline_end(void); +void readline_backward_kill_iline(void); +void readline_forward_kill_iline(void); +void readline_send_multiline(void); + #endif /* vim: set expandtab cindent cinoptions=>2\:2(0: For Vim users... */