weeding: remove partitioning and related stuff from do_justify()

Replace partitioning with calls to extract_buffer() and ingraft_buffer().

In addition to pasting the unjustified text back into the buffer at
current[current_x], ingraft_buffer() also deals with renumbering and
updating totsize, so do_justify() doesn't need to do those anymore
when unjustifying.
master
David Lawrence Ramsey 2017-02-10 00:46:49 -06:00 committed by Benno Schulenberg
parent 234bd9c9be
commit 29681e0e9f
1 changed files with 6 additions and 17 deletions

View File

@ -2178,7 +2178,6 @@ void do_justify(bool full_justify)
filestruct *edittop_save = openfile->edittop; filestruct *edittop_save = openfile->edittop;
filestruct *current_save = openfile->current; filestruct *current_save = openfile->current;
size_t current_x_save = openfile->current_x; size_t current_x_save = openfile->current_x;
size_t totsize_save = openfile->totsize;
#ifndef NANO_TINY #ifndef NANO_TINY
filestruct *mark_begin_save = openfile->mark_begin; filestruct *mark_begin_save = openfile->mark_begin;
size_t mark_begin_x_save = openfile->mark_begin_x; size_t mark_begin_x_save = openfile->mark_begin_x;
@ -2479,29 +2478,19 @@ void do_justify(bool full_justify)
/* If we actually justified something, then splice the preserved /* If we actually justified something, then splice the preserved
* unjustified text back into the file, */ * unjustified text back into the file, */
if (first_par_line != NULL) { if (first_par_line != NULL) {
/* Partition the filestruct so that it contains only the filestruct *trash = NULL, *dummy = NULL;
* text of the justified paragraph. */
filepart = partition_filestruct(first_par_line, 0,
last_par_line, filebot_inpar ?
strlen(last_par_line->data) : 0);
/* Throw away the justified paragraph, and replace it with /* Throw away the justified paragraph, and replace it with
* the preserved unjustified text. */ * the preserved unjustified text. */
free_filestruct(openfile->fileage); extract_buffer(&trash, &dummy, first_par_line, 0, last_par_line,
openfile->fileage = jusbuffer; filebot_inpar ? strlen(last_par_line->data) : 0);
openfile->filebot = jusbottom; free_filestruct(trash);
ingraft_buffer(jusbuffer);
/* Unpartition the filestruct, to contain the entire text again. */ /* Restore the old position and the mark. */
unpartition_filestruct(&filepart);
/* Renumber, from the beginning of the unjustified part. */
renumber(jusbuffer);
/* Restore the old position, the size, and the mark. */
openfile->edittop = edittop_save; openfile->edittop = edittop_save;
openfile->current = current_save; openfile->current = current_save;
openfile->current_x = current_x_save; openfile->current_x = current_x_save;
openfile->totsize = totsize_save;
#ifndef NANO_TINY #ifndef NANO_TINY
if (openfile->mark_set) { if (openfile->mark_set) {
openfile->mark_begin = mark_begin_save; openfile->mark_begin = mark_begin_save;