]> git.wh0rd.org Git - nano.git/commitdiff
Rewriting do_next_word() to use the same, simpler logic as do_prev_word().
authorBenno Schulenberg <bensberg@justemail.net>
Tue, 27 Oct 2015 16:48:24 +0000 (16:48 +0000)
committerBenno Schulenberg <bensberg@justemail.net>
Tue, 27 Oct 2015 16:48:24 +0000 (16:48 +0000)
git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@5373 35c25a1d-7b9e-4130-9fde-d3aeb78583b8

ChangeLog
src/move.c

index 0edbd4ec7ba242b2419443fa3462eb10aa619da5..a92ddb0c89fb8b629db6ff1705f4389799def588 100644 (file)
--- 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
index a462cc376ec5cd16e0cb30dfae5d4094fd1e5fb4..f8d53405fe700ba2793bfc648894457a44f2d4a2 100644 (file)
@@ -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. */