Rewriting do_next_word() to use the same, simpler logic as do_prev_word().

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@5373 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
This commit is contained in:
Benno Schulenberg 2015-10-27 16:48:24 +00:00
parent b4103321e6
commit 17b46f04da
2 changed files with 27 additions and 61 deletions

View File

@ -1,3 +1,7 @@
2015-10-27 Benno Schulenberg <bensberg@justemail.net>
* src/move.c (do_next_word): Rewrite this function to use the same
logic as do_prev_word(), reducing its number of lines to half.
2015-09-05 Benno Schulenberg <bensberg@justemail.net>
* src/winio.c (display_string, edit_draw): Force a redraw of a line
only when it contains a multicolumn character, to spare all regular

View File

@ -223,74 +223,36 @@ bool do_next_word(bool allow_punct, bool allow_update)
{
size_t pww_save = openfile->placewewant;
filestruct *current_save = openfile->current;
char *char_mb;
int char_mb_len;
bool end_line = FALSE, started_on_word = FALSE;
bool started_on_word = is_word_mbchar(openfile->current->data +
openfile->current_x, allow_punct);
bool seen_space = !started_on_word;
assert(openfile->current != NULL && openfile->current->data != NULL);
char_mb = charalloc(mb_cur_max());
/* Move forward until we find the character after the last letter of
* the current word. */
while (!end_line) {
char_mb_len = parse_mbchar(openfile->current->data +
openfile->current_x, char_mb, NULL);
/* If we've found it, stop moving forward through the current
* line. */
if (!is_word_mbchar(char_mb, allow_punct))
/* Move forward until we reach the start of a word. */
while (TRUE) {
/* If at the end of a line, move to the beginning of the next one. */
if (openfile->current->data[openfile->current_x] == '\0') {
/* If at the end of the file, stop. */
if (openfile->current->next == NULL)
break;
/* If we haven't found it, then we've started on a word, so set
* started_on_word to TRUE. */
started_on_word = TRUE;
if (openfile->current->data[openfile->current_x] == '\0')
end_line = TRUE;
else
openfile->current_x += char_mb_len;
}
/* Move forward until we find the first letter of the next word. */
if (openfile->current->data[openfile->current_x] == '\0')
end_line = TRUE;
else
openfile->current_x += char_mb_len;
for (; openfile->current != NULL;
openfile->current = openfile->current->next) {
while (!end_line) {
char_mb_len = parse_mbchar(openfile->current->data +
openfile->current_x, char_mb, NULL);
/* If we've found it, stop moving forward through the
* current line. */
if (is_word_mbchar(char_mb, allow_punct))
break;
if (openfile->current->data[openfile->current_x] == '\0')
end_line = TRUE;
else
openfile->current_x += char_mb_len;
}
/* If we've found it, stop moving forward to the beginnings of
* subsequent lines. */
if (!end_line)
break;
if (openfile->current != openfile->filebot) {
end_line = FALSE;
openfile->current = openfile->current->next;
openfile->current_x = 0;
}
seen_space = TRUE;
} else {
/* Step forward one character. */
openfile->current_x = move_mbright(openfile->current->data,
openfile->current_x);
}
free(char_mb);
/* If we haven't found it, move to the end of the file. */
if (openfile->current == NULL)
openfile->current = openfile->filebot;
/* If this is not a word character, then it's a separator; else
* if we've already seen a separator, then it's a word start. */
if (!is_word_mbchar(openfile->current->data + openfile->current_x,
allow_punct))
seen_space = TRUE;
else if (seen_space)
break;
}
openfile->placewewant = xplustabs();