Re: [PATCH]: define keyword to substitute colors in syntax files
- From: "Andrew V. Samoilov" <sav bcs zp ua>
- To: Pavel Roskin <proski gnu org>
- Cc: mc-devel gnome org
- Subject: Re: [PATCH]: define keyword to substitute colors in syntax files
- Date: Fri, 28 Feb 2003 20:50:57 +0200
Hello!
Pavel Roskin wrote:
this patch allows new "define" keyword in builtin editor syntax files.
Now only colors can be substituted, but it can be improved on request.
Thank you! I'm applying it.
What would really be nice is:
1) Define both foreground and background:
define comment brown black
context default
keyword /\* comment
This part is implemented. Test attached patch please.
2) Make it possible to put defines in a separate file:
Syntax:
include defines.syntax
file ..\*\\.sh$ Shell\sScript ^#!\s\*/.\*/([a-z]?|ba|pdk)sh
include sh.syntax
defines.syntax:
define comment brown black
sh.syntax:
context # \n comment
This part is some tricky, but it is my goal and will be implemented some
later.
--
Regards,
Andrew V. Samoilov
ChangeLog:
* syntax.c: Reimplement defines value as array of strings, so
define comment brown blue
construction is now legal.
(mc_defines_destroy): Adjust for the above.
(edit_read_syntax_rules): Likewise.
(this_try_alloc_color_pair): Move color substitution ...
(edit_read_syntax_rules): ... here.
--- mc/edit/syntax.c 2003-02-28 19:49:34.000000000 +0200
+++ mc/edit/syntax.c 2003-02-28 20:19:59.000000000 +0200
@@ -89,7 +89,11 @@ static GTree *defines;
static gint
mc_defines_destroy (gpointer key, gpointer value, gpointer data)
{
+ char **values = value;
+
g_free (key);
+ while (*values)
+ g_free (*values++);
g_free (value);
return FALSE;
@@ -555,9 +559,6 @@ this_try_alloc_color_pair (char *fg, cha
if (!*fg)
fg = 0;
if (fg) {
- p = g_tree_lookup (defines, fg);
- if (p)
- fg = p;
strncpy (f, fg, sizeof (f) - 1);
f[sizeof (f) - 1] = 0;
p = strchr (f, '/');
@@ -566,9 +567,6 @@ this_try_alloc_color_pair (char *fg, cha
fg = f;
}
if (bg) {
- p = g_tree_lookup (defines, bg);
- if (p)
- bg = p;
strncpy (b, bg, sizeof (b) - 1);
b[sizeof (b) - 1] = 0;
p = strchr (b, '/');
@@ -757,6 +755,7 @@ edit_read_syntax_rules (WEdit *edit, FIL
c->spelling = 1;
} else if (!strcmp (args[0], "keyword")) {
struct key_word *k;
+ gpointer t;
if (num_words == -1)
break_a;
check_a;
@@ -783,6 +782,12 @@ edit_read_syntax_rules (WEdit *edit, FIL
}
k->keyword = g_strdup (*a++);
k->first = *k->keyword;
+
+ /* Substitute a with array from list of defines */
+ if ((t = g_tree_lookup (defines, *a))) {
+ a = t;
+ }
+
fg = *a;
if (*a)
a++;
@@ -803,15 +808,20 @@ edit_read_syntax_rules (WEdit *edit, FIL
} else if (!strcmp (args[0], "define")) {
gpointer t;
char *key = *a++;
- char *value = *a;
- if (!key || !value)
+ char **argv;
+ if (argc < 3)
break_a;
- if ((t = g_tree_lookup (defines, key))){
- g_free (t);
- t = g_strdup (value);
+ if ((t = g_tree_lookup (defines, key))) {
+ mc_defines_destroy (NULL, t, NULL);
} else {
- g_tree_insert (defines, g_strdup (key), g_strdup (value));
+ key = g_strdup (key);
}
+ t = argv = g_new (char *, argc - 1);
+ while (*a) {
+ *argv++ = g_strdup (*a++);
+ };
+ *argv = NULL;
+ g_tree_insert (defines, key, t);
} else { /* anything else is an error */
break_a;
}
[
Date Prev][Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]