commit 23595c837615f66c937176b40b32dc6ab54f4b25
parent 669453506cfe01fc482c809b3c9cbc90237cd2e8
Author: Benno Schulenberg <bensberg@justemail.net>
Date: Fri, 20 Jan 2017 19:44:46 +0100
tweaks: differentiate single-regex matches from paired-regex matches
Don't use the 'startmatch' variable when the corresponding match is
not the start of anything but is the entire match by itself.
Diffstat:
1 file changed, 15 insertions(+), 17 deletions(-)
diff --git a/src/winio.c b/src/winio.c
@@ -2358,8 +2358,8 @@ void edit_draw(filestruct *fileptr, const char *converted,
/* The number of characters to paint. */
const char *thetext;
/* The place in converted from where painting starts. */
- regmatch_t startmatch, endmatch;
- /* Match positions of the start and end regexes. */
+ regmatch_t match, startmatch, endmatch;
+ /* Match positions of the full, start and end regexes. */
/* Two notes about regexec(). A return value of zero means
* that there is a match. Also, rm_eo is the first
@@ -2380,35 +2380,33 @@ void edit_draw(filestruct *fileptr, const char *converted,
* REG_NOMATCH, there are no more matches in the
* line. */
if (regexec(varnish->start, &fileptr->data[index], 1,
- &startmatch, (index == 0) ? 0 : REG_NOTBOL) ==
- REG_NOMATCH)
+ &match, (index == 0) ? 0 : REG_NOTBOL) != 0)
break;
/* If the match is of length zero, skip it. */
- if (startmatch.rm_so == startmatch.rm_eo) {
+ if (match.rm_so == match.rm_eo) {
index = move_mbright(fileptr->data,
- index + startmatch.rm_eo);
+ index + match.rm_eo);
continue;
}
/* Translate the match to the beginning of the line. */
- startmatch.rm_so += index;
- startmatch.rm_eo += index;
- index = startmatch.rm_eo;
+ match.rm_so += index;
+ match.rm_eo += index;
+ index = match.rm_eo;
- /* If the matching piece is not visible, skip it. */
- if (startmatch.rm_so >= till_x ||
- startmatch.rm_eo <= from_x)
+ /* If the matching part is not visible, skip it. */
+ if (match.rm_eo <= from_x || match.rm_so >= till_x)
continue;
- start_col = (startmatch.rm_so <= from_x) ?
- 0 : strnlenpt(fileptr->data,
- startmatch.rm_so) - from_col;
+ start_col = (match.rm_so <= from_x) ?
+ 0 : strnlenpt(fileptr->data,
+ match.rm_so) - from_col;
thetext = converted + actual_x(converted, start_col);
paintlen = actual_x(thetext, strnlenpt(fileptr->data,
- startmatch.rm_eo) - from_col - start_col);
+ match.rm_eo) - from_col - start_col);
mvwaddnstr(edit, row, margin + start_col,
thetext, paintlen);
@@ -2430,7 +2428,7 @@ void edit_draw(filestruct *fileptr, const char *converted,
goto tail_of_loop;
} else if (fileptr->multidata[varnish->id] == CBEGINBEFORE) {
regexec(varnish->end, fileptr->data, 1, &endmatch, 0);
- /* If the coloured part is scrolled off, skip it. */
+ /* If the part to be coloured is not visible, skip it. */
if (endmatch.rm_eo <= from_x)
goto tail_of_loop;
paintlen = actual_x(converted, strnlenpt(fileptr->data,