diff --git a/ChangeLog b/ChangeLog
index fc357fa..b9d908a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2010-11-13  Eugene Arshinov  <earshinov(at)gmail(dot)com>
+
+ * src/editor.c, src/editor.h, src/plugindata.h, src/plugins.c,
+   src/highlighting.c, src/highlighting.h, src/utils.c,
+   plugins/geanyfunctions.h:
+   Move editor.c:is_{string,comment,code}_style() functions to
+   highlighting.c. Add new editor_find_snippet() and
+   editor_insert_snippet() functions. Export these functions and
+   utils_find_open_xml_tag() for plugins; bump API version.
+
+
 2010-11-10  Nick Treleaven  <nick(dot)treleaven(at)btinternet(dot)com>
 
  * src/templates.c, src/document.c:
diff --git a/plugins/geanyfunctions.h b/plugins/geanyfunctions.h
index a356f8f..bc36ed7 100644
--- a/plugins/geanyfunctions.h
+++ b/plugins/geanyfunctions.h
@@ -92,6 +92,10 @@
 	geany_functions->p_editor->editor_get_eol_char_mode
 #define editor_goto_pos \
 	geany_functions->p_editor->editor_goto_pos
+#define editor_find_snippet \
+	geany_functions->p_editor->editor_find_snippet
+#define editor_insert_snippet \
+	geany_functions->p_editor->editor_insert_snippet
 #define scintilla_send_message \
 	geany_functions->p_scintilla->scintilla_send_message
 #define scintilla_new \
@@ -244,6 +248,8 @@
 	geany_functions->p_utils->utils_get_file_list_full
 #define utils_copy_environment \
 	geany_functions->p_utils->utils_copy_environment
+#define utils_find_open_xml_tag \
+	geany_functions->p_utils->utils_find_open_xml_tag
 #define ui_dialog_vbox_new \
 	geany_functions->p_ui->ui_dialog_vbox_new
 #define ui_frame_new_with_alignment \
@@ -330,6 +336,12 @@
 	geany_functions->p_highlighting->highlighting_get_style
 #define highlighting_set_styles \
 	geany_functions->p_highlighting->highlighting_set_styles
+#define highlighting_is_string_style \
+	geany_functions->p_highlighting->highlighting_is_string_style
+#define highlighting_is_comment_style \
+	geany_functions->p_highlighting->highlighting_is_comment_style
+#define highlighting_is_code_style \
+	geany_functions->p_highlighting->highlighting_is_code_style
 #define filetypes_detect_from_file \
 	geany_functions->p_filetypes->filetypes_detect_from_file
 #define filetypes_lookup_by_name \
diff --git a/src/editor.c b/src/editor.c
index 96ca06d..bfd026d 100644
--- a/src/editor.c
+++ b/src/editor.c
@@ -67,6 +67,7 @@
 #include "project.h"
 #include "projectprivate.h"
 #include "main.h"
+#include "highlighting.h"
 
 
 /* Note: use sciwrappers.h instead where possible.
@@ -104,8 +105,6 @@ static void on_new_line_added(GeanyEditor *editor);
 static gboolean handle_xml(GeanyEditor *editor, gint pos, gchar ch);
 static void insert_indent_after_line(GeanyEditor *editor, gint line);
 static void auto_multiline(GeanyEditor *editor, gint pos);
-static gboolean is_code_style(gint lexer, gint style);
-static gboolean is_string_style(gint lexer, gint style);
 static void auto_close_chars(ScintillaObject *sci, gint pos, gchar c);
 static void close_block(GeanyEditor *editor, gint pos);
 static void editor_highlight_braces(GeanyEditor *editor, gint cur_pos);
@@ -196,8 +195,6 @@ static void on_snippet_keybinding_activate(gchar *key)
 	GeanyDocument *doc = document_get_current();
 	const gchar *s;
 	GHashTable *specials;
-	GString *pattern;
-	gint pos, line, indent_width, cursor_pos;
 
 	if (!doc || !GTK_WIDGET_HAS_FOCUS(doc->editor->sci))
 		return;
@@ -215,17 +212,8 @@ static void on_snippet_keybinding_activate(gchar *key)
 		return;
 	}
 
-	pos = sci_get_current_position(doc->editor->sci);
-	line = sci_get_line_from_position(doc->editor->sci, pos);
-	indent_width = sci_get_line_indentation(doc->editor->sci, line);
-
-	pattern = g_string_new(s);
-	cursor_pos = snippets_make_replacements(doc->editor, pattern, indent_width);
-
-	editor_insert_text_block(doc->editor, pattern->str, pos, cursor_pos, indent_width, FALSE);
+	editor_insert_snippet(doc->editor, sci_get_current_position(doc->editor->sci), s);
 	sci_scroll_caret(doc->editor->sci);
-
-	g_string_free(pattern, TRUE);
 }
 
 
@@ -1855,7 +1843,7 @@ gboolean editor_show_calltip(GeanyEditor *editor, gint pos)
 
 	/* the style 1 before the brace (which may be highlighted) */
 	style = sci_get_style_at(sci, pos - 1);
-	if (! is_code_style(lexer, style))
+	if (! highlighting_is_code_style(lexer, style))
 		return FALSE;
 
 	word[0] = '\0';
@@ -2120,7 +2108,7 @@ gboolean editor_start_auto_complete(GeanyEditor *editor, gint pos, gboolean forc
 	style = sci_get_style_at(sci, pos - 2);
 
 	/* don't autocomplete in comments and strings */
-	if (!force && !is_code_style(lexer, style))
+	if (!force && !highlighting_is_code_style(lexer, style))
 		return FALSE;
 
 	autocomplete_scope(editor);
@@ -2515,23 +2503,20 @@ static gboolean snippets_complete_constructs(GeanyEditor *editor, gint pos, cons
 {
 	ScintillaObject *sci = editor->sci;
 	gchar *str;
-	GString *pattern;
-	gssize cur_index = -1;
+	const gchar *completion;
 	gint str_len;
 	gint ft_id = editor->document->file_type->id;
 
 	str = g_strdup(word);
 	g_strstrip(str);
-	pattern = g_string_new(snippets_find_completion_by_name(filetypes[ft_id]->name, str));
-	if (pattern == NULL || pattern->len == 0)
+
+	completion = snippets_find_completion_by_name(filetypes[ft_id]->name, str);
+	if (completion == NULL)
 	{
 		g_free(str);
-		g_string_free(pattern, TRUE);
 		return FALSE;
 	}
 
-	read_indent(editor, pos);
-
 	/* remove the typed word, it will be added again by the used auto completion
 	 * (not really necessary but this makes the auto completion more flexible,
 	 *  e.g. with a completion like hi=hello, so typing "hi<TAB>" will result in "hello") */
@@ -2541,14 +2526,10 @@ static gboolean snippets_complete_constructs(GeanyEditor *editor, gint pos, cons
 	sci_replace_sel(sci, "");
 	pos -= str_len; /* pos has changed while deleting */
 
-	cur_index = snippets_make_replacements(editor, pattern, strlen(indent));
-
-	/* finally insert the text and set the cursor */
-	editor_insert_text_block(editor, pattern->str, pos, cur_index, -1, FALSE);
+	editor_insert_snippet(editor, pos, completion);
 	sci_scroll_caret(sci);
 
 	g_free(str);
-	g_string_free(pattern, TRUE);
  	return TRUE;
 }
 
@@ -2670,7 +2651,7 @@ static gboolean handle_xml(GeanyEditor *editor, gint pos, gchar ch)
 
 	/* return if we are inside any embedded script */
 	style = sci_get_style_at(sci, pos);
-	if (style > SCE_H_XCCOMMENT && ! is_string_style(lexer, style))
+	if (style > SCE_H_XCCOMMENT && ! highlighting_is_string_style(lexer, style))
 		return FALSE;
 
 	/* if ch is /, check for </, else quit */
@@ -3434,293 +3415,6 @@ static void auto_multiline(GeanyEditor *editor, gint cur_line)
 }
 
 
-/* Checks whether the given style is a string for the given lexer.
- * It doesn't handle LEX_HTML, this should be done by the caller.
- * Returns true if the style is a string, FALSE otherwise.
- *
- * Don't forget STRINGEOL, to prevent completion whilst typing a string with no closing char.
- */
-static gboolean is_string_style(gint lexer, gint style)
-{
-	switch (lexer)
-	{
-		case SCLEX_CPP:
-			return (style == SCE_C_CHARACTER ||
-				style == SCE_C_STRING ||
-				style == SCE_C_STRINGEOL);
-
-		case SCLEX_PASCAL:
-			return (style == SCE_PAS_CHARACTER ||
-				style == SCE_PAS_STRING ||
-				style == SCE_PAS_STRINGEOL);
-
-		case SCLEX_D:
-			return (style == SCE_D_STRING ||
-				style == SCE_D_STRINGEOL ||
-				style == SCE_D_CHARACTER ||
-				style == SCE_D_STRINGB ||
-				style == SCE_D_STRINGR);
-
-		case SCLEX_PYTHON:
-			return (style == SCE_P_STRING ||
-				style == SCE_P_TRIPLE ||
-				style == SCE_P_TRIPLEDOUBLE ||
-				style == SCE_P_CHARACTER ||
-				style == SCE_P_STRINGEOL);
-
-		case SCLEX_F77:
-		case SCLEX_FORTRAN:
-			return (style == SCE_F_STRING1 ||
-				style == SCE_F_STRING2 ||
-				style == SCE_F_STRINGEOL);
-
-		case SCLEX_PERL:
-			return (/*style == SCE_PL_STRING ||*/ /* may want variable autocompletion "$(foo)" */
-				style == SCE_PL_CHARACTER ||
-				style == SCE_PL_HERE_DELIM ||
-				style == SCE_PL_HERE_Q ||
-				style == SCE_PL_HERE_QQ ||
-				style == SCE_PL_HERE_QX ||
-				style == SCE_PL_POD ||
-				style == SCE_PL_STRING_Q ||
-				style == SCE_PL_STRING_QQ ||
-				style == SCE_PL_STRING_QX ||
-				style == SCE_PL_STRING_QR ||
-				style == SCE_PL_STRING_QW ||
-				style == SCE_PL_POD_VERB);
-
-		case SCLEX_R:
-			return (style == SCE_R_STRING);
-
-		case SCLEX_RUBY:
-			return (style == SCE_RB_CHARACTER ||
-				style == SCE_RB_STRING ||
-				style == SCE_RB_HERE_DELIM ||
-				style == SCE_RB_HERE_Q ||
-				style == SCE_RB_HERE_QQ ||
-				style == SCE_RB_HERE_QX ||
-				style == SCE_RB_POD);
-
-		case SCLEX_BASH:
-			return (style == SCE_SH_STRING);
-
-		case SCLEX_SQL:
-			return (style == SCE_SQL_STRING);
-
-		case SCLEX_TCL:
-			return (style == SCE_TCL_IN_QUOTE);
-
-		case SCLEX_LUA:
-			return (style == SCE_LUA_LITERALSTRING ||
-				style == SCE_LUA_CHARACTER ||
-				style == SCE_LUA_STRINGEOL ||
-				style == SCE_LUA_STRING);
-
-		case SCLEX_HASKELL:
-			return (style == SCE_HA_CHARACTER ||
-				style == SCE_HA_STRING);
-
-		case SCLEX_FREEBASIC:
-			return (style == SCE_B_STRING ||
-				style == SCE_B_STRINGEOL);
-
-		case SCLEX_OCTAVE:
-			return (style == SCE_MATLAB_STRING ||
-				style == SCE_MATLAB_DOUBLEQUOTESTRING);
-
-		case SCLEX_HTML:
-			return (
-				style == SCE_HBA_STRING ||
-				style == SCE_HBA_STRINGEOL ||
-				style == SCE_HB_STRING ||
-				style == SCE_HB_STRINGEOL ||
-				style == SCE_H_CDATA ||
-				style == SCE_H_DOUBLESTRING ||
-				style == SCE_HJA_DOUBLESTRING ||
-				style == SCE_HJA_SINGLESTRING ||
-				style == SCE_HJA_STRINGEOL ||
-				style == SCE_HJ_DOUBLESTRING ||
-				style == SCE_HJ_SINGLESTRING ||
-				style == SCE_HJ_STRINGEOL ||
-				style == SCE_HPA_CHARACTER ||
-				style == SCE_HPA_STRING ||
-				style == SCE_HPA_TRIPLE ||
-				style == SCE_HPA_TRIPLEDOUBLE ||
-				style == SCE_HP_CHARACTER ||
-				style == SCE_HPHP_HSTRING ||  /* HSTRING is a heredoc */
-				style == SCE_HPHP_HSTRING_VARIABLE ||
-				style == SCE_HPHP_SIMPLESTRING ||
-				style == SCE_HP_STRING ||
-				style == SCE_HP_TRIPLE ||
-				style == SCE_HP_TRIPLEDOUBLE ||
-				style == SCE_H_SGML_DOUBLESTRING ||
-				style == SCE_H_SGML_SIMPLESTRING ||
-				style == SCE_H_SINGLESTRING);
-
-		case SCLEX_CMAKE:
-			return (style == SCE_CMAKE_STRINGDQ ||
-				style == SCE_CMAKE_STRINGLQ ||
-				style == SCE_CMAKE_STRINGRQ ||
-				style == SCE_CMAKE_STRINGVAR);
-
-		case SCLEX_NSIS:
-			return (style == SCE_NSIS_STRINGDQ ||
-				style == SCE_NSIS_STRINGLQ ||
-				style == SCE_NSIS_STRINGRQ ||
-				style == SCE_NSIS_STRINGVAR);
-
-		case SCLEX_ADA:
-			return (style == SCE_ADA_CHARACTER ||
-				style == SCE_ADA_STRING ||
-				style == SCE_ADA_CHARACTEREOL ||
-				style == SCE_ADA_STRINGEOL);
-	}
-	return FALSE;
-}
-
-
-/* Checks whether the given style is a comment for the given lexer.
- * It doesn't handle LEX_HTML, this should be done by the caller.
- * Returns true if the style is a comment, FALSE otherwise.
- */
-static gboolean is_comment_style(gint lexer, gint style)
-{
-	switch (lexer)
-	{
-		case SCLEX_CPP:
-			return (style == SCE_C_COMMENT ||
-				style == SCE_C_COMMENTLINE ||
-				style == SCE_C_COMMENTDOC ||
-				style == SCE_C_COMMENTLINEDOC ||
-				style == SCE_C_COMMENTDOCKEYWORD ||
-				style == SCE_C_COMMENTDOCKEYWORDERROR);
-
-		case SCLEX_PASCAL:
-			return (style == SCE_PAS_COMMENT ||
-				style == SCE_PAS_COMMENT2 ||
-				style == SCE_PAS_COMMENTLINE);
-
-		case SCLEX_D:
-			return (style == SCE_D_COMMENT ||
-				style == SCE_D_COMMENTLINE ||
-				style == SCE_D_COMMENTDOC ||
-				style == SCE_D_COMMENTNESTED ||
-				style == SCE_D_COMMENTLINEDOC ||
-				style == SCE_D_COMMENTDOCKEYWORD ||
-				style == SCE_D_COMMENTDOCKEYWORDERROR);
-
-		case SCLEX_PYTHON:
-			return (style == SCE_P_COMMENTLINE ||
-				style == SCE_P_COMMENTBLOCK);
-
-		case SCLEX_F77:
-		case SCLEX_FORTRAN:
-			return (style == SCE_F_COMMENT);
-
-		case SCLEX_PERL:
-			return (style == SCE_PL_COMMENTLINE);
-
-		case SCLEX_PROPERTIES:
-			return (style == SCE_PROPS_COMMENT);
-
-		case SCLEX_PO:
-			return (style == SCE_PO_COMMENT);
-
-		case SCLEX_LATEX:
-			return (style == SCE_L_COMMENT);
-
-		case SCLEX_MAKEFILE:
-			return (style == SCE_MAKE_COMMENT);
-
-		case SCLEX_RUBY:
-			return (style == SCE_RB_COMMENTLINE);
-
-		case SCLEX_BASH:
-			return (style == SCE_SH_COMMENTLINE);
-
-		case SCLEX_R:
-			return (style == SCE_R_COMMENT);
-
-		case SCLEX_SQL:
-			return (style == SCE_SQL_COMMENT ||
-				style == SCE_SQL_COMMENTLINE ||
-				style == SCE_SQL_COMMENTDOC);
-
-		case SCLEX_TCL:
-			return (style == SCE_TCL_COMMENT ||
-				style == SCE_TCL_COMMENTLINE ||
-				style == SCE_TCL_COMMENT_BOX ||
-				style == SCE_TCL_BLOCK_COMMENT);
-
-		case SCLEX_OCTAVE:
-			return (style == SCE_MATLAB_COMMENT);
-
-		case SCLEX_LUA:
-			return (style == SCE_LUA_COMMENT ||
-				style == SCE_LUA_COMMENTLINE ||
-				style == SCE_LUA_COMMENTDOC);
-
-		case SCLEX_HASKELL:
-			return (style == SCE_HA_COMMENTLINE ||
-				style == SCE_HA_COMMENTBLOCK ||
-				style == SCE_HA_COMMENTBLOCK2 ||
-				style == SCE_HA_COMMENTBLOCK3);
-
-		case SCLEX_FREEBASIC:
-			return (style == SCE_B_COMMENT);
-
-		case SCLEX_YAML:
-			return (style == SCE_YAML_COMMENT);
-
-		case SCLEX_HTML:
-			return (
-				style == SCE_HBA_COMMENTLINE ||
-				style == SCE_HB_COMMENTLINE ||
-				style == SCE_H_COMMENT ||
-				style == SCE_HJA_COMMENT ||
-				style == SCE_HJA_COMMENTDOC ||
-				style == SCE_HJA_COMMENTLINE ||
-				style == SCE_HJ_COMMENT ||
-				style == SCE_HJ_COMMENTDOC ||
-				style == SCE_HJ_COMMENTLINE ||
-				style == SCE_HPA_COMMENTLINE ||
-				style == SCE_HP_COMMENTLINE ||
-				style == SCE_HPHP_COMMENT ||
-				style == SCE_HPHP_COMMENTLINE ||
-				style == SCE_H_SGML_COMMENT);
-
-		case SCLEX_CMAKE:
-			return (style == SCE_CMAKE_COMMENT);
-
-		case SCLEX_NSIS:
-			return (style == SCE_NSIS_COMMENT ||
-				style == SCE_NSIS_COMMENTBOX);
-
-		case SCLEX_ADA:
-			return (style == SCE_ADA_COMMENTLINE ||
-				style == SCE_NSIS_COMMENTBOX);
-	}
-	return FALSE;
-}
-
-
-/* Checks whether the given style is normal code (not string, comment, preprocessor, etc).
- * It doesn't handle LEX_HTML, this should be done by the caller.
- */
-static gboolean is_code_style(gint lexer, gint style)
-{
-	switch (lexer)
-	{
-		case SCLEX_CPP:
-			if (style == SCE_C_PREPROCESSOR)
-				return FALSE;
-			break;
-	}
-	return !(is_comment_style(lexer, style) ||
-		is_string_style(lexer, style));
-}
-
-
 #if 0
 static gboolean editor_lexer_is_c_like(gint lexer)
 {
@@ -5202,3 +4896,40 @@ void editor_indent(GeanyEditor *editor, gboolean increase)
 		sci_set_current_line(sci, lstart);
 	}
 }
+
+
+/** Get snippet by name.
+ *
+ * If @a editor is passed, returns a snippet specific to the type of document which is opened.
+ * I @a editor is @c NULL, returns a snippet from the default set.
+ *
+ * @param editor Editor or NULL
+ * @param snippet_name Snippet name
+ * @return snippet or NULL if it was not found.  Must not be freed.
+ */
+const gchar *editor_find_snippet(GeanyEditor *editor, const gchar *snippet_name)
+{
+	const gchar *subhash_name = editor ? editor->document->file_type->name : "Default";
+	GHashTable *subhash = g_hash_table_lookup(snippet_hash, subhash_name);
+
+	return subhash ? g_hash_table_lookup(subhash, snippet_name) : NULL;
+}
+
+
+/** Replace all special sequences in the @a snippet and insert it at @a pos
+ *
+ * If you insert at the current position, consider calling @c sci_scroll_caret() after this function.
+ */
+void editor_insert_snippet(GeanyEditor *editor, gint pos, const gchar *snippet)
+{
+	gint line, indent_width, cursor_pos;
+	GString *pattern;
+
+	line = sci_get_line_from_position(editor->sci, pos);
+	indent_width = sci_get_line_indentation(editor->sci, line);
+
+	pattern = g_string_new(snippet);
+	cursor_pos = snippets_make_replacements(editor, pattern, indent_width);
+	editor_insert_text_block(editor, pattern->str, pos, cursor_pos, indent_width, FALSE);
+	g_string_free(pattern, TRUE);
+}
diff --git a/src/editor.h b/src/editor.h
index e81a074..89533e8 100644
--- a/src/editor.h
+++ b/src/editor.h
@@ -307,4 +307,8 @@ void editor_insert_text_block(GeanyEditor *editor, const gchar *text,
 
 void editor_toggle_fold(GeanyEditor *editor, gint line, gint modifiers);
 
+const gchar *editor_find_snippet(GeanyEditor *editor, const gchar *snippet_name);
+
+void editor_insert_snippet(GeanyEditor *editor, gint pos, const gchar *snippet);
+
 #endif
diff --git a/src/highlighting.c b/src/highlighting.c
index 7bdb29e..77270c8 100644
--- a/src/highlighting.c
+++ b/src/highlighting.c
@@ -3686,3 +3686,300 @@ void highlighting_init(void)
 {
 	create_color_scheme_menu();
 }
+
+
+/** Checks whether the given style is a string for the given lexer.
+ *
+ * @param lexer Scintilla lexer type (@c SCLEX_*)
+ * @param style Scintilla style (@c SCE_*)
+ *
+ * @return @c TRUE if the style is a string, @c FALSE otherwise
+ */
+gboolean highlighting_is_string_style(gint lexer, gint style)
+{
+	/* Don't forget STRINGEOL, to prevent completion whilst typing a string with no closing char. */
+
+	switch (lexer)
+	{
+		case SCLEX_CPP:
+			return (style == SCE_C_CHARACTER ||
+				style == SCE_C_STRING ||
+				style == SCE_C_STRINGEOL);
+
+		case SCLEX_PASCAL:
+			return (style == SCE_PAS_CHARACTER ||
+				style == SCE_PAS_STRING ||
+				style == SCE_PAS_STRINGEOL);
+
+		case SCLEX_D:
+			return (style == SCE_D_STRING ||
+				style == SCE_D_STRINGEOL ||
+				style == SCE_D_CHARACTER ||
+				style == SCE_D_STRINGB ||
+				style == SCE_D_STRINGR);
+
+		case SCLEX_PYTHON:
+			return (style == SCE_P_STRING ||
+				style == SCE_P_TRIPLE ||
+				style == SCE_P_TRIPLEDOUBLE ||
+				style == SCE_P_CHARACTER ||
+				style == SCE_P_STRINGEOL);
+
+		case SCLEX_F77:
+		case SCLEX_FORTRAN:
+			return (style == SCE_F_STRING1 ||
+				style == SCE_F_STRING2 ||
+				style == SCE_F_STRINGEOL);
+
+		case SCLEX_PERL:
+			return (/*style == SCE_PL_STRING ||*/ /* may want variable autocompletion "$(foo)" */
+				style == SCE_PL_CHARACTER ||
+				style == SCE_PL_HERE_DELIM ||
+				style == SCE_PL_HERE_Q ||
+				style == SCE_PL_HERE_QQ ||
+				style == SCE_PL_HERE_QX ||
+				style == SCE_PL_POD ||
+				style == SCE_PL_STRING_Q ||
+				style == SCE_PL_STRING_QQ ||
+				style == SCE_PL_STRING_QX ||
+				style == SCE_PL_STRING_QR ||
+				style == SCE_PL_STRING_QW ||
+				style == SCE_PL_POD_VERB);
+
+		case SCLEX_R:
+			return (style == SCE_R_STRING);
+
+		case SCLEX_RUBY:
+			return (style == SCE_RB_CHARACTER ||
+				style == SCE_RB_STRING ||
+				style == SCE_RB_HERE_DELIM ||
+				style == SCE_RB_HERE_Q ||
+				style == SCE_RB_HERE_QQ ||
+				style == SCE_RB_HERE_QX ||
+				style == SCE_RB_POD);
+
+		case SCLEX_BASH:
+			return (style == SCE_SH_STRING);
+
+		case SCLEX_SQL:
+			return (style == SCE_SQL_STRING);
+
+		case SCLEX_TCL:
+			return (style == SCE_TCL_IN_QUOTE);
+
+		case SCLEX_LUA:
+			return (style == SCE_LUA_LITERALSTRING ||
+				style == SCE_LUA_CHARACTER ||
+				style == SCE_LUA_STRINGEOL ||
+				style == SCE_LUA_STRING);
+
+		case SCLEX_HASKELL:
+			return (style == SCE_HA_CHARACTER ||
+				style == SCE_HA_STRING);
+
+		case SCLEX_FREEBASIC:
+			return (style == SCE_B_STRING ||
+				style == SCE_B_STRINGEOL);
+
+		case SCLEX_OCTAVE:
+			return (style == SCE_MATLAB_STRING ||
+				style == SCE_MATLAB_DOUBLEQUOTESTRING);
+
+		case SCLEX_HTML:
+			return (
+				style == SCE_HBA_STRING ||
+				style == SCE_HBA_STRINGEOL ||
+				style == SCE_HB_STRING ||
+				style == SCE_HB_STRINGEOL ||
+				style == SCE_H_CDATA ||
+				style == SCE_H_DOUBLESTRING ||
+				style == SCE_HJA_DOUBLESTRING ||
+				style == SCE_HJA_SINGLESTRING ||
+				style == SCE_HJA_STRINGEOL ||
+				style == SCE_HJ_DOUBLESTRING ||
+				style == SCE_HJ_SINGLESTRING ||
+				style == SCE_HJ_STRINGEOL ||
+				style == SCE_HPA_CHARACTER ||
+				style == SCE_HPA_STRING ||
+				style == SCE_HPA_TRIPLE ||
+				style == SCE_HPA_TRIPLEDOUBLE ||
+				style == SCE_HP_CHARACTER ||
+				style == SCE_HPHP_HSTRING ||  /* HSTRING is a heredoc */
+				style == SCE_HPHP_HSTRING_VARIABLE ||
+				style == SCE_HPHP_SIMPLESTRING ||
+				style == SCE_HP_STRING ||
+				style == SCE_HP_TRIPLE ||
+				style == SCE_HP_TRIPLEDOUBLE ||
+				style == SCE_H_SGML_DOUBLESTRING ||
+				style == SCE_H_SGML_SIMPLESTRING ||
+				style == SCE_H_SINGLESTRING);
+
+		case SCLEX_CMAKE:
+			return (style == SCE_CMAKE_STRINGDQ ||
+				style == SCE_CMAKE_STRINGLQ ||
+				style == SCE_CMAKE_STRINGRQ ||
+				style == SCE_CMAKE_STRINGVAR);
+
+		case SCLEX_NSIS:
+			return (style == SCE_NSIS_STRINGDQ ||
+				style == SCE_NSIS_STRINGLQ ||
+				style == SCE_NSIS_STRINGRQ ||
+				style == SCE_NSIS_STRINGVAR);
+
+		case SCLEX_ADA:
+			return (style == SCE_ADA_CHARACTER ||
+				style == SCE_ADA_STRING ||
+				style == SCE_ADA_CHARACTEREOL ||
+				style == SCE_ADA_STRINGEOL);
+	}
+	return FALSE;
+}
+
+
+/** Checks whether the given style is a comment for the given lexer.
+ *
+ * @param lexer Scintilla lexer type (@c SCLEX_*)
+ * @param style Scintilla style (@c SCE_*)
+ *
+ * @return @c TRUE if the style is a comment, @c FALSE otherwise
+ */
+gboolean highlighting_is_comment_style(gint lexer, gint style)
+{
+	switch (lexer)
+	{
+		case SCLEX_CPP:
+			return (style == SCE_C_COMMENT ||
+				style == SCE_C_COMMENTLINE ||
+				style == SCE_C_COMMENTDOC ||
+				style == SCE_C_COMMENTLINEDOC ||
+				style == SCE_C_COMMENTDOCKEYWORD ||
+				style == SCE_C_COMMENTDOCKEYWORDERROR);
+
+		case SCLEX_PASCAL:
+			return (style == SCE_PAS_COMMENT ||
+				style == SCE_PAS_COMMENT2 ||
+				style == SCE_PAS_COMMENTLINE);
+
+		case SCLEX_D:
+			return (style == SCE_D_COMMENT ||
+				style == SCE_D_COMMENTLINE ||
+				style == SCE_D_COMMENTDOC ||
+				style == SCE_D_COMMENTNESTED ||
+				style == SCE_D_COMMENTLINEDOC ||
+				style == SCE_D_COMMENTDOCKEYWORD ||
+				style == SCE_D_COMMENTDOCKEYWORDERROR);
+
+		case SCLEX_PYTHON:
+			return (style == SCE_P_COMMENTLINE ||
+				style == SCE_P_COMMENTBLOCK);
+
+		case SCLEX_F77:
+		case SCLEX_FORTRAN:
+			return (style == SCE_F_COMMENT);
+
+		case SCLEX_PERL:
+			return (style == SCE_PL_COMMENTLINE);
+
+		case SCLEX_PROPERTIES:
+			return (style == SCE_PROPS_COMMENT);
+
+		case SCLEX_PO:
+			return (style == SCE_PO_COMMENT);
+
+		case SCLEX_LATEX:
+			return (style == SCE_L_COMMENT);
+
+		case SCLEX_MAKEFILE:
+			return (style == SCE_MAKE_COMMENT);
+
+		case SCLEX_RUBY:
+			return (style == SCE_RB_COMMENTLINE);
+
+		case SCLEX_BASH:
+			return (style == SCE_SH_COMMENTLINE);
+
+		case SCLEX_R:
+			return (style == SCE_R_COMMENT);
+
+		case SCLEX_SQL:
+			return (style == SCE_SQL_COMMENT ||
+				style == SCE_SQL_COMMENTLINE ||
+				style == SCE_SQL_COMMENTDOC);
+
+		case SCLEX_TCL:
+			return (style == SCE_TCL_COMMENT ||
+				style == SCE_TCL_COMMENTLINE ||
+				style == SCE_TCL_COMMENT_BOX ||
+				style == SCE_TCL_BLOCK_COMMENT);
+
+		case SCLEX_OCTAVE:
+			return (style == SCE_MATLAB_COMMENT);
+
+		case SCLEX_LUA:
+			return (style == SCE_LUA_COMMENT ||
+				style == SCE_LUA_COMMENTLINE ||
+				style == SCE_LUA_COMMENTDOC);
+
+		case SCLEX_HASKELL:
+			return (style == SCE_HA_COMMENTLINE ||
+				style == SCE_HA_COMMENTBLOCK ||
+				style == SCE_HA_COMMENTBLOCK2 ||
+				style == SCE_HA_COMMENTBLOCK3);
+
+		case SCLEX_FREEBASIC:
+			return (style == SCE_B_COMMENT);
+
+		case SCLEX_YAML:
+			return (style == SCE_YAML_COMMENT);
+
+		case SCLEX_HTML:
+			return (
+				style == SCE_HBA_COMMENTLINE ||
+				style == SCE_HB_COMMENTLINE ||
+				style == SCE_H_COMMENT ||
+				style == SCE_HJA_COMMENT ||
+				style == SCE_HJA_COMMENTDOC ||
+				style == SCE_HJA_COMMENTLINE ||
+				style == SCE_HJ_COMMENT ||
+				style == SCE_HJ_COMMENTDOC ||
+				style == SCE_HJ_COMMENTLINE ||
+				style == SCE_HPA_COMMENTLINE ||
+				style == SCE_HP_COMMENTLINE ||
+				style == SCE_HPHP_COMMENT ||
+				style == SCE_HPHP_COMMENTLINE ||
+				style == SCE_H_SGML_COMMENT);
+
+		case SCLEX_CMAKE:
+			return (style == SCE_CMAKE_COMMENT);
+
+		case SCLEX_NSIS:
+			return (style == SCE_NSIS_COMMENT ||
+				style == SCE_NSIS_COMMENTBOX);
+
+		case SCLEX_ADA:
+			return (style == SCE_ADA_COMMENTLINE ||
+				style == SCE_NSIS_COMMENTBOX);
+	}
+	return FALSE;
+}
+
+
+/** Checks whether the given style is normal code (not string, comment, preprocessor, etc).
+ *
+ * @param lexer Scintilla lexer type (@c SCLEX_*)
+ * @param style Scintilla style (@c SCE_*)
+ *
+ * @return @c TRUE if the style is code, @c FALSE otherwise
+ */
+gboolean highlighting_is_code_style(gint lexer, gint style)
+{
+	switch (lexer)
+	{
+		case SCLEX_CPP:
+			if (style == SCE_C_PREPROCESSOR)
+				return FALSE;
+			break;
+	}
+	return !(highlighting_is_comment_style(lexer, style) ||
+		highlighting_is_string_style(lexer, style));
+}
diff --git a/src/highlighting.h b/src/highlighting.h
index dd341bd..3199771 100644
--- a/src/highlighting.h
+++ b/src/highlighting.h
@@ -51,4 +51,8 @@ const GeanyLexerStyle *highlighting_get_style(gint ft_id, gint style_id);
 
 void highlighting_free_styles(void);
 
+gboolean highlighting_is_string_style (gint lexer, gint style);
+gboolean highlighting_is_comment_style (gint lexer, gint style);
+gboolean highlighting_is_code_style (gint lexer, gint style);
+
 #endif
diff --git a/src/plugindata.h b/src/plugindata.h
index d0d10fb..03f01ba 100644
--- a/src/plugindata.h
+++ b/src/plugindata.h
@@ -50,7 +50,7 @@
 enum {
 	/** The Application Programming Interface (API) version, incremented
 	 * whenever any plugin data types are modified or appended to. */
-	GEANY_API_VERSION = 197,
+	GEANY_API_VERSION = 198,
 
 	/** The Application Binary Interface (ABI) version, incremented whenever
 	 * existing fields in the plugin data types have to be changed or reordered. */
@@ -431,7 +431,7 @@ typedef struct UtilsFuncs
 	GSList*		(*utils_get_file_list_full)(const gchar *path, gboolean full_path, gboolean sort,
 				GError **error);
 	gchar**		(*utils_copy_environment)(const gchar **exclude_vars, const gchar *first_varname, ...);
-
+	gchar*		(*utils_find_open_xml_tag) (const gchar sel[], gint size);
 }
 UtilsFuncs;
 
@@ -541,6 +541,9 @@ typedef struct HighlightingFuncs
 {
 	const struct GeanyLexerStyle* (*highlighting_get_style) (gint ft_id, gint style_id);
 	void		(*highlighting_set_styles) (struct _ScintillaObject *sci, struct GeanyFiletype *ft);
+	gboolean	(*highlighting_is_string_style) (gint lexer, gint style);
+	gboolean	(*highlighting_is_comment_style) (gint lexer, gint style);
+	gboolean	(*highlighting_is_code_style) (gint lexer, gint style);
 }
 HighlightingFuncs;
 
@@ -613,6 +616,10 @@ typedef struct EditorFuncs
 
 	gint	(*editor_get_eol_char_mode) (struct GeanyEditor *editor);
 	gboolean (*editor_goto_pos) (struct GeanyEditor *editor, gint pos, gboolean mark);
+
+	const gchar* (*editor_find_snippet) (GeanyEditor *editor, const gchar *snippet_name);
+
+	void (*editor_insert_snippet) (GeanyEditor *editor, gint pos, const gchar *snippet);
 }
 EditorFuncs;
 
diff --git a/src/plugins.c b/src/plugins.c
index f2657b8..7e2ba5b 100644
--- a/src/plugins.c
+++ b/src/plugins.c
@@ -124,7 +124,9 @@ static EditorFuncs editor_funcs = {
 	&editor_get_eol_char,
 	&editor_insert_text_block,
 	&editor_get_eol_char_mode,
-	&editor_goto_pos
+	&editor_goto_pos,
+	&editor_find_snippet,
+	&editor_insert_snippet
 };
 
 static ScintillaFuncs scintilla_funcs = {
@@ -216,7 +218,8 @@ static UtilsFuncs utils_funcs = {
 	&utils_str_middle_truncate,
 	&utils_str_remove_chars,
 	&utils_get_file_list_full,
-	&utils_copy_environment
+	&utils_copy_environment,
+	&utils_find_open_xml_tag
 };
 
 static UIUtilsFuncs uiutils_funcs = {
@@ -291,7 +294,10 @@ static SearchFuncs search_funcs = {
 
 static HighlightingFuncs highlighting_funcs = {
 	&highlighting_get_style,
-	&highlighting_set_styles
+	&highlighting_set_styles,
+	&highlighting_is_string_style,
+	&highlighting_is_comment_style,
+	&highlighting_is_code_style
 };
 
 static FiletypeFuncs filetype_funcs = {
diff --git a/src/utils.c b/src/utils.c
index 78dc6ce..4127d91 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -276,13 +276,13 @@ gint utils_write_file(const gchar *filename, const gchar *text)
 }
 
 
-/*
- * (stolen from anjuta and modified)
- * Search backward through size bytes looking for a '<', then return the tag, if any.
+/** Search backward through @a size bytes looking for a '<', then return the tag, if any.
+ *
  * @return The tag name
  */
 gchar *utils_find_open_xml_tag(const gchar sel[], gint size)
 {
+	/* stolen from anjuta and modified */
 	const gchar *begin, *cur;
 
 	if (G_UNLIKELY(size < 3))
