General - Added separate regex variable (color_regex and colormatches) so that color syntax and regex search/replace can coexist
git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1140 35c25a1d-7b9e-4130-9fde-d3aeb78583b8master
parent
b23d14460e
commit
3533a348fc
|
@ -5,6 +5,8 @@ CVS code -
|
||||||
- New "External Command" code, originally by Dwayne Rightler.
|
- New "External Command" code, originally by Dwayne Rightler.
|
||||||
New function files.c:open_pipe(), changes to do_insertfile(),
|
New function files.c:open_pipe(), changes to do_insertfile(),
|
||||||
new list extcmd_list, cmd is ^X after ^R by default.
|
new list extcmd_list, cmd is ^X after ^R by default.
|
||||||
|
- Added separate regex variable (color_regex and colormatches)
|
||||||
|
so that color syntax and regex search/replace can coexist.
|
||||||
- files.c:
|
- files.c:
|
||||||
check_writable_directory()
|
check_writable_directory()
|
||||||
- Stat full_path, not path (Steven Kneizys).
|
- Stat full_path, not path (Steven Kneizys).
|
||||||
|
|
5
global.c
5
global.c
|
@ -123,6 +123,11 @@ toggle *toggles = NULL;
|
||||||
regex_t search_regexp; /* Global to store compiled search regexp */
|
regex_t search_regexp; /* Global to store compiled search regexp */
|
||||||
regmatch_t regmatches[10]; /* Match positions for parenthetical
|
regmatch_t regmatches[10]; /* Match positions for parenthetical
|
||||||
subexpressions, max of 10 */
|
subexpressions, max of 10 */
|
||||||
|
#ifdef ENABLE_COLOR
|
||||||
|
regex_t color_regexp; /* Global to store compiled search regexp */
|
||||||
|
regmatch_t colormatches; /* Match positions for parenthetical */
|
||||||
|
#endif /* ENABLE_COLOR */
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int length_of_list(shortcut *s)
|
int length_of_list(shortcut *s)
|
||||||
|
|
5
proto.h
5
proto.h
|
@ -83,6 +83,11 @@ extern shortcut *currshortcut;
|
||||||
extern int use_regexp, regexp_compiled;
|
extern int use_regexp, regexp_compiled;
|
||||||
extern regex_t search_regexp;
|
extern regex_t search_regexp;
|
||||||
extern regmatch_t regmatches[10];
|
extern regmatch_t regmatches[10];
|
||||||
|
|
||||||
|
#ifdef ENABLE_COLOR
|
||||||
|
extern regex_t color_regexp;
|
||||||
|
extern regmatch_t colormatches[1];
|
||||||
|
#endif /* HJAVE_COLOR */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern toggle *toggles;
|
extern toggle *toggles;
|
||||||
|
|
48
winio.c
48
winio.c
|
@ -798,32 +798,32 @@ void edit_add(filestruct * fileptr, int yval, int start, int virt_cur_x,
|
||||||
|
|
||||||
/* First, highlight all single-line regexes */
|
/* First, highlight all single-line regexes */
|
||||||
k = start;
|
k = start;
|
||||||
regcomp(&search_regexp, tmpcolor->start, 0);
|
regcomp(&color_regexp, tmpcolor->start, 0);
|
||||||
while (!regexec(&search_regexp, &fileptr->data[k], 1,
|
while (!regexec(&color_regexp, &fileptr->data[k], 1,
|
||||||
regmatches, 0)) {
|
colormatches, 0)) {
|
||||||
|
|
||||||
if (regmatches[0].rm_eo - regmatches[0].rm_so < 1) {
|
if (colormatches[0].rm_eo - colormatches[0].rm_so < 1) {
|
||||||
statusbar("Refusing 0 length regex match");
|
statusbar("Refusing 0 length regex match");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
fprintf(stderr, "Match! (%d chars) \"%s\"\n",
|
fprintf(stderr, "Match! (%d chars) \"%s\"\n",
|
||||||
regmatches[0].rm_eo - regmatches[0].rm_so,
|
colormatches[0].rm_eo - colormatches[0].rm_so,
|
||||||
&fileptr->data[k + regmatches[0].rm_so]);
|
&fileptr->data[k + colormatches[0].rm_so]);
|
||||||
#endif
|
#endif
|
||||||
if (regmatches[0].rm_so < COLS - 1) {
|
if (colormatches[0].rm_so < COLS - 1) {
|
||||||
if (tmpcolor->bright)
|
if (tmpcolor->bright)
|
||||||
wattron(edit, A_BOLD);
|
wattron(edit, A_BOLD);
|
||||||
wattron(edit, COLOR_PAIR(tmpcolor->pairnum));
|
wattron(edit, COLOR_PAIR(tmpcolor->pairnum));
|
||||||
|
|
||||||
if (regmatches[0].rm_eo + k <= COLS)
|
if (colormatches[0].rm_eo + k <= COLS)
|
||||||
paintlen =
|
paintlen =
|
||||||
regmatches[0].rm_eo - regmatches[0].rm_so;
|
colormatches[0].rm_eo - colormatches[0].rm_so;
|
||||||
else
|
else
|
||||||
paintlen = COLS - k - regmatches[0].rm_so - 1;
|
paintlen = COLS - k - colormatches[0].rm_so - 1;
|
||||||
|
|
||||||
mvwaddnstr(edit, yval, regmatches[0].rm_so + k,
|
mvwaddnstr(edit, yval, colormatches[0].rm_so + k,
|
||||||
&fileptr->data[k + regmatches[0].rm_so],
|
&fileptr->data[k + colormatches[0].rm_so],
|
||||||
paintlen);
|
paintlen);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -832,7 +832,7 @@ void edit_add(filestruct * fileptr, int yval, int start, int virt_cur_x,
|
||||||
wattroff(edit, A_BOLD);
|
wattroff(edit, A_BOLD);
|
||||||
wattroff(edit, COLOR_PAIR(tmpcolor->pairnum));
|
wattroff(edit, COLOR_PAIR(tmpcolor->pairnum));
|
||||||
|
|
||||||
k += regmatches[0].rm_eo;
|
k += colormatches[0].rm_eo;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -845,22 +845,22 @@ void edit_add(filestruct * fileptr, int yval, int start, int virt_cur_x,
|
||||||
|
|
||||||
s = fileptr;
|
s = fileptr;
|
||||||
while (s != NULL) {
|
while (s != NULL) {
|
||||||
regcomp(&search_regexp, tmpcolor->start, 0);
|
regcomp(&color_regexp, tmpcolor->start, 0);
|
||||||
if (!regexec
|
if (!regexec
|
||||||
(&search_regexp, s->data, 1, regmatches, 0))
|
(&color_regexp, s->data, 1, colormatches, 0))
|
||||||
break;
|
break;
|
||||||
s = s->prev;
|
s = s->prev;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (s != NULL) {
|
if (s != NULL) {
|
||||||
/* We found a start, mark it */
|
/* We found a start, mark it */
|
||||||
smatch = regmatches[0].rm_so;
|
smatch = colormatches[0].rm_so;
|
||||||
|
|
||||||
e = s;
|
e = s;
|
||||||
while (e != NULL && e != fileptr) {
|
while (e != NULL && e != fileptr) {
|
||||||
regcomp(&search_regexp, tmpcolor->end, 0);
|
regcomp(&color_regexp, tmpcolor->end, 0);
|
||||||
if (!regexec
|
if (!regexec
|
||||||
(&search_regexp, e->data, 1, regmatches, 0))
|
(&color_regexp, e->data, 1, colormatches, 0))
|
||||||
break;
|
break;
|
||||||
e = e->next;
|
e = e->next;
|
||||||
}
|
}
|
||||||
|
@ -869,9 +869,9 @@ void edit_add(filestruct * fileptr, int yval, int start, int virt_cur_x,
|
||||||
continue; /* There's an end before us */
|
continue; /* There's an end before us */
|
||||||
else { /* Keep looking for an end */
|
else { /* Keep looking for an end */
|
||||||
while (e != NULL) {
|
while (e != NULL) {
|
||||||
regcomp(&search_regexp, tmpcolor->end, 0);
|
regcomp(&color_regexp, tmpcolor->end, 0);
|
||||||
if (!regexec
|
if (!regexec
|
||||||
(&search_regexp, e->data, 1, regmatches,
|
(&color_regexp, e->data, 1, colormatches,
|
||||||
0))
|
0))
|
||||||
break;
|
break;
|
||||||
e = e->next;
|
e = e->next;
|
||||||
|
@ -880,13 +880,13 @@ void edit_add(filestruct * fileptr, int yval, int start, int virt_cur_x,
|
||||||
if (e == NULL)
|
if (e == NULL)
|
||||||
continue; /* There's no start before the end :) */
|
continue; /* There's no start before the end :) */
|
||||||
else { /* Okay, we found an end, mark it! */
|
else { /* Okay, we found an end, mark it! */
|
||||||
ematch = regmatches[0].rm_eo;
|
ematch = colormatches[0].rm_eo;
|
||||||
|
|
||||||
while (e != NULL) {
|
while (e != NULL) {
|
||||||
regcomp(&search_regexp, tmpcolor->end, 0);
|
regcomp(&color_regexp, tmpcolor->end, 0);
|
||||||
if (!regexec
|
if (!regexec
|
||||||
(&search_regexp, e->data, 1,
|
(&color_regexp, e->data, 1,
|
||||||
regmatches, 0))
|
colormatches, 0))
|
||||||
break;
|
break;
|
||||||
e = e->next;
|
e = e->next;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue