From: Chris Allegretta Date: Mon, 3 Feb 2003 03:22:02 +0000 (+0000) Subject: DB's justify patch X-Git-Tag: v1.1.99pre2~8 X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=cff6e6f60f284e5a7182be9fc49bb471818a5e1d;p=nano.git DB's justify patch git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1412 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- diff --git a/ChangeLog b/ChangeLog index 612c7a8d..c0c5cd35 100644 --- a/ChangeLog +++ b/ChangeLog @@ -25,6 +25,8 @@ CVS Code - of winio.c. New function rcfile.c:nregcomp(). This fixes much of nano's resource hogging behavior in syntax higlighting. (David Benbennick). + - Fix justify failing for certain lines, new function + nano.c:breakable() (David Benbennick). - cut.c: do_cut_text() - Fix incorrect cursor location when cutting long lines diff --git a/nano.c b/nano.c index 8a327d2c..3286284d 100644 --- a/nano.c +++ b/nano.c @@ -2210,6 +2210,21 @@ filestruct *backup_lines(filestruct *first_line, size_t par_len, return first_line; } +/* Is it possible to break line at or before goal? */ +int breakable(const char *line, int goal) +{ + for(; *line != '\0' && goal >= 0; line++) { + if (*line == ' ' || *line == '\t') + return TRUE; + + if (is_cntrl_char(*line) != 0) + goal -= 2; + else + goal -= 1; + } + return FALSE; +} + /* We are trying to break a chunk off line. We find the last space such * that the display length to there is at most goal + 1. If there is * no such space, and force is not 0, then we find the first space. @@ -2512,20 +2527,24 @@ int do_justify(void) null_at(¤t->data, break_pos); current = current->next; } else if (display_len < fill && par_len > 1) { - size_t next_line_len = strlen(current->next->data); + size_t next_line_len; indent_len = quote_len + indent_length(current->next->data + quote_len); - break_pos = break_line(current->next->data + indent_len, - fill - display_len - 1, 0); - if (break_pos == -1) - /* We can't pull a word from the next line up to this one, - * so just go on. */ + /* If we can't pull a word from the next line up to this one, + * just go on. */ + if (!breakable(current->next->data + indent_len, + fill - display_len - 1)) goto continue_loc; /* If we haven't backed up the paragraph, do it now. */ if (first_mod_line == NULL) first_mod_line = backup_lines(current, par_len, quote_len); + + break_pos = break_line(current->next->data + indent_len, + fill - display_len - 1, FALSE); + assert(break_pos != -1); + current->data = (char *)nrealloc(current->data, line_len + break_pos + 2); current->data[line_len] = ' '; @@ -2544,6 +2563,7 @@ int do_justify(void) mark_beginx -= break_pos + 1; } #endif + next_line_len = strlen(current->next->data); if (indent_len + break_pos == next_line_len) { line = current->next; diff --git a/proto.h b/proto.h index 98093623..1ab4f4de 100644 --- a/proto.h +++ b/proto.h @@ -300,6 +300,7 @@ size_t indents_match(const char *a_line, size_t a_indent, const char *b_line, size_t b_indent); filestruct *backup_lines(filestruct *first_line, size_t par_len, size_t quote_len); +int breakable(const char *line, int goal); int break_line(const char *line, int goal, int force); #endif /* !DISABLE_JUSTIFY */ int do_justify(void);