On Tue, 2 Nov 2010 15:13:12 +0000%
Nick Treleaven <nick.trelea...@btinternet.com> wrote:

> On Fri, 29 Oct 2010 21:56:53 +0400
> Eugene Arshinov <earshi...@gmail.com> wrote:
> 
> > > I wasn't thinking of brace autoindentation. In that case perhaps
> > > it's simpler to add a HTML-specific setting to disable tag
> > > autoindentation.
> > > 
> > 
> > It makes sense, but since now I could not find an acceptable way to
> > implement it.  I've just discovered that GeanyFiletype's are stored
> > in a pointer array, so instead of ordinary GeanyFiletype for HTML we
> > may add to the array an instance of hypothetical HtmlFiletype
> > { GeanyFiletype parent; gboolean enable_tag_autoindentation } and of
> > course write some code to load enable_tag_autoindentation from
> > filetype config.  Is it OK?
> 
> I think just add a html_tag_autoindentation field to
> GeanyFiletypePrivate and use that.
> 

Okay, the patch is attached.  I named the field 'xml_indent_tags' and
the filetype property 'indent_tags'.  By default (like all fields in
GeanyFiletypePrivate) it is zero, but in global filetypes.{xml,html} I
set it to true.

Best regards,
Eugene.
diff --git a/data/filetypes.html b/data/filetypes.html
index 1e63c0c..9dcf5b2 100644
--- a/data/filetypes.html
+++ b/data/filetypes.html
@@ -32,6 +32,10 @@ comment_use_indent=true
 # context action command (please see Geany's main documentation for details)
 context_action_cmd=
 
+# If this setting is set to true, a new line after a line ending with an
+# unclosed tag will be automatically indented
+indent_tags=true
+
 [build_settings]
 # %f will be replaced by the complete filename
 # %e will be replaced by the filename without extension
diff --git a/data/filetypes.xml b/data/filetypes.xml
index e71c8fc..17113fe 100644
--- a/data/filetypes.xml
+++ b/data/filetypes.xml
@@ -103,3 +103,6 @@ comment_use_indent=true
 # context action command (please see Geany's main documentation for details)
 context_action_cmd=
 
+# If this setting is set to true, a new line after a line ending with an
+# unclosed tag will be automatically indented
+indent_tags=true
\ No newline at end of file
diff --git a/src/editor.c b/src/editor.c
index 33483ae..4f12952 100644
--- a/src/editor.c
+++ b/src/editor.c
@@ -55,6 +55,7 @@
 #include "document.h"
 #include "documentprivate.h"
 #include "filetypes.h"
+#include "filetypesprivate.h"
 #include "sciwrappers.h"
 #include "ui_utils.h"
 #include "utils.h"
@@ -1360,7 +1361,8 @@ static gint get_indent_size_after_line(GeanyEditor *editor, gint line)
 		 * should make the XML-related check */
 		if (additional_indent == 0 && !editor_prefs.auto_close_xml_tags &&
 			(editor->document->file_type->id == GEANY_FILETYPES_HTML ||
-			editor->document->file_type->id == GEANY_FILETYPES_XML))
+			editor->document->file_type->id == GEANY_FILETYPES_XML) &&
+			filetypes[editor->document->file_type->id]->priv->xml_indent_tags)
 		{
 			size += iprefs->width * get_xml_indent(sci, line);
 		}
diff --git a/src/filetypes.c b/src/filetypes.c
index e4d2a5b..b205774 100644
--- a/src/filetypes.c
+++ b/src/filetypes.c
@@ -1110,6 +1110,20 @@ static void load_settings(gint ft_id, GKeyFile *config, GKeyFile *configh)
 	/* read build settings */
 	build_load_menu(config, GEANY_BCS_FT, (gpointer)ft);
 	build_load_menu(configh, GEANY_BCS_HOME_FT, (gpointer)ft);
+
+	if (ft_id == GEANY_FILETYPES_XML || ft_id == GEANY_FILETYPES_HTML)
+	{
+		tmp = g_key_file_get_boolean(configh, "settings", "indent_tags", &error);
+		if (error)
+		{
+			g_error_free(error);
+			error = NULL;
+			tmp = g_key_file_get_boolean(config, "settings", "indent_tags", &error);
+			if (error) g_error_free(error);
+			else filetypes[ft_id]->priv->xml_indent_tags = tmp;
+		}
+		else filetypes[ft_id]->priv->xml_indent_tags = tmp;
+	}
 }
 
 
diff --git a/src/filetypesprivate.h b/src/filetypesprivate.h
index 3a36ce9..335b602 100644
--- a/src/filetypesprivate.h
+++ b/src/filetypesprivate.h
@@ -43,6 +43,8 @@ typedef struct GeanyFiletypePrivate
 	gchar		*last_string; /* last one compiled */
 	gboolean	custom;
 	gint		symbol_list_sort_mode;
+
+	gboolean	xml_indent_tags; /* XML tag autoindentation, for HTML and XML filetypes */
 }
 GeanyFiletypePrivate;
 
_______________________________________________
Geany-devel mailing list
Geany-devel@uvena.de
http://lists.uvena.de/cgi-bin/mailman/listinfo/geany-devel

Reply via email to