From 3264d0c5be4d785b87e8f9f41939ee395541732b Mon Sep 17 00:00:00 2001
From: Benno Schulenberg <bensberg@justemail.net>
Date: Wed, 12 Oct 2016 19:59:26 +0200
Subject: [PATCH] tweaks: move a variable that doesn't need to be global

---
 src/global.c |  7 -------
 src/proto.h  |  3 ---
 src/text.c   | 27 +++++++++++++--------------
 3 files changed, 13 insertions(+), 24 deletions(-)

diff --git a/src/global.c b/src/global.c
index 029b68be..eab922ba 100644
--- a/src/global.c
+++ b/src/global.c
@@ -90,10 +90,6 @@ filestruct *cutbuffer = NULL;
 	/* The buffer where we store cut text. */
 filestruct *cutbottom = NULL;
 	/* The last line in the cutbuffer. */
-#ifndef DISABLE_JUSTIFY
-filestruct *jusbuffer = NULL;
-	/* The buffer where we store unjustified text. */
-#endif
 partition *filepart = NULL;
 	/* The "partition" where we store a portion of the current file. */
 openfilestruct *openfile = NULL;
@@ -1691,9 +1687,6 @@ void thanks_for_all_the_fish(void)
     free(alt_speller);
 #endif
     free_filestruct(cutbuffer);
-#ifndef DISABLE_JUSTIFY
-    free_filestruct(jusbuffer);
-#endif
     /* Free the memory associated with each open file buffer. */
     while (openfile != openfile->next) {
 	openfile = openfile->next;
diff --git a/src/proto.h b/src/proto.h
index 553418bc..e5588e99 100644
--- a/src/proto.h
+++ b/src/proto.h
@@ -73,9 +73,6 @@ extern int maxrows;
 
 extern filestruct *cutbuffer;
 extern filestruct *cutbottom;
-#ifndef DISABLE_JUSTIFY
-extern filestruct *jusbuffer;
-#endif
 extern partition *filepart;
 extern openfilestruct *openfile;
 
diff --git a/src/text.c b/src/text.c
index 0fd29ff7..cd63cf75 100644
--- a/src/text.c
+++ b/src/text.c
@@ -42,8 +42,10 @@ static bool prepend_wrap = FALSE;
 	/* Should we prepend wrapped text to the next line? */
 #endif
 #ifndef DISABLE_JUSTIFY
+static filestruct *jusbuffer = NULL;
+	/* The buffer where we store unjustified text. */
 static filestruct *jusbottom = NULL;
-	/* Pointer to the end of the justify buffer. */
+	/* A pointer to the end of the buffer with unjustified text. */
 #endif
 
 #ifndef NANO_TINY
@@ -2513,8 +2515,8 @@ void do_justify(bool full_justify)
 			|| func == do_undo
 #endif
 		) {
-	/* Splice the justify buffer back into the file, but only if we
-	 * actually justified something. */
+	/* If we actually justified something, then splice the preserved
+	 * unjustified text back into the file, */
 	if (first_par_line != NULL) {
 	    /* Partition the filestruct so that it contains only the
 	     * text of the justified paragraph. */
@@ -2522,24 +2524,19 @@ void do_justify(bool full_justify)
 				last_par_line, filebot_inpar ?
 				strlen(last_par_line->data) : 0);
 
-	    /* Remove the text of the justified paragraph, and
-	     * replace it with the text in the justify buffer. */
+	    /* Throw away the justified paragraph, and replace it with
+	     * the preserved unjustified text. */
 	    free_filestruct(openfile->fileage);
 	    openfile->fileage = jusbuffer;
 	    openfile->filebot = jusbottom;
 
-	    /* Unpartition the filestruct so that it contains all the
-	     * text again.  Note that the justified paragraph has been
-	     * replaced with the unjustified paragraph. */
+	    /* Unpartition the filestruct, to contain the entire text again. */
 	    unpartition_filestruct(&filepart);
 
 	    /* Renumber, from the beginning of the unjustified part. */
 	    renumber(jusbuffer);
 
-	    /* Mark the justify buffer as empty, as it's been swallowed. */
-	    jusbuffer = NULL;
-
-	    /* Restore the justify we just did (ungrateful user!). */
+	    /* Restore the old position, the size, and the mark. */
 	    openfile->edittop = edittop_save;
 	    openfile->current = current_save;
 	    openfile->current_x = current_x_save;
@@ -2569,11 +2566,13 @@ void do_justify(bool full_justify)
 	discard_until(NULL, openfile);
 	openfile->current_undo = NULL;
 #endif
-	/* Blow away the text in the justify buffer. */
+	/* Blow away the unjustified text. */
 	free_filestruct(jusbuffer);
-	jusbuffer = NULL;
     }
 
+    /* Mark the buffer for unjustified text as empty. */
+    jusbuffer = NULL;
+
     blank_statusbar();
 
     /* Display the shortcut list with UnCut. */
-- 
GitLab