{
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. */