Index: src/text.c =================================================================== --- src/text.c (revision 5245) +++ src/text.c (working copy) @@ -501,6 +501,7 @@ #endif /* !DISABLE_WRAPPING */ case JOIN: undidmsg = _("line join"); + if (ISSET(NO_NEWLINES) || f->next != openfile->filebot) { t = make_new_node(f); t->data = mallocstrcpy(NULL, u->strdata); data = mallocstrncpy(NULL, f->data, u->mark_begin_x + 1); @@ -510,6 +511,7 @@ splice_node(f, t, f->next); if (f == openfile->filebot) openfile->filebot = t; + } goto_line_posx(u->lineno, u->begin); break; case CUT_EOF: @@ -880,6 +882,11 @@ ((current_action == CUT && u->type == CUT && !u->mark_set && keeping_cutbuffer()) || (current_action == ADD && u->type == ADD && u->mark_begin_x == fs->current_x))) return; + /* When trying to delete the final newline, don't add an undo for it. */ + if (openfile->current->data[openfile->current_x] == '\0' && + openfile->current->next == openfile->filebot && + current_action == DEL && !ISSET(NO_NEWLINES)) + return; /* Blow away the old undo stack if we are starting from the middle. */ while (fs->undotop != NULL && fs->undotop != fs->current_undo) {