Revision: 1316 http://geany-plugins.svn.sourceforge.net/geany-plugins/?rev=1316&view=re... Author: colombanw Date: 2010-04-28 21:30:25 +0000 (Wed, 28 Apr 2010)
Log Message: ----------- GeanyGenDoc: Indent inserted comment according to insertion position
Indent the inserted comment according to the insertion position indentation. This can be disabled by a (currently) hidden "indent" preference. Also use editor_insert_text_block() in place of sci_insert_text(), which fixes line endings to be the right ones for the working file.
Modified Paths: -------------- trunk/geanygendoc/src/ggd-plugin.c trunk/geanygendoc/src/ggd-plugin.h trunk/geanygendoc/src/ggd.c trunk/geanygendoc/src/ggd.h
Modified: trunk/geanygendoc/src/ggd-plugin.c =================================================================== --- trunk/geanygendoc/src/ggd-plugin.c 2010-04-28 21:29:54 UTC (rev 1315) +++ trunk/geanygendoc/src/ggd-plugin.c 2010-04-28 21:30:25 UTC (rev 1316) @@ -80,6 +80,7 @@ /* global plugin options */ gchar *GGD_OPT_doctype = NULL; gboolean GGD_OPT_save_to_refresh = FALSE; +gboolean GGD_OPT_indent = TRUE;
@@ -148,6 +149,7 @@ plugin->config = ggd_opt_group_new ("General"); ggd_opt_group_add_string (plugin->config, &GGD_OPT_doctype, "doctype"); ggd_opt_group_add_boolean (plugin->config, &GGD_OPT_save_to_refresh, "save_to_refresh"); + ggd_opt_group_add_boolean (plugin->config, &GGD_OPT_indent, "indent"); conffile = ggd_get_config_file ("ggd.conf", NULL, GGD_PERM_R, &err); if (conffile) { success = ggd_opt_group_load_from_file (plugin->config, conffile, &err);
Modified: trunk/geanygendoc/src/ggd-plugin.h =================================================================== --- trunk/geanygendoc/src/ggd-plugin.h 2010-04-28 21:29:54 UTC (rev 1315) +++ trunk/geanygendoc/src/ggd-plugin.h 2010-04-28 21:30:25 UTC (rev 1316) @@ -45,6 +45,7 @@ /* global plugin options */ extern gchar *GGD_OPT_doctype; extern gboolean GGD_OPT_save_to_refresh; +extern gboolean GGD_OPT_indent;
G_END_DECLS
Modified: trunk/geanygendoc/src/ggd.c =================================================================== --- trunk/geanygendoc/src/ggd.c 2010-04-28 21:29:54 UTC (rev 1315) +++ trunk/geanygendoc/src/ggd.c 2010-04-28 21:30:25 UTC (rev 1316) @@ -32,6 +32,14 @@ #include "ggd-plugin.h"
+/* sci_get_line_indentation() is not in the plugin API for now (API v183), then + * implement it -- borrowed from Geany's sciwrappers.c */ +#ifndef sci_get_line_indentation +# define sci_get_line_indentation(sci, line) \ + (scintilla_send_message (sci, SCI_GETLINEINDENTATION, line, 0)) +#endif /* sci_get_line_indentation */ + + /* The value that replace the "cursor" variable in templates, used to find it * and therefore the cursor position. This should be a value that the user never * want to output; otherwise it would behave strangely from the user point of @@ -304,15 +312,16 @@
/* inserts the comment for @tag in @sci according to @setting */ static gboolean -do_insert_comment (ScintillaObject *sci, +do_insert_comment (GeanyDocument *doc, GPtrArray *tag_array, const TMTag *tag, GgdFileType *ft, GgdDocSetting *setting) { - gboolean success = FALSE; - gchar *comment; - gint cursor_offset = 0; + gboolean success = FALSE; + gchar *comment; + gint cursor_offset = 0; + ScintillaObject *sci = doc->editor->sci;
comment = get_comment (ft, setting, tag_array, tag, &cursor_offset); if (comment) { @@ -329,6 +338,9 @@ line = tag->atts.entry.line - 1; line = adjust_start_line (sci, tag_array, tag, line); pos = sci_get_position_from_line (sci, line); + if (GGD_OPT_indent) { + pos += sci_get_line_indentation (sci, line); + } break; }
@@ -336,8 +348,8 @@ pos = sci_get_current_position (sci); break; } - sci_insert_text (sci, pos, comment); - sci_set_current_position (sci, pos + cursor_offset, TRUE); + editor_insert_text_block (doc->editor, comment, pos, cursor_offset, + -1, TRUE); success = TRUE; } g_free (comment); @@ -446,7 +458,7 @@
setting = get_setting_from_tag (doctype, tag_array, tag, &tag); if (setting && ! g_hash_table_lookup (tag_done_table, tag)) { - if (! do_insert_comment (sci, tag_array, tag, filetype, setting)) { + if (! do_insert_comment (doc, tag_array, tag, filetype, setting)) { success = FALSE; break; } else {
Modified: trunk/geanygendoc/src/ggd.h =================================================================== --- trunk/geanygendoc/src/ggd.h 2010-04-28 21:29:54 UTC (rev 1315) +++ trunk/geanygendoc/src/ggd.h 2010-04-28 21:30:25 UTC (rev 1316) @@ -21,7 +21,7 @@ #define H_GGD
#include <glib.h> -#include "geanyplugin.h" +#include <geanyplugin.h>
G_BEGIN_DECLS
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
plugins-commits@lists.geany.org