- Added syntax command to .nanorc file, to allow multiple syntaxes. New function color.c:update_color(), calls in various files.c places, syntaxtype struct, global variables syntaxes, syntaxfile_regexp and synfilematches
git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1197 35c25a1d-7b9e-4130-9fde-d3aeb78583b8master
parent
42c6405572
commit
b6c5dc29ef
|
@ -18,6 +18,10 @@ CVS code -
|
||||||
- More cleanups with DISABLE flags, better free_shortcutage and
|
- More cleanups with DISABLE flags, better free_shortcutage and
|
||||||
free_toggle, and get rid of unnecessary variable decls with
|
free_toggle, and get rid of unnecessary variable decls with
|
||||||
NANO_SMALL in shortcut_init() by David Benbennick.
|
NANO_SMALL in shortcut_init() by David Benbennick.
|
||||||
|
- Added "syntax" command to .nanorc file, to allow multiple
|
||||||
|
syntaxes. New function color.c:update_color(), calls in various
|
||||||
|
files.c places, syntaxtype struct, global variables syntaxes,
|
||||||
|
syntaxfile_regexp and synfilematches.
|
||||||
- configure.ac:
|
- configure.ac:
|
||||||
- Define NDEBUG to silence asserts (David Benbennick).
|
- Define NDEBUG to silence asserts (David Benbennick).
|
||||||
- files.c:
|
- files.c:
|
||||||
|
|
20
color.c
20
color.c
|
@ -177,5 +177,25 @@ int do_colorinit(void)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Update the color information based on the current filename */
|
||||||
|
void update_color(void)
|
||||||
|
{
|
||||||
|
syntaxtype *tmpsyntax;
|
||||||
|
|
||||||
|
colorstrings = NULL;
|
||||||
|
for (tmpsyntax = syntaxes; tmpsyntax != NULL; tmpsyntax = tmpsyntax->next) {
|
||||||
|
exttype *e;
|
||||||
|
for (e = tmpsyntax->extensions; e != NULL; e = e->next) {
|
||||||
|
regcomp(&syntaxfile_regexp, e->val, 0);
|
||||||
|
|
||||||
|
/* Set colorstrings if we matched the extension regex */
|
||||||
|
if (!regexec(&syntaxfile_regexp, filename, 1, synfilematches, 0))
|
||||||
|
colorstrings = tmpsyntax->color;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
do_colorinit();
|
||||||
|
edit_refresh();
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* ENABLE_COLOR */
|
#endif /* ENABLE_COLOR */
|
||||||
|
|
||||||
|
|
13
files.c
13
files.c
|
@ -61,6 +61,10 @@ void load_file(int quiet)
|
||||||
add_open_file(quiet);
|
add_open_file(quiet);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef ENABLE_COLOR
|
||||||
|
update_color();
|
||||||
|
#endif
|
||||||
|
|
||||||
wmove(edit, current_y, current_x);
|
wmove(edit, current_y, current_x);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -487,6 +491,10 @@ int do_insertfile(int loading_file)
|
||||||
else
|
else
|
||||||
edit_refresh();
|
edit_refresh();
|
||||||
|
|
||||||
|
#ifdef ENABLE_COLOR
|
||||||
|
update_color();
|
||||||
|
#endif
|
||||||
|
|
||||||
UNSET(KEEP_CUTBUFFER);
|
UNSET(KEEP_CUTBUFFER);
|
||||||
display_main_list();
|
display_main_list();
|
||||||
return i;
|
return i;
|
||||||
|
@ -612,6 +620,7 @@ int open_file_change_name(void)
|
||||||
*/
|
*/
|
||||||
int load_open_file(void)
|
int load_open_file(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (!open_files)
|
if (!open_files)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
|
@ -650,6 +659,10 @@ int load_open_file(void)
|
||||||
if (ISSET(CONSTUPDATE))
|
if (ISSET(CONSTUPDATE))
|
||||||
do_cursorpos(0);
|
do_cursorpos(0);
|
||||||
|
|
||||||
|
#ifdef ENABLE_COLOR
|
||||||
|
update_color();
|
||||||
|
#endif
|
||||||
|
|
||||||
/* now we're done */
|
/* now we're done */
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
4
global.c
4
global.c
|
@ -110,6 +110,7 @@ shortcut *browser_list = NULL;
|
||||||
#ifdef ENABLE_COLOR
|
#ifdef ENABLE_COLOR
|
||||||
colorstruct colors[NUM_NCOLORS];
|
colorstruct colors[NUM_NCOLORS];
|
||||||
colortype *colorstrings = NULL;
|
colortype *colorstrings = NULL;
|
||||||
|
syntaxtype *syntaxes = NULL;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !defined(DISABLE_BROWSER) || !defined(DISABLE_MOUSE) || !defined (DISABLE_HELP)
|
#if !defined(DISABLE_BROWSER) || !defined(DISABLE_MOUSE) || !defined (DISABLE_HELP)
|
||||||
|
@ -129,6 +130,9 @@ regmatch_t regmatches[10]; /* Match positions for parenthetical
|
||||||
#ifdef ENABLE_COLOR
|
#ifdef ENABLE_COLOR
|
||||||
regex_t color_regexp; /* Global to store compiled search regexp */
|
regex_t color_regexp; /* Global to store compiled search regexp */
|
||||||
regmatch_t colormatches[1]; /* Match positions for parenthetical */
|
regmatch_t colormatches[1]; /* Match positions for parenthetical */
|
||||||
|
|
||||||
|
regex_t syntaxfile_regexp; /* Global to store compiled search regexp */
|
||||||
|
regmatch_t synfilematches[1]; /* Match positions for parenthetical */
|
||||||
#endif /* ENABLE_COLOR */
|
#endif /* ENABLE_COLOR */
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
12
nano.h
12
nano.h
|
@ -137,6 +137,18 @@ typedef struct colortype {
|
||||||
struct colortype *next;
|
struct colortype *next;
|
||||||
} colortype;
|
} colortype;
|
||||||
|
|
||||||
|
typedef struct exttype {
|
||||||
|
char *val;
|
||||||
|
struct exttype *next;
|
||||||
|
} exttype;
|
||||||
|
|
||||||
|
typedef struct syntaxtype {
|
||||||
|
char *desc; /* Name of this syntax type */
|
||||||
|
struct exttype *extensions; /* List of extensions that this applies to */
|
||||||
|
colortype *color; /* color struct for this syntax */
|
||||||
|
struct syntaxtype *next;
|
||||||
|
} syntaxtype;
|
||||||
|
|
||||||
#endif /* ENABLE_COLOR */
|
#endif /* ENABLE_COLOR */
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -73,7 +73,9 @@
|
||||||
|
|
||||||
#
|
#
|
||||||
# Color setup
|
# Color setup
|
||||||
# Format: color foreground,background "regex" ["regex"...]
|
# Format:
|
||||||
|
# syntax "short description" ["filename regex" ...]
|
||||||
|
# color foreground,background "regex" ["regex"...]
|
||||||
#
|
#
|
||||||
# Legal colors are: white, black, red, blue, green, yellow, purple, cyan
|
# Legal colors are: white, black, red, blue, green, yellow, purple, cyan
|
||||||
# You may use the prefix "bright" to mean a stronger color highlight
|
# You may use the prefix "bright" to mean a stronger color highlight
|
||||||
|
@ -84,6 +86,7 @@
|
||||||
# color will use a transparent color. If you don't want this, be sure
|
# color will use a transparent color. If you don't want this, be sure
|
||||||
# to set the background color to black or white.
|
# to set the background color to black or white.
|
||||||
#
|
#
|
||||||
|
#syntax "c-file" ".*\.c" ".*\.h"
|
||||||
#color brightred "float " "char " "int " "void " "NULL" "[A-Z_]\{2,\}"
|
#color brightred "float " "char " "int " "void " "NULL" "[A-Z_]\{2,\}"
|
||||||
#color brightred "static" "const" "[\ ]struct" "^struct" "if " "while[\ \n\(]"
|
#color brightred "static" "const" "[\ ]struct" "^struct" "if " "while[\ \n\(]"
|
||||||
#color brightred "do[\ \n\(]" "else[\ \n]" "case " "switch " "break;"
|
#color brightred "do[\ \n\(]" "else[\ \n]" "case " "switch " "break;"
|
||||||
|
|
5
proto.h
5
proto.h
|
@ -66,6 +66,7 @@ extern openfilestruct *open_files;
|
||||||
|
|
||||||
#ifdef ENABLE_COLOR
|
#ifdef ENABLE_COLOR
|
||||||
extern colortype *colorstrings;
|
extern colortype *colorstrings;
|
||||||
|
extern syntaxtype *syntaxes;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern shortcut *shortcut_list;
|
extern shortcut *shortcut_list;
|
||||||
|
@ -90,6 +91,9 @@ extern regmatch_t regmatches[10];
|
||||||
#ifdef ENABLE_COLOR
|
#ifdef ENABLE_COLOR
|
||||||
extern regex_t color_regexp;
|
extern regex_t color_regexp;
|
||||||
extern regmatch_t colormatches[1];
|
extern regmatch_t colormatches[1];
|
||||||
|
|
||||||
|
extern regex_t syntaxfile_regexp;
|
||||||
|
extern regmatch_t synfilematches[1];
|
||||||
#endif /* ENABLE_COLOR */
|
#endif /* ENABLE_COLOR */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -279,6 +283,7 @@ char *do_browse_from(char *inpath);
|
||||||
int do_colorinit(void);
|
int do_colorinit(void);
|
||||||
void color_on(WINDOW *win, int whatever);
|
void color_on(WINDOW *win, int whatever);
|
||||||
void color_off(WINDOW *win, int whatever);
|
void color_off(WINDOW *win, int whatever);
|
||||||
|
void update_color(void);
|
||||||
|
|
||||||
extern colorstruct colors[NUM_NCOLORS];
|
extern colorstruct colors[NUM_NCOLORS];
|
||||||
#endif /* ENABLE_COLOR */
|
#endif /* ENABLE_COLOR */
|
||||||
|
|
133
rcfile.c
133
rcfile.c
|
@ -183,6 +183,93 @@ int colortoint(char *colorname, int *bright)
|
||||||
|
|
||||||
|
|
||||||
#ifdef ENABLE_COLOR
|
#ifdef ENABLE_COLOR
|
||||||
|
void parse_syntax(FILE * rcstream, char *buf, char *ptr)
|
||||||
|
{
|
||||||
|
syntaxtype *tmpsyntax = NULL;
|
||||||
|
char *fileregptr = NULL, *nameptr = NULL;
|
||||||
|
exttype *exttmp = NULL;
|
||||||
|
|
||||||
|
while (*ptr == ' ')
|
||||||
|
ptr++;
|
||||||
|
|
||||||
|
if (*ptr == '\n' || *ptr == '\0')
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (*ptr != '"') {
|
||||||
|
rcfile_error(_("regex strings must begin and end with a \" character\n"));
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
ptr++;
|
||||||
|
|
||||||
|
nameptr = ptr;
|
||||||
|
ptr = parse_next_regex(ptr);
|
||||||
|
|
||||||
|
if (ptr == NULL) {
|
||||||
|
rcfile_error(_("Missing syntax name"));
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (syntaxes == NULL) {
|
||||||
|
syntaxes = nmalloc(sizeof(syntaxtype));
|
||||||
|
syntaxes->desc = NULL;
|
||||||
|
syntaxes->desc = mallocstrcpy(syntaxes->desc, nameptr);
|
||||||
|
syntaxes->color = NULL;
|
||||||
|
syntaxes->extensions = NULL;
|
||||||
|
syntaxes->next = NULL;
|
||||||
|
tmpsyntax = syntaxes;
|
||||||
|
#ifdef DEBUG
|
||||||
|
fprintf(stderr,
|
||||||
|
"Starting a new syntax type\n");
|
||||||
|
fprintf(stderr, "string val=%s\n", tmp);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
} else {
|
||||||
|
for (tmpsyntax = syntaxes;
|
||||||
|
tmpsyntax->next != NULL; tmpsyntax = tmpsyntax->next);
|
||||||
|
#ifdef DEBUG
|
||||||
|
fprintf(stderr, "Adding new syntax after 1st\n");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
tmpsyntax->next = nmalloc(sizeof(syntaxtype));
|
||||||
|
tmpsyntax->next->desc = NULL;
|
||||||
|
tmpsyntax->next->desc = mallocstrcpy(tmpsyntax->next->desc, nameptr);
|
||||||
|
tmpsyntax->next->color = NULL;
|
||||||
|
tmpsyntax->next->extensions = NULL;
|
||||||
|
tmpsyntax->next->next = NULL;
|
||||||
|
tmpsyntax = tmpsyntax->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Now load in the extensions to their part of the struct */
|
||||||
|
while (*ptr != '\n' && *ptr != '\0') {
|
||||||
|
|
||||||
|
while (*ptr != '"' && *ptr != '\n' && *ptr != '\0')
|
||||||
|
ptr++;
|
||||||
|
|
||||||
|
if (*ptr == '\n' || *ptr == '\0')
|
||||||
|
return;
|
||||||
|
ptr++;
|
||||||
|
|
||||||
|
fileregptr = ptr;
|
||||||
|
ptr = parse_next_regex(ptr);
|
||||||
|
|
||||||
|
if (tmpsyntax->extensions == NULL) {
|
||||||
|
tmpsyntax->extensions = nmalloc(sizeof(exttype));
|
||||||
|
tmpsyntax->extensions->val = NULL;
|
||||||
|
tmpsyntax->extensions->val = mallocstrcpy(tmpsyntax->extensions->val, fileregptr);
|
||||||
|
tmpsyntax->extensions->next = NULL;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
for (exttmp = tmpsyntax->extensions; exttmp->next != NULL;
|
||||||
|
exttmp = exttmp->next);
|
||||||
|
exttmp->next = nmalloc(sizeof(exttype));
|
||||||
|
exttmp->next->val = NULL;
|
||||||
|
exttmp->next->val = mallocstrcpy(exttmp->next->val, fileregptr);
|
||||||
|
exttmp->next->next = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/* Parse the color stuff into the colorstrings array */
|
/* Parse the color stuff into the colorstrings array */
|
||||||
void parse_colors(FILE * rcstream, char *buf, char *ptr)
|
void parse_colors(FILE * rcstream, char *buf, char *ptr)
|
||||||
{
|
{
|
||||||
|
@ -190,6 +277,7 @@ void parse_colors(FILE * rcstream, char *buf, char *ptr)
|
||||||
int expectend = 0; /* Do we expect an end= line? */
|
int expectend = 0; /* Do we expect an end= line? */
|
||||||
char *tmp = NULL, *beginning, *fgstr, *bgstr;
|
char *tmp = NULL, *beginning, *fgstr, *bgstr;
|
||||||
colortype *tmpcolor = NULL;
|
colortype *tmpcolor = NULL;
|
||||||
|
syntaxtype *tmpsyntax = NULL;
|
||||||
|
|
||||||
fgstr = ptr;
|
fgstr = ptr;
|
||||||
ptr = parse_next_word(ptr);
|
ptr = parse_next_word(ptr);
|
||||||
|
@ -208,6 +296,15 @@ void parse_colors(FILE * rcstream, char *buf, char *ptr)
|
||||||
fg = colortoint(fgstr, &bright);
|
fg = colortoint(fgstr, &bright);
|
||||||
bg = colortoint(bgstr, &bright);
|
bg = colortoint(bgstr, &bright);
|
||||||
|
|
||||||
|
if (syntaxes == NULL) {
|
||||||
|
rcfile_error(_("Cannot add a color directive without a syntax line"));
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (tmpsyntax = syntaxes; tmpsyntax->next != NULL;
|
||||||
|
tmpsyntax = tmpsyntax->next)
|
||||||
|
;
|
||||||
|
|
||||||
/* Now the fun part, start adding regexps to individual strings
|
/* Now the fun part, start adding regexps to individual strings
|
||||||
in the colorstrings array, woo! */
|
in the colorstrings array, woo! */
|
||||||
|
|
||||||
|
@ -236,14 +333,14 @@ void parse_colors(FILE * rcstream, char *buf, char *ptr)
|
||||||
tmp = NULL;
|
tmp = NULL;
|
||||||
tmp = mallocstrcpy(tmp, beginning);
|
tmp = mallocstrcpy(tmp, beginning);
|
||||||
|
|
||||||
if (colorstrings == NULL) {
|
if (tmpsyntax->color == NULL) {
|
||||||
colorstrings = nmalloc(sizeof(colortype));
|
tmpsyntax->color = nmalloc(sizeof(colortype));
|
||||||
colorstrings->fg = fg;
|
tmpsyntax->color->fg = fg;
|
||||||
colorstrings->bg = bg;
|
tmpsyntax->color->bg = bg;
|
||||||
colorstrings->bright = bright;
|
tmpsyntax->color->bright = bright;
|
||||||
colorstrings->start = tmp;
|
tmpsyntax->color->start = tmp;
|
||||||
colorstrings->next = NULL;
|
tmpsyntax->color->next = NULL;
|
||||||
tmpcolor = colorstrings;
|
tmpcolor = tmpsyntax->color;
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"Starting a new colorstring for fg %d bg %d\n",
|
"Starting a new colorstring for fg %d bg %d\n",
|
||||||
|
@ -252,7 +349,7 @@ void parse_colors(FILE * rcstream, char *buf, char *ptr)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
for (tmpcolor = colorstrings;
|
for (tmpcolor = tmpsyntax->color;
|
||||||
tmpcolor->next != NULL; tmpcolor = tmpcolor->next);
|
tmpcolor->next != NULL; tmpcolor = tmpcolor->next);
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
fprintf(stderr, "Adding new entry for fg %d bg %d\n", fg, bg);
|
fprintf(stderr, "Adding new entry for fg %d bg %d\n", fg, bg);
|
||||||
|
@ -338,6 +435,8 @@ void parse_rcfile(FILE * rcstream)
|
||||||
else if (!strcasecmp(keyword, "unset"))
|
else if (!strcasecmp(keyword, "unset"))
|
||||||
set = -1;
|
set = -1;
|
||||||
#ifdef ENABLE_COLOR
|
#ifdef ENABLE_COLOR
|
||||||
|
else if (!strcasecmp(keyword, "syntax"))
|
||||||
|
parse_syntax(rcstream, buf, ptr);
|
||||||
else if (!strcasecmp(keyword, "color"))
|
else if (!strcasecmp(keyword, "color"))
|
||||||
parse_colors(rcstream, buf, ptr);
|
parse_colors(rcstream, buf, ptr);
|
||||||
#endif /* ENABLE_COLOR */
|
#endif /* ENABLE_COLOR */
|
||||||
|
@ -481,9 +580,25 @@ void do_rcfile(void)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
parse_rcfile(rcstream);
|
parse_rcfile(rcstream);
|
||||||
fclose(rcstream);
|
fclose(rcstream);
|
||||||
|
|
||||||
|
{
|
||||||
|
syntaxtype *s;
|
||||||
|
exttype *e;
|
||||||
|
colortype *c;
|
||||||
|
|
||||||
|
for (s = syntaxes; s != NULL; s = s->next) {
|
||||||
|
fprintf(stderr, "Syntax \"%s\"\n", s->desc);
|
||||||
|
for (e = s->extensions; e != NULL; e = e->next)
|
||||||
|
fprintf(stderr, " extension \"%s\"\n", e->val);
|
||||||
|
for (c = s->color; c != NULL; c = c->next)
|
||||||
|
fprintf(stderr, "Color string regex \"%s\"\n", c->start);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue