Revision: 4257 http://geany.svn.sourceforge.net/geany/?rev=4257&view=rev Author: ntrel Date: 2009-09-28 15:55:49 +0000 (Mon, 28 Sep 2009)
Log Message: ----------- Add apply_style_entries() to simplify implementing styleset_foo().
Modified Paths: -------------- trunk/ChangeLog trunk/HACKING trunk/src/highlighting.c
Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2009-09-28 15:33:05 UTC (rev 4256) +++ trunk/ChangeLog 2009-09-28 15:55:49 UTC (rev 4257) @@ -12,6 +12,8 @@ data/filetypes.restructuredtext: Remove style defaults from the code - just read them from configuration files. + * src/highlighting.c, HACKING: + Add apply_style_entries() to simplify implementing styleset_foo().
2009-09-27 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
Modified: trunk/HACKING =================================================================== --- trunk/HACKING 2009-09-28 15:33:05 UTC (rev 4256) +++ trunk/HACKING 2009-09-28 15:55:49 UTC (rev 4257) @@ -305,11 +305,10 @@ 1. Write styleset_foo_init() to setup lexer 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_tcl_init(). Another way is to use load_style_entries() - to make style initialization simpler - see styleset_c_like_init(). + as styleset_tcl_init(). You may want to use load_style_entries(). 2. Write styleset_foo() to apply styles when a new scintilla widget is created. Again you could copy and adapt a function like - styleset_tcl(). + styleset_tcl(). You may want to use apply_style_entries(). 3. In highlighting_init_styles(), add ``init_styleset_case(GEANY_FILETYPES_FOO, styleset_foo_init);``. 4. In highlighting_set_styles(), add
Modified: trunk/src/highlighting.c =================================================================== --- trunk/src/highlighting.c 2009-09-28 15:33:05 UTC (rev 4256) +++ trunk/src/highlighting.c 2009-09-28 15:55:49 UTC (rev 4257) @@ -756,16 +756,15 @@ #define foreach_range(i, size) \ for (i = 0; i < size; i++)
-/* entries contains the default style names for the filetype. - * If used, entries[n].style should have foreground and background in 0xRRGGBB format, or -1. */ +/* names: the style names for the filetype. */ static void load_style_entries(GKeyFile *config, GKeyFile *config_home, gint filetype_idx, - const gchar **entries, gsize entries_len) + const gchar **names, gsize names_len) { guint i;
- foreach_range(i, entries_len) + foreach_range(i, names_len) { - const gchar *name = entries[i]; + const gchar *name = names[i]; GeanyLexerStyle *style = &style_sets[filetype_idx].styling[i];
get_keyfile_style(config, config_home, name, style); @@ -773,6 +772,22 @@ }
+/* styles: the style IDs for the filetype. + * STYLE_DEFAULT will be set to match the first style. */ +static void apply_style_entries(ScintillaObject *sci, gint filetype_idx, + gint *styles, gsize styles_len) +{ + guint i; + + g_return_if_fail(styles_len > 0); + + set_sci_style(sci, STYLE_DEFAULT, filetype_idx, 0); + + foreach_range(i, styles_len) + set_sci_style(sci, styles[i], filetype_idx, i); +} + + /* call new_styleset(filetype_idx, >= 20) before using this. */ static void styleset_c_like_init(GKeyFile *config, GKeyFile *config_home, gint filetype_idx) @@ -807,28 +822,31 @@
static void styleset_c_like(ScintillaObject *sci, gint filetype_idx) { - set_sci_style(sci, STYLE_DEFAULT, filetype_idx, 0); - set_sci_style(sci, SCE_C_DEFAULT, filetype_idx, 0); - set_sci_style(sci, SCE_C_COMMENT, filetype_idx, 1); - set_sci_style(sci, SCE_C_COMMENTLINE, filetype_idx, 2); - set_sci_style(sci, SCE_C_COMMENTDOC, filetype_idx, 3); - set_sci_style(sci, SCE_C_NUMBER, filetype_idx, 4); - set_sci_style(sci, SCE_C_WORD, filetype_idx, 5); - set_sci_style(sci, SCE_C_WORD2, filetype_idx, 6); - set_sci_style(sci, SCE_C_STRING, filetype_idx, 7); - set_sci_style(sci, SCE_C_CHARACTER, filetype_idx, 8); - set_sci_style(sci, SCE_C_UUID, filetype_idx, 9); - set_sci_style(sci, SCE_C_PREPROCESSOR, filetype_idx, 10); - set_sci_style(sci, SCE_C_OPERATOR, filetype_idx, 11); - set_sci_style(sci, SCE_C_IDENTIFIER, filetype_idx, 12); - set_sci_style(sci, SCE_C_STRINGEOL, filetype_idx, 13); - set_sci_style(sci, SCE_C_VERBATIM, filetype_idx, 14); - set_sci_style(sci, SCE_C_REGEX, filetype_idx, 15); - set_sci_style(sci, SCE_C_COMMENTLINEDOC, filetype_idx, 16); - set_sci_style(sci, SCE_C_COMMENTDOCKEYWORD, filetype_idx, 17); - set_sci_style(sci, SCE_C_COMMENTDOCKEYWORDERROR, filetype_idx, 18); - /* is used for local structs and typedefs */ - set_sci_style(sci, SCE_C_GLOBALCLASS, filetype_idx, 19); + gint styles[] = { + SCE_C_DEFAULT, + SCE_C_COMMENT, + SCE_C_COMMENTLINE, + SCE_C_COMMENTDOC, + SCE_C_NUMBER, + SCE_C_WORD, + SCE_C_WORD2, + SCE_C_STRING, + SCE_C_CHARACTER, + SCE_C_UUID, + SCE_C_PREPROCESSOR, + SCE_C_OPERATOR, + SCE_C_IDENTIFIER, + SCE_C_STRINGEOL, + SCE_C_VERBATIM, + SCE_C_REGEX, + SCE_C_COMMENTLINEDOC, + SCE_C_COMMENTDOCKEYWORD, + SCE_C_COMMENTDOCKEYWORDERROR, + /* used for local structs and typedefs */ + SCE_C_GLOBALCLASS + }; + + apply_style_entries(sci, filetype_idx, styles, G_N_ELEMENTS(styles)); }
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.