Revision: 4143 http://geany.svn.sourceforge.net/geany/?rev=4143&view=rev Author: ntrel Date: 2009-08-31 16:11:46 +0000 (Mon, 31 Aug 2009)
Log Message: ----------- Merge custom-filetypes branch: Support adding custom filetype files e.g. filetypes.Foo.conf. - Code: Allow GeanyFiletype::extension to be NULL. Add note about using GeanyFiletype pointer instead of filetype_id for filetypes.c function arguments. Replace styleset_none() with styleset_default().
Modified Paths: -------------- trunk/ChangeLog trunk/TODO trunk/src/dialogs.c trunk/src/document.c trunk/src/filetypes.c trunk/src/filetypes.h trunk/src/highlighting.c trunk/src/main.c trunk/src/symbols.c trunk/src/templates.c
Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2009-08-31 15:46:19 UTC (rev 4142) +++ trunk/ChangeLog 2009-08-31 16:11:46 UTC (rev 4143) @@ -3,6 +3,16 @@ * src/plugins.c: Add warning if only one of the plugin_key_group[_info] symbols is defined for a plugin. + * src/templates.c, src/highlighting.c, src/dialogs.c, src/filetypes.c, + src/filetypes.h, src/document.c, src/main.c, src/symbols.c, + TODO: + Merge custom-filetypes branch: + Support adding custom filetype files e.g. filetypes.Foo.conf. + - Code: + Allow GeanyFiletype::extension to be NULL. + Add note about using GeanyFiletype pointer instead of filetype_id + for filetypes.c function arguments. + Replace styleset_none() with styleset_default().
2009-08-30 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
Modified: trunk/TODO =================================================================== --- trunk/TODO 2009-08-31 15:46:19 UTC (rev 4142) +++ trunk/TODO 2009-08-31 16:11:46 UTC (rev 4143) @@ -13,7 +13,7 @@ filetypes.common named styles) o configurable filetype and project make commands (e.g. using bud for D) - see the build-system SVN branch - o (custom filetypes) + o (better custom filetype support) o (support for adding plugin filetypes - SCI_LOADLEXERLIBRARY?) o (selectable menu of arguments to use for Make, from Make Custom) o (DBUS)
Modified: trunk/src/dialogs.c =================================================================== --- trunk/src/dialogs.c 2009-08-31 15:46:19 UTC (rev 4142) +++ trunk/src/dialogs.c 2009-08-31 16:11:46 UTC (rev 4143) @@ -88,7 +88,7 @@ gboolean ro = (response == GEANY_RESPONSE_VIEW); /* View clicked */
/* ignore detect from file item */ - if (filetype_idx > 0 && filetype_idx < GEANY_MAX_BUILT_IN_FILETYPES) + if (filetype_idx > 0) ft = g_slist_nth_data(filetypes_by_title, filetype_idx); if (encoding_idx >= 0 && encoding_idx < GEANY_ENCODINGS_MAX) charset = encodings[encoding_idx].charset; @@ -511,8 +511,7 @@ { gchar *fname = NULL;
- if (doc->file_type != NULL && doc->file_type->id != GEANY_FILETYPES_NONE && - doc->file_type->extension != NULL) + if (doc->file_type != NULL && doc->file_type->extension != NULL) fname = g_strconcat(GEANY_STRING_UNTITLED, ".", doc->file_type->extension, NULL); else
Modified: trunk/src/document.c =================================================================== --- trunk/src/document.c 2009-08-31 15:46:19 UTC (rev 4142) +++ trunk/src/document.c 2009-08-31 16:11:46 UTC (rev 4143) @@ -1464,7 +1464,11 @@ g_return_if_fail(doc != NULL); g_return_if_fail(doc->file_type != NULL);
- filebase = g_strconcat(GEANY_STRING_UNTITLED, ".", (doc->file_type)->extension, NULL); + if (doc->file_type->extension) + filebase = g_strconcat(GEANY_STRING_UNTITLED, ".", doc->file_type->extension, NULL); + else + filebase = g_strdup(GEANY_STRING_UNTITLED); + filename = g_path_get_basename(doc->file_name);
/* only search the first 3 lines */
Modified: trunk/src/filetypes.c =================================================================== --- trunk/src/filetypes.c 2009-08-31 15:46:19 UTC (rev 4142) +++ trunk/src/filetypes.c 2009-08-31 16:11:46 UTC (rev 4143) @@ -26,6 +26,9 @@ * Filetype detection, file extensions and filetype menu items. */
+/* Note: we use filetype_id for some function arguments, but GeanyFiletype is better; we should + * only use GeanyFiletype for API functions. */ + #include <string.h> #include <glib/gstdio.h>
@@ -62,6 +65,7 @@ gboolean error_regex_compiled; gchar *last_string; /* last one compiled */ #endif + gboolean custom; } GeanyFiletypePrivate;
@@ -113,7 +117,7 @@ ft->lang = -2; ft->name = g_strdup(_("None")); ft->title = g_strdup(_("None")); - ft->extension = g_strdup("*"); + ft->extension = NULL; ft->pattern = utils_strv_new("*", NULL); ft->comment_open = NULL; ft->comment_close = NULL; @@ -658,6 +662,57 @@ }
+static void add_custom_filetype(const gchar *filename) +{ + gchar *fn = utils_strdupa(strstr(filename, ".") + 1); + gchar *dot = g_strrstr(fn, ".conf"); + GeanyFiletype *ft; + + g_return_if_fail(dot); + + *dot = 0x0; + + if (g_hash_table_lookup(filetypes_hash, fn)) + return; + + geany_debug("Adding filetype %s.", fn); + ft = filetype_new(); + ft->name = g_strdup(fn); + filetype_make_title(ft, TITLE_FILE); + ft->pattern = g_new0(gchar*, 1); + ft->priv->custom = TRUE; + filetype_add(ft); +} + + +static void init_custom_filetypes(const gchar *path) +{ + GDir *dir; + + g_return_if_fail(path); + + dir = g_dir_open(path, 0, NULL); + if (dir == NULL) + return; + + while (1) + { + const gchar prefix[] = "filetypes."; + const gchar *filename = g_dir_read_name(dir); + + if (filename == NULL) + break; + + if (g_str_has_prefix(filename, prefix) && + g_str_has_suffix(filename + strlen(prefix), ".conf")) + { + add_custom_filetype(filename); + } + } + g_dir_close(dir); +} + + /* Create the filetypes array and fill it with the known filetypes. */ void filetypes_init_types() { @@ -681,6 +736,8 @@ { filetype_add(filetypes[ft_id]); } + init_custom_filetypes(app->datadir); + init_custom_filetypes(utils_build_path(app->configdir, GEANY_FILEDEFS_SUBDIR, NULL)); }
@@ -747,16 +804,18 @@ { GeanyFiletype *ft = node->data;
- if (ft->id != GEANY_FILETYPES_NONE) + if (ft->group != GEANY_FILETYPE_GROUP_NONE) create_radio_menu_item(group_menus[ft->group], ft); + else + create_radio_menu_item(filetype_menu, ft); } - create_radio_menu_item(filetype_menu, filetypes[GEANY_FILETYPES_NONE]); }
void filetypes_init() { filetypes_init_types(); + create_set_filetype_menu(); setup_config_file_menus(); } @@ -1168,13 +1227,16 @@
/* simple wrapper function to print file errors in DEBUG mode */ static void load_system_keyfile(GKeyFile *key_file, const gchar *file, GKeyFileFlags flags, - G_GNUC_UNUSED GError **just_for_compatibility) + GeanyFiletype *ft) { GError *error = NULL; gboolean done = g_key_file_load_from_file(key_file, file, flags, &error); - if (G_UNLIKELY(! done) && G_UNLIKELY(error != NULL)) + + if (error != NULL) { - geany_debug("Failed to open %s (%s)", file, error->message); + if (!done && !ft->priv->custom) + geany_debug("Failed to open %s (%s)", file, error->message); + g_error_free(error); error = NULL; } @@ -1188,10 +1250,12 @@ { GKeyFile *config, *config_home; GeanyFiletypePrivate *pft; + GeanyFiletype *ft;
g_return_if_fail(ft_id >= 0 && ft_id < (gint) filetypes_array->len);
- pft = filetypes[ft_id]->priv; + ft = filetypes[ft_id]; + pft = ft->priv;
/* when reloading, proceed only if the settings were already loaded */ if (reload && G_UNLIKELY(! pft->keyfile_loaded)) @@ -1212,7 +1276,7 @@ gchar *f = g_strconcat(app->configdir, G_DIR_SEPARATOR_S GEANY_FILEDEFS_SUBDIR G_DIR_SEPARATOR_S "filetypes.", ext, NULL);
- load_system_keyfile(config, f0, G_KEY_FILE_KEEP_COMMENTS, NULL); + load_system_keyfile(config, f0, G_KEY_FILE_KEEP_COMMENTS, ft); g_key_file_load_from_file(config_home, f, G_KEY_FILE_KEEP_COMMENTS, NULL);
g_free(ext); @@ -1231,14 +1295,18 @@ gchar *filetypes_get_conf_extension(gint filetype_idx) { gchar *result; + GeanyFiletype *ft = filetypes[filetype_idx];
+ if (ft->priv->custom) + return g_strconcat(ft->name, ".conf", NULL); + /* Handle any special extensions different from lowercase filetype->name */ switch (filetype_idx) { case GEANY_FILETYPES_CPP: result = g_strdup("cpp"); break; case GEANY_FILETYPES_CS: result = g_strdup("cs"); break; case GEANY_FILETYPES_MAKE: result = g_strdup("makefile"); break; - default: result = g_ascii_strdown(filetypes[filetype_idx]->name, -1); break; + default: result = g_ascii_strdown(ft->name, -1); break; } return result; } @@ -1248,9 +1316,9 @@ { gchar *conf_prefix = g_strconcat(app->configdir, G_DIR_SEPARATOR_S GEANY_FILEDEFS_SUBDIR G_DIR_SEPARATOR_S "filetypes.", NULL); - gint i; + guint i;
- for (i = 1; i < GEANY_MAX_BUILT_IN_FILETYPES; i++) + for (i = 1; i < filetypes_array->len; i++) { GKeyFile *config_home; gchar *fname, *ext, *data;
Modified: trunk/src/filetypes.h =================================================================== --- trunk/src/filetypes.h 2009-08-31 15:46:19 UTC (rev 4142) +++ trunk/src/filetypes.h 2009-08-31 16:11:46 UTC (rev 4143) @@ -109,7 +109,7 @@ langType lang; gchar *name; /**< Used as name for tagmanager. E.g. "C". */ gchar *title; /**< Shown in the file open dialog. E.g. "C source file". */ - gchar *extension; /**< Default file extension for new files. */ + gchar *extension; /**< Default file extension for new files, or @c NULL. */ gchar **pattern; /**< Array of filename-matching wildcard strings. */ gchar *context_action_cmd; gchar *comment_open;
Modified: trunk/src/highlighting.c =================================================================== --- trunk/src/highlighting.c 2009-08-31 15:46:19 UTC (rev 4142) +++ trunk/src/highlighting.c 2009-08-31 16:11:46 UTC (rev 4143) @@ -62,7 +62,7 @@ } StyleSet;
/* each filetype has a styleset except GEANY_FILETYPES_NONE, which uses common_style_set */ -static StyleSet style_sets[GEANY_MAX_BUILT_IN_FILETYPES] = {{0, NULL, NULL, NULL}}; +static StyleSet *style_sets = NULL;
enum /* Geany common styling */ @@ -123,7 +123,7 @@ static GeanyLexerStyle gsd_default = {0x000000, 0xffffff, FALSE, FALSE};
-static void new_style_array(gint file_type_id, gint styling_count) +static void new_styleset(gint file_type_id, gint styling_count) { StyleSet *set = &style_sets[file_type_id];
@@ -132,7 +132,7 @@ }
-static void styleset_free(gint file_type_id) +static void free_styleset(gint file_type_id) { StyleSet *style_ptr; style_ptr = &style_sets[file_type_id]; @@ -402,7 +402,7 @@
static GeanyLexerStyle *get_style(guint ft_id, guint styling_index) { - g_assert(ft_id < GEANY_MAX_BUILT_IN_FILETYPES); + g_assert(ft_id < filetypes_array->len);
if (G_UNLIKELY(ft_id == GEANY_FILETYPES_NONE)) { @@ -432,13 +432,16 @@
void highlighting_free_styles() { - gint i; + guint i;
- for (i = 0; i < GEANY_MAX_BUILT_IN_FILETYPES; i++) - styleset_free(i); + for (i = 0; i < filetypes_array->len; i++) + free_styleset(i);
if (named_style_hash) g_hash_table_destroy(named_style_hash); + + if (style_sets) + g_free(style_sets); }
@@ -600,10 +603,15 @@ }
-static void styleset_common(ScintillaObject *sci) +static void styleset_common(ScintillaObject *sci, filetype_id ft_id) { SSM(sci, SCI_STYLECLEARALL, 0, 0);
+ SSM(sci, SCI_SETWORDCHARS, 0, (sptr_t) (ft_id == GEANY_FILETYPES_NONE ? + common_style_set.wordchars : style_sets[ft_id].wordchars)); + /* have to set whitespace after setting wordchars */ + SSM(sci, SCI_SETWHITESPACECHARS, 0, (sptr_t) whitespace_chars); + /* caret colour, style and width */ SSM(sci, SCI_SETCARETFORE, invert(common_style_set.styling[GCS_CARET].foreground), 0); SSM(sci, SCI_SETCARETWIDTH, common_style_set.styling[GCS_CARET].background, 0); @@ -793,13 +801,7 @@
SSM(sci, SCI_SETLEXER, lexer, 0);
- SSM(sci, SCI_SETWORDCHARS, 0, (sptr_t) style_sets[ft_id].wordchars); - /* have to set whitespace after setting wordchars */ - SSM(sci, SCI_SETWHITESPACECHARS, 0, (sptr_t) whitespace_chars); - - SSM(sci, SCI_AUTOCSETMAXHEIGHT, editor_prefs.symbolcompletion_max_height, 0); - - styleset_common(sci); + styleset_common(sci, ft_id); }
@@ -832,7 +834,7 @@ }
-/* call new_style_array(filetype_idx, >= 20) before using this. */ +/* call new_styleset(filetype_idx, >= 20) before using this. */ static void styleset_c_like_init(GKeyFile *config, GKeyFile *config_home, gint filetype_idx) { @@ -896,7 +898,7 @@
static void styleset_c_init(gint ft_id, GKeyFile *config, GKeyFile *config_home) { - new_style_array(GEANY_FILETYPES_C, 21); + new_styleset(GEANY_FILETYPES_C, 21); styleset_c_like_init(config, config_home, GEANY_FILETYPES_C); get_keyfile_int(config, config_home, "styling", "styling_within_preprocessor", 1, 0, &style_sets[GEANY_FILETYPES_C].styling[20]); @@ -935,7 +937,7 @@
static void styleset_cpp_init(gint ft_id, GKeyFile *config, GKeyFile *config_home) { - new_style_array(GEANY_FILETYPES_CPP, 21); + new_styleset(GEANY_FILETYPES_CPP, 21); styleset_c_like_init(config, config_home, GEANY_FILETYPES_CPP); get_keyfile_int(config, config_home, "styling", "styling_within_preprocessor", 1, 0, &style_sets[GEANY_FILETYPES_CPP].styling[20]); @@ -975,7 +977,7 @@
static void styleset_glsl_init(gint ft_id, GKeyFile *config, GKeyFile *config_home) { - new_style_array(GEANY_FILETYPES_GLSL, 21); + new_styleset(GEANY_FILETYPES_GLSL, 21); styleset_c_like_init(config, config_home, GEANY_FILETYPES_GLSL); get_keyfile_int(config, config_home, "styling", "styling_within_preprocessor", 1, 0, &style_sets[GEANY_FILETYPES_GLSL].styling[20]); @@ -1025,7 +1027,7 @@
static void styleset_cs_init(gint ft_id, GKeyFile *config, GKeyFile *config_home) { - new_style_array(GEANY_FILETYPES_CS, 21); + new_styleset(GEANY_FILETYPES_CS, 21); styleset_c_like_init(config, config_home, GEANY_FILETYPES_CS); get_keyfile_int(config, config_home, "styling", "styling_within_preprocessor", 1, 0, &style_sets[GEANY_FILETYPES_CS].styling[20]); @@ -1067,7 +1069,7 @@
static void styleset_vala_init(gint ft_id, GKeyFile *config, GKeyFile *config_home) { - new_style_array(GEANY_FILETYPES_VALA, 21); + new_styleset(GEANY_FILETYPES_VALA, 21); styleset_c_like_init(config, config_home, GEANY_FILETYPES_VALA); get_keyfile_int(config, config_home, "styling", "styling_within_preprocessor", 1, 0, &style_sets[GEANY_FILETYPES_VALA].styling[20]); @@ -1124,7 +1126,7 @@
static void styleset_pascal_init(gint ft_id, GKeyFile *config, GKeyFile *config_home) { - new_style_array(GEANY_FILETYPES_PASCAL, 15); + new_styleset(GEANY_FILETYPES_PASCAL, 15); get_keyfile_hex(config, config_home, "default", 0x000000, 0xffffff, FALSE, &style_sets[GEANY_FILETYPES_PASCAL].styling[0]); get_keyfile_hex(config, config_home, "identifier", 0x000000, 0xffffff, FALSE, &style_sets[GEANY_FILETYPES_PASCAL].styling[1]); get_keyfile_hex(config, config_home, "comment", 0xd00000, 0xffffff, FALSE, &style_sets[GEANY_FILETYPES_PASCAL].styling[2]); @@ -1180,7 +1182,7 @@
static void styleset_makefile_init(gint ft_id, GKeyFile *config, GKeyFile *config_home) { - new_style_array(GEANY_FILETYPES_MAKE, 7); + new_styleset(GEANY_FILETYPES_MAKE, 7); get_keyfile_hex(config, config_home, "default", 0x00002f, 0xffffff, FALSE, &style_sets[GEANY_FILETYPES_MAKE].styling[0]); 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]); @@ -1212,7 +1214,7 @@
static void styleset_diff_init(gint ft_id, GKeyFile *config, GKeyFile *config_home) { - new_style_array(GEANY_FILETYPES_DIFF, 8); + new_styleset(GEANY_FILETYPES_DIFF, 8); get_keyfile_hex(config, config_home, "default", 0x000000, 0xffffff, FALSE, &style_sets[GEANY_FILETYPES_DIFF].styling[0]); get_keyfile_hex(config, config_home, "comment", 0x808080, 0xffffff, FALSE, &style_sets[GEANY_FILETYPES_DIFF].styling[1]); get_keyfile_hex(config, config_home, "command", 0x7f7f00, 0xffffff, FALSE, &style_sets[GEANY_FILETYPES_DIFF].styling[2]); @@ -1246,7 +1248,7 @@
static void styleset_latex_init(gint ft_id, GKeyFile *config, GKeyFile *config_home) { - new_style_array(GEANY_FILETYPES_LATEX, 5); + new_styleset(GEANY_FILETYPES_LATEX, 5); get_keyfile_hex(config, config_home, "default", 0x00002f, 0xffffff, FALSE, &style_sets[GEANY_FILETYPES_LATEX].styling[0]); get_keyfile_hex(config, config_home, "command", 0xff0000, 0xffffff, TRUE, &style_sets[GEANY_FILETYPES_LATEX].styling[1]); get_keyfile_hex(config, config_home, "tag", 0x007f7f, 0xffffff, TRUE, &style_sets[GEANY_FILETYPES_LATEX].styling[2]); @@ -1316,7 +1318,7 @@
static void styleset_markup_init(gint ft_id, GKeyFile *config, GKeyFile *config_home) { - new_style_array(GEANY_FILETYPES_XML, 56); + new_styleset(GEANY_FILETYPES_XML, 56); get_keyfile_hex(config, config_home, "html_default", 0x000000, 0xffffff, FALSE, &style_sets[GEANY_FILETYPES_XML].styling[0]); get_keyfile_hex(config, config_home, "html_tag", 0x000099, 0xffffff, FALSE, &style_sets[GEANY_FILETYPES_XML].styling[1]); get_keyfile_hex(config, config_home, "html_tagunknown", 0xff0000, 0xffffff, FALSE, &style_sets[GEANY_FILETYPES_XML].styling[2]); @@ -1546,7 +1548,7 @@
static void styleset_java_init(gint ft_id, GKeyFile *config, GKeyFile *config_home) { - new_style_array(GEANY_FILETYPES_JAVA, 20); + new_styleset(GEANY_FILETYPES_JAVA, 20); styleset_c_like_init(config, config_home, GEANY_FILETYPES_JAVA);
style_sets[GEANY_FILETYPES_JAVA].keywords = g_new(gchar*, 5); @@ -1581,7 +1583,7 @@
static void styleset_perl_init(gint ft_id, GKeyFile *config, GKeyFile *config_home) { - new_style_array(GEANY_FILETYPES_PERL, 35); + new_styleset(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_named_style(config, config_home, "commentline", "comment", &style_sets[GEANY_FILETYPES_PERL].styling[2]); @@ -1703,7 +1705,7 @@
static void styleset_python_init(gint ft_id, GKeyFile *config, GKeyFile *config_home) { - new_style_array(GEANY_FILETYPES_PYTHON, 16); + new_styleset(GEANY_FILETYPES_PYTHON, 16); get_keyfile_hex(config, config_home, "default", 0x000000, 0xffffff, FALSE, &style_sets[GEANY_FILETYPES_PYTHON].styling[0]); get_keyfile_hex(config, config_home, "commentline", 0x808080, 0xffffff, FALSE, &style_sets[GEANY_FILETYPES_PYTHON].styling[1]); get_keyfile_hex(config, config_home, "number", 0x400080, 0xffffff, FALSE, &style_sets[GEANY_FILETYPES_PYTHON].styling[2]); @@ -1762,7 +1764,7 @@
static void styleset_cmake_init(gint ft_id, GKeyFile *config, GKeyFile *config_home) { - new_style_array(GEANY_FILETYPES_CMAKE, 15); + new_styleset(GEANY_FILETYPES_CMAKE, 15); get_keyfile_hex(config, config_home, "default", 0x000000, 0xffffff, FALSE, &style_sets[GEANY_FILETYPES_CMAKE].styling[0]); get_keyfile_hex(config, config_home, "comment", 0x808080, 0xffffff, FALSE, &style_sets[GEANY_FILETYPES_CMAKE].styling[1]); get_keyfile_hex(config, config_home, "stringdq", 0xff901e, 0xffffff, FALSE, &style_sets[GEANY_FILETYPES_CMAKE].styling[2]); @@ -1818,7 +1820,7 @@
static void styleset_r_init(gint ft_id, GKeyFile *config, GKeyFile *config_home) { - new_style_array(GEANY_FILETYPES_R, 12); + new_styleset(GEANY_FILETYPES_R, 12);
get_keyfile_hex(config, config_home, "default", 0x000000, 0xffffff, FALSE, &style_sets[GEANY_FILETYPES_R].styling[0]); get_keyfile_hex(config, config_home, "comment", 0x808080, 0xffffff, FALSE, &style_sets[GEANY_FILETYPES_R].styling[1]); @@ -1869,7 +1871,7 @@
static void styleset_ruby_init(gint ft_id, GKeyFile *config, GKeyFile *config_home) { - new_style_array(GEANY_FILETYPES_RUBY, 35); + new_styleset(GEANY_FILETYPES_RUBY, 35); get_keyfile_hex(config, config_home, "default", 0x000000, 0xffffff, FALSE, &style_sets[GEANY_FILETYPES_RUBY].styling[0]); 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]); @@ -1961,7 +1963,7 @@
static void styleset_sh_init(gint ft_id, GKeyFile *config, GKeyFile *config_home) { - new_style_array(GEANY_FILETYPES_SH, 14); + new_styleset(GEANY_FILETYPES_SH, 14); get_keyfile_hex(config, config_home, "default", 0x000000, 0xffffff, FALSE, &style_sets[GEANY_FILETYPES_SH].styling[0]); 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]); @@ -2022,7 +2024,7 @@
static void styleset_docbook_init(gint ft_id, GKeyFile *config, GKeyFile *config_home) { - new_style_array(GEANY_FILETYPES_DOCBOOK, 29); + new_styleset(GEANY_FILETYPES_DOCBOOK, 29); get_keyfile_hex(config, config_home, "default", 0x000000, 0xffffff, FALSE, &style_sets[GEANY_FILETYPES_DOCBOOK].styling[0]); get_keyfile_hex(config, config_home, "tag", 0x000099, 0xffffff, FALSE, &style_sets[GEANY_FILETYPES_DOCBOOK].styling[1]); get_keyfile_hex(config, config_home, "tagunknown", 0xff0000, 0xffffff, FALSE, &style_sets[GEANY_FILETYPES_DOCBOOK].styling[2]); @@ -2164,23 +2166,20 @@ }
-static void styleset_none(ScintillaObject *sci) +static void styleset_default(ScintillaObject *sci, gint ft_id) { SSM(sci, SCI_SETLEXER, SCLEX_NULL, 0);
/* we need to set STYLE_DEFAULT before we call SCI_STYLECLEARALL in styleset_common() */ set_sci_style(sci, STYLE_DEFAULT, GEANY_FILETYPES_NONE, GCS_DEFAULT);
- styleset_common(sci); - - SSM(sci, SCI_SETWORDCHARS, 0, (sptr_t) common_style_set.wordchars); - SSM(sci, SCI_SETWHITESPACECHARS, 0, (sptr_t) whitespace_chars); + styleset_common(sci, ft_id); }
static void styleset_css_init(gint ft_id, GKeyFile *config, GKeyFile *config_home) { - new_style_array(GEANY_FILETYPES_CSS, 22); + new_styleset(GEANY_FILETYPES_CSS, 22); get_keyfile_hex(config, config_home, "default", 0x003399, 0xffffff, FALSE, &style_sets[GEANY_FILETYPES_CSS].styling[0]); get_keyfile_hex(config, config_home, "comment", 0x808080, 0xffffff, FALSE, &style_sets[GEANY_FILETYPES_CSS].styling[1]); get_keyfile_hex(config, config_home, "tag", 0x2166a4, 0xffffff, TRUE, &style_sets[GEANY_FILETYPES_CSS].styling[2]); @@ -2257,7 +2256,7 @@
static void styleset_nsis_init(gint ft_id, GKeyFile *config, GKeyFile *config_home) { - new_style_array(GEANY_FILETYPES_NSIS, 19); + new_styleset(GEANY_FILETYPES_NSIS, 19); get_keyfile_hex(config, config_home, "default", 0x000000, 0xffffff, FALSE, &style_sets[GEANY_FILETYPES_NSIS].styling[0]); get_keyfile_hex(config, config_home, "comment", 0x808080, 0xffffff, FALSE, &style_sets[GEANY_FILETYPES_NSIS].styling[1]); get_keyfile_hex(config, config_home, "stringdq", 0xff901e, 0xffffff, FALSE, &style_sets[GEANY_FILETYPES_NSIS].styling[2]); @@ -2326,7 +2325,7 @@
static void styleset_po_init(gint ft_id, GKeyFile *config, GKeyFile *config_home) { - new_style_array(GEANY_FILETYPES_PO, 9); + new_styleset(GEANY_FILETYPES_PO, 9); get_keyfile_hex(config, config_home, "default", 0x7f0000, 0xffffff, FALSE, &style_sets[GEANY_FILETYPES_PO].styling[0]); get_keyfile_hex(config, config_home, "comment", 0x808080, 0xffffff, FALSE, &style_sets[GEANY_FILETYPES_PO].styling[1]); get_keyfile_hex(config, config_home, "msgid", 0x00007f, 0xffffff, TRUE, &style_sets[GEANY_FILETYPES_PO].styling[2]); @@ -2362,7 +2361,7 @@
static void styleset_conf_init(gint ft_id, GKeyFile *config, GKeyFile *config_home) { - new_style_array(GEANY_FILETYPES_CONF, 6); + new_styleset(GEANY_FILETYPES_CONF, 6); get_keyfile_hex(config, config_home, "default", 0x7f0000, 0xffffff, FALSE, &style_sets[GEANY_FILETYPES_CONF].styling[0]); get_keyfile_hex(config, config_home, "comment", 0x808080, 0xffffff, FALSE, &style_sets[GEANY_FILETYPES_CONF].styling[1]); get_keyfile_hex(config, config_home, "section", 0x000090, 0xffffff, TRUE, &style_sets[GEANY_FILETYPES_CONF].styling[2]); @@ -2394,7 +2393,7 @@
static void styleset_asm_init(gint ft_id, GKeyFile *config, GKeyFile *config_home) { - new_style_array(GEANY_FILETYPES_ASM, 15); + new_styleset(GEANY_FILETYPES_ASM, 15); get_keyfile_hex(config, config_home, "default", 0x000000, 0xffffff, FALSE, &style_sets[GEANY_FILETYPES_ASM].styling[0]); get_keyfile_hex(config, config_home, "comment", 0x808080, 0xffffff, FALSE, &style_sets[GEANY_FILETYPES_ASM].styling[1]); get_keyfile_hex(config, config_home, "number", 0x007f00, 0xffffff, FALSE, &style_sets[GEANY_FILETYPES_ASM].styling[2]); @@ -2452,7 +2451,7 @@
static void styleset_f77_init(gint ft_id, GKeyFile *config, GKeyFile *config_home) { - new_style_array(GEANY_FILETYPES_F77, 15); + new_styleset(GEANY_FILETYPES_F77, 15); get_keyfile_hex(config, config_home, "default", 0x000000, 0xffffff, FALSE, &style_sets[GEANY_FILETYPES_F77].styling[0]); get_keyfile_hex(config, config_home, "comment", 0x808080, 0xffffff, FALSE, &style_sets[GEANY_FILETYPES_F77].styling[1]); get_keyfile_hex(config, config_home, "number", 0x007f00, 0xffffff, FALSE, &style_sets[GEANY_FILETYPES_F77].styling[2]); @@ -2508,7 +2507,7 @@
static void styleset_fortran_init(gint ft_id, GKeyFile *config, GKeyFile *config_home) { - new_style_array(GEANY_FILETYPES_FORTRAN, 15); + new_styleset(GEANY_FILETYPES_FORTRAN, 15); get_keyfile_hex(config, config_home, "default", 0x000000, 0xffffff, FALSE, &style_sets[GEANY_FILETYPES_FORTRAN].styling[0]); get_keyfile_hex(config, config_home, "comment", 0x808080, 0xffffff, FALSE, &style_sets[GEANY_FILETYPES_FORTRAN].styling[1]); get_keyfile_hex(config, config_home, "number", 0x007f00, 0xffffff, FALSE, &style_sets[GEANY_FILETYPES_FORTRAN].styling[2]); @@ -2564,7 +2563,7 @@
static void styleset_sql_init(gint ft_id, GKeyFile *config, GKeyFile *config_home) { - new_style_array(GEANY_FILETYPES_SQL, 15); + new_styleset(GEANY_FILETYPES_SQL, 15); get_keyfile_hex(config, config_home, "default", 0x000000, 0xffffff, FALSE, &style_sets[GEANY_FILETYPES_SQL].styling[0]); get_keyfile_hex(config, config_home, "comment", 0x808080, 0xffffff, FALSE, &style_sets[GEANY_FILETYPES_SQL].styling[1]); get_keyfile_hex(config, config_home, "commentline", 0x808080, 0xffffff, FALSE, &style_sets[GEANY_FILETYPES_SQL].styling[2]); @@ -2643,7 +2642,7 @@
static void styleset_markdown_init(gint ft_id, GKeyFile *config, GKeyFile *config_home) { - new_style_array(GEANY_FILETYPES_MARKDOWN, 17); + new_styleset(GEANY_FILETYPES_MARKDOWN, 17);
get_keyfile_hex(config, config_home, "default", 0x000000, 0xffffff, FALSE, &style_sets[GEANY_FILETYPES_MARKDOWN].styling[0]); get_keyfile_hex(config, config_home, "strong", 0xff0000, 0xffffff, FALSE, &style_sets[GEANY_FILETYPES_MARKDOWN].styling[1]); @@ -2699,7 +2698,7 @@
static void styleset_haskell_init(gint ft_id, GKeyFile *config, GKeyFile *config_home) { - new_style_array(GEANY_FILETYPES_HASKELL, 17); + new_styleset(GEANY_FILETYPES_HASKELL, 17);
get_keyfile_hex(config, config_home, "default", 0x000000, 0xffffff, FALSE, &style_sets[GEANY_FILETYPES_HASKELL].styling[0]); get_keyfile_hex(config, config_home, "commentline", 0x808080, 0xffffff, FALSE, &style_sets[GEANY_FILETYPES_HASKELL].styling[1]); @@ -2757,7 +2756,7 @@
static void styleset_caml_init(gint ft_id, GKeyFile *config, GKeyFile *config_home) { - new_style_array(GEANY_FILETYPES_CAML, 14); + new_styleset(GEANY_FILETYPES_CAML, 14);
get_keyfile_hex(config, config_home, "default", 0x000000, 0xffffff, FALSE, &style_sets[GEANY_FILETYPES_CAML].styling[0]); get_keyfile_hex(config, config_home, "comment", 0x808080, 0xffffff, FALSE, &style_sets[GEANY_FILETYPES_CAML].styling[1]); @@ -2814,7 +2813,7 @@
static void styleset_tcl_init(gint ft_id, GKeyFile *config, GKeyFile *config_home) { - new_style_array(GEANY_FILETYPES_TCL, 16); + new_styleset(GEANY_FILETYPES_TCL, 16); get_keyfile_hex(config, config_home, "default", 0x000000, 0xffffff, FALSE, &style_sets[GEANY_FILETYPES_TCL].styling[0]); 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]); @@ -2876,7 +2875,7 @@
static void styleset_matlab_init(gint ft_id, GKeyFile *config, GKeyFile *config_home) { - new_style_array(GEANY_FILETYPES_MATLAB, 9); + new_styleset(GEANY_FILETYPES_MATLAB, 9); get_keyfile_hex(config, config_home, "default", 0x000000, 0xffffff, FALSE, &style_sets[GEANY_FILETYPES_MATLAB].styling[0]); get_keyfile_hex(config, config_home, "comment", 0x808080, 0xffffff, FALSE, &style_sets[GEANY_FILETYPES_MATLAB].styling[1]); get_keyfile_hex(config, config_home, "command", 0x111199, 0xffffff, TRUE, &style_sets[GEANY_FILETYPES_MATLAB].styling[2]); @@ -2897,8 +2896,6 @@ { const filetype_id ft_id = GEANY_FILETYPES_MATLAB;
- styleset_common(sci); - apply_filetype_properties(sci, SCLEX_MATLAB, ft_id);
SSM(sci, SCI_SETKEYWORDS, 0, (sptr_t) style_sets[GEANY_FILETYPES_MATLAB].keywords[0]); @@ -2918,7 +2915,7 @@
static void styleset_d_init(gint ft_id, GKeyFile *config, GKeyFile *config_home) { - new_style_array(GEANY_FILETYPES_D, 18); + new_styleset(GEANY_FILETYPES_D, 18);
get_keyfile_hex(config, config_home, "default", 0x000000, 0xffffff, FALSE, &style_sets[GEANY_FILETYPES_D].styling[0]); get_keyfile_hex(config, config_home, "comment", 0xd00000, 0xffffff, FALSE, &style_sets[GEANY_FILETYPES_D].styling[1]); @@ -2999,7 +2996,7 @@
static void styleset_ferite_init(gint ft_id, GKeyFile *config, GKeyFile *config_home) { - new_style_array(GEANY_FILETYPES_FERITE, 20); + new_styleset(GEANY_FILETYPES_FERITE, 20); styleset_c_like_init(config, config_home, GEANY_FILETYPES_FERITE);
style_sets[GEANY_FILETYPES_FERITE].keywords = g_new(gchar*, 4); @@ -3026,7 +3023,7 @@
static void styleset_vhdl_init(gint ft_id, GKeyFile *config, GKeyFile *config_home) { - new_style_array(GEANY_FILETYPES_VHDL, 15); + new_styleset(GEANY_FILETYPES_VHDL, 15);
get_keyfile_hex(config, config_home, "default", 0x000000, 0xffffff, FALSE, &style_sets[GEANY_FILETYPES_VHDL].styling[0]); get_keyfile_hex(config, config_home, "comment", 0xd00000, 0xffffff, FALSE, &style_sets[GEANY_FILETYPES_VHDL].styling[1]); @@ -3112,7 +3109,7 @@
static void styleset_yaml_init(gint ft_id, GKeyFile *config, GKeyFile *config_home) { - new_style_array(GEANY_FILETYPES_YAML, 10); + new_styleset(GEANY_FILETYPES_YAML, 10);
get_keyfile_hex(config, config_home, "default", 0x000000, 0xffffff, FALSE, &style_sets[GEANY_FILETYPES_YAML].styling[0]); get_keyfile_hex(config, config_home, "comment", 0x808080, 0xffffff, FALSE, &style_sets[GEANY_FILETYPES_YAML].styling[1]); @@ -3155,7 +3152,7 @@
static void styleset_js_init(gint ft_id, GKeyFile *config, GKeyFile *config_home) { - new_style_array(GEANY_FILETYPES_JS, 20); + new_styleset(GEANY_FILETYPES_JS, 20); styleset_c_like_init(config, config_home, GEANY_FILETYPES_JS);
style_sets[GEANY_FILETYPES_JS].keywords = g_new(gchar*, 2); @@ -3191,7 +3188,7 @@
static void styleset_lua_init(gint ft_id, GKeyFile *config, GKeyFile *config_home) { - new_style_array(GEANY_FILETYPES_LUA, 20); + new_styleset(GEANY_FILETYPES_LUA, 20);
get_keyfile_hex(config, config_home, "default", 0x000000, 0xffffff, FALSE, &style_sets[GEANY_FILETYPES_LUA].styling[0]); get_keyfile_hex(config, config_home, "comment", 0xd00000, 0xffffff, FALSE, &style_sets[GEANY_FILETYPES_LUA].styling[1]); @@ -3295,7 +3292,7 @@
static void styleset_basic_init(gint ft_id, GKeyFile *config, GKeyFile *config_home) { - new_style_array(GEANY_FILETYPES_BASIC, 19); + new_styleset(GEANY_FILETYPES_BASIC, 19);
get_keyfile_hex(config, config_home, "default", 0x000000, 0xffffff, FALSE, &style_sets[GEANY_FILETYPES_BASIC].styling[0]); get_keyfile_hex(config, config_home, "comment", 0x808080, 0xffffff, FALSE, &style_sets[GEANY_FILETYPES_BASIC].styling[1]); @@ -3374,7 +3371,7 @@
static void styleset_actionscript_init(gint ft_id, GKeyFile *config, GKeyFile *config_home) { - new_style_array(GEANY_FILETYPES_AS, 20); + new_styleset(GEANY_FILETYPES_AS, 20); styleset_c_like_init(config, config_home, GEANY_FILETYPES_AS);
style_sets[GEANY_FILETYPES_AS].keywords = g_new(gchar *, 4); @@ -3400,7 +3397,7 @@
static void styleset_haxe_init(gint ft_id, GKeyFile *config, GKeyFile *config_home) { - new_style_array(GEANY_FILETYPES_HAXE, 20); + new_styleset(GEANY_FILETYPES_HAXE, 20); styleset_c_like_init(config, config_home, GEANY_FILETYPES_HAXE);
style_sets[GEANY_FILETYPES_HAXE].keywords = g_new(gchar*, 4); @@ -3443,7 +3440,7 @@
static void styleset_ada_init(gint ft_id, GKeyFile *config, GKeyFile *config_home) { - new_style_array(GEANY_FILETYPES_ADA, 12); + new_styleset(GEANY_FILETYPES_ADA, 12);
get_keyfile_hex(config, config_home, "default", 0x000000, 0xffffff, FALSE, &style_sets[GEANY_FILETYPES_ADA].styling[0]); get_keyfile_hex(config, config_home, "word", 0x00007f, 0xffffff, TRUE, &style_sets[GEANY_FILETYPES_ADA].styling[1]); @@ -3497,9 +3494,12 @@ /* Called by filetypes_load_config(). */ void highlighting_init_styles(gint filetype_idx, GKeyFile *config, GKeyFile *configh) { - /* Clear old information if necessary - e.g. reloading config */ - styleset_free(filetype_idx); + if (!style_sets) + style_sets = g_new0(StyleSet, filetypes_array->len);
+ /* Clear old information if necessary - e.g. when reloading config */ + free_styleset(filetype_idx); + /* All stylesets depend on filetypes.common */ if (filetype_idx != GEANY_FILETYPES_NONE) filetypes_load_config(GEANY_FILETYPES_NONE, FALSE); @@ -3616,8 +3616,9 @@ styleset_case(GEANY_FILETYPES_VHDL, styleset_vhdl); styleset_case(GEANY_FILETYPES_XML, styleset_xml); styleset_case(GEANY_FILETYPES_YAML, styleset_yaml); + case GEANY_FILETYPES_NONE: default: - styleset_case(GEANY_FILETYPES_NONE, styleset_none); + styleset_default(sci, filetype_idx); } }
@@ -3632,7 +3633,7 @@ * @see Scintilla messages @c SCI_STYLEGETFORE, etc, for use with ScintillaFuncs::send_message(). */ const GeanyLexerStyle *highlighting_get_style(gint ft_id, gint style_id) { - if (ft_id < 0 || ft_id > GEANY_MAX_BUILT_IN_FILETYPES) + if (ft_id < 0 || ft_id >= (gint)filetypes_array->len) return NULL;
/* ensure filetype loaded */
Modified: trunk/src/main.c =================================================================== --- trunk/src/main.c 2009-08-31 15:46:19 UTC (rev 4142) +++ trunk/src/main.c 2009-08-31 16:11:46 UTC (rev 4143) @@ -1078,7 +1078,6 @@ navqueue_free(); keybindings_free(); filetypes_save_commands(); - filetypes_free_types(); highlighting_free_styles(); templates_free_templates(); msgwin_finalize(); @@ -1093,6 +1092,7 @@ toolbar_finalize(); treeviews_finalize(); configuration_finalize(); + filetypes_free_types(); log_finalize();
tm_workspace_free(TM_WORK_OBJECT(app->tm_workspace));
Modified: trunk/src/symbols.c =================================================================== --- trunk/src/symbols.c 2009-08-31 15:46:19 UTC (rev 4142) +++ trunk/src/symbols.c 2009-08-31 16:11:46 UTC (rev 4143) @@ -1487,15 +1487,16 @@
static void load_user_tags(filetype_id ft_id) { - static guchar tags_loaded[GEANY_MAX_BUILT_IN_FILETYPES] = {0}; + static guchar *tags_loaded = NULL; static GHashTable *lang_hash = NULL; GList *fnames; const GList *node; GeanyFiletype *ft = filetypes[ft_id];
g_return_if_fail(ft_id > 0); - g_return_if_fail(ft_id < GEANY_MAX_BUILT_IN_FILETYPES);
+ if (!tags_loaded) + tags_loaded = g_new0(guchar, filetypes_array->len); if (tags_loaded[ft_id]) return; tags_loaded[ft_id] = TRUE; /* prevent reloading */
Modified: trunk/src/templates.c =================================================================== --- trunk/src/templates.c 2009-08-31 15:46:19 UTC (rev 4142) +++ trunk/src/templates.c 2009-08-31 16:11:46 UTC (rev 4143) @@ -242,6 +242,8 @@ ";
static gchar *templates[GEANY_MAX_TEMPLATES]; + +/* TODO: remove filetype templates, use custom file templates instead. */ static gchar *ft_templates[GEANY_MAX_BUILT_IN_FILETYPES] = {NULL};
@@ -686,7 +688,7 @@
if (fname == NULL) { - if (ft_id == GEANY_FILETYPES_NONE) + if (!ft->extension) shortname = g_strdup(GEANY_STRING_UNTITLED); else shortname = g_strconcat(GEANY_STRING_UNTITLED, ".", ft->extension, NULL);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.