Adding two new bindable functions which delete all characters
from the cursor to the preceding or succeeding word start. git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@5334 35c25a1d-7b9e-4130-9fde-d3aeb78583b8master
parent
20ba559b9f
commit
b3e4051ded
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
||||
|
|
15
src/global.c
15
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"))
|
||||
|
|
|
@ -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);
|
||||
|
|
41
src/text.c
41
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)
|
||||
|
|
Loading…
Reference in New Issue