SF.net SVN: geany:[3873] trunk
ntrel at users.sourceforge.net
ntrel at xxxxx
Thu Jun 18 14:20:08 UTC 2009
Revision: 3873
http://geany.svn.sourceforge.net/geany/?rev=3873&view=rev
Author: ntrel
Date: 2009-06-18 14:20:07 +0000 (Thu, 18 Jun 2009)
Log Message:
-----------
Remove gsd_* default styles, use named styles instead.
Note: this relies on filetypes.common being installed.
Add load_style_entries(), which makes style initialization
simpler, used in styleset_c_like_init().
Modified Paths:
--------------
trunk/ChangeLog
trunk/HACKING
trunk/README.Packagers
trunk/src/highlighting.c
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2009-06-17 19:04:17 UTC (rev 3872)
+++ trunk/ChangeLog 2009-06-18 14:20:07 UTC (rev 3873)
@@ -1,3 +1,12 @@
+2009-06-18 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
+
+ * src/highlighting.c, README.Packagers, HACKING:
+ Remove gsd_* default styles, use named styles instead.
+ Note: this relies on filetypes.common being installed.
+ Add load_style_entries(), which makes style initialization
+ simpler, used in styleset_c_like_init().
+
+
2009-06-17 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
* src/win32.c:
Modified: trunk/HACKING
===================================================================
--- trunk/HACKING 2009-06-17 19:04:17 UTC (rev 3872)
+++ trunk/HACKING 2009-06-18 14:20:07 UTC (rev 3873)
@@ -236,19 +236,23 @@
1. Write styleset_foo_init() to setup default styles and load style
settings from the filetypes.foo configuration file. You should probably
start by copying and adapting another filetype's initialization, such
- as styleset_asm_init().
+ as styleset_tcl_init(). Another way is to use load_style_entries()
+ to make style initialization simpler - see styleset_c_like_init().
+
+.. note::
+ Please try to make your styles fit in with the other filetypes' default
+ colors, and to use named styles where possible. Filetypes that share a
+ lexer should have the same colors. Normally, styles should leave the
+ background color empty to match the default color.
+
2. Write styleset_foo() to apply styles when a new scintilla widget
- is created. Again you could copy and adapt a function like styleset_asm().
+ is created. Again you could copy and adapt a function like
+ styleset_tcl().
3. In highlighting_init_styles(), add
``init_styleset_case(GEANY_FILETYPES_FOO, foo);``.
4. In highlighting_set_styles(), add
``styleset_case(GEANY_FILETYPES_FOO, foo);``.
-Please try to make your styles fit in with the other filetypes' default
-colors, and to use named styles where possible. Filetypes that share a
-lexer should have the same colors. Normally, styles should leave the
-background color empty to match the default color.
-
Error message parsing
^^^^^^^^^^^^^^^^^^^^^
New-style error message parsing is done with an extended GNU-style regex
Modified: trunk/README.Packagers
===================================================================
--- trunk/README.Packagers 2009-06-17 19:04:17 UTC (rev 3872)
+++ trunk/README.Packagers 2009-06-18 14:20:07 UTC (rev 3873)
@@ -26,8 +26,9 @@
manual.
What you shouldn't skip in your package: the filetype.* files in the
data/ subdirectory, these files are important. If they are missing,
-Geany has still a fallback mechanism for syntax highlighting but several
-other features for certain filetypes will fail (mainly build support).
+Geany still has a fallback mechanism for syntax highlighting (if
+filetypes.common is installed) but several other features for certain
+filetypes will fail (mainly build support).
Testing your package
Modified: trunk/src/highlighting.c
===================================================================
--- trunk/src/highlighting.c 2009-06-17 19:04:17 UTC (rev 3872)
+++ trunk/src/highlighting.c 2009-06-18 14:20:07 UTC (rev 3873)
@@ -106,6 +106,7 @@
typedef struct
{
gchar *name;
+ gchar *named_style;
GeanyLexerStyle *style;
} StyleEntry;
@@ -114,24 +115,9 @@
* e.g. "comment" => &GeanyLexerStyle{0xd00000, 0xffffff, FALSE, FALSE} */
static GHashTable *named_style_hash = NULL;
+static GeanyLexerStyle gsd_default = {0x000000, 0xffffff, FALSE, FALSE};
-/* Geany generic styles, initialized to defaults.
- * Currently only used as default styling for C-like languages.
- * Note: Ideally named styles would be used as common styling for all programming
- * languages (and perhaps all filetypes).
- * These could be replaced by default named styles in filetypes.common. */
-static GeanyLexerStyle gsd_default = {0x000000, 0xffffff, FALSE, FALSE};
-static GeanyLexerStyle gsd_comment = {0xd00000, 0xffffff, FALSE, FALSE};
-static GeanyLexerStyle gsd_comment_doc = {0x3f5fbf, 0xffffff, TRUE, FALSE};
-static GeanyLexerStyle gsd_number = {0x007f00, 0xffffff, FALSE, FALSE};
-static GeanyLexerStyle gsd_reserved_word = {0x00007f, 0xffffff, TRUE, FALSE};
-static GeanyLexerStyle gsd_system_word = {0x991111, 0xffffff, TRUE, FALSE};
-static GeanyLexerStyle gsd_user_word = {0x0000d0, 0xffffff, TRUE, FALSE};
-static GeanyLexerStyle gsd_string = {0xff901e, 0xffffff, FALSE, FALSE};
-static GeanyLexerStyle gsd_pragma = {0x007f7f, 0xffffff, FALSE, FALSE};
-static GeanyLexerStyle gsd_string_eol = {0x000000, 0xe0c0e0, FALSE, FALSE};
-
static void new_style_array(gint file_type_id, gint styling_count)
{
StyleSet *set = &style_sets[file_type_id];
@@ -190,14 +176,21 @@
}
-static void read_named_style(gchar *name, GeanyLexerStyle *style)
+/* Like glibc's strdupa, but portable.
+ * Don't use for long strings. */
+#define local_strdup(dest, src) \
+ dest = g_alloca(strlen(src) + 1); \
+ strcpy(dest, src);
+
+static void read_named_style(const gchar *named_style, GeanyLexerStyle *style)
{
GeanyLexerStyle *cs;
- gchar *comma;
+ gchar *comma, *name = NULL;
const gchar *bold = NULL;
const gchar *italic = NULL;
- g_return_if_fail(name);
+ g_return_if_fail(named_style);
+ local_strdup(name, named_style);
comma = strstr(name, ",");
if (comma)
@@ -210,11 +203,11 @@
if (cs)
{
- *style = *cs;
- if (bold)
- style->bold = !style->bold;
- if (italic)
- style->italic = !style->italic;
+ *style = *cs;
+ if (bold)
+ style->bold = !style->bold;
+ if (italic)
+ style->italic = !style->italic;
}
else
{
@@ -224,15 +217,6 @@
}
-/* convert 0x..RRGGBB to 0x..BBGGRR */
-static gint rotate_rgb(gint color)
-{
- return ((color & 0xFF0000) >> 16) +
- (color & 0x00FF00) +
- ((color & 0x0000FF) << 16);
-}
-
-
static void parse_color(const gchar *str, gint *clr)
{
gint c;
@@ -261,8 +245,6 @@
g_return_if_fail(style);
*style = *default_style;
- style->foreground = rotate_rgb(default_style->foreground);
- style->background = rotate_rgb(default_style->background);
if (!list)
return;
@@ -310,6 +292,26 @@
}
+static void get_keyfile_named_style(GKeyFile *config, GKeyFile *configh,
+ const gchar *key_name, gchar *named_style, GeanyLexerStyle *style)
+{
+ GeanyLexerStyle def;
+
+ read_named_style(named_style, &def);
+ get_keyfile_style(config, configh, key_name, &def, style);
+}
+
+
+/* convert 0x..RRGGBB to 0x..BBGGRR */
+static gint rotate_rgb(gint color)
+{
+ return ((color & 0xFF0000) >> 16) +
+ (color & 0x00FF00) +
+ ((color & 0x0000FF) << 16);
+}
+
+
+/* foreground and background are in 0xRRGGBB format */
static void get_keyfile_hex(GKeyFile *config, GKeyFile *configh,
const gchar *key,
gint foreground, gint background, gboolean bold,
@@ -317,6 +319,8 @@
{
GeanyLexerStyle def = {foreground, background, bold, FALSE};
+ def.foreground = rotate_rgb(def.foreground);
+ def.background = rotate_rgb(def.background);
get_keyfile_style(config, configh, key, &def, style);
}
@@ -754,43 +758,67 @@
}
+#define foreach_range(i, size) \
+ for (i = 0; i < size; i++)
+
+/* If used, entries[n].style should have foreground and background in 0xRRGGBB format */
+static void load_style_entries(GKeyFile *config, GKeyFile *config_home, gint filetype_idx,
+ StyleEntry *entries, gsize entries_len)
+{
+ guint i;
+
+ foreach_range(i, entries_len)
+ {
+ StyleEntry *entry = &entries[i];
+ GeanyLexerStyle *style = &style_sets[filetype_idx].styling[i];
+
+ if (entry->named_style)
+ get_keyfile_named_style(config, config_home, entry->name, entry->named_style, style);
+ else
+ if (entry->style)
+ {
+ GeanyLexerStyle *def = entry->style;
+
+ def->foreground = rotate_rgb(def->foreground);
+ def->background = rotate_rgb(def->background);
+ get_keyfile_style(config, config_home, entry->name, def, style);
+ }
+ }
+}
+
+
/* call new_style_array(filetype_idx, >= 20) before using this. */
static void
styleset_c_like_init(GKeyFile *config, GKeyFile *config_home, gint filetype_idx)
{
static GeanyLexerStyle uuid = {0x404080, 0xffffff, FALSE, FALSE};
- static GeanyLexerStyle operator = {0x301010, 0xffffff, FALSE, FALSE};
static GeanyLexerStyle verbatim = {0x301010, 0xffffff, FALSE, FALSE};
static GeanyLexerStyle regex = {0x105090, 0xffffff, FALSE, FALSE};
-
StyleEntry entries[] =
- {
- {"default", &gsd_default},
- {"comment", &gsd_comment},
- {"commentline", &gsd_comment},
- {"commentdoc", &gsd_comment_doc},
- {"number", &gsd_number},
- {"word", &gsd_reserved_word},
- {"word2", &gsd_system_word},
- {"string", &gsd_string},
- {"character", &gsd_string},
- {"uuid", &uuid},
- {"preprocessor",&gsd_pragma},
- {"operator", &operator},
- {"identifier", &gsd_default},
- {"stringeol", &gsd_string_eol},
- {"verbatim", &verbatim},
- {"regex", ®ex},
- {"commentlinedoc", &gsd_comment_doc},
- {"commentdockeyword", &gsd_comment_doc},
- {"commentdockeyworderror", &gsd_comment_doc},
- {"globalclass", &gsd_user_word}
+ {
+ {"default", "default", NULL},
+ {"comment", "comment", NULL},
+ {"commentline", "comment", NULL},
+ {"commentdoc", "commentdoc", NULL},
+ {"number", "number", NULL},
+ {"word", "word", NULL},
+ {"word2", "word2", NULL},
+ {"string", "string", NULL},
+ {"character", "string", NULL},
+ {"uuid", NULL, &uuid},
+ {"preprocessor","preprocessor", NULL},
+ {"operator", "operator", NULL},
+ {"identifier", "default", NULL},
+ {"stringeol", "stringeol", NULL},
+ {"verbatim", NULL, &verbatim},
+ {"regex", NULL, ®ex},
+ {"commentlinedoc", "commentdoc,bold", NULL},
+ {"commentdockeyword", "commentdoc,bold,italic", NULL},
+ {"commentdockeyworderror", "commentdoc", NULL},
+ {"globalclass", "type", NULL}
};
- gint i;
- for (i = 0; i < 20; i++)
- get_keyfile_style(config, config_home, entries[i].name, entries[i].style,
- &style_sets[filetype_idx].styling[i]);
+ load_style_entries(config, config_home, filetype_idx, entries, G_N_ELEMENTS(entries));
}
@@ -1127,7 +1155,7 @@
{
new_style_array(GEANY_FILETYPES_MAKE, 7);
get_keyfile_hex(config, config_home, "default", 0x00002f, 0xffffff, FALSE, &style_sets[GEANY_FILETYPES_MAKE].styling[0]);
- get_keyfile_style(config, config_home, "comment", &gsd_comment, &style_sets[GEANY_FILETYPES_MAKE].styling[1]);
+ get_keyfile_named_style(config, config_home, "comment", "comment", &style_sets[GEANY_FILETYPES_MAKE].styling[1]);
get_keyfile_hex(config, config_home, "preprocessor", 0x007f7f, 0xffffff, FALSE, &style_sets[GEANY_FILETYPES_MAKE].styling[2]);
get_keyfile_hex(config, config_home, "identifier", 0x007f00, 0xffffff, FALSE, &style_sets[GEANY_FILETYPES_MAKE].styling[3]);
get_keyfile_hex(config, config_home, "operator", 0x301010, 0xffffff, FALSE, &style_sets[GEANY_FILETYPES_MAKE].styling[4]);
@@ -1550,7 +1578,7 @@
new_style_array(GEANY_FILETYPES_PERL, 35);
get_keyfile_hex(config, config_home, "default", 0x000000, 0xffffff, FALSE, &style_sets[GEANY_FILETYPES_PERL].styling[0]);
get_keyfile_hex(config, config_home, "error", 0xff0000, 0xffffff, FALSE, &style_sets[GEANY_FILETYPES_PERL].styling[1]);
- get_keyfile_style(config, config_home, "commentline", &gsd_comment, &style_sets[GEANY_FILETYPES_PERL].styling[2]);
+ get_keyfile_named_style(config, config_home, "commentline", "comment", &style_sets[GEANY_FILETYPES_PERL].styling[2]);
get_keyfile_hex(config, config_home, "number", 0x007f00, 0xffffff, FALSE, &style_sets[GEANY_FILETYPES_PERL].styling[3]);
get_keyfile_hex(config, config_home, "word", 0x111199, 0xffffff, TRUE, &style_sets[GEANY_FILETYPES_PERL].styling[4]);
get_keyfile_hex(config, config_home, "string", 0xff901e, 0xffffff, FALSE, &style_sets[GEANY_FILETYPES_PERL].styling[5]);
@@ -1849,7 +1877,7 @@
{
new_style_array(GEANY_FILETYPES_RUBY, 35);
get_keyfile_hex(config, config_home, "default", 0x000000, 0xffffff, FALSE, &style_sets[GEANY_FILETYPES_RUBY].styling[0]);
- get_keyfile_style(config, config_home, "commentline", &gsd_comment, &style_sets[GEANY_FILETYPES_RUBY].styling[1]);
+ get_keyfile_named_style(config, config_home, "commentline", "comment", &style_sets[GEANY_FILETYPES_RUBY].styling[1]);
get_keyfile_hex(config, config_home, "number", 0x400080, 0xffffff, FALSE, &style_sets[GEANY_FILETYPES_RUBY].styling[2]);
get_keyfile_hex(config, config_home, "string", 0x008000, 0xffffff, FALSE, &style_sets[GEANY_FILETYPES_RUBY].styling[3]);
get_keyfile_hex(config, config_home, "character", 0x008000, 0xffffff, FALSE, &style_sets[GEANY_FILETYPES_RUBY].styling[4]);
@@ -1944,7 +1972,7 @@
{
new_style_array(GEANY_FILETYPES_SH, 14);
get_keyfile_hex(config, config_home, "default", 0x000000, 0xffffff, FALSE, &style_sets[GEANY_FILETYPES_SH].styling[0]);
- get_keyfile_style(config, config_home, "commentline", &gsd_comment, &style_sets[GEANY_FILETYPES_SH].styling[1]);
+ get_keyfile_named_style(config, config_home, "commentline", "comment", &style_sets[GEANY_FILETYPES_SH].styling[1]);
get_keyfile_hex(config, config_home, "number", 0x007f00, 0xffffff, FALSE, &style_sets[GEANY_FILETYPES_SH].styling[2]);
get_keyfile_hex(config, config_home, "word", 0x119911, 0xffffff, TRUE, &style_sets[GEANY_FILETYPES_SH].styling[3]);
get_keyfile_hex(config, config_home, "string", 0xff901e, 0xffffff, FALSE, &style_sets[GEANY_FILETYPES_SH].styling[4]);
@@ -2776,8 +2804,8 @@
{
new_style_array(GEANY_FILETYPES_TCL, 16);
get_keyfile_hex(config, config_home, "default", 0x000000, 0xffffff, FALSE, &style_sets[GEANY_FILETYPES_TCL].styling[0]);
- get_keyfile_style(config, config_home, "comment", &gsd_comment, &style_sets[GEANY_FILETYPES_TCL].styling[1]);
- get_keyfile_style(config, config_home, "commentline", &gsd_comment, &style_sets[GEANY_FILETYPES_TCL].styling[2]);
+ get_keyfile_named_style(config, config_home, "comment", "comment", &style_sets[GEANY_FILETYPES_TCL].styling[1]);
+ get_keyfile_named_style(config, config_home, "commentline", "comment", &style_sets[GEANY_FILETYPES_TCL].styling[2]);
get_keyfile_hex(config, config_home, "number", 0x007f00, 0xffffff, FALSE, &style_sets[GEANY_FILETYPES_TCL].styling[3]);
get_keyfile_hex(config, config_home, "operator", 0x301010, 0xffffff, FALSE, &style_sets[GEANY_FILETYPES_TCL].styling[4]);
get_keyfile_hex(config, config_home, "identifier", 0xa20000, 0xffffff, FALSE, &style_sets[GEANY_FILETYPES_TCL].styling[5]);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Commits
mailing list