isn't defined, as it's only used then. (DLR)
- text.c:
do_wrap()
- - Rename variable wrapping to prepending, to avoid confusion.
- (DLR)
+ - Rename variable wrapping to prepending, to avoid confusion,
+ and rename the static bool same_line_wrap to prepend_wrap to
+ match. (DLR)
+ - Properly add a new magicline when needed if, in the process of
+ wrapping, we prepend text to the last line of the file. (DLR)
break_line()
- Only include the newline parameter if DISABLE_HELP isn't
defined, as it's only used then. (DLR)
* use with the cancel_command() signal handler. */
#endif
#ifndef DISABLE_WRAPPING
-static bool same_line_wrap = FALSE;
+static bool prepend_wrap = FALSE;
/* Should we prepend wrapped text to the next line? */
#endif
#ifndef DISABLE_JUSTIFY
#ifndef DISABLE_WRAPPING
void wrap_reset(void)
{
- same_line_wrap = FALSE;
+ prepend_wrap = FALSE;
}
/* We wrap the given line. Precondition: we assume the cursor has been
* followed by the text after the wrap point, optionally followed by
* a space (if the text after the wrap point doesn't end in a blank)
* and the text of the next line, if they can fit without
- * wrapping, the next line exists, and the same_line_wrap flag is
+ * wrapping, the next line exists, and the prepend_wrap flag is
* set. */
/* after_break is the text that will be wrapped to the next line. */
assert(strlen(after_break) == after_break_len);
- /* We prepend the wrapped text to the next line, if the
- * same_line_wrap flag is set, there is a next line, and prepending
- * would not make the line too long. */
- if (same_line_wrap && line != openfile->filebot) {
+ /* We prepend the wrapped text to the next line, if the prepend_wrap
+ * flag is set, there is a next line, and prepending would not make
+ * the line too long. */
+ if (prepend_wrap && line != openfile->filebot) {
const char *end = after_break + move_mbleft(after_break,
after_break_len);
free(line->next->data);
line->next->data = new_line;
+
+ /* If the NO_NEWLINES flag isn't set, and text has been added to
+ * the magicline, make a new magicline. */
+ if (!ISSET(NO_NEWLINES) && openfile->filebot->data[0] != '\0')
+ new_magicline();
} else {
/* Otherwise, make a new line and copy the text after where we
* broke this line to the beginning of the new line. */
/* Step 3, clean up. Reposition the cursor and mark, and do some
* other sundry things. */
- /* Set the same_line_wrap flag, so that later wraps of this line
- * will be prepended to the next line. */
- same_line_wrap = TRUE;
+ /* Set the prepend_wrap flag, so that later wraps of this line will
+ * be prepended to the next line. */
+ prepend_wrap = TRUE;
/* Each line knows its line number. We recalculate these if we
* inserted a new line. */
renumber(line);
/* If the cursor was after the break point, we must move it. We
- * also clear the same_line_wrap flag in this case. */
+ * also clear the prepend_wrap flag in this case. */
if (openfile->current_x > wrap_loc) {
- same_line_wrap = FALSE;
+ prepend_wrap = FALSE;
openfile->current = openfile->current->next;
openfile->current_x -= wrap_loc