tweak find_paragraph() and do_justify() to remove the assumption that

the file always ends in a magicline; note that the latter isn't
completely fixed yet


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@3129 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
master
David Lawrence Ramsey 2005-11-09 19:06:01 +00:00
parent 5c33e88b25
commit 2c5d0ecbb3
2 changed files with 46 additions and 25 deletions

View File

@ -41,6 +41,7 @@ CVS code -
always ends in a magicline. Changes to cut_line(), always ends in a magicline. Changes to cut_line(),
do_cut_till_end(), open_buffer(), read_file(), write_file(), do_cut_till_end(), open_buffer(), read_file(), write_file(),
do_last_line(), do_para_end(), backup_lines(), do_last_line(), do_para_end(), backup_lines(),
find_paragraph(), do_justify() (not completely fixed yet),
do_alt_speller(), and do_wordlinechar_count(). (DLR) do_alt_speller(), and do_wordlinechar_count(). (DLR)
- Tweak a few functions to rely on fileage and filebot instead - Tweak a few functions to rely on fileage and filebot instead
of NULL for their checks to detect the top or bottom of the of NULL for their checks to detect the top or bottom of the

View File

@ -383,7 +383,6 @@ bool do_wrap(filestruct *line)
* of the line while trying to find one, we should return without * of the line while trying to find one, we should return without
* wrapping. Note that if autoindent is turned on, we don't break * wrapping. Note that if autoindent is turned on, we don't break
* at the end of it! */ * at the end of it! */
assert(line != NULL && line->data != NULL); assert(line != NULL && line->data != NULL);
/* Save the length of the line. */ /* Save the length of the line. */
@ -1042,6 +1041,8 @@ bool find_paragraph(size_t *const quote, size_t *const par)
/* Number of lines in the paragraph we search for. */ /* Number of lines in the paragraph we search for. */
filestruct *current_save; filestruct *current_save;
/* The line at the beginning of the paragraph we search for. */ /* The line at the beginning of the paragraph we search for. */
size_t current_x_save;
/* The x-coordinate at the end of the paragraph we search for. */
ssize_t current_y_save; ssize_t current_y_save;
/* The y-coordinate at the beginning of the paragraph we search /* The y-coordinate at the beginning of the paragraph we search
* for. */ * for. */
@ -1055,21 +1056,16 @@ bool find_paragraph(size_t *const quote, size_t *const par)
assert(openfile->current != NULL); assert(openfile->current != NULL);
/* Move back to the beginning of the current line. */
openfile->current_x = 0;
openfile->placewewant = 0;
/* Find the first line of the current or next paragraph. First, if /* Find the first line of the current or next paragraph. First, if
* the current line isn't in a paragraph, move forward to the line * the current line isn't in a paragraph, move forward to the line
* after the last line of the next paragraph. If we end up on the * after the last line of the next paragraph, if any. If we end up
* same line, or the line before that isn't in a paragraph, it means * on the same line, or the line before that isn't in a paragraph, it
* that there aren't any paragraphs left, so get out. Otherwise, * means that there aren't any paragraphs left, so get out.
* move back to the last line of the paragraph. If the current line * Otherwise, move back to the last line of the paragraph. If the
* is in a paragraph and it isn't the first line of that paragraph, * current line is in a paragraph and it isn't the first line of
* move back to the first line. */ * that paragraph, move back to the first line. */
if (!inpar(openfile->current)) { if (!inpar(openfile->current)) {
current_save = openfile->current; current_save = openfile->current;
do_para_end(FALSE); do_para_end(FALSE);
if (openfile->current == current_save || if (openfile->current == current_save ||
!inpar(openfile->current->prev)) !inpar(openfile->current->prev))
@ -1082,13 +1078,26 @@ bool find_paragraph(size_t *const quote, size_t *const par)
/* Now current is the first line of the paragraph. Set quote_len to /* Now current is the first line of the paragraph. Set quote_len to
* the quotation length of that line, and set par_len to the number * the quotation length of that line, and set par_len to the number
* of lines in this paragraph. */ * of lines in this paragraph by temporarily moving to the last line
* of it and saving the difference in line numbers. If, after
* moving, we end up on the same line and x-coordinate as before, it
* means that there aren't any paragraphs left, so get out. If we
* end up on the same line with a different x-coordinate from
* before, it means that the line is part of the paragraph. */
quote_len = quote_length(openfile->current->data); quote_len = quote_length(openfile->current->data);
current_save = openfile->current; current_save = openfile->current;
current_x_save = openfile->current_x;
current_y_save = openfile->current_y; current_y_save = openfile->current_y;
do_para_end(FALSE); do_para_end(FALSE);
par_len = openfile->current->lineno - current_save->lineno; par_len = openfile->current->lineno - current_save->lineno;
if (openfile->current == current_save) {
if (openfile->current_x == current_x_save)
return FALSE;
else
par_len++;
}
openfile->current = current_save; openfile->current = current_save;
openfile->current_x = current_x_save;
openfile->current_y = current_y_save; openfile->current_y = current_y_save;
/* Save the values of quote_len and par_len. */ /* Save the values of quote_len and par_len. */
@ -1108,9 +1117,8 @@ void do_justify(bool full_justify)
/* Will be the first line of the justified paragraph. For /* Will be the first line of the justified paragraph. For
* restoring after unjustify. */ * restoring after unjustify. */
filestruct *last_par_line; filestruct *last_par_line;
/* Will be the line containing the newline after the last line /* Will be the line after the last line of the justified
* of the justified paragraph. Also for restoring after * paragraph, if any. Also for restoring after unjustify. */
* unjustify. */
/* We save these variables to be restored if the user /* We save these variables to be restored if the user
* unjustifies. */ * unjustifies. */
@ -1128,6 +1136,11 @@ void do_justify(bool full_justify)
int kbinput; int kbinput;
bool meta_key, func_key, s_or_t, ran_func, finished; bool meta_key, func_key, s_or_t, ran_func, finished;
/* Move to the beginning of the current line, so that justifying at
* the end of the last line of the file will work if that line isn't
* blank. */
openfile->current_x = 0;
/* If we're justifying the entire file, start at the beginning. */ /* If we're justifying the entire file, start at the beginning. */
if (full_justify) if (full_justify)
openfile->current = openfile->fileage; openfile->current = openfile->fileage;
@ -1186,8 +1199,9 @@ void do_justify(bool full_justify)
* to the justify buffer. */ * to the justify buffer. */
if (first_par_line == NULL) if (first_par_line == NULL)
first_par_line = backup_lines(openfile->current, first_par_line = backup_lines(openfile->current,
full_justify ? openfile->filebot->lineno - full_justify ? ((openfile->current ==
openfile->current->lineno : par_len); openfile->filebot) ? 1 : openfile->filebot->lineno -
openfile->current->lineno) : par_len);
/* Initialize indent_string to a blank string. */ /* Initialize indent_string to a blank string. */
indent_string = mallocstrcpy(NULL, ""); indent_string = mallocstrcpy(NULL, "");
@ -1352,18 +1366,24 @@ void do_justify(bool full_justify)
/* Go to the next line. */ /* Go to the next line. */
par_len--; par_len--;
if (openfile->current != openfile->filebot) {
openfile->current_y++; openfile->current_y++;
openfile->current = openfile->current->next; openfile->current = openfile->current->next;
} }
}
/* We're done breaking lines, so we don't need indent_string /* We're done breaking lines, so we don't need indent_string
* anymore. */ * anymore. */
free(indent_string); free(indent_string);
/* Go to the next line, the line after the last line of the /* Go to the next line: the line after the last line of the
* paragraph. */ * paragraph, if any. If there isn't one, move to the end of
* the current line, since that's where the paragraph ends. */
if (openfile->current != openfile->filebot) {
openfile->current_y++; openfile->current_y++;
openfile->current = openfile->current->next; openfile->current = openfile->current->next;
} else
openfile->current_x = strlen(openfile->current->data);
/* We've just justified a paragraph. If we're not justifying the /* We've just justified a paragraph. If we're not justifying the
* entire file, break out of the loop. Otherwise, continue the * entire file, break out of the loop. Otherwise, continue the
@ -1420,7 +1440,7 @@ void do_justify(bool full_justify)
/* Partition the filestruct so that it contains only the /* Partition the filestruct so that it contains only the
* text of the justified paragraph. */ * text of the justified paragraph. */
filepart = partition_filestruct(first_par_line, 0, filepart = partition_filestruct(first_par_line, 0,
last_par_line, 0); last_par_line, strlen(last_par_line->data));
/* Remove the text of the justified paragraph, and /* Remove the text of the justified paragraph, and
* put the text in the justify buffer in its place. */ * put the text in the justify buffer in its place. */