Revision: 1186 http://svn.sourceforge.net/geany/?rev=1186&view=rev Author: eht16 Date: 2007-01-14 09:09:17 -0800 (Sun, 14 Jan 2007)
Log Message: ----------- Added sci_set_use_tabs(). Fixed mem leak in sci_cb_auto_forif(). Moved free_pointers() to utils.c. Applied patch from Jeff Pohlmeyer to add an option for using spaces or tabulators when inserting some whitespace.
Modified Paths: -------------- trunk/ChangeLog trunk/geany.glade trunk/src/build.c trunk/src/document.c trunk/src/geany.h trunk/src/highlighting.c trunk/src/interface.c trunk/src/keyfile.c trunk/src/prefs.c trunk/src/sci_cb.c trunk/src/sciwrappers.c trunk/src/sciwrappers.h trunk/src/utils.c trunk/src/utils.h
Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2007-01-14 13:36:30 UTC (rev 1185) +++ trunk/ChangeLog 2007-01-14 17:09:17 UTC (rev 1186) @@ -1,3 +1,16 @@ +2007-01-14 Enrico Tröger enrico.troeger@uvena.de + + * geany.glade, src/build.c, src/document.c, src/geany.h, + src/highlighting.c, src/interface.c, src/keyfile.c, src/prefs.c, + src/sci_cb.c, src/sci_wrappers.c, src/sciwrappers.h, src/utils.c, + src/utils.h: + Added sci_set_use_tabs(). + Fixed mem leak in sci_cb_auto_forif(). + Moved free_pointers() to utils.c. + Applied patch from Jeff Pohlmeyer to add an option for using spaces + or tabulators when inserting some whitespace. + + 2007-01-14 Nick Treleaven nick.treleaven@btinternet.com
* src/treeviews.c, src/treeviews.h, src/symbols.c, po/POTFILES.in:
Modified: trunk/geany.glade =================================================================== --- trunk/geany.glade 2007-01-14 13:36:30 UTC (rev 1185) +++ trunk/geany.glade 2007-01-14 17:09:17 UTC (rev 1186) @@ -5237,6 +5237,26 @@ <property name="fill">False</property> </packing> </child> + + <child> + <widget class="GtkCheckButton" id="check_use_tabs"> + <property name="visible">True</property> + <property name="tooltip" translatable="yes">Whenever some whitespace is inserted by Geany it will use tabluators when enabled otherwise Geany will use just spaces.</property> + <property name="can_focus">True</property> + <property name="label" translatable="yes">Use tabulators when inserting whitespace</property> + <property name="use_underline">True</property> + <property name="relief">GTK_RELIEF_NORMAL</property> + <property name="focus_on_click">False</property> + <property name="active">False</property> + <property name="inconsistent">False</property> + <property name="draw_indicator">True</property> + </widget> + <packing> + <property name="padding">0</property> + <property name="expand">False</property> + <property name="fill">False</property> + </packing> + </child> </widget> </child> </widget>
Modified: trunk/src/build.c =================================================================== --- trunk/src/build.c 2007-01-14 13:36:30 UTC (rev 1185) +++ trunk/src/build.c 2007-01-14 17:09:17 UTC (rev 1186) @@ -1,7 +1,8 @@ /* * build.c - this file is part of Geany, a fast and lightweight IDE * - * Copyright 2006 Enrico Troeger enrico.troeger@uvena.de + * Copyright 2005-2007 Enrico Troeger enrico.troeger@uvena.de + * Copyright 2006-2007 Nick Treleaven nick.treleaven@btinternet.com * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -29,7 +30,6 @@ #include <sys/stat.h> #include <unistd.h> #include <errno.h> -#include <stdarg.h>
#ifdef G_OS_UNIX # include <sys/types.h> @@ -78,7 +78,6 @@ static void set_stop_button(gboolean stop); static void build_exit_cb(GPid child_pid, gint status, gpointer user_data); static void run_exit_cb(GPid child_pid, gint status, gpointer user_data); -static void free_pointers(gpointer first, ...);
#ifndef G_OS_WIN32 static void kill_process(GPid *pid); @@ -154,7 +153,7 @@ if (stat(locale_filename, &st) != 0) { msgwin_status_add(_("Failed to view %s (make sure it is already compiled)"), view_file); - free_pointers(executable, view_file, locale_filename, script_name); + utils_free_pointers(executable, view_file, locale_filename, script_name, NULL);
return (GPid) 1; } @@ -189,8 +188,8 @@ _("Could not find terminal '%s' " "(check path for Terminal tool setting in Preferences)"), app->tools_term_cmd);
- free_pointers(executable, view_file, locale_filename, cmd_string, locale_cmd_string, - script_name, locale_term_cmd); + utils_free_pointers(executable, view_file, locale_filename, cmd_string, locale_cmd_string, + script_name, locale_term_cmd, NULL); g_strfreev(term_argv); return (GPid) 1; } @@ -202,8 +201,8 @@ gchar *utf8_check_executable = utils_remove_ext_from_filename(doc_list[idx].file_name); msgwin_status_add(_("Failed to execute %s (start-script could not be created)"), utf8_check_executable); - free_pointers(executable, view_file, locale_filename, cmd_string, locale_cmd_string, - utf8_check_executable, script_name, locale_term_cmd); + utils_free_pointers(executable, view_file, locale_filename, cmd_string, locale_cmd_string, + utf8_check_executable, script_name, locale_term_cmd, NULL); g_strfreev(term_argv); return (GPid) 1; } @@ -230,8 +229,8 @@ geany_debug("g_spawn_async_with_pipes() failed: %s", error->message); msgwin_status_add(_("Process failed (%s)"), error->message);
- free_pointers(executable, view_file, locale_filename, cmd_string, locale_cmd_string, - script_name, locale_term_cmd); + utils_free_pointers(executable, view_file, locale_filename, cmd_string, locale_cmd_string, + script_name, locale_term_cmd, NULL); g_strfreev(argv); g_strfreev(term_argv); g_error_free(error); @@ -246,8 +245,8 @@ build_menu_update(idx); }
- free_pointers(executable, view_file, locale_filename, cmd_string, locale_cmd_string, - script_name, locale_term_cmd); + utils_free_pointers(executable, view_file, locale_filename, cmd_string, locale_cmd_string, + script_name, locale_term_cmd, NULL); g_strfreev(argv); g_strfreev(term_argv);
@@ -1513,25 +1512,6 @@ #endif
-// frees all passed pointers if they are non-NULL, the first argument is nothing special, -// it will also be freed -static void free_pointers(gpointer first, ...) -{ - va_list a; - gpointer sa; - - for (va_start(a, first); (sa = va_arg(a, gpointer), sa!=NULL);) - { - if (sa != NULL) - g_free(sa); - } - va_end(a); - - if (first != NULL) - g_free(first); -} - - void on_build_next_error (GtkMenuItem *menuitem, gpointer user_data)
Modified: trunk/src/document.c =================================================================== --- trunk/src/document.c 2007-01-14 13:36:30 UTC (rev 1185) +++ trunk/src/document.c 2007-01-14 17:09:17 UTC (rev 1186) @@ -179,6 +179,8 @@ sci_set_mark_long_lines(sci, app->long_line_type, app->long_line_column, app->long_line_color);
sci_set_tab_width(sci, app->pref_editor_tab_width); + sci_set_use_tabs(sci, app->pref_editor_use_tabs); + sci_set_autoc_max_height(sci, app->autocompletion_max_height);
sci_set_indentionguides(sci, app->pref_editor_show_indent_guide);
Modified: trunk/src/geany.h =================================================================== --- trunk/src/geany.h 2007-01-14 13:36:30 UTC (rev 1185) +++ trunk/src/geany.h 2007-01-14 17:09:17 UTC (rev 1186) @@ -110,6 +110,7 @@ gboolean pref_editor_folding; gboolean pref_editor_unfold_all_children; gint pref_editor_tab_width; + gboolean pref_editor_use_tabs; gint pref_editor_default_encoding; gboolean pref_editor_new_line; gboolean pref_editor_replace_tabs;
Modified: trunk/src/highlighting.c =================================================================== --- trunk/src/highlighting.c 2007-01-14 13:36:30 UTC (rev 1185) +++ trunk/src/highlighting.c 2007-01-14 17:09:17 UTC (rev 1186) @@ -426,8 +426,6 @@
SSM(sci, SCI_STYLECLEARALL, 0, 0);
- SSM(sci, SCI_SETUSETABS, TRUE, 0); - // caret colour SSM(sci, SCI_SETCARETFORE, invert(common_style_set.styling[GCS_CARET].foreground), 0);
Modified: trunk/src/interface.c =================================================================== --- trunk/src/interface.c 2007-01-14 13:36:30 UTC (rev 1185) +++ trunk/src/interface.c 2007-01-14 17:09:17 UTC (rev 1186) @@ -2304,6 +2304,7 @@ GtkWidget *check_unfold_children; GtkWidget *check_indicators; GtkWidget *check_disable_dnd; + GtkWidget *check_use_tabs; GtkWidget *label172; GtkWidget *frame18; GtkWidget *alignment21; @@ -3202,6 +3203,12 @@ gtk_tooltips_set_tip (tooltips, check_disable_dnd, _("Disable drag and drop completely in the editor window so you can't drag and drop any selections within or outside of the editor window."), NULL); gtk_button_set_focus_on_click (GTK_BUTTON (check_disable_dnd), FALSE);
+ check_use_tabs = gtk_check_button_new_with_mnemonic (_("Use tabulators when inserting whitespace")); + gtk_widget_show (check_use_tabs); + gtk_box_pack_start (GTK_BOX (vbox17), check_use_tabs, FALSE, FALSE, 0); + gtk_tooltips_set_tip (tooltips, check_use_tabs, _("Whenever some whitespace is inserted by Geany it will use tabluators when enabled otherwise Geany will use just spaces."), NULL); + gtk_button_set_focus_on_click (GTK_BUTTON (check_use_tabs), FALSE); + label172 = gtk_label_new (_("<b>Features</b>")); gtk_widget_show (label172); gtk_frame_set_label_widget (GTK_FRAME (frame14), label172); @@ -3733,6 +3740,7 @@ GLADE_HOOKUP_OBJECT (prefs_dialog, check_unfold_children, "check_unfold_children"); GLADE_HOOKUP_OBJECT (prefs_dialog, check_indicators, "check_indicators"); GLADE_HOOKUP_OBJECT (prefs_dialog, check_disable_dnd, "check_disable_dnd"); + GLADE_HOOKUP_OBJECT (prefs_dialog, check_use_tabs, "check_use_tabs"); GLADE_HOOKUP_OBJECT (prefs_dialog, label172, "label172"); GLADE_HOOKUP_OBJECT (prefs_dialog, frame18, "frame18"); GLADE_HOOKUP_OBJECT (prefs_dialog, alignment21, "alignment21");
Modified: trunk/src/keyfile.c =================================================================== --- trunk/src/keyfile.c 2007-01-14 13:36:30 UTC (rev 1185) +++ trunk/src/keyfile.c 2007-01-14 17:09:17 UTC (rev 1186) @@ -1,7 +1,8 @@ /* * keyfile.c - this file is part of Geany, a fast and lightweight IDE * - * Copyright 2006 Enrico Troeger enrico.troeger@uvena.de + * Copyright 2005-2007 Enrico Troeger enrico.troeger@uvena.de + * Copyright 2006-2007 Nick Treleaven nick.treleaven@btinternet.com * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -155,6 +156,7 @@ g_key_file_set_integer_list(config, PACKAGE, "geometry", app->geometry, 4); } g_key_file_set_integer(config, PACKAGE, "pref_editor_tab_width", app->pref_editor_tab_width); + g_key_file_set_boolean(config, PACKAGE, "pref_editor_use_tabs", app->pref_editor_use_tabs); g_key_file_set_boolean(config, PACKAGE, "pref_main_confirm_exit", app->pref_main_confirm_exit); g_key_file_set_boolean(config, PACKAGE, "pref_main_suppress_search_dialogs", app->pref_main_suppress_search_dialogs); g_key_file_set_boolean(config, PACKAGE, "pref_main_load_session", app->pref_main_load_session); @@ -354,6 +356,7 @@
app->pref_editor_tab_width = utils_get_setting_integer(config, PACKAGE, "pref_editor_tab_width", 4); + app->pref_editor_use_tabs = utils_get_setting_boolean(config, PACKAGE, "pref_editor_use_tabs", TRUE); tmp_string = utils_get_setting_string(config, PACKAGE, "pref_editor_default_encoding", encodings[GEANY_ENCODING_UTF_8].charset); if (tmp_string)
Modified: trunk/src/prefs.c =================================================================== --- trunk/src/prefs.c 2007-01-14 13:36:30 UTC (rev 1185) +++ trunk/src/prefs.c 2007-01-14 17:09:17 UTC (rev 1186) @@ -1,7 +1,8 @@ /* * prefs.c - this file is part of Geany, a fast and lightweight IDE * - * Copyright 2006 Enrico Troeger enrico.troeger@uvena.de + * Copyright 2005-2007 Enrico Troeger enrico.troeger@uvena.de + * Copyright 2006-2007 Nick Treleaven nick.treleaven@btinternet.com * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -250,6 +251,9 @@ widget = lookup_widget(app->prefs_dialog, "check_disable_dnd"); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), app->pref_editor_disable_dnd);
+ widget = lookup_widget(app->prefs_dialog, "check_use_tabs"); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), app->pref_editor_use_tabs); + widget = lookup_widget(app->prefs_dialog, "check_indicators"); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), app->pref_editor_use_indicators);
@@ -556,6 +560,9 @@ widget = lookup_widget(app->prefs_dialog, "check_disable_dnd"); app->pref_editor_disable_dnd = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
+ widget = lookup_widget(app->prefs_dialog, "check_use_tabs"); + app->pref_editor_use_tabs = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); + widget = lookup_widget(app->prefs_dialog, "spin_autocheight"); app->autocompletion_max_height = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget));
Modified: trunk/src/sci_cb.c =================================================================== --- trunk/src/sci_cb.c 2007-01-14 13:36:30 UTC (rev 1185) +++ trunk/src/sci_cb.c 2007-01-14 17:09:17 UTC (rev 1186) @@ -321,9 +321,10 @@ if (doc_list[idx].file_type->id == GEANY_FILETYPES_PYTHON && sci_get_char_at(sci, pos - 2) == ':' && sci_get_style_at(sci, pos - 2) == SCE_P_OPERATOR) - { - /// TODO add something like insert_tabs() which inserts a tab or tab_width times a space - sci_add_text(sci, "\t"); + { // creates and inserts one tabulator sign or whitespace of the amount of the tab width + gchar *text = utils_get_whitespace(app->pref_editor_tab_width); + sci_add_text(sci, text); + g_free(text); }
} @@ -353,7 +354,17 @@ // and ignore the case of sci_cb_close_block else if (linebuf[i] == '{' && ! use_this_line) { - indent[j++] = '\t'; + if (app->pref_editor_use_tabs) + { + indent[j++] = '\t'; + } + else + { // insert as many spaces as a tabulator would take + gint i; + for (i = 0; i < app->pref_editor_tab_width; i++) + indent[j++] = ' '; + } + break; } else @@ -363,7 +374,19 @@ while (k > 0 && isspace(linebuf[k])) k--; // if last non-whitespace character is a { increase indention by a tab // e.g. for (...) { - if (linebuf[k] == '{') indent[j++] = '\t'; + if (linebuf[k] == '{') + { + if (app->pref_editor_use_tabs) + { + indent[j++] = '\t'; + } + else + { // insert as many spaces as a tabulator would take + gint i; + for (i = 0; i < app->pref_editor_use_tabs; i++) + indent[j++] = ' '; + } + } break; } } @@ -865,10 +888,12 @@ { static gchar buf[16]; gchar *eol; + gchar *space; gchar *construct; gint lexer, style; gint i; gint last_pos; + gint space_len; ScintillaObject *sci;
if (idx == -1 || ! doc_list[idx].is_valid || doc_list[idx].file_type == NULL) return; @@ -895,7 +920,7 @@ if (lexer == SCLEX_HTML && ! (style >= SCE_HPHP_DEFAULT && style <= SCE_HPHP_OPERATOR)) return;
- // get the indention + // get the indentation if (doc_list[idx].use_auto_indention) get_indent(sci, pos, TRUE); eol = g_strconcat(utils_get_eol_char(idx), indent, NULL); sci_get_text_range(sci, pos - 16, pos - 1, buf); @@ -912,16 +937,20 @@ i--; }
+ // get the whitespace for additional indentation + space = utils_get_whitespace(app->pref_editor_tab_width); + space_len = strlen(space); + // "pattern", buf + x, y -> x + y = 15, because buf is (pos - 16)...(pos - 1) = 15 if (! strncmp("if", buf + 13, 2)) { if (! isspace(*(buf + 12))) { - g_free(eol); + utils_free_pointers(eol, space, NULL); return; }
- construct = g_strdup_printf("()%s{%s\t%s}%s", eol, eol, eol, eol); + construct = g_strdup_printf("()%s{%s%s%s}%s", eol, eol, space, eol, eol);
SSM(sci, SCI_INSERTTEXT, pos, (sptr_t) construct); sci_goto_pos(sci, pos + 1, TRUE); @@ -931,14 +960,14 @@ { if (! isspace(*(buf + 10))) { - g_free(eol); + utils_free_pointers(eol, space, NULL); return; }
- construct = g_strdup_printf("%s{%s\t%s}%s", eol, eol, eol, eol); + construct = g_strdup_printf("%s{%s%s%s}%s", eol, eol, space, eol, eol);
SSM(sci, SCI_INSERTTEXT, pos, (sptr_t) construct); - sci_goto_pos(sci, pos + 4 + (2 * strlen(indent)), TRUE); + sci_goto_pos(sci, pos + 3 + space_len + (2 * strlen(indent)), TRUE); g_free(construct); } else if (! strncmp("for", buf + 12, 3)) @@ -948,7 +977,7 @@
if (! isspace(*(buf + 11))) { - g_free(eol); + utils_free_pointers(eol, space, NULL); return; }
@@ -962,9 +991,9 @@ var = g_strdup("i"); contruct_len = 12; } - construct = g_strdup_printf("(%s%s = 0; %s < ; %s++)%s{%s\t%s}%s", + construct = g_strdup_printf("(%s%s = 0; %s < ; %s++)%s{%s%s%s}%s", (doc_list[idx].file_type->id == GEANY_FILETYPES_CPP) ? "int " : "", - var, var, var, eol, eol, eol, eol); + var, var, var, eol, eol, space, eol, eol);
// add 4 characters because of "int " in C++ mode contruct_len += (doc_list[idx].file_type->id == GEANY_FILETYPES_CPP) ? 4 : 0; @@ -978,11 +1007,11 @@ { if (! isspace(*(buf + 9))) { - g_free(eol); + utils_free_pointers(eol, space, NULL); return; }
- construct = g_strdup_printf("()%s{%s\t%s}%s", eol, eol, eol, eol); + construct = g_strdup_printf("()%s{%s%s%s}%s", eol, eol, space, eol, eol);
SSM(sci, SCI_INSERTTEXT, pos, (sptr_t) construct); sci_goto_pos(sci, pos + 1, TRUE); @@ -992,40 +1021,41 @@ { if (! isspace(*(buf + 12))) { - g_free(eol); + utils_free_pointers(eol, space, NULL); return; }
- construct = g_strdup_printf("%s{%s\t%s}%swhile ();%s", eol, eol, eol, eol, eol); + construct = g_strdup_printf("%s{%s%s%s}%swhile ();%s", eol, eol, space, eol, eol, eol);
SSM(sci, SCI_INSERTTEXT, pos, (sptr_t) construct); - sci_goto_pos(sci, pos + 4 + (2 * strlen(indent)), TRUE); + sci_goto_pos(sci, pos + 3 + space_len + (2 * strlen(indent)), TRUE); g_free(construct); } else if (! strncmp("try", buf + 12, 3)) { if (! isspace(*(buf + 11))) { - g_free(eol); + utils_free_pointers(eol, space, NULL); return; }
- construct = g_strdup_printf("%s{%s\t%s}%scatch ()%s{%s\t%s}%s", - eol, eol, eol, eol, eol, eol, eol, eol); + construct = g_strdup_printf("%s{%s%s%s}%scatch ()%s{%s%s%s}%s", + eol, eol, space, eol, eol, eol, eol, space, eol, eol);
SSM(sci, SCI_INSERTTEXT, pos, (sptr_t) construct); - sci_goto_pos(sci, pos + 4 + (2 * strlen(indent)), TRUE); + sci_goto_pos(sci, pos + 3 + space_len + (2 * strlen(indent)), TRUE); g_free(construct); } else if (! strncmp("switch", buf + 9, 6)) { if (! isspace(*(buf + 8))) { - g_free(eol); + utils_free_pointers(eol, space, NULL); return; }
- construct = g_strdup_printf("()%s{%s\tcase : break;%s\tdefault: %s}%s", eol, eol, eol, eol, eol); + construct = g_strdup_printf("()%s{%s%scase : break;%s%sdefault: %s}%s", + eol, eol, space, eol, space, eol, eol);
SSM(sci, SCI_INSERTTEXT, pos, (sptr_t) construct); sci_goto_pos(sci, pos + 1, TRUE); @@ -1036,30 +1066,34 @@ if (doc_list[idx].file_type->id != GEANY_FILETYPES_FERITE || ! isspace(*(buf + 9))) { - g_free(eol); + utils_free_pointers(eol, space, NULL); return; }
- construct = g_strdup_printf("%s{%s\t%s}%sfix%s{%s\t%s}%s", eol, eol, eol, eol, eol, eol, eol, eol); + construct = g_strdup_printf("%s{%s%s%s}%sfix%s{%s%s%s}%s", + eol, eol, space, eol, eol, eol, eol, space, eol, eol);
SSM(sci, SCI_INSERTTEXT, pos, (sptr_t) construct); - sci_goto_pos(sci, pos + 4 + (2 * strlen(indent)), TRUE); + sci_goto_pos(sci, pos + 3 + space_len + (2 * strlen(indent)), TRUE); g_free(construct); } else if (doc_list[idx].file_type->id == GEANY_FILETYPES_FERITE && ! strncmp("monitor", buf + 8, 7)) { if (! isspace(*(buf + 7))) { - g_free(eol); + utils_free_pointers(eol, space, NULL); return; }
- construct = g_strdup_printf("%s{%s\t%s}%shandle%s{%s\t%s}%s", eol, eol, eol, eol, eol, eol, eol, eol); + construct = g_strdup_printf("%s{%s%s%s}%shandle%s{%s%s%s}%s", + eol, eol, space, eol, eol, eol, eol, space, eol, eol);
SSM(sci, SCI_INSERTTEXT, pos, (sptr_t) construct); - sci_goto_pos(sci, pos + 4 + (2 * strlen(indent)), TRUE); + sci_goto_pos(sci, pos + 3 + space_len + (2 * strlen(indent)), TRUE); g_free(construct); } + + utils_free_pointers(eol, space, NULL); }
Modified: trunk/src/sciwrappers.c =================================================================== --- trunk/src/sciwrappers.c 2007-01-14 13:36:30 UTC (rev 1185) +++ trunk/src/sciwrappers.c 2007-01-14 17:09:17 UTC (rev 1186) @@ -917,3 +917,7 @@ SSM(sci, SCI_SETTABINDENTS, set, 0); }
+void sci_set_use_tabs(ScintillaObject *sci, gboolean set) +{ + SSM(sci, SCI_SETUSETABS, set, 0); +}
Modified: trunk/src/sciwrappers.h =================================================================== --- trunk/src/sciwrappers.h 2007-01-14 13:36:30 UTC (rev 1185) +++ trunk/src/sciwrappers.h 2007-01-14 17:09:17 UTC (rev 1186) @@ -1,7 +1,8 @@ /* * sciwrappers.h - this file is part of Geany, a fast and lightweight IDE * - * Copyright 2006 Enrico Troeger enrico.troeger@uvena.de + * Copyright 2005-2007 Enrico Troeger enrico.troeger@uvena.de + * Copyright 2006-2007 Nick Treleaven nick.treleaven@btinternet.com * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -167,5 +168,6 @@
gint sci_get_overtype (ScintillaObject * sci); void sci_set_tab_indents (ScintillaObject * sci, gboolean set); +void sci_set_use_tabs (ScintillaObject * sci, gboolean set);
#endif
Modified: trunk/src/utils.c =================================================================== --- trunk/src/utils.c 2007-01-14 13:36:30 UTC (rev 1185) +++ trunk/src/utils.c 2007-01-14 17:09:17 UTC (rev 1186) @@ -31,6 +31,7 @@ #include <unistd.h> #include <string.h> #include <errno.h> +#include <stdarg.h>
#ifdef HAVE_SYS_STAT_H # include <sys/stat.h> @@ -1432,3 +1433,51 @@ }
+/* Returns a string containing whitespace of the amount a according to the + * setting app->pref_editor_use_tabs filled with simple space characters or with the right amount + * of tabulator characters (a is filled with tabulators *and* spaces if a isn't a multiple of + * app->pref_editor_tab_width) */ +gchar *utils_get_whitespace(gint a) +{ + gchar *str; + + g_return_val_if_fail(a > 0, NULL); + + if (app->pref_editor_use_tabs) + { // first fill text with tabluators and fill the rest with spaces + gint tabs = a / app->pref_editor_tab_width; + gint spaces = a % app->pref_editor_tab_width; + gint len = tabs + spaces; + + str = g_malloc(len + 1); + + memset(str, '\t', tabs); + memset(str + tabs, ' ', spaces); + str[len] = '\0'; + } + else + str = g_strnfill(a, ' '); + + return str; +} + + +/* frees all passed pointers if they are non-NULL, the first argument is nothing special, + * it will also be freed, the list should be ended with NULL */ +void utils_free_pointers(gpointer first, ...) +{ + va_list a; + gpointer sa; + + for (va_start(a, first); (sa = va_arg(a, gpointer), sa!=NULL);) + { + if (sa != NULL) + g_free(sa); + } + va_end(a); + + if (first != NULL) + g_free(first); +} + +
Modified: trunk/src/utils.h =================================================================== --- trunk/src/utils.h 2007-01-14 13:36:30 UTC (rev 1185) +++ trunk/src/utils.h 2007-01-14 17:09:17 UTC (rev 1186) @@ -1,7 +1,8 @@ /* * utils.h - this file is part of Geany, a fast and lightweight IDE * - * Copyright 2006 Enrico Troeger enrico.troeger@uvena.de + * Copyright 2005-2007 Enrico Troeger enrico.troeger@uvena.de + * Copyright 2006-2007 Nick Treleaven nick.treleaven@btinternet.com * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -143,4 +144,14 @@ /* Simple wrapper for g_locale_to_utf8; returns a copy of locale_text on failure. */ gchar *utils_get_utf8_from_locale(const gchar *locale_text);
+/* Returns a string containing whitespace of the amount a according to the + * setting app->pref_editor_use_tabs filled with simple space characters or with the right amount + * of tabulator characters (a is filled with tabulators *and* spaces if a isn't a multiple of + * app->pref_editor_tab_width) */ +gchar *utils_get_whitespace(gint amount); + +/* frees all passed pointers if they are non-NULL, the first argument is nothing special, + * it will also be freed, the list should be ended with NULL */ +void utils_free_pointers(gpointer first, ...); + #endif
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.