# HG changeset patch # User Mikael Berthe # Date 1142612054 -3600 # Node ID a681dc477c7f7d494a8b52ddac3bd5fbe1e9ee67 # Parent 402b0e288433411674570af3e05978dec028af2e Add readline_backward_word and readline_forward_word (Ctrl-Left/Ctrl-Right) diff -r 402b0e288433 -r a681dc477c7f mcabber/src/screen.c --- a/mcabber/src/screen.c Fri Mar 17 17:12:04 2006 +0100 +++ b/mcabber/src/screen.c Fri Mar 17 17:14:14 2006 +0100 @@ -1610,11 +1610,12 @@ if (ptr_inputline == inputLine) return; - for (c = ptr_inputline-1 ; c > inputLine ; c--) + for (c = ptr_inputline-1 ; c > inputLine ; c--) { if (!isalnum(*c)) { if (*c == ' ') if (!spaceallowed) break; } else spaceallowed = 0; + } if (c != inputLine || *c != ' ') if ((c < ptr_inputline-1) && (!isalnum(*c))) @@ -1629,6 +1630,46 @@ check_offset(-1); } +// readline_backward_word() +// Move back to the start of the current or previous word +void readline_backward_word() +{ + char *old_ptr_inputLine = ptr_inputline; + int spaceallowed = 1; + + if (ptr_inputline == inputLine) return; + + for (ptr_inputline-- ; ptr_inputline > inputLine ; ptr_inputline--) { + if (!isalnum(*ptr_inputline)) { + if (*ptr_inputline == ' ') + if (!spaceallowed) break; + } else spaceallowed = 0; + } + + if (ptr_inputline < old_ptr_inputLine-1 + && *ptr_inputline == ' ' && *(ptr_inputline+1) != ' ') + ptr_inputline++; + + check_offset(-1); +} + +// readline_forward_word() +// Move forward to the end of the next word +void readline_forward_word() +{ + int spaceallowed = 1; + + while (*ptr_inputline) { + ptr_inputline++; + if (!isalnum(*ptr_inputline)) { + if (*ptr_inputline == ' ') + if (!spaceallowed) break; + } else spaceallowed = 0; + } + + check_offset(1); +} + // which_row() // Tells which row our cursor is in, in the command line. // -2 -> normal text @@ -1974,6 +2015,12 @@ case 23: // Ctrl-w readline_backward_kill_word(); break; + case 516: // Ctrl-Left + readline_backward_word(); + break; + case 518: // Ctrl-Right + readline_forward_word(); + break; case 12: // Ctrl-l scr_CheckAutoAway(TRUE); scr_Resize();