tweaks: adapt find_paragraph()/justify_paragraph() for multiple quotes
Instead of passing 'quote_len' to these functions, calculate it directly in them. This will be needed when the justifying of marked text is added. When unmarked text is justified, it is a single paragraph and by definition has a uniform quoting part. But marked text may be a jumble of lines that have different quoting parts.
Этот коммит содержится в:
родитель
0ac04347d5
Коммит
311a7138b2
38
src/text.c
38
src/text.c
@ -1849,10 +1849,9 @@ bool inpar(const filestruct *const line)
|
|||||||
|
|
||||||
/* Determine the beginning, length, and quoting of the first found paragraph.
|
/* Determine the beginning, length, and quoting of the first found paragraph.
|
||||||
* Return TRUE if we found a paragraph, and FALSE otherwise. Furthermore,
|
* Return TRUE if we found a paragraph, and FALSE otherwise. Furthermore,
|
||||||
* return in firstline the first line of the paragraph, in *quotelen the
|
* return in firstline the first line of the paragraph,
|
||||||
* length of the quoting, and in *parlen the length of the paragraph. */
|
* and in *parlen the length of the paragraph. */
|
||||||
bool find_paragraph(filestruct **firstline,
|
bool find_paragraph(filestruct **firstline, size_t *const parlen)
|
||||||
size_t *const quotelen, size_t *const parlen)
|
|
||||||
{
|
{
|
||||||
filestruct *line = *firstline;
|
filestruct *line = *firstline;
|
||||||
/* The line of the current paragraph we're searching in. */
|
/* The line of the current paragraph we're searching in. */
|
||||||
@ -1870,21 +1869,22 @@ bool find_paragraph(filestruct **firstline,
|
|||||||
if (!inpar(line))
|
if (!inpar(line))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
/* We found a paragraph; determine length of quoting and number of lines. */
|
/* We found a paragraph; determine number of lines. */
|
||||||
*quotelen = quote_length((*firstline)->data);
|
|
||||||
*parlen = line->lineno - (*firstline)->lineno + 1;
|
*parlen = line->lineno - (*firstline)->lineno + 1;
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Wrap all lines of the paragraph (that starts at *line, consists of
|
/* Wrap all lines of the paragraph (that starts at *line, and consists of
|
||||||
* par_len lines, and has quote_len bytes of quoting) so they all fit
|
* par_len lines) so they all fit
|
||||||
* within the wrap_at target width. */
|
* within the wrap_at target width. */
|
||||||
void justify_paragraph(filestruct **line, size_t quote_len, size_t par_len)
|
void justify_paragraph(filestruct **line, size_t par_len)
|
||||||
{
|
{
|
||||||
filestruct *sampleline;
|
filestruct *sampleline;
|
||||||
/* The line from which the indentation is copied -- either
|
/* The line from which the indentation is copied -- either
|
||||||
* the first and only or the second line of the paragraph. */
|
* the first and only or the second line of the paragraph. */
|
||||||
|
size_t quote_len;
|
||||||
|
/* Length of the quote part. */
|
||||||
size_t lead_len;
|
size_t lead_len;
|
||||||
/* Length of the quote part plus the indentation part. */
|
/* Length of the quote part plus the indentation part. */
|
||||||
ssize_t break_pos;
|
ssize_t break_pos;
|
||||||
@ -1896,6 +1896,7 @@ void justify_paragraph(filestruct **line, size_t quote_len, size_t par_len)
|
|||||||
sampleline = (par_len == 1 ? *line : (*line)->next);
|
sampleline = (par_len == 1 ? *line : (*line)->next);
|
||||||
|
|
||||||
/* Copy the leading part (quoting + indentation) of the sample line. */
|
/* Copy the leading part (quoting + indentation) of the sample line. */
|
||||||
|
quote_len = quote_length(sampleline->data);
|
||||||
lead_len = quote_len + indent_length(sampleline->data + quote_len);
|
lead_len = quote_len + indent_length(sampleline->data + quote_len);
|
||||||
lead_string = mallocstrncpy(NULL, sampleline->data, lead_len + 1);
|
lead_string = mallocstrncpy(NULL, sampleline->data, lead_len + 1);
|
||||||
lead_string[lead_len] = '\0';
|
lead_string[lead_len] = '\0';
|
||||||
@ -1906,8 +1907,9 @@ void justify_paragraph(filestruct **line, size_t quote_len, size_t par_len)
|
|||||||
filestruct *next_line = (*line)->next;
|
filestruct *next_line = (*line)->next;
|
||||||
size_t line_len = strlen((*line)->data);
|
size_t line_len = strlen((*line)->data);
|
||||||
size_t next_line_len = strlen(next_line->data);
|
size_t next_line_len = strlen(next_line->data);
|
||||||
|
size_t next_quote_len = quote_length(next_line->data);
|
||||||
lead_len = quote_len + indent_length(next_line->data + quote_len);
|
size_t next_lead_len = next_quote_len +
|
||||||
|
indent_length(next_line->data + next_quote_len);
|
||||||
|
|
||||||
/* We're just about to tack the next line onto this one. If
|
/* We're just about to tack the next line onto this one. If
|
||||||
* this line isn't empty, make sure it ends in a space. */
|
* this line isn't empty, make sure it ends in a space. */
|
||||||
@ -1918,8 +1920,8 @@ void justify_paragraph(filestruct **line, size_t quote_len, size_t par_len)
|
|||||||
}
|
}
|
||||||
|
|
||||||
(*line)->data = charealloc((*line)->data,
|
(*line)->data = charealloc((*line)->data,
|
||||||
line_len + next_line_len - lead_len + 1);
|
line_len + next_line_len - next_lead_len + 1);
|
||||||
strcat((*line)->data, next_line->data + lead_len);
|
strcat((*line)->data, next_line->data + next_lead_len);
|
||||||
|
|
||||||
unlink_node(next_line);
|
unlink_node(next_line);
|
||||||
par_len--;
|
par_len--;
|
||||||
@ -1974,8 +1976,6 @@ void justify_paragraph(filestruct **line, size_t quote_len, size_t par_len)
|
|||||||
* full_justify is TRUE. */
|
* full_justify is TRUE. */
|
||||||
void do_justify(bool full_justify)
|
void do_justify(bool full_justify)
|
||||||
{
|
{
|
||||||
size_t quote_len;
|
|
||||||
/* Length of the quote part of the current paragraph. */
|
|
||||||
size_t par_len;
|
size_t par_len;
|
||||||
/* Number of lines in the current paragraph. */
|
/* Number of lines in the current paragraph. */
|
||||||
filestruct *first_par_line;
|
filestruct *first_par_line;
|
||||||
@ -2011,7 +2011,7 @@ void do_justify(bool full_justify)
|
|||||||
/* Find the first line of the paragraph(s) to be justified. If the
|
/* Find the first line of the paragraph(s) to be justified. If the
|
||||||
* search fails, there is nothing to justify, and we will be on the
|
* search fails, there is nothing to justify, and we will be on the
|
||||||
* last line of the file, so put the cursor at the end of it. */
|
* last line of the file, so put the cursor at the end of it. */
|
||||||
if (!find_paragraph(&openfile->current, "e_len, &par_len)) {
|
if (!find_paragraph(&openfile->current, &par_len)) {
|
||||||
openfile->current_x = strlen(openfile->filebot->data);
|
openfile->current_x = strlen(openfile->filebot->data);
|
||||||
refresh_needed = TRUE;
|
refresh_needed = TRUE;
|
||||||
return;
|
return;
|
||||||
@ -2066,12 +2066,12 @@ void do_justify(bool full_justify)
|
|||||||
jusline = cutbuffer;
|
jusline = cutbuffer;
|
||||||
|
|
||||||
/* Justify the current paragraph. */
|
/* Justify the current paragraph. */
|
||||||
justify_paragraph(&jusline, quote_len, par_len);
|
justify_paragraph(&jusline, par_len);
|
||||||
|
|
||||||
/* When justifying the entire buffer, find and justify all paragraphs. */
|
/* When justifying the entire buffer, find and justify all paragraphs. */
|
||||||
if (full_justify) {
|
if (full_justify) {
|
||||||
while (find_paragraph(&jusline, "e_len, &par_len)) {
|
while (find_paragraph(&jusline, &par_len)) {
|
||||||
justify_paragraph(&jusline, quote_len, par_len);
|
justify_paragraph(&jusline, par_len);
|
||||||
|
|
||||||
if (jusline->next == NULL)
|
if (jusline->next == NULL)
|
||||||
break;
|
break;
|
||||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user