diff --git a/ChangeLog b/ChangeLog index 476ffed87..7f881a7d8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,6 +4,12 @@ Fix type definitions being parsed as functions. * src/editor.c: Don't autocomplete in unterminated strings as well. + * src/templates.c, src/utils.h, src/dialogs.c, src/plugindata.h, + src/filetypes.c, src/ui_utils.c, plugins/saveactions.c: + Remove data_ptr argument to foreach_[s]list() macros, as using + node->data is enough sometimes; this makes the macro a bit more + efficient too. + Add foreach_[s]list() macros to the plugin API docs. 2009-06-11 Nick Treleaven diff --git a/plugins/saveactions.c b/plugins/saveactions.c index 6e2637652..538bd4bfe 100644 --- a/plugins/saveactions.c +++ b/plugins/saveactions.c @@ -42,7 +42,7 @@ GeanyData *geany_data; GeanyFunctions *geany_functions; -PLUGIN_VERSION_CHECK(98) +PLUGIN_VERSION_CHECK(GEANY_API_VERSION) PLUGIN_SET_INFO(_("Save Actions"), _("This plugin provides different actions related to saving of files."), VERSION, _("The Geany developer team")) @@ -604,7 +604,6 @@ GtkWidget *plugin_configure(GtkDialog *dialog) GtkWidget *combo; guint i; GSList *node; - GeanyFiletype *ft; notebook_vbox = gtk_vbox_new(FALSE, 2); inner_vbox = gtk_vbox_new(FALSE, 5); @@ -627,8 +626,10 @@ GtkWidget *plugin_configure(GtkDialog *dialog) pref_widgets.instantsave_ft_combo = combo = gtk_combo_box_new_text(); i = 0; - foreach_slist(ft, node, geany->filetypes_by_title) + foreach_slist(node, geany->filetypes_by_title) { + GeanyFiletype *ft = node->data; + gtk_combo_box_append_text(GTK_COMBO_BOX(combo), ft->name); if (utils_str_equal(ft->name, instantsave_default_ft)) diff --git a/src/dialogs.c b/src/dialogs.c index 54d3f656c..10a5817fb 100644 --- a/src/dialogs.c +++ b/src/dialogs.c @@ -135,7 +135,6 @@ static void create_open_file_dialog(void) GtkWidget *viewbtn; guint i; gchar *encoding_string; - GeanyFiletype *ft; GSList *node; ui_widgets.open_filesel = gtk_file_chooser_dialog_new(_("Open File"), GTK_WINDOW(main_widgets.window), @@ -174,8 +173,10 @@ static void create_open_file_dialog(void) /* now create meta filter "All Source" */ gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(ui_widgets.open_filesel), filetypes_create_file_filter_all_source()); - foreach_slist(ft, node, filetypes_by_title) + foreach_slist(node, filetypes_by_title) { + GeanyFiletype *ft = node->data; + if (G_UNLIKELY(ft->id == GEANY_FILETYPES_NONE)) continue; gtk_combo_box_append_text(GTK_COMBO_BOX(filetype_combo), ft->title); diff --git a/src/filetypes.c b/src/filetypes.c index f03b29623..6b07ef810 100644 --- a/src/filetypes.c +++ b/src/filetypes.c @@ -1492,10 +1492,11 @@ GeanyFiletype *filetypes_index(gint idx) void filetypes_foreach_named(GFunc callback, gpointer user_data) { GSList *node; - GeanyFiletype *ft; - foreach_slist(ft, node, filetypes_by_title) + foreach_slist(node, filetypes_by_title) { + GeanyFiletype *ft = node->data; + if (G_LIKELY(ft->id != GEANY_FILETYPES_NONE)) callback(ft, user_data); } diff --git a/src/plugindata.h b/src/plugindata.h index 4cee5bea0..3938a004d 100644 --- a/src/plugindata.h +++ b/src/plugindata.h @@ -45,7 +45,7 @@ enum { /** The Application Programming Interface (API) version, incremented * whenever any plugin data types are modified or appended to. */ - GEANY_API_VERSION = 141, + GEANY_API_VERSION = 142, /** The Application Binary Interface (ABI) version, incremented whenever * existing fields in the plugin data types have to be changed or reordered. */ diff --git a/src/templates.c b/src/templates.c index 28a812cbc..97d8e3c81 100644 --- a/src/templates.c +++ b/src/templates.c @@ -362,16 +362,15 @@ on_new_with_template (GtkMenuItem *menuitem, /* template items for the new file menu */ static void create_new_menu_items(void) { - GeanyFiletype *ft; GSList *node; - foreach_slist(ft, node, filetypes_by_title) + foreach_slist(node, filetypes_by_title) { - filetype_id ft_id = ft->id; + GeanyFiletype *ft = node->data; GtkWidget *tmp_menu, *tmp_button; const gchar *label = ft->title; - if (ft_templates[ft_id] == NULL) + if (ft_templates[ft->id] == NULL) continue; tmp_menu = gtk_menu_item_new_with_label(label); diff --git a/src/ui_utils.c b/src/ui_utils.c index 061626010..b79eb6425 100644 --- a/src/ui_utils.c +++ b/src/ui_utils.c @@ -2056,14 +2056,13 @@ void ui_menu_sort_by_label(GtkMenu *menu) { GList *list = gtk_container_get_children(GTK_CONTAINER(menu)); GList *node; - GtkWidget *child; gint pos; list = g_list_sort(list, compare_menu_item_labels); pos = 0; - foreach_list(child, node, list) + foreach_list(node, list) { - gtk_menu_reorder_child(menu, child, pos); + gtk_menu_reorder_child(menu, node->data, pos); pos++; } g_list_free(list); diff --git a/src/utils.h b/src/utils.h index 87b389bfd..5751e27ec 100644 --- a/src/utils.h +++ b/src/utils.h @@ -57,15 +57,17 @@ for (ptr = ptr_array->pdata, item = *ptr; \ ptr < &ptr_array->pdata[ptr_array->len]; ++ptr, item = *ptr) -/* @param node should be a (GSList*), needed for implementation. */ -#define foreach_slist(data_ptr, node, list) \ - for (node = list, data_ptr = node ? node->data : NULL; node != NULL; \ - node = g_slist_next(node), data_ptr = node ? node->data : NULL) +/** Iterates all the nodes in @a list. + * @param node should be a (GList*). + * @param list List to traverse. */ +#define foreach_list(node, list) \ + for (node = list; node != NULL; node = node->next) -/* @param node should be a (GList*), needed for implementation. */ -#define foreach_list(data_ptr, node, list) \ - for (node = list, data_ptr = node ? node->data : NULL; node != NULL; \ - node = g_list_next(node), data_ptr = node ? node->data : NULL) +/** Iterates all the nodes in @a list. + * @param node should be a (GSList*). + * @param list List to traverse. */ +#define foreach_slist(node, list) \ + foreach_list(node, list) void utils_open_browser(const gchar *uri);