diff --git a/src/nano.h b/src/nano.h
index c092d3e1c827a748b43d577308a2c20e1a8aa18c..6c031944adc0918391d34720f50df4c6393a0ae4 100644
--- a/src/nano.h
+++ b/src/nano.h
@@ -163,8 +163,9 @@ typedef enum {
 	CENTERING, FLOWING, STATIONARY
 } update_type;
 
+/* The kinds of undo actions.  ADD...REPLACE must come first. */
 typedef enum {
-	ADD, DEL, BACK, CUT, CUT_TO_EOF, REPLACE,
+	ADD, BACK, DEL, ENTER, JOIN, REPLACE,
 #ifdef ENABLE_WRAPPING
 	SPLIT_BEGIN, SPLIT_END,
 #endif
@@ -172,7 +173,7 @@ typedef enum {
 #ifdef ENABLE_COMMENT
 	COMMENT, UNCOMMENT, PREFLIGHT,
 #endif
-	JOIN, PASTE, INSERT, ENTER, OTHER
+	CUT, CUT_TO_EOF, PASTE, INSERT, OTHER
 } undo_type;
 
 /* Structure types. */
diff --git a/src/text.c b/src/text.c
index ce5e9bffb43563adb12f8b3ee2a324479ed1ecd5..9ef0f86df5e61c53748d6354194f74836c8b8037 100644
--- a/src/text.c
+++ b/src/text.c
@@ -678,7 +678,7 @@ void redo_cut(undo *u)
 void do_undo(void)
 {
 	undo *u = openfile->current_undo;
-	filestruct *f, *t = NULL;
+	filestruct *f = NULL, *t = NULL;
 	filestruct *oldcutbuffer, *oldcutbottom;
 	char *data, *undidmsg = NULL;
 	size_t from_x, to_x;
@@ -688,13 +688,14 @@ void do_undo(void)
 		return;
 	}
 
-	f = fsfromline(u->mark_begin_lineno);
-	if (!f)
-		return;
+	if (u->type <= REPLACE) {
+		f = fsfromline(u->mark_begin_lineno);
+		if (f == NULL)
+			return;
+	}
 
 #ifdef DEBUG
 	fprintf(stderr, "  >> Undoing a type %d...\n", u->type);
-	fprintf(stderr, "  >> Data we're about to undo = \"%s\"\n", f->data);
 #endif
 
 	openfile->current_x = u->begin;
@@ -848,7 +849,7 @@ void do_undo(void)
 /* Redo the last thing(s) we undid. */
 void do_redo(void)
 {
-	filestruct *f, *shoveline;
+	filestruct *f = NULL, *shoveline;
 	char *data, *redidmsg = NULL;
 	undo *u = openfile->undotop;
 
@@ -866,13 +867,14 @@ void do_redo(void)
 		return;
 	}
 
-	f = fsfromline(u->type == INSERT ? 1 : u->mark_begin_lineno);
-	if (!f)
-		return;
+	if (u->type <= REPLACE) {
+		f = fsfromline(u->mark_begin_lineno);
+		if (f == NULL)
+			return;
+	}
 
 #ifdef DEBUG
 	fprintf(stderr, "  >> Redo running for type %d\n", u->type);
-	fprintf(stderr, "  >> Data we're about to redo = \"%s\"\n", f->data);
 #endif
 
 	switch (u->type) {