commit 17b46f04dadecbdb990b714549053b6868cb86ec
parent b4103321e66533467346e2c9aa6d7fe51bafc143
Author: Benno Schulenberg <bensberg@justemail.net>
Date: Tue, 27 Oct 2015 16:48:24 +0000
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
Diffstat:
M | ChangeLog | | | 4 | ++++ |
M | src/move.c | | | 82 | +++++++++++++++++++++---------------------------------------------------------- |
2 files changed, 26 insertions(+), 60 deletions(-)
diff --git a/ChangeLog b/ChangeLog
@@ -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
diff --git a/src/move.c b/src/move.c
@@ -223,75 +223,37 @@ 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))
- 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))
+ /* 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 (openfile->current->data[openfile->current_x] == '\0')
- end_line = TRUE;
- else
- openfile->current_x += char_mb_len;
+ 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);
}
- /* If we've found it, stop moving forward to the beginnings of
- * subsequent lines. */
- if (!end_line)
+ /* 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;
-
- if (openfile->current != openfile->filebot) {
- end_line = FALSE;
- openfile->current_x = 0;
- }
}
- free(char_mb);
-
- /* If we haven't found it, move to the end of the file. */
- if (openfile->current == NULL)
- openfile->current = openfile->filebot;
-
openfile->placewewant = xplustabs();
/* If allow_update is TRUE, update the screen. */