diff --git a/ChangeLog b/ChangeLog index 66898a80ac05510a3d285e5a7a115241db5df06c..3eb8bc56253d89e54db06d856ec7b49b1c681ad9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2015-07-31 Benno Schulenberg <bensberg@justemail.net> + * src/text.c (do_cutword, do_cut_prev_word, do_cut_next_word), + src/global.c (shortcut_init, strtosc), doc/texinfo/nano.texi, + doc/man/nanorc.5: Add two new bindable functions, 'cutwordleft' + and 'cutwordright', which delete all characters from the cursor + to the preceding or succeeding word start. Fixes bug #32803. + 2015-07-30 Benno Schulenberg <bensberg@justemail.net> * src/global.c (shortcut_init): Don't show ^R and ^T in the help lines in restricted mode (if possible), to give visual feedback. diff --git a/doc/man/nanorc.5 b/doc/man/nanorc.5 index f405058fd57aece44e4d1385df77ab94ee5ebc35..80e566b94bee815a70a6b3d72bf5d0354f4bef00 100644 --- a/doc/man/nanorc.5 +++ b/doc/man/nanorc.5 @@ -418,6 +418,12 @@ current cursor position. .B mark Sets the mark at the current position, to start selecting text. .TP +.B cutwordleft +Cuts from the cursor position to the beginning of the preceding word. +.TP +.B cutwordright +Cuts from the cursor position to the beginning of the next word. +.TP .B cutrestoffile Cuts all text from the cursor position till the end of the buffer. .TP diff --git a/doc/texinfo/nano.texi b/doc/texinfo/nano.texi index 3769f2c0fa8c61f94b6069b93e8c3664d6ab1f31..0b250fbb25cafbeb37ac5628fb64ffdeb2e9c0e9 100644 --- a/doc/texinfo/nano.texi +++ b/doc/texinfo/nano.texi @@ -988,6 +988,12 @@ current cursor position. @item mark Sets the mark at the current position, to start selecting text. +@item cutwordleft +Cuts from the cursor position to the beginning of the preceding word. + +@item cutwordright +Cuts from the cursor position to the beginning of the next word. + @item cutrestoffile Cuts all text from the cursor position till the end of the buffer. diff --git a/src/global.c b/src/global.c index cde81a6ccdd2f1db4979c960ef33a00beaf97c13..725ac9046884046348f01caefd21aca509c7f802 100644 --- a/src/global.c +++ b/src/global.c @@ -587,6 +587,10 @@ void shortcut_init(void) const char *nano_backspace_msg = N_("Delete the character to the left of the cursor"); #ifndef NANO_TINY + const char *nano_cut_word_left_msg = + N_("Cut backward from cursor to word start"); + const char *nano_cut_word_right_msg = + N_("Cut forward from cursor to next word start"); const char *nano_cut_till_eof_msg = N_("Cut from the cursor position to the end of the file"); #endif @@ -893,7 +897,8 @@ void shortcut_init(void) add_to_funcs(do_tab, MMAIN, N_("Tab"), IFSCHELP(nano_tab_msg), TOGETHER, NOVIEW); add_to_funcs(do_enter_void, MMAIN, - N_("Enter"), IFSCHELP(nano_enter_msg), TOGETHER, NOVIEW); + N_("Enter"), IFSCHELP(nano_enter_msg), BLANKAFTER, NOVIEW); + add_to_funcs(do_delete, MMAIN, N_("Delete"), IFSCHELP(nano_delete_msg), TOGETHER, NOVIEW); add_to_funcs(do_backspace, MMAIN, @@ -906,6 +911,10 @@ void shortcut_init(void) NOVIEW); #ifndef NANO_TINY + add_to_funcs(do_cut_prev_word, MMAIN, + N_("Cut Left"), IFSCHELP(nano_cut_word_left_msg), TOGETHER, NOVIEW); + add_to_funcs(do_cut_next_word, MMAIN, + N_("Cut Right"), IFSCHELP(nano_cut_word_right_msg), TOGETHER, NOVIEW); add_to_funcs(do_cut_till_eof, MMAIN, N_("CutTillEnd"), IFSCHELP(nano_cut_till_eof_msg), BLANKAFTER, NOVIEW); #endif @@ -1392,6 +1401,10 @@ sc *strtosc(char *input) s->scfunc = do_prev_word_void; else if (!strcasecmp(input, "nextword")) s->scfunc = do_next_word_void; + else if (!strcasecmp(input, "cutwordleft")) + s->scfunc = do_cut_prev_word; + else if (!strcasecmp(input, "cutwordright")) + s->scfunc = do_cut_next_word; else if (!strcasecmp(input, "findbracket")) s->scfunc = do_find_bracket; else if (!strcasecmp(input, "wordcount")) diff --git a/src/proto.h b/src/proto.h index 777acf602563702c73aa9bde80c2fa82b9d3832d..70e7ee6aac54bb0111072882e62bbdf79a4e89e8 100644 --- a/src/proto.h +++ b/src/proto.h @@ -646,6 +646,10 @@ void do_mark(void); #endif void do_delete(void); void do_backspace(void); +#ifndef NANO_TINY +void do_cut_prev_word(void); +void do_cut_next_word(void); +#endif void do_tab(void); #ifndef NANO_TINY void do_indent(ssize_t cols); diff --git a/src/text.c b/src/text.c index 05a51ca0b8d2f4dbcc24772fad0db9b593da9e05..ffea145b42ae51e94d66ddbaf38ce495b941e2bc 100644 --- a/src/text.c +++ b/src/text.c @@ -185,6 +185,47 @@ void do_backspace(void) } } +#ifndef NANO_TINY +/* Delete text from the cursor until the first start of a word to + * the right, or to the left when backward is true. */ +void do_cutword(bool backward) +{ + /* Remember the current cursor position. */ + filestruct *is_current = openfile->current; + size_t is_current_x = openfile->current_x; + + /* Move the cursor to a word start, to the left or to the right. */ + if (backward) + do_prev_word(ISSET(WORD_BOUNDS), FALSE); + else + do_next_word(ISSET(WORD_BOUNDS), FALSE); + + /* Set the mark at the start of that word. */ + openfile->mark_begin = openfile->current; + openfile->mark_begin_x = openfile->current_x; + openfile->mark_set = TRUE; + + /* Put the cursor back where it was, so an undo will put it there too. */ + openfile->current = is_current; + openfile->current_x = is_current_x; + + /* Now kill the marked region and a word is gone. */ + do_cut_text_void(); +} + +/* Delete a word leftward. */ +void do_cut_prev_word(void) +{ + do_cutword(TRUE); +} + +/* Delete a word rightward. */ +void do_cut_next_word(void) +{ + do_cutword(FALSE); +} +#endif /* !NANO_TINY */ + /* Insert a tab. If the TABS_TO_SPACES flag is set, insert the number * of spaces that a tab would normally take up. */ void do_tab(void)