tweaks: simplify the determining of the prefix for justified lines
parent
432a7d7729
commit
45c36f93e5
56
src/text.c
56
src/text.c
|
@ -2223,8 +2223,11 @@ void do_justify(bool full_justify)
|
||||||
while (TRUE) {
|
while (TRUE) {
|
||||||
size_t i;
|
size_t i;
|
||||||
/* Generic loop variable. */
|
/* Generic loop variable. */
|
||||||
filestruct *curr_first_par_line;
|
filestruct *firstline;
|
||||||
/* The first line of the current paragraph. */
|
/* The first line of the current paragraph. */
|
||||||
|
filestruct *sampleline;
|
||||||
|
/* The line from which the indentation is copied -- either
|
||||||
|
* the first and only or the second line of the paragraph. */
|
||||||
size_t quote_len;
|
size_t quote_len;
|
||||||
/* Length of the initial quotation of the current paragraph. */
|
/* Length of the initial quotation of the current paragraph. */
|
||||||
size_t indent_len;
|
size_t indent_len;
|
||||||
|
@ -2234,14 +2237,7 @@ void do_justify(bool full_justify)
|
||||||
ssize_t break_pos;
|
ssize_t break_pos;
|
||||||
/* Where we will break lines. */
|
/* Where we will break lines. */
|
||||||
char *indent_string;
|
char *indent_string;
|
||||||
/* The first indentation that doesn't match the initial
|
/* The indentation that is copied from the sample line. */
|
||||||
* indentation of the current paragraph. This is put at the
|
|
||||||
* beginning of every line broken off the first justified
|
|
||||||
* line of the paragraph. Note that this works because a
|
|
||||||
* paragraph can only contain two indentations at most: the
|
|
||||||
* initial one, and a different one starting on a line after
|
|
||||||
* the first. See the comment at begpar() for more about
|
|
||||||
* when a line is part of a paragraph. */
|
|
||||||
|
|
||||||
/* Find the first line of the paragraph to be justified. That
|
/* Find the first line of the paragraph to be justified. That
|
||||||
* is the start of this paragraph if we're in one, or the start
|
* is the start of this paragraph if we're in one, or the start
|
||||||
|
@ -2283,40 +2279,16 @@ void do_justify(bool full_justify)
|
||||||
first_par_line = openfile->current;
|
first_par_line = openfile->current;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set curr_first_par_line to the first line of the current
|
/* Remember the first line of the current paragraph. */
|
||||||
* paragraph. */
|
firstline = openfile->current;
|
||||||
curr_first_par_line = openfile->current;
|
|
||||||
|
|
||||||
/* Initialize indent_string to a blank string. */
|
/* The sample line is either the only line or the second line. */
|
||||||
indent_string = mallocstrcpy(NULL, "");
|
sampleline = (par_len == 1 ? firstline : firstline->next);
|
||||||
|
|
||||||
/* Find the first indentation in the paragraph that doesn't
|
/* Copy the leading part (quoting + indentation) of the sample line. */
|
||||||
* match the indentation of the first line, and save it in
|
indent_len = quote_len + indent_length(sampleline->data + quote_len);
|
||||||
* indent_string. If all the indentations are the same, save
|
indent_string = mallocstrncpy(NULL, sampleline->data, indent_len + 1);
|
||||||
* the indentation of the first line in indent_string. */
|
indent_string[indent_len] = '\0';
|
||||||
{
|
|
||||||
const filestruct *indent_line = openfile->current;
|
|
||||||
bool past_first_line = FALSE;
|
|
||||||
|
|
||||||
for (i = 0; i < par_len; i++) {
|
|
||||||
indent_len = quote_len +
|
|
||||||
indent_length(indent_line->data + quote_len);
|
|
||||||
|
|
||||||
if (indent_len != strlen(indent_string)) {
|
|
||||||
indent_string = mallocstrncpy(indent_string,
|
|
||||||
indent_line->data, indent_len + 1);
|
|
||||||
indent_string[indent_len] = '\0';
|
|
||||||
|
|
||||||
if (past_first_line)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (indent_line == openfile->current)
|
|
||||||
past_first_line = TRUE;
|
|
||||||
|
|
||||||
indent_line = indent_line->next;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Now tack all the lines of the paragraph together, skipping
|
/* Now tack all the lines of the paragraph together, skipping
|
||||||
* the quoting and indentation on all lines after the first. */
|
* the quoting and indentation on all lines after the first. */
|
||||||
|
@ -2442,7 +2414,7 @@ void do_justify(bool full_justify)
|
||||||
|
|
||||||
/* Renumber the now-justified paragraph, since both refreshing the
|
/* Renumber the now-justified paragraph, since both refreshing the
|
||||||
* edit window and finding a paragraph need correct line numbers. */
|
* edit window and finding a paragraph need correct line numbers. */
|
||||||
renumber(curr_first_par_line);
|
renumber(firstline);
|
||||||
|
|
||||||
/* We've just finished justifying the paragraph. If we're not
|
/* We've just finished justifying the paragraph. If we're not
|
||||||
* justifying the entire file, break out of the loop.
|
* justifying the entire file, break out of the loop.
|
||||||
|
|
Loading…
Reference in New Issue