From: Thomas Roessler Date: Wed, 17 May 2000 09:06:38 +0000 (+0000) Subject: Add forward-word and backward-word functions to the editor. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f2842a20d94791f57df30579a94897fe86876d6b;p=neomutt Add forward-word and backward-word functions to the editor. --- diff --git a/OPS b/OPS index 91e0a7831..76aabce03 100644 --- a/OPS +++ b/OPS @@ -57,6 +57,7 @@ OP_DISPLAY_MESSAGE "display a message" OP_EDIT_MESSAGE "edit the raw message" OP_EDITOR_BACKSPACE "delete the char in front of the cursor" OP_EDITOR_BACKWARD_CHAR "move the cursor one character to the left" +OP_EDITOR_BACKWARD_WORD "move the cursor to the beginning of the word" OP_EDITOR_BOL "jump to the beginning of the line" OP_EDITOR_BUFFY_CYCLE "cycle among incoming mailboxes" OP_EDITOR_COMPLETE "complete filename or alias" @@ -64,6 +65,7 @@ OP_EDITOR_COMPLETE_QUERY "complete address with query" OP_EDITOR_DELETE_CHAR "delete the char under the cursor" OP_EDITOR_EOL "jump to the end of the line" OP_EDITOR_FORWARD_CHAR "move the cursor one character to the right" +OP_EDITOR_FORWARD_WORD "move the cursor to the end of the word" OP_EDITOR_HISTORY_DOWN "scroll up through the history list" OP_EDITOR_HISTORY_UP "scroll up through the history list" OP_EDITOR_KILL_EOL "delete chars from cursor to end of line" diff --git a/enter.c b/enter.c index 63bb1b605..a9307223a 100644 --- a/enter.c +++ b/enter.c @@ -277,6 +277,60 @@ int _mutt_enter_string (unsigned char *buf, size_t buflen, int y, int x, } } break; + case OP_EDITOR_BACKWARD_WORD: + if (curpos == 0) + { + BEEP (); + } + else + { + if (curpos > 0 && !ISSPACE (buf[curpos]) && ISSPACE (buf[curpos - 1])) + curpos--; + while (curpos > 0 && ISSPACE (buf[curpos])) + curpos--; + while (curpos > 0 && !ISSPACE (buf[curpos])) + curpos--; + if (ISSPACE (buf[curpos]) && !ISSPACE (buf[curpos + 1])) + curpos++; + + if (!pass) + { + if (curpos < begin) + { + begin = curpos - width/2; + redraw = M_REDRAW_LINE; + } + else + move (y, x + curpos - begin); + } + } + break; + + case OP_EDITOR_FORWARD_WORD: + if (curpos == lastchar) + { + BEEP (); + } + else + { + while (curpos < lastchar && ISSPACE (buf[curpos])) + curpos++; + while (curpos < lastchar && !ISSPACE (buf[curpos])) + curpos++; + + if (!pass) + { + if (curpos >= begin + width) + { + begin = curpos - width / 2; + redraw = M_REDRAW_LINE; + } + else + move (y, x + curpos - begin); + } + } + break; + case OP_EDITOR_DELETE_CHAR: if (curpos != lastchar) { diff --git a/functions.h b/functions.h index 04849decf..4b9e762e5 100644 --- a/functions.h +++ b/functions.h @@ -352,22 +352,24 @@ struct binding_t OpQuery[] = { struct binding_t OpEditor[] = { { "bol", OP_EDITOR_BOL, "\001" }, { "backward-char", OP_EDITOR_BACKWARD_CHAR, "\002" }, + { "backward-word", OP_EDITOR_BACKWARD_WORD, "\033b"}, { "delete-char", OP_EDITOR_DELETE_CHAR, "\004" }, { "eol", OP_EDITOR_EOL, "\005" }, { "forward-char", OP_EDITOR_FORWARD_CHAR, "\006" }, + { "forward-word", OP_EDITOR_FORWARD_WORD, "\033f"}, { "backspace", OP_EDITOR_BACKSPACE, "\010" }, { "kill-eol", OP_EDITOR_KILL_EOL, "\013" }, - { "kill-eow", OP_EDITOR_KILL_EOW, "\033d" }, + { "kill-eow", OP_EDITOR_KILL_EOW, "\033d"}, { "kill-line", OP_EDITOR_KILL_LINE, "\025" }, { "quote-char", OP_EDITOR_QUOTE_CHAR, "\026" }, { "kill-word", OP_EDITOR_KILL_WORD, "\027" }, - { "complete", OP_EDITOR_COMPLETE, "\t" }, + { "complete", OP_EDITOR_COMPLETE, "\t" }, { "complete-query", OP_EDITOR_COMPLETE_QUERY, "\024" }, - { "buffy-cycle", OP_EDITOR_BUFFY_CYCLE, " " }, - { "history-up", OP_EDITOR_HISTORY_UP, NULL }, - { "history-down", OP_EDITOR_HISTORY_DOWN, NULL }, - { "transpose-chars", OP_EDITOR_TRANSPOSE_CHARS, NULL }, - { NULL, 0, NULL } + { "buffy-cycle", OP_EDITOR_BUFFY_CYCLE, " " }, + { "history-up", OP_EDITOR_HISTORY_UP, NULL }, + { "history-down", OP_EDITOR_HISTORY_DOWN, NULL }, + { "transpose-chars", OP_EDITOR_TRANSPOSE_CHARS, NULL }, + { NULL, 0, NULL } };