From 15540051aca220b21603b2a592ca27326f01c91c Mon Sep 17 00:00:00 2001
From: David Lawrence Ramsey <pooka109@gmail.com>
Date: Mon, 14 Mar 2005 20:06:23 +0000
Subject: [PATCH] when justifying, don't remove a space after a duplicate
 character in punct anymore, as it doesn't really make us more compatible with
 Pico

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@2369 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
---
 ChangeLog  |  8 +++--
 src/nano.c | 88 +++++++++++++++++++-----------------------------------
 2 files changed, 35 insertions(+), 61 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 63e3f35f..62054409 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -176,9 +176,11 @@ CVS code -
 	  duplicating code.  Also overhaul the justify code to make it
 	  leave the right number of spaces at the ends of the lines of a
 	  paragraph, to make it (partially) support multibyte
-	  characters, and to make it simpler.  New functions
-	  do_para_begin_void() and do_para_end_void(); changes to
-	  justify_format(), do_para_begin(), inpar(), do_para_end(),
+	  characters, and to make it simpler.  Also, don't remove a
+	  space after a duplicate character in punct anymore, as it
+	  doesn't really make us more compatible with Pico.  New
+	  functions do_para_begin_void() and do_para_end_void(); changes
+	  to justify_format(), do_para_begin(), inpar(), do_para_end(),
 	  break_line(), do_para_search() (renamed find_paragraph()), and
 	  do_justify(); removal of breakable(). (DLR)
 	- Still more steps toward full wide/multibyte character support.
diff --git a/src/nano.c b/src/nano.c
index 0ac08b5a..df873788 100644
--- a/src/nano.c
+++ b/src/nano.c
@@ -2353,9 +2353,8 @@ size_t indent_length(const char *line)
 
 #ifndef DISABLE_JUSTIFY
 /* justify_format() replaces blanks with spaces and multiple spaces by 1
- * (except it maintains 2 after a non-repeated character in punct
- * followed by a character in brackets, and removes all at the end of
- * the line).
+ * (except it maintains up to 2 after a character in punct optionally
+ * followed by a character in brackets, and removes all from the end).
  *
  * justify_format() might make line->data shorter, and change the actual
  * pointer with null_at().
@@ -2393,82 +2392,54 @@ void justify_format(filestruct *paragraph, size_t skip)
 	    while (*end != '\0' && is_blank_char(*end)) {
 		end++;
 		shift++;
+
 #ifndef NANO_SMALL
+		/* Keep track of the change in the current line. */
 		if (mark_beginbuf == paragraph &&
 			mark_beginx >= end - paragraph->data)
 		    mark_shift++;
 #endif
 	    }
-	/* If this character is punctuation, there are two ways we can
-	 * handle it. */
+	/* If this character is punctuation optionally followed by a
+	 * bracket and then followed by blanks, make sure there are no
+	 * more than two blanks after it, and make sure that the blanks
+	 * are spaces. */
 	} else if (strchr(punct, *end) != NULL) {
 	    *new_end = *end;
 	    new_end++;
 	    end++;
 
-	    /* If this character is punctuation followed by itself and
-	     * optionally followed by a bracket, make sure there is no
-	     * more than one blank after it, and make sure that the
-	     * blank is a space. */
-	    if (*end != '\0' && *end == *(end - 1)) {
+	    if (*end != '\0' && strchr(brackets, *end) != NULL) {
 		*new_end = *end;
 		new_end++;
 		end++;
+	    }
 
-		if (*end != '\0' && strchr(brackets, *end) != NULL) {
-		    *new_end = *end;
-		    new_end++;
-		    end++;
-		}
-
-		if (*end != '\0' && is_blank_char(*end)) {
-		    *new_end = ' ';
-		    new_end++;
-		    end++;
-		}
-
-		while (*end != '\0' && is_blank_char(*end)) {
-		    end++;
-		    shift++;
-#ifndef NANO_SMALL
-		if (mark_beginbuf == paragraph &&
-			mark_beginx >= end - paragraph->data)
-		    mark_shift++;
-#endif
-		}
-	    /* If this character is punctuation optionally followed by a
-	     * bracket and then followed by spaces, make sure there are
-	     * no more than two blanks after it, and make sure that the
-	     * blanks are spaces. */
-	    } else {
-		if (*end != '\0' && strchr(brackets, *end) != NULL) {
-		    *new_end = *end;
-		    new_end++;
-		    end++;
-		}
+	    if (*end != '\0' && is_blank_char(*end)) {
+		*new_end = ' ';
+		new_end++;
+		end++;
+	    }
 
-		if (*end != '\0' && is_blank_char(*end)) {
-		    *new_end = ' ';
-		    new_end++;
-		    end++;
-		}
+	    if (*end != '\0' && is_blank_char(*end)) {
+		*new_end = ' ';
+		new_end++;
+		end++;
+	    }
 
-		if (*end != '\0' && is_blank_char(*end)) {
-		    *new_end = ' ';
-		    new_end++;
-		    end++;
-		}
+	    while (*end != '\0' && is_blank_char(*end)) {
+		end++;
+		shift++;
 
-		while (*end != '\0' && is_blank_char(*end)) {
-		    end++;
-		    shift++;
 #ifndef NANO_SMALL
-		if (mark_beginbuf == paragraph &&
-			mark_beginx >= end - paragraph->data)
-		    mark_shift++;
+	    /* Keep track of the change in the current line. */
+	    if (mark_beginbuf == paragraph &&
+		mark_beginx >= end - paragraph->data)
+		mark_shift++;
 #endif
-		}
 	    }
+	/* If this character is neither blank nor punctuation, leave it
+	 * alone. */
 	} else {
 	    *new_end = *end;
 	    new_end++;
@@ -2480,6 +2451,7 @@ void justify_format(filestruct *paragraph, size_t skip)
 
     *new_end = *end;
 
+    /* Make sure that there are no spaces at the end of the line. */
     while (new_end > new_paragraph_data + skip &&
 	*(new_end - 1) == ' ') {
 	new_end--;
-- 
GitLab