+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.
.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
@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.
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
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,
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
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"))
#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);
}
}
+#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)