Eliding a variable, and tweaking some comments.

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@5454 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
master
Benno Schulenberg 2015-11-29 14:15:16 +00:00
parent 98f2f852dd
commit 0129299dc9
2 changed files with 25 additions and 27 deletions

View File

@ -9,6 +9,7 @@
* src/winio.c (edit_draw): Use the main cache-allocation routine. * src/winio.c (edit_draw): Use the main cache-allocation routine.
* src/winio.c (edit_draw): Delete two redundant conditions, and move * src/winio.c (edit_draw): Delete two redundant conditions, and move
the least frequent case to the end. the least frequent case to the end.
* src/winio.c (edit_draw): Elide a variable, tweak some comments.
2015-11-28 Benno Schulenberg <bensberg@justemail.net> 2015-11-28 Benno Schulenberg <bensberg@justemail.net>
* src/nano.c (main): Allow the user full control over the values of * src/nano.c (main): Allow the user full control over the values of

View File

@ -2550,32 +2550,21 @@ void edit_draw(filestruct *fileptr, const char *converted, int
} }
k = startmatch.rm_eo; k = startmatch.rm_eo;
} }
} else { } else { /* This is a multiline expression. */
/* This is a multi-line regex. There are two steps.
* First, we have to see if the beginning of the line is
* colored by a start on an earlier line, and an end on
* this line or later.
*
* We find the first line before fileptr matching the
* start. If every match on that line is followed by an
* end, then go to step two. Otherwise, find the next
* line after start_line matching the end. If that line
* is not before fileptr, then paint the beginning of
* this line. */
const filestruct *start_line = fileptr->prev; const filestruct *start_line = fileptr->prev;
/* The first line before fileptr matching start. */ /* The first line before fileptr that matches 'start'. */
regoff_t start_col; regoff_t start_col;
/* Where it starts in that line. */ /* Where the match starts in that line. */
const filestruct *end_line; const filestruct *end_line;
short md = fileptr->multidata[tmpcolor->id]; /* The line that matches 'end'. */
/* First see if the multidata was maybe calculated earlier. */ /* First see if the multidata was maybe already calculated. */
if (md == CNONE) if (fileptr->multidata[tmpcolor->id] == CNONE)
goto end_of_loop; goto end_of_loop;
else if (md == CWHOLELINE) { else if (fileptr->multidata[tmpcolor->id] == CWHOLELINE) {
mvwaddnstr(edit, line, 0, converted, -1); mvwaddnstr(edit, line, 0, converted, -1);
goto end_of_loop; goto end_of_loop;
} else if (md == CBEGINBEFORE) { } else if (fileptr->multidata[tmpcolor->id] == CBEGINBEFORE) {
regexec(tmpcolor->end, fileptr->data, 1, &endmatch, 0); regexec(tmpcolor->end, fileptr->data, 1, &endmatch, 0);
/* If the coloured part is scrolled off, skip it. */ /* If the coloured part is scrolled off, skip it. */
if (endmatch.rm_eo <= startpos) if (endmatch.rm_eo <= startpos)
@ -2584,22 +2573,30 @@ void edit_draw(filestruct *fileptr, const char *converted, int
endmatch.rm_eo) - start); endmatch.rm_eo) - start);
mvwaddnstr(edit, line, 0, converted, paintlen); mvwaddnstr(edit, line, 0, converted, paintlen);
goto end_of_loop; goto end_of_loop;
} if (md == -1) } if (fileptr->multidata[tmpcolor->id] == -1)
/* Assume this until proven otherwise below. */ /* Assume this until proven otherwise below. */
fileptr->multidata[tmpcolor->id] = CNONE; fileptr->multidata[tmpcolor->id] = CNONE;
/* There is no precalculated multidata, so find it out now.
* First check if the beginning of the line is colored by a
* start on an earlier line, and an end on this line or later.
*
* So: find the first line before fileptr matching the start.
* If every match on that line is followed by an end, then go
* to step two. Otherwise, find a line after start_line that
* matches the end. If that line is not before fileptr, then
* paint the beginning of this line. */
while (start_line != NULL && regexec(tmpcolor->start, while (start_line != NULL && regexec(tmpcolor->start,
start_line->data, 1, &startmatch, 0) == start_line->data, 1, &startmatch, 0) == REG_NOMATCH) {
REG_NOMATCH) { /* There is no start; but if there is an end on this line,
/* If there is an end on this line, there is no need * there is no need to look for starts on earlier lines. */
* to look for starts on earlier lines. */ if (regexec(tmpcolor->end, start_line->data, 0, NULL, 0) == 0)
if (regexec(tmpcolor->end, start_line->data, 0,
NULL, 0) == 0)
goto step_two; goto step_two;
start_line = start_line->prev; start_line = start_line->prev;
} }
/* If the found start has been qualified as an end earlier, /* If a found start has been qualified as an end earlier,
* believe it and skip to the next step. */ * believe it and skip to the next step. */
if (start_line != NULL && start_line->multidata != NULL && if (start_line != NULL && start_line->multidata != NULL &&
(start_line->multidata[tmpcolor->id] == CBEGINBEFORE || (start_line->multidata[tmpcolor->id] == CBEGINBEFORE ||