2015-12-08 Benno Schulenberg <bensberg@justemail.net>
- * src/nano.c (splice_node): Make this function update 'filebot',
- instead of doing it in four different places.
+ * src/nano.c (splice_node, unlink_node): Let these functions update
+ 'filebot', instead of doing it in four different places each.
2015-12-07 Benno Schulenberg <bensberg@justemail.net>
* src/winio.c (edit_draw): Quit the loop when there is no end match.
openfile->filebot = newnode;
}
-/* Unlink a node from the rest of the filestruct and delete it. */
+/* Disconnect a node from a linked list of filestructs and delete it. */
void unlink_node(filestruct *fileptr)
{
assert(fileptr != NULL);
if (fileptr->next != NULL)
fileptr->next->prev = fileptr->prev;
+ /* Update filebot when removing a node at the end of file. */
+ if (openfile && openfile->filebot == fileptr)
+ openfile->filebot = fileptr->prev;
+
delete_node(fileptr);
}
-/* Delete a node from the filestruct. */
+/* Free the data structures in the given node. */
void delete_node(filestruct *fileptr)
{
assert(fileptr != NULL && fileptr->data != NULL);
openfile->mark_begin_x += openfile->current_x;
}
#endif
- if (openfile->filebot == foo)
- openfile->filebot = openfile->current;
unlink_node(foo);
renumber(openfile->current);
f->data = charealloc(f->data, strlen(f->data) +
strlen(&f->next->data[u->mark_begin_x]) + 1);
strcat(f->data, &f->next->data[u->mark_begin_x]);
- if (openfile->filebot == f->next)
- openfile->filebot = f;
unlink_node(f->next);
goto_line_posx(u->lineno, u->begin);
break;
}
f->data = charealloc(f->data, strlen(f->data) + strlen(u->strdata) + 1);
strcat(f->data, u->strdata);
- if (f->next == openfile->filebot)
- openfile->filebot = f;
unlink_node(f->next);
renumber(f);
goto_line_posx(u->mark_begin_lineno, u->mark_begin_x);
strcat(openfile->current->data, next_line->data +
indent_len);
- /* Don't destroy edittop or filebot! */
+ /* Don't destroy edittop! */
if (next_line == openfile->edittop)
openfile->edittop = openfile->current;
- if (next_line == openfile->filebot)
- openfile->filebot = openfile->current;
#ifndef NANO_TINY
/* Adjust the mark coordinates to compensate for the change