Hi Nick.
I have just written a fix to prevent leaks, and changed iterating over
opened documents to be more efficient. I attach the new patch, it should
be applied instead of the previous one.
diff --git a/src/document.c b/src/document.c
index 408ca53..6f37103 100644
--- a/src/document.c
+++ b/src/document.c
@@ -106,6 +106,8 @@ typedef struct
static void document_undo_clear(GeanyDocument *doc);
static void document_redo_add(GeanyDocument *doc, guint type, gpointer data);
static gboolean update_tags_from_buffer(GeanyDocument *doc);
+static void document_load_config(GeanyDocument *doc, GeanyFiletype *type,
+ gboolean filetype_changed);
/* ignore the case of filenames and paths under WIN32, causes errors if not */
@@ -2459,25 +2461,14 @@ static gboolean update_type_keywords(GeanyDocument *doc, gint lang)
return ret;
}
-
-/** Sets the filetype of the document (which controls syntax highlighting and tags)
- * @param doc The document to use.
- * @param type The filetype. */
-void document_set_filetype(GeanyDocument *doc, GeanyFiletype *type)
+static void document_load_config(GeanyDocument *doc, GeanyFiletype *type,
+ gboolean filetype_changed)
{
- gboolean ft_changed;
-
g_return_if_fail(doc);
if (type == NULL)
type = filetypes[GEANY_FILETYPES_NONE];
- geany_debug("%s : %s (%s)",
- (doc->file_name != NULL) ? doc->file_name : "unknown",
- (type->name != NULL) ? type->name : "unknown",
- (doc->encoding != NULL) ? doc->encoding : "unknown");
-
- ft_changed = (doc->file_type != type);
- if (ft_changed) /* filetype has changed */
+ if (filetype_changed)
{
doc->file_type = type;
@@ -2500,6 +2491,32 @@ void document_set_filetype(GeanyDocument *doc, GeanyFiletype *type)
}
+/** Sets the filetype of the document (which controls syntax highlighting and tags)
+ * @param doc The document to use.
+ * @param type The filetype. */
+void document_set_filetype(GeanyDocument *doc, GeanyFiletype *type)
+{
+ gboolean ft_changed;
+
+ g_return_if_fail(doc);
+ if (type == NULL)
+ type = filetypes[GEANY_FILETYPES_NONE];
+
+ geany_debug("%s : %s (%s)",
+ (doc->file_name != NULL) ? doc->file_name : "unknown",
+ (type->name != NULL) ? type->name : "unknown",
+ (doc->encoding != NULL) ? doc->encoding : "unknown");
+
+ ft_changed = (doc->file_type != type); /* filetype has changed */
+ document_load_config(doc, type, ft_changed);
+}
+
+void document_reload_config(GeanyDocument *doc)
+{
+ document_load_config(doc, doc->file_type, TRUE);
+}
+
+
/**
* Sets the encoding of a %document.
* This function only set the encoding of the %document, it does not any conversions. The new
diff --git a/src/document.h b/src/document.h
index c560a32..66e1dd5 100644
--- a/src/document.h
+++ b/src/document.h
@@ -154,6 +154,8 @@ void document_set_text_changed(GeanyDocument *doc, gboolean changed);
void document_set_filetype(GeanyDocument *doc, GeanyFiletype *type);
+void document_reload_config(GeanyDocument *doc);
+
void document_rename_file(GeanyDocument *doc, const gchar *new_filename);
GeanyDocument *document_index(gint idx);
diff --git a/src/filetypes.c b/src/filetypes.c
index 8175f29..567a0dc 100644
--- a/src/filetypes.c
+++ b/src/filetypes.c
@@ -1226,9 +1226,7 @@ void filetypes_load_config(gint ft_id, gboolean reload)
}
load_settings(ft_id, config, config_home);
- if (! reload)
- /* reloading highlighting settings not yet supported */
- highlighting_init_styles(ft_id, config, config_home);
+ highlighting_init_styles(ft_id, config, config_home);
g_key_file_free(config);
g_key_file_free(config_home);
diff --git a/src/highlighting.c b/src/highlighting.c
index c7ad1bf..5280328 100644
--- a/src/highlighting.c
+++ b/src/highlighting.c
@@ -129,6 +129,21 @@ static void new_style_array(gint file_type_id, gint styling_count)
}
+static void styleset_free(gint file_type_id)
+{
+ StyleSet *style_ptr;
+ style_ptr = &style_sets[file_type_id];
+
+ style_ptr->count = 0;
+ g_free(style_ptr->styling);
+ style_ptr->styling = NULL;
+ g_strfreev(style_ptr->keywords);
+ style_ptr->keywords = NULL;
+ g_free(style_ptr->wordchars);
+ style_ptr->wordchars = NULL;
+}
+
+
static void get_keyfile_keywords(GKeyFile *config, GKeyFile *configh,
const gchar *key, gint ft_id, gint pos, const gchar *default_value)
{
@@ -423,15 +438,7 @@ void highlighting_free_styles()
gint i;
for (i = 0; i < GEANY_MAX_BUILT_IN_FILETYPES; i++)
- {
- StyleSet *style_ptr;
- style_ptr = &style_sets[i];
-
- style_ptr->count = 0;
- g_free(style_ptr->styling);
- g_strfreev(style_ptr->keywords);
- g_free(style_ptr->wordchars);
- }
+ styleset_free(i);
if (named_style_hash)
g_hash_table_destroy(named_style_hash);
@@ -530,7 +537,10 @@ static void styleset_common_init(gint ft_id, GKeyFile *config, GKeyFile *config_
common_style_set_valid = TRUE; /* ensure filetypes.common is only loaded once */
/* named styles */
- named_style_hash = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
+ if (named_style_hash)
+ g_hash_table_remove_all(named_style_hash);
+ else
+ named_style_hash = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
/* first set default to the "default" named style */
add_named_style(config, "default");
@@ -3560,6 +3570,9 @@ static void styleset_ada(ScintillaObject *sci)
/* Called by filetypes_load_config(). */
void highlighting_init_styles(gint filetype_idx, GKeyFile *config, GKeyFile *configh)
{
+ /* Clear old information if necessary */
+ styleset_free(filetype_idx);
+
/* All stylesets depend on filetypes.common */
if (filetype_idx != GEANY_FILETYPES_NONE)
filetypes_load_config(GEANY_FILETYPES_NONE, FALSE);
diff --git a/src/main.c b/src/main.c
index 6a0cec5..870ff36 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1233,6 +1233,13 @@ void main_reload_configuration(void)
filetypes_load_config(i, TRUE);
}
+ for (i = 0; i < documents_array->len; i++)
+ {
+ GeanyDocument *doc = documents[i];
+ if (doc->is_valid)
+ document_reload_config(doc);
+ }
+
/* C tag names to ignore */
symbols_reload_config_files();
_______________________________________________
Geany-devel mailing list
[email protected]
http://lists.uvena.de/cgi-bin/mailman/listinfo/geany-devel