mirror of git://git.sv.gnu.org/nano.git
DB's justify patch
git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1412 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
This commit is contained in:
parent
ce452fb880
commit
cff6e6f60f
|
@ -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
|
||||
|
|
32
nano.c
32
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;
|
||||
|
||||
|
|
1
proto.h
1
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);
|
||||
|
|
Loading…
Reference in New Issue