[gtksourceview/wip/chergert/gsv-gtk4] wip: port to GTK 4



commit 4b991f24137d3e2e7945fc192a4a2585a31763f0
Author: Christian Hergert <chergert redhat com>
Date:   Thu Jan 9 19:04:53 2020 -0800

    wip: port to GTK 4

 docs/reference/gtksourceview-docs.xml.in           |    1 -
 docs/reference/meson.build                         |    1 -
 .../words/gtksourcecompletionwords.c               |    3 +-
 gtksourceview/gtksource-enumtypes.c                |  274 ++++
 gtksourceview/gtksource-enumtypes.h                |  101 ++
 gtksourceview/gtksource-marshal.c                  | 1178 ++++++++++++++
 gtksourceview/gtksource-marshal.h                  |  201 +++
 gtksourceview/gtksource.h                          |    1 -
 gtksourceview/gtksourceautocleanups.h              |    0
 gtksourceview/gtksourcebuffer-private.h            |   80 +-
 gtksourceview/gtksourcebuffer.c                    |  872 +++--------
 gtksourceview/gtksourcebuffer.h                    |  225 +--
 gtksourceview/gtksourcebufferinputstream-private.h |   46 +-
 gtksourceview/gtksourcebufferinputstream.c         |  126 +-
 gtksourceview/gtksourcebufferinternal-private.h    |   18 +-
 gtksourceview/gtksourcebufferinternal.c            |    8 +-
 .../gtksourcebufferoutputstream-private.h          |   51 +-
 gtksourceview/gtksourcebufferoutputstream.c        |  381 ++---
 gtksourceview/gtksourcecompletion.c                |   59 +-
 gtksourceview/gtksourcecompletion.ui               |    6 +-
 gtksourceview/gtksourcecompletioncontainer.c       |  222 ---
 gtksourceview/gtksourcecompletioninfo.c            |  159 +-
 gtksourceview/gtksourcecontextengine-private.h     |  145 +-
 gtksourceview/gtksourcecontextengine.c             | 1118 +++++++-------
 gtksourceview/gtksourceencoding-private.h          |   11 +-
 gtksourceview/gtksourceencoding.c                  |   10 +-
 gtksourceview/gtksourceencoding.h                  |   42 +-
 gtksourceview/gtksourceengine-private.h            |   82 +-
 gtksourceview/gtksourceengine.c                    |   44 +-
 gtksourceview/gtksourcefile-private.h              |   46 +-
 gtksourceview/gtksourcefile.c                      |  219 ++-
 gtksourceview/gtksourcefile.h                      |   78 +-
 gtksourceview/gtksourcefileloader.c                |  280 ++--
 gtksourceview/gtksourcefileloader.h                |  109 +-
 gtksourceview/gtksourcefilesaver.c                 |  331 ++--
 gtksourceview/gtksourcefilesaver.h                 |  131 +-
 gtksourceview/gtksourcegutter-private.h            |   15 +-
 gtksourceview/gtksourcegutter.c                    | 1601 +++++++-------------
 gtksourceview/gtksourcegutter.h                    |   60 +-
 gtksourceview/gtksourcegutterrenderer-private.h    |   22 +-
 gtksourceview/gtksourcegutterrenderer.c            | 1450 ++++++------------
 gtksourceview/gtksourcegutterrenderer.h            |  203 +--
 gtksourceview/gtksourcegutterrendererlines.c       |  340 ++---
 gtksourceview/gtksourcegutterrendererlines.h       |   68 +
 gtksourceview/gtksourcegutterrenderermarks.c       |   40 +-
 gtksourceview/gtksourcegutterrenderermarks.h       |   59 +
 gtksourceview/gtksourcegutterrendererpixbuf.c      |  212 +--
 gtksourceview/gtksourcegutterrendererpixbuf.h      |   62 +-
 gtksourceview/gtksourcegutterrenderertext.c        |  278 ++--
 gtksourceview/gtksourcegutterrenderertext.h        |   68 +-
 gtksourceview/gtksourceinit.c                      |   19 +-
 gtksourceview/gtksourceinit.h                      |   12 +-
 gtksourceview/gtksourceiter.c                      |   52 +-
 gtksourceview/gtksourceiter.h                      |   98 ++
 gtksourceview/gtksourcelanguage-parser-2.c         |   34 +-
 gtksourceview/gtksourcelanguage-private.h          |   87 +-
 gtksourceview/gtksourcelanguage.c                  |  249 ++-
 gtksourceview/gtksourcelanguage.h                  |   71 +-
 gtksourceview/gtksourcelanguagemanager-private.h   |    7 +-
 gtksourceview/gtksourcelanguagemanager.c           |  130 +-
 gtksourceview/gtksourcelanguagemanager.h           |   63 +-
 ...ontainer-private.h => gtksourcelines-private.h} |   24 +-
 gtksourceview/gtksourcelines.c                     |  641 ++++++++
 gtksourceview/gtksourcelines.h                     |   99 ++
 gtksourceview/gtksourcemap.c                       |  392 +++--
 gtksourceview/gtksourcemap.h                       |   38 +-
 gtksourceview/gtksourcemark.c                      |   49 +-
 gtksourceview/gtksourcemark.h                      |   50 +-
 gtksourceview/gtksourcemarkattributes.c            |  111 +-
 gtksourceview/gtksourcemarkattributes.h            |   92 +-
 gtksourceview/gtksourcemarkssequence-private.h     |   79 +-
 gtksourceview/gtksourcemarkssequence.c             |  150 +-
 gtksourceview/gtksourcemarshalers.list             |    7 +-
 gtksourceview/gtksourcepixbufhelper-private.h      |   45 +-
 gtksourceview/gtksourcepixbufhelper.c              |  102 +-
 gtksourceview/gtksourceprintcompositor.c           |  967 ++++++------
 gtksourceview/gtksourceprintcompositor.h           |  225 ++-
 gtksourceview/gtksourceregex.c                     |   11 +-
 gtksourceview/gtksourceregex.h                     |   85 ++
 gtksourceview/gtksourceregion.c                    |    8 +-
 gtksourceview/gtksourceregion.h                    |   89 +-
 gtksourceview/gtksourcesearchcontext-private.h     |    7 +-
 gtksourceview/gtksourcesearchcontext.c             |  969 ++++++------
 gtksourceview/gtksourcesearchcontext.h             |  164 +-
 gtksourceview/gtksourcesearchsettings.c            |  216 ++-
 gtksourceview/gtksourcesearchsettings.h            |   73 +-
 gtksourceview/gtksourcespacedrawer-private.h       |   15 +-
 gtksourceview/gtksourcespacedrawer.c               |  402 ++---
 gtksourceview/gtksourcespacedrawer.h               |   94 +-
 gtksourceview/gtksourcestyle-private.h             |   25 +-
 gtksourceview/gtksourcestyle.c                     |   44 +-
 gtksourceview/gtksourcestyle.h                     |   25 +-
 gtksourceview/gtksourcestylescheme-private.h       |   10 +-
 gtksourceview/gtksourcestylescheme.c               |  334 ++--
 gtksourceview/gtksourcestylescheme.h               |   52 +-
 gtksourceview/gtksourcestyleschemechooser.c        |    6 +-
 gtksourceview/gtksourcestyleschemechooser.h        |   35 +-
 gtksourceview/gtksourcestyleschemechooserbutton.c  |   36 +-
 gtksourceview/gtksourcestyleschemechooserbutton.h  |   31 +-
 gtksourceview/gtksourcestyleschemechooserwidget.c  |   53 +-
 gtksourceview/gtksourcestyleschemechooserwidget.h  |   34 +-
 .../gtksourcestyleschememanager-private.h          |    8 +-
 gtksourceview/gtksourcestyleschememanager.c        |  130 +-
 gtksourceview/gtksourcestyleschememanager.h        |   70 +-
 gtksourceview/gtksourcetag.c                       |   24 +-
 gtksourceview/gtksourcetag.h                       |   17 +-
 gtksourceview/gtksourcetypes-private.h             |   29 +-
 gtksourceview/gtksourcetypes.h                     |   71 +-
 gtksourceview/gtksourceundomanager.c               |  289 ----
 gtksourceview/gtksourceundomanager.h               |   88 --
 gtksourceview/gtksourceundomanagerdefault.c        | 1590 -------------------
 gtksourceview/gtksourceundomanagerdefault.h        |   59 -
 gtksourceview/gtksourceutils-private.h             |   35 +-
 gtksourceview/gtksourceutils.c                     |   12 +-
 gtksourceview/gtksourceutils.h                     |   12 +-
 gtksourceview/gtksourceversion.c                   |    6 +-
 gtksourceview/gtksourceview.c                      | 1593 ++++++++-----------
 gtksourceview/gtksourceview.h                      |  211 ++-
 gtksourceview/meson.build                          |   27 +-
 gtksourceview/quarkset-inline.h                    |  188 +++
 meson.build                                        |    2 +-
 po/POTFILES.in                                     |    1 -
 tests/meson.build                                  |    1 -
 tests/test-completion.c                            |   20 +-
 tests/test-search-performances.c                   |    2 +-
 tests/test-search.c                                |    8 +-
 tests/test-space-drawing.c                         |    4 +-
 tests/test-undo-manager-performances.c             |  103 --
 tests/test-widget.c                                |   31 +-
 testsuite/meson.build                              |    1 -
 testsuite/test-undo-manager.c                      |  918 -----------
 131 files changed, 10896 insertions(+), 12502 deletions(-)
---
diff --git a/docs/reference/gtksourceview-docs.xml.in b/docs/reference/gtksourceview-docs.xml.in
index c2f3ec7e..8669e238 100644
--- a/docs/reference/gtksourceview-docs.xml.in
+++ b/docs/reference/gtksourceview-docs.xml.in
@@ -90,7 +90,6 @@
       <xi:include href="xml/region.xml"/>
       <xi:include href="xml/spacedrawer.xml"/>
       <xi:include href="xml/tag.xml"/>
-      <xi:include href="xml/undomanager.xml"/>
       <xi:include href="xml/utils.xml"/>
       <xi:include href="xml/version.xml"/>
     </chapter>
diff --git a/docs/reference/meson.build b/docs/reference/meson.build
index f3a4e8f8..f1fa7427 100644
--- a/docs/reference/meson.build
+++ b/docs/reference/meson.build
@@ -39,7 +39,6 @@ reference_private_h = [
   'gtksourcestylescheme-private.h',
   'gtksourcestyleschememanager-private.h',
   'gtksourcetypes-private.h',
-  'gtksourceundomanagerdefault.h',
   'gtksourceutils-private.h',
 ]
 
diff --git a/gtksourceview/completion-providers/words/gtksourcecompletionwords.c 
b/gtksourceview/completion-providers/words/gtksourcecompletionwords.c
index 32b04e46..2cf8dc4d 100644
--- a/gtksourceview/completion-providers/words/gtksourcecompletionwords.c
+++ b/gtksourceview/completion-providers/words/gtksourcecompletionwords.c
@@ -268,8 +268,7 @@ gtk_source_completion_words_populate (GtkSourceCompletionProvider *provider,
        if (add_in_idle (words))
        {
                gtk_source_completion_words_library_lock (priv->library);
-               priv->idle_id = gdk_threads_add_idle ((GSourceFunc)add_in_idle,
-                                                            words);
+               priv->idle_id = g_idle_add ((GSourceFunc)add_in_idle, words);
        }
 }
 
diff --git a/gtksourceview/gtksource-enumtypes.c b/gtksourceview/gtksource-enumtypes.c
new file mode 100644
index 00000000..906d31db
--- /dev/null
+++ b/gtksourceview/gtksource-enumtypes.c
@@ -0,0 +1,274 @@
+
+/* This file is generated by glib-mkenums, do not modify it. This code is licensed under the same license as 
the containing project. Note that it links to GLib, so must comply with the LGPL linking clauses. */
+
+#include "gtksource-enumtypes.h"
+#include "gtksource.h"
+#include "gtksourceautocleanups.h"
+#include "gtksourcebuffer.h"
+#include "gtksourceencoding.h"
+#include "gtksourcefile.h"
+#include "gtksourcefileloader.h"
+#include "gtksourcefilesaver.h"
+#include "gtksourcegutterrenderer.h"
+#include "gtksourceinit.h"
+#include "gtksourcelanguage.h"
+#include "gtksourcelanguagemanager.h"
+#include "gtksourcemark.h"
+#include "gtksourcemarkattributes.h"
+#include "gtksourceprintcompositor.h"
+#include "gtksourceregion.h"
+#include "gtksourcesearchcontext.h"
+#include "gtksourcesearchsettings.h"
+#include "gtksourcespacedrawer.h"
+#include "gtksourcestyle.h"
+#include "gtksourcestylescheme.h"
+#include "gtksourcestyleschememanager.h"
+#include "gtksourcetag.h"
+#include "gtksourcetypes.h"
+#include "gtksourceutils.h"
+#include "gtksourceview.h"
+
+#define C_ENUM(v) ((gint) v)
+#define C_FLAGS(v) ((guint) v)
+
+/* enumerations from "gtksourcebuffer.h" */
+
+GType
+gtk_source_bracket_match_type_get_type (void)
+{
+  static volatile gsize gtype_id = 0;
+  static const GEnumValue values[] = {
+    { C_ENUM(GTK_SOURCE_BRACKET_MATCH_NONE), "GTK_SOURCE_BRACKET_MATCH_NONE", "none" },
+    { C_ENUM(GTK_SOURCE_BRACKET_MATCH_OUT_OF_RANGE), "GTK_SOURCE_BRACKET_MATCH_OUT_OF_RANGE", "out-of-range" 
},
+    { C_ENUM(GTK_SOURCE_BRACKET_MATCH_NOT_FOUND), "GTK_SOURCE_BRACKET_MATCH_NOT_FOUND", "not-found" },
+    { C_ENUM(GTK_SOURCE_BRACKET_MATCH_FOUND), "GTK_SOURCE_BRACKET_MATCH_FOUND", "found" },
+    { 0, NULL, NULL }
+  };
+  if (g_once_init_enter (&gtype_id)) {
+    GType new_type = g_enum_register_static (g_intern_static_string ("GtkSourceBracketMatchType"), values);
+    g_once_init_leave (&gtype_id, new_type);
+  }
+  return (GType) gtype_id;
+}
+
+GType
+gtk_source_change_case_type_get_type (void)
+{
+  static volatile gsize gtype_id = 0;
+  static const GEnumValue values[] = {
+    { C_ENUM(GTK_SOURCE_CHANGE_CASE_LOWER), "GTK_SOURCE_CHANGE_CASE_LOWER", "lower" },
+    { C_ENUM(GTK_SOURCE_CHANGE_CASE_UPPER), "GTK_SOURCE_CHANGE_CASE_UPPER", "upper" },
+    { C_ENUM(GTK_SOURCE_CHANGE_CASE_TOGGLE), "GTK_SOURCE_CHANGE_CASE_TOGGLE", "toggle" },
+    { C_ENUM(GTK_SOURCE_CHANGE_CASE_TITLE), "GTK_SOURCE_CHANGE_CASE_TITLE", "title" },
+    { 0, NULL, NULL }
+  };
+  if (g_once_init_enter (&gtype_id)) {
+    GType new_type = g_enum_register_static (g_intern_static_string ("GtkSourceChangeCaseType"), values);
+    g_once_init_leave (&gtype_id, new_type);
+  }
+  return (GType) gtype_id;
+}
+
+GType
+gtk_source_sort_flags_get_type (void)
+{
+  static volatile gsize gtype_id = 0;
+  static const GFlagsValue values[] = {
+    { C_FLAGS(GTK_SOURCE_SORT_FLAGS_NONE), "GTK_SOURCE_SORT_FLAGS_NONE", "none" },
+    { C_FLAGS(GTK_SOURCE_SORT_FLAGS_CASE_SENSITIVE), "GTK_SOURCE_SORT_FLAGS_CASE_SENSITIVE", 
"case-sensitive" },
+    { C_FLAGS(GTK_SOURCE_SORT_FLAGS_REVERSE_ORDER), "GTK_SOURCE_SORT_FLAGS_REVERSE_ORDER", "reverse-order" },
+    { C_FLAGS(GTK_SOURCE_SORT_FLAGS_REMOVE_DUPLICATES), "GTK_SOURCE_SORT_FLAGS_REMOVE_DUPLICATES", 
"remove-duplicates" },
+    { 0, NULL, NULL }
+  };
+  if (g_once_init_enter (&gtype_id)) {
+    GType new_type = g_flags_register_static (g_intern_static_string ("GtkSourceSortFlags"), values);
+    g_once_init_leave (&gtype_id, new_type);
+  }
+  return (GType) gtype_id;
+}
+
+/* enumerations from "gtksourcefile.h" */
+
+GType
+gtk_source_newline_type_get_type (void)
+{
+  static volatile gsize gtype_id = 0;
+  static const GEnumValue values[] = {
+    { C_ENUM(GTK_SOURCE_NEWLINE_TYPE_LF), "GTK_SOURCE_NEWLINE_TYPE_LF", "lf" },
+    { C_ENUM(GTK_SOURCE_NEWLINE_TYPE_CR), "GTK_SOURCE_NEWLINE_TYPE_CR", "cr" },
+    { C_ENUM(GTK_SOURCE_NEWLINE_TYPE_CR_LF), "GTK_SOURCE_NEWLINE_TYPE_CR_LF", "cr-lf" },
+    { 0, NULL, NULL }
+  };
+  if (g_once_init_enter (&gtype_id)) {
+    GType new_type = g_enum_register_static (g_intern_static_string ("GtkSourceNewlineType"), values);
+    g_once_init_leave (&gtype_id, new_type);
+  }
+  return (GType) gtype_id;
+}
+
+GType
+gtk_source_compression_type_get_type (void)
+{
+  static volatile gsize gtype_id = 0;
+  static const GEnumValue values[] = {
+    { C_ENUM(GTK_SOURCE_COMPRESSION_TYPE_NONE), "GTK_SOURCE_COMPRESSION_TYPE_NONE", "none" },
+    { C_ENUM(GTK_SOURCE_COMPRESSION_TYPE_GZIP), "GTK_SOURCE_COMPRESSION_TYPE_GZIP", "gzip" },
+    { 0, NULL, NULL }
+  };
+  if (g_once_init_enter (&gtype_id)) {
+    GType new_type = g_enum_register_static (g_intern_static_string ("GtkSourceCompressionType"), values);
+    g_once_init_leave (&gtype_id, new_type);
+  }
+  return (GType) gtype_id;
+}
+
+/* enumerations from "gtksourcefileloader.h" */
+
+GType
+gtk_source_file_loader_error_get_type (void)
+{
+  static volatile gsize gtype_id = 0;
+  static const GEnumValue values[] = {
+    { C_ENUM(GTK_SOURCE_FILE_LOADER_ERROR_TOO_BIG), "GTK_SOURCE_FILE_LOADER_ERROR_TOO_BIG", "too-big" },
+    { C_ENUM(GTK_SOURCE_FILE_LOADER_ERROR_ENCODING_AUTO_DETECTION_FAILED), 
"GTK_SOURCE_FILE_LOADER_ERROR_ENCODING_AUTO_DETECTION_FAILED", "encoding-auto-detection-failed" },
+    { C_ENUM(GTK_SOURCE_FILE_LOADER_ERROR_CONVERSION_FALLBACK), 
"GTK_SOURCE_FILE_LOADER_ERROR_CONVERSION_FALLBACK", "conversion-fallback" },
+    { 0, NULL, NULL }
+  };
+  if (g_once_init_enter (&gtype_id)) {
+    GType new_type = g_enum_register_static (g_intern_static_string ("GtkSourceFileLoaderError"), values);
+    g_once_init_leave (&gtype_id, new_type);
+  }
+  return (GType) gtype_id;
+}
+
+/* enumerations from "gtksourcefilesaver.h" */
+
+GType
+gtk_source_file_saver_error_get_type (void)
+{
+  static volatile gsize gtype_id = 0;
+  static const GEnumValue values[] = {
+    { C_ENUM(GTK_SOURCE_FILE_SAVER_ERROR_INVALID_CHARS), "GTK_SOURCE_FILE_SAVER_ERROR_INVALID_CHARS", 
"invalid-chars" },
+    { C_ENUM(GTK_SOURCE_FILE_SAVER_ERROR_EXTERNALLY_MODIFIED), 
"GTK_SOURCE_FILE_SAVER_ERROR_EXTERNALLY_MODIFIED", "externally-modified" },
+    { 0, NULL, NULL }
+  };
+  if (g_once_init_enter (&gtype_id)) {
+    GType new_type = g_enum_register_static (g_intern_static_string ("GtkSourceFileSaverError"), values);
+    g_once_init_leave (&gtype_id, new_type);
+  }
+  return (GType) gtype_id;
+}
+
+GType
+gtk_source_file_saver_flags_get_type (void)
+{
+  static volatile gsize gtype_id = 0;
+  static const GFlagsValue values[] = {
+    { C_FLAGS(GTK_SOURCE_FILE_SAVER_FLAGS_NONE), "GTK_SOURCE_FILE_SAVER_FLAGS_NONE", "none" },
+    { C_FLAGS(GTK_SOURCE_FILE_SAVER_FLAGS_IGNORE_INVALID_CHARS), 
"GTK_SOURCE_FILE_SAVER_FLAGS_IGNORE_INVALID_CHARS", "ignore-invalid-chars" },
+    { C_FLAGS(GTK_SOURCE_FILE_SAVER_FLAGS_IGNORE_MODIFICATION_TIME), 
"GTK_SOURCE_FILE_SAVER_FLAGS_IGNORE_MODIFICATION_TIME", "ignore-modification-time" },
+    { C_FLAGS(GTK_SOURCE_FILE_SAVER_FLAGS_CREATE_BACKUP), "GTK_SOURCE_FILE_SAVER_FLAGS_CREATE_BACKUP", 
"create-backup" },
+    { 0, NULL, NULL }
+  };
+  if (g_once_init_enter (&gtype_id)) {
+    GType new_type = g_flags_register_static (g_intern_static_string ("GtkSourceFileSaverFlags"), values);
+    g_once_init_leave (&gtype_id, new_type);
+  }
+  return (GType) gtype_id;
+}
+
+/* enumerations from "gtksourcespacedrawer.h" */
+
+GType
+gtk_source_space_type_flags_get_type (void)
+{
+  static volatile gsize gtype_id = 0;
+  static const GFlagsValue values[] = {
+    { C_FLAGS(GTK_SOURCE_SPACE_TYPE_NONE), "GTK_SOURCE_SPACE_TYPE_NONE", "none" },
+    { C_FLAGS(GTK_SOURCE_SPACE_TYPE_SPACE), "GTK_SOURCE_SPACE_TYPE_SPACE", "space" },
+    { C_FLAGS(GTK_SOURCE_SPACE_TYPE_TAB), "GTK_SOURCE_SPACE_TYPE_TAB", "tab" },
+    { C_FLAGS(GTK_SOURCE_SPACE_TYPE_NEWLINE), "GTK_SOURCE_SPACE_TYPE_NEWLINE", "newline" },
+    { C_FLAGS(GTK_SOURCE_SPACE_TYPE_NBSP), "GTK_SOURCE_SPACE_TYPE_NBSP", "nbsp" },
+    { C_FLAGS(GTK_SOURCE_SPACE_TYPE_ALL), "GTK_SOURCE_SPACE_TYPE_ALL", "all" },
+    { 0, NULL, NULL }
+  };
+  if (g_once_init_enter (&gtype_id)) {
+    GType new_type = g_flags_register_static (g_intern_static_string ("GtkSourceSpaceTypeFlags"), values);
+    g_once_init_leave (&gtype_id, new_type);
+  }
+  return (GType) gtype_id;
+}
+
+GType
+gtk_source_space_location_flags_get_type (void)
+{
+  static volatile gsize gtype_id = 0;
+  static const GFlagsValue values[] = {
+    { C_FLAGS(GTK_SOURCE_SPACE_LOCATION_NONE), "GTK_SOURCE_SPACE_LOCATION_NONE", "none" },
+    { C_FLAGS(GTK_SOURCE_SPACE_LOCATION_LEADING), "GTK_SOURCE_SPACE_LOCATION_LEADING", "leading" },
+    { C_FLAGS(GTK_SOURCE_SPACE_LOCATION_INSIDE_TEXT), "GTK_SOURCE_SPACE_LOCATION_INSIDE_TEXT", "inside-text" 
},
+    { C_FLAGS(GTK_SOURCE_SPACE_LOCATION_TRAILING), "GTK_SOURCE_SPACE_LOCATION_TRAILING", "trailing" },
+    { C_FLAGS(GTK_SOURCE_SPACE_LOCATION_ALL), "GTK_SOURCE_SPACE_LOCATION_ALL", "all" },
+    { 0, NULL, NULL }
+  };
+  if (g_once_init_enter (&gtype_id)) {
+    GType new_type = g_flags_register_static (g_intern_static_string ("GtkSourceSpaceLocationFlags"), 
values);
+    g_once_init_leave (&gtype_id, new_type);
+  }
+  return (GType) gtype_id;
+}
+
+/* enumerations from "gtksourceview.h" */
+
+GType
+gtk_source_smart_home_end_type_get_type (void)
+{
+  static volatile gsize gtype_id = 0;
+  static const GEnumValue values[] = {
+    { C_ENUM(GTK_SOURCE_SMART_HOME_END_DISABLED), "GTK_SOURCE_SMART_HOME_END_DISABLED", "disabled" },
+    { C_ENUM(GTK_SOURCE_SMART_HOME_END_BEFORE), "GTK_SOURCE_SMART_HOME_END_BEFORE", "before" },
+    { C_ENUM(GTK_SOURCE_SMART_HOME_END_AFTER), "GTK_SOURCE_SMART_HOME_END_AFTER", "after" },
+    { C_ENUM(GTK_SOURCE_SMART_HOME_END_ALWAYS), "GTK_SOURCE_SMART_HOME_END_ALWAYS", "always" },
+    { 0, NULL, NULL }
+  };
+  if (g_once_init_enter (&gtype_id)) {
+    GType new_type = g_enum_register_static (g_intern_static_string ("GtkSourceSmartHomeEndType"), values);
+    g_once_init_leave (&gtype_id, new_type);
+  }
+  return (GType) gtype_id;
+}
+
+GType
+gtk_source_background_pattern_type_get_type (void)
+{
+  static volatile gsize gtype_id = 0;
+  static const GEnumValue values[] = {
+    { C_ENUM(GTK_SOURCE_BACKGROUND_PATTERN_TYPE_NONE), "GTK_SOURCE_BACKGROUND_PATTERN_TYPE_NONE", "none" },
+    { C_ENUM(GTK_SOURCE_BACKGROUND_PATTERN_TYPE_GRID), "GTK_SOURCE_BACKGROUND_PATTERN_TYPE_GRID", "grid" },
+    { 0, NULL, NULL }
+  };
+  if (g_once_init_enter (&gtype_id)) {
+    GType new_type = g_enum_register_static (g_intern_static_string ("GtkSourceBackgroundPatternType"), 
values);
+    g_once_init_leave (&gtype_id, new_type);
+  }
+  return (GType) gtype_id;
+}
+
+/* Generated data ends here */
+
+GType
+gtk_source_gutter_renderer_alignment_mode_get_type (void)
+{
+  static volatile gsize gtype_id = 0;
+  static const GEnumValue values[] = {
+    { C_ENUM(GTK_SOURCE_GUTTER_RENDERER_ALIGNMENT_MODE_CELL), 
"GTK_SOURCE_GUTTER_RENDERER_ALIGNMENT_MODE_CELL", "cell" },
+    { C_ENUM(GTK_SOURCE_GUTTER_RENDERER_ALIGNMENT_MODE_FIRST), 
"GTK_SOURCE_GUTTER_RENDERER_ALIGNMENT_MODE_FIRST", "first" },
+    { C_ENUM(GTK_SOURCE_GUTTER_RENDERER_ALIGNMENT_MODE_LAST), 
"GTK_SOURCE_GUTTER_RENDERER_ALIGNMENT_MODE_LAST", "last" },
+    { 0, NULL, NULL }
+  };
+  if (g_once_init_enter (&gtype_id)) {
+    GType new_type = g_enum_register_static (g_intern_static_string 
("GtkSourceGutterRendererAlignmentMode"), values);
+    g_once_init_leave (&gtype_id, new_type);
+  }
+  return (GType) gtype_id;
+}
diff --git a/gtksourceview/gtksource-enumtypes.h b/gtksourceview/gtksource-enumtypes.h
new file mode 100644
index 00000000..843cf9b6
--- /dev/null
+++ b/gtksourceview/gtksource-enumtypes.h
@@ -0,0 +1,101 @@
+
+/* This file is generated by glib-mkenums, do not modify it. This code is licensed under the same license as 
the containing project. Note that it links to GLib, so must comply with the LGPL linking clauses. */
+
+#pragma once
+
+#include <glib-object.h>
+
+
+#if defined (GTK_SOURCE_COMPILATION) && defined (HAVE_CONFIG_H)
+# include <config.h>
+#endif
+
+#if !defined (GTK_SOURCE_H_INSIDE) && !defined (GTK_SOURCE_COMPILATION)
+# error "Only <gtksourceview/gtksource.h> can be included directly."
+#endif
+
+#include "gtksourceversion.h"
+
+
+G_BEGIN_DECLS
+
+/* enumerations from "gtksourcebuffer.h" */
+
+GTK_SOURCE_ENUM_EXTERN
+GType gtk_source_bracket_match_type_get_type (void);
+#define GTK_SOURCE_TYPE_BRACKET_MATCH_TYPE (gtk_source_bracket_match_type_get_type())
+
+GTK_SOURCE_ENUM_EXTERN
+GType gtk_source_change_case_type_get_type (void);
+#define GTK_SOURCE_TYPE_CHANGE_CASE_TYPE (gtk_source_change_case_type_get_type())
+
+GTK_SOURCE_ENUM_EXTERN
+GType gtk_source_sort_flags_get_type (void);
+#define GTK_SOURCE_TYPE_SORT_FLAGS (gtk_source_sort_flags_get_type())
+
+/* enumerations from "gtksourcecompletion.h" */
+
+GTK_SOURCE_ENUM_EXTERN
+GType gtk_source_completion_error_get_type (void);
+#define GTK_SOURCE_TYPE_COMPLETION_ERROR (gtk_source_completion_error_get_type())
+
+/* enumerations from "gtksourcecompletioncontext.h" */
+
+GTK_SOURCE_ENUM_EXTERN
+GType gtk_source_completion_activation_get_type (void);
+#define GTK_SOURCE_TYPE_COMPLETION_ACTIVATION (gtk_source_completion_activation_get_type())
+
+/* enumerations from "gtksourcefile.h" */
+
+GTK_SOURCE_ENUM_EXTERN
+GType gtk_source_newline_type_get_type (void);
+#define GTK_SOURCE_TYPE_NEWLINE_TYPE (gtk_source_newline_type_get_type())
+
+GTK_SOURCE_ENUM_EXTERN
+GType gtk_source_compression_type_get_type (void);
+#define GTK_SOURCE_TYPE_COMPRESSION_TYPE (gtk_source_compression_type_get_type())
+
+/* enumerations from "gtksourcefileloader.h" */
+
+GTK_SOURCE_ENUM_EXTERN
+GType gtk_source_file_loader_error_get_type (void);
+#define GTK_SOURCE_TYPE_FILE_LOADER_ERROR (gtk_source_file_loader_error_get_type())
+
+/* enumerations from "gtksourcefilesaver.h" */
+
+GTK_SOURCE_ENUM_EXTERN
+GType gtk_source_file_saver_error_get_type (void);
+#define GTK_SOURCE_TYPE_FILE_SAVER_ERROR (gtk_source_file_saver_error_get_type())
+
+GTK_SOURCE_ENUM_EXTERN
+GType gtk_source_file_saver_flags_get_type (void);
+#define GTK_SOURCE_TYPE_FILE_SAVER_FLAGS (gtk_source_file_saver_flags_get_type())
+
+/* enumerations from "gtksourcespacedrawer.h" */
+
+GTK_SOURCE_ENUM_EXTERN
+GType gtk_source_space_type_flags_get_type (void);
+#define GTK_SOURCE_TYPE_SPACE_TYPE_FLAGS (gtk_source_space_type_flags_get_type())
+
+GTK_SOURCE_ENUM_EXTERN
+GType gtk_source_space_location_flags_get_type (void);
+#define GTK_SOURCE_TYPE_SPACE_LOCATION_FLAGS (gtk_source_space_location_flags_get_type())
+
+/* enumerations from "gtksourceview.h" */
+
+GTK_SOURCE_ENUM_EXTERN
+GType gtk_source_smart_home_end_type_get_type (void);
+#define GTK_SOURCE_TYPE_SMART_HOME_END_TYPE (gtk_source_smart_home_end_type_get_type())
+
+GTK_SOURCE_ENUM_EXTERN
+GType gtk_source_background_pattern_type_get_type (void);
+#define GTK_SOURCE_TYPE_BACKGROUND_PATTERN_TYPE (gtk_source_background_pattern_type_get_type())
+
+GTK_SOURCE_ENUM_EXTERN
+GType gtk_source_gutter_renderer_alignment_mode_get_type (void);
+#define GTK_SOURCE_TYPE_GUTTER_RENDERER_ALIGNMENT_MODE (gtk_source_gutter_renderer_alignment_mode_get_type())
+
+G_END_DECLS
+
+/* Generated data ends here */
+
diff --git a/gtksourceview/gtksource-marshal.c b/gtksourceview/gtksource-marshal.c
new file mode 100644
index 00000000..94c3479f
--- /dev/null
+++ b/gtksourceview/gtksource-marshal.c
@@ -0,0 +1,1178 @@
+/* This file is generated by glib-genmarshal, do not modify it. This code is licensed under the same license 
as the containing project. Note that it links to GLib, so must comply with the LGPL linking clauses. */
+#include "gtksource-marshal.h"
+
+#include <glib-object.h>
+
+#ifdef G_ENABLE_DEBUG
+#define g_marshal_value_peek_boolean(v)  g_value_get_boolean (v)
+#define g_marshal_value_peek_char(v)     g_value_get_schar (v)
+#define g_marshal_value_peek_uchar(v)    g_value_get_uchar (v)
+#define g_marshal_value_peek_int(v)      g_value_get_int (v)
+#define g_marshal_value_peek_uint(v)     g_value_get_uint (v)
+#define g_marshal_value_peek_long(v)     g_value_get_long (v)
+#define g_marshal_value_peek_ulong(v)    g_value_get_ulong (v)
+#define g_marshal_value_peek_int64(v)    g_value_get_int64 (v)
+#define g_marshal_value_peek_uint64(v)   g_value_get_uint64 (v)
+#define g_marshal_value_peek_enum(v)     g_value_get_enum (v)
+#define g_marshal_value_peek_flags(v)    g_value_get_flags (v)
+#define g_marshal_value_peek_float(v)    g_value_get_float (v)
+#define g_marshal_value_peek_double(v)   g_value_get_double (v)
+#define g_marshal_value_peek_string(v)   (char*) g_value_get_string (v)
+#define g_marshal_value_peek_param(v)    g_value_get_param (v)
+#define g_marshal_value_peek_boxed(v)    g_value_get_boxed (v)
+#define g_marshal_value_peek_pointer(v)  g_value_get_pointer (v)
+#define g_marshal_value_peek_object(v)   g_value_get_object (v)
+#define g_marshal_value_peek_variant(v)  g_value_get_variant (v)
+#else /* !G_ENABLE_DEBUG */
+/* WARNING: This code accesses GValues directly, which is UNSUPPORTED API.
+ *          Do not access GValues directly in your code. Instead, use the
+ *          g_value_get_*() functions
+ */
+#define g_marshal_value_peek_boolean(v)  (v)->data[0].v_int
+#define g_marshal_value_peek_char(v)     (v)->data[0].v_int
+#define g_marshal_value_peek_uchar(v)    (v)->data[0].v_uint
+#define g_marshal_value_peek_int(v)      (v)->data[0].v_int
+#define g_marshal_value_peek_uint(v)     (v)->data[0].v_uint
+#define g_marshal_value_peek_long(v)     (v)->data[0].v_long
+#define g_marshal_value_peek_ulong(v)    (v)->data[0].v_ulong
+#define g_marshal_value_peek_int64(v)    (v)->data[0].v_int64
+#define g_marshal_value_peek_uint64(v)   (v)->data[0].v_uint64
+#define g_marshal_value_peek_enum(v)     (v)->data[0].v_long
+#define g_marshal_value_peek_flags(v)    (v)->data[0].v_ulong
+#define g_marshal_value_peek_float(v)    (v)->data[0].v_float
+#define g_marshal_value_peek_double(v)   (v)->data[0].v_double
+#define g_marshal_value_peek_string(v)   (v)->data[0].v_pointer
+#define g_marshal_value_peek_param(v)    (v)->data[0].v_pointer
+#define g_marshal_value_peek_boxed(v)    (v)->data[0].v_pointer
+#define g_marshal_value_peek_pointer(v)  (v)->data[0].v_pointer
+#define g_marshal_value_peek_object(v)   (v)->data[0].v_pointer
+#define g_marshal_value_peek_variant(v)  (v)->data[0].v_pointer
+#endif /* !G_ENABLE_DEBUG */
+
+void
+_gtk_source_marshal_BOOLEAN__BOXED_BOXED_INT_INT_OBJECT (GClosure     *closure,
+                                                         GValue       *return_value,
+                                                         guint         n_param_values,
+                                                         const GValue *param_values,
+                                                         gpointer      invocation_hint G_GNUC_UNUSED,
+                                                         gpointer      marshal_data)
+{
+  typedef gboolean (*GMarshalFunc_BOOLEAN__BOXED_BOXED_INT_INT_OBJECT) (gpointer data1,
+                                                                        gpointer arg1,
+                                                                        gpointer arg2,
+                                                                        gint arg3,
+                                                                        gint arg4,
+                                                                        gpointer arg5,
+                                                                        gpointer data2);
+  GCClosure *cc = (GCClosure *) closure;
+  gpointer data1, data2;
+  GMarshalFunc_BOOLEAN__BOXED_BOXED_INT_INT_OBJECT callback;
+  gboolean v_return;
+
+  g_return_if_fail (return_value != NULL);
+  g_return_if_fail (n_param_values == 6);
+
+  if (G_CCLOSURE_SWAP_DATA (closure))
+    {
+      data1 = closure->data;
+      data2 = g_value_peek_pointer (param_values + 0);
+    }
+  else
+    {
+      data1 = g_value_peek_pointer (param_values + 0);
+      data2 = closure->data;
+    }
+  callback = (GMarshalFunc_BOOLEAN__BOXED_BOXED_INT_INT_OBJECT) (marshal_data ? marshal_data : cc->callback);
+
+  v_return = callback (data1,
+                       g_marshal_value_peek_boxed (param_values + 1),
+                       g_marshal_value_peek_boxed (param_values + 2),
+                       g_marshal_value_peek_int (param_values + 3),
+                       g_marshal_value_peek_int (param_values + 4),
+                       g_marshal_value_peek_object (param_values + 5),
+                       data2);
+
+  g_value_set_boolean (return_value, v_return);
+}
+
+void
+_gtk_source_marshal_BOOLEAN__BOXED_BOXED_INT_INT_OBJECTv (GClosure *closure,
+                                                          GValue   *return_value,
+                                                          gpointer  instance,
+                                                          va_list   args,
+                                                          gpointer  marshal_data,
+                                                          int       n_params,
+                                                          GType    *param_types)
+{
+  typedef gboolean (*GMarshalFunc_BOOLEAN__BOXED_BOXED_INT_INT_OBJECT) (gpointer data1,
+                                                                        gpointer arg1,
+                                                                        gpointer arg2,
+                                                                        gint arg3,
+                                                                        gint arg4,
+                                                                        gpointer arg5,
+                                                                        gpointer data2);
+  GCClosure *cc = (GCClosure *) closure;
+  gpointer data1, data2;
+  GMarshalFunc_BOOLEAN__BOXED_BOXED_INT_INT_OBJECT callback;
+  gboolean v_return;
+  gpointer arg0;
+  gpointer arg1;
+  gint arg2;
+  gint arg3;
+  gpointer arg4;
+  va_list args_copy;
+
+  G_VA_COPY (args_copy, args);
+  arg0 = (gpointer) va_arg (args_copy, gpointer);
+  if ((param_types[0] & G_SIGNAL_TYPE_STATIC_SCOPE) == 0 && arg0 != NULL)
+    arg0 = g_boxed_copy (param_types[0] & ~G_SIGNAL_TYPE_STATIC_SCOPE, arg0);
+  arg1 = (gpointer) va_arg (args_copy, gpointer);
+  if ((param_types[1] & G_SIGNAL_TYPE_STATIC_SCOPE) == 0 && arg1 != NULL)
+    arg1 = g_boxed_copy (param_types[1] & ~G_SIGNAL_TYPE_STATIC_SCOPE, arg1);
+  arg2 = (gint) va_arg (args_copy, gint);
+  arg3 = (gint) va_arg (args_copy, gint);
+  arg4 = (gpointer) va_arg (args_copy, gpointer);
+  if (arg4 != NULL)
+    arg4 = g_object_ref (arg4);
+  va_end (args_copy);
+
+  g_return_if_fail (return_value != NULL);
+
+  if (G_CCLOSURE_SWAP_DATA (closure))
+    {
+      data1 = closure->data;
+      data2 = instance;
+    }
+  else
+    {
+      data1 = instance;
+      data2 = closure->data;
+    }
+  callback = (GMarshalFunc_BOOLEAN__BOXED_BOXED_INT_INT_OBJECT) (marshal_data ? marshal_data : cc->callback);
+
+  v_return = callback (data1,
+                       arg0,
+                       arg1,
+                       arg2,
+                       arg3,
+                       arg4,
+                       data2);
+  if ((param_types[0] & G_SIGNAL_TYPE_STATIC_SCOPE) == 0 && arg0 != NULL)
+    g_boxed_free (param_types[0] & ~G_SIGNAL_TYPE_STATIC_SCOPE, arg0);
+  if ((param_types[1] & G_SIGNAL_TYPE_STATIC_SCOPE) == 0 && arg1 != NULL)
+    g_boxed_free (param_types[1] & ~G_SIGNAL_TYPE_STATIC_SCOPE, arg1);
+  if (arg4 != NULL)
+    g_object_unref (arg4);
+
+  g_value_set_boolean (return_value, v_return);
+}
+
+void
+_gtk_source_marshal_BOOLEAN__BOXED_BOXED_BOXED (GClosure     *closure,
+                                                GValue       *return_value,
+                                                guint         n_param_values,
+                                                const GValue *param_values,
+                                                gpointer      invocation_hint G_GNUC_UNUSED,
+                                                gpointer      marshal_data)
+{
+  typedef gboolean (*GMarshalFunc_BOOLEAN__BOXED_BOXED_BOXED) (gpointer data1,
+                                                               gpointer arg1,
+                                                               gpointer arg2,
+                                                               gpointer arg3,
+                                                               gpointer data2);
+  GCClosure *cc = (GCClosure *) closure;
+  gpointer data1, data2;
+  GMarshalFunc_BOOLEAN__BOXED_BOXED_BOXED callback;
+  gboolean v_return;
+
+  g_return_if_fail (return_value != NULL);
+  g_return_if_fail (n_param_values == 4);
+
+  if (G_CCLOSURE_SWAP_DATA (closure))
+    {
+      data1 = closure->data;
+      data2 = g_value_peek_pointer (param_values + 0);
+    }
+  else
+    {
+      data1 = g_value_peek_pointer (param_values + 0);
+      data2 = closure->data;
+    }
+  callback = (GMarshalFunc_BOOLEAN__BOXED_BOXED_BOXED) (marshal_data ? marshal_data : cc->callback);
+
+  v_return = callback (data1,
+                       g_marshal_value_peek_boxed (param_values + 1),
+                       g_marshal_value_peek_boxed (param_values + 2),
+                       g_marshal_value_peek_boxed (param_values + 3),
+                       data2);
+
+  g_value_set_boolean (return_value, v_return);
+}
+
+void
+_gtk_source_marshal_BOOLEAN__BOXED_BOXED_BOXEDv (GClosure *closure,
+                                                 GValue   *return_value,
+                                                 gpointer  instance,
+                                                 va_list   args,
+                                                 gpointer  marshal_data,
+                                                 int       n_params,
+                                                 GType    *param_types)
+{
+  typedef gboolean (*GMarshalFunc_BOOLEAN__BOXED_BOXED_BOXED) (gpointer data1,
+                                                               gpointer arg1,
+                                                               gpointer arg2,
+                                                               gpointer arg3,
+                                                               gpointer data2);
+  GCClosure *cc = (GCClosure *) closure;
+  gpointer data1, data2;
+  GMarshalFunc_BOOLEAN__BOXED_BOXED_BOXED callback;
+  gboolean v_return;
+  gpointer arg0;
+  gpointer arg1;
+  gpointer arg2;
+  va_list args_copy;
+
+  G_VA_COPY (args_copy, args);
+  arg0 = (gpointer) va_arg (args_copy, gpointer);
+  if ((param_types[0] & G_SIGNAL_TYPE_STATIC_SCOPE) == 0 && arg0 != NULL)
+    arg0 = g_boxed_copy (param_types[0] & ~G_SIGNAL_TYPE_STATIC_SCOPE, arg0);
+  arg1 = (gpointer) va_arg (args_copy, gpointer);
+  if ((param_types[1] & G_SIGNAL_TYPE_STATIC_SCOPE) == 0 && arg1 != NULL)
+    arg1 = g_boxed_copy (param_types[1] & ~G_SIGNAL_TYPE_STATIC_SCOPE, arg1);
+  arg2 = (gpointer) va_arg (args_copy, gpointer);
+  if ((param_types[2] & G_SIGNAL_TYPE_STATIC_SCOPE) == 0 && arg2 != NULL)
+    arg2 = g_boxed_copy (param_types[2] & ~G_SIGNAL_TYPE_STATIC_SCOPE, arg2);
+  va_end (args_copy);
+
+  g_return_if_fail (return_value != NULL);
+
+  if (G_CCLOSURE_SWAP_DATA (closure))
+    {
+      data1 = closure->data;
+      data2 = instance;
+    }
+  else
+    {
+      data1 = instance;
+      data2 = closure->data;
+    }
+  callback = (GMarshalFunc_BOOLEAN__BOXED_BOXED_BOXED) (marshal_data ? marshal_data : cc->callback);
+
+  v_return = callback (data1,
+                       arg0,
+                       arg1,
+                       arg2,
+                       data2);
+  if ((param_types[0] & G_SIGNAL_TYPE_STATIC_SCOPE) == 0 && arg0 != NULL)
+    g_boxed_free (param_types[0] & ~G_SIGNAL_TYPE_STATIC_SCOPE, arg0);
+  if ((param_types[1] & G_SIGNAL_TYPE_STATIC_SCOPE) == 0 && arg1 != NULL)
+    g_boxed_free (param_types[1] & ~G_SIGNAL_TYPE_STATIC_SCOPE, arg1);
+  if ((param_types[2] & G_SIGNAL_TYPE_STATIC_SCOPE) == 0 && arg2 != NULL)
+    g_boxed_free (param_types[2] & ~G_SIGNAL_TYPE_STATIC_SCOPE, arg2);
+
+  g_value_set_boolean (return_value, v_return);
+}
+
+void
+_gtk_source_marshal_STRING__OBJECT (GClosure     *closure,
+                                    GValue       *return_value,
+                                    guint         n_param_values,
+                                    const GValue *param_values,
+                                    gpointer      invocation_hint G_GNUC_UNUSED,
+                                    gpointer      marshal_data)
+{
+  typedef gchar* (*GMarshalFunc_STRING__OBJECT) (gpointer data1,
+                                                 gpointer arg1,
+                                                 gpointer data2);
+  GCClosure *cc = (GCClosure *) closure;
+  gpointer data1, data2;
+  GMarshalFunc_STRING__OBJECT callback;
+  gchar* v_return;
+
+  g_return_if_fail (return_value != NULL);
+  g_return_if_fail (n_param_values == 2);
+
+  if (G_CCLOSURE_SWAP_DATA (closure))
+    {
+      data1 = closure->data;
+      data2 = g_value_peek_pointer (param_values + 0);
+    }
+  else
+    {
+      data1 = g_value_peek_pointer (param_values + 0);
+      data2 = closure->data;
+    }
+  callback = (GMarshalFunc_STRING__OBJECT) (marshal_data ? marshal_data : cc->callback);
+
+  v_return = callback (data1,
+                       g_marshal_value_peek_object (param_values + 1),
+                       data2);
+
+  g_value_take_string (return_value, v_return);
+}
+
+void
+_gtk_source_marshal_STRING__OBJECTv (GClosure *closure,
+                                     GValue   *return_value,
+                                     gpointer  instance,
+                                     va_list   args,
+                                     gpointer  marshal_data,
+                                     int       n_params,
+                                     GType    *param_types)
+{
+  typedef gchar* (*GMarshalFunc_STRING__OBJECT) (gpointer data1,
+                                                 gpointer arg1,
+                                                 gpointer data2);
+  GCClosure *cc = (GCClosure *) closure;
+  gpointer data1, data2;
+  GMarshalFunc_STRING__OBJECT callback;
+  gchar* v_return;
+  gpointer arg0;
+  va_list args_copy;
+
+  G_VA_COPY (args_copy, args);
+  arg0 = (gpointer) va_arg (args_copy, gpointer);
+  if (arg0 != NULL)
+    arg0 = g_object_ref (arg0);
+  va_end (args_copy);
+
+  g_return_if_fail (return_value != NULL);
+
+  if (G_CCLOSURE_SWAP_DATA (closure))
+    {
+      data1 = closure->data;
+      data2 = instance;
+    }
+  else
+    {
+      data1 = instance;
+      data2 = closure->data;
+    }
+  callback = (GMarshalFunc_STRING__OBJECT) (marshal_data ? marshal_data : cc->callback);
+
+  v_return = callback (data1,
+                       arg0,
+                       data2);
+  if (arg0 != NULL)
+    g_object_unref (arg0);
+
+  g_value_take_string (return_value, v_return);
+}
+
+void
+_gtk_source_marshal_VOID__BOXED_BOXED (GClosure     *closure,
+                                       GValue       *return_value G_GNUC_UNUSED,
+                                       guint         n_param_values,
+                                       const GValue *param_values,
+                                       gpointer      invocation_hint G_GNUC_UNUSED,
+                                       gpointer      marshal_data)
+{
+  typedef void (*GMarshalFunc_VOID__BOXED_BOXED) (gpointer data1,
+                                                  gpointer arg1,
+                                                  gpointer arg2,
+                                                  gpointer data2);
+  GCClosure *cc = (GCClosure *) closure;
+  gpointer data1, data2;
+  GMarshalFunc_VOID__BOXED_BOXED callback;
+
+  g_return_if_fail (n_param_values == 3);
+
+  if (G_CCLOSURE_SWAP_DATA (closure))
+    {
+      data1 = closure->data;
+      data2 = g_value_peek_pointer (param_values + 0);
+    }
+  else
+    {
+      data1 = g_value_peek_pointer (param_values + 0);
+      data2 = closure->data;
+    }
+  callback = (GMarshalFunc_VOID__BOXED_BOXED) (marshal_data ? marshal_data : cc->callback);
+
+  callback (data1,
+            g_marshal_value_peek_boxed (param_values + 1),
+            g_marshal_value_peek_boxed (param_values + 2),
+            data2);
+}
+
+void
+_gtk_source_marshal_VOID__BOXED_BOXEDv (GClosure *closure,
+                                        GValue   *return_value G_GNUC_UNUSED,
+                                        gpointer  instance,
+                                        va_list   args,
+                                        gpointer  marshal_data,
+                                        int       n_params,
+                                        GType    *param_types)
+{
+  typedef void (*GMarshalFunc_VOID__BOXED_BOXED) (gpointer data1,
+                                                  gpointer arg1,
+                                                  gpointer arg2,
+                                                  gpointer data2);
+  GCClosure *cc = (GCClosure *) closure;
+  gpointer data1, data2;
+  GMarshalFunc_VOID__BOXED_BOXED callback;
+  gpointer arg0;
+  gpointer arg1;
+  va_list args_copy;
+
+  G_VA_COPY (args_copy, args);
+  arg0 = (gpointer) va_arg (args_copy, gpointer);
+  if ((param_types[0] & G_SIGNAL_TYPE_STATIC_SCOPE) == 0 && arg0 != NULL)
+    arg0 = g_boxed_copy (param_types[0] & ~G_SIGNAL_TYPE_STATIC_SCOPE, arg0);
+  arg1 = (gpointer) va_arg (args_copy, gpointer);
+  if ((param_types[1] & G_SIGNAL_TYPE_STATIC_SCOPE) == 0 && arg1 != NULL)
+    arg1 = g_boxed_copy (param_types[1] & ~G_SIGNAL_TYPE_STATIC_SCOPE, arg1);
+  va_end (args_copy);
+
+
+  if (G_CCLOSURE_SWAP_DATA (closure))
+    {
+      data1 = closure->data;
+      data2 = instance;
+    }
+  else
+    {
+      data1 = instance;
+      data2 = closure->data;
+    }
+  callback = (GMarshalFunc_VOID__BOXED_BOXED) (marshal_data ? marshal_data : cc->callback);
+
+  callback (data1,
+            arg0,
+            arg1,
+            data2);
+  if ((param_types[0] & G_SIGNAL_TYPE_STATIC_SCOPE) == 0 && arg0 != NULL)
+    g_boxed_free (param_types[0] & ~G_SIGNAL_TYPE_STATIC_SCOPE, arg0);
+  if ((param_types[1] & G_SIGNAL_TYPE_STATIC_SCOPE) == 0 && arg1 != NULL)
+    g_boxed_free (param_types[1] & ~G_SIGNAL_TYPE_STATIC_SCOPE, arg1);
+}
+
+void
+_gtk_source_marshal_VOID__BOXED_BOXED_BOXED (GClosure     *closure,
+                                             GValue       *return_value G_GNUC_UNUSED,
+                                             guint         n_param_values,
+                                             const GValue *param_values,
+                                             gpointer      invocation_hint G_GNUC_UNUSED,
+                                             gpointer      marshal_data)
+{
+  typedef void (*GMarshalFunc_VOID__BOXED_BOXED_BOXED) (gpointer data1,
+                                                        gpointer arg1,
+                                                        gpointer arg2,
+                                                        gpointer arg3,
+                                                        gpointer data2);
+  GCClosure *cc = (GCClosure *) closure;
+  gpointer data1, data2;
+  GMarshalFunc_VOID__BOXED_BOXED_BOXED callback;
+
+  g_return_if_fail (n_param_values == 4);
+
+  if (G_CCLOSURE_SWAP_DATA (closure))
+    {
+      data1 = closure->data;
+      data2 = g_value_peek_pointer (param_values + 0);
+    }
+  else
+    {
+      data1 = g_value_peek_pointer (param_values + 0);
+      data2 = closure->data;
+    }
+  callback = (GMarshalFunc_VOID__BOXED_BOXED_BOXED) (marshal_data ? marshal_data : cc->callback);
+
+  callback (data1,
+            g_marshal_value_peek_boxed (param_values + 1),
+            g_marshal_value_peek_boxed (param_values + 2),
+            g_marshal_value_peek_boxed (param_values + 3),
+            data2);
+}
+
+void
+_gtk_source_marshal_VOID__BOXED_BOXED_BOXEDv (GClosure *closure,
+                                              GValue   *return_value G_GNUC_UNUSED,
+                                              gpointer  instance,
+                                              va_list   args,
+                                              gpointer  marshal_data,
+                                              int       n_params,
+                                              GType    *param_types)
+{
+  typedef void (*GMarshalFunc_VOID__BOXED_BOXED_BOXED) (gpointer data1,
+                                                        gpointer arg1,
+                                                        gpointer arg2,
+                                                        gpointer arg3,
+                                                        gpointer data2);
+  GCClosure *cc = (GCClosure *) closure;
+  gpointer data1, data2;
+  GMarshalFunc_VOID__BOXED_BOXED_BOXED callback;
+  gpointer arg0;
+  gpointer arg1;
+  gpointer arg2;
+  va_list args_copy;
+
+  G_VA_COPY (args_copy, args);
+  arg0 = (gpointer) va_arg (args_copy, gpointer);
+  if ((param_types[0] & G_SIGNAL_TYPE_STATIC_SCOPE) == 0 && arg0 != NULL)
+    arg0 = g_boxed_copy (param_types[0] & ~G_SIGNAL_TYPE_STATIC_SCOPE, arg0);
+  arg1 = (gpointer) va_arg (args_copy, gpointer);
+  if ((param_types[1] & G_SIGNAL_TYPE_STATIC_SCOPE) == 0 && arg1 != NULL)
+    arg1 = g_boxed_copy (param_types[1] & ~G_SIGNAL_TYPE_STATIC_SCOPE, arg1);
+  arg2 = (gpointer) va_arg (args_copy, gpointer);
+  if ((param_types[2] & G_SIGNAL_TYPE_STATIC_SCOPE) == 0 && arg2 != NULL)
+    arg2 = g_boxed_copy (param_types[2] & ~G_SIGNAL_TYPE_STATIC_SCOPE, arg2);
+  va_end (args_copy);
+
+
+  if (G_CCLOSURE_SWAP_DATA (closure))
+    {
+      data1 = closure->data;
+      data2 = instance;
+    }
+  else
+    {
+      data1 = instance;
+      data2 = closure->data;
+    }
+  callback = (GMarshalFunc_VOID__BOXED_BOXED_BOXED) (marshal_data ? marshal_data : cc->callback);
+
+  callback (data1,
+            arg0,
+            arg1,
+            arg2,
+            data2);
+  if ((param_types[0] & G_SIGNAL_TYPE_STATIC_SCOPE) == 0 && arg0 != NULL)
+    g_boxed_free (param_types[0] & ~G_SIGNAL_TYPE_STATIC_SCOPE, arg0);
+  if ((param_types[1] & G_SIGNAL_TYPE_STATIC_SCOPE) == 0 && arg1 != NULL)
+    g_boxed_free (param_types[1] & ~G_SIGNAL_TYPE_STATIC_SCOPE, arg1);
+  if ((param_types[2] & G_SIGNAL_TYPE_STATIC_SCOPE) == 0 && arg2 != NULL)
+    g_boxed_free (param_types[2] & ~G_SIGNAL_TYPE_STATIC_SCOPE, arg2);
+}
+
+void
+_gtk_source_marshal_VOID__BOXED_ENUM (GClosure     *closure,
+                                      GValue       *return_value G_GNUC_UNUSED,
+                                      guint         n_param_values,
+                                      const GValue *param_values,
+                                      gpointer      invocation_hint G_GNUC_UNUSED,
+                                      gpointer      marshal_data)
+{
+  typedef void (*GMarshalFunc_VOID__BOXED_ENUM) (gpointer data1,
+                                                 gpointer arg1,
+                                                 gint arg2,
+                                                 gpointer data2);
+  GCClosure *cc = (GCClosure *) closure;
+  gpointer data1, data2;
+  GMarshalFunc_VOID__BOXED_ENUM callback;
+
+  g_return_if_fail (n_param_values == 3);
+
+  if (G_CCLOSURE_SWAP_DATA (closure))
+    {
+      data1 = closure->data;
+      data2 = g_value_peek_pointer (param_values + 0);
+    }
+  else
+    {
+      data1 = g_value_peek_pointer (param_values + 0);
+      data2 = closure->data;
+    }
+  callback = (GMarshalFunc_VOID__BOXED_ENUM) (marshal_data ? marshal_data : cc->callback);
+
+  callback (data1,
+            g_marshal_value_peek_boxed (param_values + 1),
+            g_marshal_value_peek_enum (param_values + 2),
+            data2);
+}
+
+void
+_gtk_source_marshal_VOID__BOXED_ENUMv (GClosure *closure,
+                                       GValue   *return_value G_GNUC_UNUSED,
+                                       gpointer  instance,
+                                       va_list   args,
+                                       gpointer  marshal_data,
+                                       int       n_params,
+                                       GType    *param_types)
+{
+  typedef void (*GMarshalFunc_VOID__BOXED_ENUM) (gpointer data1,
+                                                 gpointer arg1,
+                                                 gint arg2,
+                                                 gpointer data2);
+  GCClosure *cc = (GCClosure *) closure;
+  gpointer data1, data2;
+  GMarshalFunc_VOID__BOXED_ENUM callback;
+  gpointer arg0;
+  gint arg1;
+  va_list args_copy;
+
+  G_VA_COPY (args_copy, args);
+  arg0 = (gpointer) va_arg (args_copy, gpointer);
+  if ((param_types[0] & G_SIGNAL_TYPE_STATIC_SCOPE) == 0 && arg0 != NULL)
+    arg0 = g_boxed_copy (param_types[0] & ~G_SIGNAL_TYPE_STATIC_SCOPE, arg0);
+  arg1 = (gint) va_arg (args_copy, gint);
+  va_end (args_copy);
+
+
+  if (G_CCLOSURE_SWAP_DATA (closure))
+    {
+      data1 = closure->data;
+      data2 = instance;
+    }
+  else
+    {
+      data1 = instance;
+      data2 = closure->data;
+    }
+  callback = (GMarshalFunc_VOID__BOXED_ENUM) (marshal_data ? marshal_data : cc->callback);
+
+  callback (data1,
+            arg0,
+            arg1,
+            data2);
+  if ((param_types[0] & G_SIGNAL_TYPE_STATIC_SCOPE) == 0 && arg0 != NULL)
+    g_boxed_free (param_types[0] & ~G_SIGNAL_TYPE_STATIC_SCOPE, arg0);
+}
+
+void
+_gtk_source_marshal_VOID__BOXED_INT (GClosure     *closure,
+                                     GValue       *return_value G_GNUC_UNUSED,
+                                     guint         n_param_values,
+                                     const GValue *param_values,
+                                     gpointer      invocation_hint G_GNUC_UNUSED,
+                                     gpointer      marshal_data)
+{
+  typedef void (*GMarshalFunc_VOID__BOXED_INT) (gpointer data1,
+                                                gpointer arg1,
+                                                gint arg2,
+                                                gpointer data2);
+  GCClosure *cc = (GCClosure *) closure;
+  gpointer data1, data2;
+  GMarshalFunc_VOID__BOXED_INT callback;
+
+  g_return_if_fail (n_param_values == 3);
+
+  if (G_CCLOSURE_SWAP_DATA (closure))
+    {
+      data1 = closure->data;
+      data2 = g_value_peek_pointer (param_values + 0);
+    }
+  else
+    {
+      data1 = g_value_peek_pointer (param_values + 0);
+      data2 = closure->data;
+    }
+  callback = (GMarshalFunc_VOID__BOXED_INT) (marshal_data ? marshal_data : cc->callback);
+
+  callback (data1,
+            g_marshal_value_peek_boxed (param_values + 1),
+            g_marshal_value_peek_int (param_values + 2),
+            data2);
+}
+
+void
+_gtk_source_marshal_VOID__BOXED_INTv (GClosure *closure,
+                                      GValue   *return_value G_GNUC_UNUSED,
+                                      gpointer  instance,
+                                      va_list   args,
+                                      gpointer  marshal_data,
+                                      int       n_params,
+                                      GType    *param_types)
+{
+  typedef void (*GMarshalFunc_VOID__BOXED_INT) (gpointer data1,
+                                                gpointer arg1,
+                                                gint arg2,
+                                                gpointer data2);
+  GCClosure *cc = (GCClosure *) closure;
+  gpointer data1, data2;
+  GMarshalFunc_VOID__BOXED_INT callback;
+  gpointer arg0;
+  gint arg1;
+  va_list args_copy;
+
+  G_VA_COPY (args_copy, args);
+  arg0 = (gpointer) va_arg (args_copy, gpointer);
+  if ((param_types[0] & G_SIGNAL_TYPE_STATIC_SCOPE) == 0 && arg0 != NULL)
+    arg0 = g_boxed_copy (param_types[0] & ~G_SIGNAL_TYPE_STATIC_SCOPE, arg0);
+  arg1 = (gint) va_arg (args_copy, gint);
+  va_end (args_copy);
+
+
+  if (G_CCLOSURE_SWAP_DATA (closure))
+    {
+      data1 = closure->data;
+      data2 = instance;
+    }
+  else
+    {
+      data1 = instance;
+      data2 = closure->data;
+    }
+  callback = (GMarshalFunc_VOID__BOXED_INT) (marshal_data ? marshal_data : cc->callback);
+
+  callback (data1,
+            arg0,
+            arg1,
+            data2);
+  if ((param_types[0] & G_SIGNAL_TYPE_STATIC_SCOPE) == 0 && arg0 != NULL)
+    g_boxed_free (param_types[0] & ~G_SIGNAL_TYPE_STATIC_SCOPE, arg0);
+}
+
+void
+_gtk_source_marshal_VOID__ENUM_INT (GClosure     *closure,
+                                    GValue       *return_value G_GNUC_UNUSED,
+                                    guint         n_param_values,
+                                    const GValue *param_values,
+                                    gpointer      invocation_hint G_GNUC_UNUSED,
+                                    gpointer      marshal_data)
+{
+  typedef void (*GMarshalFunc_VOID__ENUM_INT) (gpointer data1,
+                                               gint arg1,
+                                               gint arg2,
+                                               gpointer data2);
+  GCClosure *cc = (GCClosure *) closure;
+  gpointer data1, data2;
+  GMarshalFunc_VOID__ENUM_INT callback;
+
+  g_return_if_fail (n_param_values == 3);
+
+  if (G_CCLOSURE_SWAP_DATA (closure))
+    {
+      data1 = closure->data;
+      data2 = g_value_peek_pointer (param_values + 0);
+    }
+  else
+    {
+      data1 = g_value_peek_pointer (param_values + 0);
+      data2 = closure->data;
+    }
+  callback = (GMarshalFunc_VOID__ENUM_INT) (marshal_data ? marshal_data : cc->callback);
+
+  callback (data1,
+            g_marshal_value_peek_enum (param_values + 1),
+            g_marshal_value_peek_int (param_values + 2),
+            data2);
+}
+
+void
+_gtk_source_marshal_VOID__ENUM_INTv (GClosure *closure,
+                                     GValue   *return_value G_GNUC_UNUSED,
+                                     gpointer  instance,
+                                     va_list   args,
+                                     gpointer  marshal_data,
+                                     int       n_params,
+                                     GType    *param_types)
+{
+  typedef void (*GMarshalFunc_VOID__ENUM_INT) (gpointer data1,
+                                               gint arg1,
+                                               gint arg2,
+                                               gpointer data2);
+  GCClosure *cc = (GCClosure *) closure;
+  gpointer data1, data2;
+  GMarshalFunc_VOID__ENUM_INT callback;
+  gint arg0;
+  gint arg1;
+  va_list args_copy;
+
+  G_VA_COPY (args_copy, args);
+  arg0 = (gint) va_arg (args_copy, gint);
+  arg1 = (gint) va_arg (args_copy, gint);
+  va_end (args_copy);
+
+
+  if (G_CCLOSURE_SWAP_DATA (closure))
+    {
+      data1 = closure->data;
+      data2 = instance;
+    }
+  else
+    {
+      data1 = instance;
+      data2 = closure->data;
+    }
+  callback = (GMarshalFunc_VOID__ENUM_INT) (marshal_data ? marshal_data : cc->callback);
+
+  callback (data1,
+            arg0,
+            arg1,
+            data2);
+
+}
+
+void
+_gtk_source_marshal_VOID__BOXED_BOXED_FLAGS (GClosure     *closure,
+                                             GValue       *return_value G_GNUC_UNUSED,
+                                             guint         n_param_values,
+                                             const GValue *param_values,
+                                             gpointer      invocation_hint G_GNUC_UNUSED,
+                                             gpointer      marshal_data)
+{
+  typedef void (*GMarshalFunc_VOID__BOXED_BOXED_FLAGS) (gpointer data1,
+                                                        gpointer arg1,
+                                                        gpointer arg2,
+                                                        guint arg3,
+                                                        gpointer data2);
+  GCClosure *cc = (GCClosure *) closure;
+  gpointer data1, data2;
+  GMarshalFunc_VOID__BOXED_BOXED_FLAGS callback;
+
+  g_return_if_fail (n_param_values == 4);
+
+  if (G_CCLOSURE_SWAP_DATA (closure))
+    {
+      data1 = closure->data;
+      data2 = g_value_peek_pointer (param_values + 0);
+    }
+  else
+    {
+      data1 = g_value_peek_pointer (param_values + 0);
+      data2 = closure->data;
+    }
+  callback = (GMarshalFunc_VOID__BOXED_BOXED_FLAGS) (marshal_data ? marshal_data : cc->callback);
+
+  callback (data1,
+            g_marshal_value_peek_boxed (param_values + 1),
+            g_marshal_value_peek_boxed (param_values + 2),
+            g_marshal_value_peek_flags (param_values + 3),
+            data2);
+}
+
+void
+_gtk_source_marshal_VOID__BOXED_BOXED_FLAGSv (GClosure *closure,
+                                              GValue   *return_value G_GNUC_UNUSED,
+                                              gpointer  instance,
+                                              va_list   args,
+                                              gpointer  marshal_data,
+                                              int       n_params,
+                                              GType    *param_types)
+{
+  typedef void (*GMarshalFunc_VOID__BOXED_BOXED_FLAGS) (gpointer data1,
+                                                        gpointer arg1,
+                                                        gpointer arg2,
+                                                        guint arg3,
+                                                        gpointer data2);
+  GCClosure *cc = (GCClosure *) closure;
+  gpointer data1, data2;
+  GMarshalFunc_VOID__BOXED_BOXED_FLAGS callback;
+  gpointer arg0;
+  gpointer arg1;
+  guint arg2;
+  va_list args_copy;
+
+  G_VA_COPY (args_copy, args);
+  arg0 = (gpointer) va_arg (args_copy, gpointer);
+  if ((param_types[0] & G_SIGNAL_TYPE_STATIC_SCOPE) == 0 && arg0 != NULL)
+    arg0 = g_boxed_copy (param_types[0] & ~G_SIGNAL_TYPE_STATIC_SCOPE, arg0);
+  arg1 = (gpointer) va_arg (args_copy, gpointer);
+  if ((param_types[1] & G_SIGNAL_TYPE_STATIC_SCOPE) == 0 && arg1 != NULL)
+    arg1 = g_boxed_copy (param_types[1] & ~G_SIGNAL_TYPE_STATIC_SCOPE, arg1);
+  arg2 = (guint) va_arg (args_copy, guint);
+  va_end (args_copy);
+
+
+  if (G_CCLOSURE_SWAP_DATA (closure))
+    {
+      data1 = closure->data;
+      data2 = instance;
+    }
+  else
+    {
+      data1 = instance;
+      data2 = closure->data;
+    }
+  callback = (GMarshalFunc_VOID__BOXED_BOXED_FLAGS) (marshal_data ? marshal_data : cc->callback);
+
+  callback (data1,
+            arg0,
+            arg1,
+            arg2,
+            data2);
+  if ((param_types[0] & G_SIGNAL_TYPE_STATIC_SCOPE) == 0 && arg0 != NULL)
+    g_boxed_free (param_types[0] & ~G_SIGNAL_TYPE_STATIC_SCOPE, arg0);
+  if ((param_types[1] & G_SIGNAL_TYPE_STATIC_SCOPE) == 0 && arg1 != NULL)
+    g_boxed_free (param_types[1] & ~G_SIGNAL_TYPE_STATIC_SCOPE, arg1);
+}
+
+void
+_gtk_source_marshal_VOID__OBJECT_UINT (GClosure     *closure,
+                                       GValue       *return_value G_GNUC_UNUSED,
+                                       guint         n_param_values,
+                                       const GValue *param_values,
+                                       gpointer      invocation_hint G_GNUC_UNUSED,
+                                       gpointer      marshal_data)
+{
+  typedef void (*GMarshalFunc_VOID__OBJECT_UINT) (gpointer data1,
+                                                  gpointer arg1,
+                                                  guint arg2,
+                                                  gpointer data2);
+  GCClosure *cc = (GCClosure *) closure;
+  gpointer data1, data2;
+  GMarshalFunc_VOID__OBJECT_UINT callback;
+
+  g_return_if_fail (n_param_values == 3);
+
+  if (G_CCLOSURE_SWAP_DATA (closure))
+    {
+      data1 = closure->data;
+      data2 = g_value_peek_pointer (param_values + 0);
+    }
+  else
+    {
+      data1 = g_value_peek_pointer (param_values + 0);
+      data2 = closure->data;
+    }
+  callback = (GMarshalFunc_VOID__OBJECT_UINT) (marshal_data ? marshal_data : cc->callback);
+
+  callback (data1,
+            g_marshal_value_peek_object (param_values + 1),
+            g_marshal_value_peek_uint (param_values + 2),
+            data2);
+}
+
+void
+_gtk_source_marshal_VOID__OBJECT_UINTv (GClosure *closure,
+                                        GValue   *return_value G_GNUC_UNUSED,
+                                        gpointer  instance,
+                                        va_list   args,
+                                        gpointer  marshal_data,
+                                        int       n_params,
+                                        GType    *param_types)
+{
+  typedef void (*GMarshalFunc_VOID__OBJECT_UINT) (gpointer data1,
+                                                  gpointer arg1,
+                                                  guint arg2,
+                                                  gpointer data2);
+  GCClosure *cc = (GCClosure *) closure;
+  gpointer data1, data2;
+  GMarshalFunc_VOID__OBJECT_UINT callback;
+  gpointer arg0;
+  guint arg1;
+  va_list args_copy;
+
+  G_VA_COPY (args_copy, args);
+  arg0 = (gpointer) va_arg (args_copy, gpointer);
+  if (arg0 != NULL)
+    arg0 = g_object_ref (arg0);
+  arg1 = (guint) va_arg (args_copy, guint);
+  va_end (args_copy);
+
+
+  if (G_CCLOSURE_SWAP_DATA (closure))
+    {
+      data1 = closure->data;
+      data2 = instance;
+    }
+  else
+    {
+      data1 = instance;
+      data2 = closure->data;
+    }
+  callback = (GMarshalFunc_VOID__OBJECT_UINT) (marshal_data ? marshal_data : cc->callback);
+
+  callback (data1,
+            arg0,
+            arg1,
+            data2);
+  if (arg0 != NULL)
+    g_object_unref (arg0);
+}
+
+void
+_gtk_source_marshal_VOID__BOXED_BOXED_OBJECT (GClosure     *closure,
+                                              GValue       *return_value G_GNUC_UNUSED,
+                                              guint         n_param_values,
+                                              const GValue *param_values,
+                                              gpointer      invocation_hint G_GNUC_UNUSED,
+                                              gpointer      marshal_data)
+{
+  typedef void (*GMarshalFunc_VOID__BOXED_BOXED_OBJECT) (gpointer data1,
+                                                         gpointer arg1,
+                                                         gpointer arg2,
+                                                         gpointer arg3,
+                                                         gpointer data2);
+  GCClosure *cc = (GCClosure *) closure;
+  gpointer data1, data2;
+  GMarshalFunc_VOID__BOXED_BOXED_OBJECT callback;
+
+  g_return_if_fail (n_param_values == 4);
+
+  if (G_CCLOSURE_SWAP_DATA (closure))
+    {
+      data1 = closure->data;
+      data2 = g_value_peek_pointer (param_values + 0);
+    }
+  else
+    {
+      data1 = g_value_peek_pointer (param_values + 0);
+      data2 = closure->data;
+    }
+  callback = (GMarshalFunc_VOID__BOXED_BOXED_OBJECT) (marshal_data ? marshal_data : cc->callback);
+
+  callback (data1,
+            g_marshal_value_peek_boxed (param_values + 1),
+            g_marshal_value_peek_boxed (param_values + 2),
+            g_marshal_value_peek_object (param_values + 3),
+            data2);
+}
+
+void
+_gtk_source_marshal_VOID__BOXED_BOXED_OBJECTv (GClosure *closure,
+                                               GValue   *return_value G_GNUC_UNUSED,
+                                               gpointer  instance,
+                                               va_list   args,
+                                               gpointer  marshal_data,
+                                               int       n_params,
+                                               GType    *param_types)
+{
+  typedef void (*GMarshalFunc_VOID__BOXED_BOXED_OBJECT) (gpointer data1,
+                                                         gpointer arg1,
+                                                         gpointer arg2,
+                                                         gpointer arg3,
+                                                         gpointer data2);
+  GCClosure *cc = (GCClosure *) closure;
+  gpointer data1, data2;
+  GMarshalFunc_VOID__BOXED_BOXED_OBJECT callback;
+  gpointer arg0;
+  gpointer arg1;
+  gpointer arg2;
+  va_list args_copy;
+
+  G_VA_COPY (args_copy, args);
+  arg0 = (gpointer) va_arg (args_copy, gpointer);
+  if ((param_types[0] & G_SIGNAL_TYPE_STATIC_SCOPE) == 0 && arg0 != NULL)
+    arg0 = g_boxed_copy (param_types[0] & ~G_SIGNAL_TYPE_STATIC_SCOPE, arg0);
+  arg1 = (gpointer) va_arg (args_copy, gpointer);
+  if ((param_types[1] & G_SIGNAL_TYPE_STATIC_SCOPE) == 0 && arg1 != NULL)
+    arg1 = g_boxed_copy (param_types[1] & ~G_SIGNAL_TYPE_STATIC_SCOPE, arg1);
+  arg2 = (gpointer) va_arg (args_copy, gpointer);
+  if (arg2 != NULL)
+    arg2 = g_object_ref (arg2);
+  va_end (args_copy);
+
+
+  if (G_CCLOSURE_SWAP_DATA (closure))
+    {
+      data1 = closure->data;
+      data2 = instance;
+    }
+  else
+    {
+      data1 = instance;
+      data2 = closure->data;
+    }
+  callback = (GMarshalFunc_VOID__BOXED_BOXED_OBJECT) (marshal_data ? marshal_data : cc->callback);
+
+  callback (data1,
+            arg0,
+            arg1,
+            arg2,
+            data2);
+  if ((param_types[0] & G_SIGNAL_TYPE_STATIC_SCOPE) == 0 && arg0 != NULL)
+    g_boxed_free (param_types[0] & ~G_SIGNAL_TYPE_STATIC_SCOPE, arg0);
+  if ((param_types[1] & G_SIGNAL_TYPE_STATIC_SCOPE) == 0 && arg1 != NULL)
+    g_boxed_free (param_types[1] & ~G_SIGNAL_TYPE_STATIC_SCOPE, arg1);
+  if (arg2 != NULL)
+    g_object_unref (arg2);
+}
+
+void
+_gtk_source_marshal_BOOLEAN__BOXED_BOXED_OBJECT (GClosure     *closure,
+                                                 GValue       *return_value,
+                                                 guint         n_param_values,
+                                                 const GValue *param_values,
+                                                 gpointer      invocation_hint G_GNUC_UNUSED,
+                                                 gpointer      marshal_data)
+{
+  typedef gboolean (*GMarshalFunc_BOOLEAN__BOXED_BOXED_OBJECT) (gpointer data1,
+                                                                gpointer arg1,
+                                                                gpointer arg2,
+                                                                gpointer arg3,
+                                                                gpointer data2);
+  GCClosure *cc = (GCClosure *) closure;
+  gpointer data1, data2;
+  GMarshalFunc_BOOLEAN__BOXED_BOXED_OBJECT callback;
+  gboolean v_return;
+
+  g_return_if_fail (return_value != NULL);
+  g_return_if_fail (n_param_values == 4);
+
+  if (G_CCLOSURE_SWAP_DATA (closure))
+    {
+      data1 = closure->data;
+      data2 = g_value_peek_pointer (param_values + 0);
+    }
+  else
+    {
+      data1 = g_value_peek_pointer (param_values + 0);
+      data2 = closure->data;
+    }
+  callback = (GMarshalFunc_BOOLEAN__BOXED_BOXED_OBJECT) (marshal_data ? marshal_data : cc->callback);
+
+  v_return = callback (data1,
+                       g_marshal_value_peek_boxed (param_values + 1),
+                       g_marshal_value_peek_boxed (param_values + 2),
+                       g_marshal_value_peek_object (param_values + 3),
+                       data2);
+
+  g_value_set_boolean (return_value, v_return);
+}
+
+void
+_gtk_source_marshal_BOOLEAN__BOXED_BOXED_OBJECTv (GClosure *closure,
+                                                  GValue   *return_value,
+                                                  gpointer  instance,
+                                                  va_list   args,
+                                                  gpointer  marshal_data,
+                                                  int       n_params,
+                                                  GType    *param_types)
+{
+  typedef gboolean (*GMarshalFunc_BOOLEAN__BOXED_BOXED_OBJECT) (gpointer data1,
+                                                                gpointer arg1,
+                                                                gpointer arg2,
+                                                                gpointer arg3,
+                                                                gpointer data2);
+  GCClosure *cc = (GCClosure *) closure;
+  gpointer data1, data2;
+  GMarshalFunc_BOOLEAN__BOXED_BOXED_OBJECT callback;
+  gboolean v_return;
+  gpointer arg0;
+  gpointer arg1;
+  gpointer arg2;
+  va_list args_copy;
+
+  G_VA_COPY (args_copy, args);
+  arg0 = (gpointer) va_arg (args_copy, gpointer);
+  if ((param_types[0] & G_SIGNAL_TYPE_STATIC_SCOPE) == 0 && arg0 != NULL)
+    arg0 = g_boxed_copy (param_types[0] & ~G_SIGNAL_TYPE_STATIC_SCOPE, arg0);
+  arg1 = (gpointer) va_arg (args_copy, gpointer);
+  if ((param_types[1] & G_SIGNAL_TYPE_STATIC_SCOPE) == 0 && arg1 != NULL)
+    arg1 = g_boxed_copy (param_types[1] & ~G_SIGNAL_TYPE_STATIC_SCOPE, arg1);
+  arg2 = (gpointer) va_arg (args_copy, gpointer);
+  if (arg2 != NULL)
+    arg2 = g_object_ref (arg2);
+  va_end (args_copy);
+
+  g_return_if_fail (return_value != NULL);
+
+  if (G_CCLOSURE_SWAP_DATA (closure))
+    {
+      data1 = closure->data;
+      data2 = instance;
+    }
+  else
+    {
+      data1 = instance;
+      data2 = closure->data;
+    }
+  callback = (GMarshalFunc_BOOLEAN__BOXED_BOXED_OBJECT) (marshal_data ? marshal_data : cc->callback);
+
+  v_return = callback (data1,
+                       arg0,
+                       arg1,
+                       arg2,
+                       data2);
+  if ((param_types[0] & G_SIGNAL_TYPE_STATIC_SCOPE) == 0 && arg0 != NULL)
+    g_boxed_free (param_types[0] & ~G_SIGNAL_TYPE_STATIC_SCOPE, arg0);
+  if ((param_types[1] & G_SIGNAL_TYPE_STATIC_SCOPE) == 0 && arg1 != NULL)
+    g_boxed_free (param_types[1] & ~G_SIGNAL_TYPE_STATIC_SCOPE, arg1);
+  if (arg2 != NULL)
+    g_object_unref (arg2);
+
+  g_value_set_boolean (return_value, v_return);
+}
+
diff --git a/gtksourceview/gtksource-marshal.h b/gtksourceview/gtksource-marshal.h
new file mode 100644
index 00000000..2f2d3c1d
--- /dev/null
+++ b/gtksourceview/gtksource-marshal.h
@@ -0,0 +1,201 @@
+/* This file is generated by glib-genmarshal, do not modify it. This code is licensed under the same license 
as the containing project. Note that it links to GLib, so must comply with the LGPL linking clauses. */
+#pragma once
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+extern
+void _gtk_source_marshal_BOOLEAN__BOXED_BOXED_INT_INT_OBJECT (GClosure     *closure,
+                                                              GValue       *return_value,
+                                                              guint         n_param_values,
+                                                              const GValue *param_values,
+                                                              gpointer      invocation_hint,
+                                                              gpointer      marshal_data);
+extern
+void _gtk_source_marshal_BOOLEAN__BOXED_BOXED_INT_INT_OBJECTv (GClosure *closure,
+                                                               GValue   *return_value,
+                                                               gpointer  instance,
+                                                               va_list   args,
+                                                               gpointer  marshal_data,
+                                                               int       n_params,
+                                                               GType    *param_types);
+
+extern
+void _gtk_source_marshal_BOOLEAN__BOXED_BOXED_BOXED (GClosure     *closure,
+                                                     GValue       *return_value,
+                                                     guint         n_param_values,
+                                                     const GValue *param_values,
+                                                     gpointer      invocation_hint,
+                                                     gpointer      marshal_data);
+extern
+void _gtk_source_marshal_BOOLEAN__BOXED_BOXED_BOXEDv (GClosure *closure,
+                                                      GValue   *return_value,
+                                                      gpointer  instance,
+                                                      va_list   args,
+                                                      gpointer  marshal_data,
+                                                      int       n_params,
+                                                      GType    *param_types);
+
+extern
+void _gtk_source_marshal_STRING__OBJECT (GClosure     *closure,
+                                         GValue       *return_value,
+                                         guint         n_param_values,
+                                         const GValue *param_values,
+                                         gpointer      invocation_hint,
+                                         gpointer      marshal_data);
+extern
+void _gtk_source_marshal_STRING__OBJECTv (GClosure *closure,
+                                          GValue   *return_value,
+                                          gpointer  instance,
+                                          va_list   args,
+                                          gpointer  marshal_data,
+                                          int       n_params,
+                                          GType    *param_types);
+
+extern
+void _gtk_source_marshal_VOID__BOXED_BOXED (GClosure     *closure,
+                                            GValue       *return_value,
+                                            guint         n_param_values,
+                                            const GValue *param_values,
+                                            gpointer      invocation_hint,
+                                            gpointer      marshal_data);
+extern
+void _gtk_source_marshal_VOID__BOXED_BOXEDv (GClosure *closure,
+                                             GValue   *return_value,
+                                             gpointer  instance,
+                                             va_list   args,
+                                             gpointer  marshal_data,
+                                             int       n_params,
+                                             GType    *param_types);
+
+extern
+void _gtk_source_marshal_VOID__BOXED_BOXED_BOXED (GClosure     *closure,
+                                                  GValue       *return_value,
+                                                  guint         n_param_values,
+                                                  const GValue *param_values,
+                                                  gpointer      invocation_hint,
+                                                  gpointer      marshal_data);
+extern
+void _gtk_source_marshal_VOID__BOXED_BOXED_BOXEDv (GClosure *closure,
+                                                   GValue   *return_value,
+                                                   gpointer  instance,
+                                                   va_list   args,
+                                                   gpointer  marshal_data,
+                                                   int       n_params,
+                                                   GType    *param_types);
+
+extern
+void _gtk_source_marshal_VOID__BOXED_ENUM (GClosure     *closure,
+                                           GValue       *return_value,
+                                           guint         n_param_values,
+                                           const GValue *param_values,
+                                           gpointer      invocation_hint,
+                                           gpointer      marshal_data);
+extern
+void _gtk_source_marshal_VOID__BOXED_ENUMv (GClosure *closure,
+                                            GValue   *return_value,
+                                            gpointer  instance,
+                                            va_list   args,
+                                            gpointer  marshal_data,
+                                            int       n_params,
+                                            GType    *param_types);
+
+extern
+void _gtk_source_marshal_VOID__BOXED_INT (GClosure     *closure,
+                                          GValue       *return_value,
+                                          guint         n_param_values,
+                                          const GValue *param_values,
+                                          gpointer      invocation_hint,
+                                          gpointer      marshal_data);
+extern
+void _gtk_source_marshal_VOID__BOXED_INTv (GClosure *closure,
+                                           GValue   *return_value,
+                                           gpointer  instance,
+                                           va_list   args,
+                                           gpointer  marshal_data,
+                                           int       n_params,
+                                           GType    *param_types);
+
+extern
+void _gtk_source_marshal_VOID__ENUM_INT (GClosure     *closure,
+                                         GValue       *return_value,
+                                         guint         n_param_values,
+                                         const GValue *param_values,
+                                         gpointer      invocation_hint,
+                                         gpointer      marshal_data);
+extern
+void _gtk_source_marshal_VOID__ENUM_INTv (GClosure *closure,
+                                          GValue   *return_value,
+                                          gpointer  instance,
+                                          va_list   args,
+                                          gpointer  marshal_data,
+                                          int       n_params,
+                                          GType    *param_types);
+
+extern
+void _gtk_source_marshal_VOID__BOXED_BOXED_FLAGS (GClosure     *closure,
+                                                  GValue       *return_value,
+                                                  guint         n_param_values,
+                                                  const GValue *param_values,
+                                                  gpointer      invocation_hint,
+                                                  gpointer      marshal_data);
+extern
+void _gtk_source_marshal_VOID__BOXED_BOXED_FLAGSv (GClosure *closure,
+                                                   GValue   *return_value,
+                                                   gpointer  instance,
+                                                   va_list   args,
+                                                   gpointer  marshal_data,
+                                                   int       n_params,
+                                                   GType    *param_types);
+
+extern
+void _gtk_source_marshal_VOID__OBJECT_UINT (GClosure     *closure,
+                                            GValue       *return_value,
+                                            guint         n_param_values,
+                                            const GValue *param_values,
+                                            gpointer      invocation_hint,
+                                            gpointer      marshal_data);
+extern
+void _gtk_source_marshal_VOID__OBJECT_UINTv (GClosure *closure,
+                                             GValue   *return_value,
+                                             gpointer  instance,
+                                             va_list   args,
+                                             gpointer  marshal_data,
+                                             int       n_params,
+                                             GType    *param_types);
+
+extern
+void _gtk_source_marshal_VOID__BOXED_BOXED_OBJECT (GClosure     *closure,
+                                                   GValue       *return_value,
+                                                   guint         n_param_values,
+                                                   const GValue *param_values,
+                                                   gpointer      invocation_hint,
+                                                   gpointer      marshal_data);
+extern
+void _gtk_source_marshal_VOID__BOXED_BOXED_OBJECTv (GClosure *closure,
+                                                    GValue   *return_value,
+                                                    gpointer  instance,
+                                                    va_list   args,
+                                                    gpointer  marshal_data,
+                                                    int       n_params,
+                                                    GType    *param_types);
+
+extern
+void _gtk_source_marshal_BOOLEAN__BOXED_BOXED_OBJECT (GClosure     *closure,
+                                                      GValue       *return_value,
+                                                      guint         n_param_values,
+                                                      const GValue *param_values,
+                                                      gpointer      invocation_hint,
+                                                      gpointer      marshal_data);
+extern
+void _gtk_source_marshal_BOOLEAN__BOXED_BOXED_OBJECTv (GClosure *closure,
+                                                       GValue   *return_value,
+                                                       gpointer  instance,
+                                                       va_list   args,
+                                                       gpointer  marshal_data,
+                                                       int       n_params,
+                                                       GType    *param_types);
+
+
+G_END_DECLS
diff --git a/gtksourceview/gtksource.h b/gtksourceview/gtksource.h
index 2f84a3b4..2f795750 100644
--- a/gtksourceview/gtksource.h
+++ b/gtksourceview/gtksource.h
@@ -54,7 +54,6 @@
 #include "gtksourcestyleschemechooserwidget.h"
 #include "gtksourcestyleschememanager.h"
 #include "gtksourcetag.h"
-#include "gtksourceundomanager.h"
 #include "gtksourceutils.h"
 #include "gtksourceversion.h"
 #include "gtksourceview.h"
diff --git a/gtksourceview/gtksourceautocleanups.h b/gtksourceview/gtksourceautocleanups.h
new file mode 100644
index 00000000..e69de29b
diff --git a/gtksourceview/gtksourcebuffer-private.h b/gtksourceview/gtksourcebuffer-private.h
index 492c33c8..c4986e1a 100644
--- a/gtksourceview/gtksourcebuffer-private.h
+++ b/gtksourceview/gtksourcebuffer-private.h
@@ -2,7 +2,7 @@
 /*
  * This file is part of GtkSourceView
  *
- * Copyright 2013, 2016 - Sébastien Wilmet <swilmet gnome org>
+ * Copyright (C) 2013, 2016 - Sébastien Wilmet <swilmet gnome org>
  *
  * GtkSourceView is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -18,7 +18,8 @@
  * along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#pragma once
+#ifndef GTK_SOURCE_BUFFER_PRIVATE_H
+#define GTK_SOURCE_BUFFER_PRIVATE_H
 
 #include <gtk/gtk.h>
 
@@ -29,48 +30,61 @@
 G_BEGIN_DECLS
 
 GTK_SOURCE_INTERNAL
-void                      _gtk_source_buffer_update_syntax_highlight     (GtkSourceBuffer        *buffer,
-                                                                          const GtkTextIter      *start,
-                                                                          const GtkTextIter      *end,
-                                                                          gboolean                
synchronous);
-GTK_SOURCE_INTERNAL
-void                      _gtk_source_buffer_update_search_highlight     (GtkSourceBuffer        *buffer,
-                                                                          const GtkTextIter      *start,
-                                                                          const GtkTextIter      *end,
-                                                                          gboolean                
synchronous);
+void                    _gtk_source_buffer_update_syntax_highlight     (GtkSourceBuffer        *buffer,
+                                                                        const GtkTextIter      *start,
+                                                                        const GtkTextIter      *end,
+                                                                        gboolean                synchronous);
+
 GTK_SOURCE_INTERNAL
-GtkSourceMark            *_gtk_source_buffer_source_mark_next            (GtkSourceBuffer        *buffer,
-                                                                          GtkSourceMark          *mark,
-                                                                          const gchar            *category);
+void                    _gtk_source_buffer_update_search_highlight     (GtkSourceBuffer        *buffer,
+                                                                        const GtkTextIter      *start,
+                                                                        const GtkTextIter      *end,
+                                                                        gboolean                synchronous);
+
 GTK_SOURCE_INTERNAL
-GtkSourceMark            *_gtk_source_buffer_source_mark_prev            (GtkSourceBuffer        *buffer,
-                                                                          GtkSourceMark          *mark,
-                                                                          const gchar            *category);
+GtkSourceMark          *_gtk_source_buffer_source_mark_next            (GtkSourceBuffer        *buffer,
+                                                                        GtkSourceMark          *mark,
+                                                                        const gchar            *category);
+
 GTK_SOURCE_INTERNAL
-GtkTextTag               *_gtk_source_buffer_get_bracket_match_tag       (GtkSourceBuffer        *buffer);
+GtkSourceMark          *_gtk_source_buffer_source_mark_prev            (GtkSourceBuffer        *buffer,
+                                                                        GtkSourceMark          *mark,
+                                                                        const gchar            *category);
+
 GTK_SOURCE_INTERNAL
-void                      _gtk_source_buffer_add_search_context          (GtkSourceBuffer        *buffer,
-                                                                          GtkSourceSearchContext 
*search_context);
+GtkTextTag             *_gtk_source_buffer_get_bracket_match_tag       (GtkSourceBuffer        *buffer);
+
 GTK_SOURCE_INTERNAL
-void                      _gtk_source_buffer_set_as_invalid_character    (GtkSourceBuffer        *buffer,
-                                                                          const GtkTextIter      *start,
-                                                                          const GtkTextIter      *end);
+void                    _gtk_source_buffer_add_search_context          (GtkSourceBuffer        *buffer,
+                                                                        GtkSourceSearchContext 
*search_context);
+
 GTK_SOURCE_INTERNAL
-gboolean                  _gtk_source_buffer_has_invalid_chars           (GtkSourceBuffer        *buffer);
+void                    _gtk_source_buffer_set_as_invalid_character    (GtkSourceBuffer        *buffer,
+                                                                        const GtkTextIter      *start,
+                                                                        const GtkTextIter      *end);
+
 GTK_SOURCE_INTERNAL
-GtkSourceBracketMatchType _gtk_source_buffer_find_bracket_match          (GtkSourceBuffer        *buffer,
-                                                                          const GtkTextIter      *pos,
-                                                                          GtkTextIter            *bracket,
-                                                                          GtkTextIter            
*bracket_match);
+gboolean                _gtk_source_buffer_has_invalid_chars           (GtkSourceBuffer        *buffer);
+
 GTK_SOURCE_INTERNAL
-void                      _gtk_source_buffer_save_and_clear_selection    (GtkSourceBuffer        *buffer);
+GtkSourceBracketMatchType
+                        _gtk_source_buffer_find_bracket_match          (GtkSourceBuffer        *buffer,
+                                                                        const GtkTextIter      *pos,
+                                                                        GtkTextIter            *bracket,
+                                                                        GtkTextIter            
*bracket_match);
+
 GTK_SOURCE_INTERNAL
-void                      _gtk_source_buffer_restore_selection           (GtkSourceBuffer        *buffer);
+void                    _gtk_source_buffer_save_and_clear_selection    (GtkSourceBuffer        *buffer);
+
 GTK_SOURCE_INTERNAL
-gboolean                  _gtk_source_buffer_is_undo_redo_enabled        (GtkSourceBuffer        *buffer);
+void                    _gtk_source_buffer_restore_selection           (GtkSourceBuffer        *buffer);
+
 GTK_SOURCE_INTERNAL
-gboolean                  _gtk_source_buffer_has_source_marks            (GtkSourceBuffer        *buffer);
+gboolean               _gtk_source_buffer_has_source_marks             (GtkSourceBuffer        *buffer);
+
 GTK_SOURCE_INTERNAL
-gboolean                  _gtk_source_buffer_has_spaces_tag              (GtkSourceBuffer        *buffer);
+gboolean               _gtk_source_buffer_has_spaces_tag               (GtkSourceBuffer        *buffer);
 
 G_END_DECLS
+
+#endif /* GTK_SOURCE_BUFFER_PRIVATE_H */
diff --git a/gtksourceview/gtksourcebuffer.c b/gtksourceview/gtksourcebuffer.c
index cdec9a0d..b27ff3bf 100644
--- a/gtksourceview/gtksourcebuffer.c
+++ b/gtksourceview/gtksourcebuffer.c
@@ -2,11 +2,11 @@
 /*
  * This file is part of GtkSourceView
  *
- * Copyright 1999-2002 - Mikael Hermansson <tyan linux se>,
- *                       Chris Phelps <chicane reninet com> and
- *                       Jeroen Zwartepoorte <jeroen xs4all nl>
- * Copyright 2003 - Paolo Maggi <paolo maggi polito it> and
- *                  Gustavo Giráldez <gustavo giraldez gmx net>
+ * Copyright (C) 1999-2002 - Mikael Hermansson <tyan linux se>,
+ *                           Chris Phelps <chicane reninet com> and
+ *                           Jeroen Zwartepoorte <jeroen xs4all nl>
+ * Copyright (C) 2003 - Paolo Maggi <paolo maggi polito it> and
+ *                      Gustavo Giráldez <gustavo giraldez gmx net>
  *
  * GtkSourceView is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -22,7 +22,9 @@
  * along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "config.h"
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
 
 #include "gtksourcebuffer.h"
 #include "gtksourcebuffer-private.h"
@@ -34,13 +36,13 @@
 #include "gtksourcelanguage.h"
 #include "gtksourcelanguage-private.h"
 #include "gtksource-marshal.h"
-#include "gtksourceundomanager.h"
-#include "gtksourceundomanagerdefault.h"
 #include "gtksourcestyle.h"
+#include "gtksourcestylescheme.h"
 #include "gtksourcestylescheme-private.h"
 #include "gtksourcestyleschememanager.h"
 #include "gtksourcemark.h"
 #include "gtksourcemarkssequence-private.h"
+#include "gtksourcesearchcontext.h"
 #include "gtksourcesearchcontext-private.h"
 #include "gtksourcetag.h"
 #include "gtksource-enumtypes.h"
@@ -53,8 +55,7 @@
  *
  * A #GtkSourceBuffer object is the model for #GtkSourceView widgets.
  * It extends the #GtkTextBuffer class by adding features useful to display
- * and edit source code such as syntax highlighting and bracket matching. It
- * also implements support for the undo/redo.
+ * and edit source code such as syntax highlighting and bracket matching.
  *
  * To create a #GtkSourceBuffer use gtk_source_buffer_new() or
  * gtk_source_buffer_new_with_language(). The second form is just a convenience
@@ -65,34 +66,6 @@
  * The highlighting is enabled by default, but you can disable it with
  * gtk_source_buffer_set_highlight_syntax().
  *
- * # Undo/Redo
- *
- * A custom #GtkSourceUndoManager can be implemented and set with
- * gtk_source_buffer_set_undo_manager(). However the default implementation
- * should be suitable for most uses, so you can use the API provided by
- * #GtkSourceBuffer instead of using #GtkSourceUndoManager. By default, actions
- * that can be undone or redone are defined as groups of operations between a
- * call to gtk_text_buffer_begin_user_action() and
- * gtk_text_buffer_end_user_action(). In general, this happens whenever the user
- * presses any key which modifies the buffer. But the default undo manager will
- * try to merge similar consecutive actions into one undo/redo level. The
- * merging is done word by word, so after writing a new sentence (character by
- * character), each undo will remove the previous word.
- *
- * The default undo manager remembers the "modified" state of the buffer, and
- * restores it when an action is undone or redone. It can be useful in a text
- * editor to know whether the file is saved. See gtk_text_buffer_get_modified()
- * and gtk_text_buffer_set_modified().
- *
- * The default undo manager also restores the selected text (or cursor
- * position), if the selection was related to the action. For example if the
- * user selects some text and deletes it, an undo will restore the selection. On
- * the other hand, if some text is selected but a deletion occurs elsewhere (the
- * deletion was done programmatically), an undo will not restore the selection,
- * it will only moves the cursor (the cursor is moved so that the user sees the
- * undo's effect). Warning: the selection restoring behavior might change in the
- * future.
- *
  * # Context Classes # {#context-classes}
  *
  * It is possible to retrieve some information from the syntax highlighting
@@ -167,6 +140,7 @@
 
 enum
 {
+       CURSOR_MOVED,
        HIGHLIGHT_UPDATED,
        SOURCE_MARK_UPDATED,
        UNDO,
@@ -178,19 +152,15 @@ enum
 enum
 {
        PROP_0,
-       PROP_CAN_UNDO,
-       PROP_CAN_REDO,
-       PROP_HIGHLIGHT_SYNTAX,
        PROP_HIGHLIGHT_MATCHING_BRACKETS,
-       PROP_MAX_UNDO_LEVELS,
+       PROP_HIGHLIGHT_SYNTAX,
+       PROP_IMPLICIT_TRAILING_NEWLINE,
        PROP_LANGUAGE,
        PROP_STYLE_SCHEME,
-       PROP_UNDO_MANAGER,
-       PROP_IMPLICIT_TRAILING_NEWLINE,
        N_PROPERTIES
 };
 
-typedef struct
+struct _GtkSourceBufferPrivate
 {
        GtkTextTag *bracket_match_tag;
        GtkSourceBracketMatchType bracket_match_state;
@@ -204,9 +174,6 @@ typedef struct
        GtkSourceLanguage *language;
        GtkSourceEngine *highlight_engine;
 
-       GtkSourceUndoManager *undo_manager;
-       gint max_undo_levels;
-
        GtkTextMark *tmp_insert_mark;
        GtkTextMark *tmp_selection_bound_mark;
 
@@ -218,7 +185,7 @@ typedef struct
        guint highlight_syntax : 1;
        guint highlight_brackets : 1;
        guint implicit_trailing_newline : 1;
-} GtkSourceBufferPrivate;
+};
 
 static guint buffer_signals[N_SIGNALS];
 static GParamSpec *buffer_properties[N_PROPERTIES];
@@ -235,17 +202,13 @@ static void      gtk_source_buffer_get_property         (GObject
                                                         guint                    prop_id,
                                                         GValue                  *value,
                                                         GParamSpec              *pspec);
-static void     gtk_source_buffer_can_undo_handler     (GtkSourceUndoManager    *manager,
-                                                        GtkSourceBuffer         *buffer);
-static void     gtk_source_buffer_can_redo_handler     (GtkSourceUndoManager    *manager,
-                                                        GtkSourceBuffer         *buffer);
 static void     gtk_source_buffer_real_insert_text     (GtkTextBuffer           *buffer,
                                                         GtkTextIter             *iter,
                                                         const gchar             *text,
                                                         gint                     len);
-static void     gtk_source_buffer_real_insert_pixbuf   (GtkTextBuffer           *buffer,
+static void     gtk_source_buffer_real_insert_texture  (GtkTextBuffer           *buffer,
                                                         GtkTextIter             *pos,
-                                                        GdkPixbuf               *pixbuf);
+                                                        GdkTexture              *texture);
 static void     gtk_source_buffer_real_insert_child_anchor
                                                        (GtkTextBuffer           *buffer,
                                                         GtkTextIter             *pos,
@@ -260,9 +223,6 @@ static void          gtk_source_buffer_real_mark_set        (GtkTextBuffer           
*buffer,
 static void     gtk_source_buffer_real_mark_deleted    (GtkTextBuffer           *buffer,
                                                         GtkTextMark             *mark);
 
-static void     gtk_source_buffer_real_undo            (GtkSourceBuffer         *buffer);
-static void     gtk_source_buffer_real_redo            (GtkSourceBuffer         *buffer);
-
 static void     gtk_source_buffer_real_highlight_updated
                                                        (GtkSourceBuffer         *buffer,
                                                         GtkTextIter             *start,
@@ -272,9 +232,7 @@ static void
 gtk_source_buffer_check_tag_for_spaces (GtkSourceBuffer *buffer,
                                         GtkSourceTag    *tag)
 {
-       GtkSourceBufferPrivate *priv = gtk_source_buffer_get_instance_private (buffer);
-
-       if (!priv->has_draw_spaces_tag)
+       if (!buffer->priv->has_draw_spaces_tag)
        {
                gboolean draw_spaces_set;
 
@@ -284,7 +242,7 @@ gtk_source_buffer_check_tag_for_spaces (GtkSourceBuffer *buffer,
 
                if (draw_spaces_set)
                {
-                       priv->has_draw_spaces_tag = TRUE;
+                       buffer->priv->has_draw_spaces_tag = TRUE;
                }
        }
 }
@@ -316,15 +274,8 @@ static void
 gtk_source_buffer_constructed (GObject *object)
 {
        GtkSourceBuffer *buffer = GTK_SOURCE_BUFFER (object);
-       GtkSourceBufferPrivate *priv = gtk_source_buffer_get_instance_private (buffer);
        GtkTextTagTable *table;
 
-       if (priv->undo_manager == NULL)
-       {
-               /* This will install the default undo manager */
-               gtk_source_buffer_set_undo_manager (buffer, NULL);
-       }
-
        G_OBJECT_CLASS (gtk_source_buffer_parent_class)->constructed (object);
 
        table = gtk_text_buffer_get_tag_table (GTK_TEXT_BUFFER (buffer));
@@ -354,14 +305,11 @@ gtk_source_buffer_class_init (GtkSourceBufferClass *klass)
 
        text_buffer_class->delete_range = gtk_source_buffer_real_delete_range;
        text_buffer_class->insert_text = gtk_source_buffer_real_insert_text;
-       text_buffer_class->insert_pixbuf = gtk_source_buffer_real_insert_pixbuf;
+       text_buffer_class->insert_texture = gtk_source_buffer_real_insert_texture;
        text_buffer_class->insert_child_anchor = gtk_source_buffer_real_insert_child_anchor;
        text_buffer_class->mark_set = gtk_source_buffer_real_mark_set;
        text_buffer_class->mark_deleted = gtk_source_buffer_real_mark_deleted;
 
-       klass->undo = gtk_source_buffer_real_undo;
-       klass->redo = gtk_source_buffer_real_redo;
-
        /**
         * GtkSourceBuffer:highlight-syntax:
         *
@@ -388,22 +336,6 @@ gtk_source_buffer_class_init (GtkSourceBufferClass *klass)
                                      G_PARAM_READWRITE |
                                      G_PARAM_STATIC_STRINGS);
 
-       /**
-        * GtkSourceBuffer:max-undo-levels:
-        *
-        * Number of undo levels for the buffer. -1 means no limit. This property
-        * will only affect the default undo manager.
-        */
-       buffer_properties[PROP_MAX_UNDO_LEVELS] =
-               g_param_spec_int ("max-undo-levels",
-                                 "Maximum Undo Levels",
-                                 "Number of undo levels for the buffer",
-                                 -1,
-                                 G_MAXINT,
-                                 -1,
-                                 G_PARAM_READWRITE |
-                                 G_PARAM_STATIC_STRINGS);
-
        buffer_properties[PROP_LANGUAGE] =
                g_param_spec_object ("language",
                                     "Language",
@@ -412,22 +344,6 @@ gtk_source_buffer_class_init (GtkSourceBufferClass *klass)
                                     G_PARAM_READWRITE |
                                     G_PARAM_STATIC_STRINGS);
 
-       buffer_properties[PROP_CAN_UNDO] =
-               g_param_spec_boolean ("can-undo",
-                                     "Can undo",
-                                     "Whether Undo operation is possible",
-                                     FALSE,
-                                     G_PARAM_READABLE |
-                                     G_PARAM_STATIC_STRINGS);
-
-       buffer_properties[PROP_CAN_REDO] =
-               g_param_spec_boolean ("can-redo",
-                                     "Can redo",
-                                     "Whether Redo operation is possible",
-                                     FALSE,
-                                     G_PARAM_READABLE |
-                                     G_PARAM_STATIC_STRINGS);
-
        /**
         * GtkSourceBuffer:style-scheme:
         *
@@ -443,15 +359,6 @@ gtk_source_buffer_class_init (GtkSourceBufferClass *klass)
                                     G_PARAM_READWRITE |
                                     G_PARAM_STATIC_STRINGS);
 
-       buffer_properties[PROP_UNDO_MANAGER] =
-               g_param_spec_object ("undo-manager",
-                                    "Undo manager",
-                                    "The buffer undo manager",
-                                    GTK_SOURCE_TYPE_UNDO_MANAGER,
-                                    G_PARAM_READWRITE |
-                                    G_PARAM_CONSTRUCT |
-                                    G_PARAM_STATIC_STRINGS);
-
        /**
         * GtkSourceBuffer:implicit-trailing-newline:
         *
@@ -471,6 +378,21 @@ gtk_source_buffer_class_init (GtkSourceBufferClass *klass)
 
        g_object_class_install_properties (object_class, N_PROPERTIES, buffer_properties);
 
+       /**
+        * GtkSourceBuffer::cursor-moved:
+        * @buffer: a #GtkSourceBuffer
+        *
+        * The "cursor-moved" signal is emitted when then insertion mark has moved.
+        *
+        * Since: 5.0
+        */
+       buffer_signals[CURSOR_MOVED] =
+               g_signal_new_class_handler ("cursor-moved",
+                                           G_OBJECT_CLASS_TYPE (object_class),
+                                           G_SIGNAL_RUN_LAST,
+                                           NULL, NULL, NULL, NULL,
+                                           G_TYPE_NONE, 0);
+
        /**
         * GtkSourceBuffer::highlight-updated:
         * @buffer: the buffer that received the signal
@@ -517,43 +439,6 @@ gtk_source_buffer_class_init (GtkSourceBufferClass *klass)
                                    G_TYPE_FROM_CLASS (klass),
                                    g_cclosure_marshal_VOID__OBJECTv);
 
-       /**
-        * GtkSourceBuffer::undo:
-        * @buffer: the buffer that received the signal
-        *
-        * The ::undo signal is emitted to undo the last user action which
-        * modified the buffer.
-        */
-       buffer_signals[UNDO] =
-           g_signal_new ("undo",
-                         G_OBJECT_CLASS_TYPE (object_class),
-                         G_SIGNAL_RUN_LAST,
-                         G_STRUCT_OFFSET (GtkSourceBufferClass, undo),
-                         NULL, NULL,
-                         g_cclosure_marshal_VOID__VOID,
-                         G_TYPE_NONE, 0);
-       g_signal_set_va_marshaller (buffer_signals[UNDO],
-                                   G_TYPE_FROM_CLASS (klass),
-                                   g_cclosure_marshal_VOID__VOIDv);
-
-       /**
-        * GtkSourceBuffer::redo:
-        * @buffer: the buffer that received the signal
-        *
-        * The ::redo signal is emitted to redo the last undo operation.
-        */
-       buffer_signals[REDO] =
-           g_signal_new ("redo",
-                         G_OBJECT_CLASS_TYPE (object_class),
-                         G_SIGNAL_RUN_LAST,
-                         G_STRUCT_OFFSET (GtkSourceBufferClass, redo),
-                         NULL, NULL,
-                         g_cclosure_marshal_VOID__VOID,
-                         G_TYPE_NONE, 0);
-       g_signal_set_va_marshaller (buffer_signals[REDO],
-                                   G_TYPE_FROM_CLASS (klass),
-                                   g_cclosure_marshal_VOID__VOIDv);
-
        /**
         * GtkSourceBuffer::bracket-matched:
         * @buffer: a #GtkSourceBuffer.
@@ -586,58 +471,12 @@ gtk_source_buffer_class_init (GtkSourceBufferClass *klass)
                                    _gtk_source_marshal_VOID__BOXED_ENUMv);
 }
 
-static void
-set_undo_manager (GtkSourceBuffer      *buffer,
-                  GtkSourceUndoManager *manager)
-{
-       GtkSourceBufferPrivate *priv = gtk_source_buffer_get_instance_private (buffer);
-
-       if (manager == priv->undo_manager)
-       {
-               return;
-       }
-
-       if (priv->undo_manager != NULL)
-       {
-               g_signal_handlers_disconnect_by_func (priv->undo_manager,
-                                                     G_CALLBACK (gtk_source_buffer_can_undo_handler),
-                                                     buffer);
-
-               g_signal_handlers_disconnect_by_func (priv->undo_manager,
-                                                     G_CALLBACK (gtk_source_buffer_can_redo_handler),
-                                                     buffer);
-
-               g_object_unref (priv->undo_manager);
-               priv->undo_manager = NULL;
-       }
-
-       if (manager != NULL)
-       {
-               priv->undo_manager = g_object_ref (manager);
-
-               g_signal_connect (priv->undo_manager,
-                                 "can-undo-changed",
-                                 G_CALLBACK (gtk_source_buffer_can_undo_handler),
-                                 buffer);
-
-               g_signal_connect (priv->undo_manager,
-                                 "can-redo-changed",
-                                 G_CALLBACK (gtk_source_buffer_can_redo_handler),
-                                 buffer);
-
-               /* Notify possible changes in the can-undo/redo state */
-               g_object_notify_by_pspec (G_OBJECT (buffer), buffer_properties[PROP_CAN_UNDO]);
-               g_object_notify_by_pspec (G_OBJECT (buffer), buffer_properties[PROP_CAN_REDO]);
-       }
-}
-
 static void
 search_context_weak_notify_cb (GtkSourceBuffer *buffer,
                               GObject         *search_context)
 {
-       GtkSourceBufferPrivate *priv = gtk_source_buffer_get_instance_private (buffer);
-
-       priv->search_contexts = g_list_remove (priv->search_contexts, search_context);
+       buffer->priv->search_contexts = g_list_remove (buffer->priv->search_contexts,
+                                                      search_context);
 }
 
 static void
@@ -645,10 +484,11 @@ gtk_source_buffer_init (GtkSourceBuffer *buffer)
 {
        GtkSourceBufferPrivate *priv = gtk_source_buffer_get_instance_private (buffer);
 
+       buffer->priv = priv;
+
        priv->highlight_syntax = TRUE;
        priv->highlight_brackets = TRUE;
        priv->bracket_match_state = GTK_SOURCE_BRACKET_MATCH_NONE;
-       priv->max_undo_levels = -1;
 
        priv->source_marks = g_hash_table_new_full (g_str_hash,
                                                    g_str_equal,
@@ -669,30 +509,24 @@ static void
 gtk_source_buffer_dispose (GObject *object)
 {
        GtkSourceBuffer *buffer = GTK_SOURCE_BUFFER (object);
-       GtkSourceBufferPrivate *priv = gtk_source_buffer_get_instance_private (buffer);
        GList *l;
 
-       if (priv->bracket_highlighting_timeout_id != 0)
+       if (buffer->priv->bracket_highlighting_timeout_id != 0)
        {
-               g_source_remove (priv->bracket_highlighting_timeout_id);
-               priv->bracket_highlighting_timeout_id = 0;
+               g_source_remove (buffer->priv->bracket_highlighting_timeout_id);
+               buffer->priv->bracket_highlighting_timeout_id = 0;
        }
 
-       if (priv->undo_manager != NULL)
+       if (buffer->priv->highlight_engine != NULL)
        {
-               set_undo_manager (buffer, NULL);
+               _gtk_source_engine_attach_buffer (buffer->priv->highlight_engine, NULL);
        }
 
-       if (priv->highlight_engine != NULL)
-       {
-               _gtk_source_engine_attach_buffer (priv->highlight_engine, NULL);
-       }
-
-       g_clear_object (&priv->highlight_engine);
-       g_clear_object (&priv->language);
-       g_clear_object (&priv->style_scheme);
+       g_clear_object (&buffer->priv->highlight_engine);
+       g_clear_object (&buffer->priv->language);
+       g_clear_object (&buffer->priv->style_scheme);
 
-       for (l = priv->search_contexts; l != NULL; l = l->next)
+       for (l = buffer->priv->search_contexts; l != NULL; l = l->next)
        {
                GtkSourceSearchContext *search_context = l->data;
 
@@ -701,15 +535,15 @@ gtk_source_buffer_dispose (GObject *object)
                                     buffer);
        }
 
-       g_list_free (priv->search_contexts);
-       priv->search_contexts = NULL;
+       g_list_free (buffer->priv->search_contexts);
+       buffer->priv->search_contexts = NULL;
 
-       g_clear_object (&priv->all_source_marks);
+       g_clear_object (&buffer->priv->all_source_marks);
 
-       if (priv->source_marks != NULL)
+       if (buffer->priv->source_marks != NULL)
        {
-               g_hash_table_unref (priv->source_marks);
-               priv->source_marks = NULL;
+               g_hash_table_unref (buffer->priv->source_marks);
+               buffer->priv->source_marks = NULL;
        }
 
        G_OBJECT_CLASS (gtk_source_buffer_parent_class)->dispose (object);
@@ -721,7 +555,11 @@ gtk_source_buffer_set_property (GObject      *object,
                                const GValue *value,
                                GParamSpec   *pspec)
 {
-       GtkSourceBuffer *buffer = GTK_SOURCE_BUFFER (object);
+       GtkSourceBuffer *buffer;
+
+       g_return_if_fail (GTK_SOURCE_IS_BUFFER (object));
+
+       buffer = GTK_SOURCE_BUFFER (object);
 
        switch (prop_id)
        {
@@ -733,10 +571,6 @@ gtk_source_buffer_set_property (GObject      *object,
                        gtk_source_buffer_set_highlight_matching_brackets (buffer, g_value_get_boolean 
(value));
                        break;
 
-               case PROP_MAX_UNDO_LEVELS:
-                       gtk_source_buffer_set_max_undo_levels (buffer, g_value_get_int (value));
-                       break;
-
                case PROP_LANGUAGE:
                        gtk_source_buffer_set_language (buffer, g_value_get_object (value));
                        break;
@@ -745,10 +579,6 @@ gtk_source_buffer_set_property (GObject      *object,
                        gtk_source_buffer_set_style_scheme (buffer, g_value_get_object (value));
                        break;
 
-               case PROP_UNDO_MANAGER:
-                       gtk_source_buffer_set_undo_manager (buffer, g_value_get_object (value));
-                       break;
-
                case PROP_IMPLICIT_TRAILING_NEWLINE:
                        gtk_source_buffer_set_implicit_trailing_newline (buffer, g_value_get_boolean (value));
                        break;
@@ -765,45 +595,32 @@ gtk_source_buffer_get_property (GObject    *object,
                                GValue     *value,
                                GParamSpec *pspec)
 {
-       GtkSourceBuffer *buffer = GTK_SOURCE_BUFFER (object);
-       GtkSourceBufferPrivate *priv = gtk_source_buffer_get_instance_private (buffer);
+       GtkSourceBuffer *buffer;
+
+       g_return_if_fail (GTK_SOURCE_IS_BUFFER (object));
+
+       buffer = GTK_SOURCE_BUFFER (object);
 
        switch (prop_id)
        {
                case PROP_HIGHLIGHT_SYNTAX:
-                       g_value_set_boolean (value, priv->highlight_syntax);
+                       g_value_set_boolean (value, buffer->priv->highlight_syntax);
                        break;
 
                case PROP_HIGHLIGHT_MATCHING_BRACKETS:
-                       g_value_set_boolean (value, priv->highlight_brackets);
-                       break;
-
-               case PROP_MAX_UNDO_LEVELS:
-                       g_value_set_int (value, priv->max_undo_levels);
+                       g_value_set_boolean (value, buffer->priv->highlight_brackets);
                        break;
 
                case PROP_LANGUAGE:
-                       g_value_set_object (value, priv->language);
+                       g_value_set_object (value, buffer->priv->language);
                        break;
 
                case PROP_STYLE_SCHEME:
-                       g_value_set_object (value, priv->style_scheme);
-                       break;
-
-               case PROP_CAN_UNDO:
-                       g_value_set_boolean (value, gtk_source_buffer_can_undo (buffer));
-                       break;
-
-               case PROP_CAN_REDO:
-                       g_value_set_boolean (value, gtk_source_buffer_can_redo (buffer));
-                       break;
-
-               case PROP_UNDO_MANAGER:
-                       g_value_set_object (value, priv->undo_manager);
+                       g_value_set_object (value, buffer->priv->style_scheme);
                        break;
 
                case PROP_IMPLICIT_TRAILING_NEWLINE:
-                       g_value_set_boolean (value, priv->implicit_trailing_newline);
+                       g_value_set_boolean (value, buffer->priv->implicit_trailing_newline);
                        break;
 
                default:
@@ -823,8 +640,6 @@ gtk_source_buffer_get_property (GObject    *object,
 GtkSourceBuffer *
 gtk_source_buffer_new (GtkTextTagTable *table)
 {
-       g_return_val_if_fail (table == NULL || GTK_IS_TEXT_TAG_TABLE (table), NULL);
-
        return g_object_new (GTK_SOURCE_TYPE_BUFFER,
                             "tag-table", table,
                             NULL);
@@ -852,58 +667,37 @@ gtk_source_buffer_new_with_language (GtkSourceLanguage *language)
                             NULL);
 }
 
-static void
-gtk_source_buffer_can_undo_handler (GtkSourceUndoManager *manager,
-                                    GtkSourceBuffer      *buffer)
-{
-       g_return_if_fail (GTK_SOURCE_IS_BUFFER (buffer));
-
-       g_object_notify_by_pspec (G_OBJECT (buffer), buffer_properties[PROP_CAN_UNDO]);
-}
-
-static void
-gtk_source_buffer_can_redo_handler (GtkSourceUndoManager *manager,
-                                    GtkSourceBuffer      *buffer)
-{
-       g_return_if_fail (GTK_SOURCE_IS_BUFFER (buffer));
-
-       g_object_notify_by_pspec (G_OBJECT (buffer), buffer_properties[PROP_CAN_REDO]);
-}
-
 static void
 update_bracket_match_style (GtkSourceBuffer *buffer)
 {
-       GtkSourceBufferPrivate *priv = gtk_source_buffer_get_instance_private (buffer);
        GtkSourceStyle *style = NULL;
 
-       if (priv->bracket_match_tag == NULL)
+       if (buffer->priv->bracket_match_tag == NULL)
        {
                return;
        }
 
-       if (priv->style_scheme != NULL)
+       if (buffer->priv->style_scheme != NULL)
        {
-               style = _gtk_source_style_scheme_get_matching_brackets_style (priv->style_scheme);
+               style = _gtk_source_style_scheme_get_matching_brackets_style (buffer->priv->style_scheme);
        }
 
-       gtk_source_style_apply (style, priv->bracket_match_tag);
+       gtk_source_style_apply (style, buffer->priv->bracket_match_tag);
 }
 
 static GtkTextTag *
 get_bracket_match_tag (GtkSourceBuffer *buffer)
 {
-       GtkSourceBufferPrivate *priv = gtk_source_buffer_get_instance_private (buffer);
-
-       if (priv->bracket_match_tag == NULL)
+       if (buffer->priv->bracket_match_tag == NULL)
        {
-               priv->bracket_match_tag =
+               buffer->priv->bracket_match_tag =
                        gtk_text_buffer_create_tag (GTK_TEXT_BUFFER (buffer),
                                                    NULL,
                                                    NULL);
                update_bracket_match_style (buffer);
        }
 
-       return priv->bracket_match_tag;
+       return buffer->priv->bracket_match_tag;
 }
 
 /* This is private, just used by the print compositor to not print bracket
@@ -913,9 +707,7 @@ get_bracket_match_tag (GtkSourceBuffer *buffer)
 GtkTextTag *
 _gtk_source_buffer_get_bracket_match_tag (GtkSourceBuffer *buffer)
 {
-       GtkSourceBufferPrivate *priv = gtk_source_buffer_get_instance_private (buffer);
-
-       return priv->bracket_match_tag;
+       return buffer->priv->bracket_match_tag;
 }
 
 static gunichar
@@ -1062,14 +854,15 @@ remove_tag_with_minimal_damage (GtkTextBuffer     *buffer,
 static void
 update_bracket_highlighting (GtkSourceBuffer *source_buffer)
 {
-       GtkTextBuffer *buffer = GTK_TEXT_BUFFER (source_buffer);
-       GtkSourceBufferPrivate *priv = gtk_source_buffer_get_instance_private (source_buffer);
+       GtkTextBuffer *buffer;
        GtkTextIter insert_iter;
        GtkTextIter bracket;
        GtkTextIter bracket_match;
        GtkSourceBracketMatchType previous_state;
 
-       if (priv->bracket_match_tag != NULL)
+       buffer = GTK_TEXT_BUFFER (source_buffer);
+
+       if (source_buffer->priv->bracket_match_tag != NULL)
        {
                GtkTextIter start;
                GtkTextIter end;
@@ -1077,20 +870,20 @@ update_bracket_highlighting (GtkSourceBuffer *source_buffer)
                gtk_text_buffer_get_bounds (buffer, &start, &end);
 
                remove_tag_with_minimal_damage (GTK_TEXT_BUFFER (source_buffer),
-                                               priv->bracket_match_tag,
+                                               source_buffer->priv->bracket_match_tag,
                                                &start,
                                                &end);
        }
 
-       if (!priv->highlight_brackets)
+       if (!source_buffer->priv->highlight_brackets)
        {
-               if (priv->bracket_match_tag != NULL)
+               if (source_buffer->priv->bracket_match_tag != NULL)
                {
                        GtkTextTagTable *table;
 
                        table = gtk_text_buffer_get_tag_table (buffer);
-                       gtk_text_tag_table_remove (table, priv->bracket_match_tag);
-                       priv->bracket_match_tag = NULL;
+                       gtk_text_tag_table_remove (table, source_buffer->priv->bracket_match_tag);
+                       source_buffer->priv->bracket_match_tag = NULL;
                }
 
                return;
@@ -1100,14 +893,14 @@ update_bracket_highlighting (GtkSourceBuffer *source_buffer)
                                          &insert_iter,
                                          gtk_text_buffer_get_insert (buffer));
 
-       previous_state = priv->bracket_match_state;
-       priv->bracket_match_state =
+       previous_state = source_buffer->priv->bracket_match_state;
+       source_buffer->priv->bracket_match_state =
                _gtk_source_buffer_find_bracket_match (source_buffer,
                                                       &insert_iter,
                                                       &bracket,
                                                       &bracket_match);
 
-       if (priv->bracket_match_state == GTK_SOURCE_BRACKET_MATCH_FOUND)
+       if (source_buffer->priv->bracket_match_state == GTK_SOURCE_BRACKET_MATCH_FOUND)
        {
                GtkTextIter next_iter;
 
@@ -1137,13 +930,13 @@ update_bracket_highlighting (GtkSourceBuffer *source_buffer)
         * positions are nonbrackets.
         */
        if (previous_state != GTK_SOURCE_BRACKET_MATCH_NONE ||
-           priv->bracket_match_state != GTK_SOURCE_BRACKET_MATCH_NONE)
+           source_buffer->priv->bracket_match_state != GTK_SOURCE_BRACKET_MATCH_NONE)
        {
                g_signal_emit (source_buffer,
                               buffer_signals[BRACKET_MATCHED],
                               0,
                               NULL,
-                              priv->bracket_match_state);
+                              source_buffer->priv->bracket_match_state);
        }
 }
 
@@ -1151,22 +944,19 @@ static gboolean
 bracket_highlighting_timeout_cb (gpointer user_data)
 {
        GtkSourceBuffer *buffer = GTK_SOURCE_BUFFER (user_data);
-       GtkSourceBufferPrivate *priv = gtk_source_buffer_get_instance_private (buffer);
 
        update_bracket_highlighting (buffer);
 
-       priv->bracket_highlighting_timeout_id = 0;
+       buffer->priv->bracket_highlighting_timeout_id = 0;
        return G_SOURCE_REMOVE;
 }
 
 static void
 queue_bracket_highlighting_update (GtkSourceBuffer *buffer)
 {
-       GtkSourceBufferPrivate *priv = gtk_source_buffer_get_instance_private (buffer);
-
-       if (priv->bracket_highlighting_timeout_id != 0)
+       if (buffer->priv->bracket_highlighting_timeout_id != 0)
        {
-               g_source_remove (priv->bracket_highlighting_timeout_id);
+               g_source_remove (buffer->priv->bracket_highlighting_timeout_id);
        }
 
        /* Queue an update to the bracket location instead of doing it
@@ -1186,12 +976,12 @@ queue_bracket_highlighting_update (GtkSourceBuffer *buffer)
         * If we had access to a GdkFrameClock, we might consider using
         * ::update() or ::after-paint() to synchronize this.
         */
-       priv->bracket_highlighting_timeout_id =
-               gdk_threads_add_timeout_full (G_PRIORITY_LOW,
-                                             UPDATE_BRACKET_DELAY,
-                                             bracket_highlighting_timeout_cb,
-                                             buffer,
-                                             NULL);
+       buffer->priv->bracket_highlighting_timeout_id =
+               g_timeout_add_full (G_PRIORITY_LOW,
+                                   UPDATE_BRACKET_DELAY,
+                                   bracket_highlighting_timeout_cb,
+                                   buffer,
+                                   NULL);
 }
 
 /* Although this function is not really useful
@@ -1202,6 +992,8 @@ static void
 cursor_moved (GtkSourceBuffer *buffer)
 {
        queue_bracket_highlighting_update (buffer);
+
+       g_signal_emit (buffer, buffer_signals[CURSOR_MOVED], 0);
 }
 
 static void
@@ -1218,13 +1010,12 @@ gtk_source_buffer_content_inserted (GtkTextBuffer *buffer,
                                    gint           end_offset)
 {
        GtkSourceBuffer *source_buffer = GTK_SOURCE_BUFFER (buffer);
-       GtkSourceBufferPrivate *priv = gtk_source_buffer_get_instance_private (source_buffer);
 
        cursor_moved (source_buffer);
 
-       if (priv->highlight_engine != NULL)
+       if (source_buffer->priv->highlight_engine != NULL)
        {
-               _gtk_source_engine_text_inserted (priv->highlight_engine,
+               _gtk_source_engine_text_inserted (source_buffer->priv->highlight_engine,
                                                  start_offset,
                                                  end_offset);
        }
@@ -1257,14 +1048,14 @@ gtk_source_buffer_real_insert_text (GtkTextBuffer *buffer,
                                            gtk_text_iter_get_offset (iter));
 }
 
-/* insert_pixbuf and insert_child_anchor do nothing except notifying
+/* insert_texture and insert_child_anchor do nothing except notifying
  * the highlighting engine about the change, because engine's idea
  * of buffer char count must be correct at all times.
  */
 static void
-gtk_source_buffer_real_insert_pixbuf (GtkTextBuffer *buffer,
-                                     GtkTextIter   *iter,
-                                     GdkPixbuf     *pixbuf)
+gtk_source_buffer_real_insert_texture (GtkTextBuffer *buffer,
+                                       GtkTextIter   *iter,
+                                       GdkTexture    *texture)
 {
        gint start_offset;
 
@@ -1279,7 +1070,7 @@ gtk_source_buffer_real_insert_pixbuf (GtkTextBuffer *buffer,
         * default signal handler revalidates it to point to the end of the
         * inserted text.
         */
-       GTK_TEXT_BUFFER_CLASS (gtk_source_buffer_parent_class)->insert_pixbuf (buffer, iter, pixbuf);
+       GTK_TEXT_BUFFER_CLASS (gtk_source_buffer_parent_class)->insert_texture (buffer, iter, texture);
 
        gtk_source_buffer_content_inserted (buffer,
                                            start_offset,
@@ -1317,7 +1108,6 @@ gtk_source_buffer_real_delete_range (GtkTextBuffer *buffer,
 {
        gint offset, length;
        GtkSourceBuffer *source_buffer = GTK_SOURCE_BUFFER (buffer);
-       GtkSourceBufferPrivate *priv = gtk_source_buffer_get_instance_private (source_buffer);
 
        g_return_if_fail (GTK_SOURCE_IS_BUFFER (buffer));
        g_return_if_fail (start != NULL);
@@ -1334,9 +1124,9 @@ gtk_source_buffer_real_delete_range (GtkTextBuffer *buffer,
        cursor_moved (source_buffer);
 
        /* emit text deleted for engines */
-       if (priv->highlight_engine != NULL)
+       if (source_buffer->priv->highlight_engine != NULL)
        {
-               _gtk_source_engine_text_deleted (priv->highlight_engine,
+               _gtk_source_engine_text_deleted (source_buffer->priv->highlight_engine,
                                                 offset, length);
        }
 }
@@ -1532,195 +1322,6 @@ _gtk_source_buffer_find_bracket_match (GtkSourceBuffer   *buffer,
        return result_right;
 }
 
-/**
- * gtk_source_buffer_can_undo:
- * @buffer: a #GtkSourceBuffer.
- *
- * Determines whether a source buffer can undo the last action.
- *
- * Returns: %TRUE if it's possible to undo the last action.
- */
-gboolean
-gtk_source_buffer_can_undo (GtkSourceBuffer *buffer)
-{
-       GtkSourceBufferPrivate *priv = gtk_source_buffer_get_instance_private (buffer);
-
-       g_return_val_if_fail (GTK_SOURCE_IS_BUFFER (buffer), FALSE);
-
-       return gtk_source_undo_manager_can_undo (priv->undo_manager);
-}
-
-/**
- * gtk_source_buffer_can_redo:
- * @buffer: a #GtkSourceBuffer.
- *
- * Determines whether a source buffer can redo the last action
- * (i.e. if the last operation was an undo).
- *
- * Returns: %TRUE if a redo is possible.
- */
-gboolean
-gtk_source_buffer_can_redo (GtkSourceBuffer *buffer)
-{
-       GtkSourceBufferPrivate *priv = gtk_source_buffer_get_instance_private (buffer);
-
-       g_return_val_if_fail (GTK_SOURCE_IS_BUFFER (buffer), FALSE);
-
-       return gtk_source_undo_manager_can_redo (priv->undo_manager);
-}
-
-/**
- * gtk_source_buffer_undo:
- * @buffer: a #GtkSourceBuffer.
- *
- * Undoes the last user action which modified the buffer.  Use
- * gtk_source_buffer_can_undo() to check whether a call to this
- * function will have any effect.
- *
- * This function emits the #GtkSourceBuffer::undo signal.
- */
-void
-gtk_source_buffer_undo (GtkSourceBuffer *buffer)
-{
-       g_return_if_fail (GTK_SOURCE_IS_BUFFER (buffer));
-
-       g_signal_emit (buffer, buffer_signals[UNDO], 0);
-}
-
-/**
- * gtk_source_buffer_redo:
- * @buffer: a #GtkSourceBuffer.
- *
- * Redoes the last undo operation.  Use gtk_source_buffer_can_redo()
- * to check whether a call to this function will have any effect.
- *
- * This function emits the #GtkSourceBuffer::redo signal.
- */
-void
-gtk_source_buffer_redo (GtkSourceBuffer *buffer)
-{
-       g_return_if_fail (GTK_SOURCE_IS_BUFFER (buffer));
-
-       g_signal_emit (buffer, buffer_signals[REDO], 0);
-}
-
-/**
- * gtk_source_buffer_get_max_undo_levels:
- * @buffer: a #GtkSourceBuffer.
- *
- * Determines the number of undo levels the buffer will track for buffer edits.
- *
- * Returns: the maximum number of possible undo levels or -1 if no limit is set.
- */
-gint
-gtk_source_buffer_get_max_undo_levels (GtkSourceBuffer *buffer)
-{
-       GtkSourceBufferPrivate *priv = gtk_source_buffer_get_instance_private (buffer);
-
-       g_return_val_if_fail (GTK_SOURCE_IS_BUFFER (buffer), 0);
-
-       return priv->max_undo_levels;
-}
-
-/**
- * gtk_source_buffer_set_max_undo_levels:
- * @buffer: a #GtkSourceBuffer.
- * @max_undo_levels: the desired maximum number of undo levels.
- *
- * Sets the number of undo levels for user actions the buffer will
- * track.  If the number of user actions exceeds the limit set by this
- * function, older actions will be discarded.
- *
- * If @max_undo_levels is -1, the undo/redo is unlimited.
- *
- * If @max_undo_levels is 0, the undo/redo is disabled.
- */
-void
-gtk_source_buffer_set_max_undo_levels (GtkSourceBuffer *buffer,
-                                      gint             max_undo_levels)
-{
-       GtkSourceBufferPrivate *priv = gtk_source_buffer_get_instance_private (buffer);
-
-       g_return_if_fail (GTK_SOURCE_IS_BUFFER (buffer));
-
-       if (priv->max_undo_levels == max_undo_levels)
-       {
-               return;
-       }
-
-       priv->max_undo_levels = max_undo_levels;
-
-       if (GTK_SOURCE_IS_UNDO_MANAGER_DEFAULT (priv->undo_manager))
-       {
-               gtk_source_undo_manager_default_set_max_undo_levels (GTK_SOURCE_UNDO_MANAGER_DEFAULT 
(priv->undo_manager),
-                                                                    max_undo_levels);
-       }
-
-       g_object_notify_by_pspec (G_OBJECT (buffer), buffer_properties[PROP_MAX_UNDO_LEVELS]);
-}
-
-gboolean
-_gtk_source_buffer_is_undo_redo_enabled (GtkSourceBuffer *buffer)
-{
-       GtkSourceBufferPrivate *priv = gtk_source_buffer_get_instance_private (buffer);
-
-       g_return_val_if_fail (GTK_SOURCE_IS_BUFFER (buffer), FALSE);
-
-       if (priv->undo_manager == NULL)
-       {
-               return FALSE;
-       }
-
-       /* A custom UndoManager is not forced to follow max_undo_levels. */
-       if (!GTK_SOURCE_IS_UNDO_MANAGER_DEFAULT (priv->undo_manager))
-       {
-               return TRUE;
-       }
-
-       return priv->max_undo_levels != 0;
-}
-
-/**
- * gtk_source_buffer_begin_not_undoable_action:
- * @buffer: a #GtkSourceBuffer.
- *
- * Marks the beginning of a not undoable action on the buffer,
- * disabling the undo manager.  Typically you would call this function
- * before initially setting the contents of the buffer (e.g. when
- * loading a file in a text editor).
- *
- * You may nest gtk_source_buffer_begin_not_undoable_action() /
- * gtk_source_buffer_end_not_undoable_action() blocks.
- */
-void
-gtk_source_buffer_begin_not_undoable_action (GtkSourceBuffer *buffer)
-{
-       GtkSourceBufferPrivate *priv = gtk_source_buffer_get_instance_private (buffer);
-
-       g_return_if_fail (GTK_SOURCE_IS_BUFFER (buffer));
-
-       gtk_source_undo_manager_begin_not_undoable_action (priv->undo_manager);
-}
-
-/**
- * gtk_source_buffer_end_not_undoable_action:
- * @buffer: a #GtkSourceBuffer.
- *
- * Marks the end of a not undoable action on the buffer.  When the
- * last not undoable block is closed through the call to this
- * function, the list of undo actions is cleared and the undo manager
- * is re-enabled.
- */
-void
-gtk_source_buffer_end_not_undoable_action (GtkSourceBuffer *buffer)
-{
-       GtkSourceBufferPrivate *priv = gtk_source_buffer_get_instance_private (buffer);
-
-       g_return_if_fail (GTK_SOURCE_IS_BUFFER (buffer));
-
-       gtk_source_undo_manager_end_not_undoable_action (priv->undo_manager);
-}
-
 /**
  * gtk_source_buffer_get_highlight_matching_brackets:
  * @buffer: a #GtkSourceBuffer.
@@ -1734,11 +1335,9 @@ gtk_source_buffer_end_not_undoable_action (GtkSourceBuffer *buffer)
 gboolean
 gtk_source_buffer_get_highlight_matching_brackets (GtkSourceBuffer *buffer)
 {
-       GtkSourceBufferPrivate *priv = gtk_source_buffer_get_instance_private (buffer);
-
        g_return_val_if_fail (GTK_SOURCE_IS_BUFFER (buffer), FALSE);
 
-       return priv->highlight_brackets;
+       return buffer->priv->highlight_brackets;
 }
 
 /**
@@ -1755,15 +1354,13 @@ void
 gtk_source_buffer_set_highlight_matching_brackets (GtkSourceBuffer *buffer,
                                                   gboolean         highlight)
 {
-       GtkSourceBufferPrivate *priv = gtk_source_buffer_get_instance_private (buffer);
-
        g_return_if_fail (GTK_SOURCE_IS_BUFFER (buffer));
 
        highlight = highlight != FALSE;
 
-       if (highlight != priv->highlight_brackets)
+       if (highlight != buffer->priv->highlight_brackets)
        {
-               priv->highlight_brackets = highlight;
+               buffer->priv->highlight_brackets = highlight;
 
                update_bracket_highlighting (buffer);
 
@@ -1783,11 +1380,9 @@ gtk_source_buffer_set_highlight_matching_brackets (GtkSourceBuffer *buffer,
 gboolean
 gtk_source_buffer_get_highlight_syntax (GtkSourceBuffer *buffer)
 {
-       GtkSourceBufferPrivate *priv = gtk_source_buffer_get_instance_private (buffer);
-
        g_return_val_if_fail (GTK_SOURCE_IS_BUFFER (buffer), FALSE);
 
-       return priv->highlight_syntax;
+       return buffer->priv->highlight_syntax;
 }
 
 /**
@@ -1809,15 +1404,13 @@ void
 gtk_source_buffer_set_highlight_syntax (GtkSourceBuffer *buffer,
                                        gboolean         highlight)
 {
-       GtkSourceBufferPrivate *priv = gtk_source_buffer_get_instance_private (buffer);
-
        g_return_if_fail (GTK_SOURCE_IS_BUFFER (buffer));
 
        highlight = highlight != FALSE;
 
-       if (priv->highlight_syntax != highlight)
+       if (buffer->priv->highlight_syntax != highlight)
        {
-               priv->highlight_syntax = highlight;
+               buffer->priv->highlight_syntax = highlight;
                g_object_notify_by_pspec (G_OBJECT (buffer), buffer_properties[PROP_HIGHLIGHT_SYNTAX]);
        }
 }
@@ -1839,38 +1432,36 @@ void
 gtk_source_buffer_set_language (GtkSourceBuffer   *buffer,
                                GtkSourceLanguage *language)
 {
-       GtkSourceBufferPrivate *priv = gtk_source_buffer_get_instance_private (buffer);
-
        g_return_if_fail (GTK_SOURCE_IS_BUFFER (buffer));
        g_return_if_fail (GTK_SOURCE_IS_LANGUAGE (language) || language == NULL);
 
-       if (!g_set_object (&priv->language, language))
+       if (!g_set_object (&buffer->priv->language, language))
        {
                return;
        }
 
-       if (priv->highlight_engine != NULL)
+       if (buffer->priv->highlight_engine != NULL)
        {
                /* disconnect the old engine */
-               _gtk_source_engine_attach_buffer (priv->highlight_engine, NULL);
-               g_object_unref (priv->highlight_engine);
-               priv->highlight_engine = NULL;
+               _gtk_source_engine_attach_buffer (buffer->priv->highlight_engine, NULL);
+               g_object_unref (buffer->priv->highlight_engine);
+               buffer->priv->highlight_engine = NULL;
        }
 
        if (language != NULL)
        {
                /* get a new engine */
-               priv->highlight_engine = _gtk_source_language_create_engine (language);
+               buffer->priv->highlight_engine = _gtk_source_language_create_engine (language);
 
-               if (priv->highlight_engine != NULL)
+               if (buffer->priv->highlight_engine != NULL)
                {
-                       _gtk_source_engine_attach_buffer (priv->highlight_engine,
+                       _gtk_source_engine_attach_buffer (buffer->priv->highlight_engine,
                                                          GTK_TEXT_BUFFER (buffer));
 
-                       if (priv->style_scheme != NULL)
+                       if (buffer->priv->style_scheme != NULL)
                        {
-                               _gtk_source_engine_set_style_scheme (priv->highlight_engine,
-                                                                    priv->style_scheme);
+                               _gtk_source_engine_set_style_scheme (buffer->priv->highlight_engine,
+                                                                    buffer->priv->style_scheme);
                        }
                }
        }
@@ -1892,11 +1483,9 @@ gtk_source_buffer_set_language (GtkSourceBuffer   *buffer,
 GtkSourceLanguage *
 gtk_source_buffer_get_language (GtkSourceBuffer *buffer)
 {
-       GtkSourceBufferPrivate *priv = gtk_source_buffer_get_instance_private (buffer);
-
        g_return_val_if_fail (GTK_SOURCE_IS_BUFFER (buffer), NULL);
 
-       return priv->language;
+       return buffer->priv->language;
 }
 
 /*
@@ -1914,13 +1503,11 @@ _gtk_source_buffer_update_syntax_highlight (GtkSourceBuffer   *buffer,
                                            const GtkTextIter *end,
                                            gboolean           synchronous)
 {
-       GtkSourceBufferPrivate *priv = gtk_source_buffer_get_instance_private (buffer);
-
        g_return_if_fail (GTK_SOURCE_IS_BUFFER (buffer));
 
-       if (priv->highlight_engine != NULL)
+       if (buffer->priv->highlight_engine != NULL)
        {
-               _gtk_source_engine_update_highlight (priv->highlight_engine,
+               _gtk_source_engine_update_highlight (buffer->priv->highlight_engine,
                                                     start,
                                                     end,
                                                     synchronous);
@@ -1933,12 +1520,11 @@ _gtk_source_buffer_update_search_highlight (GtkSourceBuffer   *buffer,
                                            const GtkTextIter *end,
                                            gboolean           synchronous)
 {
-       GtkSourceBufferPrivate *priv = gtk_source_buffer_get_instance_private (buffer);
        GList *l;
 
        g_return_if_fail (GTK_SOURCE_IS_BUFFER (buffer));
 
-       for (l = priv->search_contexts; l != NULL; l = l->next)
+       for (l = buffer->priv->search_contexts; l != NULL; l = l->next)
        {
                GtkSourceSearchContext *search_context = l->data;
 
@@ -1997,18 +1583,16 @@ void
 gtk_source_buffer_set_style_scheme (GtkSourceBuffer      *buffer,
                                    GtkSourceStyleScheme *scheme)
 {
-       GtkSourceBufferPrivate *priv = gtk_source_buffer_get_instance_private (buffer);
-
        g_return_if_fail (GTK_SOURCE_IS_BUFFER (buffer));
        g_return_if_fail (GTK_SOURCE_IS_STYLE_SCHEME (scheme) || scheme == NULL);
 
-       if (g_set_object (&priv->style_scheme, scheme))
+       if (g_set_object (&buffer->priv->style_scheme, scheme))
        {
                update_bracket_match_style (buffer);
 
-               if (priv->highlight_engine != NULL)
+               if (buffer->priv->highlight_engine != NULL)
                {
-                       _gtk_source_engine_set_style_scheme (priv->highlight_engine, scheme);
+                       _gtk_source_engine_set_style_scheme (buffer->priv->highlight_engine, scheme);
                }
 
                g_object_notify_by_pspec (G_OBJECT (buffer), buffer_properties[PROP_STYLE_SCHEME]);
@@ -2029,33 +1613,29 @@ gtk_source_buffer_set_style_scheme (GtkSourceBuffer      *buffer,
 GtkSourceStyleScheme *
 gtk_source_buffer_get_style_scheme (GtkSourceBuffer *buffer)
 {
-       GtkSourceBufferPrivate *priv = gtk_source_buffer_get_instance_private (buffer);
-
        g_return_val_if_fail (GTK_SOURCE_IS_BUFFER (buffer), NULL);
 
-       return priv->style_scheme;
+       return buffer->priv->style_scheme;
 }
 
 static void
 add_source_mark (GtkSourceBuffer *buffer,
                 GtkSourceMark   *mark)
 {
-       GtkSourceBufferPrivate *priv = gtk_source_buffer_get_instance_private (buffer);
-
        const gchar *category;
        GtkSourceMarksSequence *seq;
 
-       _gtk_source_marks_sequence_add (priv->all_source_marks,
+       _gtk_source_marks_sequence_add (buffer->priv->all_source_marks,
                                        GTK_TEXT_MARK (mark));
 
        category = gtk_source_mark_get_category (mark);
-       seq = g_hash_table_lookup (priv->source_marks, category);
+       seq = g_hash_table_lookup (buffer->priv->source_marks, category);
 
        if (seq == NULL)
        {
                seq = _gtk_source_marks_sequence_new (GTK_TEXT_BUFFER (buffer));
 
-               g_hash_table_insert (priv->source_marks,
+               g_hash_table_insert (buffer->priv->source_marks,
                                     g_strdup (category),
                                     seq);
        }
@@ -2090,16 +1670,15 @@ gtk_source_buffer_real_mark_deleted (GtkTextBuffer *buffer,
        if (GTK_SOURCE_IS_MARK (mark))
        {
                GtkSourceBuffer *source_buffer = GTK_SOURCE_BUFFER (buffer);
-               GtkSourceBufferPrivate *priv = gtk_source_buffer_get_instance_private (source_buffer);
                const gchar *category;
                GtkSourceMarksSequence *seq;
 
                category = gtk_source_mark_get_category (GTK_SOURCE_MARK (mark));
-               seq = g_hash_table_lookup (priv->source_marks, category);
+               seq = g_hash_table_lookup (source_buffer->priv->source_marks, category);
 
                if (_gtk_source_marks_sequence_is_empty (seq))
                {
-                       g_hash_table_remove (priv->source_marks, category);
+                       g_hash_table_remove (source_buffer->priv->source_marks, category);
                }
 
                g_signal_emit (buffer, buffer_signals[SOURCE_MARK_UPDATED], 0, mark);
@@ -2111,26 +1690,6 @@ gtk_source_buffer_real_mark_deleted (GtkTextBuffer *buffer,
        }
 }
 
-static void
-gtk_source_buffer_real_undo (GtkSourceBuffer *buffer)
-{
-       GtkSourceBufferPrivate *priv = gtk_source_buffer_get_instance_private (buffer);
-
-       g_return_if_fail (gtk_source_undo_manager_can_undo (priv->undo_manager));
-
-       gtk_source_undo_manager_undo (priv->undo_manager);
-}
-
-static void
-gtk_source_buffer_real_redo (GtkSourceBuffer *buffer)
-{
-       GtkSourceBufferPrivate *priv = gtk_source_buffer_get_instance_private (buffer);
-
-       g_return_if_fail (gtk_source_undo_manager_can_redo (priv->undo_manager));
-
-       gtk_source_undo_manager_redo (priv->undo_manager);
-}
-
 /**
  * gtk_source_buffer_create_source_mark:
  * @buffer: a #GtkSourceBuffer.
@@ -2186,11 +1745,9 @@ static GtkSourceMarksSequence *
 get_marks_sequence (GtkSourceBuffer *buffer,
                    const gchar     *category)
 {
-       GtkSourceBufferPrivate *priv = gtk_source_buffer_get_instance_private (buffer);
-
        return category == NULL ?
-               priv->all_source_marks :
-               g_hash_table_lookup (priv->source_marks, category);
+               buffer->priv->all_source_marks :
+               g_hash_table_lookup (buffer->priv->source_marks, category);
 }
 
 GtkSourceMark *
@@ -2240,7 +1797,7 @@ _gtk_source_buffer_source_mark_prev (GtkSourceBuffer *buffer,
 /**
  * gtk_source_buffer_forward_iter_to_source_mark:
  * @buffer: a #GtkSourceBuffer.
- * @iter: (inout): an iterator.
+ * @iter: an iterator.
  * @category: (nullable): category to search for, or %NULL
  *
  * Moves @iter to the position of the next #GtkSourceMark of the given
@@ -2274,7 +1831,7 @@ gtk_source_buffer_forward_iter_to_source_mark (GtkSourceBuffer *buffer,
 /**
  * gtk_source_buffer_backward_iter_to_source_mark:
  * @buffer: a #GtkSourceBuffer.
- * @iter: (inout): an iterator.
+ * @iter: an iterator.
  * @category: (nullable): category to search for, or %NULL
  *
  * Moves @iter to the position of the previous #GtkSourceMark of the given
@@ -2431,13 +1988,11 @@ gtk_source_buffer_remove_source_marks (GtkSourceBuffer   *buffer,
 gboolean
 _gtk_source_buffer_has_source_marks (GtkSourceBuffer *buffer)
 {
-       GtkSourceBufferPrivate *priv = gtk_source_buffer_get_instance_private (buffer);
-
        g_return_val_if_fail (GTK_SOURCE_IS_BUFFER (buffer), FALSE);
 
-       if (priv->all_source_marks != NULL)
+       if (buffer->priv->all_source_marks != NULL)
        {
-               return !_gtk_source_marks_sequence_is_empty (priv->all_source_marks);
+               return !_gtk_source_marks_sequence_is_empty (buffer->priv->all_source_marks);
        }
 
        return FALSE;
@@ -2551,7 +2106,7 @@ gtk_source_buffer_get_context_classes_at_iter (GtkSourceBuffer   *buffer,
 /**
  * gtk_source_buffer_iter_forward_to_context_class_toggle:
  * @buffer: a #GtkSourceBuffer.
- * @iter: (inout): a #GtkTextIter.
+ * @iter: a #GtkTextIter.
  * @context_class: the context class.
  *
  * Moves forward to the next toggle (on or off) of the context class. If no
@@ -2590,7 +2145,7 @@ gtk_source_buffer_iter_forward_to_context_class_toggle (GtkSourceBuffer *buffer,
 /**
  * gtk_source_buffer_iter_backward_to_context_class_toggle:
  * @buffer: a #GtkSourceBuffer.
- * @iter: (inout): a #GtkTextIter.
+ * @iter: a #GtkTextIter.
  * @context_class: the context class.
  *
  * Moves backward to the next toggle (on or off) of the context class. If no
@@ -2635,7 +2190,6 @@ gtk_source_buffer_iter_backward_to_context_class_toggle (GtkSourceBuffer *buffer
 void
 _gtk_source_buffer_save_and_clear_selection (GtkSourceBuffer *buffer)
 {
-       GtkSourceBufferPrivate *priv = gtk_source_buffer_get_instance_private (buffer);
        GtkTextBuffer *buf;
 
        g_return_if_fail (GTK_SOURCE_IS_BUFFER (buffer));
@@ -2651,13 +2205,13 @@ _gtk_source_buffer_save_and_clear_selection (GtkSourceBuffer *buffer)
                GtkTextIter insert_iter;
                GtkTextIter selection_bound_iter;
 
-               g_assert (priv->tmp_insert_mark == NULL);
-               g_assert (priv->tmp_selection_bound_mark == NULL);
+               g_assert (buffer->priv->tmp_insert_mark == NULL);
+               g_assert (buffer->priv->tmp_selection_bound_mark == NULL);
 
                gtk_text_buffer_get_iter_at_mark (buf, &insert_iter, gtk_text_buffer_get_insert (buf));
                gtk_text_buffer_get_iter_at_mark (buf, &selection_bound_iter, 
gtk_text_buffer_get_selection_bound (buf));
-               priv->tmp_insert_mark = gtk_text_buffer_create_mark (buf, NULL, &insert_iter, FALSE);
-               priv->tmp_selection_bound_mark = gtk_text_buffer_create_mark (buf, NULL, 
&selection_bound_iter, FALSE);
+               buffer->priv->tmp_insert_mark = gtk_text_buffer_create_mark (buf, NULL, &insert_iter, FALSE);
+               buffer->priv->tmp_selection_bound_mark = gtk_text_buffer_create_mark (buf, NULL, 
&selection_bound_iter, FALSE);
 
                gtk_text_buffer_place_cursor (buf, &insert_iter);
        }
@@ -2666,12 +2220,10 @@ _gtk_source_buffer_save_and_clear_selection (GtkSourceBuffer *buffer)
 void
 _gtk_source_buffer_restore_selection (GtkSourceBuffer *buffer)
 {
-       GtkSourceBufferPrivate *priv = gtk_source_buffer_get_instance_private (buffer);
-
        g_return_if_fail (GTK_SOURCE_IS_BUFFER (buffer));
 
-       if (priv->tmp_insert_mark != NULL &&
-           priv->tmp_selection_bound_mark != NULL)
+       if (buffer->priv->tmp_insert_mark != NULL &&
+           buffer->priv->tmp_selection_bound_mark != NULL)
        {
                GtkTextBuffer *buf;
                GtkTextIter insert_iter;
@@ -2679,15 +2231,15 @@ _gtk_source_buffer_restore_selection (GtkSourceBuffer *buffer)
 
                buf = GTK_TEXT_BUFFER (buffer);
 
-               gtk_text_buffer_get_iter_at_mark (buf, &insert_iter, priv->tmp_insert_mark);
-               gtk_text_buffer_get_iter_at_mark (buf, &selection_bound_iter, priv->tmp_selection_bound_mark);
+               gtk_text_buffer_get_iter_at_mark (buf, &insert_iter, buffer->priv->tmp_insert_mark);
+               gtk_text_buffer_get_iter_at_mark (buf, &selection_bound_iter, 
buffer->priv->tmp_selection_bound_mark);
 
                gtk_text_buffer_select_range (buf, &insert_iter, &selection_bound_iter);
 
-               gtk_text_buffer_delete_mark (buf, priv->tmp_insert_mark);
-               gtk_text_buffer_delete_mark (buf, priv->tmp_selection_bound_mark);
-               priv->tmp_insert_mark = NULL;
-               priv->tmp_selection_bound_mark = NULL;
+               gtk_text_buffer_delete_mark (buf, buffer->priv->tmp_insert_mark);
+               gtk_text_buffer_delete_mark (buf, buffer->priv->tmp_selection_bound_mark);
+               buffer->priv->tmp_insert_mark = NULL;
+               buffer->priv->tmp_selection_bound_mark = NULL;
        }
 }
 
@@ -3192,78 +2744,20 @@ gtk_source_buffer_sort_lines (GtkSourceBuffer    *buffer,
        g_free (lines);
 }
 
-/**
- * gtk_source_buffer_set_undo_manager:
- * @buffer: a #GtkSourceBuffer.
- * @manager: (nullable): A #GtkSourceUndoManager or %NULL.
- *
- * Set the buffer undo manager. If @manager is %NULL the default undo manager
- * will be set.
- */
-void
-gtk_source_buffer_set_undo_manager (GtkSourceBuffer      *buffer,
-                                    GtkSourceUndoManager *manager)
-{
-       GtkSourceBufferPrivate *priv = gtk_source_buffer_get_instance_private (buffer);
-
-       g_return_if_fail (GTK_SOURCE_IS_BUFFER (buffer));
-       g_return_if_fail (manager == NULL || GTK_SOURCE_IS_UNDO_MANAGER (manager));
-
-       if (manager == NULL)
-       {
-               manager = g_object_new (GTK_SOURCE_TYPE_UNDO_MANAGER_DEFAULT,
-                                       "buffer", buffer,
-                                       "max-undo-levels", priv->max_undo_levels,
-                                       NULL);
-       }
-       else
-       {
-               g_object_ref (manager);
-       }
-
-       set_undo_manager (buffer, manager);
-       g_object_unref (manager);
-
-       g_object_notify_by_pspec (G_OBJECT (buffer), buffer_properties[PROP_UNDO_MANAGER]);
-}
-
-/**
- * gtk_source_buffer_get_undo_manager:
- * @buffer: a #GtkSourceBuffer.
- *
- * Returns the #GtkSourceUndoManager associated with the buffer,
- * see gtk_source_buffer_set_undo_manager().  The returned object should not be
- * unreferenced by the user.
- *
- * Returns: (nullable) (transfer none): the #GtkSourceUndoManager associated
- * with the buffer, or %NULL.
- */
-GtkSourceUndoManager *
-gtk_source_buffer_get_undo_manager (GtkSourceBuffer *buffer)
-{
-       GtkSourceBufferPrivate *priv = gtk_source_buffer_get_instance_private (buffer);
-
-       g_return_val_if_fail (GTK_SOURCE_IS_BUFFER (buffer), NULL);
-
-       return priv->undo_manager;
-}
-
 void
 _gtk_source_buffer_add_search_context (GtkSourceBuffer        *buffer,
                                       GtkSourceSearchContext *search_context)
 {
-       GtkSourceBufferPrivate *priv = gtk_source_buffer_get_instance_private (buffer);
-
        g_return_if_fail (GTK_SOURCE_IS_BUFFER (buffer));
        g_return_if_fail (GTK_SOURCE_IS_SEARCH_CONTEXT (search_context));
        g_return_if_fail (gtk_source_search_context_get_buffer (search_context) == buffer);
 
-       if (g_list_find (priv->search_contexts, search_context) != NULL)
+       if (g_list_find (buffer->priv->search_contexts, search_context) != NULL)
        {
                return;
        }
 
-       priv->search_contexts = g_list_prepend (priv->search_contexts,
+       buffer->priv->search_contexts = g_list_prepend (buffer->priv->search_contexts,
                                                        search_context);
 
        g_object_weak_ref (G_OBJECT (search_context),
@@ -3276,15 +2770,14 @@ sync_invalid_char_tag (GtkSourceBuffer *buffer,
                       GParamSpec      *pspec,
                       gpointer         data)
 {
-       GtkSourceBufferPrivate *priv = gtk_source_buffer_get_instance_private (buffer);
        GtkSourceStyle *style = NULL;
 
-       if (priv->style_scheme != NULL)
+       if (buffer->priv->style_scheme != NULL)
        {
-               style = gtk_source_style_scheme_get_style (priv->style_scheme, "def:error");
+               style = gtk_source_style_scheme_get_style (buffer->priv->style_scheme, "def:error");
        }
 
-       gtk_source_style_apply (style, priv->invalid_char_tag);
+       gtk_source_style_apply (style, buffer->priv->invalid_char_tag);
 }
 
 static void
@@ -3304,11 +2797,9 @@ _gtk_source_buffer_set_as_invalid_character (GtkSourceBuffer   *buffer,
                                             const GtkTextIter *start,
                                             const GtkTextIter *end)
 {
-       GtkSourceBufferPrivate *priv = gtk_source_buffer_get_instance_private (buffer);
-
-       if (priv->invalid_char_tag == NULL)
+       if (buffer->priv->invalid_char_tag == NULL)
        {
-               priv->invalid_char_tag = gtk_text_buffer_create_tag (GTK_TEXT_BUFFER (buffer),
+               buffer->priv->invalid_char_tag = gtk_text_buffer_create_tag (GTK_TEXT_BUFFER (buffer),
                                                                             "invalid-char-style",
                                                                             NULL);
 
@@ -3323,11 +2814,11 @@ _gtk_source_buffer_set_as_invalid_character (GtkSourceBuffer   *buffer,
        /* Make sure the 'error' tag has the priority over
         * syntax highlighting tags.
         */
-       text_tag_set_highest_priority (priv->invalid_char_tag,
+       text_tag_set_highest_priority (buffer->priv->invalid_char_tag,
                                       GTK_TEXT_BUFFER (buffer));
 
        gtk_text_buffer_apply_tag (GTK_TEXT_BUFFER (buffer),
-                                  priv->invalid_char_tag,
+                                  buffer->priv->invalid_char_tag,
                                   start,
                                   end);
 }
@@ -3335,20 +2826,19 @@ _gtk_source_buffer_set_as_invalid_character (GtkSourceBuffer   *buffer,
 gboolean
 _gtk_source_buffer_has_invalid_chars (GtkSourceBuffer *buffer)
 {
-       GtkSourceBufferPrivate *priv = gtk_source_buffer_get_instance_private (buffer);
        GtkTextIter start;
 
        g_return_val_if_fail (GTK_SOURCE_IS_BUFFER (buffer), FALSE);
 
-       if (priv->invalid_char_tag == NULL)
+       if (buffer->priv->invalid_char_tag == NULL)
        {
                return FALSE;
        }
 
        gtk_text_buffer_get_start_iter (GTK_TEXT_BUFFER (buffer), &start);
 
-       if (gtk_text_iter_starts_tag (&start, priv->invalid_char_tag) ||
-           gtk_text_iter_forward_to_tag_toggle (&start, priv->invalid_char_tag))
+       if (gtk_text_iter_starts_tag (&start, buffer->priv->invalid_char_tag) ||
+           gtk_text_iter_forward_to_tag_toggle (&start, buffer->priv->invalid_char_tag))
        {
                return TRUE;
        }
@@ -3383,15 +2873,13 @@ void
 gtk_source_buffer_set_implicit_trailing_newline (GtkSourceBuffer *buffer,
                                                 gboolean         implicit_trailing_newline)
 {
-       GtkSourceBufferPrivate *priv = gtk_source_buffer_get_instance_private (buffer);
-
        g_return_if_fail (GTK_SOURCE_IS_BUFFER (buffer));
 
        implicit_trailing_newline = implicit_trailing_newline != FALSE;
 
-       if (priv->implicit_trailing_newline != implicit_trailing_newline)
+       if (buffer->priv->implicit_trailing_newline != implicit_trailing_newline)
        {
-               priv->implicit_trailing_newline = implicit_trailing_newline;
+               buffer->priv->implicit_trailing_newline = implicit_trailing_newline;
                g_object_notify_by_pspec (G_OBJECT (buffer), 
buffer_properties[PROP_IMPLICIT_TRAILING_NEWLINE]);
        }
 }
@@ -3406,11 +2894,9 @@ gtk_source_buffer_set_implicit_trailing_newline (GtkSourceBuffer *buffer,
 gboolean
 gtk_source_buffer_get_implicit_trailing_newline (GtkSourceBuffer *buffer)
 {
-       GtkSourceBufferPrivate *priv = gtk_source_buffer_get_instance_private (buffer);
-
        g_return_val_if_fail (GTK_SOURCE_IS_BUFFER (buffer), TRUE);
 
-       return priv->implicit_trailing_newline;
+       return buffer->priv->implicit_trailing_newline;
 }
 
 /**
@@ -3475,9 +2961,7 @@ gtk_source_buffer_create_source_tag (GtkSourceBuffer *buffer,
 gboolean
 _gtk_source_buffer_has_spaces_tag (GtkSourceBuffer *buffer)
 {
-       GtkSourceBufferPrivate *priv = gtk_source_buffer_get_instance_private (buffer);
-
        g_return_val_if_fail (GTK_SOURCE_IS_BUFFER (buffer), FALSE);
 
-       return priv->has_draw_spaces_tag;
+       return buffer->priv->has_draw_spaces_tag;
 }
diff --git a/gtksourceview/gtksourcebuffer.h b/gtksourceview/gtksourcebuffer.h
index 382955f6..6d951f2b 100644
--- a/gtksourceview/gtksourcebuffer.h
+++ b/gtksourceview/gtksourcebuffer.h
@@ -2,11 +2,11 @@
  *
  * This file is part of GtkSourceView
  *
- * Copyright 1999-2002 - Mikael Hermansson <tyan linux se>,
- *                       Chris Phelps <chicane reninet com> and
- *                       Jeroen Zwartepoorte <jeroen xs4all nl>
- * Copyright 2003 - Paolo Maggi, Gustavo Giráldez
- * Copyright 2014 - Sébastien Wilmet <swilmet gnome org>
+ * Copyright (C) 1999-2002 - Mikael Hermansson <tyan linux se>,
+ *                           Chris Phelps <chicane reninet com> and
+ *                           Jeroen Zwartepoorte <jeroen xs4all nl>
+ * Copyright (C) 2003 - Paolo Maggi, Gustavo Giráldez
+ * Copyright (C) 2014 - Sébastien Wilmet <swilmet gnome org>
  *
  * GtkSourceView is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -22,7 +22,8 @@
  * along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#pragma once
+#ifndef GTK_SOURCE_BUFFER_H
+#define GTK_SOURCE_BUFFER_H
 
 #if !defined (GTK_SOURCE_H_INSIDE) && !defined (GTK_SOURCE_COMPILATION)
 #error "Only <gtksourceview/gtksource.h> can be included directly."
@@ -34,10 +35,15 @@
 
 G_BEGIN_DECLS
 
-#define GTK_SOURCE_TYPE_BUFFER (gtk_source_buffer_get_type())
+#define GTK_SOURCE_TYPE_BUFFER            (gtk_source_buffer_get_type ())
+#define GTK_SOURCE_BUFFER(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_SOURCE_TYPE_BUFFER, 
GtkSourceBuffer))
+#define GTK_SOURCE_BUFFER_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_SOURCE_TYPE_BUFFER, 
GtkSourceBufferClass))
+#define GTK_SOURCE_IS_BUFFER(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_SOURCE_TYPE_BUFFER))
+#define GTK_SOURCE_IS_BUFFER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_SOURCE_TYPE_BUFFER))
+#define GTK_SOURCE_BUFFER_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_SOURCE_TYPE_BUFFER, 
GtkSourceBufferClass))
 
-GTK_SOURCE_AVAILABLE_IN_ALL
-G_DECLARE_DERIVABLE_TYPE (GtkSourceBuffer, gtk_source_buffer, GTK_SOURCE, BUFFER, GtkTextBuffer)
+typedef struct _GtkSourceBufferClass           GtkSourceBufferClass;
+typedef struct _GtkSourceBufferPrivate         GtkSourceBufferPrivate;
 
 /**
  * GtkSourceBracketMatchType:
@@ -89,138 +95,151 @@ typedef enum _GtkSourceSortFlags
        GTK_SOURCE_SORT_FLAGS_REMOVE_DUPLICATES = 1 << 2,
 } GtkSourceSortFlags;
 
+struct _GtkSourceBuffer
+{
+       GtkTextBuffer parent_instance;
+
+       GtkSourceBufferPrivate *priv;
+};
+
 struct _GtkSourceBufferClass
 {
        GtkTextBufferClass parent_class;
 
        /* Signals */
-       void (*undo)            (GtkSourceBuffer *buffer);
-       void (*redo)            (GtkSourceBuffer *buffer);
-
        void (*bracket_matched) (GtkSourceBuffer           *buffer,
-                                GtkTextIter               *iter,
-                                GtkSourceBracketMatchType  state);
+                                GtkTextIter               *iter,
+                                GtkSourceBracketMatchType  state);
 
        /*< private >*/
        gpointer _reserved[20];
 };
 
 GTK_SOURCE_AVAILABLE_IN_ALL
-GtkSourceBuffer       *gtk_source_buffer_new                                   (GtkTextTagTable         
*table);
-GTK_SOURCE_AVAILABLE_IN_ALL
-GtkSourceBuffer       *gtk_source_buffer_new_with_language                     (GtkSourceLanguage       
*language);
-GTK_SOURCE_AVAILABLE_IN_ALL
-gboolean               gtk_source_buffer_get_highlight_syntax                  (GtkSourceBuffer         
*buffer);
-GTK_SOURCE_AVAILABLE_IN_ALL
-void                   gtk_source_buffer_set_highlight_syntax                  (GtkSourceBuffer         
*buffer,
-                                                                                gboolean                 
highlight);
-GTK_SOURCE_AVAILABLE_IN_ALL
-gboolean               gtk_source_buffer_get_highlight_matching_brackets       (GtkSourceBuffer         
*buffer);
-GTK_SOURCE_AVAILABLE_IN_ALL
-void                   gtk_source_buffer_set_highlight_matching_brackets       (GtkSourceBuffer         
*buffer,
-                                                                                gboolean                 
highlight);
-GTK_SOURCE_AVAILABLE_IN_ALL
-gint                   gtk_source_buffer_get_max_undo_levels                   (GtkSourceBuffer         
*buffer);
-GTK_SOURCE_AVAILABLE_IN_ALL
-void                   gtk_source_buffer_set_max_undo_levels                   (GtkSourceBuffer         
*buffer,
-                                                                                gint                     
max_undo_levels);
+GType                   gtk_source_buffer_get_type                             (void) G_GNUC_CONST;
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-GtkSourceLanguage     *gtk_source_buffer_get_language                          (GtkSourceBuffer         
*buffer);
+GtkSourceBuffer                *gtk_source_buffer_new                                  (GtkTextTagTable      
  *table);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-void                   gtk_source_buffer_set_language                          (GtkSourceBuffer         
*buffer,
-                                                                                GtkSourceLanguage       
*language);
+GtkSourceBuffer        *gtk_source_buffer_new_with_language                    (GtkSourceLanguage      
*language);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-gboolean               gtk_source_buffer_can_undo                              (GtkSourceBuffer         
*buffer);
+gboolean                gtk_source_buffer_get_highlight_syntax                 (GtkSourceBuffer        
*buffer);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-gboolean               gtk_source_buffer_can_redo                              (GtkSourceBuffer         
*buffer);
+void                    gtk_source_buffer_set_highlight_syntax                 (GtkSourceBuffer        
*buffer,
+                                                                                gboolean                
highlight);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-GtkSourceStyleScheme  *gtk_source_buffer_get_style_scheme                      (GtkSourceBuffer         
*buffer);
+gboolean                gtk_source_buffer_get_highlight_matching_brackets      (GtkSourceBuffer        
*buffer);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-void                   gtk_source_buffer_set_style_scheme                      (GtkSourceBuffer         
*buffer,
-                                                                                GtkSourceStyleScheme    
*scheme);
+void                    gtk_source_buffer_set_highlight_matching_brackets      (GtkSourceBuffer        
*buffer,
+                                                                                gboolean                
highlight);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-void                   gtk_source_buffer_ensure_highlight                      (GtkSourceBuffer         
*buffer,
-                                                                                const GtkTextIter       
*start,
-                                                                                const GtkTextIter       
*end);
+GtkSourceLanguage      *gtk_source_buffer_get_language                         (GtkSourceBuffer        
*buffer);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-void                   gtk_source_buffer_undo                                  (GtkSourceBuffer         
*buffer);
+void                    gtk_source_buffer_set_language                         (GtkSourceBuffer        
*buffer,
+                                                                                GtkSourceLanguage      
*language);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-void                   gtk_source_buffer_redo                                  (GtkSourceBuffer         
*buffer);
+GtkSourceStyleScheme    *gtk_source_buffer_get_style_scheme                    (GtkSourceBuffer        
*buffer);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-void                   gtk_source_buffer_begin_not_undoable_action             (GtkSourceBuffer         
*buffer);
+void                    gtk_source_buffer_set_style_scheme                     (GtkSourceBuffer        
*buffer,
+                                                                                GtkSourceStyleScheme   
*scheme);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-void                   gtk_source_buffer_end_not_undoable_action               (GtkSourceBuffer         
*buffer);
+void                    gtk_source_buffer_ensure_highlight                     (GtkSourceBuffer        
*buffer,
+                                                                                const GtkTextIter      
*start,
+                                                                                const GtkTextIter      *end);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-GtkSourceMark         *gtk_source_buffer_create_source_mark                    (GtkSourceBuffer         
*buffer,
-                                                                                const gchar             
*name,
-                                                                                const gchar             
*category,
-                                                                                const GtkTextIter       
*where);
+GtkSourceMark          *gtk_source_buffer_create_source_mark                   (GtkSourceBuffer        
*buffer,
+                                                                                const gchar            *name,
+                                                                                const gchar            
*category,
+                                                                                const GtkTextIter      
*where);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-gboolean               gtk_source_buffer_forward_iter_to_source_mark           (GtkSourceBuffer         
*buffer,
-                                                                                GtkTextIter             
*iter,
-                                                                                const gchar             
*category);
+gboolean                gtk_source_buffer_forward_iter_to_source_mark          (GtkSourceBuffer        
*buffer,
+                                                                                GtkTextIter            *iter,
+                                                                                const gchar            
*category);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-gboolean               gtk_source_buffer_backward_iter_to_source_mark          (GtkSourceBuffer         
*buffer,
-                                                                                GtkTextIter             
*iter,
-                                                                                const gchar             
*category);
+gboolean                gtk_source_buffer_backward_iter_to_source_mark         (GtkSourceBuffer        
*buffer,
+                                                                                GtkTextIter            *iter,
+                                                                                const gchar            
*category);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-GSList                *gtk_source_buffer_get_source_marks_at_iter              (GtkSourceBuffer         
*buffer,
-                                                                                GtkTextIter             
*iter,
-                                                                                const gchar             
*category);
+GSList                 *gtk_source_buffer_get_source_marks_at_iter             (GtkSourceBuffer        
*buffer,
+                                                                                GtkTextIter            *iter,
+                                                                                const gchar            
*category);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-GSList                *gtk_source_buffer_get_source_marks_at_line              (GtkSourceBuffer         
*buffer,
-                                                                                gint                     
line,
-                                                                                const gchar             
*category);
+GSList                 *gtk_source_buffer_get_source_marks_at_line             (GtkSourceBuffer        
*buffer,
+                                                                                gint                    line,
+                                                                                const gchar            
*category);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-void                   gtk_source_buffer_remove_source_marks                   (GtkSourceBuffer         
*buffer,
-                                                                                const GtkTextIter       
*start,
-                                                                                const GtkTextIter       *end,
-                                                                                const gchar             
*category);
+void                    gtk_source_buffer_remove_source_marks                  (GtkSourceBuffer        
*buffer,
+                                                                                const GtkTextIter      
*start,
+                                                                                const GtkTextIter      *end,
+                                                                                const gchar            
*category);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-gboolean               gtk_source_buffer_iter_has_context_class                (GtkSourceBuffer         
*buffer,
-                                                                                const GtkTextIter       
*iter,
-                                                                                const gchar             
*context_class);
+gboolean                gtk_source_buffer_iter_has_context_class               (GtkSourceBuffer        
*buffer,
+                                                                                const GtkTextIter      *iter,
+                                                                                const gchar            
*context_class);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-gchar                **gtk_source_buffer_get_context_classes_at_iter           (GtkSourceBuffer         
*buffer,
-                                                                                const GtkTextIter       
*iter);
+gchar                 **gtk_source_buffer_get_context_classes_at_iter          (GtkSourceBuffer        
*buffer,
+                                                                                const GtkTextIter      
*iter);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-gboolean               gtk_source_buffer_iter_forward_to_context_class_toggle  (GtkSourceBuffer         
*buffer,
-                                                                                GtkTextIter             
*iter,
-                                                                                const gchar             
*context_class);
+gboolean                gtk_source_buffer_iter_forward_to_context_class_toggle (GtkSourceBuffer        
*buffer,
+                                                                                GtkTextIter            *iter,
+                                                                                const gchar            
*context_class);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-gboolean               gtk_source_buffer_iter_backward_to_context_class_toggle (GtkSourceBuffer         
*buffer,
-                                                                                GtkTextIter             
*iter,
-                                                                                const gchar             
*context_class);
+gboolean                gtk_source_buffer_iter_backward_to_context_class_toggle
+                                                                               (GtkSourceBuffer        
*buffer,
+                                                                                GtkTextIter            *iter,
+                                                                                const gchar            
*context_class);
+
 GTK_SOURCE_AVAILABLE_IN_3_12
-void                   gtk_source_buffer_change_case                           (GtkSourceBuffer         
*buffer,
-                                                                                GtkSourceChangeCaseType  
case_type,
-                                                                                GtkTextIter             
*start,
-                                                                                GtkTextIter             
*end);
+void                    gtk_source_buffer_change_case                          (GtkSourceBuffer        
*buffer,
+                                                                                GtkSourceChangeCaseType 
case_type,
+                                                                                GtkTextIter            
*start,
+                                                                                GtkTextIter            *end);
+
 GTK_SOURCE_AVAILABLE_IN_3_16
-void                   gtk_source_buffer_join_lines                            (GtkSourceBuffer         
*buffer,
-                                                                                GtkTextIter             
*start,
-                                                                                GtkTextIter             
*end);
+void                    gtk_source_buffer_join_lines                           (GtkSourceBuffer        
*buffer,
+                                                                                GtkTextIter            
*start,
+                                                                                GtkTextIter            *end);
+
 GTK_SOURCE_AVAILABLE_IN_3_18
-void                   gtk_source_buffer_sort_lines                            (GtkSourceBuffer         
*buffer,
-                                                                                GtkTextIter             
*start,
-                                                                                GtkTextIter             *end,
-                                                                                GtkSourceSortFlags       
flags,
-                                                                                gint                     
column);
-GTK_SOURCE_AVAILABLE_IN_ALL
-GtkSourceUndoManager  *gtk_source_buffer_get_undo_manager                      (GtkSourceBuffer         
*buffer);
-GTK_SOURCE_AVAILABLE_IN_ALL
-void                   gtk_source_buffer_set_undo_manager                      (GtkSourceBuffer         
*buffer,
-                                                                                GtkSourceUndoManager    
*manager);
+void                    gtk_source_buffer_sort_lines                           (GtkSourceBuffer        
*buffer,
+                                                                                GtkTextIter            
*start,
+                                                                                GtkTextIter            *end,
+                                                                                GtkSourceSortFlags     flags,
+                                                                                gint                   
column);
+
 GTK_SOURCE_AVAILABLE_IN_3_14
-void                   gtk_source_buffer_set_implicit_trailing_newline         (GtkSourceBuffer         
*buffer,
-                                                                                gboolean                 
implicit_trailing_newline);
+void                    gtk_source_buffer_set_implicit_trailing_newline        (GtkSourceBuffer        
*buffer,
+                                                                                gboolean                
implicit_trailing_newline);
+
 GTK_SOURCE_AVAILABLE_IN_3_14
-gboolean               gtk_source_buffer_get_implicit_trailing_newline         (GtkSourceBuffer         
*buffer);
-GTK_SOURCE_AVAILABLE_IN_ALL
-GtkTextTag            *gtk_source_buffer_create_source_tag                     (GtkSourceBuffer         
*buffer,
-                                                                                const gchar             
*tag_name,
-                                                                                const gchar             
*first_property_name,
-                                                                                ...);
+gboolean                gtk_source_buffer_get_implicit_trailing_newline        (GtkSourceBuffer        
*buffer);
 
+GTK_SOURCE_AVAILABLE_IN_ALL
+GtkTextTag             *gtk_source_buffer_create_source_tag                    (GtkSourceBuffer        
*buffer,
+                                                                                const gchar            
*tag_name,
+                                                                                const gchar            
*first_property_name,
+                                                                                ...);
 
 G_END_DECLS
+
+#endif /* GTK_SOURCE_BUFFER_H */
diff --git a/gtksourceview/gtksourcebufferinputstream-private.h 
b/gtksourceview/gtksourcebufferinputstream-private.h
index 571c947e..0ed13e30 100644
--- a/gtksourceview/gtksourcebufferinputstream-private.h
+++ b/gtksourceview/gtksourcebufferinputstream-private.h
@@ -2,8 +2,8 @@
 /*
  * This file is part of GtkSourceView
  *
- * Copyright 2010 - Ignacio Casal Quinteiro
- * Copyright 2014 - Sébastien Wilmet <swilmet gnome org>
+ * Copyright (C) 2010 - Ignacio Casal Quinteiro
+ * Copyright (C) 2014 - Sébastien Wilmet <swilmet gnome org>
  *
  * GtkSourceView is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -19,7 +19,8 @@
  * along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#pragma once
+#ifndef GTK_SOURCE_BUFFER_INPUT_STREAM_PRIVATE_H
+#define GTK_SOURCE_BUFFER_INPUT_STREAM_PRIVATE_H
 
 #include <gio/gio.h>
 #include <gtk/gtk.h>
@@ -30,18 +31,43 @@
 
 G_BEGIN_DECLS
 
-#define GTK_SOURCE_TYPE_BUFFER_INPUT_STREAM (_gtk_source_buffer_input_stream_get_type())
+#define GTK_SOURCE_TYPE_BUFFER_INPUT_STREAM            (_gtk_source_buffer_input_stream_get_type ())
+#define GTK_SOURCE_BUFFER_INPUT_STREAM(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), 
GTK_SOURCE_TYPE_BUFFER_INPUT_STREAM, GtkSourceBufferInputStream))
+#define GTK_SOURCE_BUFFER_INPUT_STREAM_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), 
GTK_SOURCE_TYPE_BUFFER_INPUT_STREAM, GtkSourceBufferInputStreamClass))
+#define GTK_SOURCE_IS_BUFFER_INPUT_STREAM(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), 
GTK_SOURCE_TYPE_BUFFER_INPUT_STREAM))
+#define GTK_SOURCE_IS_BUFFER_INPUT_STREAM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), 
GTK_SOURCE_TYPE_BUFFER_INPUT_STREAM))
+#define GTK_SOURCE_BUFFER_INPUT_STREAM_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), 
GTK_SOURCE_TYPE_BUFFER_INPUT_STREAM, GtkSourceBufferInputStreamClass))
+
+typedef struct _GtkSourceBufferInputStreamClass                GtkSourceBufferInputStreamClass;
+typedef struct _GtkSourceBufferInputStreamPrivate      GtkSourceBufferInputStreamPrivate;
+
+struct _GtkSourceBufferInputStream
+{
+       GInputStream parent;
+
+       GtkSourceBufferInputStreamPrivate *priv;
+};
+
+struct _GtkSourceBufferInputStreamClass
+{
+       GInputStreamClass parent_class;
+};
 
 GTK_SOURCE_INTERNAL
-G_DECLARE_FINAL_TYPE (GtkSourceBufferInputStream, _gtk_source_buffer_input_stream, GTK_SOURCE, 
BUFFER_INPUT_STREAM, GInputStream)
+GType           _gtk_source_buffer_input_stream_get_type               (void) G_GNUC_CONST;
 
 GTK_SOURCE_INTERNAL
-GtkSourceBufferInputStream *_gtk_source_buffer_input_stream_new            (GtkTextBuffer              
*buffer,
-                                                                            GtkSourceNewlineType        type,
-                                                                            gboolean                    
add_trailing_newline);
+GtkSourceBufferInputStream
+               *_gtk_source_buffer_input_stream_new                    (GtkTextBuffer              *buffer,
+                                                                        GtkSourceNewlineType        type,
+                                                                        gboolean                    
add_trailing_newline);
+
 GTK_SOURCE_INTERNAL
-gsize                       _gtk_source_buffer_input_stream_get_total_size (GtkSourceBufferInputStream 
*stream);
+gsize           _gtk_source_buffer_input_stream_get_total_size         (GtkSourceBufferInputStream *stream);
+
 GTK_SOURCE_INTERNAL
-gsize                       _gtk_source_buffer_input_stream_tell           (GtkSourceBufferInputStream 
*stream);
+gsize           _gtk_source_buffer_input_stream_tell                   (GtkSourceBufferInputStream *stream);
 
 G_END_DECLS
+
+#endif /* GTK_SOURCE_BUFFER_INPUT_STREAM_PRIVATE_H */
diff --git a/gtksourceview/gtksourcebufferinputstream.c b/gtksourceview/gtksourcebufferinputstream.c
index a8d9be86..18af2817 100644
--- a/gtksourceview/gtksourcebufferinputstream.c
+++ b/gtksourceview/gtksourcebufferinputstream.c
@@ -2,8 +2,8 @@
 /*
  * This file is part of GtkSourceView
  *
- * Copyright 2010 - Ignacio Casal Quinteiro
- * Copyright 2014 - Sébastien Wilmet <swilmet gnome org>
+ * Copyright (C) 2010 - Ignacio Casal Quinteiro
+ * Copyright (C) 2014 - Sébastien Wilmet <swilmet gnome org>
  *
  * GtkSourceView is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -19,7 +19,9 @@
  * along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "config.h"
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
 
 #include <glib.h>
 #include <gio/gio.h>
@@ -35,10 +37,8 @@
  * thread.
  */
 
-struct _GtkSourceBufferInputStream
+struct _GtkSourceBufferInputStreamPrivate
 {
-       GInputStream parent_instance;
-
        GtkTextBuffer *buffer;
        GtkTextMark *pos;
        gint bytes_partial;
@@ -58,12 +58,12 @@ enum
        PROP_ADD_TRAILING_NEWLINE
 };
 
-G_DEFINE_TYPE (GtkSourceBufferInputStream, _gtk_source_buffer_input_stream, G_TYPE_INPUT_STREAM)
+G_DEFINE_TYPE_WITH_PRIVATE (GtkSourceBufferInputStream, _gtk_source_buffer_input_stream, 
G_TYPE_INPUT_STREAM);
 
 static gsize
 get_new_line_size (GtkSourceBufferInputStream *stream)
 {
-       switch (stream->newline_type)
+       switch (stream->priv->newline_type)
        {
                case GTK_SOURCE_NEWLINE_TYPE_CR:
                case GTK_SOURCE_NEWLINE_TYPE_LF:
@@ -83,7 +83,7 @@ get_new_line_size (GtkSourceBufferInputStream *stream)
 static const gchar *
 get_new_line (GtkSourceBufferInputStream *stream)
 {
-       switch (stream->newline_type)
+       switch (stream->priv->newline_type)
        {
                case GTK_SOURCE_NEWLINE_TYPE_LF:
                        return "\n";
@@ -104,8 +104,8 @@ get_new_line (GtkSourceBufferInputStream *stream)
 
 static gsize
 read_line (GtkSourceBufferInputStream *stream,
-           gchar                      *outbuf,
-           gsize                       space_left)
+          gchar                      *outbuf,
+          gsize                       space_left)
 {
        GtkTextIter start, next, end;
        gchar *buf;
@@ -114,14 +114,14 @@ read_line (GtkSourceBufferInputStream *stream,
        const gchar *newline;
        gboolean is_last;
 
-       if (stream->buffer == NULL)
+       if (stream->priv->buffer == NULL)
        {
                return 0;
        }
 
-       gtk_text_buffer_get_iter_at_mark (stream->buffer,
+       gtk_text_buffer_get_iter_at_mark (stream->priv->buffer,
                                          &start,
-                                         stream->pos);
+                                         stream->priv->pos);
 
        if (gtk_text_iter_is_end (&start))
        {
@@ -143,7 +143,7 @@ read_line (GtkSourceBufferInputStream *stream,
 
        /* the bytes of a line includes also the newline, so with the
           offsets we remove the newline and we add the new newline size */
-       bytes = gtk_text_iter_get_bytes_in_line (&start) - stream->bytes_partial;
+       bytes = gtk_text_iter_get_bytes_in_line (&start) - stream->priv->bytes_partial;
 
        /* bytes_in_line includes the newlines, so we remove that assuming that
           they are single byte characters */
@@ -201,7 +201,7 @@ read_line (GtkSourceBufferInputStream *stream,
 
                /* Note: offset is one past what we wrote */
                gtk_text_iter_forward_chars (&start, char_offset);
-               stream->bytes_partial += written;
+               stream->priv->bytes_partial += written;
                read = written;
        }
        else
@@ -216,12 +216,12 @@ read_line (GtkSourceBufferInputStream *stream,
                }
 
                start = next;
-               stream->bytes_partial = 0;
+               stream->priv->bytes_partial = 0;
                read = bytes_to_write;
        }
 
-       gtk_text_buffer_move_mark (stream->buffer,
-                                  stream->pos,
+       gtk_text_buffer_move_mark (stream->priv->buffer,
+                                  stream->priv->pos,
                                   &start);
 
        g_free (buf);
@@ -230,10 +230,10 @@ read_line (GtkSourceBufferInputStream *stream,
 
 static gssize
 _gtk_source_buffer_input_stream_read (GInputStream  *input_stream,
-                                      void          *buffer,
-                                      gsize          count,
-                                      GCancellable  *cancellable,
-                                      GError       **error)
+                                     void          *buffer,
+                                     gsize          count,
+                                     GCancellable  *cancellable,
+                                     GError       **error)
 {
        GtkSourceBufferInputStream *stream;
        GtkTextIter iter;
@@ -253,21 +253,21 @@ _gtk_source_buffer_input_stream_read (GInputStream  *input_stream,
                return -1;
        }
 
-       if (stream->buffer == NULL)
+       if (stream->priv->buffer == NULL)
        {
                return 0;
        }
 
        /* Initialize the mark to the first char in the text buffer */
-       if (!stream->is_initialized)
+       if (!stream->priv->is_initialized)
        {
-               gtk_text_buffer_get_start_iter (stream->buffer, &iter);
-               stream->pos = gtk_text_buffer_create_mark (stream->buffer,
+               gtk_text_buffer_get_start_iter (stream->priv->buffer, &iter);
+               stream->priv->pos = gtk_text_buffer_create_mark (stream->priv->buffer,
                                                                 NULL,
                                                                 &iter,
                                                                 FALSE);
 
-               stream->is_initialized = TRUE;
+               stream->priv->is_initialized = TRUE;
        }
 
        space_left = count;
@@ -278,24 +278,24 @@ _gtk_source_buffer_input_stream_read (GInputStream  *input_stream,
                n = read_line (stream, (gchar *)buffer + read, space_left);
                read += n;
                space_left -= n;
-       } while (space_left > 0 && n != 0 && stream->bytes_partial == 0);
+       } while (space_left > 0 && n != 0 && stream->priv->bytes_partial == 0);
 
        /* Make sure that non-empty files are always terminated with \n (see bug #95676).
         * Note that we strip the trailing \n when loading the file */
-       gtk_text_buffer_get_iter_at_mark (stream->buffer,
+       gtk_text_buffer_get_iter_at_mark (stream->priv->buffer,
                                          &iter,
-                                         stream->pos);
+                                         stream->priv->pos);
 
        if (gtk_text_iter_is_end (&iter) &&
            !gtk_text_iter_is_start (&iter) &&
-           stream->add_trailing_newline)
+           stream->priv->add_trailing_newline)
        {
                gssize newline_size;
 
                newline_size = get_new_line_size (stream);
 
                if (space_left >= newline_size &&
-                   !stream->newline_added)
+                   !stream->priv->newline_added)
                {
                        const gchar *newline;
 
@@ -304,7 +304,7 @@ _gtk_source_buffer_input_stream_read (GInputStream  *input_stream,
                        memcpy ((gchar *)buffer + read, newline, newline_size);
 
                        read += newline_size;
-                       stream->newline_added = TRUE;
+                       stream->priv->newline_added = TRUE;
                }
        }
 
@@ -313,17 +313,17 @@ _gtk_source_buffer_input_stream_read (GInputStream  *input_stream,
 
 static gboolean
 _gtk_source_buffer_input_stream_close (GInputStream  *input_stream,
-                                       GCancellable  *cancellable,
-                                       GError       **error)
+                                      GCancellable  *cancellable,
+                                      GError       **error)
 {
        GtkSourceBufferInputStream *stream = GTK_SOURCE_BUFFER_INPUT_STREAM (input_stream);
 
-       stream->newline_added = FALSE;
+       stream->priv->newline_added = FALSE;
 
-       if (stream->is_initialized &&
-           stream->buffer != NULL)
+       if (stream->priv->is_initialized &&
+           stream->priv->buffer != NULL)
        {
-               gtk_text_buffer_delete_mark (stream->buffer, stream->pos);
+               gtk_text_buffer_delete_mark (stream->priv->buffer, stream->priv->pos);
        }
 
        return TRUE;
@@ -331,25 +331,25 @@ _gtk_source_buffer_input_stream_close (GInputStream  *input_stream,
 
 static void
 _gtk_source_buffer_input_stream_set_property (GObject      *object,
-                                              guint         prop_id,
-                                              const GValue *value,
-                                              GParamSpec   *pspec)
+                                             guint         prop_id,
+                                             const GValue *value,
+                                             GParamSpec   *pspec)
 {
        GtkSourceBufferInputStream *stream = GTK_SOURCE_BUFFER_INPUT_STREAM (object);
 
        switch (prop_id)
        {
                case PROP_BUFFER:
-                       g_assert (stream->buffer == NULL);
-                       stream->buffer = g_value_dup_object (value);
+                       g_assert (stream->priv->buffer == NULL);
+                       stream->priv->buffer = g_value_dup_object (value);
                        break;
 
                case PROP_NEWLINE_TYPE:
-                       stream->newline_type = g_value_get_enum (value);
+                       stream->priv->newline_type = g_value_get_enum (value);
                        break;
 
                case PROP_ADD_TRAILING_NEWLINE:
-                       stream->add_trailing_newline = g_value_get_boolean (value);
+                       stream->priv->add_trailing_newline = g_value_get_boolean (value);
                        break;
 
                default:
@@ -360,24 +360,24 @@ _gtk_source_buffer_input_stream_set_property (GObject      *object,
 
 static void
 _gtk_source_buffer_input_stream_get_property (GObject    *object,
-                                              guint       prop_id,
-                                              GValue     *value,
-                                              GParamSpec *pspec)
+                                         guint       prop_id,
+                                         GValue     *value,
+                                         GParamSpec *pspec)
 {
        GtkSourceBufferInputStream *stream = GTK_SOURCE_BUFFER_INPUT_STREAM (object);
 
        switch (prop_id)
        {
                case PROP_BUFFER:
-                       g_value_set_object (value, stream->buffer);
+                       g_value_set_object (value, stream->priv->buffer);
                        break;
 
                case PROP_NEWLINE_TYPE:
-                       g_value_set_enum (value, stream->newline_type);
+                       g_value_set_enum (value, stream->priv->newline_type);
                        break;
 
                case PROP_ADD_TRAILING_NEWLINE:
-                       g_value_set_boolean (value, stream->add_trailing_newline);
+                       g_value_set_boolean (value, stream->priv->add_trailing_newline);
                        break;
 
                default:
@@ -391,7 +391,7 @@ _gtk_source_buffer_input_stream_dispose (GObject *object)
 {
        GtkSourceBufferInputStream *stream = GTK_SOURCE_BUFFER_INPUT_STREAM (object);
 
-       g_clear_object (&stream->buffer);
+       g_clear_object (&stream->priv->buffer);
 
        G_OBJECT_CLASS (_gtk_source_buffer_input_stream_parent_class)->dispose (object);
 }
@@ -456,7 +456,7 @@ _gtk_source_buffer_input_stream_class_init (GtkSourceBufferInputStreamClass *kla
 static void
 _gtk_source_buffer_input_stream_init (GtkSourceBufferInputStream *stream)
 {
-       stream = _gtk_source_buffer_input_stream_get_instance_private (stream);
+       stream->priv = _gtk_source_buffer_input_stream_get_instance_private (stream);
 }
 
 /**
@@ -469,8 +469,8 @@ _gtk_source_buffer_input_stream_init (GtkSourceBufferInputStream *stream)
  */
 GtkSourceBufferInputStream *
 _gtk_source_buffer_input_stream_new (GtkTextBuffer        *buffer,
-                                     GtkSourceNewlineType  type,
-                                     gboolean              add_trailing_newline)
+                                    GtkSourceNewlineType  type,
+                                    gboolean              add_trailing_newline)
 {
        g_return_val_if_fail (GTK_IS_TEXT_BUFFER (buffer), NULL);
 
@@ -486,12 +486,12 @@ _gtk_source_buffer_input_stream_get_total_size (GtkSourceBufferInputStream *stre
 {
        g_return_val_if_fail (GTK_SOURCE_IS_BUFFER_INPUT_STREAM (stream), 0);
 
-       if (stream->buffer == NULL)
+       if (stream->priv->buffer == NULL)
        {
                return 0;
        }
 
-       return gtk_text_buffer_get_char_count (stream->buffer);
+       return gtk_text_buffer_get_char_count (stream->priv->buffer);
 }
 
 gsize
@@ -502,8 +502,8 @@ _gtk_source_buffer_input_stream_tell (GtkSourceBufferInputStream *stream)
        /* FIXME: is this potentially inefficient? If yes, we could keep
           track of the offset internally, assuming the mark doesn't move
           during the operation */
-       if (!stream->is_initialized ||
-           stream->buffer == NULL)
+       if (!stream->priv->is_initialized ||
+           stream->priv->buffer == NULL)
        {
                return 0;
        }
@@ -511,9 +511,9 @@ _gtk_source_buffer_input_stream_tell (GtkSourceBufferInputStream *stream)
        {
                GtkTextIter iter;
 
-               gtk_text_buffer_get_iter_at_mark (stream->buffer,
+               gtk_text_buffer_get_iter_at_mark (stream->priv->buffer,
                                                  &iter,
-                                                 stream->pos);
+                                                 stream->priv->pos);
                return gtk_text_iter_get_offset (&iter);
        }
 }
diff --git a/gtksourceview/gtksourcebufferinternal-private.h b/gtksourceview/gtksourcebufferinternal-private.h
index cf6e3759..f6715803 100644
--- a/gtksourceview/gtksourcebufferinternal-private.h
+++ b/gtksourceview/gtksourcebufferinternal-private.h
@@ -2,7 +2,7 @@
 /*
  * This file is part of GtkSourceView
  *
- * Copyright 2016 - Sébastien Wilmet <swilmet gnome org>
+ * Copyright (C) 2016 - Sébastien Wilmet <swilmet gnome org>
  *
  * GtkSourceView is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -18,23 +18,29 @@
  * along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#pragma once
+#ifndef GTK_SOURCE_BUFFER_INTERNAL_PRIVATE_H
+#define GTK_SOURCE_BUFFER_INTERNAL_PRIVATE_H
 
 #include <glib-object.h>
+
 #include "gtksourcetypes.h"
 #include "gtksourcetypes-private.h"
 
 G_BEGIN_DECLS
 
-#define GTK_SOURCE_TYPE_BUFFER_INTERNAL (_gtk_source_buffer_internal_get_type())
+#define GTK_SOURCE_TYPE_BUFFER_INTERNAL (_gtk_source_buffer_internal_get_type ())
 
 G_GNUC_INTERNAL
 G_DECLARE_FINAL_TYPE (GtkSourceBufferInternal, _gtk_source_buffer_internal, GTK_SOURCE, BUFFER_INTERNAL, 
GObject)
 
 G_GNUC_INTERNAL
-GtkSourceBufferInternal *_gtk_source_buffer_internal_get_from_buffer   (GtkSourceBuffer         *buffer);
+GtkSourceBufferInternal *
+               _gtk_source_buffer_internal_get_from_buffer             (GtkSourceBuffer *buffer);
+
 G_GNUC_INTERNAL
-void                     _gtk_source_buffer_internal_emit_search_start (GtkSourceBufferInternal 
*buffer_internal,
-                                                                        GtkSourceSearchContext  
*search_context);
+void           _gtk_source_buffer_internal_emit_search_start           (GtkSourceBufferInternal 
*buffer_internal,
+                                                                        GtkSourceSearchContext  
*search_context);
 
 G_END_DECLS
+
+#endif /* GTK_SOURCE_BUFFER_INTERNAL_PRIVATE_H */
diff --git a/gtksourceview/gtksourcebufferinternal.c b/gtksourceview/gtksourcebufferinternal.c
index 2361de8b..05157c18 100644
--- a/gtksourceview/gtksourcebufferinternal.c
+++ b/gtksourceview/gtksourcebufferinternal.c
@@ -2,7 +2,7 @@
 /*
  * This file is part of GtkSourceView
  *
- * Copyright 2016 - Sébastien Wilmet <swilmet gnome org>
+ * Copyright (C) 2016 - Sébastien Wilmet <swilmet gnome org>
  *
  * GtkSourceView is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -18,7 +18,9 @@
  * along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "config.h"
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
 
 #include "gtksourcebufferinternal-private.h"
 #include "gtksourcebuffer.h"
@@ -111,7 +113,7 @@ _gtk_source_buffer_internal_get_from_buffer (GtkSourceBuffer *buffer)
 
 void
 _gtk_source_buffer_internal_emit_search_start (GtkSourceBufferInternal *buffer_internal,
-                                               GtkSourceSearchContext  *search_context)
+                                              GtkSourceSearchContext  *search_context)
 {
        g_return_if_fail (GTK_SOURCE_IS_BUFFER_INTERNAL (buffer_internal));
        g_return_if_fail (GTK_SOURCE_IS_SEARCH_CONTEXT (search_context));
diff --git a/gtksourceview/gtksourcebufferoutputstream-private.h 
b/gtksourceview/gtksourcebufferoutputstream-private.h
index b723fa0c..b8f8a0b3 100644
--- a/gtksourceview/gtksourcebufferoutputstream-private.h
+++ b/gtksourceview/gtksourcebufferoutputstream-private.h
@@ -2,8 +2,8 @@
 /*
  * This file is part of GtkSourceView
  *
- * Copyright 2010 - Ignacio Casal Quinteiro
- * Copyright 2014 - Sébastien Wilmet <swilmet gnome org>
+ * Copyright (C) 2010 - Ignacio Casal Quinteiro
+ * Copyright (C) 2014 - Sébastien Wilmet <swilmet gnome org>
  *
  * GtkSourceView is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -19,7 +19,8 @@
  * along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#pragma once
+#ifndef GTK_SOURCE_BUFFER_OUTPUT_STREAM_PRIVATE_H
+#define GTK_SOURCE_BUFFER_OUTPUT_STREAM_PRIVATE_H
 
 #include <gtk/gtk.h>
 
@@ -30,20 +31,48 @@
 
 G_BEGIN_DECLS
 
-#define GTK_SOURCE_TYPE_BUFFER_OUTPUT_STREAM (gtk_source_buffer_output_stream_get_type())
+#define GTK_SOURCE_TYPE_BUFFER_OUTPUT_STREAM           (gtk_source_buffer_output_stream_get_type ())
+#define GTK_SOURCE_BUFFER_OUTPUT_STREAM(obj)           (G_TYPE_CHECK_INSTANCE_CAST ((obj), 
GTK_SOURCE_TYPE_BUFFER_OUTPUT_STREAM, GtkSourceBufferOutputStream))
+#define GTK_SOURCE_BUFFER_OUTPUT_STREAM_CLASS(klass)   (G_TYPE_CHECK_CLASS_CAST ((klass), 
GTK_SOURCE_TYPE_BUFFER_OUTPUT_STREAM, GtkSourceBufferOutputStreamClass))
+#define GTK_SOURCE_IS_BUFFER_OUTPUT_STREAM(obj)                (G_TYPE_CHECK_INSTANCE_TYPE ((obj), 
GTK_SOURCE_TYPE_BUFFER_OUTPUT_STREAM))
+#define GTK_SOURCE_IS_BUFFER_OUTPUT_STREAM_CLASS(klass)        (G_TYPE_CHECK_CLASS_TYPE ((klass), 
GTK_SOURCE_TYPE_BUFFER_OUTPUT_STREAM))
+#define GTK_SOURCE_BUFFER_OUTPUT_STREAM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), 
GTK_SOURCE_TYPE_BUFFER_OUTPUT_STREAM, GtkSourceBufferOutputStreamClass))
+
+typedef struct _GtkSourceBufferOutputStreamClass       GtkSourceBufferOutputStreamClass;
+typedef struct _GtkSourceBufferOutputStreamPrivate     GtkSourceBufferOutputStreamPrivate;
+
+struct _GtkSourceBufferOutputStream
+{
+       GOutputStream parent;
+
+       GtkSourceBufferOutputStreamPrivate *priv;
+};
+
+struct _GtkSourceBufferOutputStreamClass
+{
+       GOutputStreamClass parent_class;
+};
 
 GTK_SOURCE_INTERNAL
-G_DECLARE_FINAL_TYPE (GtkSourceBufferOutputStream, gtk_source_buffer_output_stream, GTK_SOURCE, 
BUFFER_OUTPUT_STREAM, GOutputStream)
+GType                   gtk_source_buffer_output_stream_get_type       (void) G_GNUC_CONST;
 
 GTK_SOURCE_INTERNAL
-GtkSourceBufferOutputStream *gtk_source_buffer_output_stream_new                 (GtkSourceBuffer            
 *buffer,
-                                                                                  GSList                     
 *candidate_encodings,
-                                                                                  gboolean                   
  remove_trailing_newline);
+GtkSourceBufferOutputStream
+                       *gtk_source_buffer_output_stream_new            (GtkSourceBuffer             *buffer,
+                                                                        GSList                      
*candidate_encodings,
+                                                                        gboolean                     
remove_trailing_newline);
+
 GTK_SOURCE_INTERNAL
-GtkSourceNewlineType         gtk_source_buffer_output_stream_detect_newline_type 
(GtkSourceBufferOutputStream *stream);
+GtkSourceNewlineType    gtk_source_buffer_output_stream_detect_newline_type
+                                                                       (GtkSourceBufferOutputStream *stream);
+
 GTK_SOURCE_INTERNAL
-const GtkSourceEncoding     *gtk_source_buffer_output_stream_get_guessed         
(GtkSourceBufferOutputStream *stream);
+const GtkSourceEncoding        *gtk_source_buffer_output_stream_get_guessed    (GtkSourceBufferOutputStream 
*stream);
+
 GTK_SOURCE_INTERNAL
-guint                        gtk_source_buffer_output_stream_get_num_fallbacks   
(GtkSourceBufferOutputStream *stream);
+guint                   gtk_source_buffer_output_stream_get_num_fallbacks
+                                                                       (GtkSourceBufferOutputStream *stream);
 
 G_END_DECLS
+
+#endif /* GTK_SOURCE_BUFFER_OUTPUT_STREAM_PRIVATE_H */
diff --git a/gtksourceview/gtksourcebufferoutputstream.c b/gtksourceview/gtksourcebufferoutputstream.c
index ab41c2b5..a9ac6e2e 100644
--- a/gtksourceview/gtksourcebufferoutputstream.c
+++ b/gtksourceview/gtksourcebufferoutputstream.c
@@ -2,8 +2,8 @@
 /*
  * This file is part of GtkSourceView
  *
- * Copyright 2010 - Ignacio Casal Quinteiro
- * Copyright 2014 - Sébastien Wilmet <swilmet gnome org>
+ * Copyright (C) 2010 - Ignacio Casal Quinteiro
+ * Copyright (C) 2014 - Sébastien Wilmet <swilmet gnome org>
  *
  * GtkSourceView is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -19,14 +19,15 @@
  * along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "config.h"
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
 
-#include <string.h>
-#include <errno.h>
 #include <glib/gi18n-lib.h>
+#include <errno.h>
+#include <string.h>
 
 #include "gtksourcebufferoutputstream-private.h"
-#include "gtksourcebuffer.h"
 #include "gtksourcebuffer-private.h"
 #include "gtksourceencoding.h"
 #include "gtksourcefileloader.h"
@@ -56,10 +57,8 @@
 
 #define MAX_UNICHAR_LEN 6
 
-struct _GtkSourceBufferOutputStream
+struct _GtkSourceBufferOutputStreamPrivate
 {
-       GOutputStream parent_instance;
-
        GtkSourceBuffer *source_buffer;
        GtkTextIter pos;
 
@@ -95,37 +94,39 @@ enum
        PROP_REMOVE_TRAILING_NEWLINE
 };
 
-G_DEFINE_TYPE (GtkSourceBufferOutputStream, gtk_source_buffer_output_stream, G_TYPE_OUTPUT_STREAM)
+G_DEFINE_TYPE_WITH_PRIVATE (GtkSourceBufferOutputStream, gtk_source_buffer_output_stream, 
G_TYPE_OUTPUT_STREAM)
+
+static gssize gtk_source_buffer_output_stream_write   (GOutputStream  *stream,
+                                                      const void     *buffer,
+                                                      gsize           count,
+                                                      GCancellable   *cancellable,
+                                                      GError        **error);
 
-static gssize   gtk_source_buffer_output_stream_write (GOutputStream  *stream,
-                                                       const void     *buffer,
-                                                       gsize           count,
-                                                       GCancellable   *cancellable,
-                                                       GError        **error);
 static gboolean gtk_source_buffer_output_stream_close (GOutputStream  *stream,
-                                                       GCancellable   *cancellable,
-                                                       GError        **error);
+                                                      GCancellable   *cancellable,
+                                                      GError        **error);
+
 static gboolean gtk_source_buffer_output_stream_flush (GOutputStream  *stream,
-                                                       GCancellable   *cancellable,
-                                                       GError        **error);
+                                                      GCancellable   *cancellable,
+                                                      GError        **error);
 
 static void
 gtk_source_buffer_output_stream_set_property (GObject      *object,
-                                              guint         prop_id,
-                                              const GValue *value,
-                                              GParamSpec   *pspec)
+                                             guint         prop_id,
+                                             const GValue *value,
+                                             GParamSpec   *pspec)
 {
        GtkSourceBufferOutputStream *stream = GTK_SOURCE_BUFFER_OUTPUT_STREAM (object);
 
        switch (prop_id)
        {
                case PROP_BUFFER:
-                       g_assert (stream->source_buffer == NULL);
-                       stream->source_buffer = g_value_dup_object (value);
+                       g_assert (stream->priv->source_buffer == NULL);
+                       stream->priv->source_buffer = g_value_dup_object (value);
                        break;
 
                case PROP_REMOVE_TRAILING_NEWLINE:
-                       stream->remove_trailing_newline = g_value_get_boolean (value);
+                       stream->priv->remove_trailing_newline = g_value_get_boolean (value);
                        break;
 
                default:
@@ -136,20 +137,20 @@ gtk_source_buffer_output_stream_set_property (GObject      *object,
 
 static void
 gtk_source_buffer_output_stream_get_property (GObject    *object,
-                                              guint       prop_id,
-                                              GValue     *value,
-                                              GParamSpec *pspec)
+                                             guint       prop_id,
+                                             GValue     *value,
+                                             GParamSpec *pspec)
 {
        GtkSourceBufferOutputStream *stream = GTK_SOURCE_BUFFER_OUTPUT_STREAM (object);
 
        switch (prop_id)
        {
                case PROP_BUFFER:
-                       g_value_set_object (value, stream->source_buffer);
+                       g_value_set_object (value, stream->priv->source_buffer);
                        break;
 
                case PROP_REMOVE_TRAILING_NEWLINE:
-                       g_value_set_boolean (value, stream->remove_trailing_newline);
+                       g_value_set_boolean (value, stream->priv->remove_trailing_newline);
                        break;
 
                default:
@@ -163,8 +164,8 @@ gtk_source_buffer_output_stream_dispose (GObject *object)
 {
        GtkSourceBufferOutputStream *stream = GTK_SOURCE_BUFFER_OUTPUT_STREAM (object);
 
-       g_clear_object (&stream->source_buffer);
-       g_clear_object (&stream->charset_conv);
+       g_clear_object (&stream->priv->source_buffer);
+       g_clear_object (&stream->priv->charset_conv);
 
        G_OBJECT_CLASS (gtk_source_buffer_output_stream_parent_class)->dispose (object);
 }
@@ -174,9 +175,9 @@ gtk_source_buffer_output_stream_finalize (GObject *object)
 {
        GtkSourceBufferOutputStream *stream = GTK_SOURCE_BUFFER_OUTPUT_STREAM (object);
 
-       g_free (stream->buffer);
-       g_free (stream->iconv_buffer);
-       g_slist_free (stream->encodings);
+       g_free (stream->priv->buffer);
+       g_free (stream->priv->iconv_buffer);
+       g_slist_free (stream->priv->encodings);
 
        G_OBJECT_CLASS (gtk_source_buffer_output_stream_parent_class)->finalize (object);
 }
@@ -186,18 +187,18 @@ gtk_source_buffer_output_stream_constructed (GObject *object)
 {
        GtkSourceBufferOutputStream *stream = GTK_SOURCE_BUFFER_OUTPUT_STREAM (object);
 
-       if (stream->source_buffer == NULL)
+       if (stream->priv->source_buffer == NULL)
        {
                g_critical ("This should never happen, a problem happened constructing the Buffer Output 
Stream!");
                return;
        }
 
-       gtk_source_buffer_begin_not_undoable_action (stream->source_buffer);
+       gtk_text_buffer_begin_irreversible_action (GTK_TEXT_BUFFER (stream->priv->source_buffer));
 
-       gtk_text_buffer_set_text (GTK_TEXT_BUFFER (stream->source_buffer), "", 0);
-       gtk_text_buffer_set_modified (GTK_TEXT_BUFFER (stream->source_buffer), FALSE);
+       gtk_text_buffer_set_text (GTK_TEXT_BUFFER (stream->priv->source_buffer), "", 0);
+       gtk_text_buffer_set_modified (GTK_TEXT_BUFFER (stream->priv->source_buffer), FALSE);
 
-       gtk_source_buffer_end_not_undoable_action (stream->source_buffer);
+       gtk_text_buffer_end_irreversible_action (GTK_TEXT_BUFFER (stream->priv->source_buffer));
 
        G_OBJECT_CLASS (gtk_source_buffer_output_stream_parent_class)->constructed (object);
 }
@@ -242,42 +243,44 @@ gtk_source_buffer_output_stream_class_init (GtkSourceBufferOutputStreamClass *kl
 static void
 gtk_source_buffer_output_stream_init (GtkSourceBufferOutputStream *stream)
 {
-       stream->buffer = NULL;
-       stream->buflen = 0;
+       stream->priv = gtk_source_buffer_output_stream_get_instance_private (stream);
+
+       stream->priv->buffer = NULL;
+       stream->priv->buflen = 0;
 
-       stream->charset_conv = NULL;
-       stream->encodings = NULL;
-       stream->current_encoding = NULL;
+       stream->priv->charset_conv = NULL;
+       stream->priv->encodings = NULL;
+       stream->priv->current_encoding = NULL;
 
-       stream->error_offset = -1;
+       stream->priv->error_offset = -1;
 
-       stream->is_initialized = FALSE;
-       stream->is_closed = FALSE;
-       stream->is_utf8 = FALSE;
-       stream->use_first = FALSE;
+       stream->priv->is_initialized = FALSE;
+       stream->priv->is_closed = FALSE;
+       stream->priv->is_utf8 = FALSE;
+       stream->priv->use_first = FALSE;
 }
 
 static const GtkSourceEncoding *
 get_encoding (GtkSourceBufferOutputStream *stream)
 {
-       if (stream->current_encoding == NULL)
+       if (stream->priv->current_encoding == NULL)
        {
-               stream->current_encoding = stream->encodings;
+               stream->priv->current_encoding = stream->priv->encodings;
        }
        else
        {
-               stream->current_encoding = g_slist_next (stream->current_encoding);
+               stream->priv->current_encoding = g_slist_next (stream->priv->current_encoding);
        }
 
-       if (stream->current_encoding != NULL)
+       if (stream->priv->current_encoding != NULL)
        {
-               return stream->current_encoding->data;
+               return stream->priv->current_encoding->data;
        }
 
-       stream->use_first = TRUE;
-       stream->current_encoding = stream->encodings;
+       stream->priv->use_first = TRUE;
+       stream->priv->current_encoding = stream->priv->encodings;
 
-       return stream->current_encoding->data;
+       return stream->priv->current_encoding->data;
 }
 
 static gboolean
@@ -354,21 +357,21 @@ try_convert (GCharsetConverter *converter,
 
 static GCharsetConverter *
 guess_encoding (GtkSourceBufferOutputStream *stream,
-                const void                  *inbuf,
-                gsize                        inbuf_size)
+               const void                  *inbuf,
+               gsize                        inbuf_size)
 {
        GCharsetConverter *conv = NULL;
 
        if (inbuf == NULL || inbuf_size == 0)
        {
-               stream->is_utf8 = TRUE;
+               stream->priv->is_utf8 = TRUE;
                return NULL;
        }
 
-       if (stream->encodings != NULL &&
-           stream->encodings->next == NULL)
+       if (stream->priv->encodings != NULL &&
+           stream->priv->encodings->next == NULL)
        {
-               stream->use_first = TRUE;
+               stream->priv->use_first = TRUE;
        }
 
        /* We just check the first block */
@@ -389,7 +392,7 @@ guess_encoding (GtkSourceBufferOutputStream *stream,
 
                DEBUG ({
                       g_print ("trying charset: %s\n",
-                               gtk_source_encoding_get_charset (stream->current_encoding->data));
+                               gtk_source_encoding_get_charset (stream->priv->current_encoding->data));
                });
 
                if (enc == gtk_source_encoding_get_utf8 ())
@@ -398,9 +401,9 @@ guess_encoding (GtkSourceBufferOutputStream *stream,
                        const gchar *end;
 
                        if (g_utf8_validate (inbuf, inbuf_size, &end) ||
-                           stream->use_first)
+                           stream->priv->use_first)
                        {
-                               stream->is_utf8 = TRUE;
+                               stream->priv->is_utf8 = TRUE;
                                break;
                        }
 
@@ -408,7 +411,7 @@ guess_encoding (GtkSourceBufferOutputStream *stream,
                        remainder = inbuf_size - (end - (gchar *)inbuf);
                        if (remainder < 6)
                        {
-                               stream->is_utf8 = TRUE;
+                               stream->priv->is_utf8 = TRUE;
                                break;
                        }
 
@@ -420,7 +423,7 @@ guess_encoding (GtkSourceBufferOutputStream *stream,
                                                NULL);
 
                /* If we tried all encodings we use the first one */
-               if (stream->use_first)
+               if (stream->priv->use_first)
                {
                        break;
                }
@@ -472,8 +475,8 @@ get_newline_type (GtkTextIter *end)
 
 GtkSourceBufferOutputStream *
 gtk_source_buffer_output_stream_new (GtkSourceBuffer *buffer,
-                                     GSList          *candidate_encodings,
-                                     gboolean         remove_trailing_newline)
+                                    GSList          *candidate_encodings,
+                                    gboolean         remove_trailing_newline)
 {
        GtkSourceBufferOutputStream *stream;
 
@@ -482,7 +485,7 @@ gtk_source_buffer_output_stream_new (GtkSourceBuffer *buffer,
                               "remove-trailing-newline", remove_trailing_newline,
                               NULL);
 
-       stream->encodings = g_slist_copy (candidate_encodings);
+       stream->priv->encodings = g_slist_copy (candidate_encodings);
 
        return stream;
 }
@@ -496,14 +499,14 @@ gtk_source_buffer_output_stream_detect_newline_type (GtkSourceBufferOutputStream
        g_return_val_if_fail (GTK_SOURCE_IS_BUFFER_OUTPUT_STREAM (stream),
                              GTK_SOURCE_NEWLINE_TYPE_DEFAULT);
 
-       if (stream->source_buffer == NULL)
+       if (stream->priv->source_buffer == NULL)
        {
                return GTK_SOURCE_NEWLINE_TYPE_DEFAULT;
        }
 
        type = GTK_SOURCE_NEWLINE_TYPE_DEFAULT;
 
-       gtk_text_buffer_get_start_iter (GTK_TEXT_BUFFER (stream->source_buffer),
+       gtk_text_buffer_get_start_iter (GTK_TEXT_BUFFER (stream->priv->source_buffer),
                                        &iter);
 
        if (gtk_text_iter_ends_line (&iter) || gtk_text_iter_forward_to_line_end (&iter))
@@ -519,11 +522,11 @@ gtk_source_buffer_output_stream_get_guessed (GtkSourceBufferOutputStream *stream
 {
        g_return_val_if_fail (GTK_SOURCE_IS_BUFFER_OUTPUT_STREAM (stream), NULL);
 
-       if (stream->current_encoding != NULL)
+       if (stream->priv->current_encoding != NULL)
        {
-               return stream->current_encoding->data;
+               return stream->priv->current_encoding->data;
        }
-       else if (stream->is_utf8 || !stream->is_initialized)
+       else if (stream->priv->is_utf8 || !stream->priv->is_initialized)
        {
                /* If it is not initialized we assume that we are trying to
                 * convert the empty string.
@@ -539,7 +542,7 @@ gtk_source_buffer_output_stream_get_num_fallbacks (GtkSourceBufferOutputStream *
 {
        g_return_val_if_fail (GTK_SOURCE_IS_BUFFER_OUTPUT_STREAM (stream), 0);
 
-       return stream->n_fallback_errors;
+       return stream->priv->n_fallback_errors;
 }
 
 static void
@@ -547,31 +550,31 @@ apply_error_tag (GtkSourceBufferOutputStream *stream)
 {
        GtkTextIter start;
 
-       if (stream->error_offset == -1 ||
-           stream->source_buffer == NULL)
+       if (stream->priv->error_offset == -1 ||
+           stream->priv->source_buffer == NULL)
        {
                return;
        }
 
-       gtk_text_buffer_get_iter_at_offset (GTK_TEXT_BUFFER (stream->source_buffer),
-                                           &start, stream->error_offset);
+       gtk_text_buffer_get_iter_at_offset (GTK_TEXT_BUFFER (stream->priv->source_buffer),
+                                           &start, stream->priv->error_offset);
 
-       _gtk_source_buffer_set_as_invalid_character (stream->source_buffer,
+       _gtk_source_buffer_set_as_invalid_character (stream->priv->source_buffer,
                                                     &start,
-                                                    &stream->pos);
+                                                    &stream->priv->pos);
 
-       stream->error_offset = -1;
+       stream->priv->error_offset = -1;
 }
 
 static void
 insert_fallback (GtkSourceBufferOutputStream *stream,
-                 const gchar                 *buffer)
+                const gchar                 *buffer)
 {
        guint8 out[4];
        guint8 v;
        const gchar hex[] = "0123456789ABCDEF";
 
-       if (stream->source_buffer == NULL)
+       if (stream->priv->source_buffer == NULL)
        {
                return;
        }
@@ -585,30 +588,30 @@ insert_fallback (GtkSourceBufferOutputStream *stream,
        out[2] = hex[(v & 0x0f) >> 0];
        out[3] = '\0';
 
-       gtk_text_buffer_insert (GTK_TEXT_BUFFER (stream->source_buffer),
-                               &stream->pos, (const gchar *)out, 3);
+       gtk_text_buffer_insert (GTK_TEXT_BUFFER (stream->priv->source_buffer),
+                               &stream->priv->pos, (const gchar *)out, 3);
 
-       ++stream->n_fallback_errors;
+       ++stream->priv->n_fallback_errors;
 }
 
 static void
 validate_and_insert (GtkSourceBufferOutputStream *stream,
-                     gchar                       *buffer,
-                     gsize                        count,
-                     gboolean                     owned)
+                    gchar                       *buffer,
+                    gsize                        count,
+                    gboolean                     owned)
 {
        GtkTextBuffer *text_buffer;
        GtkTextIter *iter;
        gsize len;
        gchar *free_text = NULL;
 
-       if (stream->source_buffer == NULL)
+       if (stream->priv->source_buffer == NULL)
        {
                return;
        }
 
-       text_buffer = GTK_TEXT_BUFFER (stream->source_buffer);
-       iter = &stream->pos;
+       text_buffer = GTK_TEXT_BUFFER (stream->priv->source_buffer);
+       iter = &stream->priv->pos;
        len = count;
 
        while (len != 0)
@@ -634,10 +637,10 @@ validate_and_insert (GtkSourceBufferOutputStream *stream,
 
                        if (ptr && *ptr == '\r' && ptr - buffer == (glong)len - 1)
                        {
-                               stream->buffer = g_new (gchar, 2);
-                               stream->buffer[0] = '\r';
-                               stream->buffer[1] = '\0';
-                               stream->buflen = 1;
+                               stream->priv->buffer = g_new (gchar, 2);
+                               stream->priv->buffer[0] = '\r';
+                               stream->priv->buffer[1] = '\0';
+                               stream->priv->buflen = 1;
 
                                /* Decrease also the len so in the check
                                   nvalid == len we get out of this method */
@@ -698,16 +701,16 @@ validate_and_insert (GtkSourceBufferOutputStream *stream,
                if ((len < MAX_UNICHAR_LEN) &&
                    (g_utf8_get_char_validated (buffer, len) == (gunichar)-2))
                {
-                       stream->buffer = g_strndup (end, len);
-                       stream->buflen = len;
+                       stream->priv->buffer = g_strndup (end, len);
+                       stream->priv->buflen = len;
 
                        break;
                }
 
                /* we need the start of the chunk of invalid chars */
-               if (stream->error_offset == -1)
+               if (stream->priv->error_offset == -1)
                {
-                       stream->error_offset = gtk_text_iter_get_offset (&stream->pos);
+                       stream->priv->error_offset = gtk_text_iter_get_offset (&stream->priv->pos);
                }
 
                insert_fallback (stream, buffer);
@@ -724,12 +727,12 @@ remove_trailing_newline (GtkSourceBufferOutputStream *stream)
        GtkTextIter end;
        GtkTextIter start;
 
-       if (stream->source_buffer == NULL)
+       if (stream->priv->source_buffer == NULL)
        {
                return;
        }
 
-       gtk_text_buffer_get_end_iter (GTK_TEXT_BUFFER (stream->source_buffer), &end);
+       gtk_text_buffer_get_end_iter (GTK_TEXT_BUFFER (stream->priv->source_buffer), &end);
        start = end;
 
        gtk_text_iter_set_line_offset (&start, 0);
@@ -742,7 +745,7 @@ remove_trailing_newline (GtkSourceBufferOutputStream *stream)
                        gtk_text_iter_forward_to_line_end (&start);
                }
 
-               gtk_text_buffer_delete (GTK_TEXT_BUFFER (stream->source_buffer),
+               gtk_text_buffer_delete (GTK_TEXT_BUFFER (stream->priv->source_buffer),
                                        &start,
                                        &end);
        }
@@ -751,30 +754,30 @@ remove_trailing_newline (GtkSourceBufferOutputStream *stream)
 static void
 end_append_text_to_document (GtkSourceBufferOutputStream *stream)
 {
-       if (stream->source_buffer == NULL)
+       if (stream->priv->source_buffer == NULL)
        {
                return;
        }
 
-       if (stream->remove_trailing_newline)
+       if (stream->priv->remove_trailing_newline)
        {
                remove_trailing_newline (stream);
        }
 
-       gtk_text_buffer_set_modified (GTK_TEXT_BUFFER (stream->source_buffer),
+       gtk_text_buffer_set_modified (GTK_TEXT_BUFFER (stream->priv->source_buffer),
                                      FALSE);
 
-       gtk_text_buffer_end_user_action (GTK_TEXT_BUFFER (stream->source_buffer));
-       gtk_source_buffer_end_not_undoable_action (stream->source_buffer);
+       gtk_text_buffer_end_user_action (GTK_TEXT_BUFFER (stream->priv->source_buffer));
+       gtk_text_buffer_end_irreversible_action (GTK_TEXT_BUFFER (stream->priv->source_buffer));
 }
 
 static gboolean
 convert_text (GtkSourceBufferOutputStream  *stream,
-              const gchar                  *inbuf,
-              gsize                         inbuf_len,
-              gchar                       **outbuf,
-              gsize                        *outbuf_len,
-              GError                      **error)
+             const gchar                  *inbuf,
+             gsize                         inbuf_len,
+             gchar                       **outbuf,
+             gsize                        *outbuf_len,
+             GError                      **error)
 {
        gchar *out, *dest;
        gsize in_left, out_left, outbuf_size, res;
@@ -799,7 +802,7 @@ convert_text (GtkSourceBufferOutputStream  *stream,
                /* If we reached here is because we need to convert the text,
                   so we convert it using iconv.
                   See that if inbuf is NULL the data will be flushed */
-               res = g_iconv (stream->iconv,
+               res = g_iconv (stream->priv->iconv,
                               (gchar **)&inbuf, &in_left,
                               &out, &out_left);
 
@@ -812,8 +815,8 @@ convert_text (GtkSourceBufferOutputStream  *stream,
                        {
                                case EINVAL:
                                        /* Incomplete text, do not report an error */
-                                       stream->iconv_buffer = g_strndup (inbuf, in_left);
-                                       stream->iconv_buflen = in_left;
+                                       stream->priv->iconv_buffer = g_strndup (inbuf, in_left);
+                                       stream->priv->iconv_buflen = in_left;
                                        done = TRUE;
                                        break;
 
@@ -872,10 +875,10 @@ convert_text (GtkSourceBufferOutputStream  *stream,
 
 static gssize
 gtk_source_buffer_output_stream_write (GOutputStream  *stream,
-                                       const void     *buffer,
-                                       gsize           count,
-                                       GCancellable   *cancellable,
-                                       GError        **error)
+                                      const void     *buffer,
+                                      gsize           count,
+                                      GCancellable   *cancellable,
+                                      GError        **error)
 {
        GtkSourceBufferOutputStream *ostream;
        gchar *text;
@@ -885,19 +888,19 @@ gtk_source_buffer_output_stream_write (GOutputStream  *stream,
        ostream = GTK_SOURCE_BUFFER_OUTPUT_STREAM (stream);
 
        if (g_cancellable_set_error_if_cancelled (cancellable, error) ||
-           ostream->source_buffer == NULL)
+           ostream->priv->source_buffer == NULL)
        {
                return -1;
        }
 
-       if (!ostream->is_initialized)
+       if (!ostream->priv->is_initialized)
        {
-               ostream->charset_conv = guess_encoding (ostream, buffer, count);
+               ostream->priv->charset_conv = guess_encoding (ostream, buffer, count);
 
                /* If we still have the previous case is that we didn't guess
                   anything */
-               if (ostream->charset_conv == NULL &&
-                   !ostream->is_utf8)
+               if (ostream->priv->charset_conv == NULL &&
+                   !ostream->priv->is_utf8)
                {
                        g_set_error_literal (error, GTK_SOURCE_FILE_LOADER_ERROR,
                                             GTK_SOURCE_FILE_LOADER_ERROR_ENCODING_AUTO_DETECTION_FAILED,
@@ -907,18 +910,18 @@ gtk_source_buffer_output_stream_write (GOutputStream  *stream,
                }
 
                /* Do not initialize iconv if we are not going to convert anything */
-               if (!ostream->is_utf8)
+               if (!ostream->priv->is_utf8)
                {
                        gchar *from_charset;
 
                        /* Initialize iconv */
-                       g_object_get (G_OBJECT (ostream->charset_conv),
+                       g_object_get (G_OBJECT (ostream->priv->charset_conv),
                                      "from-charset", &from_charset,
                                      NULL);
 
-                       ostream->iconv = g_iconv_open ("UTF-8", from_charset);
+                       ostream->priv->iconv = g_iconv_open ("UTF-8", from_charset);
 
-                       if (ostream->iconv == (GIConv)-1)
+                       if (ostream->priv->iconv == (GIConv)-1)
                        {
                                if (errno == EINVAL)
                                {
@@ -934,7 +937,7 @@ gtk_source_buffer_output_stream_write (GOutputStream  *stream,
                                }
 
                                g_free (from_charset);
-                               g_clear_object (&ostream->charset_conv);
+                               g_clear_object (&ostream->priv->charset_conv);
 
                                return -1;
                        }
@@ -947,29 +950,29 @@ gtk_source_buffer_output_stream_write (GOutputStream  *stream,
                 * as only one action, for the features that rely on the user
                 * action.
                 */
-               gtk_source_buffer_begin_not_undoable_action (ostream->source_buffer);
-               gtk_text_buffer_begin_user_action (GTK_TEXT_BUFFER (ostream->source_buffer));
+               gtk_text_buffer_begin_irreversible_action (GTK_TEXT_BUFFER (ostream->priv->source_buffer));
+               gtk_text_buffer_begin_user_action (GTK_TEXT_BUFFER (ostream->priv->source_buffer));
 
-               gtk_text_buffer_get_start_iter (GTK_TEXT_BUFFER (ostream->source_buffer),
-                                               &ostream->pos);
+               gtk_text_buffer_get_start_iter (GTK_TEXT_BUFFER (ostream->priv->source_buffer),
+                                               &ostream->priv->pos);
 
-               ostream->is_initialized = TRUE;
+               ostream->priv->is_initialized = TRUE;
        }
 
-       if (ostream->buflen > 0)
+       if (ostream->priv->buflen > 0)
        {
-               len = ostream->buflen + count;
+               len = ostream->priv->buflen + count;
                text = g_malloc (len + 1);
 
-               memcpy (text, ostream->buffer, ostream->buflen);
-               memcpy (text + ostream->buflen, buffer, count);
+               memcpy (text, ostream->priv->buffer, ostream->priv->buflen);
+               memcpy (text + ostream->priv->buflen, buffer, count);
 
                text[len] = '\0';
 
-               g_free (ostream->buffer);
+               g_free (ostream->priv->buffer);
 
-               ostream->buffer = NULL;
-               ostream->buflen = 0;
+               ostream->priv->buffer = NULL;
+               ostream->priv->buflen = 0;
 
                freetext = TRUE;
        }
@@ -979,14 +982,14 @@ gtk_source_buffer_output_stream_write (GOutputStream  *stream,
                len = count;
        }
 
-       if (!ostream->is_utf8)
+       if (!ostream->priv->is_utf8)
        {
                gchar *outbuf;
                gsize outbuf_len;
 
                /* check if iconv was correctly initializated, this shouldn't
                   happen but better be safe */
-               if (ostream->iconv == NULL)
+               if (ostream->priv->iconv == NULL)
                {
                        g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_INITIALIZED,
                                             _("Invalid object, not initialized"));
@@ -1000,16 +1003,16 @@ gtk_source_buffer_output_stream_write (GOutputStream  *stream,
                }
 
                /* manage the previous conversion buffer */
-               if (ostream->iconv_buflen > 0)
+               if (ostream->priv->iconv_buflen > 0)
                {
                        gchar *text2;
                        gsize len2;
 
-                       len2 = len + ostream->iconv_buflen;
+                       len2 = len + ostream->priv->iconv_buflen;
                        text2 = g_malloc (len2 + 1);
 
-                       memcpy (text2, ostream->iconv_buffer, ostream->iconv_buflen);
-                       memcpy (text2 + ostream->iconv_buflen, text, len);
+                       memcpy (text2, ostream->priv->iconv_buffer, ostream->priv->iconv_buflen);
+                       memcpy (text2 + ostream->priv->iconv_buflen, text, len);
 
                        text2[len2] = '\0';
 
@@ -1021,10 +1024,10 @@ gtk_source_buffer_output_stream_write (GOutputStream  *stream,
                        text = text2;
                        len = len2;
 
-                       g_free (ostream->iconv_buffer);
+                       g_free (ostream->priv->iconv_buffer);
 
-                       ostream->iconv_buffer = NULL;
-                       ostream->iconv_buflen = 0;
+                       ostream->priv->iconv_buffer = NULL;
+                       ostream->priv->iconv_buflen = 0;
 
                        freetext = TRUE;
                }
@@ -1061,21 +1064,21 @@ gtk_source_buffer_output_stream_write (GOutputStream  *stream,
 
 static gboolean
 gtk_source_buffer_output_stream_flush (GOutputStream  *stream,
-                                       GCancellable   *cancellable,
-                                       GError        **error)
+                                      GCancellable   *cancellable,
+                                      GError        **error)
 {
        GtkSourceBufferOutputStream *ostream;
 
        ostream = GTK_SOURCE_BUFFER_OUTPUT_STREAM (stream);
 
-       if (ostream->is_closed ||
-           ostream->source_buffer == NULL)
+       if (ostream->priv->is_closed ||
+           ostream->priv->source_buffer == NULL)
        {
                return TRUE;
        }
 
        /* if we have converted something flush residual data, validate and insert */
-       if (ostream->iconv != NULL)
+       if (ostream->priv->iconv != NULL)
        {
                gchar *outbuf;
                gsize outbuf_len;
@@ -1091,65 +1094,65 @@ gtk_source_buffer_output_stream_flush (GOutputStream  *stream,
                }
        }
 
-       if (ostream->buflen > 0 && *ostream->buffer != '\r')
+       if (ostream->priv->buflen > 0 && *ostream->priv->buffer != '\r')
        {
                /* If we reached here is because the last insertion was a half
                   correct char, which has to be inserted as fallback */
                gchar *text;
 
-               if (ostream->error_offset == -1)
+               if (ostream->priv->error_offset == -1)
                {
-                       ostream->error_offset = gtk_text_iter_get_offset (&ostream->pos);
+                       ostream->priv->error_offset = gtk_text_iter_get_offset (&ostream->priv->pos);
                }
 
-               text = ostream->buffer;
-               while (ostream->buflen != 0)
+               text = ostream->priv->buffer;
+               while (ostream->priv->buflen != 0)
                {
                        insert_fallback (ostream, text);
                        ++text;
-                       --ostream->buflen;
+                       --ostream->priv->buflen;
                }
 
-               g_free (ostream->buffer);
-               ostream->buffer = NULL;
+               g_free (ostream->priv->buffer);
+               ostream->priv->buffer = NULL;
        }
-       else if (ostream->buflen == 1 && *ostream->buffer == '\r')
+       else if (ostream->priv->buflen == 1 && *ostream->priv->buffer == '\r')
        {
                /* The previous chars can be invalid */
                apply_error_tag (ostream);
 
                /* See special case above, flush this */
-               gtk_text_buffer_insert (GTK_TEXT_BUFFER (ostream->source_buffer),
-                                       &ostream->pos,
+               gtk_text_buffer_insert (GTK_TEXT_BUFFER (ostream->priv->source_buffer),
+                                       &ostream->priv->pos,
                                        "\r",
                                        1);
 
-               g_free (ostream->buffer);
-               ostream->buffer = NULL;
-               ostream->buflen = 0;
+               g_free (ostream->priv->buffer);
+               ostream->priv->buffer = NULL;
+               ostream->priv->buflen = 0;
        }
 
-       if (ostream->iconv_buflen > 0 )
+       if (ostream->priv->iconv_buflen > 0 )
        {
                /* If we reached here is because the last insertion was a half
                   correct char, which has to be inserted as fallback */
                gchar *text;
 
-               if (ostream->error_offset == -1)
+               if (ostream->priv->error_offset == -1)
                {
-                       ostream->error_offset = gtk_text_iter_get_offset (&ostream->pos);
+                       ostream->priv->error_offset = gtk_text_iter_get_offset (&ostream->priv->pos);
                }
 
-               text = ostream->iconv_buffer;
-               while (ostream->iconv_buflen != 0)
+               text = ostream->priv->iconv_buffer;
+               while (ostream->priv->iconv_buflen != 0)
                {
                        insert_fallback (ostream, text);
                        ++text;
-                       --ostream->iconv_buflen;
+                       --ostream->priv->iconv_buflen;
                }
 
-               g_free (ostream->iconv_buffer);
-               ostream->iconv_buffer = NULL;
+               g_free (ostream->priv->iconv_buffer);
+               ostream->priv->iconv_buffer = NULL;
        }
 
        apply_error_tag (ostream);
@@ -1159,24 +1162,24 @@ gtk_source_buffer_output_stream_flush (GOutputStream  *stream,
 
 static gboolean
 gtk_source_buffer_output_stream_close (GOutputStream  *stream,
-                                       GCancellable   *cancellable,
-                                       GError        **error)
+                                      GCancellable   *cancellable,
+                                      GError        **error)
 {
        GtkSourceBufferOutputStream *ostream = GTK_SOURCE_BUFFER_OUTPUT_STREAM (stream);
 
-       if (!ostream->is_closed && ostream->is_initialized)
+       if (!ostream->priv->is_closed && ostream->priv->is_initialized)
        {
                end_append_text_to_document (ostream);
 
-               if (ostream->iconv != NULL)
+               if (ostream->priv->iconv != NULL)
                {
-                       g_iconv_close (ostream->iconv);
+                       g_iconv_close (ostream->priv->iconv);
                }
 
-               ostream->is_closed = TRUE;
+               ostream->priv->is_closed = TRUE;
        }
 
-       if (ostream->buflen > 0 || ostream->iconv_buflen > 0)
+       if (ostream->priv->buflen > 0 || ostream->priv->iconv_buflen > 0)
        {
                g_set_error (error,
                             G_IO_ERROR,
diff --git a/gtksourceview/gtksourcecompletion.c b/gtksourceview/gtksourcecompletion.c
index 3df3c6ea..676ca68e 100644
--- a/gtksourceview/gtksourcecompletion.c
+++ b/gtksourceview/gtksourcecompletion.c
@@ -108,7 +108,6 @@
 #include "gtksourcecompletioninfo-private.h"
 #include "gtksourcecompletionproposal.h"
 #include "gtksourcecompletionprovider.h"
-#include "gtksourcecompletioncontainer-private.h"
 #include "gtksourcecompletioncontext-private.h"
 #include "gtksourcebuffer.h"
 #include "gtksource-marshal.h"
@@ -634,8 +633,8 @@ gtk_source_completion_hide_default (GtkSourceCompletion *completion)
 
 static void
 gtk_source_completion_proposals_size_allocate (GtkSourceCompletion *completion,
-                                              GtkAllocation       *allocation,
-                                              GtkWidget           *widget)
+                                               GtkAllocation       *allocation,
+                                               GtkWidget           *widget)
 {
        GtkTreeViewColumn *column;
        gint cell_offset = 0;
@@ -649,10 +648,15 @@ gtk_source_completion_proposals_size_allocate (GtkSourceCompletion *completion,
                return;
        }
 
+#if 0
        gtk_widget_style_get (GTK_WIDGET (completion->tree_view_proposals),
                              "focus-padding", &focus_padding,
                              "horizontal-separator", &horizontal_separator,
                              NULL);
+#else
+       focus_padding = 0;
+       horizontal_separator = 0;
+#endif
 
        column = gtk_tree_view_get_column (completion->tree_view_proposals, 1);
        column_offset = gtk_tree_view_column_get_x_offset (column);
@@ -744,9 +748,10 @@ gtk_source_completion_activate_proposal (GtkSourceCompletion *completion)
 static void
 update_info_position (GtkSourceCompletion *completion)
 {
+#if 0
        GdkDisplay *display;
        GdkMonitor *monitor;
-       GdkWindow *window;
+       GdkSurface *window;
        GdkRectangle geom;
        gint x, y;
        gint width, height;
@@ -772,6 +777,7 @@ update_info_position (GtkSourceCompletion *completion)
        }
 
        gtk_window_move (GTK_WINDOW (completion->info_window), x, y);
+#endif
 }
 
 static GtkSourceCompletionProvider *
@@ -1283,13 +1289,15 @@ hide_completion_cb (GtkSourceCompletion *completion)
 
 static gboolean
 view_key_press_event_cb (GtkSourceView       *view,
-                        GdkEventKey         *event,
-                        GtkSourceCompletion *completion)
+                         GdkEventKey         *event,
+                         GtkSourceCompletion *completion)
 {
        static gboolean mnemonic_keyval_set = FALSE;
        static guint mnemonic_keyval = GDK_KEY_VoidSymbol;
        GdkModifierType mod;
        GtkBindingSet *binding_set;
+       guint state = 0;
+       guint keyval = 0;
 
        if (!gtk_widget_get_visible (GTK_WIDGET (completion->main_window)))
        {
@@ -1308,11 +1316,14 @@ view_key_press_event_cb (GtkSourceView       *view,
                g_object_unref (label);
        }
 
-       mod = gtk_accelerator_get_default_mod_mask () & event->state;
+       gdk_event_get_state ((GdkEvent *)event, &state);
+       gdk_event_get_keyval ((GdkEvent *)event, &keyval);
+
+       mod = gtk_accelerator_get_default_mod_mask () & state;
 
        /* Handle info button mnemonic */
        if ((mod & GDK_MOD1_MASK) != 0 &&
-           event->keyval == mnemonic_keyval &&
+           keyval == mnemonic_keyval &&
            gtk_widget_get_sensitive (GTK_WIDGET (completion->info_button)))
        {
                gtk_toggle_button_set_active (completion->info_button,
@@ -1321,9 +1332,10 @@ view_key_press_event_cb (GtkSourceView       *view,
        }
 
        if ((mod & GDK_MOD1_MASK) != 0 &&
-           GDK_KEY_0 <= event->keyval && event->keyval <= GDK_KEY_9)
+           GDK_KEY_0 <= keyval &&
+           keyval <= GDK_KEY_9)
        {
-               if (activate_by_accelerator (completion, event->keyval - GDK_KEY_0))
+               if (activate_by_accelerator (completion, keyval - GDK_KEY_0))
                {
                        return TRUE;
                }
@@ -1331,10 +1343,7 @@ view_key_press_event_cb (GtkSourceView       *view,
 
        binding_set = gtk_binding_set_by_class (G_OBJECT_GET_CLASS (completion));
 
-       if (gtk_binding_set_activate (binding_set,
-                                     event->keyval,
-                                     event->state,
-                                     G_OBJECT (completion)))
+       if (gtk_binding_set_activate (binding_set, keyval, state, G_OBJECT (completion)))
        {
                return TRUE;
        }
@@ -1587,7 +1596,6 @@ style_context_changed (GtkStyleContext     *style_context,
        gtk_style_context_set_state (style_context, GTK_STATE_FLAG_NORMAL);
 
        gtk_style_context_get (style_context,
-                              gtk_style_context_get_state (style_context),
                               GTK_STYLE_PROPERTY_FONT, &font_desc,
                               NULL);
 
@@ -2089,13 +2097,10 @@ init_tree_view (GtkSourceCompletion *completion,
        gtk_style_context_set_state (style_context, GTK_STATE_FLAG_INSENSITIVE);
 
        gtk_style_context_get (style_context,
-                              gtk_style_context_get_state (style_context),
                               "background-color", &background_color,
                               NULL);
 
-       gtk_style_context_get_color (style_context,
-                                    gtk_style_context_get_state (style_context),
-                                    &foreground_color);
+       gtk_style_context_get_color (style_context, &foreground_color);
 
        gtk_style_context_restore (style_context);
 
@@ -2171,7 +2176,9 @@ init_main_window (GtkSourceCompletion *completion,
        completion->selection_label = GTK_LABEL (gtk_builder_get_object (builder, "selection_label"));
        completion->bottom_bar = GTK_WIDGET (gtk_builder_get_object (builder, "bottom_bar"));
 
-       gtk_container_set_border_width (GTK_CONTAINER (completion->main_window), 0);
+       g_object_set (completion->main_window,
+                     "margin", 0,
+                     NULL);
 
        gtk_window_set_attached_to (GTK_WINDOW (completion->main_window),
                                    GTK_WIDGET (completion->view));
@@ -2186,10 +2193,8 @@ init_main_window (GtkSourceCompletion *completion,
                                  G_CALLBACK (update_window_position),
                                  completion);
 
-       g_signal_connect (completion->main_window,
-                         "delete-event",
-                         G_CALLBACK (gtk_widget_hide_on_delete),
-                         NULL);
+       gtk_window_set_hide_on_close (GTK_WINDOW (completion->main_window),
+                                     TRUE);
 
        g_signal_connect (completion->main_window,
                          "notify::transient-for",
@@ -2251,14 +2256,9 @@ gtk_source_completion_constructed (GObject *object)
        GtkSourceCompletion *completion = GTK_SOURCE_COMPLETION (object);
        GError *error = NULL;
        GtkBuilder *builder = gtk_builder_new ();
-       GtkSourceCompletionContainer *container = _gtk_source_completion_container_new ();
-       g_object_ref_sink (container);
 
        gtk_builder_set_translation_domain (builder, GETTEXT_PACKAGE);
 
-       /* GtkSourceCompletionContainer is a private type. */
-       gtk_builder_expose_object (builder, "completion_container", G_OBJECT (container));
-
        gtk_builder_add_from_resource (builder,
                                       "/org/gnome/gtksourceview/ui/gtksourcecompletion.ui",
                                       &error);
@@ -2274,7 +2274,6 @@ gtk_source_completion_constructed (GObject *object)
        connect_style_context (completion);
 
        g_object_unref (builder);
-       g_object_unref (container);
 
        G_OBJECT_CLASS (gtk_source_completion_parent_class)->constructed (object);
 }
diff --git a/gtksourceview/gtksourcecompletion.ui b/gtksourceview/gtksourcecompletion.ui
index 497eabd0..926fd739 100644
--- a/gtksourceview/gtksourcecompletion.ui
+++ b/gtksourceview/gtksourcecompletion.ui
@@ -38,8 +38,12 @@ along with this library; if not, see <http://www.gnu.org/licenses/>.
         <property name="visible">True</property>
         <property name="orientation">vertical</property>
         <child>
-          <object class="GtkSourceCompletionContainer" id="completion_container">
+          <object class="GtkScrolledWindow" id="completion_container">
             <property name="visible">True</property>
+            <!-- TODO: this will need more work with a gtk4 port -->
+            <property name="propagate-natural-height">True</property>
+            <property name="propagate-natural-width">True</property>
+            <property name="max-content-height">250</property>
             <property name="can_focus">False</property>
             <child>
               <object class="GtkTreeView" id="tree_view_proposals">
diff --git a/gtksourceview/gtksourcecompletioninfo.c b/gtksourceview/gtksourcecompletioninfo.c
index 93884df5..5555664e 100644
--- a/gtksourceview/gtksourcecompletioninfo.c
+++ b/gtksourceview/gtksourcecompletioninfo.c
@@ -79,122 +79,6 @@ G_DEFINE_TYPE (GtkSourceCompletionInfo, gtk_source_completion_info, GTK_TYPE_WIN
 
 /* Resize the window */
 
-static gboolean
-idle_resize (GtkSourceCompletionInfo *info)
-{
-       GtkWidget *child = gtk_bin_get_child (GTK_BIN (info));
-       GtkRequisition nat_size;
-       guint border_width;
-       gint window_width;
-       gint window_height;
-       gint cur_window_width;
-       gint cur_window_height;
-
-       info->idle_resize = 0;
-
-       if (child == NULL)
-       {
-               return G_SOURCE_REMOVE;
-       }
-
-       gtk_widget_get_preferred_size (child, NULL, &nat_size);
-
-       border_width = gtk_container_get_border_width (GTK_CONTAINER (info));
-
-       window_width = nat_size.width + 2 * border_width;
-       window_height = nat_size.height + 2 * border_width;
-
-       gtk_window_get_size (GTK_WINDOW (info), &cur_window_width, &cur_window_height);
-
-       /* Avoid an infinite loop */
-       if (cur_window_width != window_width || cur_window_height != window_height)
-       {
-               gtk_window_resize (GTK_WINDOW (info),
-                                  MAX (1, window_width),
-                                  MAX (1, window_height));
-       }
-
-       return G_SOURCE_REMOVE;
-}
-
-static void
-queue_resize (GtkSourceCompletionInfo *info)
-{
-       if (info->idle_resize == 0)
-       {
-               info->idle_resize = g_idle_add ((GSourceFunc)idle_resize, info);
-       }
-}
-
-static void
-gtk_source_completion_info_check_resize (GtkContainer *container)
-{
-       GtkSourceCompletionInfo *info = GTK_SOURCE_COMPLETION_INFO (container);
-       queue_resize (info);
-
-       GTK_CONTAINER_CLASS (gtk_source_completion_info_parent_class)->check_resize (container);
-}
-
-/* Geometry management */
-
-static GtkSizeRequestMode
-gtk_source_completion_info_get_request_mode (GtkWidget *widget)
-{
-       return GTK_SIZE_REQUEST_CONSTANT_SIZE;
-}
-
-static void
-gtk_source_completion_info_get_preferred_width (GtkWidget *widget,
-                                               gint      *min_width,
-                                               gint      *nat_width)
-{
-       GtkWidget *child = gtk_bin_get_child (GTK_BIN (widget));
-       gint width = 0;
-
-       if (child != NULL)
-       {
-               GtkRequisition nat_size;
-               gtk_widget_get_preferred_size (child, NULL, &nat_size);
-               width = nat_size.width;
-       }
-
-       if (min_width != NULL)
-       {
-               *min_width = width;
-       }
-
-       if (nat_width != NULL)
-       {
-               *nat_width = width;
-       }
-}
-
-static void
-gtk_source_completion_info_get_preferred_height (GtkWidget *widget,
-                                                gint      *min_height,
-                                                gint      *nat_height)
-{
-       GtkWidget *child = gtk_bin_get_child (GTK_BIN (widget));
-       gint height = 0;
-
-       if (child != NULL)
-       {
-               GtkRequisition nat_size;
-               gtk_widget_get_preferred_size (child, NULL, &nat_size);
-               height = nat_size.height;
-       }
-
-       if (min_height != NULL)
-       {
-               *min_height = height;
-       }
-
-       if (nat_height != NULL)
-       {
-               *nat_height = height;
-       }
-}
-
 /* Init, dispose, finalize, ... */
 
 static gboolean
@@ -250,8 +134,6 @@ update_attached_to (GtkSourceCompletionInfo *info)
 static void
 gtk_source_completion_info_init (GtkSourceCompletionInfo *info)
 {
-       info = gtk_source_completion_info_get_instance_private (info);
-
        g_signal_connect (info,
                          "notify::attached-to",
                          G_CALLBACK (update_attached_to),
@@ -264,9 +146,9 @@ gtk_source_completion_info_init (GtkSourceCompletionInfo *info)
        gtk_widget_set_name (GTK_WIDGET (info), "gtk-tooltip");
 
        gtk_window_set_type_hint (GTK_WINDOW (info),
-                                 GDK_WINDOW_TYPE_HINT_COMBO);
+                                 GDK_SURFACE_TYPE_HINT_COMBO);
 
-       gtk_container_set_border_width (GTK_CONTAINER (info), 1);
+       g_object_set (info, "margin", 1, NULL);
 }
 
 static void
@@ -292,13 +174,14 @@ gtk_source_completion_info_show (GtkWidget *widget)
 
        if (info->attached_to != NULL && !info->transient_set)
        {
-               GtkWidget *toplevel;
+               GtkRoot *toplevel;
+
+               toplevel = gtk_widget_get_root (GTK_WIDGET (info->attached_to));
 
-               toplevel = gtk_widget_get_toplevel (GTK_WIDGET (info->attached_to));
-               if (gtk_widget_is_toplevel (toplevel))
+               if (toplevel != NULL)
                {
                        gtk_window_set_transient_for (GTK_WINDOW (info),
-                                                     GTK_WINDOW (toplevel));
+                                                     GTK_WINDOW (toplevel));
                        info->transient_set = TRUE;
                }
        }
@@ -306,37 +189,15 @@ gtk_source_completion_info_show (GtkWidget *widget)
        GTK_WIDGET_CLASS (gtk_source_completion_info_parent_class)->show (widget);
 }
 
-static gboolean
-gtk_source_completion_info_draw (GtkWidget *widget,
-                                 cairo_t   *cr)
-{
-       GTK_WIDGET_CLASS (gtk_source_completion_info_parent_class)->draw (widget, cr);
-
-       gtk_render_frame (gtk_widget_get_style_context (widget),
-                         cr,
-                         0, 0,
-                         gtk_widget_get_allocated_width (widget),
-                         gtk_widget_get_allocated_height (widget));
-
-       return FALSE;
-}
-
 static void
 gtk_source_completion_info_class_init (GtkSourceCompletionInfoClass *klass)
 {
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
        GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
-       GtkContainerClass *container_class = GTK_CONTAINER_CLASS (klass);
 
        object_class->dispose = gtk_source_completion_info_dispose;
 
        widget_class->show = gtk_source_completion_info_show;
-       widget_class->draw = gtk_source_completion_info_draw;
-       widget_class->get_request_mode = gtk_source_completion_info_get_request_mode;
-       widget_class->get_preferred_width = gtk_source_completion_info_get_preferred_width;
-       widget_class->get_preferred_height = gtk_source_completion_info_get_preferred_height;
-
-       container_class->check_resize = gtk_source_completion_info_check_resize;
 }
 
 void
@@ -349,6 +210,7 @@ _gtk_source_completion_info_set_xoffset (GtkSourceCompletionInfo *window,
 }
 
 /* Move to iter */
+#if 0
 
 static void
 get_iter_pos (GtkTextView *text_view,
@@ -529,6 +391,7 @@ move_to_cursor (GtkSourceCompletionInfo *window,
 
        move_to_iter (window, view, &insert);
 }
+#endif
 
 /* Public functions */
 
@@ -542,7 +405,7 @@ gtk_source_completion_info_new (void)
 {
        return g_object_new (GTK_SOURCE_TYPE_COMPLETION_INFO,
                             "type", GTK_WINDOW_POPUP,
-                            "border-width", 3,
+                            "margin", 3,
                             NULL);
 }
 
@@ -565,6 +428,7 @@ gtk_source_completion_info_move_to_iter (GtkSourceCompletionInfo *info,
        g_return_if_fail (GTK_SOURCE_IS_COMPLETION_INFO (info));
        g_return_if_fail (GTK_IS_TEXT_VIEW (view));
 
+#if 0
        if (iter == NULL)
        {
                move_to_cursor (info, view);
@@ -573,4 +437,5 @@ gtk_source_completion_info_move_to_iter (GtkSourceCompletionInfo *info,
        {
                move_to_iter (info, view, iter);
        }
+#endif
 }
diff --git a/gtksourceview/gtksourcecontextengine-private.h b/gtksourceview/gtksourcecontextengine-private.h
index 3d931b3b..61f96e86 100644
--- a/gtksourceview/gtksourcecontextengine-private.h
+++ b/gtksourceview/gtksourcecontextengine-private.h
@@ -2,8 +2,8 @@
  *
  * This file is part of GtkSourceView
  *
- * Copyright 2003 - Gustavo Giráldez
- * Copyright 2005 - Marco Barisione, Emanuele Aina
+ * Copyright (C) 2003 - Gustavo Giráldez
+ * Copyright (C) 2005 - Marco Barisione, Emanuele Aina
  *
  * GtkSourceView is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -19,91 +19,126 @@
  * along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#pragma once
+#ifndef GTK_SOURCE_CONTEXT_ENGINE_PRIVATE_H
+#define GTK_SOURCE_CONTEXT_ENGINE_PRIVATE_H
 
-#include "gtksourceengine-private.h"
 #include "gtksourcetypes.h"
+#include "gtksourceengine-private.h"
 #include "gtksourcetypes-private.h"
 
 G_BEGIN_DECLS
 
-#define GTK_SOURCE_TYPE_CONTEXT_ENGINE (_gtk_source_context_engine_get_type())
+#define GTK_SOURCE_TYPE_CONTEXT_ENGINE            (_gtk_source_context_engine_get_type ())
+#define GTK_SOURCE_CONTEXT_ENGINE(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), 
GTK_SOURCE_TYPE_CONTEXT_ENGINE, GtkSourceContextEngine))
+#define GTK_SOURCE_CONTEXT_ENGINE_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), 
GTK_SOURCE_TYPE_CONTEXT_ENGINE, GtkSourceContextEngineClass))
+#define GTK_SOURCE_IS_CONTEXT_ENGINE(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), 
GTK_SOURCE_TYPE_CONTEXT_ENGINE))
+#define GTK_SOURCE_IS_CONTEXT_ENGINE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), 
GTK_SOURCE_TYPE_CONTEXT_ENGINE))
+#define GTK_SOURCE_CONTEXT_ENGINE_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), 
GTK_SOURCE_TYPE_CONTEXT_ENGINE, GtkSourceContextEngineClass))
 
 typedef struct _GtkSourceContextData          GtkSourceContextData;
 typedef struct _GtkSourceContextReplace       GtkSourceContextReplace;
 typedef struct _GtkSourceContextClass         GtkSourceContextClass;
+typedef struct _GtkSourceContextEngineClass   GtkSourceContextEngineClass;
+typedef struct _GtkSourceContextEnginePrivate GtkSourceContextEnginePrivate;
+
+struct _GtkSourceContextEngine
+{
+       GObject parent_instance;
+
+       /*< private >*/
+       GtkSourceContextEnginePrivate *priv;
+};
+
+struct _GtkSourceContextEngineClass
+{
+       GObjectClass parent_class;
+};
 
 typedef enum _GtkSourceContextFlags {
-       GTK_SOURCE_CONTEXT_EXTEND_PARENT   = 1 << 0,
-       GTK_SOURCE_CONTEXT_END_PARENT      = 1 << 1,
-       GTK_SOURCE_CONTEXT_END_AT_LINE_END = 1 << 2,
-       GTK_SOURCE_CONTEXT_FIRST_LINE_ONLY = 1 << 3,
-       GTK_SOURCE_CONTEXT_ONCE_ONLY       = 1 << 4,
-       GTK_SOURCE_CONTEXT_STYLE_INSIDE    = 1 << 5
+       GTK_SOURCE_CONTEXT_EXTEND_PARENT        = 1 << 0,
+       GTK_SOURCE_CONTEXT_END_PARENT           = 1 << 1,
+       GTK_SOURCE_CONTEXT_END_AT_LINE_END      = 1 << 2,
+       GTK_SOURCE_CONTEXT_FIRST_LINE_ONLY      = 1 << 3,
+       GTK_SOURCE_CONTEXT_ONCE_ONLY            = 1 << 4,
+       GTK_SOURCE_CONTEXT_STYLE_INSIDE         = 1 << 5
 } GtkSourceContextFlags;
 
 typedef enum _GtkSourceContextRefOptions {
-       GTK_SOURCE_CONTEXT_IGNORE_STYLE   = 1 << 0,
-       GTK_SOURCE_CONTEXT_OVERRIDE_STYLE = 1 << 1,
-       GTK_SOURCE_CONTEXT_REF_ORIGINAL   = 1 << 2
+       GTK_SOURCE_CONTEXT_IGNORE_STYLE         = 1 << 0,
+       GTK_SOURCE_CONTEXT_OVERRIDE_STYLE       = 1 << 1,
+       GTK_SOURCE_CONTEXT_REF_ORIGINAL         = 1 << 2
 } GtkSourceContextRefOptions;
 
 G_GNUC_INTERNAL
-G_DECLARE_FINAL_TYPE (GtkSourceContextEngine, _gtk_source_context_engine, GTK_SOURCE, CONTEXT_ENGINE, 
GObject)
+GType                   _gtk_source_context_engine_get_type            (void) G_GNUC_CONST;
 
 G_GNUC_INTERNAL
-GtkSourceContextData    *_gtk_source_context_data_new             (GtkSourceLanguage           *lang);
+GtkSourceContextData   *_gtk_source_context_data_new                   (GtkSourceLanguage       *lang);
+
 G_GNUC_INTERNAL
-GtkSourceContextData    *_gtk_source_context_data_ref             (GtkSourceContextData        *data);
+GtkSourceContextData   *_gtk_source_context_data_ref                   (GtkSourceContextData    *data);
+
 G_GNUC_INTERNAL
-void                     _gtk_source_context_data_unref           (GtkSourceContextData        *data);
+void                    _gtk_source_context_data_unref                 (GtkSourceContextData    *data);
+
 G_GNUC_INTERNAL
-GtkSourceContextClass   *gtk_source_context_class_new             (gchar const                 *name,
-                                                                   gboolean                     enabled);
+GtkSourceContextClass  *gtk_source_context_class_new                   (gchar const             *name,
+                                                                        gboolean                 enabled);
+
 G_GNUC_INTERNAL
-void                     gtk_source_context_class_free            (GtkSourceContextClass       *cclass);
+void                    gtk_source_context_class_free                  (GtkSourceContextClass   *cclass);
+
 G_GNUC_INTERNAL
-GtkSourceContextEngine  *_gtk_source_context_engine_new           (GtkSourceContextData        *data);
+GtkSourceContextEngine *_gtk_source_context_engine_new                 (GtkSourceContextData    *data);
+
 G_GNUC_INTERNAL
-gboolean                 _gtk_source_context_data_define_context  (GtkSourceContextData        *data,
-                                                                   const gchar                 *id,
-                                                                   const gchar                 *parent_id,
-                                                                   const gchar                 *match_regex,
-                                                                   const gchar                 *start_regex,
-                                                                   const gchar                 *end_regex,
-                                                                   const gchar                 *style,
-                                                                   GSList                      
*context_classes,
-                                                                   GtkSourceContextFlags        flags,
-                                                                   GError                     **error);
+gboolean                _gtk_source_context_data_define_context        (GtkSourceContextData    *data,
+                                                                        const gchar             *id,
+                                                                        const gchar             *parent_id,
+                                                                        const gchar             *match_regex,
+                                                                        const gchar             *start_regex,
+                                                                        const gchar             *end_regex,
+                                                                        const gchar             *style,
+                                                                        GSList                  
*context_classes,
+                                                                        GtkSourceContextFlags    flags,
+                                                                        GError                 **error);
+
 G_GNUC_INTERNAL
-gboolean                 _gtk_source_context_data_add_sub_pattern (GtkSourceContextData        *data,
-                                                                   const gchar                 *id,
-                                                                   const gchar                 *parent_id,
-                                                                   const gchar                 *name,
-                                                                   const gchar                 *where,
-                                                                   const gchar                 *style,
-                                                                   GSList                      
*context_classes,
-                                                                   GError                     **error);
+gboolean                _gtk_source_context_data_add_sub_pattern       (GtkSourceContextData    *data,
+                                                                        const gchar             *id,
+                                                                        const gchar             *parent_id,
+                                                                        const gchar             *name,
+                                                                        const gchar             *where,
+                                                                        const gchar             *style,
+                                                                        GSList                  
*context_classes,
+                                                                        GError                 **error);
+
 G_GNUC_INTERNAL
-gboolean                 _gtk_source_context_data_add_ref         (GtkSourceContextData        *data,
-                                                                   const gchar                 *parent_id,
-                                                                   const gchar                 *ref_id,
-                                                                   GtkSourceContextRefOptions   options,
-                                                                   const gchar                 *style,
-                                                                   gboolean                     all,
-                                                                   GError                     **error);
+gboolean                _gtk_source_context_data_add_ref               (GtkSourceContextData    *data,
+                                                                        const gchar             *parent_id,
+                                                                        const gchar             *ref_id,
+                                                                        GtkSourceContextRefOptions options,
+                                                                        const gchar             *style,
+                                                                        gboolean                 all,
+                                                                        GError                 **error);
+
 G_GNUC_INTERNAL
-GtkSourceContextReplace *_gtk_source_context_replace_new          (const gchar                 
*to_replace_id,
-                                                                   const gchar                 
*replace_with_id);
+GtkSourceContextReplace        *_gtk_source_context_replace_new                (const gchar             
*to_replace_id,
+                                                                        const gchar             
*replace_with_id);
+
 G_GNUC_INTERNAL
-void                     _gtk_source_context_replace_free         (GtkSourceContextReplace     *repl);
+void                    _gtk_source_context_replace_free               (GtkSourceContextReplace *repl);
+
 G_GNUC_INTERNAL
-gboolean                 _gtk_source_context_data_finish_parse    (GtkSourceContextData        *data,
-                                                                   GList                       *overrides,
-                                                                   GError                     **error);
+gboolean                _gtk_source_context_data_finish_parse          (GtkSourceContextData    *data,
+                                                                        GList                   *overrides,
+                                                                        GError                 **error);
+
 /* Only for lang files version 1, do not use it */
 G_GNUC_INTERNAL
-void                     _gtk_source_context_data_set_escape_char (GtkSourceContextData        *data,
-                                                                   gunichar                     esc_char);
+void                    _gtk_source_context_data_set_escape_char       (GtkSourceContextData    *data,
+                                                                        gunichar                 esc_char);
 
 G_END_DECLS
+
+#endif /* GTK_SOURCE_CONTEXT_ENGINE_PRIVATE_H */
diff --git a/gtksourceview/gtksourcecontextengine.c b/gtksourceview/gtksourcecontextengine.c
index dc1bf174..0a591982 100644
--- a/gtksourceview/gtksourcecontextengine.c
+++ b/gtksourceview/gtksourcecontextengine.c
@@ -2,8 +2,8 @@
  *
  * This file is part of GtkSourceView
  *
- * Copyright 2003 - Gustavo Giráldez <gustavo giraldez gmx net>
- * Copyright 2005, 2006 - Marco Barisione, Emanuele Aina
+ * Copyright (C) 2003 - Gustavo Giráldez <gustavo giraldez gmx net>
+ * Copyright (C) 2005, 2006 - Marco Barisione, Emanuele Aina
  *
  * GtkSourceView is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -19,18 +19,20 @@
  * along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "config.h"
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
 
-#include <string.h>
 #include <glib.h>
 #include <glib/gi18n-lib.h>
+#include <string.h>
 
 #include "gtksourcecontextengine-private.h"
 #include "gtksourceregion.h"
 #include "gtksourcelanguage.h"
 #include "gtksourcelanguage-private.h"
 #include "gtksourcebuffer.h"
-#include "gtksourceregex-private.h"
+#include "gtksourceregex.h"
 #include "gtksourcestyle.h"
 #include "gtksourcestylescheme.h"
 #include "gtksourceutils-private.h"
@@ -412,10 +414,8 @@ struct _GtkSourceContextData
        GHashTable *definitions;
 };
 
-struct _GtkSourceContextEngine
+struct _GtkSourceContextEnginePrivate
 {
-  GObject parent_instance;
-
        GtkSourceContextData *ctx_data;
 
        GtkTextBuffer *buffer;
@@ -456,9 +456,9 @@ struct _GtkSourceContextEngine
 };
 
 #ifdef ENABLE_CHECK_TREE
-static void check_tree             (GtkSourceContextEngine *ce);
-static void check_segment_list     (Segment                *segment);
-static void check_segment_children (Segment                *segment);
+static void check_tree (GtkSourceContextEngine *ce);
+static void check_segment_list (Segment *segment);
+static void check_segment_children (Segment *segment);
 #define CHECK_TREE check_tree
 #define CHECK_SEGMENT_LIST check_segment_list
 #define CHECK_SEGMENT_CHILDREN check_segment_children
@@ -468,62 +468,66 @@ static void check_segment_children (Segment                *segment);
 #define CHECK_SEGMENT_CHILDREN(s)
 #endif
 
-static GQuark             gtk_source_context_engine_error_quark (void) G_GNUC_CONST;
-static Segment           *create_segment                        (GtkSourceContextEngine  *ce,
-                                                                 Segment                 *parent,
-                                                                 Context                 *context,
-                                                                 gint                     start_at,
-                                                                 gint                     end_at,
-                                                                 gboolean                 is_start,
-                                                                 Segment                 *hint);
-static Segment           *segment_new                           (GtkSourceContextEngine  *ce,
-                                                                 Segment                 *parent,
-                                                                 Context                 *context,
-                                                                 gint                     start_at,
-                                                                 gint                     end_at,
-                                                                 gboolean                 is_start);
-static Context           *context_new                           (Context                 *parent,
-                                                                 ContextDefinition       *definition,
-                                                                 const gchar             *line_text,
-                                                                 const gchar             *style,
-                                                                 gboolean                 
ignore_children_style);
-static void               context_unref                         (Context                 *context);
-static void               context_freeze                        (Context                 *context);
-static void               context_thaw                          (Context                 *context);
-static void               erase_segments                        (GtkSourceContextEngine  *ce,
-                                                                 gint                     start,
-                                                                 gint                     end,
-                                                                 Segment                 *hint);
-static void               segment_remove                        (GtkSourceContextEngine  *ce,
-                                                                 Segment                 *segment);
-static void               find_insertion_place                  (Segment                 *segment,
-                                                                 gint                     offset,
-                                                                 Segment                **parent,
-                                                                 Segment                **prev,
-                                                                 Segment                **next,
-                                                                 Segment                 *hint);
-static void               segment_destroy                       (GtkSourceContextEngine  *ce,
-                                                                 Segment                 *segment);
-static ContextDefinition *context_definition_ref                (ContextDefinition       *definition);
-static void               context_definition_unref              (ContextDefinition       *definition);
-static void               segment_extend                        (Segment                 *state,
-                                                                 gint                     end_at);
-static Context           *ancestor_context_ends_here            (Context                 *state,
-                                                                 LineInfo                *line,
-                                                                 gint                     pos);
-static void               definition_iter_init                  (DefinitionsIter         *iter,
-                                                                 ContextDefinition       *definition);
-static DefinitionChild   *definition_iter_next                  (DefinitionsIter         *iter);
-static void               definition_iter_destroy               (DefinitionsIter         *iter);
-static void               update_syntax                         (GtkSourceContextEngine  *ce,
-                                                                 const GtkTextIter       *end,
-                                                                 gint                     time);
-static void               install_idle_worker                   (GtkSourceContextEngine  *ce);
-static void               install_first_update                  (GtkSourceContextEngine  *ce);
+static GQuark          gtk_source_context_engine_error_quark (void) G_GNUC_CONST;
+
+static Segment        *create_segment          (GtkSourceContextEngine *ce,
+                                                Segment                *parent,
+                                                Context                *context,
+                                                gint                    start_at,
+                                                gint                    end_at,
+                                                gboolean                is_start,
+                                                Segment                *hint);
+static Segment        *segment_new             (GtkSourceContextEngine *ce,
+                                                Segment                *parent,
+                                                Context                *context,
+                                                gint                    start_at,
+                                                gint                    end_at,
+                                                gboolean                is_start);
+static Context        *context_new             (Context                *parent,
+                                                ContextDefinition      *definition,
+                                                const gchar            *line_text,
+                                                const gchar            *style,
+                                                gboolean                ignore_children_style);
+static void            context_unref           (Context                *context);
+static void            context_freeze          (Context                *context);
+static void            context_thaw            (Context                *context);
+static void            erase_segments          (GtkSourceContextEngine *ce,
+                                                gint                    start,
+                                                gint                    end,
+                                                Segment                *hint);
+static void            segment_remove          (GtkSourceContextEngine *ce,
+                                                Segment                *segment);
+
+static void            find_insertion_place    (Segment                *segment,
+                                                gint                    offset,
+                                                Segment               **parent,
+                                                Segment               **prev,
+                                                Segment               **next,
+                                                Segment                *hint);
+static void            segment_destroy         (GtkSourceContextEngine *ce,
+                                                Segment                *segment);
+static ContextDefinition *context_definition_ref(ContextDefinition     *definition);
+static void            context_definition_unref(ContextDefinition      *definition);
+
+static void            segment_extend          (Segment                *state,
+                                                gint                    end_at);
+static Context        *ancestor_context_ends_here (Context             *state,
+                                                LineInfo               *line,
+                                                gint                    pos);
+static void            definition_iter_init    (DefinitionsIter        *iter,
+                                                ContextDefinition      *definition);
+static DefinitionChild *definition_iter_next   (DefinitionsIter        *iter);
+static void            definition_iter_destroy (DefinitionsIter        *iter);
+
+static void            update_syntax           (GtkSourceContextEngine *ce,
+                                                const GtkTextIter      *end,
+                                                gint                    time);
+static void            install_idle_worker     (GtkSourceContextEngine *ce);
+static void            install_first_update    (GtkSourceContextEngine *ce);
 
 static ContextDefinition *
 gtk_source_context_data_lookup (GtkSourceContextData *ctx_data,
-                                const gchar          *id)
+                               const gchar          *id)
 {
        return g_hash_table_lookup (ctx_data->definitions, id);
 }
@@ -572,7 +576,7 @@ gtk_source_context_class_free (GtkSourceContextClass *cclass)
 
 static ContextClassTag *
 context_class_tag_new (GtkTextTag *tag,
-                       gboolean    enabled)
+                      gboolean    enabled)
 {
        ContextClassTag *attrtag = g_slice_new (ContextClassTag);
 
@@ -595,8 +599,8 @@ struct BufAndIters {
 
 static void
 unhighlight_region_cb (G_GNUC_UNUSED gpointer  style,
-                       GSList                 *tags,
-                       gpointer                user_data)
+                      GSList                 *tags,
+                      gpointer                user_data)
 {
        struct BufAndIters *data = user_data;
 
@@ -612,27 +616,27 @@ unhighlight_region_cb (G_GNUC_UNUSED gpointer  style,
 
 static void
 unhighlight_region (GtkSourceContextEngine *ce,
-                    const GtkTextIter      *start,
-                    const GtkTextIter      *end)
+                   const GtkTextIter      *start,
+                   const GtkTextIter      *end)
 {
        struct BufAndIters data;
 
-       data.buffer = ce->buffer;
+       data.buffer = ce->priv->buffer;
        data.start = start;
        data.end = end;
 
        if (gtk_text_iter_equal (start, end))
                return;
 
-       g_hash_table_foreach (ce->tags, (GHFunc) unhighlight_region_cb, &data);
+       g_hash_table_foreach (ce->priv->tags, (GHFunc) unhighlight_region_cb, &data);
 }
 
 #define MAX_STYLE_DEPENDENCY_DEPTH     50
 
 static void
 set_tag_style (GtkSourceContextEngine *ce,
-               GtkTextTag             *tag,
-               const gchar            *style_id)
+              GtkTextTag             *tag,
+              const gchar            *style_id)
 {
        GtkSourceStyle *style;
        const char *map_to;
@@ -643,11 +647,11 @@ set_tag_style (GtkSourceContextEngine *ce,
 
        gtk_source_style_apply (NULL, tag);
 
-       if (ce->style_scheme == NULL)
+       if (ce->priv->style_scheme == NULL)
                return;
 
        map_to = style_id;
-       style = gtk_source_style_scheme_get_style (ce->style_scheme, style_id);
+       style = gtk_source_style_scheme_get_style (ce->priv->style_scheme, style_id);
 
        while (style == NULL)
        {
@@ -661,11 +665,11 @@ set_tag_style (GtkSourceContextEngine *ce,
 
                /* FIXME Style references really must be fixed, both parser for
                 * sane use in lang files, and engine for safe use. */
-               map_to = gtk_source_language_get_style_fallback (ce->ctx_data->lang, map_to);
+               map_to = gtk_source_language_get_style_fallback (ce->priv->ctx_data->lang, map_to);
                if (map_to == NULL)
                        break;
 
-               style = gtk_source_style_scheme_get_style (ce->style_scheme, map_to);
+               style = gtk_source_style_scheme_get_style (ce->priv->style_scheme, map_to);
        }
 
        /* not having style is fine, since parser checks validity of every style reference,
@@ -676,18 +680,18 @@ set_tag_style (GtkSourceContextEngine *ce,
 
 static GtkTextTag *
 create_tag (GtkSourceContextEngine *ce,
-            const gchar            *style_id)
+           const gchar            *style_id)
 {
        GtkTextTag *new_tag;
 
        g_assert (style_id != NULL);
 
-       new_tag = gtk_text_buffer_create_tag (ce->buffer, NULL, NULL);
+       new_tag = gtk_text_buffer_create_tag (ce->priv->buffer, NULL, NULL);
        /* It must have priority lower than user tags but still
         * higher than highlighting tags created before */
-       gtk_text_tag_set_priority (new_tag, ce->n_tags);
+       gtk_text_tag_set_priority (new_tag, ce->priv->n_tags);
        set_tag_style (ce, new_tag, style_id);
-       ce->n_tags += 1;
+       ce->priv->n_tags += 1;
 
        return new_tag;
 }
@@ -695,7 +699,7 @@ create_tag (GtkSourceContextEngine *ce,
 /* Find tag which has to be overridden. */
 static GtkTextTag *
 get_parent_tag (Context    *context,
-                const char *style)
+               const char *style)
 {
        while (context != NULL)
        {
@@ -716,8 +720,8 @@ get_parent_tag (Context    *context,
 
 static GtkTextTag *
 get_tag_for_parent (GtkSourceContextEngine *ce,
-                    const char             *style,
-                    Context                *parent)
+                   const char             *style,
+                   Context                *parent)
 {
        GSList *tags;
        GtkTextTag *parent_tag = NULL;
@@ -726,7 +730,7 @@ get_tag_for_parent (GtkSourceContextEngine *ce,
        g_return_val_if_fail (style != NULL, NULL);
 
        parent_tag = get_parent_tag (parent, style);
-       tags = g_hash_table_lookup (ce->tags, style);
+       tags = g_hash_table_lookup (ce->priv->tags, style);
 
        if (tags && (!parent_tag ||
                gtk_text_tag_get_priority (tags->data) > gtk_text_tag_get_priority (parent_tag)))
@@ -750,7 +754,7 @@ get_tag_for_parent (GtkSourceContextEngine *ce,
                tag = create_tag (ce, style);
 
                tags = g_slist_prepend (tags, g_object_ref (tag));
-               g_hash_table_insert (ce->tags, g_strdup (style), tags);
+               g_hash_table_insert (ce->priv->tags, g_strdup (style), tags);
 
 #ifdef ENABLE_DEBUG
                {
@@ -769,7 +773,7 @@ get_tag_for_parent (GtkSourceContextEngine *ce,
                                parent = parent->parent;
                        }
 
-                       tags = g_hash_table_lookup (ce->tags, style);
+                       tags = g_hash_table_lookup (ce->priv->tags, style);
                        n = g_slist_length (tags);
                        g_print ("created %d tag for style %s: %s\n", n, style, style_path->str);
                        g_string_free (style_path, TRUE);
@@ -782,8 +786,8 @@ get_tag_for_parent (GtkSourceContextEngine *ce,
 
 static GtkTextTag *
 get_subpattern_tag (GtkSourceContextEngine *ce,
-                    Context                *context,
-                    SubPatternDefinition   *sp_def)
+                   Context                *context,
+                   SubPatternDefinition   *sp_def)
 {
        if (sp_def->style == NULL)
                return NULL;
@@ -802,7 +806,7 @@ get_subpattern_tag (GtkSourceContextEngine *ce,
 
 static GtkTextTag *
 get_context_tag (GtkSourceContextEngine *ce,
-                 Context                *context)
+                Context                *context)
 {
        if (context->style != NULL && context->tag == NULL)
                context->tag = get_tag_for_parent (ce,
@@ -813,13 +817,13 @@ get_context_tag (GtkSourceContextEngine *ce,
 
 static void
 apply_tags (GtkSourceContextEngine *ce,
-            Segment                *segment,
-            gint                    start_offset,
-            gint                    end_offset)
+           Segment                *segment,
+           gint                    start_offset,
+           gint                    end_offset)
 {
        GtkTextTag *tag;
        GtkTextIter start_iter, end_iter;
-       GtkTextBuffer *buffer = ce->buffer;
+       GtkTextBuffer *buffer = ce->priv->buffer;
        SubPattern *sp;
        Segment *child;
 
@@ -858,7 +862,7 @@ apply_tags (GtkSourceContextEngine *ce,
                        gtk_text_buffer_get_iter_at_offset (buffer, &start_iter, style_start_at);
                        end_iter = start_iter;
                        gtk_text_iter_forward_chars (&end_iter, style_end_at - style_start_at);
-                       gtk_text_buffer_apply_tag (ce->buffer, tag, &start_iter, &end_iter);
+                       gtk_text_buffer_apply_tag (ce->priv->buffer, tag, &start_iter, &end_iter);
                }
        }
 
@@ -876,7 +880,7 @@ apply_tags (GtkSourceContextEngine *ce,
                                gtk_text_buffer_get_iter_at_offset (buffer, &start_iter, start);
                                end_iter = start_iter;
                                gtk_text_iter_forward_chars (&end_iter, end - start);
-                               gtk_text_buffer_apply_tag (ce->buffer, tag, &start_iter, &end_iter);
+                               gtk_text_buffer_apply_tag (ce->priv->buffer, tag, &start_iter, &end_iter);
                        }
                }
        }
@@ -892,8 +896,8 @@ apply_tags (GtkSourceContextEngine *ce,
 
 static void
 highlight_region (GtkSourceContextEngine *ce,
-                  GtkTextIter            *start,
-                  GtkTextIter            *end)
+                 GtkTextIter            *start,
+                 GtkTextIter            *end)
 {
 #ifdef ENABLE_PROFILE
        GTimer *timer;
@@ -911,7 +915,7 @@ highlight_region (GtkSourceContextEngine *ce,
        /* First we need to delete tags in the regions. */
        unhighlight_region (ce, start, end);
 
-       apply_tags (ce, ce->root_segment,
+       apply_tags (ce, ce->priv->root_segment,
                    gtk_text_iter_get_offset (start),
                    gtk_text_iter_get_offset (end));
 
@@ -938,14 +942,14 @@ highlight_region (GtkSourceContextEngine *ce,
  */
 static void
 ensure_highlighted (GtkSourceContextEngine *ce,
-                    const GtkTextIter      *start,
-                    const GtkTextIter      *end)
+                   const GtkTextIter      *start,
+                   const GtkTextIter      *end)
 {
        GtkSourceRegion *region;
        GtkSourceRegionIter reg_iter;
 
        /* Get the subregions not yet highlighted. */
-       region = gtk_source_region_intersect_subregion (ce->refresh_region, start, end);
+       region = gtk_source_region_intersect_subregion (ce->priv->refresh_region, start, end);
 
        if (region == NULL)
                return;
@@ -965,12 +969,12 @@ ensure_highlighted (GtkSourceContextEngine *ce,
        g_clear_object (&region);
 
        /* Remove the just highlighted region. */
-       gtk_source_region_subtract_subregion (ce->refresh_region, start, end);
+       gtk_source_region_subtract_subregion (ce->priv->refresh_region, start, end);
 }
 
 static GtkTextTag *
 get_context_class_tag (GtkSourceContextEngine *ce,
-                       gchar const            *name)
+                      gchar const            *name)
 {
        gchar *tag_name;
        GtkTextTagTable *tag_table;
@@ -978,15 +982,15 @@ get_context_class_tag (GtkSourceContextEngine *ce,
 
        tag_name = g_strdup_printf ("gtksourceview:context-classes:%s", name);
 
-       tag_table = gtk_text_buffer_get_tag_table (ce->buffer);
+       tag_table = gtk_text_buffer_get_tag_table (ce->priv->buffer);
        tag = gtk_text_tag_table_lookup (tag_table, tag_name);
 
        if (tag == NULL)
        {
-               tag = gtk_text_buffer_create_tag (ce->buffer, tag_name, NULL);
+               tag = gtk_text_buffer_create_tag (ce->priv->buffer, tag_name, NULL);
                g_return_val_if_fail (tag != NULL, NULL);
 
-               ce->context_classes = g_slist_prepend (ce->context_classes,
+               ce->priv->context_classes = g_slist_prepend (ce->priv->context_classes,
                                                             g_object_ref (tag));
        }
 
@@ -996,7 +1000,7 @@ get_context_class_tag (GtkSourceContextEngine *ce,
 
 static GSList *
 extend_context_classes (GtkSourceContextEngine *ce,
-                        GSList                 *definitions)
+                       GSList                 *definitions)
 {
        GSList *item;
        GSList *ret = NULL;
@@ -1015,8 +1019,8 @@ extend_context_classes (GtkSourceContextEngine *ce,
 
 static GSList *
 get_subpattern_context_classes (GtkSourceContextEngine *ce,
-                                Context                *context,
-                                SubPatternDefinition   *sp_def)
+                               Context                *context,
+                               SubPatternDefinition   *sp_def)
 {
        g_assert (sp_def->index < context->definition->n_sub_patterns);
 
@@ -1035,7 +1039,7 @@ get_subpattern_context_classes (GtkSourceContextEngine *ce,
 
 static GSList *
 get_context_classes (GtkSourceContextEngine *ce,
-                     Context                *context)
+                    Context                *context)
 {
        if (context->context_classes == NULL)
        {
@@ -1049,15 +1053,15 @@ get_context_classes (GtkSourceContextEngine *ce,
 
 static void
 apply_context_classes (GtkSourceContextEngine *ce,
-                       GSList                 *context_classes,
-                       gint                    start,
-                       gint                    end)
+                      GSList                 *context_classes,
+                      gint                    start,
+                      gint                    end)
 {
        GtkTextIter start_iter;
        GtkTextIter end_iter;
        GSList *item;
 
-       gtk_text_buffer_get_iter_at_offset (ce->buffer, &start_iter, start);
+       gtk_text_buffer_get_iter_at_offset (ce->priv->buffer, &start_iter, start);
        end_iter = start_iter;
        gtk_text_iter_forward_chars (&end_iter, end - start);
 
@@ -1067,14 +1071,14 @@ apply_context_classes (GtkSourceContextEngine *ce,
 
                if (attrtag->enabled)
                {
-                       gtk_text_buffer_apply_tag (ce->buffer,
+                       gtk_text_buffer_apply_tag (ce->priv->buffer,
                                                   attrtag->tag,
                                                   &start_iter,
                                                   &end_iter);
                }
                else
                {
-                       gtk_text_buffer_remove_tag (ce->buffer,
+                       gtk_text_buffer_remove_tag (ce->priv->buffer,
                                                    attrtag->tag,
                                                    &start_iter,
                                                    &end_iter);
@@ -1084,9 +1088,9 @@ apply_context_classes (GtkSourceContextEngine *ce,
 
 static void
 add_region_context_classes (GtkSourceContextEngine *ce,
-                            Segment                *segment,
-                            gint                    start_offset,
-                            gint                    end_offset)
+                           Segment                *segment,
+                           gint                    start_offset,
+                           gint                    end_offset)
 {
        SubPattern *sp;
        Segment *child;
@@ -1151,8 +1155,8 @@ add_region_context_classes (GtkSourceContextEngine *ce,
 
 static void
 remove_region_context_classes (GtkSourceContextEngine *ce,
-                               const GtkTextIter      *start,
-                               const GtkTextIter      *end)
+                              const GtkTextIter      *start,
+                              const GtkTextIter      *end)
 {
        GSList *l;
 
@@ -1161,18 +1165,18 @@ remove_region_context_classes (GtkSourceContextEngine *ce,
                return;
        }
 
-       for (l = ce->context_classes; l != NULL; l = l->next)
+       for (l = ce->priv->context_classes; l != NULL; l = l->next)
        {
                GtkTextTag *tag = l->data;
 
-               gtk_text_buffer_remove_tag (ce->buffer, tag, start, end);
+               gtk_text_buffer_remove_tag (ce->priv->buffer, tag, start, end);
        }
 }
 
 static void
 refresh_context_classes (GtkSourceContextEngine *ce,
-                         const GtkTextIter      *start,
-                         const GtkTextIter      *end)
+                        const GtkTextIter      *start,
+                        const GtkTextIter      *end)
 {
 #ifdef ENABLE_PROFILE
        GTimer *timer;
@@ -1197,7 +1201,7 @@ refresh_context_classes (GtkSourceContextEngine *ce,
        remove_region_context_classes (ce, start, &realend);
 
        add_region_context_classes (ce,
-                                   ce->root_segment,
+                                   ce->priv->root_segment,
                                    gtk_text_iter_get_offset (start),
                                    gtk_text_iter_get_offset (&realend));
 
@@ -1222,8 +1226,8 @@ refresh_context_classes (GtkSourceContextEngine *ce,
  */
 static void
 refresh_range (GtkSourceContextEngine *ce,
-               const GtkTextIter      *start,
-               const GtkTextIter      *end)
+              const GtkTextIter      *start,
+              const GtkTextIter      *end)
 {
        GtkTextIter real_end;
 
@@ -1242,7 +1246,7 @@ refresh_range (GtkSourceContextEngine *ce,
                gtk_text_iter_backward_cursor_position (&real_end);
        }
 
-       g_signal_emit_by_name (ce->buffer,
+       g_signal_emit_by_name (ce->priv->buffer,
                               "highlight-updated",
                               start,
                               &real_end);
@@ -1262,7 +1266,7 @@ refresh_range (GtkSourceContextEngine *ce,
  */
 static gint
 segment_cmp (Segment *s1,
-             Segment *s2)
+            Segment *s2)
 {
        if (s1->start_at < s2->start_at)
                return -1;
@@ -1290,18 +1294,18 @@ segment_cmp (Segment *s1,
  */
 static void
 add_invalid (GtkSourceContextEngine *ce,
-             Segment                *segment)
+            Segment                *segment)
 {
 #ifdef ENABLE_CHECK_TREE
-       g_assert (!g_slist_find (ce->invalid, segment));
+       g_assert (!g_slist_find (ce->priv->invalid, segment));
 #endif
        g_return_if_fail (SEGMENT_IS_INVALID (segment));
 
-       ce->invalid = g_slist_insert_sorted (ce->invalid,
+       ce->priv->invalid = g_slist_insert_sorted (ce->priv->invalid,
                                                   segment,
                                                   (GCompareFunc) segment_cmp);
 
-       DEBUG (g_print ("%d invalid\n", g_slist_length (ce->invalid)));
+       DEBUG (g_print ("%d invalid\n", g_slist_length (ce->priv->invalid)));
 }
 
 /**
@@ -1315,12 +1319,12 @@ add_invalid (GtkSourceContextEngine *ce,
  */
 static void
 remove_invalid (GtkSourceContextEngine *ce,
-                Segment                *segment)
+               Segment                *segment)
 {
 #ifdef ENABLE_CHECK_TREE
-       g_assert (g_slist_find (ce->invalid, segment) != NULL);
+       g_assert (g_slist_find (ce->priv->invalid, segment) != NULL);
 #endif
-       ce->invalid = g_slist_remove (ce->invalid, segment);
+       ce->priv->invalid = g_slist_remove (ce->priv->invalid, segment);
 }
 
 /**
@@ -1334,8 +1338,8 @@ remove_invalid (GtkSourceContextEngine *ce,
  */
 static void
 fix_offsets_insert_ (Segment *segment,
-                     gint     start,
-                     gint     delta)
+                    gint     start,
+                    gint     delta)
 {
        Segment *child;
        SubPattern *sp;
@@ -1372,11 +1376,11 @@ fix_offsets_insert_ (Segment *segment,
  */
 static void
 find_insertion_place_forward_ (Segment  *segment,
-                               gint      offset,
-                               Segment  *start,
-                               Segment **parent,
-                               Segment **prev,
-                               Segment **next)
+                              gint      offset,
+                              Segment  *start,
+                              Segment **parent,
+                              Segment **prev,
+                              Segment **next)
 {
        Segment *child;
 
@@ -1440,11 +1444,11 @@ find_insertion_place_forward_ (Segment  *segment,
  */
 static void
 find_insertion_place_backward_ (Segment  *segment,
-                                gint      offset,
-                                Segment  *start,
-                                Segment **parent,
-                                Segment **prev,
-                                Segment **next)
+                               gint      offset,
+                               Segment  *start,
+                               Segment **parent,
+                               Segment **prev,
+                               Segment **next)
 {
        Segment *child;
 
@@ -1514,11 +1518,11 @@ find_insertion_place_backward_ (Segment  *segment,
  */
 static void
 find_insertion_place (Segment  *segment,
-                      gint      offset,
-                      Segment **parent,
-                      Segment **prev,
-                      Segment **next,
-                      Segment  *hint)
+                     gint      offset,
+                     Segment **parent,
+                     Segment **prev,
+                     Segment **next,
+                     Segment  *hint)
 {
        g_assert (segment->start_at <= offset && segment->end_at >= offset);
 
@@ -1570,9 +1574,9 @@ find_insertion_place (Segment  *segment,
  */
 static Segment *
 get_invalid_at (GtkSourceContextEngine *ce,
-                gint                    offset)
+               gint                    offset)
 {
-       GSList *link = ce->invalid;
+       GSList *link = ce->priv->invalid;
 
        while (link != NULL)
        {
@@ -1601,7 +1605,7 @@ get_invalid_at (GtkSourceContextEngine *ce,
  */
 static void
 segment_add_subpattern (Segment    *state,
-                        SubPattern *sp)
+                       SubPattern *sp)
 {
        sp->next = state->sub_patterns;
        state->sub_patterns = sp;
@@ -1621,9 +1625,9 @@ segment_add_subpattern (Segment    *state,
  */
 static SubPattern *
 sub_pattern_new (Segment              *segment,
-                 gint                  start_at,
-                 gint                  end_at,
-                 SubPatternDefinition *sp_def)
+                gint                  start_at,
+                gint                  end_at,
+                SubPatternDefinition *sp_def)
 {
        SubPattern *sp;
 
@@ -1662,7 +1666,7 @@ sub_pattern_free (SubPattern *sp)
  */
 static void
 segment_make_invalid_ (GtkSourceContextEngine *ce,
-                       Segment                *segment)
+                      Segment                *segment)
 {
        Context *ctx;
        SubPattern *sp;
@@ -1702,8 +1706,8 @@ segment_make_invalid_ (GtkSourceContextEngine *ce,
  */
 static Segment *
 simple_segment_split_ (GtkSourceContextEngine *ce,
-                       Segment                *segment,
-                       gint                    offset)
+                      Segment                *segment,
+                      gint                    offset)
 {
        SubPattern *sp;
        Segment *new_segment, *invalid;
@@ -1763,11 +1767,11 @@ simple_segment_split_ (GtkSourceContextEngine *ce,
  */
 static void
 invalidate_region (GtkSourceContextEngine *ce,
-                   gint                    offset,
-                   gint                    length)
+                  gint                    offset,
+                  gint                    length)
 {
-       InvalidRegion *region = &ce->invalid_region;
-       GtkTextBuffer *buffer = ce->buffer;
+       InvalidRegion *region = &ce->priv->invalid_region;
+       GtkTextBuffer *buffer = ce->priv->buffer;
        GtkTextIter iter;
        gint end_offset;
 
@@ -1835,8 +1839,8 @@ invalidate_region (GtkSourceContextEngine *ce,
  */
 static void
 insert_range (GtkSourceContextEngine *ce,
-              gint                    offset,
-              gint                    length)
+             gint                    offset,
+             gint                    length)
 {
        Segment *parent, *prev = NULL, *next = NULL, *new_segment;
        Segment *segment;
@@ -1848,9 +1852,9 @@ insert_range (GtkSourceContextEngine *ce,
        parent = get_invalid_at (ce, offset);
 
        if (parent == NULL)
-               find_insertion_place (ce->root_segment, offset,
+               find_insertion_place (ce->priv->root_segment, offset,
                                      &parent, &prev, &next,
-                                     ce->hint);
+                                     ce->priv->hint);
 
        g_assert (parent->start_at <= offset);
        g_assert (parent->end_at >= offset);
@@ -1947,13 +1951,13 @@ insert_range (GtkSourceContextEngine *ce,
  */
 static void
 gtk_source_context_engine_text_inserted (GtkSourceEngine *engine,
-                                         gint             start_offset,
-                                         gint             end_offset)
+                                        gint             start_offset,
+                                        gint             end_offset)
 {
        GtkTextIter iter;
        GtkSourceContextEngine *ce = GTK_SOURCE_CONTEXT_ENGINE (engine);
 
-       if (!ce->disabled)
+       if (!ce->priv->disabled)
        {
                g_return_if_fail (start_offset < end_offset);
 
@@ -1964,7 +1968,7 @@ gtk_source_context_engine_text_inserted (GtkSourceEngine *engine,
                 * highlighted because the engine analyzes the previous line, end
                 * context there is none, start context at this line is none too,
                 * and the engine stops. */
-               gtk_text_buffer_get_iter_at_offset (ce->buffer, &iter, end_offset);
+               gtk_text_buffer_get_iter_at_offset (ce->priv->buffer, &iter, end_offset);
                if (gtk_text_iter_starts_line (&iter) && !gtk_text_iter_ends_line (&iter))
                {
                        gtk_text_iter_forward_to_line_end (&iter);
@@ -1985,8 +1989,8 @@ gtk_source_context_engine_text_inserted (GtkSourceEngine *engine,
  */
 static inline gint
 fix_offset_delete_one_ (gint offset,
-                        gint start,
-                        gint length)
+                       gint start,
+                       gint length)
 {
        if (offset > start)
        {
@@ -2011,9 +2015,9 @@ fix_offset_delete_one_ (gint offset,
  */
 static void
 fix_offsets_delete_ (Segment *segment,
-                     gint     offset,
-                     gint     length,
-                     Segment *hint)
+                    gint     offset,
+                    gint     length,
+                    Segment *hint)
 {
        Segment *child;
        SubPattern *sp;
@@ -2063,14 +2067,14 @@ fix_offsets_delete_ (Segment *segment,
  */
 static void
 delete_range_ (GtkSourceContextEngine *ce,
-               gint                    start,
-               gint                    end)
+              gint                    start,
+              gint                    end)
 {
        g_return_if_fail (start < end);
 
        /* FIXME adjacent invalid segments? */
        erase_segments (ce, start, end, NULL);
-       fix_offsets_delete_ (ce->root_segment, start, end - start, ce->hint);
+       fix_offsets_delete_ (ce->priv->root_segment, start, end - start, ce->priv->hint);
 
        /* no need to invalidate at start, update_tree will do it */
 
@@ -2087,14 +2091,14 @@ delete_range_ (GtkSourceContextEngine *ce,
  */
 static void
 gtk_source_context_engine_text_deleted (GtkSourceEngine *engine,
-                                        gint             offset,
-                                        gint             length)
+                                       gint             offset,
+                                       gint             length)
 {
        GtkSourceContextEngine *ce = GTK_SOURCE_CONTEXT_ENGINE (engine);
 
        g_return_if_fail (length > 0);
 
-       if (!ce->disabled)
+       if (!ce->priv->disabled)
        {
                invalidate_region (ce, offset, - length);
        }
@@ -2109,8 +2113,8 @@ gtk_source_context_engine_text_deleted (GtkSourceEngine *engine,
 static Segment *
 get_invalid_segment (GtkSourceContextEngine *ce)
 {
-       g_return_val_if_fail (ce->invalid_region.empty, NULL);
-       return ce->invalid ? ce->invalid->data : NULL;
+       g_return_val_if_fail (ce->priv->invalid_region.empty, NULL);
+       return ce->priv->invalid ? ce->priv->invalid->data : NULL;
 }
 
 /**
@@ -2125,26 +2129,26 @@ get_invalid_line (GtkSourceContextEngine *ce)
        GtkTextIter iter;
        gint offset = G_MAXINT;
 
-       if (!ce->invalid_region.empty)
+       if (!ce->priv->invalid_region.empty)
        {
                gint tmp;
-               gtk_text_buffer_get_iter_at_mark (ce->buffer,
+               gtk_text_buffer_get_iter_at_mark (ce->priv->buffer,
                                                  &iter,
-                                                 ce->invalid_region.start);
+                                                 ce->priv->invalid_region.start);
                tmp = gtk_text_iter_get_offset (&iter);
                offset = MIN (offset, tmp);
        }
 
-       if (ce->invalid)
+       if (ce->priv->invalid)
        {
-               Segment *segment = ce->invalid->data;
+               Segment *segment = ce->priv->invalid->data;
                offset = MIN (offset, segment->start_at);
        }
 
        if (offset == G_MAXINT)
                return -1;
 
-       gtk_text_buffer_get_iter_at_offset (ce->buffer, &iter, offset);
+       gtk_text_buffer_get_iter_at_offset (ce->priv->buffer, &iter, offset);
        return gtk_text_iter_get_line (&iter);
 }
 
@@ -2157,7 +2161,7 @@ get_invalid_line (GtkSourceContextEngine *ce)
 static void
 update_tree (GtkSourceContextEngine *ce)
 {
-       InvalidRegion *region = &ce->invalid_region;
+       InvalidRegion *region = &ce->priv->invalid_region;
        gint start, end, delta;
        gint erase_start, erase_end;
        GtkTextIter iter;
@@ -2165,9 +2169,9 @@ update_tree (GtkSourceContextEngine *ce)
        if (region->empty)
                return;
 
-       gtk_text_buffer_get_iter_at_mark (ce->buffer, &iter, region->start);
+       gtk_text_buffer_get_iter_at_mark (ce->priv->buffer, &iter, region->start);
        start = gtk_text_iter_get_offset (&iter);
-       gtk_text_buffer_get_iter_at_mark (ce->buffer, &iter, region->end);
+       gtk_text_buffer_get_iter_at_mark (ce->priv->buffer, &iter, region->end);
        end = gtk_text_iter_get_offset (&iter);
 
        delta = region->delta;
@@ -2199,7 +2203,7 @@ update_tree (GtkSourceContextEngine *ce)
        if (erase_start < erase_end)
        {
                erase_segments (ce, erase_start, erase_end, NULL);
-               create_segment (ce, ce->root_segment, NULL, erase_start, erase_end, FALSE, NULL);
+               create_segment (ce, ce->priv->root_segment, NULL, erase_start, erase_end, FALSE, NULL);
        }
        else if (get_invalid_at (ce, start) == NULL)
        {
@@ -2229,15 +2233,15 @@ update_tree (GtkSourceContextEngine *ce)
  */
 static void
 gtk_source_context_engine_update_highlight (GtkSourceEngine   *engine,
-                                            const GtkTextIter *start,
-                                            const GtkTextIter *end,
-                                            gboolean           synchronous)
+                                           const GtkTextIter *start,
+                                           const GtkTextIter *end,
+                                           gboolean           synchronous)
 {
        gint invalid_line;
        gint end_line;
        GtkSourceContextEngine *ce = GTK_SOURCE_CONTEXT_ENGINE (engine);
 
-       if (!ce->highlight || ce->disabled)
+       if (!ce->priv->highlight || ce->priv->disabled)
                return;
 
        invalid_line = get_invalid_line (ce);
@@ -2281,20 +2285,20 @@ gtk_source_context_engine_update_highlight (GtkSourceEngine   *engine,
  */
 static void
 enable_highlight (GtkSourceContextEngine *ce,
-                  gboolean                enable)
+                 gboolean                enable)
 {
        GtkTextIter start, end;
 
-       if (!enable == !ce->highlight)
+       if (!enable == !ce->priv->highlight)
                return;
 
-       ce->highlight = enable != 0;
-       gtk_text_buffer_get_bounds (GTK_TEXT_BUFFER (ce->buffer),
+       ce->priv->highlight = enable != 0;
+       gtk_text_buffer_get_bounds (GTK_TEXT_BUFFER (ce->priv->buffer),
                                    &start, &end);
 
        if (enable)
        {
-               gtk_source_region_add_subregion (ce->refresh_region, &start, &end);
+               gtk_source_region_add_subregion (ce->priv->refresh_region, &start, &end);
 
                refresh_range (ce, &start, &end);
        }
@@ -2309,7 +2313,7 @@ buffer_notify_highlight_syntax_cb (GtkSourceContextEngine *ce)
 {
        gboolean highlight;
 
-       g_object_get (ce->buffer, "highlight-syntax", &highlight, NULL);
+       g_object_get (ce->priv->buffer, "highlight-syntax", &highlight, NULL);
        enable_highlight (ce, highlight);
 }
 
@@ -2325,7 +2329,7 @@ buffer_notify_highlight_syntax_cb (GtkSourceContextEngine *ce)
 static gboolean
 all_analyzed (GtkSourceContextEngine *ce)
 {
-       return ce->invalid == NULL && ce->invalid_region.empty;
+       return ce->priv->invalid == NULL && ce->priv->invalid_region.empty;
 }
 
 /**
@@ -2340,7 +2344,7 @@ idle_worker (GtkSourceContextEngine *ce)
 {
        gboolean retval = G_SOURCE_CONTINUE;
 
-       g_return_val_if_fail (ce->buffer != NULL, G_SOURCE_REMOVE);
+       g_return_val_if_fail (ce->priv->buffer != NULL, G_SOURCE_REMOVE);
 
        /* analyze batch of text */
        update_syntax (ce, NULL, INCREMENTAL_UPDATE_TIME_SLICE);
@@ -2348,7 +2352,7 @@ idle_worker (GtkSourceContextEngine *ce)
 
        if (all_analyzed (ce))
        {
-               ce->incremental_update = 0;
+               ce->priv->incremental_update = 0;
                retval = G_SOURCE_REMOVE;
        }
 
@@ -2365,13 +2369,13 @@ idle_worker (GtkSourceContextEngine *ce)
 static gboolean
 first_update_callback (GtkSourceContextEngine *ce)
 {
-       g_return_val_if_fail (ce->buffer != NULL, G_SOURCE_REMOVE);
+       g_return_val_if_fail (ce->priv->buffer != NULL, G_SOURCE_REMOVE);
 
        /* analyze batch of text */
        update_syntax (ce, NULL, FIRST_UPDATE_TIME_SLICE);
        CHECK_TREE (ce);
 
-       ce->first_update = 0;
+       ce->priv->first_update = 0;
 
        if (!all_analyzed (ce))
                install_idle_worker (ce);
@@ -2389,10 +2393,12 @@ first_update_callback (GtkSourceContextEngine *ce)
 static void
 install_idle_worker (GtkSourceContextEngine *ce)
 {
-       if (ce->first_update == 0 && ce->incremental_update == 0)
-               ce->incremental_update =
-                       gdk_threads_add_idle_full (INCREMENTAL_UPDATE_PRIORITY,
-                                                  (GSourceFunc) idle_worker, ce, NULL);
+       if (ce->priv->first_update == 0 && ce->priv->incremental_update == 0)
+               ce->priv->incremental_update =
+                       g_idle_add_full (INCREMENTAL_UPDATE_PRIORITY,
+                                        (GSourceFunc) idle_worker,
+                                        ce,
+                                        NULL);
 }
 
 /**
@@ -2405,18 +2411,19 @@ install_idle_worker (GtkSourceContextEngine *ce)
 static void
 install_first_update (GtkSourceContextEngine *ce)
 {
-       if (ce->first_update == 0)
+       if (ce->priv->first_update == 0)
        {
-               if (ce->incremental_update != 0)
+               if (ce->priv->incremental_update != 0)
                {
-                       g_source_remove (ce->incremental_update);
-                       ce->incremental_update = 0;
+                       g_source_remove (ce->priv->incremental_update);
+                       ce->priv->incremental_update = 0;
                }
 
-               ce->first_update =
-                       gdk_threads_add_idle_full (FIRST_UPDATE_PRIORITY,
-                                                  (GSourceFunc) first_update_callback,
-                                                  ce, NULL);
+               ce->priv->first_update =
+                       g_idle_add_full (FIRST_UPDATE_PRIORITY,
+                                        (GSourceFunc) first_update_callback,
+                                        ce,
+                                        NULL);
        }
 }
 
@@ -2425,10 +2432,11 @@ install_first_update (GtkSourceContextEngine *ce)
 static void _gtk_source_engine_interface_init (GtkSourceEngineInterface *iface);
 
 G_DEFINE_TYPE_WITH_CODE (GtkSourceContextEngine,
-                         _gtk_source_context_engine,
-                         G_TYPE_OBJECT,
-                         G_IMPLEMENT_INTERFACE (GTK_SOURCE_TYPE_ENGINE,
-                                                _gtk_source_engine_interface_init))
+                        _gtk_source_context_engine,
+                        G_TYPE_OBJECT,
+                        G_ADD_PRIVATE (GtkSourceContextEngine)
+                        G_IMPLEMENT_INTERFACE (GTK_SOURCE_TYPE_ENGINE,
+                                               _gtk_source_engine_interface_init))
 
 static GQuark
 gtk_source_context_engine_error_quark (void)
@@ -2441,8 +2449,8 @@ gtk_source_context_engine_error_quark (void)
 
 static void
 remove_tags_hash_cb (G_GNUC_UNUSED gpointer  style,
-                     GSList                 *tags,
-                     GtkTextTagTable        *table)
+                    GSList                 *tags,
+                    GtkTextTagTable        *table)
 {
        GSList *l = tags;
 
@@ -2465,10 +2473,10 @@ remove_tags_hash_cb (G_GNUC_UNUSED gpointer  style,
 static void
 destroy_tags_hash (GtkSourceContextEngine *ce)
 {
-       g_hash_table_foreach (ce->tags, (GHFunc) remove_tags_hash_cb,
-                              gtk_text_buffer_get_tag_table (ce->buffer));
-       g_hash_table_destroy (ce->tags);
-       ce->tags = NULL;
+       g_hash_table_foreach (ce->priv->tags, (GHFunc) remove_tags_hash_cb,
+                              gtk_text_buffer_get_tag_table (ce->priv->buffer));
+       g_hash_table_destroy (ce->priv->tags);
+       ce->priv->tags = NULL;
 }
 
 static void
@@ -2477,9 +2485,9 @@ destroy_context_classes_list (GtkSourceContextEngine *ce)
        GtkTextTagTable *table;
        GSList *l;
 
-       table = gtk_text_buffer_get_tag_table (ce->buffer);
+       table = gtk_text_buffer_get_tag_table (ce->priv->buffer);
 
-       for (l = ce->context_classes; l != NULL; l = l->next)
+       for (l = ce->priv->context_classes; l != NULL; l = l->next)
        {
                GtkTextTag *tag = l->data;
 
@@ -2487,8 +2495,8 @@ destroy_context_classes_list (GtkSourceContextEngine *ce)
                g_object_unref (tag);
        }
 
-       g_slist_free (ce->context_classes);
-       ce->context_classes = NULL;
+       g_slist_free (ce->priv->context_classes);
+       ce->priv->context_classes = NULL;
 }
 
 /**
@@ -2501,47 +2509,47 @@ destroy_context_classes_list (GtkSourceContextEngine *ce)
  */
 static void
 gtk_source_context_engine_attach_buffer (GtkSourceEngine *engine,
-                                         GtkTextBuffer   *buffer)
+                                        GtkTextBuffer   *buffer)
 {
        GtkSourceContextEngine *ce = GTK_SOURCE_CONTEXT_ENGINE (engine);
 
        g_return_if_fail (!buffer || GTK_IS_TEXT_BUFFER (buffer));
 
-       if (ce->buffer == buffer)
+       if (ce->priv->buffer == buffer)
                return;
 
        /* Detach previous buffer if there is one. */
-       if (ce->buffer != NULL)
+       if (ce->priv->buffer != NULL)
        {
-               g_signal_handlers_disconnect_by_func (ce->buffer,
+               g_signal_handlers_disconnect_by_func (ce->priv->buffer,
                                                      (gpointer) buffer_notify_highlight_syntax_cb,
                                                      ce);
 
-               if (ce->first_update != 0)
-                       g_source_remove (ce->first_update);
-               if (ce->incremental_update != 0)
-                       g_source_remove (ce->incremental_update);
-               ce->first_update = 0;
-               ce->incremental_update = 0;
-
-               if (ce->root_segment != NULL)
-                       segment_destroy (ce, ce->root_segment);
-               if (ce->root_context != NULL)
-                       context_unref (ce->root_context);
-               g_assert (!ce->invalid);
-               g_slist_free (ce->invalid);
-               ce->root_segment = NULL;
-               ce->root_context = NULL;
-               ce->invalid = NULL;
-
-               if (ce->invalid_region.start != NULL)
-                       gtk_text_buffer_delete_mark (ce->buffer,
-                                                    ce->invalid_region.start);
-               if (ce->invalid_region.end != NULL)
-                       gtk_text_buffer_delete_mark (ce->buffer,
-                                                    ce->invalid_region.end);
-               ce->invalid_region.start = NULL;
-               ce->invalid_region.end = NULL;
+               if (ce->priv->first_update != 0)
+                       g_source_remove (ce->priv->first_update);
+               if (ce->priv->incremental_update != 0)
+                       g_source_remove (ce->priv->incremental_update);
+               ce->priv->first_update = 0;
+               ce->priv->incremental_update = 0;
+
+               if (ce->priv->root_segment != NULL)
+                       segment_destroy (ce, ce->priv->root_segment);
+               if (ce->priv->root_context != NULL)
+                       context_unref (ce->priv->root_context);
+               g_assert (!ce->priv->invalid);
+               g_slist_free (ce->priv->invalid);
+               ce->priv->root_segment = NULL;
+               ce->priv->root_context = NULL;
+               ce->priv->invalid = NULL;
+
+               if (ce->priv->invalid_region.start != NULL)
+                       gtk_text_buffer_delete_mark (ce->priv->buffer,
+                                                    ce->priv->invalid_region.start);
+               if (ce->priv->invalid_region.end != NULL)
+                       gtk_text_buffer_delete_mark (ce->priv->buffer,
+                                                    ce->priv->invalid_region.end);
+               ce->priv->invalid_region.start = NULL;
+               ce->priv->invalid_region.end = NULL;
 
                /* this deletes tags from the tag table, therefore there is no need
                 * in removing tags from the text (it may be very slow).
@@ -2550,51 +2558,51 @@ gtk_source_context_engine_attach_buffer (GtkSourceEngine *engine,
                 * nothing. Caveat: if tag table is shared with other buffer, we do
                 * need to remove tags. */
                destroy_tags_hash (ce);
-               ce->n_tags = 0;
+               ce->priv->n_tags = 0;
 
                destroy_context_classes_list (ce);
 
-               g_clear_object (&ce->refresh_region);
+               g_clear_object (&ce->priv->refresh_region);
        }
 
-       ce->buffer = buffer;
+       ce->priv->buffer = buffer;
 
        if (buffer != NULL)
        {
                ContextDefinition *main_definition;
                GtkTextIter start, end;
 
-               main_definition = gtk_source_context_data_lookup_root (ce->ctx_data);
+               main_definition = gtk_source_context_data_lookup_root (ce->priv->ctx_data);
 
                /* If we don't abort here, we will crash later (#485661). But it should
                 * never happen, _gtk_source_context_data_finish_parse checks main context. */
                g_assert (main_definition != NULL);
 
-               ce->root_context = context_new (NULL, main_definition, NULL, NULL, FALSE);
-               ce->root_segment = create_segment (ce, NULL, ce->root_context, 0, 0, TRUE, NULL);
+               ce->priv->root_context = context_new (NULL, main_definition, NULL, NULL, FALSE);
+               ce->priv->root_segment = create_segment (ce, NULL, ce->priv->root_context, 0, 0, TRUE, NULL);
 
-               ce->tags = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
-               ce->context_classes = NULL;
+               ce->priv->tags = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
+               ce->priv->context_classes = NULL;
 
                gtk_text_buffer_get_bounds (buffer, &start, &end);
-               ce->invalid_region.start = gtk_text_buffer_create_mark (buffer, NULL,
+               ce->priv->invalid_region.start = gtk_text_buffer_create_mark (buffer, NULL,
                                                                              &start, TRUE);
-               ce->invalid_region.end = gtk_text_buffer_create_mark (buffer, NULL,
+               ce->priv->invalid_region.end = gtk_text_buffer_create_mark (buffer, NULL,
                                                                            &end, FALSE);
 
                if (gtk_text_buffer_get_char_count (buffer) != 0)
                {
-                       ce->invalid_region.empty = FALSE;
-                       ce->invalid_region.delta = gtk_text_buffer_get_char_count (buffer);
+                       ce->priv->invalid_region.empty = FALSE;
+                       ce->priv->invalid_region.delta = gtk_text_buffer_get_char_count (buffer);
                }
                else
                {
-                       ce->invalid_region.empty = TRUE;
-                       ce->invalid_region.delta = 0;
+                       ce->priv->invalid_region.empty = TRUE;
+                       ce->priv->invalid_region.delta = 0;
                }
 
-               g_object_get (buffer, "highlight-syntax", &ce->highlight, NULL);
-               ce->refresh_region = gtk_source_region_new (buffer);
+               g_object_get (buffer, "highlight-syntax", &ce->priv->highlight, NULL);
+               ce->priv->refresh_region = gtk_source_region_new (buffer);
 
                g_signal_connect_swapped (buffer,
                                          "notify::highlight-syntax",
@@ -2616,9 +2624,9 @@ gtk_source_context_engine_attach_buffer (GtkSourceEngine *engine,
 static void
 disable_syntax_analysis (GtkSourceContextEngine *ce)
 {
-       if (!ce->disabled)
+       if (!ce->priv->disabled)
        {
-               ce->disabled = TRUE;
+               ce->priv->disabled = TRUE;
                gtk_source_context_engine_attach_buffer (GTK_SOURCE_ENGINE (ce), NULL);
                /* FIXME maybe emit some signal here? */
        }
@@ -2626,8 +2634,8 @@ disable_syntax_analysis (GtkSourceContextEngine *ce)
 
 static void
 set_tag_style_hash_cb (const char             *style,
-                       GSList                 *tags,
-                       GtkSourceContextEngine *ce)
+                      GSList                 *tags,
+                      GtkSourceContextEngine *ce)
 {
        while (tags != NULL)
        {
@@ -2646,7 +2654,7 @@ set_tag_style_hash_cb (const char             *style,
  */
 static void
 gtk_source_context_engine_set_style_scheme (GtkSourceEngine      *engine,
-                                            GtkSourceStyleScheme *scheme)
+                                           GtkSourceStyleScheme *scheme)
 {
        GtkSourceContextEngine *ce;
 
@@ -2655,9 +2663,9 @@ gtk_source_context_engine_set_style_scheme (GtkSourceEngine      *engine,
 
        ce = GTK_SOURCE_CONTEXT_ENGINE (engine);
 
-       if (g_set_object (&ce->style_scheme, scheme))
+       if (g_set_object (&ce->priv->style_scheme, scheme))
        {
-               g_hash_table_foreach (ce->tags, (GHFunc) set_tag_style_hash_cb, ce);
+               g_hash_table_foreach (ce->priv->tags, (GHFunc) set_tag_style_hash_cb, ce);
        }
 }
 
@@ -2666,7 +2674,7 @@ gtk_source_context_engine_finalize (GObject *object)
 {
        GtkSourceContextEngine *ce = GTK_SOURCE_CONTEXT_ENGINE (object);
 
-       if (ce->buffer != NULL)
+       if (ce->priv->buffer != NULL)
        {
                g_critical ("finalizing engine with attached buffer");
                /* Disconnect the buffer (if there is one), which destroys almost
@@ -2674,26 +2682,26 @@ gtk_source_context_engine_finalize (GObject *object)
                gtk_source_context_engine_attach_buffer (GTK_SOURCE_ENGINE (ce), NULL);
        }
 
-       g_assert (!ce->tags);
-       g_assert (!ce->root_context);
-       g_assert (!ce->root_segment);
+       g_assert (!ce->priv->tags);
+       g_assert (!ce->priv->root_context);
+       g_assert (!ce->priv->root_segment);
 
-       if (ce->first_update != 0)
+       if (ce->priv->first_update != 0)
        {
-               g_source_remove (ce->first_update);
-               ce->first_update = 0;
+               g_source_remove (ce->priv->first_update);
+               ce->priv->first_update = 0;
        }
 
-       if (ce->incremental_update != 0)
+       if (ce->priv->incremental_update != 0)
        {
-               g_source_remove (ce->incremental_update);
-               ce->incremental_update = 0;
+               g_source_remove (ce->priv->incremental_update);
+               ce->priv->incremental_update = 0;
        }
 
-       _gtk_source_context_data_unref (ce->ctx_data);
+       _gtk_source_context_data_unref (ce->priv->ctx_data);
 
-       if (ce->style_scheme != NULL)
-               g_object_unref (ce->style_scheme);
+       if (ce->priv->style_scheme != NULL)
+               g_object_unref (ce->priv->style_scheme);
 
        G_OBJECT_CLASS (_gtk_source_context_engine_parent_class)->finalize (object);
 }
@@ -2719,7 +2727,7 @@ _gtk_source_context_engine_class_init (GtkSourceContextEngineClass *klass)
 static void
 _gtk_source_context_engine_init (GtkSourceContextEngine *ce)
 {
-       ce = _gtk_source_context_engine_get_instance_private (ce);
+       ce->priv = _gtk_source_context_engine_get_instance_private (ce);
 }
 
 GtkSourceContextEngine *
@@ -2731,7 +2739,7 @@ _gtk_source_context_engine_new (GtkSourceContextData *ctx_data)
        g_return_val_if_fail (ctx_data->lang != NULL, NULL);
 
        ce = g_object_new (GTK_SOURCE_TYPE_CONTEXT_ENGINE, NULL);
-       ce->ctx_data = _gtk_source_context_data_ref (ctx_data);
+       ce->priv->ctx_data = _gtk_source_context_data_ref (ctx_data);
 
        return ce;
 }
@@ -2740,7 +2748,7 @@ _gtk_source_context_engine_new (GtkSourceContextData *ctx_data)
  * _gtk_source_context_data_new:
  * @lang: #GtkSourceLanguage.
  *
- * Creates new context definition set. It does not set lang->ctx_data,
+ * Creates new context definition set. It does not set lang->priv->ctx_data,
  * that's lang business.
  */
 GtkSourceContextData *
@@ -2772,7 +2780,7 @@ _gtk_source_context_data_ref (GtkSourceContextData *ctx_data)
  * @ctx_data: #GtkSourceContextData.
  *
  * Decreases reference count in ctx_data. When reference count
- * drops to zero, ctx_data is freed, and ctx_data->lang->ctx_data
+ * drops to zero, ctx_data is freed, and ctx_data->lang->priv->ctx_data
  * is unset.
  */
 void
@@ -2782,8 +2790,9 @@ _gtk_source_context_data_unref (GtkSourceContextData *ctx_data)
 
        if (--ctx_data->ref_count == 0)
        {
-               if (ctx_data->lang != NULL)
-                       _gtk_source_language_clear_ctx_data (ctx_data->lang, ctx_data);
+               if (ctx_data->lang != NULL && ctx_data->lang->priv != NULL &&
+                   ctx_data->lang->priv->ctx_data == ctx_data)
+                       ctx_data->lang->priv->ctx_data = NULL;
                g_hash_table_destroy (ctx_data->definitions);
                g_slice_free (GtkSourceContextData, ctx_data);
        }
@@ -2805,9 +2814,9 @@ _gtk_source_context_data_unref (GtkSourceContextData *ctx_data)
  */
 static void
 apply_sub_patterns (Segment         *state,
-                    LineInfo        *line,
-                    GtkSourceRegex  *regex,
-                    SubPatternWhere  where)
+                   LineInfo        *line,
+                   GtkSourceRegex  *regex,
+                   SubPatternWhere  where)
 {
        GSList *sub_pattern_list = state->context->definition->sub_patterns;
 
@@ -2892,10 +2901,10 @@ apply_sub_patterns (Segment         *state,
  */
 static gboolean
 can_apply_match (Context        *state,
-                 LineInfo       *line,
-                 gint            match_start,
-                 gint           *match_end,
-                 GtkSourceRegex *regex)
+                LineInfo       *line,
+                gint            match_start,
+                gint           *match_end,
+                GtkSourceRegex *regex)
 {
        gint end_match_pos;
        gboolean ancestor_ends;
@@ -2953,7 +2962,7 @@ can_apply_match (Context        *state,
 
 static gint
 line_pos_to_offset (LineInfo *line,
-                    gint      pos)
+                   gint      pos)
 {
        if (line->char_length != line->byte_length)
                pos = g_utf8_pointer_to_offset (line->text, line->text + pos);
@@ -2980,10 +2989,10 @@ line_pos_to_offset (LineInfo *line,
  */
 static gboolean
 apply_match (Segment         *state,
-             LineInfo        *line,
-             gint            *line_pos,
-             GtkSourceRegex  *regex,
-             SubPatternWhere  where)
+            LineInfo        *line,
+            gint            *line_pos,
+            GtkSourceRegex  *regex,
+            SubPatternWhere  where)
 {
        gint match_end;
 
@@ -3018,7 +3027,7 @@ apply_match (Segment         *state,
  */
 static GtkSourceRegex *
 create_reg_all (Context           *context,
-                ContextDefinition *definition)
+               ContextDefinition *definition)
 {
        DefinitionsIter iter;
        DefinitionChild *child_def;
@@ -3153,10 +3162,10 @@ context_ref (Context *context)
 /* does not copy style */
 static Context *
 context_new (Context           *parent,
-             ContextDefinition *definition,
-             const gchar       *line_text,
-             const gchar       *style,
-             gboolean           ignore_children_style)
+            ContextDefinition *definition,
+            const gchar       *line_text,
+            const gchar       *style,
+            gboolean           ignore_children_style)
 {
        Context *context;
 
@@ -3224,8 +3233,8 @@ context_new (Context           *parent,
 
 static void
 context_unref_hash_cb (gpointer  text,
-                       Context  *context,
-                       gpointer  user_data)
+                      Context  *context,
+                      gpointer  user_data)
 {
        context->parent = NULL;
        context_unref (context);
@@ -3233,15 +3242,15 @@ context_unref_hash_cb (gpointer  text,
 
 static gboolean
 remove_context_cb (G_GNUC_UNUSED gpointer  text,
-                   Context                *context,
-                   Context                *target)
+                  Context                *context,
+                  Context                *target)
 {
        return context == target;
 }
 
 static void
 context_remove_child (Context *parent,
-                      Context *context)
+                     Context *context)
 {
        ContextPtr *ptr, *prev = NULL;
        gboolean delete = TRUE;
@@ -3357,8 +3366,8 @@ context_unref (Context *context)
 
 static void
 context_freeze_hash_cb (gpointer  text,
-                        Context  *context,
-                        gpointer  user_data)
+                       Context  *context,
+                       gpointer  user_data)
 {
        context_freeze (context);
 }
@@ -3407,15 +3416,15 @@ context_freeze (Context *ctx)
 
 static void
 get_child_contexts_hash_cb (G_GNUC_UNUSED gpointer   text,
-                            Context                 *context,
-                            GSList                 **list)
+                           Context                 *context,
+                           GSList                 **list)
 {
        *list = g_slist_prepend (*list, context);
 }
 
 static void
-context_thaw_cb (Context  *ctx,
-                 gpointer  user_data)
+context_thaw_cb (Context *ctx,
+                gpointer user_data)
 {
        context_thaw (ctx);
 }
@@ -3464,8 +3473,8 @@ context_thaw (Context *ctx)
 
 static Context *
 create_child_context (Context         *parent,
-                      DefinitionChild *child_def,
-                      const gchar     *line_text)
+                     DefinitionChild *child_def,
+                     const gchar     *line_text)
 {
        Context *context;
        ContextPtr *ptr;
@@ -3546,11 +3555,11 @@ create_child_context (Context         *parent,
  */
 static Segment *
 segment_new (GtkSourceContextEngine *ce,
-             Segment                *parent,
-             Context                *context,
-             gint                    start_at,
-             gint                    end_at,
-             gboolean                is_start)
+            Segment                *parent,
+            Context                *context,
+            gint                    start_at,
+            gint                    end_at,
+            gboolean                is_start)
 {
        Segment *segment;
 
@@ -3573,10 +3582,10 @@ segment_new (GtkSourceContextEngine *ce,
 
 static void
 find_segment_position_forward_ (Segment  *segment,
-                                gint      start_at,
-                                gint      end_at,
-                                Segment **prev,
-                                Segment **next)
+                               gint      start_at,
+                               gint      end_at,
+                               Segment **prev,
+                               Segment **next)
 {
        g_assert (segment->start_at <= start_at);
 
@@ -3615,10 +3624,10 @@ find_segment_position_forward_ (Segment  *segment,
 
 static void
 find_segment_position_backward_ (Segment  *segment,
-                                 gint      start_at,
-                                 gint      end_at,
-                                 Segment **prev,
-                                 Segment **next)
+                                gint      start_at,
+                                gint      end_at,
+                                Segment **prev,
+                                Segment **next)
 {
        g_assert (start_at < segment->end_at);
 
@@ -3652,11 +3661,11 @@ find_segment_position_backward_ (Segment  *segment,
  */
 static void
 find_segment_position (Segment  *parent,
-                       Segment  *hint,
-                       gint      start_at,
-                       gint      end_at,
-                       Segment **prev,
-                       Segment **next)
+                      Segment  *hint,
+                      gint      start_at,
+                      gint      end_at,
+                      Segment **prev,
+                      Segment **next)
 {
        Segment *tmp;
 
@@ -3705,12 +3714,12 @@ find_segment_position (Segment  *parent,
  */
 static Segment *
 create_segment (GtkSourceContextEngine *ce,
-                Segment                *parent,
-                Context                *context,
-                gint                    start_at,
-                gint                    end_at,
-                gboolean                is_start,
-                Segment                *hint)
+               Segment                *parent,
+               Context                *context,
+               gint                    start_at,
+               gint                    end_at,
+               gboolean                is_start,
+               Segment                *hint)
 {
        Segment *segment;
 
@@ -3724,7 +3733,7 @@ create_segment (GtkSourceContextEngine *ce,
 
                if (hint == NULL)
                {
-                       hint = ce->hint;
+                       hint = ce->priv->hint;
                        while (hint != NULL && hint->parent != parent)
                                hint = hint->parent;
                }
@@ -3767,7 +3776,7 @@ create_segment (GtkSourceContextEngine *ce,
  */
 static void
 segment_extend (Segment *state,
-                gint     end_at)
+               gint     end_at)
 {
        while (state != NULL && state->end_at < end_at)
        {
@@ -3779,7 +3788,7 @@ segment_extend (Segment *state,
 
 static void
 segment_destroy_children (GtkSourceContextEngine *ce,
-                          Segment                *segment)
+                         Segment                *segment)
 {
        Segment *child;
        SubPattern *sp;
@@ -3820,7 +3829,7 @@ segment_destroy_children (GtkSourceContextEngine *ce,
  */
 static void
 segment_destroy (GtkSourceContextEngine *ce,
-                 Segment                *segment)
+                Segment                *segment)
 {
        g_return_if_fail (segment != NULL);
 
@@ -3828,10 +3837,10 @@ segment_destroy (GtkSourceContextEngine *ce,
 
        /* segment neighbours and parent may be invalid here,
         * so we only can unset the hint */
-       if (ce->hint == segment)
-               ce->hint = NULL;
-        if (ce->hint2 == segment)
-                ce->hint2 = NULL;
+       if (ce->priv->hint == segment)
+               ce->priv->hint = NULL;
+        if (ce->priv->hint2 == segment)
+                ce->priv->hint2 = NULL;
 
        if (SEGMENT_IS_INVALID (segment))
                remove_invalid (ce, segment);
@@ -3839,7 +3848,7 @@ segment_destroy (GtkSourceContextEngine *ce,
        context_unref (segment->context);
 
 #ifdef ENABLE_DEBUG
-       g_assert (!g_slist_find (ce->invalid, segment));
+       g_assert (!g_slist_find (ce->priv->invalid, segment));
        memset (segment, 1, sizeof (Segment));
 #else
        g_slice_free (Segment, segment);
@@ -3853,11 +3862,11 @@ segment_destroy (GtkSourceContextEngine *ce,
  */
 static gboolean
 container_context_starts_here (GtkSourceContextEngine  *ce,
-                               Segment                 *state,
-                               DefinitionChild         *child_def,
-                               LineInfo                *line,
-                               gint                    *line_pos, /* bytes */
-                               Segment                **new_state)
+                              Segment                 *state,
+                              DefinitionChild         *child_def,
+                              LineInfo                *line,
+                              gint                    *line_pos, /* bytes */
+                              Segment                **new_state)
 {
        Context *new_context;
        Segment *new_segment;
@@ -3894,7 +3903,7 @@ container_context_starts_here (GtkSourceContextEngine  *ce,
                                      line_pos_to_offset (line, *line_pos),
                                      line_pos_to_offset (line, match_end),
                                      TRUE,
-                                     ce->hint2);
+                                     ce->priv->hint2);
 
        /* This new context could end at the same position (i.e. have zero length),
         * and then we get an infinite loop. We can't possibly know about it at this point
@@ -3917,7 +3926,7 @@ container_context_starts_here (GtkSourceContextEngine  *ce,
                            SUB_PATTERN_WHERE_START);
        *line_pos = match_end;
        *new_state = new_segment;
-       ce->hint2 = NULL;
+       ce->priv->hint2 = NULL;
        context_unref (new_context);
        return TRUE;
 }
@@ -3928,12 +3937,12 @@ container_context_starts_here (GtkSourceContextEngine  *ce,
  * See child_starts_here().
  */
 static gboolean
-simple_context_starts_here (GtkSourceContextEngine  *ce,
-                            Segment                 *state,
-                            DefinitionChild         *child_def,
-                            LineInfo                *line,
-                            gint                    *line_pos, /* bytes */
-                            Segment                **new_state)
+simple_context_starts_here (GtkSourceContextEngine *ce,
+                           Segment                *state,
+                           DefinitionChild        *child_def,
+                           LineInfo               *line,
+                           gint                   *line_pos, /* bytes */
+                           Segment               **new_state)
 {
        gint match_end;
        Context *new_context;
@@ -3985,9 +3994,9 @@ simple_context_starts_here (GtkSourceContextEngine  *ce,
                                              line_pos_to_offset (line, *line_pos),
                                              line_pos_to_offset (line, match_end),
                                              TRUE,
-                                             ce->hint2);
+                                             ce->priv->hint2);
                apply_sub_patterns (new_segment, line, definition->u.match, SUB_PATTERN_WHERE_DEFAULT);
-               ce->hint2 = new_segment;
+               ce->priv->hint2 = new_segment;
        }
 
        /* Terminate parent if needed */
@@ -3995,7 +4004,7 @@ simple_context_starts_here (GtkSourceContextEngine  *ce,
        {
                do
                {
-                       ce->hint2 = state;
+                       ce->priv->hint2 = state;
                        state = state->parent;
                }
                while (SEGMENT_ENDS_PARENT (state));
@@ -4024,11 +4033,11 @@ simple_context_starts_here (GtkSourceContextEngine  *ce,
  */
 static gboolean
 child_starts_here (GtkSourceContextEngine  *ce,
-                   Segment                 *state,
-                   DefinitionChild         *child_def,
-                   LineInfo                *line,
-                   gint                    *line_pos,
-                   Segment                **new_state)
+                  Segment                 *state,
+                  DefinitionChild         *child_def,
+                  LineInfo                *line,
+                  gint                    *line_pos,
+                  Segment                **new_state)
 {
        g_return_val_if_fail (child_def->resolved, FALSE);
 
@@ -4065,8 +4074,8 @@ child_starts_here (GtkSourceContextEngine  *ce,
  */
 static gboolean
 segment_ends_here (Segment  *state,
-                   LineInfo *line,
-                   gint      pos)
+                  LineInfo *line,
+                  gint      pos)
 {
        g_assert (SEGMENT_IS_CONTAINER (state));
 
@@ -4091,8 +4100,8 @@ segment_ends_here (Segment  *state,
  */
 static Context *
 ancestor_context_ends_here (Context  *state,
-                            LineInfo *line,
-                            gint      line_pos)
+                           LineInfo *line,
+                           gint      line_pos)
 {
        Context *current_context;
        GSList *current_context_list;
@@ -4154,9 +4163,9 @@ ancestor_context_ends_here (Context  *state,
  */
 static gboolean
 ancestor_ends_here (Segment   *state,
-                    LineInfo  *line,
-                    gint       line_pos,
-                    Segment  **new_state)
+                   LineInfo  *line,
+                   gint       line_pos,
+                   Segment  **new_state)
 {
        Context *terminating_context;
 
@@ -4195,14 +4204,14 @@ ancestor_ends_here (Segment   *state,
  */
 static gboolean
 next_segment (GtkSourceContextEngine  *ce,
-              Segment                 *state,
-              LineInfo                *line,
-              gint                    *line_pos,
-              Segment                **new_state)
+             Segment                 *state,
+             LineInfo                *line,
+             gint                    *line_pos,
+             Segment                **new_state)
 {
        gint pos = *line_pos;
 
-       g_assert (!ce->hint2 || ce->hint2->parent == state);
+       g_assert (!ce->priv->hint2 || ce->priv->hint2->parent == state);
        g_assert (pos <= line->byte_length);
 
        while (pos <= line->byte_length)
@@ -4305,7 +4314,7 @@ next_segment (GtkSourceContextEngine  *ce,
                                        state = state->parent;
 
                                *new_state = state->parent;
-                               ce->hint2 = state;
+                               ce->priv->hint2 = state;
                                *line_pos = pos;
                                return TRUE;
                        }
@@ -4330,12 +4339,12 @@ next_segment (GtkSourceContextEngine  *ce,
  */
 static Segment *
 check_line_end (GtkSourceContextEngine *ce,
-                Segment                *state)
+               Segment                *state)
 {
        Segment *current_segment;
        Segment *terminating_segment;
 
-       g_assert (!ce->hint2 || ce->hint2->parent == state);
+       g_assert (!ce->priv->hint2 || ce->priv->hint2->parent == state);
 
        /* A context can be terminated by the parent if extend_parent is
         * FALSE, so we need to verify the end of all the parents of
@@ -4354,7 +4363,7 @@ check_line_end (GtkSourceContextEngine *ce,
 
        if (terminating_segment != NULL)
        {
-               ce->hint2 = terminating_segment;
+               ce->priv->hint2 = terminating_segment;
                return terminating_segment->parent;
        }
        else
@@ -4365,7 +4374,7 @@ check_line_end (GtkSourceContextEngine *ce,
 
 static void
 delete_zero_length_segments (GtkSourceContextEngine *ce,
-                             GList                  *list)
+                            GList                  *list)
 {
        while (list != NULL)
        {
@@ -4398,9 +4407,9 @@ delete_zero_length_segments (GtkSourceContextEngine *ce,
                                l = next;
                        }
 
-                       if (ce->hint2 != NULL)
+                       if (ce->priv->hint2 != NULL)
                        {
-                               Segment *s2 = ce->hint2;
+                               Segment *s2 = ce->priv->hint2;
                                gboolean child = FALSE;
 
                                while (s2 != NULL)
@@ -4415,7 +4424,7 @@ delete_zero_length_segments (GtkSourceContextEngine *ce,
                                }
 
                                if (child)
-                                       ce->hint2 = s->parent;
+                                       ce->priv->hint2 = s->parent;
                        }
 
                        segment_remove (ce, s);
@@ -4438,8 +4447,8 @@ delete_zero_length_segments (GtkSourceContextEngine *ce,
  */
 static Segment *
 analyze_line (GtkSourceContextEngine *ce,
-              Segment                *state,
-              LineInfo               *line)
+             Segment                *state,
+             LineInfo               *line)
 {
        gint line_pos = 0;
        GList *end_segments = NULL;
@@ -4447,9 +4456,9 @@ analyze_line (GtkSourceContextEngine *ce,
 
        g_assert (SEGMENT_IS_CONTAINER (state));
 
-        if (ce->hint2 == NULL || ce->hint2->parent != state)
-                ce->hint2 = state->last_child;
-        g_assert (!ce->hint2 || ce->hint2->parent == state);
+        if (ce->priv->hint2 == NULL || ce->priv->hint2->parent != state)
+                ce->priv->hint2 = state->last_child;
+        g_assert (!ce->priv->hint2 || ce->priv->hint2->parent == state);
 
        timer = g_timer_new ();
 
@@ -4475,9 +4484,9 @@ analyze_line (GtkSourceContextEngine *ce,
 
                state = new_state;
 
-                if (ce->hint2 == NULL || ce->hint2->parent != state)
-                        ce->hint2 = state->last_child;
-                g_assert (!ce->hint2 || ce->hint2->parent == state);
+                if (ce->priv->hint2 == NULL || ce->priv->hint2->parent != state)
+                        ce->priv->hint2 = state->last_child;
+                g_assert (!ce->priv->hint2 || ce->priv->hint2->parent == state);
 
                /* XXX this a temporary workaround for zero-length segments in the end
                 * of line. there are no zero-length segments in the middle because it goes
@@ -4489,7 +4498,7 @@ analyze_line (GtkSourceContextEngine *ce,
        }
 
        g_timer_destroy (timer);
-       if (ce->disabled)
+       if (ce->priv->disabled)
                return NULL;
 
        /* Extend current state to the end of line. */
@@ -4532,9 +4541,9 @@ analyze_line (GtkSourceContextEngine *ce,
  */
 static void
 get_line_info (GtkTextBuffer     *buffer,
-               const GtkTextIter *line_start,
-               const GtkTextIter *line_end,
-               LineInfo          *line)
+              const GtkTextIter *line_start,
+              const GtkTextIter *line_end,
+              LineInfo          *line)
 {
        g_assert (!gtk_text_iter_equal (line_start, line_end));
 
@@ -4589,7 +4598,7 @@ line_info_destroy (LineInfo *line)
 static void
 segment_tree_zero_len (GtkSourceContextEngine *ce)
 {
-       Segment *root = ce->root_segment;
+       Segment *root = ce->priv->root_segment;
        segment_destroy_children (ce, root);
        root->start_at = root->end_at = 0;
        CHECK_TREE (ce);
@@ -4598,7 +4607,7 @@ segment_tree_zero_len (GtkSourceContextEngine *ce)
 #ifdef ENABLE_CHECK_TREE
 static Segment *
 get_segment_at_offset_slow_ (Segment *segment,
-                             gint     offset)
+                            gint     offset)
 {
        Segment *child;
 
@@ -4668,7 +4677,7 @@ start:
 #define SEGMENT_DISTANCE(s,o) (MIN (ABS ((s)->start_at - (o)), ABS ((s)->end_at - (o))))
 static Segment *
 get_segment_in_ (Segment *segment,
-                 gint     offset)
+                gint     offset)
 {
        Segment *child;
 
@@ -4730,7 +4739,7 @@ get_segment_in_ (Segment *segment,
 /* assumes zero-length segments can't have children */
 static Segment *
 get_segment_ (Segment *segment,
-              gint     offset)
+             gint     offset)
 {
        if (segment->parent != NULL)
        {
@@ -4822,26 +4831,26 @@ get_segment_ (Segment *segment,
  */
 static Segment *
 get_segment_at_offset (GtkSourceContextEngine *ce,
-                       Segment                *hint,
-                       gint                    offset)
+                      Segment                *hint,
+                      gint                    offset)
 {
        Segment *result;
 
-       if (offset == ce->root_segment->end_at)
-               return ce->root_segment;
+       if (offset == ce->priv->root_segment->end_at)
+               return ce->priv->root_segment;
 
 #ifdef ENABLE_DEBUG
        /* if you see this message (often), then something is
         * wrong with the hints business, i.e. optimizations
         * do not work quite like they should */
-       if (hint == NULL || hint == ce->root_segment)
+       if (hint == NULL || hint == ce->priv->root_segment)
        {
                static int c;
                g_print ("searching from root %d\n", ++c);
        }
 #endif
 
-       result = get_segment_ (hint ? hint : ce->root_segment, offset);
+       result = get_segment_ (hint ? hint : ce->priv->root_segment, offset);
 
 #ifdef ENABLE_CHECK_TREE
        g_assert (result == get_segment_at_offset_slow_ (hint, offset));
@@ -4862,7 +4871,7 @@ get_segment_at_offset (GtkSourceContextEngine *ce,
  */
 static void
 segment_remove (GtkSourceContextEngine *ce,
-                Segment                *segment)
+               Segment                *segment)
 {
        if (segment->next != NULL)
                segment->next->prev = segment->prev;
@@ -4874,28 +4883,28 @@ segment_remove (GtkSourceContextEngine *ce,
        else
                segment->parent->children = segment->next;
 
-       /* if ce->hint is being deleted, set it to some
+       /* if ce->priv->hint is being deleted, set it to some
         * neighbour segment */
-       if (ce->hint == segment)
+       if (ce->priv->hint == segment)
        {
                if (segment->next != NULL)
-                       ce->hint = segment->next;
+                       ce->priv->hint = segment->next;
                else if (segment->prev != NULL)
-                       ce->hint = segment->prev;
+                       ce->priv->hint = segment->prev;
                else
-                       ce->hint = segment->parent;
+                       ce->priv->hint = segment->parent;
        }
 
-        /* if ce->hint2 is being deleted, set it to some
+        /* if ce->priv->hint2 is being deleted, set it to some
          * neighbour segment */
-        if (ce->hint2 == segment)
+        if (ce->priv->hint2 == segment)
         {
                 if (segment->next != NULL)
-                        ce->hint2 = segment->next;
+                        ce->priv->hint2 = segment->next;
                 else if (segment->prev != NULL)
-                        ce->hint2 = segment->prev;
+                        ce->priv->hint2 = segment->prev;
                 else
-                        ce->hint2 = segment->parent;
+                        ce->priv->hint2 = segment->parent;
         }
 
        segment_destroy (ce, segment);
@@ -4903,9 +4912,9 @@ segment_remove (GtkSourceContextEngine *ce,
 
 static void
 segment_erase_middle_ (GtkSourceContextEngine *ce,
-                       Segment                *segment,
-                       gint                    start,
-                       gint                    end)
+                      Segment                *segment,
+                      gint                    start,
+                      gint                    end)
 {
        Segment *new_segment, *child;
        SubPattern *sp;
@@ -5013,9 +5022,9 @@ segment_erase_middle_ (GtkSourceContextEngine *ce,
  */
 static void
 segment_erase_range_ (GtkSourceContextEngine *ce,
-                      Segment                *segment,
-                      gint                    start,
-                      gint                    end)
+                     Segment                *segment,
+                     gint                    start,
+                     gint                    end)
 {
        g_assert (start < end);
 
@@ -5129,8 +5138,8 @@ segment_erase_range_ (GtkSourceContextEngine *ce,
  */
 static void
 segment_merge (GtkSourceContextEngine *ce,
-               Segment                *first,
-               Segment                *second)
+              Segment                *first,
+              Segment                *second)
 {
        Segment *parent;
 
@@ -5213,26 +5222,26 @@ segment_merge (GtkSourceContextEngine *ce,
  *
  * Erases all non-toplevel segments in the interval
  * [@start, @end]. Its action on the tree is roughly
- * equivalent to segment_erase_range_(ce->root_segment, start, end)
+ * equivalent to segment_erase_range_(ce->priv->root_segment, start, end)
  * (but that does not accept toplevel segment).
  */
 static void
 erase_segments (GtkSourceContextEngine *ce,
-                gint                    start,
-                gint                    end,
-                Segment                *hint)
+               gint                    start,
+               gint                    end,
+               Segment                *hint)
 {
-       Segment *root = ce->root_segment;
+       Segment *root = ce->priv->root_segment;
        Segment *child, *hint_prev;
 
        if (root->children == NULL)
                return;
 
        if (hint == NULL)
-               hint = ce->hint;
+               hint = ce->priv->hint;
 
        if (hint != NULL)
-               while (hint != NULL && hint->parent != ce->root_segment)
+               while (hint != NULL && hint->parent != ce->priv->root_segment)
                        hint = hint->parent;
 
        if (hint == NULL)
@@ -5250,14 +5259,14 @@ erase_segments (GtkSourceContextEngine *ce,
                        child = next;
 
                        if (next != NULL)
-                               ce->hint = next;
+                               ce->priv->hint = next;
 
                        continue;
                }
 
                if (child->start_at > end)
                {
-                       ce->hint = child;
+                       ce->priv->hint = child;
                        break;
                }
 
@@ -5270,8 +5279,8 @@ erase_segments (GtkSourceContextEngine *ce,
        {
                Segment *prev = child->prev;
 
-               if (ce->hint == NULL)
-                       ce->hint = child;
+               if (ce->priv->hint == NULL)
+                       ce->priv->hint = child;
 
                if (child->start_at > end)
                {
@@ -5311,8 +5320,8 @@ erase_segments (GtkSourceContextEngine *ce,
 /* TODO it must be refactored. */
 static void
 update_syntax (GtkSourceContextEngine *ce,
-               const GtkTextIter      *end,
-               gint                    time)
+              const GtkTextIter      *end,
+              gint                    time)
 {
        GtkTextBuffer *buffer;
        GtkTextIter start_iter, end_iter;
@@ -5325,10 +5334,10 @@ update_syntax (GtkSourceContextEngine *ce,
        gboolean first_line = FALSE;
        GTimer *timer;
 
-       buffer = ce->buffer;
-       state = ce->root_segment;
+       buffer = ce->priv->buffer;
+       state = ce->priv->root_segment;
 
-       context_freeze (ce->root_context);
+       context_freeze (ce->priv->root_context);
        update_tree (ce);
 
        if (!gtk_text_buffer_get_char_count (buffer))
@@ -5393,7 +5402,7 @@ update_syntax (GtkSourceContextEngine *ce,
        if (start_offset == end_offset)
        {
                g_assert (end_offset == gtk_text_buffer_get_char_count (buffer));
-               g_assert (g_slist_length (ce->invalid) == 1);
+               g_assert (g_slist_length (ce->priv->invalid) == 1);
                segment_remove (ce, invalid);
                CHECK_TREE (ce);
                goto out;
@@ -5425,7 +5434,7 @@ update_syntax (GtkSourceContextEngine *ce,
                }
 
                /* Analyze the line */
-               erase_segments (ce, line_start_offset, line_end_offset, ce->hint);
+               erase_segments (ce, line_start_offset, line_end_offset, ce->priv->hint);
                get_line_info (buffer, &line_start, &line_end, &line);
 
 #ifdef ENABLE_CHECK_TREE
@@ -5437,26 +5446,26 @@ update_syntax (GtkSourceContextEngine *ce,
 
                if (first_line)
                {
-                       state = ce->root_segment;
+                       state = ce->priv->root_segment;
                }
                else
                {
                        state = get_segment_at_offset (ce,
-                                                      ce->hint ? ce->hint : state,
+                                                      ce->priv->hint ? ce->priv->hint : state,
                                                       line_start_offset - 1);
                }
 
                g_assert (state->context != NULL);
 
-               ce->hint2 = ce->hint;
+               ce->priv->hint2 = ce->priv->hint;
 
-               if (ce->hint2 != NULL && ce->hint2->parent != state)
-                       ce->hint2 = NULL;
+               if (ce->priv->hint2 != NULL && ce->priv->hint2->parent != state)
+                       ce->priv->hint2 = NULL;
 
                state = analyze_line (ce, state, &line);
 
                /* At this point analyze_line() could have disabled highlighting */
-               if (ce->disabled)
+               if (ce->priv->disabled)
                        return;
 
 #ifdef ENABLE_CHECK_TREE
@@ -5469,14 +5478,14 @@ update_syntax (GtkSourceContextEngine *ce,
                /* XXX this is wrong */
                /* I don't know anymore why it's wrong, I guess it means
                 * "may be inefficient" */
-               if (ce->hint2 != NULL)
-                       ce->hint = ce->hint2;
+               if (ce->priv->hint2 != NULL)
+                       ce->priv->hint = ce->priv->hint2;
                else
-                       ce->hint = state;
+                       ce->priv->hint = state;
 
                line_info_destroy (&line);
 
-               gtk_source_region_add_subregion (ce->refresh_region, &line_start, &line_end);
+               gtk_source_region_add_subregion (ce->priv->refresh_region, &line_start, &line_end);
                analyzed_end = line_end_offset;
                invalid = get_invalid_segment (ce);
 
@@ -5495,7 +5504,7 @@ update_syntax (GtkSourceContextEngine *ce,
                {
                        Segment *old_state, *hint;
 
-                       hint = ce->hint ? ce->hint : state;
+                       hint = ce->priv->hint ? ce->priv->hint : state;
                        old_state = get_segment_at_offset (ce, hint, line_end_offset);
 
                        /* We can merge old and new stuff if: contexts are the same,
@@ -5545,9 +5554,9 @@ update_syntax (GtkSourceContextEngine *ce,
 
        if (analyzed_end == gtk_text_buffer_get_char_count (buffer))
        {
-               g_assert (g_slist_length (ce->invalid) <= 1);
+               g_assert (g_slist_length (ce->priv->invalid) <= 1);
 
-               if (ce->invalid != NULL)
+               if (ce->priv->invalid != NULL)
                {
                        invalid = get_invalid_segment (ce);
                        segment_remove (ce, invalid);
@@ -5570,7 +5579,7 @@ update_syntax (GtkSourceContextEngine *ce,
 
 out:
        /* must call context_thaw, so this is the only return point */
-       context_thaw (ce->root_context);
+       context_thaw (ce->priv->root_context);
 }
 
 
@@ -5578,11 +5587,11 @@ out:
 
 static DefinitionChild *
 definition_child_new (ContextDefinition *definition,
-                      const gchar       *child_id,
-                      const gchar       *style,
-                      gboolean           override_style,
-                      gboolean           is_ref_all,
-                      gboolean           original_ref)
+                     const gchar       *child_id,
+                     const gchar       *style,
+                     gboolean           override_style,
+                     gboolean           is_ref_all,
+                     gboolean           original_ref)
 {
        DefinitionChild *ch;
 
@@ -5636,14 +5645,14 @@ copy_context_classes (GSList *context_classes)
 
 static ContextDefinition *
 context_definition_new (const gchar            *id,
-                        ContextType             type,
-                        const gchar            *match,
-                        const gchar            *start,
-                        const gchar            *end,
-                        const gchar            *style,
-                        GSList                 *context_classes,
-                        GtkSourceContextFlags   flags,
-                        GError                **error)
+                       ContextType             type,
+                       const gchar            *match,
+                       const gchar            *start,
+                       const gchar            *end,
+                       const gchar            *style,
+                       GSList                 *context_classes,
+                       GtkSourceContextFlags   flags,
+                       GError                **error)
 {
        ContextDefinition *definition;
        gboolean regex_error = FALSE;
@@ -5800,7 +5809,7 @@ context_definition_unref (ContextDefinition *definition)
 
 static void
 definition_iter_init (DefinitionsIter   *iter,
-                      ContextDefinition *definition)
+                     ContextDefinition *definition)
 {
        iter->children_stack = g_slist_prepend (NULL, definition->children);
 }
@@ -5851,15 +5860,15 @@ definition_iter_next (DefinitionsIter *iter)
 
 gboolean
 _gtk_source_context_data_define_context (GtkSourceContextData   *ctx_data,
-                                         const gchar            *id,
-                                         const gchar            *parent_id,
-                                         const gchar            *match_regex,
-                                         const gchar            *start_regex,
-                                         const gchar            *end_regex,
-                                         const gchar            *style,
-                                         GSList                 *context_classes,
-                                         GtkSourceContextFlags   flags,
-                                         GError                **error)
+                                        const gchar            *id,
+                                        const gchar            *parent_id,
+                                        const gchar            *match_regex,
+                                        const gchar            *start_regex,
+                                        const gchar            *end_regex,
+                                        const gchar            *style,
+                                        GSList                 *context_classes,
+                                        GtkSourceContextFlags   flags,
+                                        GError                **error)
 {
        ContextDefinition *definition, *parent = NULL;
        ContextType type;
@@ -5941,13 +5950,13 @@ _gtk_source_context_data_define_context (GtkSourceContextData   *ctx_data,
 
 gboolean
 _gtk_source_context_data_add_sub_pattern (GtkSourceContextData  *ctx_data,
-                                          const gchar           *id,
-                                          const gchar           *parent_id,
-                                          const gchar           *name,
-                                          const gchar           *where,
-                                          const gchar           *style,
-                                          GSList                *context_classes,
-                                          GError               **error)
+                                         const gchar           *id,
+                                         const gchar           *parent_id,
+                                         const gchar           *name,
+                                         const gchar           *where,
+                                         const gchar           *style,
+                                         GSList                *context_classes,
+                                         GError               **error)
 {
        ContextDefinition *parent;
        SubPatternDefinition *sp_def;
@@ -6044,12 +6053,12 @@ context_is_pure_container (ContextDefinition *def)
 
 gboolean
 _gtk_source_context_data_add_ref (GtkSourceContextData        *ctx_data,
-                                  const gchar                 *parent_id,
-                                  const gchar                 *ref_id,
-                                  GtkSourceContextRefOptions   options,
-                                  const gchar                 *style,
-                                  gboolean                     all,
-                                  GError                     **error)
+                                 const gchar                 *parent_id,
+                                 const gchar                 *ref_id,
+                                 GtkSourceContextRefOptions   options,
+                                 const gchar                 *style,
+                                 gboolean                     all,
+                                 GError                     **error)
 {
        ContextDefinition *parent;
        ContextDefinition *ref;
@@ -6083,7 +6092,7 @@ _gtk_source_context_data_add_ref (GtkSourceContextData        *ctx_data,
                             GTK_SOURCE_CONTEXT_ENGINE_ERROR_INVALID_STYLE,
                             _("style override used with wildcard context reference"
                               " in language “%s” in ref “%s”"),
-                            gtk_source_language_get_id (ctx_data->lang), ref_id);
+                            ctx_data->lang->priv->id, ref_id);
                return FALSE;
        }
 
@@ -6109,8 +6118,8 @@ struct ResolveRefData {
 
 static void
 resolve_reference (G_GNUC_UNUSED const gchar *id,
-                   ContextDefinition         *definition,
-                   gpointer                   user_data)
+                  ContextDefinition         *definition,
+                  gpointer                   user_data)
 {
        GSList *l;
 
@@ -6143,7 +6152,7 @@ resolve_reference (G_GNUC_UNUSED const gchar *id,
                                                     GTK_SOURCE_CONTEXT_ENGINE_ERROR_INVALID_STYLE,
                                                     _("style override used with wildcard context reference"
                                                       " in language “%s” in ref “%s”"),
-                                                    gtk_source_language_get_id (data->ctx_data->lang), 
ref->id);
+                                                    data->ctx_data->lang->priv->id, ref->id);
                                }
                                else
                                {
@@ -6162,9 +6171,9 @@ resolve_reference (G_GNUC_UNUSED const gchar *id,
 
 static gboolean
 process_replace (GtkSourceContextData  *ctx_data,
-                 const gchar           *id,
-                 const gchar           *replace_with,
-                 GError               **error)
+                const gchar           *id,
+                const gchar           *replace_with,
+                GError               **error)
 {
        ContextDefinition *to_replace, *new;
 
@@ -6194,8 +6203,8 @@ process_replace (GtkSourceContextData  *ctx_data,
 }
 
 GtkSourceContextReplace *
-_gtk_source_context_replace_new (const gchar *to_replace_id,
-                                 const gchar *replace_with_id)
+_gtk_source_context_replace_new        (const gchar *to_replace_id,
+                                const gchar *replace_with_id)
 {
        GtkSourceContextReplace *repl;
 
@@ -6240,8 +6249,8 @@ _gtk_source_context_replace_free (GtkSourceContextReplace *repl)
  */
 gboolean
 _gtk_source_context_data_finish_parse (GtkSourceContextData  *ctx_data,
-                                       GList                 *overrides,
-                                       GError               **error)
+                                      GList                 *overrides,
+                                      GError               **error)
 {
        struct ResolveRefData data;
        gchar *root_id;
@@ -6275,9 +6284,7 @@ _gtk_source_context_data_finish_parse (GtkSourceContextData  *ctx_data,
        }
 
        /* Sanity check: user may have screwed up the files by now (#485661) */
-       root_id = g_strdup_printf ("%s:%s",
-                                  gtk_source_language_get_id (ctx_data->lang),
-                                  gtk_source_language_get_id (ctx_data->lang));
+       root_id = g_strdup_printf ("%s:%s", ctx_data->lang->priv->id, ctx_data->lang->priv->id);
        main_definition = gtk_source_context_data_lookup (ctx_data, root_id);
        g_free (root_id);
 
@@ -6285,8 +6292,9 @@ _gtk_source_context_data_finish_parse (GtkSourceContextData  *ctx_data,
        {
                g_set_error (error, GTK_SOURCE_CONTEXT_ENGINE_ERROR,
                             GTK_SOURCE_CONTEXT_ENGINE_ERROR_BAD_FILE,
-                            _("Missing main language definition (id = “%s”.)"),
-                            gtk_source_language_get_id (ctx_data->lang));
+                            _("Missing main language "
+                              "definition (id = \"%s\".)"),
+                            ctx_data->lang->priv->id);
                return FALSE;
        }
 
@@ -6295,7 +6303,7 @@ _gtk_source_context_data_finish_parse (GtkSourceContextData  *ctx_data,
 
 static void
 add_escape_ref (ContextDefinition    *definition,
-                GtkSourceContextData *ctx_data)
+               GtkSourceContextData *ctx_data)
 {
        GError *error = NULL;
 
@@ -6323,8 +6331,8 @@ out:
 
 static void
 prepend_definition (G_GNUC_UNUSED gchar  *id,
-                    ContextDefinition    *definition,
-                    GSList              **list)
+                   ContextDefinition    *definition,
+                   GSList              **list)
 {
        *list = g_slist_prepend (*list, definition);
 }
@@ -6338,7 +6346,7 @@ prepend_definition (G_GNUC_UNUSED gchar  *id,
    next line. */
 void
 _gtk_source_context_data_set_escape_char (GtkSourceContextData *ctx_data,
-                                          gunichar              escape_char)
+                                         gunichar              escape_char)
 {
        GError *error = NULL;
        char buf[10];
@@ -6393,7 +6401,7 @@ out:
 #ifdef ENABLE_CHECK_TREE
 static void
 check_segment (GtkSourceContextEngine *ce,
-               Segment                *segment)
+              Segment                *segment)
 {
        Segment *child;
 
@@ -6402,9 +6410,9 @@ check_segment (GtkSourceContextEngine *ce,
        g_assert (!segment->next || segment->next->start_at >= segment->end_at);
 
        if (SEGMENT_IS_INVALID (segment))
-               g_assert (g_slist_find (ce->invalid, segment) != NULL);
+               g_assert (g_slist_find (ce->priv->invalid, segment) != NULL);
        else
-               g_assert (g_slist_find (ce->invalid, segment) == NULL);
+               g_assert (g_slist_find (ce->priv->invalid, segment) == NULL);
 
        if (segment->children != NULL)
                g_assert (!SEGMENT_IS_INVALID (segment) && SEGMENT_IS_CONTAINER (segment));
@@ -6427,8 +6435,8 @@ struct CheckContextData {
 
 static void
 check_context_hash_cb (const char *text,
-                       Context    *context,
-                       gpointer    user_data)
+                      Context    *context,
+                      gpointer    user_data)
 {
        struct CheckContextData *data = user_data;
 
@@ -6466,21 +6474,21 @@ check_context (Context *context)
 static void
 check_tree (GtkSourceContextEngine *ce)
 {
-       Segment *root = ce->root_segment;
+       Segment *root = ce->priv->root_segment;
 
        check_regex ();
 
        g_assert (root->start_at == 0);
 
-       if (ce->invalid_region.empty)
-               g_assert (root->end_at == gtk_text_buffer_get_char_count (ce->buffer));
+       if (ce->priv->invalid_region.empty)
+               g_assert (root->end_at == gtk_text_buffer_get_char_count (ce->priv->buffer));
 
        g_assert (!root->parent);
        check_segment (ce, root);
 
-       g_assert (!ce->root_context->parent);
-       g_assert (root->context == ce->root_context);
-       check_context (ce->root_context);
+       g_assert (!ce->priv->root_context->parent);
+       g_assert (root->context == ce->priv->root_context);
+       check_context (ce->priv->root_context);
 }
 
 static void
diff --git a/gtksourceview/gtksourceencoding-private.h b/gtksourceview/gtksourceencoding-private.h
index 89d505cd..cd9e73db 100644
--- a/gtksourceview/gtksourceencoding-private.h
+++ b/gtksourceview/gtksourceencoding-private.h
@@ -2,7 +2,7 @@
 /*
  * This file is part of GtkSourceView
  *
- * Copyright 2014 - Sébastien Wilmet <swilmet gnome org>
+ * Copyright (C) 2014 - Sébastien Wilmet <swilmet gnome org>
  *
  * GtkSourceView is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -18,7 +18,8 @@
  * along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#pragma once
+#ifndef GTK_SOURCE_ENCODING_PRIVATE_H
+#define GTK_SOURCE_ENCODING_PRIVATE_H
 
 #include <glib.h>
 #include "gtksourcetypes-private.h"
@@ -42,7 +43,9 @@ typedef enum _GtkSourceEncodingDuplicates
 } GtkSourceEncodingDuplicates;
 
 GTK_SOURCE_INTERNAL
-GSList *_gtk_source_encoding_remove_duplicates (GSList                      *encodings,
-                                                GtkSourceEncodingDuplicates  removal_type);
+GSList *               _gtk_source_encoding_remove_duplicates          (GSList                      
*encodings,
+                                                                        GtkSourceEncodingDuplicates  
removal_type);
 
 G_END_DECLS
+
+#endif  /* GTK_SOURCE_ENCODING_PRIVATE_H */
diff --git a/gtksourceview/gtksourceencoding.c b/gtksourceview/gtksourceencoding.c
index 6e73f408..5e5cdeb3 100644
--- a/gtksourceview/gtksourceencoding.c
+++ b/gtksourceview/gtksourceencoding.c
@@ -2,8 +2,8 @@
 /*
  * This file is part of GtkSourceView
  *
- * Copyright 2002-2005 - Paolo Maggi
- * Copyright 2014, 2015 - Sébastien Wilmet <swilmet gnome org>
+ * Copyright (C) 2002-2005 - Paolo Maggi
+ * Copyright (C) 2014, 2015 - Sébastien Wilmet <swilmet gnome org>
  *
  * GtkSourceView is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -19,7 +19,9 @@
  * along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "config.h"
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
 
 #include "gtksourceencoding.h"
 #include "gtksourceencoding-private.h"
@@ -56,7 +58,7 @@ G_DEFINE_BOXED_TYPE (GtkSourceEncoding, gtk_source_encoding,
 /*
  * The original versions of the following tables are taken from profterm
  *
- * Copyright 2002 Red Hat, Inc.
+ * Copyright (C) 2002 Red Hat, Inc.
  */
 
 typedef enum _GtkSourceEncodingIndex
diff --git a/gtksourceview/gtksourceencoding.h b/gtksourceview/gtksourceencoding.h
index fce777fc..e7a065ea 100644
--- a/gtksourceview/gtksourceencoding.h
+++ b/gtksourceview/gtksourceencoding.h
@@ -2,8 +2,8 @@
 /*
  * This file is part of GtkSourceView
  *
- * Copyright 2002-2005 - Paolo Maggi
- * Copyright 2014, 2015 - Sébastien Wilmet <swilmet gnome org>
+ * Copyright (C) 2002-2005 - Paolo Maggi
+ * Copyright (C) 2014, 2015 - Sébastien Wilmet <swilmet gnome org>
  *
  * GtkSourceView is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -19,13 +19,13 @@
  * along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#pragma once
+#ifndef GTK_SOURCE_ENCODING_H
+#define GTK_SOURCE_ENCODING_H
 
 #if !defined (GTK_SOURCE_H_INSIDE) && !defined (GTK_SOURCE_COMPILATION)
 #error "Only <gtksourceview/gtksource.h> can be included directly."
 #endif
 
-#include <glib.h>
 #include <glib-object.h>
 
 #include "gtksourcetypes.h"
@@ -35,28 +35,40 @@ G_BEGIN_DECLS
 #define GTK_SOURCE_TYPE_ENCODING (gtk_source_encoding_get_type ())
 
 GTK_SOURCE_AVAILABLE_IN_3_14
-GType                    gtk_source_encoding_get_type               (void) G_GNUC_CONST;
+GType                   gtk_source_encoding_get_type                   (void) G_GNUC_CONST;
+
 GTK_SOURCE_AVAILABLE_IN_3_14
-const GtkSourceEncoding *gtk_source_encoding_get_from_charset       (const gchar             *charset);
+const GtkSourceEncoding        *gtk_source_encoding_get_from_charset           (const gchar             
*charset);
+
 GTK_SOURCE_AVAILABLE_IN_3_14
-gchar                   *gtk_source_encoding_to_string              (const GtkSourceEncoding *enc);
+gchar                  *gtk_source_encoding_to_string                  (const GtkSourceEncoding *enc);
+
 GTK_SOURCE_AVAILABLE_IN_3_14
-const gchar             *gtk_source_encoding_get_name               (const GtkSourceEncoding *enc);
+const gchar            *gtk_source_encoding_get_name                   (const GtkSourceEncoding *enc);
+
 GTK_SOURCE_AVAILABLE_IN_3_14
-const gchar             *gtk_source_encoding_get_charset            (const GtkSourceEncoding *enc);
+const gchar            *gtk_source_encoding_get_charset                (const GtkSourceEncoding *enc);
+
 GTK_SOURCE_AVAILABLE_IN_3_14
-const GtkSourceEncoding *gtk_source_encoding_get_utf8               (void);
+const GtkSourceEncoding        *gtk_source_encoding_get_utf8                   (void);
+
 GTK_SOURCE_AVAILABLE_IN_3_14
-const GtkSourceEncoding *gtk_source_encoding_get_current            (void);
+const GtkSourceEncoding        *gtk_source_encoding_get_current                (void);
+
 GTK_SOURCE_AVAILABLE_IN_3_14
-GSList                  *gtk_source_encoding_get_all                (void);
+GSList                 *gtk_source_encoding_get_all                    (void);
+
 GTK_SOURCE_AVAILABLE_IN_3_18
-GSList                  *gtk_source_encoding_get_default_candidates (void);
+GSList                 *gtk_source_encoding_get_default_candidates     (void);
 
 /* These should not be used, they are just to make python bindings happy */
+
 GTK_SOURCE_AVAILABLE_IN_3_14
-GtkSourceEncoding       *gtk_source_encoding_copy                   (const GtkSourceEncoding *enc);
+GtkSourceEncoding      *gtk_source_encoding_copy                       (const GtkSourceEncoding *enc);
+
 GTK_SOURCE_AVAILABLE_IN_3_14
-void                     gtk_source_encoding_free                   (GtkSourceEncoding       *enc);
+void                    gtk_source_encoding_free                       (GtkSourceEncoding       *enc);
 
 G_END_DECLS
+
+#endif  /* GTK_SOURCE_ENCODING_H */
diff --git a/gtksourceview/gtksourceengine-private.h b/gtksourceview/gtksourceengine-private.h
index aacc8b18..447c8f51 100644
--- a/gtksourceview/gtksourceengine-private.h
+++ b/gtksourceview/gtksourceengine-private.h
@@ -2,7 +2,7 @@
  *
  * This file is part of GtkSourceView
  *
- * Copyright 2003 - Gustavo Giráldez
+ * Copyright (C) 2003 - Gustavo Giráldez
  *
  * GtkSourceView is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -18,57 +18,73 @@
  * along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#pragma once
+#ifndef GTK_SOURCE_ENGINE_PRIVATE_H
+#define GTK_SOURCE_ENGINE_PRIVATE_H
 
 #include <gtk/gtk.h>
+
 #include "gtksourcetypes.h"
 #include "gtksourcetypes-private.h"
 
 G_BEGIN_DECLS
 
-#define GTK_SOURCE_TYPE_ENGINE (_gtk_source_engine_get_type())
+#define GTK_SOURCE_TYPE_ENGINE               (_gtk_source_engine_get_type ())
+#define GTK_SOURCE_ENGINE(obj)               (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_SOURCE_TYPE_ENGINE, 
GtkSourceEngine))
+#define GTK_SOURCE_IS_ENGINE(obj)            (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_SOURCE_TYPE_ENGINE))
+#define GTK_SOURCE_ENGINE_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), GTK_SOURCE_TYPE_ENGINE, 
GtkSourceEngineInterface))
 
-G_GNUC_INTERNAL
-G_DECLARE_INTERFACE (GtkSourceEngine, _gtk_source_engine, GTK_SOURCE, ENGINE, GObject)
+typedef struct _GtkSourceEngineInterface GtkSourceEngineInterface;
 
 struct _GtkSourceEngineInterface
 {
        GTypeInterface parent_interface;
 
-       void (* attach_buffer)    (GtkSourceEngine      *engine,
-                                  GtkTextBuffer        *buffer);
-       void (* text_inserted)    (GtkSourceEngine      *engine,
-                                  gint                  start_offset,
-                                  gint                  end_offset);
-       void (* text_deleted)     (GtkSourceEngine      *engine,
-                                  gint                  offset,
-                                  gint                  length);
-       void (* update_highlight) (GtkSourceEngine      *engine,
-                                  const GtkTextIter    *start,
-                                  const GtkTextIter    *end,
-                                  gboolean              synchronous);
-       void (* set_style_scheme) (GtkSourceEngine      *engine,
-                                  GtkSourceStyleScheme *scheme);
+       void     (* attach_buffer)    (GtkSourceEngine      *engine,
+                                      GtkTextBuffer        *buffer);
+
+       void     (* text_inserted)    (GtkSourceEngine      *engine,
+                                      gint                  start_offset,
+                                      gint                  end_offset);
+       void     (* text_deleted)     (GtkSourceEngine      *engine,
+                                      gint                  offset,
+                                      gint                  length);
+
+       void     (* update_highlight) (GtkSourceEngine      *engine,
+                                      const GtkTextIter    *start,
+                                      const GtkTextIter    *end,
+                                      gboolean              synchronous);
+
+       void     (* set_style_scheme) (GtkSourceEngine      *engine,
+                                      GtkSourceStyleScheme *scheme);
 };
 
 G_GNUC_INTERNAL
-void _gtk_source_engine_attach_buffer    (GtkSourceEngine      *engine,
-                                          GtkTextBuffer        *buffer);
+GType       _gtk_source_engine_get_type                (void) G_GNUC_CONST;
+
+G_GNUC_INTERNAL
+void        _gtk_source_engine_attach_buffer   (GtkSourceEngine      *engine,
+                                                GtkTextBuffer        *buffer);
+
 G_GNUC_INTERNAL
-void _gtk_source_engine_text_inserted    (GtkSourceEngine      *engine,
-                                          gint                  start_offset,
-                                          gint                  end_offset);
+void        _gtk_source_engine_text_inserted   (GtkSourceEngine      *engine,
+                                                gint                  start_offset,
+                                                gint                  end_offset);
+
 G_GNUC_INTERNAL
-void _gtk_source_engine_text_deleted     (GtkSourceEngine      *engine,
-                                          gint                  offset,
-                                          gint                  length);
+void        _gtk_source_engine_text_deleted    (GtkSourceEngine      *engine,
+                                                gint                  offset,
+                                                gint                  length);
+
 G_GNUC_INTERNAL
-void _gtk_source_engine_update_highlight (GtkSourceEngine      *engine,
-                                          const GtkTextIter    *start,
-                                          const GtkTextIter    *end,
-                                          gboolean              synchronous);
+void        _gtk_source_engine_update_highlight        (GtkSourceEngine      *engine,
+                                                const GtkTextIter    *start,
+                                                const GtkTextIter    *end,
+                                                gboolean              synchronous);
+
 G_GNUC_INTERNAL
-void _gtk_source_engine_set_style_scheme (GtkSourceEngine      *engine,
-                                          GtkSourceStyleScheme *scheme);
+void        _gtk_source_engine_set_style_scheme        (GtkSourceEngine      *engine,
+                                                GtkSourceStyleScheme *scheme);
 
 G_END_DECLS
+
+#endif /* GTK_SOURCE_ENGINE_PRIVATE_H */
diff --git a/gtksourceview/gtksourceengine.c b/gtksourceview/gtksourceengine.c
index 9e4b9ca2..d1a6b549 100644
--- a/gtksourceview/gtksourceengine.c
+++ b/gtksourceview/gtksourceengine.c
@@ -2,7 +2,7 @@
  *
  * This file is part of GtkSourceView
  *
- * Copyright 2003 - Gustavo Giráldez
+ * Copyright (C) 2003 - Gustavo Giráldez
  *
  * GtkSourceView is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -20,7 +20,9 @@
 
 /* Interface for syntax highlighting engines. */
 
-#include "config.h"
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
 
 #include "gtksourceengine-private.h"
 #include "gtksourcestylescheme.h"
@@ -34,51 +36,51 @@ _gtk_source_engine_default_init (GtkSourceEngineInterface *interface)
 
 void
 _gtk_source_engine_attach_buffer (GtkSourceEngine *engine,
-                                  GtkTextBuffer   *buffer)
+                                 GtkTextBuffer   *buffer)
 {
        g_return_if_fail (GTK_SOURCE_IS_ENGINE (engine));
-       g_return_if_fail (GTK_SOURCE_ENGINE_GET_IFACE (engine)->attach_buffer != NULL);
+       g_return_if_fail (GTK_SOURCE_ENGINE_GET_INTERFACE (engine)->attach_buffer != NULL);
 
-       GTK_SOURCE_ENGINE_GET_IFACE (engine)->attach_buffer (engine, buffer);
+       GTK_SOURCE_ENGINE_GET_INTERFACE (engine)->attach_buffer (engine, buffer);
 }
 
 void
 _gtk_source_engine_text_inserted (GtkSourceEngine *engine,
-                                  gint             start_offset,
-                                  gint             end_offset)
+                                 gint             start_offset,
+                                 gint             end_offset)
 {
        g_return_if_fail (GTK_SOURCE_IS_ENGINE (engine));
-       g_return_if_fail (GTK_SOURCE_ENGINE_GET_IFACE (engine)->text_inserted != NULL);
+       g_return_if_fail (GTK_SOURCE_ENGINE_GET_INTERFACE (engine)->text_inserted != NULL);
 
-       GTK_SOURCE_ENGINE_GET_IFACE (engine)->text_inserted (engine,
+       GTK_SOURCE_ENGINE_GET_INTERFACE (engine)->text_inserted (engine,
                                                                 start_offset,
                                                                 end_offset);
 }
 
 void
 _gtk_source_engine_text_deleted (GtkSourceEngine *engine,
-                                 gint             offset,
-                                 gint             length)
+                                gint             offset,
+                                gint             length)
 {
        g_return_if_fail (GTK_SOURCE_IS_ENGINE (engine));
-       g_return_if_fail (GTK_SOURCE_ENGINE_GET_IFACE (engine)->text_deleted != NULL);
+       g_return_if_fail (GTK_SOURCE_ENGINE_GET_INTERFACE (engine)->text_deleted != NULL);
 
-       GTK_SOURCE_ENGINE_GET_IFACE (engine)->text_deleted (engine,
+       GTK_SOURCE_ENGINE_GET_INTERFACE (engine)->text_deleted (engine,
                                                                offset,
                                                                length);
 }
 
 void
 _gtk_source_engine_update_highlight (GtkSourceEngine   *engine,
-                                     const GtkTextIter *start,
-                                     const GtkTextIter *end,
-                                     gboolean           synchronous)
+                                    const GtkTextIter *start,
+                                    const GtkTextIter *end,
+                                    gboolean           synchronous)
 {
        g_return_if_fail (GTK_SOURCE_IS_ENGINE (engine));
        g_return_if_fail (start != NULL && end != NULL);
-       g_return_if_fail (GTK_SOURCE_ENGINE_GET_IFACE (engine)->update_highlight != NULL);
+       g_return_if_fail (GTK_SOURCE_ENGINE_GET_INTERFACE (engine)->update_highlight != NULL);
 
-       GTK_SOURCE_ENGINE_GET_IFACE (engine)->update_highlight (engine,
+       GTK_SOURCE_ENGINE_GET_INTERFACE (engine)->update_highlight (engine,
                                                                    start,
                                                                    end,
                                                                    synchronous);
@@ -86,11 +88,11 @@ _gtk_source_engine_update_highlight (GtkSourceEngine   *engine,
 
 void
 _gtk_source_engine_set_style_scheme (GtkSourceEngine      *engine,
-                                     GtkSourceStyleScheme *scheme)
+                                    GtkSourceStyleScheme *scheme)
 {
        g_return_if_fail (GTK_SOURCE_IS_ENGINE (engine));
        g_return_if_fail (GTK_SOURCE_IS_STYLE_SCHEME (scheme) || scheme == NULL);
-       g_return_if_fail (GTK_SOURCE_ENGINE_GET_IFACE (engine)->set_style_scheme != NULL);
+       g_return_if_fail (GTK_SOURCE_ENGINE_GET_INTERFACE (engine)->set_style_scheme != NULL);
 
-       GTK_SOURCE_ENGINE_GET_IFACE (engine)->set_style_scheme (engine, scheme);
+       GTK_SOURCE_ENGINE_GET_INTERFACE (engine)->set_style_scheme (engine, scheme);
 }
diff --git a/gtksourceview/gtksourcefile-private.h b/gtksourceview/gtksourcefile-private.h
index 68a94ef8..8370b024 100644
--- a/gtksourceview/gtksourcefile-private.h
+++ b/gtksourceview/gtksourcefile-private.h
@@ -2,7 +2,7 @@
 /*
  * This file is part of GtkSourceView
  *
- * Copyright 2014, 2015 - Sébastien Wilmet <swilmet gnome org>
+ * Copyright (C) 2014, 2015 - Sébastien Wilmet <swilmet gnome org>
  *
  * GtkSourceView is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -18,39 +18,41 @@
  * along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#pragma once
+#ifndef GTK_SOURCE_FILE_PRIVATE_H
+#define GTK_SOURCE_FILE_PRIVATE_H
 
-#include "gtksourcefile.h"
+#include "gtksourcetypes.h"
+#include "gtksourcetypes-private.h"
 
 G_BEGIN_DECLS
 
 G_GNUC_INTERNAL
-void                      _gtk_source_file_set_encoding               (GtkSourceFile                  *file,
-                                                                       const GtkSourceEncoding        
*encoding);
+void             _gtk_source_file_set_encoding            (GtkSourceFile            *file,
+                                                           const GtkSourceEncoding  *encoding);
 G_GNUC_INTERNAL
-void                      _gtk_source_file_set_newline_type           (GtkSourceFile                  *file,
-                                                                       GtkSourceNewlineType            
newline_type);
+void             _gtk_source_file_set_newline_type        (GtkSourceFile            *file,
+                                                           GtkSourceNewlineType      newline_type);
 G_GNUC_INTERNAL
-void                      _gtk_source_file_set_compression_type       (GtkSourceFile                  *file,
-                                                                       GtkSourceCompressionType        
compression_type);
+void             _gtk_source_file_set_compression_type    (GtkSourceFile            *file,
+                                                           GtkSourceCompressionType  compression_type);
 G_GNUC_INTERNAL
-GMountOperation          *_gtk_source_file_create_mount_operation     (GtkSourceFile                  *file);
-G_GNUC_BEGIN_IGNORE_DEPRECATIONS
+GMountOperation *_gtk_source_file_create_mount_operation  (GtkSourceFile            *file);
 G_GNUC_INTERNAL
-gboolean                  _gtk_source_file_get_modification_time      (GtkSourceFile                  *file,
-                                                                       GTimeVal                       
*modification_time);
+gboolean         _gtk_source_file_get_modification_time   (GtkSourceFile            *file,
+                                                           gint64                   *modification_time);
 G_GNUC_INTERNAL
-void                      _gtk_source_file_set_modification_time      (GtkSourceFile                  *file,
-                                                                       GTimeVal                        
modification_time);
-G_GNUC_END_IGNORE_DEPRECATIONS
+void             _gtk_source_file_set_modification_time   (GtkSourceFile            *file,
+                                                           gint64                    modification_time);
 G_GNUC_INTERNAL
-void                      _gtk_source_file_set_externally_modified    (GtkSourceFile                  *file,
-                                                                       gboolean                        
externally_modified);
+void             _gtk_source_file_set_externally_modified (GtkSourceFile            *file,
+                                                           gboolean                  externally_modified);
 G_GNUC_INTERNAL
-void                      _gtk_source_file_set_deleted                (GtkSourceFile                  *file,
-                                                                       gboolean                        
deleted);
+void             _gtk_source_file_set_deleted             (GtkSourceFile            *file,
+                                                           gboolean                  deleted);
 G_GNUC_INTERNAL
-void                      _gtk_source_file_set_readonly               (GtkSourceFile                  *file,
-                                                                       gboolean                        
readonly);
+void             _gtk_source_file_set_readonly            (GtkSourceFile            *file,
+                                                           gboolean                  readonly);
 
 G_END_DECLS
+
+#endif /* GTK_SOURCE_FILE_PRIVATE_H */
diff --git a/gtksourceview/gtksourcefile.c b/gtksourceview/gtksourcefile.c
index 212d46b2..b0945072 100644
--- a/gtksourceview/gtksourcefile.c
+++ b/gtksourceview/gtksourcefile.c
@@ -2,7 +2,7 @@
 /*
  * This file is part of GtkSourceView
  *
- * Copyright 2014, 2015 - Sébastien Wilmet <swilmet gnome org>
+ * Copyright (C) 2014, 2015 - Sébastien Wilmet <swilmet gnome org>
  *
  * GtkSourceView is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -18,8 +18,11 @@
  * along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "config.h"
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
 
+#include "gtksourcefile.h"
 #include "gtksourcefile-private.h"
 #include "gtksourceencoding.h"
 #include "gtksource-enumtypes.h"
@@ -55,7 +58,7 @@ enum
        PROP_READ_ONLY
 };
 
-typedef struct
+struct _GtkSourceFilePrivate
 {
        GFile *location;
        const GtkSourceEncoding *encoding;
@@ -69,46 +72,49 @@ typedef struct
        /* Last known modification time of 'location'. The value is updated on a
         * file loading or file saving.
         */
-       GTimeVal modification_time;
+       gint64 modification_time;
 
        guint modification_time_set : 1;
 
        guint externally_modified : 1;
        guint deleted : 1;
        guint readonly : 1;
-} GtkSourceFilePrivate;
+};
 
 G_DEFINE_TYPE_WITH_PRIVATE (GtkSourceFile, gtk_source_file, G_TYPE_OBJECT)
 
 static void
 gtk_source_file_get_property (GObject    *object,
-                              guint       prop_id,
-                              GValue     *value,
-                              GParamSpec *pspec)
+                             guint       prop_id,
+                             GValue     *value,
+                             GParamSpec *pspec)
 {
-       GtkSourceFile *file = GTK_SOURCE_FILE (object);
-       GtkSourceFilePrivate *priv = gtk_source_file_get_instance_private (file);
+       GtkSourceFile *file;
+
+       g_return_if_fail (GTK_SOURCE_IS_FILE (object));
+
+       file = GTK_SOURCE_FILE (object);
 
        switch (prop_id)
        {
                case PROP_LOCATION:
-                       g_value_set_object (value, priv->location);
+                       g_value_set_object (value, file->priv->location);
                        break;
 
                case PROP_ENCODING:
-                       g_value_set_boxed (value, priv->encoding);
+                       g_value_set_boxed (value, file->priv->encoding);
                        break;
 
                case PROP_NEWLINE_TYPE:
-                       g_value_set_enum (value, priv->newline_type);
+                       g_value_set_enum (value, file->priv->newline_type);
                        break;
 
                case PROP_COMPRESSION_TYPE:
-                       g_value_set_enum (value, priv->compression_type);
+                       g_value_set_enum (value, file->priv->compression_type);
                        break;
 
                case PROP_READ_ONLY:
-                       g_value_set_boolean (value, priv->readonly);
+                       g_value_set_boolean (value, file->priv->readonly);
                        break;
 
                default:
@@ -119,11 +125,15 @@ gtk_source_file_get_property (GObject    *object,
 
 static void
 gtk_source_file_set_property (GObject      *object,
-                              guint         prop_id,
-                              const GValue *value,
-                              GParamSpec   *pspec)
+                             guint         prop_id,
+                             const GValue *value,
+                             GParamSpec   *pspec)
 {
-       GtkSourceFile *file = GTK_SOURCE_FILE (object);
+       GtkSourceFile *file;
+
+       g_return_if_fail (GTK_SOURCE_IS_FILE (object));
+
+       file = GTK_SOURCE_FILE (object);
 
        switch (prop_id)
        {
@@ -141,14 +151,13 @@ static void
 gtk_source_file_dispose (GObject *object)
 {
        GtkSourceFile *file = GTK_SOURCE_FILE (object);
-       GtkSourceFilePrivate *priv = gtk_source_file_get_instance_private (file);
 
-       g_clear_object (&priv->location);
+       g_clear_object (&file->priv->location);
 
-       if (priv->mount_operation_notify != NULL)
+       if (file->priv->mount_operation_notify != NULL)
        {
-               priv->mount_operation_notify (priv->mount_operation_userdata);
-               priv->mount_operation_notify = NULL;
+               file->priv->mount_operation_notify (file->priv->mount_operation_userdata);
+               file->priv->mount_operation_notify = NULL;
        }
 
        G_OBJECT_CLASS (gtk_source_file_parent_class)->dispose (object);
@@ -252,11 +261,11 @@ gtk_source_file_class_init (GtkSourceFileClass *klass)
 static void
 gtk_source_file_init (GtkSourceFile *file)
 {
-       GtkSourceFilePrivate *priv = gtk_source_file_get_instance_private (file);
+       file->priv = gtk_source_file_get_instance_private (file);
 
-       priv->encoding = NULL;
-       priv->newline_type = GTK_SOURCE_NEWLINE_TYPE_LF;
-       priv->compression_type = GTK_SOURCE_COMPRESSION_TYPE_NONE;
+       file->priv->encoding = NULL;
+       file->priv->newline_type = GTK_SOURCE_NEWLINE_TYPE_LF;
+       file->priv->compression_type = GTK_SOURCE_COMPRESSION_TYPE_NONE;
 }
 
 /**
@@ -282,22 +291,20 @@ gtk_source_file_new (void)
  */
 void
 gtk_source_file_set_location (GtkSourceFile *file,
-                              GFile         *location)
+                             GFile         *location)
 {
-       GtkSourceFilePrivate *priv = gtk_source_file_get_instance_private (file);
-
        g_return_if_fail (GTK_SOURCE_IS_FILE (file));
        g_return_if_fail (location == NULL || G_IS_FILE (location));
 
-       if (g_set_object (&priv->location, location))
+       if (g_set_object (&file->priv->location, location))
        {
                g_object_notify (G_OBJECT (file), "location");
 
                /* The modification_time is for the old location. */
-               priv->modification_time_set = FALSE;
+               file->priv->modification_time_set = FALSE;
 
-               priv->externally_modified = FALSE;
-               priv->deleted = FALSE;
+               file->priv->externally_modified = FALSE;
+               file->priv->deleted = FALSE;
        }
 }
 
@@ -311,24 +318,20 @@ gtk_source_file_set_location (GtkSourceFile *file,
 GFile *
 gtk_source_file_get_location (GtkSourceFile *file)
 {
-       GtkSourceFilePrivate *priv = gtk_source_file_get_instance_private (file);
-
        g_return_val_if_fail (GTK_SOURCE_IS_FILE (file), NULL);
 
-       return priv->location;
+       return file->priv->location;
 }
 
 void
 _gtk_source_file_set_encoding (GtkSourceFile           *file,
-                               const GtkSourceEncoding *encoding)
+                              const GtkSourceEncoding *encoding)
 {
-       GtkSourceFilePrivate *priv = gtk_source_file_get_instance_private (file);
-
        g_return_if_fail (GTK_SOURCE_IS_FILE (file));
 
-       if (priv->encoding != encoding)
+       if (file->priv->encoding != encoding)
        {
-               priv->encoding = encoding;
+               file->priv->encoding = encoding;
                g_object_notify (G_OBJECT (file), "encoding");
        }
 }
@@ -346,24 +349,20 @@ _gtk_source_file_set_encoding (GtkSourceFile           *file,
 const GtkSourceEncoding *
 gtk_source_file_get_encoding (GtkSourceFile *file)
 {
-       GtkSourceFilePrivate *priv = gtk_source_file_get_instance_private (file);
-
        g_return_val_if_fail (GTK_SOURCE_IS_FILE (file), NULL);
 
-       return priv->encoding;
+       return file->priv->encoding;
 }
 
 void
 _gtk_source_file_set_newline_type (GtkSourceFile        *file,
-                                   GtkSourceNewlineType  newline_type)
+                                  GtkSourceNewlineType  newline_type)
 {
-       GtkSourceFilePrivate *priv = gtk_source_file_get_instance_private (file);
-
        g_return_if_fail (GTK_SOURCE_IS_FILE (file));
 
-       if (priv->newline_type != newline_type)
+       if (file->priv->newline_type != newline_type)
        {
-               priv->newline_type = newline_type;
+               file->priv->newline_type = newline_type;
                g_object_notify (G_OBJECT (file), "newline-type");
        }
 }
@@ -378,24 +377,20 @@ _gtk_source_file_set_newline_type (GtkSourceFile        *file,
 GtkSourceNewlineType
 gtk_source_file_get_newline_type (GtkSourceFile *file)
 {
-       GtkSourceFilePrivate *priv = gtk_source_file_get_instance_private (file);
-
        g_return_val_if_fail (GTK_SOURCE_IS_FILE (file), GTK_SOURCE_NEWLINE_TYPE_DEFAULT);
 
-       return priv->newline_type;
+       return file->priv->newline_type;
 }
 
 void
 _gtk_source_file_set_compression_type (GtkSourceFile            *file,
-                                       GtkSourceCompressionType  compression_type)
+                                      GtkSourceCompressionType  compression_type)
 {
-       GtkSourceFilePrivate *priv = gtk_source_file_get_instance_private (file);
-
        g_return_if_fail (GTK_SOURCE_IS_FILE (file));
 
-       if (priv->compression_type != compression_type)
+       if (file->priv->compression_type != compression_type)
        {
-               priv->compression_type = compression_type;
+               file->priv->compression_type = compression_type;
                g_object_notify (G_OBJECT (file), "compression-type");
        }
 }
@@ -410,11 +405,9 @@ _gtk_source_file_set_compression_type (GtkSourceFile            *file,
 GtkSourceCompressionType
 gtk_source_file_get_compression_type (GtkSourceFile *file)
 {
-       GtkSourceFilePrivate *priv = gtk_source_file_get_instance_private (file);
-
        g_return_val_if_fail (GTK_SOURCE_IS_FILE (file), GTK_SOURCE_COMPRESSION_TYPE_NONE);
 
-       return priv->compression_type;
+       return file->priv->compression_type;
 }
 
 /**
@@ -437,40 +430,34 @@ gtk_source_file_get_compression_type (GtkSourceFile *file)
  */
 void
 gtk_source_file_set_mount_operation_factory (GtkSourceFile                  *file,
-                                             GtkSourceMountOperationFactory  callback,
-                                             gpointer                        user_data,
-                                             GDestroyNotify                  notify)
+                                            GtkSourceMountOperationFactory  callback,
+                                            gpointer                        user_data,
+                                            GDestroyNotify                  notify)
 {
-       GtkSourceFilePrivate *priv = gtk_source_file_get_instance_private (file);
-
        g_return_if_fail (GTK_SOURCE_IS_FILE (file));
 
-       if (priv->mount_operation_notify != NULL)
+       if (file->priv->mount_operation_notify != NULL)
        {
-               priv->mount_operation_notify (priv->mount_operation_userdata);
+               file->priv->mount_operation_notify (file->priv->mount_operation_userdata);
        }
 
-       priv->mount_operation_factory = callback;
-       priv->mount_operation_userdata = user_data;
-       priv->mount_operation_notify = notify;
+       file->priv->mount_operation_factory = callback;
+       file->priv->mount_operation_userdata = user_data;
+       file->priv->mount_operation_notify = notify;
 }
 
 GMountOperation *
 _gtk_source_file_create_mount_operation (GtkSourceFile *file)
 {
-       GtkSourceFilePrivate *priv = gtk_source_file_get_instance_private (file);
-
-       return (file != NULL && priv->mount_operation_factory != NULL) ?
-               priv->mount_operation_factory (file, priv->mount_operation_userdata) :
+       return (file != NULL && file->priv->mount_operation_factory != NULL) ?
+               file->priv->mount_operation_factory (file, file->priv->mount_operation_userdata) :
                g_mount_operation_new ();
 }
 
 gboolean
 _gtk_source_file_get_modification_time (GtkSourceFile *file,
-                                        GTimeVal      *modification_time)
+                                       gint64        *modification_time)
 {
-       GtkSourceFilePrivate *priv = gtk_source_file_get_instance_private (file);
-
        g_assert (modification_time != NULL);
 
        if (file == NULL)
@@ -480,26 +467,24 @@ _gtk_source_file_get_modification_time (GtkSourceFile *file,
 
        g_return_val_if_fail (GTK_SOURCE_IS_FILE (file), FALSE);
 
-       if (priv->modification_time_set)
+       if (file->priv->modification_time_set)
        {
-               *modification_time = priv->modification_time;
+               *modification_time = file->priv->modification_time;
        }
 
-       return priv->modification_time_set;
+       return file->priv->modification_time_set;
 }
 
 void
 _gtk_source_file_set_modification_time (GtkSourceFile *file,
-                                        GTimeVal       modification_time)
+                                       gint64         modification_time)
 {
-       GtkSourceFilePrivate *priv = gtk_source_file_get_instance_private (file);
-
        if (file != NULL)
        {
                g_return_if_fail (GTK_SOURCE_IS_FILE (file));
 
-               priv->modification_time = modification_time;
-               priv->modification_time_set = TRUE;
+               file->priv->modification_time = modification_time;
+               file->priv->modification_time_set = TRUE;
        }
 }
 
@@ -516,16 +501,14 @@ _gtk_source_file_set_modification_time (GtkSourceFile *file,
 gboolean
 gtk_source_file_is_local (GtkSourceFile *file)
 {
-       GtkSourceFilePrivate *priv = gtk_source_file_get_instance_private (file);
-
        g_return_val_if_fail (GTK_SOURCE_IS_FILE (file), FALSE);
 
-       if (priv->location == NULL)
+       if (file->priv->location == NULL)
        {
                return FALSE;
        }
 
-       return g_file_has_uri_scheme (priv->location, "file");
+       return g_file_has_uri_scheme (file->priv->location, "file");
 }
 
 /**
@@ -547,15 +530,14 @@ gtk_source_file_is_local (GtkSourceFile *file)
 void
 gtk_source_file_check_file_on_disk (GtkSourceFile *file)
 {
-       GtkSourceFilePrivate *priv = gtk_source_file_get_instance_private (file);
        GFileInfo *info;
 
-       if (priv->location == NULL)
+       if (file->priv->location == NULL)
        {
                return;
        }
 
-       info = g_file_query_info (priv->location,
+       info = g_file_query_info (file->priv->location,
                                  G_FILE_ATTRIBUTE_TIME_MODIFIED ","
                                  G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE,
                                  G_FILE_QUERY_INFO_NONE,
@@ -564,25 +546,28 @@ gtk_source_file_check_file_on_disk (GtkSourceFile *file)
 
        if (info == NULL)
        {
-               priv->deleted = TRUE;
+               file->priv->deleted = TRUE;
                return;
        }
 
        if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_TIME_MODIFIED) &&
-           priv->modification_time_set)
+           file->priv->modification_time_set)
        {
-               GTimeVal timeval;
+               GDateTime *dt;
+               gint64 mtime;
 
-               g_file_info_get_modification_time (info, &timeval);
+               dt = g_file_info_get_modification_date_time (info);
+               mtime = g_date_time_to_unix (dt);
 
                /* Note that the modification time can even go backwards if the
                 * user is copying over an old file.
                 */
-               if (timeval.tv_sec != priv->modification_time.tv_sec ||
-                   timeval.tv_usec != priv->modification_time.tv_usec)
+               if (mtime != file->priv->modification_time)
                {
-                       priv->externally_modified = TRUE;
+                       file->priv->externally_modified = TRUE;
                }
+
+               g_date_time_unref (dt);
        }
 
        if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE))
@@ -599,13 +584,11 @@ gtk_source_file_check_file_on_disk (GtkSourceFile *file)
 
 void
 _gtk_source_file_set_externally_modified (GtkSourceFile *file,
-                                          gboolean       externally_modified)
+                                         gboolean       externally_modified)
 {
-       GtkSourceFilePrivate *priv = gtk_source_file_get_instance_private (file);
-
        g_return_if_fail (GTK_SOURCE_IS_FILE (file));
 
-       priv->externally_modified = externally_modified != FALSE;
+       file->priv->externally_modified = externally_modified != FALSE;
 }
 
 /**
@@ -624,22 +607,18 @@ _gtk_source_file_set_externally_modified (GtkSourceFile *file,
 gboolean
 gtk_source_file_is_externally_modified (GtkSourceFile *file)
 {
-       GtkSourceFilePrivate *priv = gtk_source_file_get_instance_private (file);
-
        g_return_val_if_fail (GTK_SOURCE_IS_FILE (file), FALSE);
 
-       return priv->externally_modified;
+       return file->priv->externally_modified;
 }
 
 void
 _gtk_source_file_set_deleted (GtkSourceFile *file,
-                              gboolean       deleted)
+                             gboolean       deleted)
 {
-       GtkSourceFilePrivate *priv = gtk_source_file_get_instance_private (file);
-
        g_return_if_fail (GTK_SOURCE_IS_FILE (file));
 
-       priv->deleted = deleted != FALSE;
+       file->priv->deleted = deleted != FALSE;
 }
 
 /**
@@ -658,26 +637,22 @@ _gtk_source_file_set_deleted (GtkSourceFile *file,
 gboolean
 gtk_source_file_is_deleted (GtkSourceFile *file)
 {
-       GtkSourceFilePrivate *priv = gtk_source_file_get_instance_private (file);
-
        g_return_val_if_fail (GTK_SOURCE_IS_FILE (file), FALSE);
 
-       return priv->deleted;
+       return file->priv->deleted;
 }
 
 void
 _gtk_source_file_set_readonly (GtkSourceFile *file,
-                               gboolean       readonly)
+                              gboolean       readonly)
 {
-       GtkSourceFilePrivate *priv = gtk_source_file_get_instance_private (file);
-
        g_return_if_fail (GTK_SOURCE_IS_FILE (file));
 
        readonly = readonly != FALSE;
 
-       if (priv->readonly != readonly)
+       if (file->priv->readonly != readonly)
        {
-               priv->readonly = readonly;
+               file->priv->readonly = readonly;
                g_object_notify (G_OBJECT (file), "read-only");
        }
 }
@@ -698,9 +673,7 @@ _gtk_source_file_set_readonly (GtkSourceFile *file,
 gboolean
 gtk_source_file_is_readonly (GtkSourceFile *file)
 {
-       GtkSourceFilePrivate *priv = gtk_source_file_get_instance_private (file);
-
        g_return_val_if_fail (GTK_SOURCE_IS_FILE (file), FALSE);
 
-       return priv->readonly;
+       return file->priv->readonly;
 }
diff --git a/gtksourceview/gtksourcefile.h b/gtksourceview/gtksourcefile.h
index 382502ff..70a70301 100644
--- a/gtksourceview/gtksourcefile.h
+++ b/gtksourceview/gtksourcefile.h
@@ -2,7 +2,7 @@
 /*
  * This file is part of GtkSourceView
  *
- * Copyright 2014, 2015 - Sébastien Wilmet <swilmet gnome org>
+ * Copyright (C) 2014, 2015 - Sébastien Wilmet <swilmet gnome org>
  *
  * GtkSourceView is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -18,7 +18,8 @@
  * along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#pragma once
+#ifndef GTK_SOURCE_FILE_H
+#define GTK_SOURCE_FILE_H
 
 #if !defined (GTK_SOURCE_H_INSIDE) && !defined (GTK_SOURCE_COMPILATION)
 #error "Only <gtksourceview/gtksource.h> can be included directly."
@@ -30,7 +31,15 @@
 
 G_BEGIN_DECLS
 
-#define GTK_SOURCE_TYPE_FILE (gtk_source_file_get_type())
+#define GTK_SOURCE_TYPE_FILE             (gtk_source_file_get_type ())
+#define GTK_SOURCE_FILE(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_SOURCE_TYPE_FILE, 
GtkSourceFile))
+#define GTK_SOURCE_FILE_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_SOURCE_TYPE_FILE, 
GtkSourceFileClass))
+#define GTK_SOURCE_IS_FILE(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_SOURCE_TYPE_FILE))
+#define GTK_SOURCE_IS_FILE_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_SOURCE_TYPE_FILE))
+#define GTK_SOURCE_FILE_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_SOURCE_TYPE_FILE, 
GtkSourceFileClass))
+
+typedef struct _GtkSourceFileClass    GtkSourceFileClass;
+typedef struct _GtkSourceFilePrivate  GtkSourceFilePrivate;
 
 /**
  * GtkSourceNewlineType:
@@ -85,47 +94,68 @@ typedef enum _GtkSourceCompressionType
  * Since: 3.14
  */
 typedef GMountOperation *(*GtkSourceMountOperationFactory) (GtkSourceFile *file,
-                                                            gpointer       userdata);
+                                                           gpointer       userdata);
 
-GTK_SOURCE_AVAILABLE_IN_3_14
-G_DECLARE_DERIVABLE_TYPE (GtkSourceFile, gtk_source_file, GTK_SOURCE, FILE, GObject)
+struct _GtkSourceFile
+{
+       GObject parent;
+
+       GtkSourceFilePrivate *priv;
+};
 
 struct _GtkSourceFileClass
 {
        GObjectClass parent_class;
 
-       /*< private >*/
-       gpointer _reserved[10];
+       gpointer padding[10];
 };
 
+GTK_SOURCE_AVAILABLE_IN_3_14
+GType           gtk_source_file_get_type                       (void) G_GNUC_CONST;
 
 GTK_SOURCE_AVAILABLE_IN_3_14
-GtkSourceFile            *gtk_source_file_new                         (void);
+GtkSourceFile  *gtk_source_file_new                            (void);
+
 GTK_SOURCE_AVAILABLE_IN_3_14
-GFile                    *gtk_source_file_get_location                (GtkSourceFile                  *file);
+GFile          *gtk_source_file_get_location                   (GtkSourceFile *file);
+
 GTK_SOURCE_AVAILABLE_IN_3_14
-void                      gtk_source_file_set_location                (GtkSourceFile                  *file,
-                                                                       GFile                          
*location);
+void            gtk_source_file_set_location                   (GtkSourceFile *file,
+                                                                GFile         *location);
+
 GTK_SOURCE_AVAILABLE_IN_3_14
-const GtkSourceEncoding  *gtk_source_file_get_encoding                (GtkSourceFile                  *file);
+const GtkSourceEncoding *
+                gtk_source_file_get_encoding                   (GtkSourceFile *file);
+
 GTK_SOURCE_AVAILABLE_IN_3_14
-GtkSourceNewlineType      gtk_source_file_get_newline_type            (GtkSourceFile                  *file);
+GtkSourceNewlineType
+                gtk_source_file_get_newline_type               (GtkSourceFile *file);
+
 GTK_SOURCE_AVAILABLE_IN_3_14
-GtkSourceCompressionType  gtk_source_file_get_compression_type        (GtkSourceFile                  *file);
+GtkSourceCompressionType
+                gtk_source_file_get_compression_type           (GtkSourceFile *file);
+
 GTK_SOURCE_AVAILABLE_IN_3_14
-void                      gtk_source_file_set_mount_operation_factory (GtkSourceFile                  *file,
-                                                                       GtkSourceMountOperationFactory  
callback,
-                                                                       gpointer                        
user_data,
-                                                                       GDestroyNotify                  
notify);
+void            gtk_source_file_set_mount_operation_factory    (GtkSourceFile                  *file,
+                                                                GtkSourceMountOperationFactory  callback,
+                                                                gpointer                        user_data,
+                                                                GDestroyNotify                  notify);
+
 GTK_SOURCE_AVAILABLE_IN_3_18
-void                      gtk_source_file_check_file_on_disk          (GtkSourceFile                  *file);
+void            gtk_source_file_check_file_on_disk             (GtkSourceFile *file);
+
 GTK_SOURCE_AVAILABLE_IN_3_18
-gboolean                  gtk_source_file_is_local                    (GtkSourceFile                  *file);
+gboolean        gtk_source_file_is_local                       (GtkSourceFile *file);
+
 GTK_SOURCE_AVAILABLE_IN_3_18
-gboolean                  gtk_source_file_is_externally_modified      (GtkSourceFile                  *file);
+gboolean        gtk_source_file_is_externally_modified         (GtkSourceFile *file);
+
 GTK_SOURCE_AVAILABLE_IN_3_18
-gboolean                  gtk_source_file_is_deleted                  (GtkSourceFile                  *file);
+gboolean        gtk_source_file_is_deleted                     (GtkSourceFile *file);
+
 GTK_SOURCE_AVAILABLE_IN_3_18
-gboolean                  gtk_source_file_is_readonly                 (GtkSourceFile                  *file);
+gboolean        gtk_source_file_is_readonly                    (GtkSourceFile *file);
 
 G_END_DECLS
+
+#endif /* GTK_SOURCE_FILE_H */
diff --git a/gtksourceview/gtksourcefileloader.c b/gtksourceview/gtksourcefileloader.c
index e6970fe2..022d28f1 100644
--- a/gtksourceview/gtksourcefileloader.c
+++ b/gtksourceview/gtksourcefileloader.c
@@ -2,10 +2,10 @@
 /*
  * This file is part of GtkSourceView
  *
- * Copyright 2005 - Paolo Maggi
- * Copyright 2007 - Paolo Maggi, Steve Frécinaux
- * Copyright 2008 - Jesse van den Kieboom
- * Copyright 2014, 2016 - Sébastien Wilmet
+ * Copyright (C) 2005 - Paolo Maggi
+ * Copyright (C) 2007 - Paolo Maggi, Steve Frécinaux
+ * Copyright (C) 2008 - Jesse van den Kieboom
+ * Copyright (C) 2014, 2016 - Sébastien Wilmet
  *
  * GtkSourceView is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -21,12 +21,15 @@
  * along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "config.h"
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
 
 #include <glib/gi18n-lib.h>
 
 #include "gtksourcefileloader.h"
 #include "gtksourcebuffer.h"
+#include "gtksourcefile.h"
 #include "gtksourcefile-private.h"
 #include "gtksourcebufferoutputstream-private.h"
 #include "gtksourceencoding.h"
@@ -47,8 +50,8 @@
  * operation with gtk_source_file_loader_load_async().
  *
  * Running a #GtkSourceFileLoader is an undoable action for the
- * #GtkSourceBuffer. That is, gtk_source_buffer_begin_not_undoable_action() and
- * gtk_source_buffer_end_not_undoable_action() are called, which delete the
+ * #GtkSourceBuffer. That is, gtk_text_buffer_begin_irreversible_action() and
+ * gtk_text_buffer_end_irreversible_action() are called, which delete the
  * undo/redo history.
  *
  * After a file loading, the buffer is reset to the contents provided by the
@@ -88,10 +91,8 @@ enum
                                G_FILE_ATTRIBUTE_STANDARD_SIZE "," \
                                G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE
 
-struct _GtkSourceFileLoader
+struct _GtkSourceFileLoaderPrivate
 {
-       GObject parent_instance;
-
        /* Weak ref to the GtkSourceBuffer. A strong ref could create a
         * reference cycle in an application. For example a subclass of
         * GtkSourceBuffer can have a strong ref to the FileLoader.
@@ -120,7 +121,8 @@ struct _GtkSourceFileLoader
        GTask *task;
 };
 
-typedef struct
+typedef struct _TaskData TaskData;
+struct _TaskData
 {
        /* The two streams cannot be spliced directly, because:
         * (1) We need to call the progress callback.
@@ -144,11 +146,11 @@ typedef struct
 
        guint guess_content_type_from_content : 1;
        guint tried_mount : 1;
-} TaskData;
+};
 
-G_DEFINE_TYPE (GtkSourceFileLoader, gtk_source_file_loader, G_TYPE_OBJECT)
+G_DEFINE_TYPE_WITH_PRIVATE (GtkSourceFileLoader, gtk_source_file_loader, G_TYPE_OBJECT)
 
-static void open_file       (GTask *task);
+static void open_file (GTask *task);
 static void read_file_chunk (GTask *task);
 
 static TaskData *
@@ -197,36 +199,36 @@ get_compression_type_from_content_type (const gchar *content_type)
 
 static void
 gtk_source_file_loader_set_property (GObject      *object,
-                                     guint         prop_id,
-                                     const GValue *value,
-                                     GParamSpec   *pspec)
+                                    guint         prop_id,
+                                    const GValue *value,
+                                    GParamSpec   *pspec)
 {
        GtkSourceFileLoader *loader = GTK_SOURCE_FILE_LOADER (object);
 
        switch (prop_id)
        {
                case PROP_BUFFER:
-                       g_assert (loader->source_buffer == NULL);
-                       loader->source_buffer = g_value_get_object (value);
-                       g_object_add_weak_pointer (G_OBJECT (loader->source_buffer),
-                                                  (gpointer *)&loader->source_buffer);
+                       g_assert (loader->priv->source_buffer == NULL);
+                       loader->priv->source_buffer = g_value_get_object (value);
+                       g_object_add_weak_pointer (G_OBJECT (loader->priv->source_buffer),
+                                                  (gpointer *)&loader->priv->source_buffer);
                        break;
 
                case PROP_FILE:
-                       g_assert (loader->file == NULL);
-                       loader->file = g_value_get_object (value);
-                       g_object_add_weak_pointer (G_OBJECT (loader->file),
-                                                  (gpointer *)&loader->file);
+                       g_assert (loader->priv->file == NULL);
+                       loader->priv->file = g_value_get_object (value);
+                       g_object_add_weak_pointer (G_OBJECT (loader->priv->file),
+                                                  (gpointer *)&loader->priv->file);
                        break;
 
                case PROP_LOCATION:
-                       g_assert (loader->location == NULL);
-                       loader->location = g_value_dup_object (value);
+                       g_assert (loader->priv->location == NULL);
+                       loader->priv->location = g_value_dup_object (value);
                        break;
 
                case PROP_INPUT_STREAM:
-                       g_assert (loader->input_stream_property == NULL);
-                       loader->input_stream_property = g_value_dup_object (value);
+                       g_assert (loader->priv->input_stream_property == NULL);
+                       loader->priv->input_stream_property = g_value_dup_object (value);
                        break;
 
                default:
@@ -237,28 +239,28 @@ gtk_source_file_loader_set_property (GObject      *object,
 
 static void
 gtk_source_file_loader_get_property (GObject    *object,
-                                     guint       prop_id,
-                                     GValue     *value,
-                                     GParamSpec *pspec)
+                                    guint       prop_id,
+                                    GValue     *value,
+                                    GParamSpec *pspec)
 {
        GtkSourceFileLoader *loader = GTK_SOURCE_FILE_LOADER (object);
 
        switch (prop_id)
        {
                case PROP_BUFFER:
-                       g_value_set_object (value, loader->source_buffer);
+                       g_value_set_object (value, loader->priv->source_buffer);
                        break;
 
                case PROP_FILE:
-                       g_value_set_object (value, loader->file);
+                       g_value_set_object (value, loader->priv->file);
                        break;
 
                case PROP_LOCATION:
-                       g_value_set_object (value, loader->location);
+                       g_value_set_object (value, loader->priv->location);
                        break;
 
                case PROP_INPUT_STREAM:
-                       g_value_set_object (value, loader->input_stream_property);
+                       g_value_set_object (value, loader->priv->input_stream_property);
                        break;
 
                default:
@@ -272,28 +274,28 @@ gtk_source_file_loader_dispose (GObject *object)
 {
        GtkSourceFileLoader *loader = GTK_SOURCE_FILE_LOADER (object);
 
-       if (loader->source_buffer != NULL)
+       if (loader->priv->source_buffer != NULL)
        {
-               g_object_remove_weak_pointer (G_OBJECT (loader->source_buffer),
-                                             (gpointer *)&loader->source_buffer);
+               g_object_remove_weak_pointer (G_OBJECT (loader->priv->source_buffer),
+                                             (gpointer *)&loader->priv->source_buffer);
 
-               loader->source_buffer = NULL;
+               loader->priv->source_buffer = NULL;
        }
 
-       if (loader->file != NULL)
+       if (loader->priv->file != NULL)
        {
-               g_object_remove_weak_pointer (G_OBJECT (loader->file),
-                                             (gpointer *)&loader->file);
+               g_object_remove_weak_pointer (G_OBJECT (loader->priv->file),
+                                             (gpointer *)&loader->priv->file);
 
-               loader->file = NULL;
+               loader->priv->file = NULL;
        }
 
-       g_clear_object (&loader->location);
-       g_clear_object (&loader->input_stream_property);
-       g_clear_object (&loader->task);
+       g_clear_object (&loader->priv->location);
+       g_clear_object (&loader->priv->input_stream_property);
+       g_clear_object (&loader->priv->task);
 
-       g_slist_free (loader->candidate_encodings);
-       loader->candidate_encodings = NULL;
+       g_slist_free (loader->priv->candidate_encodings);
+       loader->priv->candidate_encodings = NULL;
 
        G_OBJECT_CLASS (gtk_source_file_loader_parent_class)->dispose (object);
 }
@@ -311,12 +313,12 @@ set_default_candidate_encodings (GtkSourceFileLoader *loader)
         */
        list = gtk_source_encoding_get_default_candidates ();
 
-       if (loader->file == NULL)
+       if (loader->priv->file == NULL)
        {
                goto end;
        }
 
-       file_encoding = gtk_source_file_get_encoding (loader->file);
+       file_encoding = gtk_source_file_get_encoding (loader->priv->file);
 
        if (file_encoding == NULL)
        {
@@ -342,8 +344,8 @@ set_default_candidate_encodings (GtkSourceFileLoader *loader)
        list = g_slist_prepend (list, (gpointer) file_encoding);
 
 end:
-       g_slist_free (loader->candidate_encodings);
-       loader->candidate_encodings = list;
+       g_slist_free (loader->priv->candidate_encodings);
+       loader->priv->candidate_encodings = list;
 }
 
 static void
@@ -351,18 +353,18 @@ gtk_source_file_loader_constructed (GObject *object)
 {
        GtkSourceFileLoader *loader = GTK_SOURCE_FILE_LOADER (object);
 
-       if (loader->file != NULL)
+       if (loader->priv->file != NULL)
        {
                set_default_candidate_encodings (loader);
 
-               if (loader->location == NULL &&
-                   loader->input_stream_property == NULL)
+               if (loader->priv->location == NULL &&
+                   loader->priv->input_stream_property == NULL)
                {
-                       loader->location = gtk_source_file_get_location (loader->file);
+                       loader->priv->location = gtk_source_file_get_location (loader->priv->file);
 
-                       if (loader->location != NULL)
+                       if (loader->priv->location != NULL)
                        {
-                               g_object_ref (loader->location);
+                               g_object_ref (loader->priv->location);
                        }
                        else
                        {
@@ -466,13 +468,13 @@ gtk_source_file_loader_class_init (GtkSourceFileLoaderClass *klass)
 static void
 gtk_source_file_loader_init (GtkSourceFileLoader *loader)
 {
-       loader = gtk_source_file_loader_get_instance_private (loader);
+       loader->priv = gtk_source_file_loader_get_instance_private (loader);
 }
 
 static void
 close_input_stream_cb (GObject      *source_object,
-                       GAsyncResult *result,
-                       gpointer      user_data)
+                      GAsyncResult *result,
+                      gpointer      user_data)
 {
        GInputStream *input_stream = G_INPUT_STREAM (source_object);
        GTask *task = G_TASK (user_data);
@@ -596,8 +598,8 @@ write_file_chunk (GTask *task)
 
 static void
 read_cb (GObject      *source_object,
-         GAsyncResult *result,
-         gpointer      user_data)
+        GAsyncResult *result,
+        gpointer      user_data)
 {
        GInputStream *input_stream = G_INPUT_STREAM (source_object);
        GTask *task = G_TASK (user_data);
@@ -657,10 +659,10 @@ read_cb (GObject      *source_object,
                /* Flush the stream to ensure proper line ending detection. */
                g_output_stream_flush (G_OUTPUT_STREAM (task_data->output_stream), NULL, NULL);
 
-               loader->auto_detected_encoding =
+               loader->priv->auto_detected_encoding =
                        gtk_source_buffer_output_stream_get_guessed (task_data->output_stream);
 
-               loader->auto_detected_newline_type =
+               loader->priv->auto_detected_newline_type =
                        gtk_source_buffer_output_stream_detect_newline_type (task_data->output_stream);
 
                write_complete (task);
@@ -717,11 +719,11 @@ create_input_stream (GTask *task)
        loader = g_task_get_source_object (task);
        task_data = g_task_get_task_data (task);
 
-       loader->auto_detected_compression_type = GTK_SOURCE_COMPRESSION_TYPE_NONE;
+       loader->priv->auto_detected_compression_type = GTK_SOURCE_COMPRESSION_TYPE_NONE;
 
-       if (loader->input_stream_property != NULL)
+       if (loader->priv->input_stream_property != NULL)
        {
-               task_data->input_stream = g_object_ref (loader->input_stream_property);
+               task_data->input_stream = g_object_ref (loader->priv->input_stream_property);
        }
        else if (g_file_info_has_attribute (task_data->info, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE))
        {
@@ -731,7 +733,7 @@ create_input_stream (GTask *task)
                {
                        case GTK_SOURCE_COMPRESSION_TYPE_GZIP:
                                add_gzip_decompressor_stream (task);
-                               loader->auto_detected_compression_type = GTK_SOURCE_COMPRESSION_TYPE_GZIP;
+                               loader->priv->auto_detected_compression_type = 
GTK_SOURCE_COMPRESSION_TYPE_GZIP;
                                break;
 
                        case GTK_SOURCE_COMPRESSION_TYPE_NONE:
@@ -751,8 +753,8 @@ create_input_stream (GTask *task)
 
 static void
 query_info_cb (GObject      *source_object,
-               GAsyncResult *result,
-               gpointer      user_data)
+              GAsyncResult *result,
+              gpointer      user_data)
 {
        GFile *location = G_FILE (source_object);
        GTask *task = G_TASK (user_data);
@@ -795,8 +797,8 @@ query_info_cb (GObject      *source_object,
 
 static void
 mount_cb (GObject      *source_object,
-          GAsyncResult *result,
-          gpointer      user_data)
+         GAsyncResult *result,
+         gpointer      user_data)
 {
        GFile *location = G_FILE (source_object);
        GTask *task = G_TASK (user_data);
@@ -829,7 +831,7 @@ recover_not_mounted (GTask *task)
        loader = g_task_get_source_object (task);
        task_data = g_task_get_task_data (task);
 
-       mount_operation = _gtk_source_file_create_mount_operation (loader->file);
+       mount_operation = _gtk_source_file_create_mount_operation (loader->priv->file);
 
        DEBUG ({
               g_print ("%s\n", G_STRFUNC);
@@ -837,7 +839,7 @@ recover_not_mounted (GTask *task)
 
        task_data->tried_mount = TRUE;
 
-       g_file_mount_enclosing_volume (loader->location,
+       g_file_mount_enclosing_volume (loader->priv->location,
                                       G_MOUNT_MOUNT_NONE,
                                       mount_operation,
                                       g_task_get_cancellable (task),
@@ -849,8 +851,8 @@ recover_not_mounted (GTask *task)
 
 static void
 open_file_cb (GObject      *source_object,
-              GAsyncResult *result,
-              gpointer      user_data)
+             GAsyncResult *result,
+             gpointer      user_data)
 {
        GFile *location = G_FILE (source_object);
        GTask *task = G_TASK (user_data);
@@ -902,7 +904,7 @@ open_file (GTask *task)
 
        loader = g_task_get_source_object (task);
 
-       g_file_read_async (loader->location,
+       g_file_read_async (loader->priv->location,
                           g_task_get_priority (task),
                           g_task_get_cancellable (task),
                           open_file_cb,
@@ -938,7 +940,7 @@ gtk_source_file_loader_error_quark (void)
  */
 GtkSourceFileLoader *
 gtk_source_file_loader_new (GtkSourceBuffer *buffer,
-                            GtkSourceFile   *file)
+                           GtkSourceFile   *file)
 {
        g_return_val_if_fail (GTK_SOURCE_IS_BUFFER (buffer), NULL);
        g_return_val_if_fail (GTK_SOURCE_IS_FILE (file), NULL);
@@ -962,8 +964,8 @@ gtk_source_file_loader_new (GtkSourceBuffer *buffer,
  */
 GtkSourceFileLoader *
 gtk_source_file_loader_new_from_stream (GtkSourceBuffer *buffer,
-                                        GtkSourceFile   *file,
-                                        GInputStream    *stream)
+                                       GtkSourceFile   *file,
+                                       GInputStream    *stream)
 {
        g_return_val_if_fail (GTK_SOURCE_IS_BUFFER (buffer), NULL);
        g_return_val_if_fail (GTK_SOURCE_IS_FILE (file), NULL);
@@ -998,18 +1000,18 @@ gtk_source_file_loader_new_from_stream (GtkSourceBuffer *buffer,
  */
 void
 gtk_source_file_loader_set_candidate_encodings (GtkSourceFileLoader *loader,
-                                                GSList              *candidate_encodings)
+                                               GSList              *candidate_encodings)
 {
        GSList *list;
 
        g_return_if_fail (GTK_SOURCE_IS_FILE_LOADER (loader));
-       g_return_if_fail (loader->task == NULL);
+       g_return_if_fail (loader->priv->task == NULL);
 
        list = g_slist_copy (candidate_encodings);
        list = _gtk_source_encoding_remove_duplicates (list, GTK_SOURCE_ENCODING_DUPLICATES_KEEP_FIRST);
 
-       g_slist_free (loader->candidate_encodings);
-       loader->candidate_encodings = list;
+       g_slist_free (loader->priv->candidate_encodings);
+       loader->priv->candidate_encodings = list;
 }
 
 /**
@@ -1024,7 +1026,7 @@ gtk_source_file_loader_get_buffer (GtkSourceFileLoader *loader)
 {
        g_return_val_if_fail (GTK_SOURCE_IS_FILE_LOADER (loader), NULL);
 
-       return loader->source_buffer;
+       return loader->priv->source_buffer;
 }
 
 /**
@@ -1039,7 +1041,7 @@ gtk_source_file_loader_get_file (GtkSourceFileLoader *loader)
 {
        g_return_val_if_fail (GTK_SOURCE_IS_FILE_LOADER (loader), NULL);
 
-       return loader->file;
+       return loader->priv->file;
 }
 
 /**
@@ -1055,7 +1057,7 @@ gtk_source_file_loader_get_location (GtkSourceFileLoader *loader)
 {
        g_return_val_if_fail (GTK_SOURCE_IS_FILE_LOADER (loader), NULL);
 
-       return loader->location;
+       return loader->priv->location;
 }
 
 /**
@@ -1071,7 +1073,7 @@ gtk_source_file_loader_get_input_stream (GtkSourceFileLoader *loader)
 {
        g_return_val_if_fail (GTK_SOURCE_IS_FILE_LOADER (loader), NULL);
 
-       return loader->input_stream_property;
+       return loader->priv->input_stream_property;
 }
 
 /**
@@ -1102,36 +1104,36 @@ gtk_source_file_loader_get_input_stream (GtkSourceFileLoader *loader)
  */
 void
 gtk_source_file_loader_load_async (GtkSourceFileLoader   *loader,
-                                   gint                   io_priority,
-                                   GCancellable          *cancellable,
-                                   GFileProgressCallback  progress_callback,
-                                   gpointer               progress_callback_data,
-                                   GDestroyNotify         progress_callback_notify,
-                                   GAsyncReadyCallback    callback,
-                                   gpointer               user_data)
+                                  gint                   io_priority,
+                                  GCancellable          *cancellable,
+                                  GFileProgressCallback  progress_callback,
+                                  gpointer               progress_callback_data,
+                                  GDestroyNotify         progress_callback_notify,
+                                  GAsyncReadyCallback    callback,
+                                  gpointer               user_data)
 {
        TaskData *task_data;
        gboolean implicit_trailing_newline;
 
        g_return_if_fail (GTK_SOURCE_IS_FILE_LOADER (loader));
        g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
-       g_return_if_fail (loader->task == NULL);
+       g_return_if_fail (loader->priv->task == NULL);
 
-       loader->task = g_task_new (loader, cancellable, callback, user_data);
-       g_task_set_priority (loader->task, io_priority);
+       loader->priv->task = g_task_new (loader, cancellable, callback, user_data);
+       g_task_set_priority (loader->priv->task, io_priority);
 
        task_data = task_data_new ();
-       g_task_set_task_data (loader->task, task_data, task_data_free);
+       g_task_set_task_data (loader->priv->task, task_data, task_data_free);
 
        task_data->progress_cb = progress_callback;
        task_data->progress_cb_data = progress_callback_data;
        task_data->progress_cb_notify = progress_callback_notify;
 
-       if (loader->source_buffer == NULL ||
-           loader->file == NULL ||
-           (loader->location == NULL && loader->input_stream_property == NULL))
+       if (loader->priv->source_buffer == NULL ||
+           loader->priv->file == NULL ||
+           (loader->priv->location == NULL && loader->priv->input_stream_property == NULL))
        {
-               g_task_return_boolean (loader->task, FALSE);
+               g_task_return_boolean (loader->priv->task, FALSE);
                return;
        }
 
@@ -1146,36 +1148,36 @@ gtk_source_file_loader_load_async (GtkSourceFileLoader   *loader,
         * location is directly needed (for example to display the filename in a
         * tab or an info bar with the progress information).
         */
-       if (loader->input_stream_property != NULL)
+       if (loader->priv->input_stream_property != NULL)
        {
-               gtk_source_file_set_location (loader->file, NULL);
+               gtk_source_file_set_location (loader->priv->file, NULL);
        }
        else
        {
-               gtk_source_file_set_location (loader->file,
-                                             loader->location);
+               gtk_source_file_set_location (loader->priv->file,
+                                             loader->priv->location);
        }
 
-       implicit_trailing_newline = gtk_source_buffer_get_implicit_trailing_newline (loader->source_buffer);
+       implicit_trailing_newline = gtk_source_buffer_get_implicit_trailing_newline 
(loader->priv->source_buffer);
 
        /* The BufferOutputStream has a strong reference to the buffer.
          * We create the BufferOutputStream here so we are sure that the
          * buffer will not be destroyed during the file loading.
          */
-       task_data->output_stream = gtk_source_buffer_output_stream_new (loader->source_buffer,
-                                                                       loader->candidate_encodings,
+       task_data->output_stream = gtk_source_buffer_output_stream_new (loader->priv->source_buffer,
+                                                                       loader->priv->candidate_encodings,
                                                                        implicit_trailing_newline);
 
-       if (loader->input_stream_property != NULL)
+       if (loader->priv->input_stream_property != NULL)
        {
                task_data->guess_content_type_from_content = TRUE;
                task_data->info = g_file_info_new ();
 
-               create_input_stream (loader->task);
+               create_input_stream (loader->priv->task);
        }
        else
        {
-               open_file (loader->task);
+               open_file (loader->priv->task);
        }
 }
 
@@ -1196,8 +1198,8 @@ gtk_source_file_loader_load_async (GtkSourceFileLoader   *loader,
  */
 gboolean
 gtk_source_file_loader_load_finish (GtkSourceFileLoader  *loader,
-                                    GAsyncResult         *result,
-                                    GError              **error)
+                                   GAsyncResult         *result,
+                                   GError              **error)
 {
        gboolean ok;
        gboolean update_file_properties;
@@ -1226,7 +1228,7 @@ gtk_source_file_loader_load_finish (GtkSourceFileLoader  *loader,
                                        real_error->domain == GTK_SOURCE_FILE_LOADER_ERROR &&
                                        real_error->code == GTK_SOURCE_FILE_LOADER_ERROR_CONVERSION_FALLBACK);
 
-       if (update_file_properties && loader->file != NULL)
+       if (update_file_properties && loader->priv->file != NULL)
        {
                TaskData *task_data;
 
@@ -1236,24 +1238,32 @@ gtk_source_file_loader_load_finish (GtkSourceFileLoader  *loader,
                 * operation.
                 */
 
-               _gtk_source_file_set_encoding (loader->file,
-                                              loader->auto_detected_encoding);
+               _gtk_source_file_set_encoding (loader->priv->file,
+                                              loader->priv->auto_detected_encoding);
 
-               _gtk_source_file_set_newline_type (loader->file,
-                                                  loader->auto_detected_newline_type);
+               _gtk_source_file_set_newline_type (loader->priv->file,
+                                                  loader->priv->auto_detected_newline_type);
 
-               _gtk_source_file_set_compression_type (loader->file,
-                                                      loader->auto_detected_compression_type);
+               _gtk_source_file_set_compression_type (loader->priv->file,
+                                                      loader->priv->auto_detected_compression_type);
 
-               _gtk_source_file_set_externally_modified (loader->file, FALSE);
-               _gtk_source_file_set_deleted (loader->file, FALSE);
+               _gtk_source_file_set_externally_modified (loader->priv->file, FALSE);
+               _gtk_source_file_set_deleted (loader->priv->file, FALSE);
 
                if (g_file_info_has_attribute (task_data->info, G_FILE_ATTRIBUTE_TIME_MODIFIED))
                {
-                       GTimeVal modification_time;
+                       GDateTime *dt;
+                       gint64 mtime = 0;
+
+                       dt = g_file_info_get_modification_date_time (task_data->info);
+
+                       if (dt != NULL)
+                       {
+                               mtime = g_date_time_to_unix (dt);
+                               g_date_time_unref (dt);
+                       }
 
-                       g_file_info_get_modification_time (task_data->info, &modification_time);
-                       _gtk_source_file_set_modification_time (loader->file, modification_time);
+                       _gtk_source_file_set_modification_time (loader->priv->file, mtime);
                }
 
                if (g_file_info_has_attribute (task_data->info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE))
@@ -1263,15 +1273,15 @@ gtk_source_file_loader_load_finish (GtkSourceFileLoader  *loader,
                        readonly = !g_file_info_get_attribute_boolean (task_data->info,
                                                                       G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE);
 
-                       _gtk_source_file_set_readonly (loader->file, readonly);
+                       _gtk_source_file_set_readonly (loader->priv->file, readonly);
                }
                else
                {
-                       _gtk_source_file_set_readonly (loader->file, FALSE);
+                       _gtk_source_file_set_readonly (loader->priv->file, FALSE);
                }
        }
 
-       g_clear_object (&loader->task);
+       g_clear_object (&loader->priv->task);
 
        if (real_error != NULL)
        {
@@ -1293,7 +1303,7 @@ gtk_source_file_loader_get_encoding (GtkSourceFileLoader *loader)
 {
        g_return_val_if_fail (GTK_SOURCE_IS_FILE_LOADER (loader), NULL);
 
-       return loader->auto_detected_encoding;
+       return loader->priv->auto_detected_encoding;
 }
 
 /**
@@ -1309,7 +1319,7 @@ gtk_source_file_loader_get_newline_type (GtkSourceFileLoader *loader)
        g_return_val_if_fail (GTK_SOURCE_IS_FILE_LOADER (loader),
                              GTK_SOURCE_NEWLINE_TYPE_LF);
 
-       return loader->auto_detected_newline_type;
+       return loader->priv->auto_detected_newline_type;
 }
 
 /**
@@ -1325,5 +1335,5 @@ gtk_source_file_loader_get_compression_type (GtkSourceFileLoader *loader)
        g_return_val_if_fail (GTK_SOURCE_IS_FILE_LOADER (loader),
                              GTK_SOURCE_COMPRESSION_TYPE_NONE);
 
-       return loader->auto_detected_compression_type;
+       return loader->priv->auto_detected_compression_type;
 }
diff --git a/gtksourceview/gtksourcefileloader.h b/gtksourceview/gtksourcefileloader.h
index aee8b094..85fda09c 100644
--- a/gtksourceview/gtksourcefileloader.h
+++ b/gtksourceview/gtksourcefileloader.h
@@ -2,10 +2,10 @@
 /*
  * This file is part of GtkSourceView
  *
- * Copyright 2005 - Paolo Maggi
- * Copyright 2007 - Paolo Maggi, Steve Frécinaux
- * Copyright 2008 - Jesse van den Kieboom
- * Copyright 2014 - Sébastien Wilmet
+ * Copyright (C) 2005 - Paolo Maggi
+ * Copyright (C) 2007 - Paolo Maggi, Steve Frécinaux
+ * Copyright (C) 2008 - Jesse van den Kieboom
+ * Copyright (C) 2014 - Sébastien Wilmet
  *
  * GtkSourceView is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -21,7 +21,8 @@
  * along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#pragma once
+#ifndef GTK_SOURCE_FILE_LOADER_H
+#define GTK_SOURCE_FILE_LOADER_H
 
 #if !defined (GTK_SOURCE_H_INSIDE) && !defined (GTK_SOURCE_COMPILATION)
 #error "Only <gtksourceview/gtksource.h> can be included directly."
@@ -34,8 +35,17 @@
 
 G_BEGIN_DECLS
 
-#define GTK_SOURCE_TYPE_FILE_LOADER  (gtk_source_file_loader_get_type())
-#define GTK_SOURCE_FILE_LOADER_ERROR (gtk_source_file_loader_error_quark())
+#define GTK_SOURCE_TYPE_FILE_LOADER              (gtk_source_file_loader_get_type())
+#define GTK_SOURCE_FILE_LOADER(obj)              (G_TYPE_CHECK_INSTANCE_CAST((obj), 
GTK_SOURCE_TYPE_FILE_LOADER, GtkSourceFileLoader))
+#define GTK_SOURCE_FILE_LOADER_CLASS(klass)      (G_TYPE_CHECK_CLASS_CAST((klass), 
GTK_SOURCE_TYPE_FILE_LOADER, GtkSourceFileLoaderClass))
+#define GTK_SOURCE_IS_FILE_LOADER(obj)           (G_TYPE_CHECK_INSTANCE_TYPE((obj), 
GTK_SOURCE_TYPE_FILE_LOADER))
+#define GTK_SOURCE_IS_FILE_LOADER_CLASS(klass)   (G_TYPE_CHECK_CLASS_TYPE ((klass), 
GTK_SOURCE_TYPE_FILE_LOADER))
+#define GTK_SOURCE_FILE_LOADER_GET_CLASS(obj)    (G_TYPE_INSTANCE_GET_CLASS((obj), 
GTK_SOURCE_TYPE_FILE_LOADER, GtkSourceFileLoaderClass))
+
+typedef struct _GtkSourceFileLoaderClass   GtkSourceFileLoaderClass;
+typedef struct _GtkSourceFileLoaderPrivate GtkSourceFileLoaderPrivate;
+
+#define GTK_SOURCE_FILE_LOADER_ERROR gtk_source_file_loader_error_quark ()
 
 /**
  * GtkSourceFileLoaderError:
@@ -54,47 +64,78 @@ typedef enum _GtkSourceFileLoaderError
        GTK_SOURCE_FILE_LOADER_ERROR_CONVERSION_FALLBACK
 } GtkSourceFileLoaderError;
 
+struct _GtkSourceFileLoader
+{
+       GObject parent;
+
+       GtkSourceFileLoaderPrivate *priv;
+};
+
+struct _GtkSourceFileLoaderClass
+{
+       GObjectClass parent_class;
+
+       gpointer padding[10];
+};
+
 GTK_SOURCE_AVAILABLE_IN_3_14
-G_DECLARE_FINAL_TYPE (GtkSourceFileLoader, gtk_source_file_loader, GTK_SOURCE, FILE_LOADER, GObject)
+GType                   gtk_source_file_loader_get_type        (void) G_GNUC_CONST;
 
 GTK_SOURCE_AVAILABLE_IN_3_14
-GQuark                    gtk_source_file_loader_error_quark             (void);
+GQuark                  gtk_source_file_loader_error_quark     (void);
+
 GTK_SOURCE_AVAILABLE_IN_3_14
-GtkSourceFileLoader      *gtk_source_file_loader_new                     (GtkSourceBuffer        *buffer,
-                                                                          GtkSourceFile          *file);
+GtkSourceFileLoader    *gtk_source_file_loader_new             (GtkSourceBuffer         *buffer,
+                                                                GtkSourceFile           *file);
+
 GTK_SOURCE_AVAILABLE_IN_3_14
-GtkSourceFileLoader      *gtk_source_file_loader_new_from_stream         (GtkSourceBuffer        *buffer,
-                                                                          GtkSourceFile          *file,
-                                                                          GInputStream           *stream);
+GtkSourceFileLoader    *gtk_source_file_loader_new_from_stream (GtkSourceBuffer         *buffer,
+                                                                GtkSourceFile           *file,
+                                                                GInputStream            *stream);
+
 GTK_SOURCE_AVAILABLE_IN_3_14
-void                      gtk_source_file_loader_set_candidate_encodings (GtkSourceFileLoader    *loader,
-                                                                          GSList                 
*candidate_encodings);
+void                    gtk_source_file_loader_set_candidate_encodings
+                                                               (GtkSourceFileLoader     *loader,
+                                                                GSList                  
*candidate_encodings);
+
 GTK_SOURCE_AVAILABLE_IN_3_14
-GtkSourceBuffer          *gtk_source_file_loader_get_buffer              (GtkSourceFileLoader    *loader);
+GtkSourceBuffer                *gtk_source_file_loader_get_buffer      (GtkSourceFileLoader     *loader);
+
 GTK_SOURCE_AVAILABLE_IN_3_14
-GtkSourceFile            *gtk_source_file_loader_get_file                (GtkSourceFileLoader    *loader);
+GtkSourceFile          *gtk_source_file_loader_get_file        (GtkSourceFileLoader     *loader);
+
 GTK_SOURCE_AVAILABLE_IN_3_14
-GFile                    *gtk_source_file_loader_get_location            (GtkSourceFileLoader    *loader);
+GFile                  *gtk_source_file_loader_get_location    (GtkSourceFileLoader     *loader);
+
 GTK_SOURCE_AVAILABLE_IN_3_14
-GInputStream             *gtk_source_file_loader_get_input_stream        (GtkSourceFileLoader    *loader);
+GInputStream           *gtk_source_file_loader_get_input_stream
+                                                               (GtkSourceFileLoader     *loader);
+
 GTK_SOURCE_AVAILABLE_IN_3_14
-void                      gtk_source_file_loader_load_async              (GtkSourceFileLoader    *loader,
-                                                                          gint                    
io_priority,
-                                                                          GCancellable           
*cancellable,
-                                                                          GFileProgressCallback   
progress_callback,
-                                                                          gpointer                
progress_callback_data,
-                                                                          GDestroyNotify          
progress_callback_notify,
-                                                                          GAsyncReadyCallback     callback,
-                                                                          gpointer                user_data);
+void                    gtk_source_file_loader_load_async      (GtkSourceFileLoader     *loader,
+                                                                gint                     io_priority,
+                                                                GCancellable            *cancellable,
+                                                                GFileProgressCallback    progress_callback,
+                                                                gpointer                 
progress_callback_data,
+                                                                GDestroyNotify           
progress_callback_notify,
+                                                                GAsyncReadyCallback      callback,
+                                                                gpointer                 user_data);
+
 GTK_SOURCE_AVAILABLE_IN_3_14
-gboolean                  gtk_source_file_loader_load_finish             (GtkSourceFileLoader    *loader,
-                                                                          GAsyncResult           *result,
-                                                                          GError                **error);
+gboolean                gtk_source_file_loader_load_finish     (GtkSourceFileLoader     *loader,
+                                                                GAsyncResult            *result,
+                                                                GError                 **error);
+
 GTK_SOURCE_AVAILABLE_IN_3_14
-const GtkSourceEncoding  *gtk_source_file_loader_get_encoding            (GtkSourceFileLoader    *loader);
+const GtkSourceEncoding        *gtk_source_file_loader_get_encoding    (GtkSourceFileLoader     *loader);
+
 GTK_SOURCE_AVAILABLE_IN_3_14
-GtkSourceNewlineType      gtk_source_file_loader_get_newline_type        (GtkSourceFileLoader    *loader);
+GtkSourceNewlineType    gtk_source_file_loader_get_newline_type (GtkSourceFileLoader    *loader);
+
 GTK_SOURCE_AVAILABLE_IN_3_14
-GtkSourceCompressionType  gtk_source_file_loader_get_compression_type    (GtkSourceFileLoader    *loader);
+GtkSourceCompressionType gtk_source_file_loader_get_compression_type
+                                                               (GtkSourceFileLoader     *loader);
 
 G_END_DECLS
+
+#endif  /* GTK_SOURCE_FILE_LOADER_H  */
diff --git a/gtksourceview/gtksourcefilesaver.c b/gtksourceview/gtksourcefilesaver.c
index 18e87913..22b87115 100644
--- a/gtksourceview/gtksourcefilesaver.c
+++ b/gtksourceview/gtksourcefilesaver.c
@@ -2,10 +2,10 @@
 /*
  * This file is part of GtkSourceView
  *
- * Copyright 2005-2007 - Paolo Borelli and Paolo Maggi
- * Copyright 2007 - Steve Frécinaux
- * Copyright 2008 - Jesse van den Kieboom
- * Copyright 2014, 2016 - Sébastien Wilmet
+ * Copyright (C) 2005-2007 - Paolo Borelli and Paolo Maggi
+ * Copyright (C) 2007 - Steve Frécinaux
+ * Copyright (C) 2008 - Jesse van den Kieboom
+ * Copyright (C) 2014, 2016 - Sébastien Wilmet
  *
  * GtkSourceView is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -21,17 +21,19 @@
  * along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "config.h"
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
 
 #include <glib/gi18n-lib.h>
 
-#include "gtksourcefilesaver.h"
-#include "gtksourcefile-private.h"
+#include "gtksourcebuffer-private.h"
 #include "gtksourcebufferinputstream-private.h"
 #include "gtksourceencoding.h"
-#include "gtksourcebuffer.h"
-#include "gtksourcebuffer-private.h"
 #include "gtksource-enumtypes.h"
+#include "gtksourcefile.h"
+#include "gtksourcefile-private.h"
+#include "gtksourcefilesaver.h"
 
 /**
  * SECTION:filesaver
@@ -81,10 +83,8 @@ enum
        PROP_FLAGS
 };
 
-struct _GtkSourceFileSaver
+struct _GtkSourceFileSaverPrivate
 {
-       GObject parent_instance;
-
        /* Weak ref to the GtkSourceBuffer. A strong ref could create a
         * reference cycle in an application. For example a subclass of
         * GtkSourceBuffer can have a strong ref to the FileSaver.
@@ -107,7 +107,8 @@ struct _GtkSourceFileSaver
        GTask *task;
 };
 
-typedef struct
+typedef struct _TaskData TaskData;
+struct _TaskData
 {
        /* The output_stream contains the required converter(s) for the encoding
         * and the compression type.
@@ -137,12 +138,12 @@ typedef struct
        gchar chunk_buffer[WRITE_CHUNK_SIZE];
 
        guint tried_mount : 1;
-} TaskData;
+};
 
-G_DEFINE_TYPE (GtkSourceFileSaver, gtk_source_file_saver, G_TYPE_OBJECT)
+G_DEFINE_TYPE_WITH_PRIVATE (GtkSourceFileSaver, gtk_source_file_saver, G_TYPE_OBJECT)
 
-static void read_file_chunk     (GTask *task);
-static void write_file_chunk    (GTask *task);
+static void read_file_chunk (GTask *task);
+static void write_file_chunk (GTask *task);
 static void recover_not_mounted (GTask *task);
 
 static TaskData *
@@ -176,31 +177,31 @@ task_data_free (gpointer data)
 
 static void
 gtk_source_file_saver_set_property (GObject      *object,
-                                    guint         prop_id,
-                                    const GValue *value,
-                                    GParamSpec   *pspec)
+                                   guint         prop_id,
+                                   const GValue *value,
+                                   GParamSpec   *pspec)
 {
        GtkSourceFileSaver *saver = GTK_SOURCE_FILE_SAVER (object);
 
        switch (prop_id)
        {
                case PROP_BUFFER:
-                       g_assert (saver->source_buffer == NULL);
-                       saver->source_buffer = g_value_get_object (value);
-                       g_object_add_weak_pointer (G_OBJECT (saver->source_buffer),
-                                                  (gpointer *)&saver->source_buffer);
+                       g_assert (saver->priv->source_buffer == NULL);
+                       saver->priv->source_buffer = g_value_get_object (value);
+                       g_object_add_weak_pointer (G_OBJECT (saver->priv->source_buffer),
+                                                  (gpointer *)&saver->priv->source_buffer);
                        break;
 
                case PROP_FILE:
-                       g_assert (saver->file == NULL);
-                       saver->file = g_value_get_object (value);
-                       g_object_add_weak_pointer (G_OBJECT (saver->file),
-                                                  (gpointer *)&saver->file);
+                       g_assert (saver->priv->file == NULL);
+                       saver->priv->file = g_value_get_object (value);
+                       g_object_add_weak_pointer (G_OBJECT (saver->priv->file),
+                                                  (gpointer *)&saver->priv->file);
                        break;
 
                case PROP_LOCATION:
-                       g_assert (saver->location == NULL);
-                       saver->location = g_value_dup_object (value);
+                       g_assert (saver->priv->location == NULL);
+                       saver->priv->location = g_value_dup_object (value);
                        break;
 
                case PROP_ENCODING:
@@ -227,40 +228,40 @@ gtk_source_file_saver_set_property (GObject      *object,
 
 static void
 gtk_source_file_saver_get_property (GObject    *object,
-                                    guint       prop_id,
-                                    GValue     *value,
-                                    GParamSpec *pspec)
+                                   guint       prop_id,
+                                   GValue     *value,
+                                   GParamSpec *pspec)
 {
        GtkSourceFileSaver *saver = GTK_SOURCE_FILE_SAVER (object);
 
        switch (prop_id)
        {
                case PROP_BUFFER:
-                       g_value_set_object (value, saver->source_buffer);
+                       g_value_set_object (value, saver->priv->source_buffer);
                        break;
 
                case PROP_FILE:
-                       g_value_set_object (value, saver->file);
+                       g_value_set_object (value, saver->priv->file);
                        break;
 
                case PROP_LOCATION:
-                       g_value_set_object (value, saver->location);
+                       g_value_set_object (value, saver->priv->location);
                        break;
 
                case PROP_ENCODING:
-                       g_value_set_boxed (value, saver->encoding);
+                       g_value_set_boxed (value, saver->priv->encoding);
                        break;
 
                case PROP_NEWLINE_TYPE:
-                       g_value_set_enum (value, saver->newline_type);
+                       g_value_set_enum (value, saver->priv->newline_type);
                        break;
 
                case PROP_COMPRESSION_TYPE:
-                       g_value_set_enum (value, saver->compression_type);
+                       g_value_set_enum (value, saver->priv->compression_type);
                        break;
 
                case PROP_FLAGS:
-                       g_value_set_flags (value, saver->flags);
+                       g_value_set_flags (value, saver->priv->flags);
                        break;
 
                default:
@@ -274,24 +275,24 @@ gtk_source_file_saver_dispose (GObject *object)
 {
        GtkSourceFileSaver *saver = GTK_SOURCE_FILE_SAVER (object);
 
-       if (saver->source_buffer != NULL)
+       if (saver->priv->source_buffer != NULL)
        {
-               g_object_remove_weak_pointer (G_OBJECT (saver->source_buffer),
-                                             (gpointer *)&saver->source_buffer);
+               g_object_remove_weak_pointer (G_OBJECT (saver->priv->source_buffer),
+                                             (gpointer *)&saver->priv->source_buffer);
 
-               saver->source_buffer = NULL;
+               saver->priv->source_buffer = NULL;
        }
 
-       if (saver->file != NULL)
+       if (saver->priv->file != NULL)
        {
-               g_object_remove_weak_pointer (G_OBJECT (saver->file),
-                                             (gpointer *)&saver->file);
+               g_object_remove_weak_pointer (G_OBJECT (saver->priv->file),
+                                             (gpointer *)&saver->priv->file);
 
-               saver->file = NULL;
+               saver->priv->file = NULL;
        }
 
-       g_clear_object (&saver->location);
-       g_clear_object (&saver->task);
+       g_clear_object (&saver->priv->location);
+       g_clear_object (&saver->priv->task);
 
        G_OBJECT_CLASS (gtk_source_file_saver_parent_class)->dispose (object);
 }
@@ -301,28 +302,28 @@ gtk_source_file_saver_constructed (GObject *object)
 {
        GtkSourceFileSaver *saver = GTK_SOURCE_FILE_SAVER (object);
 
-       if (saver->file != NULL)
+       if (saver->priv->file != NULL)
        {
                const GtkSourceEncoding *encoding;
                GtkSourceNewlineType newline_type;
                GtkSourceCompressionType compression_type;
 
-               encoding = gtk_source_file_get_encoding (saver->file);
+               encoding = gtk_source_file_get_encoding (saver->priv->file);
                gtk_source_file_saver_set_encoding (saver, encoding);
 
-               newline_type = gtk_source_file_get_newline_type (saver->file);
+               newline_type = gtk_source_file_get_newline_type (saver->priv->file);
                gtk_source_file_saver_set_newline_type (saver, newline_type);
 
-               compression_type = gtk_source_file_get_compression_type (saver->file);
+               compression_type = gtk_source_file_get_compression_type (saver->priv->file);
                gtk_source_file_saver_set_compression_type (saver, compression_type);
 
-               if (saver->location == NULL)
+               if (saver->priv->location == NULL)
                {
-                       saver->location = gtk_source_file_get_location (saver->file);
+                       saver->priv->location = gtk_source_file_get_location (saver->priv->file);
 
-                       if (saver->location != NULL)
+                       if (saver->priv->location != NULL)
                        {
-                               g_object_ref (saver->location);
+                               g_object_ref (saver->priv->location);
                        }
                        else
                        {
@@ -482,6 +483,7 @@ gtk_source_file_saver_class_init (GtkSourceFileSaverClass *klass)
 static void
 gtk_source_file_saver_init (GtkSourceFileSaver *saver)
 {
+       saver->priv = gtk_source_file_saver_get_instance_private (saver);
 }
 
 /* BEGIN NOTE:
@@ -507,8 +509,8 @@ gtk_source_file_saver_init (GtkSourceFileSaver *saver)
  */
 static void
 cancel_output_stream_ready_cb (GObject      *source_object,
-                               GAsyncResult *result,
-                               gpointer      user_data)
+                              GAsyncResult *result,
+                              gpointer      user_data)
 {
        GOutputStream *output_stream = G_OUTPUT_STREAM (source_object);
        GTask *task = G_TASK (user_data);
@@ -560,8 +562,8 @@ cancel_output_stream (GTask *task)
 
 static void
 query_info_cb (GObject      *source_object,
-               GAsyncResult *result,
-               gpointer      user_data)
+              GAsyncResult *result,
+              gpointer      user_data)
 {
        GFile *location = G_FILE (source_object);
        GTask *task = G_TASK (user_data);
@@ -592,8 +594,8 @@ query_info_cb (GObject      *source_object,
 
 static void
 close_output_stream_cb (GObject      *source_object,
-                        GAsyncResult *result,
-                        gpointer      user_data)
+                       GAsyncResult *result,
+                       gpointer      user_data)
 {
        GOutputStream *output_stream = G_OUTPUT_STREAM (source_object);
        GTask *task = G_TASK (user_data);
@@ -626,7 +628,7 @@ close_output_stream_cb (GObject      *source_object,
               g_print ("Query info on file\n");
        });
 
-       g_file_query_info_async (saver->location,
+       g_file_query_info_async (saver->priv->location,
                                 QUERY_ATTRIBUTES,
                                 G_FILE_QUERY_INFO_NONE,
                                 g_task_get_priority (task),
@@ -676,8 +678,8 @@ write_complete (GTask *task)
 
 static void
 write_file_chunk_cb (GObject      *source_object,
-                     GAsyncResult *result,
-                     gpointer      user_data)
+                    GAsyncResult *result,
+                    gpointer      user_data)
 {
        GOutputStream *output_stream = G_OUTPUT_STREAM (source_object);
        GTask *task = G_TASK (user_data);
@@ -795,8 +797,8 @@ read_file_chunk (GTask *task)
 
 static void
 replace_file_cb (GObject      *source_object,
-                 GAsyncResult *result,
-                 gpointer      user_data)
+                GAsyncResult *result,
+                gpointer      user_data)
 {
        GFile *location = G_FILE (source_object);
        GTask *task = G_TASK (user_data);
@@ -832,7 +834,7 @@ replace_file_cb (GObject      *source_object,
                return;
        }
 
-       if (saver->compression_type == GTK_SOURCE_COMPRESSION_TYPE_GZIP)
+       if (saver->priv->compression_type == GTK_SOURCE_COMPRESSION_TYPE_GZIP)
        {
                GZlibCompressor *compressor;
 
@@ -857,14 +859,14 @@ replace_file_cb (GObject      *source_object,
 
        DEBUG ({
               g_print ("Encoding charset: %s\n",
-                       gtk_source_encoding_get_charset (saver->encoding));
+                       gtk_source_encoding_get_charset (saver->priv->encoding));
        });
 
-       if (saver->encoding != gtk_source_encoding_get_utf8 ())
+       if (saver->priv->encoding != gtk_source_encoding_get_utf8 ())
        {
                GCharsetConverter *converter;
 
-               converter = g_charset_converter_new (gtk_source_encoding_get_charset (saver->encoding),
+               converter = g_charset_converter_new (gtk_source_encoding_get_charset (saver->priv->encoding),
                                                     "UTF-8",
                                                     NULL);
 
@@ -898,14 +900,14 @@ begin_write (GTask *task)
 
        saver = g_task_get_source_object (task);
 
-       create_backup = (saver->flags & GTK_SOURCE_FILE_SAVER_FLAGS_CREATE_BACKUP) != 0;
+       create_backup = (saver->priv->flags & GTK_SOURCE_FILE_SAVER_FLAGS_CREATE_BACKUP) != 0;
 
        DEBUG ({
               g_print ("Start replacing file contents\n");
               g_print ("Make backup: %s\n", create_backup ? "yes" : "no");
        });
 
-       g_file_replace_async (saver->location,
+       g_file_replace_async (saver->priv->location,
                              NULL,
                              create_backup,
                              G_FILE_CREATE_NONE,
@@ -917,16 +919,16 @@ begin_write (GTask *task)
 
 static void
 check_externally_modified_cb (GObject      *source_object,
-                              GAsyncResult *result,
-                              gpointer      user_data)
+                             GAsyncResult *result,
+                             gpointer      user_data)
 {
        GFile *location = G_FILE (source_object);
        GTask *task = G_TASK (user_data);
        GtkSourceFileSaver *saver;
        TaskData *task_data;
        GFileInfo *info;
-       GTimeVal old_mtime;
-       GTimeVal cur_mtime;
+       gint64 old_mtime;
+       gint64 cur_mtime;
        GError *error = NULL;
 
        DEBUG ({
@@ -961,14 +963,17 @@ check_externally_modified_cb (GObject      *source_object,
                return;
        }
 
-       if (_gtk_source_file_get_modification_time (saver->file, &old_mtime) &&
+       if (_gtk_source_file_get_modification_time (saver->priv->file, &old_mtime) &&
            info != NULL &&
            g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_TIME_MODIFIED))
        {
-               g_file_info_get_modification_time (info, &cur_mtime);
+               GDateTime *dt;
 
-               if (old_mtime.tv_sec != cur_mtime.tv_sec ||
-                   old_mtime.tv_usec != cur_mtime.tv_usec)
+               dt = g_file_info_get_modification_date_time (info);
+               cur_mtime = g_date_time_to_unix (dt);
+               g_date_time_unref (dt);
+
+               if (old_mtime != cur_mtime)
                {
                        DEBUG ({
                               g_print ("The file is externally modified\n");
@@ -999,21 +1004,21 @@ check_externally_modified (GTask *task)
 
        saver = g_task_get_source_object (task);
 
-       if (saver->file != NULL)
+       if (saver->priv->file != NULL)
        {
                GFile *prev_location;
 
-               prev_location = gtk_source_file_get_location (saver->file);
+               prev_location = gtk_source_file_get_location (saver->priv->file);
 
                /* Don't check for externally modified for a "save as" operation,
                 * because the user has normally accepted to overwrite the file if it
                 * already exists.
                 */
                save_as = (prev_location == NULL ||
-                          !g_file_equal (prev_location, saver->location));
+                          !g_file_equal (prev_location, saver->priv->location));
        }
 
-       if (saver->flags & GTK_SOURCE_FILE_SAVER_FLAGS_IGNORE_MODIFICATION_TIME ||
+       if (saver->priv->flags & GTK_SOURCE_FILE_SAVER_FLAGS_IGNORE_MODIFICATION_TIME ||
            save_as)
        {
                begin_write (task);
@@ -1024,7 +1029,7 @@ check_externally_modified (GTask *task)
               g_print ("Check externally modified\n");
        });
 
-       g_file_query_info_async (saver->location,
+       g_file_query_info_async (saver->priv->location,
                                 G_FILE_ATTRIBUTE_TIME_MODIFIED,
                                 G_FILE_QUERY_INFO_NONE,
                                 g_task_get_priority (task),
@@ -1035,8 +1040,8 @@ check_externally_modified (GTask *task)
 
 static void
 mount_cb (GObject      *source_object,
-          GAsyncResult *result,
-          gpointer      user_data)
+         GAsyncResult *result,
+         gpointer      user_data)
 {
        GFile *location = G_FILE (source_object);
        GTask *task = G_TASK (user_data);
@@ -1067,7 +1072,7 @@ recover_not_mounted (GTask *task)
        saver = g_task_get_source_object (task);
        task_data = g_task_get_task_data (task);
 
-       mount_operation = _gtk_source_file_create_mount_operation (saver->file);
+       mount_operation = _gtk_source_file_create_mount_operation (saver->priv->file);
 
        DEBUG ({
               g_print ("%s\n", G_STRFUNC);
@@ -1075,7 +1080,7 @@ recover_not_mounted (GTask *task)
 
        task_data->tried_mount = TRUE;
 
-       g_file_mount_enclosing_volume (saver->location,
+       g_file_mount_enclosing_volume (saver->priv->location,
                                       G_MOUNT_MOUNT_NONE,
                                       mount_operation,
                                       g_task_get_cancellable (task),
@@ -1114,7 +1119,7 @@ gtk_source_file_saver_error_quark (void)
  */
 GtkSourceFileSaver *
 gtk_source_file_saver_new (GtkSourceBuffer *buffer,
-                           GtkSourceFile   *file)
+                          GtkSourceFile   *file)
 {
        g_return_val_if_fail (GTK_SOURCE_IS_BUFFER (buffer), NULL);
        g_return_val_if_fail (GTK_SOURCE_IS_FILE (file), NULL);
@@ -1144,8 +1149,8 @@ gtk_source_file_saver_new (GtkSourceBuffer *buffer,
  */
 GtkSourceFileSaver *
 gtk_source_file_saver_new_with_target (GtkSourceBuffer *buffer,
-                                       GtkSourceFile   *file,
-                                       GFile           *target_location)
+                                      GtkSourceFile   *file,
+                                      GFile           *target_location)
 {
        g_return_val_if_fail (GTK_SOURCE_IS_BUFFER (buffer), NULL);
        g_return_val_if_fail (GTK_SOURCE_IS_FILE (file), NULL);
@@ -1170,7 +1175,7 @@ gtk_source_file_saver_get_buffer (GtkSourceFileSaver *saver)
 {
        g_return_val_if_fail (GTK_SOURCE_IS_FILE_SAVER (saver), NULL);
 
-       return saver->source_buffer;
+       return saver->priv->source_buffer;
 }
 
 /**
@@ -1185,7 +1190,7 @@ gtk_source_file_saver_get_file (GtkSourceFileSaver *saver)
 {
        g_return_val_if_fail (GTK_SOURCE_IS_FILE_SAVER (saver), NULL);
 
-       return saver->file;
+       return saver->priv->file;
 }
 
 /**
@@ -1200,7 +1205,7 @@ gtk_source_file_saver_get_location (GtkSourceFileSaver *saver)
 {
        g_return_val_if_fail (GTK_SOURCE_IS_FILE_SAVER (saver), NULL);
 
-       return saver->location;
+       return saver->priv->location;
 }
 
 /**
@@ -1215,19 +1220,19 @@ gtk_source_file_saver_get_location (GtkSourceFileSaver *saver)
  */
 void
 gtk_source_file_saver_set_encoding (GtkSourceFileSaver      *saver,
-                                    const GtkSourceEncoding *encoding)
+                                   const GtkSourceEncoding *encoding)
 {
        g_return_if_fail (GTK_SOURCE_IS_FILE_SAVER (saver));
-       g_return_if_fail (saver->task == NULL);
+       g_return_if_fail (saver->priv->task == NULL);
 
        if (encoding == NULL)
        {
                encoding = gtk_source_encoding_get_utf8 ();
        }
 
-       if (saver->encoding != encoding)
+       if (saver->priv->encoding != encoding)
        {
-               saver->encoding = encoding;
+               saver->priv->encoding = encoding;
                g_object_notify (G_OBJECT (saver), "encoding");
        }
 }
@@ -1244,7 +1249,7 @@ gtk_source_file_saver_get_encoding (GtkSourceFileSaver *saver)
 {
        g_return_val_if_fail (GTK_SOURCE_IS_FILE_SAVER (saver), NULL);
 
-       return saver->encoding;
+       return saver->priv->encoding;
 }
 
 /**
@@ -1259,14 +1264,14 @@ gtk_source_file_saver_get_encoding (GtkSourceFileSaver *saver)
  */
 void
 gtk_source_file_saver_set_newline_type (GtkSourceFileSaver   *saver,
-                                        GtkSourceNewlineType  newline_type)
+                                       GtkSourceNewlineType  newline_type)
 {
        g_return_if_fail (GTK_SOURCE_IS_FILE_SAVER (saver));
-       g_return_if_fail (saver->task == NULL);
+       g_return_if_fail (saver->priv->task == NULL);
 
-       if (saver->newline_type != newline_type)
+       if (saver->priv->newline_type != newline_type)
        {
-               saver->newline_type = newline_type;
+               saver->priv->newline_type = newline_type;
                g_object_notify (G_OBJECT (saver), "newline-type");
        }
 }
@@ -1283,7 +1288,7 @@ gtk_source_file_saver_get_newline_type (GtkSourceFileSaver *saver)
 {
        g_return_val_if_fail (GTK_SOURCE_IS_FILE_SAVER (saver), GTK_SOURCE_NEWLINE_TYPE_DEFAULT);
 
-       return saver->newline_type;
+       return saver->priv->newline_type;
 }
 
 /**
@@ -1298,14 +1303,14 @@ gtk_source_file_saver_get_newline_type (GtkSourceFileSaver *saver)
  */
 void
 gtk_source_file_saver_set_compression_type (GtkSourceFileSaver       *saver,
-                                            GtkSourceCompressionType  compression_type)
+                                           GtkSourceCompressionType  compression_type)
 {
        g_return_if_fail (GTK_SOURCE_IS_FILE_SAVER (saver));
-       g_return_if_fail (saver->task == NULL);
+       g_return_if_fail (saver->priv->task == NULL);
 
-       if (saver->compression_type != compression_type)
+       if (saver->priv->compression_type != compression_type)
        {
-               saver->compression_type = compression_type;
+               saver->priv->compression_type = compression_type;
                g_object_notify (G_OBJECT (saver), "compression-type");
        }
 }
@@ -1322,7 +1327,7 @@ gtk_source_file_saver_get_compression_type (GtkSourceFileSaver *saver)
 {
        g_return_val_if_fail (GTK_SOURCE_IS_FILE_SAVER (saver), GTK_SOURCE_COMPRESSION_TYPE_NONE);
 
-       return saver->compression_type;
+       return saver->priv->compression_type;
 }
 
 /**
@@ -1334,14 +1339,14 @@ gtk_source_file_saver_get_compression_type (GtkSourceFileSaver *saver)
  */
 void
 gtk_source_file_saver_set_flags (GtkSourceFileSaver      *saver,
-                                 GtkSourceFileSaverFlags  flags)
+                                GtkSourceFileSaverFlags  flags)
 {
        g_return_if_fail (GTK_SOURCE_IS_FILE_SAVER (saver));
-       g_return_if_fail (saver->task == NULL);
+       g_return_if_fail (saver->priv->task == NULL);
 
-       if (saver->flags != flags)
+       if (saver->priv->flags != flags)
        {
-               saver->flags = flags;
+               saver->priv->flags = flags;
                g_object_notify (G_OBJECT (saver), "flags");
        }
 }
@@ -1358,7 +1363,7 @@ gtk_source_file_saver_get_flags (GtkSourceFileSaver *saver)
 {
        g_return_val_if_fail (GTK_SOURCE_IS_FILE_SAVER (saver), GTK_SOURCE_FILE_SAVER_FLAGS_NONE);
 
-       return saver->flags;
+       return saver->priv->flags;
 }
 
 /**
@@ -1387,14 +1392,14 @@ gtk_source_file_saver_get_flags (GtkSourceFileSaver *saver)
  * https://bugzilla.gnome.org/show_bug.cgi?id=616044
  */
 void
-gtk_source_file_saver_save_async (GtkSourceFileSaver    *saver,
-                                  gint                   io_priority,
-                                  GCancellable          *cancellable,
-                                  GFileProgressCallback  progress_callback,
-                                  gpointer               progress_callback_data,
-                                  GDestroyNotify         progress_callback_notify,
-                                  GAsyncReadyCallback    callback,
-                                  gpointer               user_data)
+gtk_source_file_saver_save_async (GtkSourceFileSaver     *saver,
+                                 gint                    io_priority,
+                                 GCancellable           *cancellable,
+                                 GFileProgressCallback   progress_callback,
+                                 gpointer                progress_callback_data,
+                                 GDestroyNotify          progress_callback_notify,
+                                 GAsyncReadyCallback     callback,
+                                 gpointer                user_data)
 {
        TaskData *task_data;
        gboolean check_invalid_chars;
@@ -1402,31 +1407,31 @@ gtk_source_file_saver_save_async (GtkSourceFileSaver    *saver,
 
        g_return_if_fail (GTK_SOURCE_IS_FILE_SAVER (saver));
        g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
-       g_return_if_fail (saver->task == NULL);
+       g_return_if_fail (saver->priv->task == NULL);
 
-       saver->task = g_task_new (saver, cancellable, callback, user_data);
-       g_task_set_priority (saver->task, io_priority);
+       saver->priv->task = g_task_new (saver, cancellable, callback, user_data);
+       g_task_set_priority (saver->priv->task, io_priority);
 
        task_data = task_data_new ();
-       g_task_set_task_data (saver->task, task_data, task_data_free);
+       g_task_set_task_data (saver->priv->task, task_data, task_data_free);
 
        task_data->progress_cb = progress_callback;
        task_data->progress_cb_data = progress_callback_data;
        task_data->progress_cb_notify = progress_callback_notify;
 
-       if (saver->source_buffer == NULL ||
-           saver->file == NULL ||
-           saver->location == NULL)
+       if (saver->priv->source_buffer == NULL ||
+           saver->priv->file == NULL ||
+           saver->priv->location == NULL)
        {
-               g_task_return_boolean (saver->task, FALSE);
+               g_task_return_boolean (saver->priv->task, FALSE);
                return;
        }
 
-       check_invalid_chars = (saver->flags & GTK_SOURCE_FILE_SAVER_FLAGS_IGNORE_INVALID_CHARS) == 0;
+       check_invalid_chars = (saver->priv->flags & GTK_SOURCE_FILE_SAVER_FLAGS_IGNORE_INVALID_CHARS) == 0;
 
-       if (check_invalid_chars && _gtk_source_buffer_has_invalid_chars (saver->source_buffer))
+       if (check_invalid_chars && _gtk_source_buffer_has_invalid_chars (saver->priv->source_buffer))
        {
-               g_task_return_new_error (saver->task,
+               g_task_return_new_error (saver->priv->task,
                                         GTK_SOURCE_FILE_SAVER_ERROR,
                                         GTK_SOURCE_FILE_SAVER_ERROR_INVALID_CHARS,
                                         _("The buffer contains invalid characters."));
@@ -1437,17 +1442,17 @@ gtk_source_file_saver_save_async (GtkSourceFileSaver    *saver,
               g_print ("Start saving\n");
        });
 
-       implicit_trailing_newline = gtk_source_buffer_get_implicit_trailing_newline (saver->source_buffer);
+       implicit_trailing_newline = gtk_source_buffer_get_implicit_trailing_newline 
(saver->priv->source_buffer);
 
        /* The BufferInputStream has a strong reference to the buffer.
         * We create the BufferInputStream here so we are sure that the
         * buffer will not be destroyed during the file saving.
         */
-       task_data->input_stream = _gtk_source_buffer_input_stream_new (GTK_TEXT_BUFFER (saver->source_buffer),
-                                                                      saver->newline_type,
+       task_data->input_stream = _gtk_source_buffer_input_stream_new (GTK_TEXT_BUFFER 
(saver->priv->source_buffer),
+                                                                      saver->priv->newline_type,
                                                                       implicit_trailing_newline);
 
-       check_externally_modified (saver->task);
+       check_externally_modified (saver->priv->task);
 }
 
 /**
@@ -1470,8 +1475,8 @@ gtk_source_file_saver_save_async (GtkSourceFileSaver    *saver,
  */
 gboolean
 gtk_source_file_saver_save_finish (GtkSourceFileSaver  *saver,
-                                   GAsyncResult        *result,
-                                   GError             **error)
+                                  GAsyncResult        *result,
+                                  GError             **error)
 {
        gboolean ok;
 
@@ -1481,44 +1486,48 @@ gtk_source_file_saver_save_finish (GtkSourceFileSaver  *saver,
 
        ok = g_task_propagate_boolean (G_TASK (result), error);
 
-       if (ok && saver->file != NULL)
+       if (ok && saver->priv->file != NULL)
        {
                TaskData *task_data;
 
-               gtk_source_file_set_location (saver->file,
-                                             saver->location);
+               gtk_source_file_set_location (saver->priv->file,
+                                             saver->priv->location);
 
-               _gtk_source_file_set_encoding (saver->file,
-                                              saver->encoding);
+               _gtk_source_file_set_encoding (saver->priv->file,
+                                              saver->priv->encoding);
 
-               _gtk_source_file_set_newline_type (saver->file,
-                                                  saver->newline_type);
+               _gtk_source_file_set_newline_type (saver->priv->file,
+                                                  saver->priv->newline_type);
 
-               _gtk_source_file_set_compression_type (saver->file,
-                                                      saver->compression_type);
+               _gtk_source_file_set_compression_type (saver->priv->file,
+                                                      saver->priv->compression_type);
 
-               _gtk_source_file_set_externally_modified (saver->file, FALSE);
-               _gtk_source_file_set_deleted (saver->file, FALSE);
-               _gtk_source_file_set_readonly (saver->file, FALSE);
+               _gtk_source_file_set_externally_modified (saver->priv->file, FALSE);
+               _gtk_source_file_set_deleted (saver->priv->file, FALSE);
+               _gtk_source_file_set_readonly (saver->priv->file, FALSE);
 
                task_data = g_task_get_task_data (G_TASK (result));
 
                if (g_file_info_has_attribute (task_data->info, G_FILE_ATTRIBUTE_TIME_MODIFIED))
                {
-                       GTimeVal modification_time;
+                       GDateTime *dt;
+                       gint64 mtime;
+
+                       dt = g_file_info_get_modification_date_time (task_data->info);
+                       mtime = g_date_time_to_unix (dt);
+                       g_date_time_unref (dt);
 
-                       g_file_info_get_modification_time (task_data->info, &modification_time);
-                       _gtk_source_file_set_modification_time (saver->file, modification_time);
+                       _gtk_source_file_set_modification_time (saver->priv->file, mtime);
                }
        }
 
-       if (ok && saver->source_buffer != NULL)
+       if (ok && saver->priv->source_buffer != NULL)
        {
-               gtk_text_buffer_set_modified (GTK_TEXT_BUFFER (saver->source_buffer),
+               gtk_text_buffer_set_modified (GTK_TEXT_BUFFER (saver->priv->source_buffer),
                                              FALSE);
        }
 
-       g_clear_object (&saver->task);
+       g_clear_object (&saver->priv->task);
 
        return ok;
 }
diff --git a/gtksourceview/gtksourcefilesaver.h b/gtksourceview/gtksourcefilesaver.h
index 06714342..6a7f9aac 100644
--- a/gtksourceview/gtksourcefilesaver.h
+++ b/gtksourceview/gtksourcefilesaver.h
@@ -2,10 +2,10 @@
 /*
  * This file is part of GtkSourceView
  *
- * Copyright 2005, 2007 Paolo Maggi
- * Copyright 2007 Steve Frécinaux
- * Copyright 2008 Jesse van den Kieboom
- * Copyright 2014 Sébastien Wilmet
+ * Copyright (C) 2005, 2007 - Paolo Maggi
+ * Copyrhing (C) 2007 - Steve Frécinaux
+ * Copyright (C) 2008 - Jesse van den Kieboom
+ * Copyright (C) 2014 - Sébastien Wilmet
  *
  * GtkSourceView is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -21,7 +21,8 @@
  * along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#pragma once
+#ifndef GTK_SOURCE_FILE_SAVER_H
+#define GTK_SOURCE_FILE_SAVER_H
 
 #if !defined (GTK_SOURCE_H_INSIDE) && !defined (GTK_SOURCE_COMPILATION)
 #error "Only <gtksourceview/gtksource.h> can be included directly."
@@ -34,8 +35,17 @@
 
 G_BEGIN_DECLS
 
-#define GTK_SOURCE_TYPE_FILE_SAVER  (gtk_source_file_saver_get_type())
-#define GTK_SOURCE_FILE_SAVER_ERROR (gtk_source_file_saver_error_quark())
+#define GTK_SOURCE_TYPE_FILE_SAVER              (gtk_source_file_saver_get_type())
+#define GTK_SOURCE_FILE_SAVER(obj)              (G_TYPE_CHECK_INSTANCE_CAST((obj), 
GTK_SOURCE_TYPE_FILE_SAVER, GtkSourceFileSaver))
+#define GTK_SOURCE_FILE_SAVER_CLASS(klass)      (G_TYPE_CHECK_CLASS_CAST((klass), 
GTK_SOURCE_TYPE_FILE_SAVER, GtkSourceFileSaverClass))
+#define GTK_SOURCE_IS_FILE_SAVER(obj)           (G_TYPE_CHECK_INSTANCE_TYPE((obj), 
GTK_SOURCE_TYPE_FILE_SAVER))
+#define GTK_SOURCE_IS_FILE_SAVER_CLASS(klass)   (G_TYPE_CHECK_CLASS_TYPE ((klass), 
GTK_SOURCE_TYPE_FILE_SAVER))
+#define GTK_SOURCE_FILE_SAVER_GET_CLASS(obj)    (G_TYPE_INSTANCE_GET_CLASS((obj), 
GTK_SOURCE_TYPE_FILE_SAVER, GtkSourceFileSaverClass))
+
+typedef struct _GtkSourceFileSaverClass   GtkSourceFileSaverClass;
+typedef struct _GtkSourceFileSaverPrivate GtkSourceFileSaverPrivate;
+
+#define GTK_SOURCE_FILE_SAVER_ERROR gtk_source_file_saver_error_quark ()
 
 /**
  * GtkSourceFileSaverError:
@@ -65,62 +75,95 @@ typedef enum _GtkSourceFileSaverError
  */
 typedef enum _GtkSourceFileSaverFlags
 {
-       GTK_SOURCE_FILE_SAVER_FLAGS_NONE                     = 0,
-       GTK_SOURCE_FILE_SAVER_FLAGS_IGNORE_INVALID_CHARS     = 1 << 0,
-       GTK_SOURCE_FILE_SAVER_FLAGS_IGNORE_MODIFICATION_TIME = 1 << 1,
-       GTK_SOURCE_FILE_SAVER_FLAGS_CREATE_BACKUP            = 1 << 2
+       GTK_SOURCE_FILE_SAVER_FLAGS_NONE                        = 0,
+       GTK_SOURCE_FILE_SAVER_FLAGS_IGNORE_INVALID_CHARS        = 1 << 0,
+       GTK_SOURCE_FILE_SAVER_FLAGS_IGNORE_MODIFICATION_TIME    = 1 << 1,
+       GTK_SOURCE_FILE_SAVER_FLAGS_CREATE_BACKUP               = 1 << 2
 } GtkSourceFileSaverFlags;
 
+struct _GtkSourceFileSaver
+{
+       GObject object;
+
+       GtkSourceFileSaverPrivate *priv;
+};
+
+struct _GtkSourceFileSaverClass
+{
+       GObjectClass parent_class;
+
+       gpointer padding[10];
+};
+
 GTK_SOURCE_AVAILABLE_IN_3_14
-G_DECLARE_FINAL_TYPE (GtkSourceFileSaver, gtk_source_file_saver, GTK_SOURCE, FILE_SAVER, GObject)
+GType                   gtk_source_file_saver_get_type         (void) G_GNUC_CONST;
 
 GTK_SOURCE_AVAILABLE_IN_3_14
-GQuark                    gtk_source_file_saver_error_quark          (void);
+GQuark                  gtk_source_file_saver_error_quark      (void);
+
 GTK_SOURCE_AVAILABLE_IN_3_14
-GtkSourceFileSaver       *gtk_source_file_saver_new                  (GtkSourceBuffer           *buffer,
-                                                                      GtkSourceFile             *file);
+GtkSourceFileSaver     *gtk_source_file_saver_new              (GtkSourceBuffer          *buffer,
+                                                                GtkSourceFile            *file);
+
 GTK_SOURCE_AVAILABLE_IN_3_14
-GtkSourceFileSaver       *gtk_source_file_saver_new_with_target      (GtkSourceBuffer           *buffer,
-                                                                      GtkSourceFile             *file,
-                                                                      GFile                     
*target_location);
+GtkSourceFileSaver     *gtk_source_file_saver_new_with_target  (GtkSourceBuffer          *buffer,
+                                                                GtkSourceFile            *file,
+                                                                GFile                    *target_location);
+
 GTK_SOURCE_AVAILABLE_IN_3_14
-GtkSourceBuffer          *gtk_source_file_saver_get_buffer           (GtkSourceFileSaver        *saver);
+GtkSourceBuffer                *gtk_source_file_saver_get_buffer       (GtkSourceFileSaver       *saver);
+
 GTK_SOURCE_AVAILABLE_IN_3_14
-GtkSourceFile            *gtk_source_file_saver_get_file             (GtkSourceFileSaver        *saver);
+GtkSourceFile          *gtk_source_file_saver_get_file         (GtkSourceFileSaver       *saver);
+
 GTK_SOURCE_AVAILABLE_IN_3_14
-GFile                    *gtk_source_file_saver_get_location         (GtkSourceFileSaver        *saver);
+GFile                  *gtk_source_file_saver_get_location     (GtkSourceFileSaver       *saver);
+
 GTK_SOURCE_AVAILABLE_IN_3_14
-void                      gtk_source_file_saver_set_encoding         (GtkSourceFileSaver        *saver,
-                                                                      const GtkSourceEncoding   *encoding);
+void                    gtk_source_file_saver_set_encoding     (GtkSourceFileSaver       *saver,
+                                                                const GtkSourceEncoding  *encoding);
+
 GTK_SOURCE_AVAILABLE_IN_3_14
-const GtkSourceEncoding  *gtk_source_file_saver_get_encoding         (GtkSourceFileSaver        *saver);
+const GtkSourceEncoding *gtk_source_file_saver_get_encoding    (GtkSourceFileSaver       *saver);
+
 GTK_SOURCE_AVAILABLE_IN_3_14
-void                      gtk_source_file_saver_set_newline_type     (GtkSourceFileSaver        *saver,
-                                                                      GtkSourceNewlineType       
newline_type);
+void                    gtk_source_file_saver_set_newline_type (GtkSourceFileSaver       *saver,
+                                                                GtkSourceNewlineType      newline_type);
+
 GTK_SOURCE_AVAILABLE_IN_3_14
-GtkSourceNewlineType      gtk_source_file_saver_get_newline_type     (GtkSourceFileSaver        *saver);
+GtkSourceNewlineType    gtk_source_file_saver_get_newline_type (GtkSourceFileSaver       *saver);
+
 GTK_SOURCE_AVAILABLE_IN_3_14
-void                      gtk_source_file_saver_set_compression_type (GtkSourceFileSaver        *saver,
-                                                                      GtkSourceCompressionType   
compression_type);
+void                    gtk_source_file_saver_set_compression_type
+                                                               (GtkSourceFileSaver       *saver,
+                                                                GtkSourceCompressionType  compression_type);
+
 GTK_SOURCE_AVAILABLE_IN_3_14
-GtkSourceCompressionType  gtk_source_file_saver_get_compression_type (GtkSourceFileSaver        *saver);
+GtkSourceCompressionType gtk_source_file_saver_get_compression_type
+                                                               (GtkSourceFileSaver       *saver);
+
 GTK_SOURCE_AVAILABLE_IN_3_14
-void                      gtk_source_file_saver_set_flags            (GtkSourceFileSaver        *saver,
-                                                                      GtkSourceFileSaverFlags    flags);
+void                    gtk_source_file_saver_set_flags        (GtkSourceFileSaver       *saver,
+                                                                GtkSourceFileSaverFlags   flags);
+
 GTK_SOURCE_AVAILABLE_IN_3_14
-GtkSourceFileSaverFlags   gtk_source_file_saver_get_flags            (GtkSourceFileSaver        *saver);
+GtkSourceFileSaverFlags         gtk_source_file_saver_get_flags        (GtkSourceFileSaver       *saver);
+
 GTK_SOURCE_AVAILABLE_IN_3_14
-void                      gtk_source_file_saver_save_async           (GtkSourceFileSaver        *saver,
-                                                                      gint                       io_priority,
-                                                                      GCancellable              *cancellable,
-                                                                      GFileProgressCallback      
progress_callback,
-                                                                      gpointer                   
progress_callback_data,
-                                                                      GDestroyNotify             
progress_callback_notify,
-                                                                      GAsyncReadyCallback        callback,
-                                                                      gpointer                   user_data);
+void                    gtk_source_file_saver_save_async       (GtkSourceFileSaver       *saver,
+                                                                gint                      io_priority,
+                                                                GCancellable             *cancellable,
+                                                                GFileProgressCallback     progress_callback,
+                                                                gpointer                  
progress_callback_data,
+                                                                GDestroyNotify            
progress_callback_notify,
+                                                                GAsyncReadyCallback       callback,
+                                                                gpointer                  user_data);
+
 GTK_SOURCE_AVAILABLE_IN_3_14
-gboolean                  gtk_source_file_saver_save_finish          (GtkSourceFileSaver        *saver,
-                                                                      GAsyncResult              *result,
-                                                                      GError                   **error);
+gboolean                gtk_source_file_saver_save_finish      (GtkSourceFileSaver       *saver,
+                                                                GAsyncResult             *result,
+                                                                GError                  **error);
 
 G_END_DECLS
+
+#endif  /* GTK_SOURCE_FILE_SAVER_H  */
diff --git a/gtksourceview/gtksourcegutter-private.h b/gtksourceview/gtksourcegutter-private.h
index e1ebeb8a..33d62e08 100644
--- a/gtksourceview/gtksourcegutter-private.h
+++ b/gtksourceview/gtksourcegutter-private.h
@@ -2,7 +2,7 @@
  *
  * This file is part of GtkSourceView
  *
- * Copyright 2009 - Jesse van den Kieboom
+ * Copyright (C) 2009 - Jesse van den Kieboom
  *
  * GtkSourceView is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -18,19 +18,20 @@
  * along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#pragma once
+#ifndef GTK_SOURCE_GUTTER_PRIVATE_H
+#define GTK_SOURCE_GUTTER_PRIVATE_H
 
 #include <gtk/gtk.h>
+
 #include "gtksourcetypes.h"
 
 G_BEGIN_DECLS
 
 G_GNUC_INTERNAL
-GtkSourceGutter *_gtk_source_gutter_new  (GtkSourceView     *view,
-                                          GtkTextWindowType  type);
+GtkSourceGutter *_gtk_source_gutter_new       (GtkTextWindowType  type);
 G_GNUC_INTERNAL
-void             _gtk_source_gutter_draw (GtkSourceGutter   *gutter,
-                                          GtkSourceView     *view,
-                                          cairo_t           *cr);
+GtkSourceLines  *_gtk_source_gutter_get_lines (GtkSourceGutter   *gutter);
 
 G_END_DECLS
+
+#endif /* GTK_SOURCE_GUTTER_PRIVATE_H */
diff --git a/gtksourceview/gtksourcegutter.c b/gtksourceview/gtksourcegutter.c
index 9a988e53..fc8e24bb 100644
--- a/gtksourceview/gtksourcegutter.c
+++ b/gtksourceview/gtksourcegutter.c
@@ -2,7 +2,7 @@
  *
  * This file is part of GtkSourceView
  *
- * Copyright 2009 - Jesse van den Kieboom
+ * Copyright (C) 2009 - Jesse van den Kieboom
  *
  * GtkSourceView is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -18,10 +18,14 @@
  * along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "config.h"
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
 
 #include "gtksourcegutter.h"
 #include "gtksourcegutter-private.h"
+#include "gtksourcelines.h"
+#include "gtksourcelines-private.h"
 #include "gtksourceview.h"
 #include "gtksourcegutterrenderer.h"
 #include "gtksourcegutterrenderer-private.h"
@@ -62,89 +66,58 @@ typedef struct
 
        gint prelit;
        gint position;
-
-       gulong queue_draw_handler;
-       gulong size_changed_handler;
-       gulong notify_xpad_handler;
-       gulong notify_ypad_handler;
-       gulong notify_visible_handler;
 } Renderer;
 
-struct _GtkSourceGutter
+struct _GtkSourceGutterPrivate
 {
-       GObject parent_instance;
+       GtkSourceView     *view;
+       GList             *renderers;
+       GtkSourceLines    *lines;
 
-       GtkSourceView *view;
-       GtkTextWindowType window_type;
-       GtkOrientation orientation;
+       GtkTextWindowType  window_type;
+       GtkOrientation     orientation;
 
-       GList *renderers;
+       gulong             adj_changed_handler;
+       gulong             realize_handler;
+       gulong             style_updated_handler;
 
-       guint is_drawing : 1;
+       guint              is_drawing : 1;
 };
 
-G_DEFINE_TYPE (GtkSourceGutter, gtk_source_gutter, G_TYPE_OBJECT)
-
-static gboolean on_view_motion_notify_event (GtkSourceView    *view,
-                                             GdkEventMotion   *event,
-                                             GtkSourceGutter  *gutter);
-static gboolean on_view_enter_notify_event  (GtkSourceView    *view,
-                                             GdkEventCrossing *event,
-                                             GtkSourceGutter  *gutter);
-static gboolean on_view_leave_notify_event  (GtkSourceView    *view,
-                                             GdkEventCrossing *event,
-                                             GtkSourceGutter  *gutter);
-static gboolean on_view_button_press_event  (GtkSourceView    *view,
-                                             GdkEventButton   *event,
-                                             GtkSourceGutter  *gutter);
-static gboolean on_view_query_tooltip       (GtkSourceView    *view,
-                                             gint              x,
-                                             gint              y,
-                                             gboolean          keyboard_mode,
-                                             GtkTooltip       *tooltip,
-                                             GtkSourceGutter  *gutter);
-static void     on_view_style_updated       (GtkSourceView    *view,
-                                             GtkSourceGutter  *gutter);
-static void     do_redraw                   (GtkSourceGutter  *gutter);
-static void     update_gutter_size          (GtkSourceGutter  *gutter);
-
-static GdkWindow *
-get_window (GtkSourceGutter *gutter)
-{
-       return gtk_text_view_get_window (GTK_TEXT_VIEW (gutter->view),
-                                        gutter->window_type);
-}
-
-static void
-on_renderer_size_changed (GtkSourceGutterRenderer *renderer,
-                          GParamSpec              *spec,
-                          GtkSourceGutter         *gutter)
-{
-       update_gutter_size (gutter);
-}
-
-static void
-on_renderer_queue_draw (GtkSourceGutterRenderer *renderer,
-                        GtkSourceGutter         *gutter)
-{
-       do_redraw (gutter);
-}
-
-static void
-on_renderer_notify_padding (GtkSourceGutterRenderer *renderer,
-                            GParamSpec              *spec,
-                            GtkSourceGutter         *gutter)
-{
-       update_gutter_size (gutter);
-}
-
-static void
-on_renderer_notify_visible (GtkSourceGutterRenderer *renderer,
-                            GParamSpec              *spec,
-                            GtkSourceGutter         *gutter)
-{
-       update_gutter_size (gutter);
-}
+G_DEFINE_TYPE_WITH_PRIVATE (GtkSourceGutter, gtk_source_gutter, GTK_TYPE_CONTAINER)
+
+static void gtk_source_gutter_add           (GtkContainer             *container,
+                                             GtkWidget                *widget);
+static void gtk_source_gutter_remove        (GtkContainer             *container,
+                                             GtkWidget                *widget);
+static void on_view_style_updated           (GtkSourceView            *view,
+                                             GtkSourceGutter          *gutter);
+static void on_gutter_motion_enter          (GtkSourceGutter          *gutter,
+                                             gdouble                   x,
+                                             gdouble                   y,
+                                             GdkCrossingMode           mode,
+                                             GdkNotifyType             notify_type,
+                                             GtkEventControllerMotion *motion);
+static void on_gutter_motion                (GtkSourceGutter          *gutter,
+                                             gdouble                   x,
+                                             gdouble                   y,
+                                             GtkEventControllerMotion *motion);
+static void on_gutter_motion_leave          (GtkSourceGutter          *gutter,
+                                             GdkCrossingMode           mode,
+                                             GdkNotifyType             notify_type,
+                                             GtkEventControllerMotion *motion);
+static void on_gutter_pressed_cb            (GtkSourceGutter          *gutter,
+                                             gint                      n_presses,
+                                             gdouble                   x,
+                                             gdouble                   y,
+                                             GtkGestureClick          *click);
+static void do_redraw                       (GtkSourceGutter          *gutter);
+static void gtk_source_gutter_snapshot      (GtkWidget                *widget,
+                                             GtkSnapshot              *snapshot);
+static void gtk_source_gutter_size_allocate (GtkWidget                *widget,
+                                             gint                      width,
+                                             gint                      height,
+                                             gint                      baseline);
 
 static Renderer *
 renderer_new (GtkSourceGutter         *gutter,
@@ -158,38 +131,7 @@ renderer_new (GtkSourceGutter         *gutter,
        ret->prelit = -1;
 
        _gtk_source_gutter_renderer_set_view (renderer,
-                                             GTK_TEXT_VIEW (gutter->view),
-                                             gutter->window_type);
-
-       ret->size_changed_handler =
-               g_signal_connect (ret->renderer,
-                                 "notify::size",
-                                 G_CALLBACK (on_renderer_size_changed),
-                                 gutter);
-
-       ret->queue_draw_handler =
-               g_signal_connect (ret->renderer,
-                                 "queue-draw",
-                                 G_CALLBACK (on_renderer_queue_draw),
-                                 gutter);
-
-       ret->notify_xpad_handler =
-               g_signal_connect (ret->renderer,
-                                 "notify::xpad",
-                                 G_CALLBACK (on_renderer_notify_padding),
-                                 gutter);
-
-       ret->notify_ypad_handler =
-               g_signal_connect (ret->renderer,
-                                 "notify::ypad",
-                                 G_CALLBACK (on_renderer_notify_padding),
-                                 gutter);
-
-       ret->notify_visible_handler =
-               g_signal_connect (ret->renderer,
-                                 "notify::visible",
-                                 G_CALLBACK (on_renderer_notify_visible),
-                                 gutter);
+                                             gutter->priv->view);
 
        return ret;
 }
@@ -197,40 +139,48 @@ renderer_new (GtkSourceGutter         *gutter,
 static void
 renderer_free (Renderer *renderer)
 {
-       g_signal_handler_disconnect (renderer->renderer,
-                                    renderer->queue_draw_handler);
-
-       g_signal_handler_disconnect (renderer->renderer,
-                                    renderer->size_changed_handler);
-
-       g_signal_handler_disconnect (renderer->renderer,
-                                    renderer->notify_xpad_handler);
-
-       g_signal_handler_disconnect (renderer->renderer,
-                                    renderer->notify_ypad_handler);
-
-       g_signal_handler_disconnect (renderer->renderer,
-                                    renderer->notify_visible_handler);
-
-       _gtk_source_gutter_renderer_set_view (renderer->renderer,
-                                             NULL,
-                                             GTK_TEXT_WINDOW_PRIVATE);
+       _gtk_source_gutter_renderer_set_view (renderer->renderer, NULL);
 
        g_object_unref (renderer->renderer);
        g_slice_free (Renderer, renderer);
 }
 
 static void
-gtk_source_gutter_dispose (GObject *object)
+get_alignment_modes (GtkSourceGutter *gutter,
+                     gboolean        *needs_wrap_first,
+                     gboolean        *needs_wrap_last)
 {
-       GtkSourceGutter *gutter = GTK_SOURCE_GUTTER (object);
+       const GList *list;
+
+       g_assert (GTK_SOURCE_GUTTER (gutter));
+       g_assert (needs_wrap_first != NULL);
+       g_assert (needs_wrap_last != NULL);
+
+       *needs_wrap_first = FALSE;
+       *needs_wrap_last = FALSE;
+
+       for (list = gutter->priv->renderers; list; list = list->next)
+       {
+               Renderer *renderer = list->data;
+               GtkSourceGutterRendererAlignmentMode mode;
 
-       g_list_free_full (gutter->renderers, (GDestroyNotify)renderer_free);
-       gutter->renderers = NULL;
+               mode = gtk_source_gutter_renderer_get_alignment_mode (renderer->renderer);
 
-       gutter->view = NULL;
+               switch (mode)
+               {
+                       case GTK_SOURCE_GUTTER_RENDERER_ALIGNMENT_MODE_FIRST:
+                               *needs_wrap_first = TRUE;
+                               break;
+
+                       case GTK_SOURCE_GUTTER_RENDERER_ALIGNMENT_MODE_LAST:
+                               *needs_wrap_last = TRUE;
+                               break;
 
-       G_OBJECT_CLASS (gtk_source_gutter_parent_class)->dispose (object);
+                       case GTK_SOURCE_GUTTER_RENDERER_ALIGNMENT_MODE_CELL:
+                       default:
+                               break;
+               }
+       }
 }
 
 static void
@@ -244,11 +194,13 @@ gtk_source_gutter_get_property (GObject    *object,
        switch (prop_id)
        {
                case PROP_VIEW:
-                       g_value_set_object (value, self->view);
+                       g_value_set_object (value, self->priv->view);
                        break;
+
                case PROP_WINDOW_TYPE:
-                       g_value_set_enum (value, self->window_type);
+                       g_value_set_enum (value, self->priv->window_type);
                        break;
+
                default:
                        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
                        break;
@@ -256,143 +208,233 @@ gtk_source_gutter_get_property (GObject    *object,
 }
 
 static void
-on_view_realize (GtkSourceView   *view,
-                 GtkSourceGutter *gutter)
+on_adjustment_value_changed (GtkAdjustment   *adj,
+                             GtkSourceGutter *gutter)
 {
-       update_gutter_size (gutter);
+       const GList *list;
+
+       for (list = gutter->priv->renderers; list; list = list->next)
+       {
+               Renderer *renderer = list->data;
+
+               gtk_widget_queue_draw (GTK_WIDGET (renderer->renderer));
+       }
+}
+
+static GtkAdjustment *
+get_adjustment (GtkSourceGutter *gutter,
+               GtkSourceView   *view)
+{
+       if (gutter->priv->window_type == GTK_TEXT_WINDOW_LEFT ||
+           gutter->priv->window_type == GTK_TEXT_WINDOW_RIGHT)
+       {
+               return gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (view));
+       }
+       else
+       {
+               return gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (view));
+       }
+}
+
+static void
+connect_view (GtkSourceGutter *gutter,
+              GtkSourceView   *view)
+{
+       g_assert (GTK_SOURCE_IS_GUTTER (gutter));
+       g_assert (GTK_SOURCE_IS_VIEW (view));
+
+       gutter->priv->adj_changed_handler =
+               g_signal_connect (get_adjustment (gutter, view),
+                                 "value-changed",
+                                 G_CALLBACK (on_adjustment_value_changed),
+                                 gutter);
+
+       gutter->priv->style_updated_handler =
+               g_signal_connect (view,
+                                 "style-updated",
+                                 G_CALLBACK (on_view_style_updated),
+                                 gutter);
+}
+
+static void
+disconnect_view (GtkSourceGutter *gutter,
+                 GtkSourceView   *view)
+{
+       g_assert (GTK_SOURCE_IS_GUTTER (gutter));
+       g_assert (GTK_SOURCE_IS_VIEW (view));
+
+       g_clear_signal_handler (&gutter->priv->adj_changed_handler,
+                               get_adjustment (gutter, view));
+       g_clear_signal_handler (&gutter->priv->realize_handler, view);
+       g_clear_signal_handler (&gutter->priv->style_updated_handler, view);
 }
 
 static void
 set_view (GtkSourceGutter *gutter,
           GtkSourceView   *view)
 {
-       gutter->view = view;
-
-       g_signal_connect_object (view,
-                                "motion-notify-event",
-                                G_CALLBACK (on_view_motion_notify_event),
-                                gutter,
-                                0);
-
-       g_signal_connect_object (view,
-                                "enter-notify-event",
-                                G_CALLBACK (on_view_enter_notify_event),
-                                gutter,
-                                0);
-
-       g_signal_connect_object (view,
-                                "leave-notify-event",
-                                G_CALLBACK (on_view_leave_notify_event),
-                                gutter,
-                                0);
-
-       g_signal_connect_object (view,
-                                "button-press-event",
-                                G_CALLBACK (on_view_button_press_event),
-                                gutter,
-                                0);
-
-       g_signal_connect_object (view,
-                                "query-tooltip",
-                                G_CALLBACK (on_view_query_tooltip),
-                                gutter,
-                                0);
-
-       g_signal_connect_object (view,
-                                "realize",
-                                G_CALLBACK (on_view_realize),
-                                gutter,
-                                0);
-
-       g_signal_connect_object (view,
-                                "style-updated",
-                                G_CALLBACK (on_view_style_updated),
-                                gutter,
-                                0);
+       g_return_if_fail (GTK_SOURCE_IS_GUTTER (gutter));
+       g_return_if_fail (!view || GTK_SOURCE_IS_VIEW (view));
+
+       if (view == gutter->priv->view)
+       {
+               return;
+       }
+
+       if (gutter->priv->view != NULL)
+       {
+               disconnect_view (gutter, gutter->priv->view);
+       }
+
+       gutter->priv->view = view;
+
+       if (view != NULL)
+       {
+               connect_view (gutter, view);
+       }
 }
 
 static void
 do_redraw (GtkSourceGutter *gutter)
 {
-       GdkWindow *window;
-
-       window = gtk_text_view_get_window (GTK_TEXT_VIEW (gutter->view),
-                                          gutter->window_type);
-
-       if (window && !gutter->is_drawing)
+       if (!gutter->priv->is_drawing)
        {
-               gdk_window_invalidate_rect (window, NULL, FALSE);
+               gtk_widget_queue_draw (GTK_WIDGET (gutter));
        }
 }
 
-static gint
-calculate_gutter_size (GtkSourceGutter *gutter,
-                       GArray          *sizes)
+static void
+gtk_source_gutter_map (GtkWidget *widget)
 {
-       GList *item;
-       gint total_width = 0;
+       gtk_widget_set_cursor_from_name (widget, "arrow");
+       GTK_WIDGET_CLASS (gtk_source_gutter_parent_class)->map (widget);
+}
+
+static void
+gtk_source_gutter_measure (GtkWidget      *widget,
+                           GtkOrientation  orientation,
+                           int             for_size,
+                           int            *minimum,
+                           int            *natural,
+                           int            *minimum_baseline,
+                           int            *natural_baseline)
+{
+       GtkSourceGutter *gutter = GTK_SOURCE_GUTTER (widget);
+       const GList *item;
 
        /* Calculate size */
-       for (item = gutter->renderers; item; item = g_list_next (item))
+       for (item = gutter->priv->renderers; item; item = item->next)
        {
                Renderer *renderer = item->data;
-               gint width;
+               int r_minimum;
+               int r_natural;
+               int r_minimum_baseline;
+               int r_natural_baseline;
 
-               if (!gtk_source_gutter_renderer_get_visible (renderer->renderer))
+               if (!gtk_widget_get_visible (GTK_WIDGET (renderer->renderer)))
                {
-                       width = 0;
+                       continue;
                }
-               else
-               {
-                       gint xpad;
-                       gint size;
 
-                       size = gtk_source_gutter_renderer_get_size (renderer->renderer);
+               gtk_widget_measure (GTK_WIDGET (renderer->renderer),
+                                   orientation,
+                                   for_size,
+                                   &r_minimum,
+                                   &r_natural,
+                                   &r_minimum_baseline,
+                                   &r_natural_baseline);
 
-                       gtk_source_gutter_renderer_get_padding (renderer->renderer,
-                                                               &xpad,
-                                                               NULL);
+               *minimum += r_minimum;
+               *natural += r_natural;
+       }
 
-                       width = size + 2 * xpad;
-               }
+       *minimum_baseline = -1;
+       *natural_baseline = -1;
+}
 
-               if (sizes)
-               {
-                       g_array_append_val (sizes, width);
-               }
+static void
+apply_style (GtkSourceGutter *gutter,
+            GtkStyleContext *style_context)
+{
+       const gchar *class;
 
-               total_width += width;
+       switch (gutter->priv->window_type)
+       {
+               case GTK_TEXT_WINDOW_TOP:
+                       class = GTK_STYLE_CLASS_TOP;
+                       break;
+
+               case GTK_TEXT_WINDOW_RIGHT:
+                       class = GTK_STYLE_CLASS_RIGHT;
+                       break;
+
+               case GTK_TEXT_WINDOW_BOTTOM:
+                       class = GTK_STYLE_CLASS_BOTTOM;
+                       break;
+
+               case GTK_TEXT_WINDOW_LEFT:
+                       class = GTK_STYLE_CLASS_LEFT;
+                       break;
+
+               case GTK_TEXT_WINDOW_WIDGET:
+               case GTK_TEXT_WINDOW_TEXT:
+               default:
+                       g_return_if_reached ();
        }
 
-       return total_width;
+       gtk_style_context_add_class (style_context, class);
+}
+
+static void
+gtk_source_gutter_root (GtkWidget *widget)
+{
+       GtkWidget *view;
+
+       GTK_WIDGET_CLASS (gtk_source_gutter_parent_class)->root (widget);
+
+       view = gtk_widget_get_ancestor (widget, GTK_SOURCE_TYPE_VIEW);
+       set_view (GTK_SOURCE_GUTTER (widget), GTK_SOURCE_VIEW (view));
+}
+
+static void
+gtk_source_gutter_unroot (GtkWidget *widget)
+{
+       GTK_WIDGET_CLASS (gtk_source_gutter_parent_class)->unroot (widget);
+       set_view (GTK_SOURCE_GUTTER (widget), NULL);
 }
 
 static void
-update_gutter_size (GtkSourceGutter *gutter)
+gtk_source_gutter_forall (GtkContainer *container,
+                          GtkCallback   callback,
+                          gpointer      callback_data)
 {
-       gint width = calculate_gutter_size (gutter, NULL);
+       GtkSourceGutter *gutter = GTK_SOURCE_GUTTER (container);
+       const GList *list = gutter->priv->renderers;
+
+       while (list != NULL)
+       {
+               Renderer *renderer = list->data;
+
+               list = list->next;
 
-       gtk_text_view_set_border_window_size (GTK_TEXT_VIEW (gutter->view),
-                                             gutter->window_type,
-                                             width);
+               callback (GTK_WIDGET (renderer->renderer), callback_data);
+       }
 }
 
 static void
-gtk_source_gutter_set_property (GObject      *object,
-                                guint         prop_id,
-                                const GValue *value,
-                                GParamSpec   *pspec)
+gtk_source_gutter_set_property (GObject       *object,
+                                guint          prop_id,
+                                const GValue  *value,
+                                GParamSpec    *pspec)
 {
        GtkSourceGutter *self = GTK_SOURCE_GUTTER (object);
 
        switch (prop_id)
        {
-               case PROP_VIEW:
-                       set_view (self, GTK_SOURCE_VIEW (g_value_get_object (value)));
-                       break;
                case PROP_WINDOW_TYPE:
-                       self->window_type = g_value_get_enum (value);
+                       self->priv->window_type = g_value_get_enum (value);
                        break;
+
                default:
                        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
                        break;
@@ -402,33 +444,48 @@ gtk_source_gutter_set_property (GObject      *object,
 static void
 gtk_source_gutter_constructed (GObject *object)
 {
-       GtkSourceGutter *gutter;
-
-       gutter = GTK_SOURCE_GUTTER (object);
+       GtkSourceGutter *gutter = GTK_SOURCE_GUTTER (object);
+       GtkStyleContext *context;
 
-       if (gutter->window_type == GTK_TEXT_WINDOW_LEFT ||
-           gutter->window_type == GTK_TEXT_WINDOW_RIGHT)
+       if (gutter->priv->window_type == GTK_TEXT_WINDOW_LEFT ||
+           gutter->priv->window_type == GTK_TEXT_WINDOW_RIGHT)
        {
-               gutter->orientation = GTK_ORIENTATION_HORIZONTAL;
+               gutter->priv->orientation = GTK_ORIENTATION_HORIZONTAL;
+               gtk_widget_set_vexpand (GTK_WIDGET (gutter), TRUE);
        }
        else
        {
-               gutter->orientation = GTK_ORIENTATION_VERTICAL;
+               gutter->priv->orientation = GTK_ORIENTATION_VERTICAL;
+               gtk_widget_set_hexpand (GTK_WIDGET (gutter), TRUE);
        }
 
        G_OBJECT_CLASS (gtk_source_gutter_parent_class)->constructed (object);
+
+       context = gtk_widget_get_style_context (GTK_WIDGET (gutter));
+       apply_style (gutter, context);
 }
 
 static void
 gtk_source_gutter_class_init (GtkSourceGutterClass *klass)
 {
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
+       GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+       GtkContainerClass *container_class = GTK_CONTAINER_CLASS (klass);
 
-       object_class->set_property = gtk_source_gutter_set_property;
+       object_class->constructed = gtk_source_gutter_constructed;
        object_class->get_property = gtk_source_gutter_get_property;
+       object_class->set_property = gtk_source_gutter_set_property;
 
-       object_class->dispose = gtk_source_gutter_dispose;
-       object_class->constructed = gtk_source_gutter_constructed;
+       widget_class->map = gtk_source_gutter_map;
+       widget_class->measure = gtk_source_gutter_measure;
+       widget_class->root = gtk_source_gutter_root;
+       widget_class->size_allocate = gtk_source_gutter_size_allocate;
+       widget_class->snapshot = gtk_source_gutter_snapshot;
+       widget_class->unroot = gtk_source_gutter_unroot;
+
+       container_class->forall = gtk_source_gutter_forall;
+       container_class->add = gtk_source_gutter_add;
+       container_class->remove = gtk_source_gutter_remove;
 
        /**
         * GtkSourceGutter:view:
@@ -441,7 +498,7 @@ gtk_source_gutter_class_init (GtkSourceGutterClass *klass)
                                                              "View",
                                                              "",
                                                              GTK_SOURCE_TYPE_VIEW,
-                                                             G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+                                                             G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
 
        /**
         * GtkSourceGutter:window-type:
@@ -454,14 +511,45 @@ gtk_source_gutter_class_init (GtkSourceGutterClass *klass)
                                                            "Window Type",
                                                            "The gutters' text window type",
                                                            GTK_TYPE_TEXT_WINDOW_TYPE,
-                                                           0,
+                                                           GTK_TEXT_WINDOW_LEFT,
                                                            G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+
+       gtk_widget_class_set_css_name (widget_class, "gutter");
 }
 
 static void
 gtk_source_gutter_init (GtkSourceGutter *self)
 {
-       self = gtk_source_gutter_get_instance_private (self);
+       GtkGesture *click;
+       GtkEventController *motion;
+
+       self->priv = gtk_source_gutter_get_instance_private (self);
+
+        self->priv->window_type = GTK_TEXT_WINDOW_LEFT;
+
+       /* Setup fallback click handling */
+       click = gtk_gesture_click_new ();
+       g_signal_connect_swapped (click,
+                                 "pressed",
+                                 G_CALLBACK (on_gutter_pressed_cb),
+                                self);
+       gtk_widget_add_controller (GTK_WIDGET (self), GTK_EVENT_CONTROLLER (click));
+
+       /* Track motion enter/leave for prelit status */
+       motion = gtk_event_controller_motion_new ();
+       g_signal_connect_swapped (motion,
+                                 "enter",
+                                 G_CALLBACK (on_gutter_motion_enter),
+                                 self);
+       g_signal_connect_swapped (motion,
+                                 "leave",
+                                 G_CALLBACK (on_gutter_motion_leave),
+                                 self);
+       g_signal_connect_swapped (motion,
+                                 "motion",
+                                 G_CALLBACK (on_gutter_motion),
+                                 self);
+       gtk_widget_add_controller (GTK_WIDGET (self), motion);
 }
 
 static gint
@@ -487,32 +575,27 @@ static void
 append_renderer (GtkSourceGutter *gutter,
                  Renderer        *renderer)
 {
-       gutter->renderers =
-               g_list_insert_sorted_with_data (gutter->renderers,
+       gutter->priv->renderers =
+               g_list_insert_sorted_with_data (gutter->priv->renderers,
                                                renderer,
                                                (GCompareDataFunc)sort_by_position,
                                                NULL);
-
-       update_gutter_size (gutter);
 }
 
 GtkSourceGutter *
-_gtk_source_gutter_new (GtkSourceView     *view,
-                        GtkTextWindowType  type)
+_gtk_source_gutter_new (GtkTextWindowType type)
 {
        return g_object_new (GTK_SOURCE_TYPE_GUTTER,
-                            "view", view,
                             "window_type", type,
                             NULL);
 }
 
-/* Public API */
-
 /**
  * gtk_source_gutter_get_view:
  * @gutter: a #GtkSourceGutter.
  *
  * Returns: (transfer none): the associated #GtkSourceView.
+ *
  * Since: 3.24
  */
 GtkSourceView *
@@ -520,22 +603,7 @@ gtk_source_gutter_get_view (GtkSourceGutter *gutter)
 {
        g_return_val_if_fail (GTK_SOURCE_IS_GUTTER (gutter), NULL);
 
-       return gutter->view;
-}
-
-/**
- * gtk_source_gutter_get_window_type:
- * @gutter: a #GtkSourceGutter.
- *
- * Returns: the #GtkTextWindowType of @gutter.
- * Since: 3.24
- */
-GtkTextWindowType
-gtk_source_gutter_get_window_type (GtkSourceGutter *gutter)
-{
-       g_return_val_if_fail (GTK_SOURCE_IS_GUTTER (gutter), GTK_TEXT_WINDOW_PRIVATE);
-
-       return gutter->window_type;
+       return gutter->priv->view;
 }
 
 /**
@@ -563,10 +631,11 @@ gtk_source_gutter_insert (GtkSourceGutter         *gutter,
        g_return_val_if_fail (GTK_SOURCE_IS_GUTTER (gutter), FALSE);
        g_return_val_if_fail (GTK_SOURCE_IS_GUTTER_RENDERER (renderer), FALSE);
        g_return_val_if_fail (gtk_source_gutter_renderer_get_view (renderer) == NULL, FALSE);
-       g_return_val_if_fail (gtk_source_gutter_renderer_get_window_type (renderer) == 
GTK_TEXT_WINDOW_PRIVATE, FALSE);
 
        internal_renderer = renderer_new (gutter, renderer, position);
        append_renderer (gutter, internal_renderer);
+       gtk_widget_set_parent (GTK_WIDGET (renderer), GTK_WIDGET (gutter));
+       gtk_widget_queue_resize (GTK_WIDGET (gutter));
 
        return TRUE;
 }
@@ -579,7 +648,7 @@ renderer_find (GtkSourceGutter          *gutter,
 {
        GList *list;
 
-       for (list = gutter->renderers; list; list = g_list_next (list))
+       for (list = gutter->priv->renderers; list; list = list->next)
        {
                *ret = list->data;
 
@@ -597,6 +666,55 @@ renderer_find (GtkSourceGutter          *gutter,
        return FALSE;
 }
 
+static void
+gtk_source_gutter_add (GtkContainer *container,
+                      GtkWidget    *widget)
+{
+       if (!GTK_SOURCE_IS_GUTTER_RENDERER (widget))
+       {
+               g_warning ("Cannot add %s to %s as it is not a GtkSourceGutterRenderer",
+                          G_OBJECT_TYPE_NAME (widget),
+                          G_OBJECT_TYPE_NAME (container));
+       }
+       else
+       {
+               gtk_source_gutter_insert (GTK_SOURCE_GUTTER (container),
+                                         GTK_SOURCE_GUTTER_RENDERER (widget),
+                                         0);
+       }
+}
+
+static void
+gtk_source_gutter_remove (GtkContainer *container,
+                          GtkWidget    *widget)
+{
+       GtkSourceGutterRenderer *renderer;
+       GtkSourceGutter *gutter;
+       Renderer *ret;
+       GList *retlist;
+
+       g_return_if_fail (GTK_SOURCE_IS_GUTTER (container));
+       g_return_if_fail (GTK_SOURCE_IS_GUTTER_RENDERER (widget));
+
+       gutter = GTK_SOURCE_GUTTER (container);
+       renderer = GTK_SOURCE_GUTTER_RENDERER (widget);
+
+       if (renderer_find (gutter, renderer, &ret, &retlist))
+       {
+               gutter->priv->renderers =
+                       g_list_delete_link (gutter->priv->renderers, retlist);
+               gtk_widget_unparent (GTK_WIDGET (renderer));
+               renderer_free (ret);
+               gtk_widget_queue_resize (GTK_WIDGET (gutter));
+       }
+       else
+       {
+               g_warning ("Failed to locate %s within %s",
+                          G_OBJECT_TYPE_NAME (widget),
+                          G_OBJECT_TYPE_NAME (gutter));
+       }
+}
+
 /**
  * gtk_source_gutter_reorder:
  * @gutter: a #GtkSourceGutterRenderer.
@@ -620,676 +738,212 @@ gtk_source_gutter_reorder (GtkSourceGutter         *gutter,
 
        if (renderer_find (gutter, renderer, &ret, &retlist))
        {
-               gutter->renderers =
-                       g_list_delete_link (gutter->renderers,
-                                           retlist);
-
+               gutter->priv->renderers =
+                       g_list_delete_link (gutter->priv->renderers, retlist);
                ret->position = position;
                append_renderer (gutter, ret);
+               gtk_widget_queue_allocate (GTK_WIDGET (gutter));
        }
 }
 
-/**
- * gtk_source_gutter_remove:
- * @gutter: a #GtkSourceGutter.
- * @renderer: a #GtkSourceGutterRenderer.
- *
- * Removes @renderer from @gutter.
- *
- * Since: 2.8
- */
-void
-gtk_source_gutter_remove (GtkSourceGutter         *gutter,
-                          GtkSourceGutterRenderer *renderer)
+static void
+gtk_source_gutter_size_allocate (GtkWidget *widget,
+                                 gint       width,
+                                 gint       height,
+                                 gint       baseline)
 {
-       Renderer *ret;
-       GList *retlist;
+       GtkSourceGutter *gutter = GTK_SOURCE_GUTTER (widget);
+       const GList *list;
+       gint x = 0;
 
-       g_return_if_fail (GTK_SOURCE_IS_GUTTER (gutter));
-       g_return_if_fail (GTK_SOURCE_IS_GUTTER_RENDERER (renderer));
+       GTK_WIDGET_CLASS (gtk_source_gutter_parent_class)->size_allocate (widget,
+                                                                         width,
+                                                                         height,
+                                                                         baseline);
 
-       if (renderer_find (gutter, renderer, &ret, &retlist))
+       for (list = gutter->priv->renderers; list; list = list->next)
        {
-               gutter->renderers =
-                       g_list_delete_link (gutter->renderers,
-                                           retlist);
-
-               update_gutter_size (gutter);
-               renderer_free (ret);
-       }
-}
-
-/**
- * gtk_source_gutter_queue_draw:
- * @gutter: a #GtkSourceGutter.
- *
- * Invalidates the drawable area of the gutter. You can use this to force a
- * redraw of the gutter if something has changed and needs to be redrawn.
- *
- * Since: 2.8
- */
-void
-gtk_source_gutter_queue_draw (GtkSourceGutter *gutter)
-{
-       g_return_if_fail (GTK_SOURCE_IS_GUTTER (gutter));
-
-       do_redraw (gutter);
-}
+               Renderer *renderer = list->data;
+               GtkRequisition child_req;
+               GtkAllocation alloc;
 
-typedef struct
-{
-       gint total_height;
-       gint lines_count;
-       GArray *buffer_coords;
-       GArray *line_heights;
-       GArray *line_numbers;
-       GtkTextIter start;
-       GtkTextIter end;
-} LinesInfo;
+               gtk_widget_get_preferred_size (GTK_WIDGET (renderer->renderer),
+                                              &child_req, NULL);
 
-static LinesInfo *
-lines_info_new (void)
-{
-       LinesInfo *info;
+               alloc.x = x;
+               alloc.y = 0;
+               alloc.width = child_req.width;
+               alloc.height = height;
 
-       info = g_slice_new0 (LinesInfo);
+               gtk_widget_size_allocate (GTK_WIDGET (renderer->renderer),
+                                         &alloc,
+                                         -1);
 
-       info->buffer_coords = g_array_new (FALSE, FALSE, sizeof (gint));
-       info->line_heights = g_array_new (FALSE, FALSE, sizeof (gint));
-       info->line_numbers = g_array_new (FALSE, FALSE, sizeof (gint));
+               x += alloc.width;
+       }
 
-       return info;
+       gtk_widget_queue_draw (widget);
 }
 
 static void
-lines_info_free (LinesInfo *info)
+gtk_source_gutter_snapshot (GtkWidget   *widget,
+                            GtkSnapshot *snapshot)
 {
-       if (info != NULL)
-       {
-               g_array_free (info->buffer_coords, TRUE);
-               g_array_free (info->line_heights, TRUE);
-               g_array_free (info->line_numbers, TRUE);
-
-               g_slice_free (LinesInfo, info);
-       }
-}
-
-/* This function is taken and adapted from gtk+/tests/testtext.c */
-static LinesInfo *
-get_lines_info (GtkTextView *text_view,
-                gint         first_y_buffer_coord,
-                gint         last_y_buffer_coord)
-{
-       LinesInfo *info;
-       GtkTextIter iter;
-       gint last_line_num = -1;
-
-       info = lines_info_new ();
-
-       /* Get iter at first y */
-       gtk_text_view_get_line_at_y (text_view, &iter, first_y_buffer_coord, NULL);
+       GtkSourceGutter *gutter = GTK_SOURCE_GUTTER (widget);
+       GtkTextView *text_view = GTK_TEXT_VIEW (gutter->priv->view);
+       GtkStyleContext *view_context;
+       const GList *list;
+       GdkRectangle visible_rect;
+       GtkTextIter begin;
+       GtkTextIter end;
+       gboolean needs_wrap_first = FALSE;
+       gboolean needs_wrap_last = FALSE;
 
-       info->start = iter;
+       g_clear_object (&gutter->priv->lines);
 
-       /* For each iter, get its location and add it to the arrays.
-        * Stop when we pass last_y_buffer_coord.
-        */
-       while (!gtk_text_iter_is_end (&iter))
+       if (text_view == NULL || gtk_widget_get_width (widget) == 0)
        {
-               gint y;
-               gint height;
-               gint line_num;
-
-               gtk_text_view_get_line_yrange (text_view, &iter, &y, &height);
-
-               g_array_append_val (info->buffer_coords, y);
-               g_array_append_val (info->line_heights, height);
-
-               info->total_height += height;
-
-               line_num = gtk_text_iter_get_line (&iter);
-               g_array_append_val (info->line_numbers, line_num);
+               return;
+       }
 
-               last_line_num = line_num;
+       /* We need the style from the view itself for highlight lines */
+       view_context = gtk_widget_get_style_context (GTK_WIDGET (gutter->priv->view));
 
-               info->lines_count++;
+       gtk_text_view_get_visible_rect (text_view, &visible_rect);
+       gtk_text_view_get_iter_at_location (text_view, &begin,
+                                           visible_rect.x, visible_rect.y);
+       gtk_text_view_get_iter_at_location (text_view, &end,
+                                           visible_rect.x,
+                                           visible_rect.y + visible_rect.height);
 
-               if (last_y_buffer_coord <= (y + height))
-               {
-                       break;
-               }
-
-               gtk_text_iter_forward_line (&iter);
-       }
-
-       if (gtk_text_iter_is_end (&iter))
+       /* The first step is to get line information about all the visible
+        * lines. We do this up front so that we can do it once to reduce many
+        * times the renderers need to walk through the buffer contents as that
+        * can be expensive.
+        */
+       get_alignment_modes (gutter, &needs_wrap_first, &needs_wrap_last);
+       gutter->priv->lines = _gtk_source_lines_new (text_view,
+                                                    &begin,
+                                                    &end,
+                                                    needs_wrap_first,
+                                                    needs_wrap_last);
+
+       /* Draw the current-line highlight if necessary */
+       if (gtk_source_view_get_highlight_current_line (gutter->priv->view))
        {
-               gint y;
-               gint height;
-               gint line_num;
+               guint cursor_line;
 
-               gtk_text_view_get_line_yrange (text_view, &iter, &y, &height);
+               cursor_line = _gtk_source_lines_get_cursor_line (gutter->priv->lines);
 
-               line_num = gtk_text_iter_get_line (&iter);
-
-               if (line_num != last_line_num)
+               if (cursor_line >= gtk_source_lines_get_first (gutter->priv->lines) &&
+                   cursor_line <= gtk_source_lines_get_last (gutter->priv->lines))
                {
-                       g_array_append_val (info->buffer_coords, y);
-                       g_array_append_val (info->line_heights, height);
-
-                       info->total_height += height;
-
-                       g_array_append_val (info->line_numbers, line_num);
-                       info->lines_count++;
+                       gint y;
+                       gint height;
+
+                       gtk_source_lines_get_line_yrange (gutter->priv->lines,
+                                                         cursor_line,
+                                                         GTK_SOURCE_GUTTER_RENDERER_ALIGNMENT_MODE_CELL,
+                                                         &y,
+                                                         &height);
+
+                       gtk_style_context_save (view_context);
+                       gtk_style_context_add_class (view_context, "current-line-number");
+
+                       gtk_snapshot_render_background (snapshot,
+                                                       view_context,
+                                                       0,
+                                                       y,
+                                                       gtk_widget_get_width (widget),
+                                                       height);
+
+                       gtk_style_context_restore (view_context);
                }
        }
 
-       if (info->lines_count == 0)
-       {
-               gint y = 0;
-               gint n = 0;
-               gint height;
-
-               info->lines_count = 1;
-
-               g_array_append_val (info->buffer_coords, y);
-               g_array_append_val (info->line_numbers, n);
-
-               gtk_text_view_get_line_yrange (text_view, &iter, &y, &height);
-               g_array_append_val (info->line_heights, height);
-
-               info->total_height += height;
-       }
-
-       info->end = iter;
-
-       return info;
-}
-
-/* Returns %TRUE if @clip is set. @clip contains the area that should be drawn. */
-static gboolean
-get_clip_rectangle (GtkSourceGutter *gutter,
-                    GtkSourceView   *view,
-                    cairo_t         *cr,
-                    GdkRectangle    *clip)
-{
-       GdkWindow *window = get_window (gutter);
-
-       if (window == NULL || !gtk_cairo_should_draw_window (cr, window))
-       {
-               return FALSE;
-       }
-
-       gtk_cairo_transform_to_window (cr, GTK_WIDGET (view), window);
+       gutter->priv->is_drawing = TRUE;
 
-       return gdk_cairo_get_clip_rectangle (cr, clip);
-}
-
-static void
-apply_style (GtkSourceGutter *gutter,
-             GtkSourceView   *view,
-             GtkStyleContext *style_context,
-             cairo_t         *cr)
-{
-       const gchar *class;
-       GdkRGBA fg_color;
-
-       switch (gutter->window_type)
+       /* Now let the renderers populate information about the lines that are
+        * to be rendered. They may need to go through line by line and add
+        * classes (GQuark) to the lines to be used when snapshoting. Since
+        * we've already calculated line information, this is relatively fast.
+        *
+        * We also only emit the ::query-data signal in the case that the
+        * renderer has not override then (*query_data) vfunc which saves quite
+        * a bit of signal overhead.
+        */
+       for (list = gutter->priv->renderers; list; list = list->next)
        {
-               case GTK_TEXT_WINDOW_TOP:
-                       class = GTK_STYLE_CLASS_TOP;
-                       break;
-
-               case GTK_TEXT_WINDOW_RIGHT:
-                       class = GTK_STYLE_CLASS_RIGHT;
-                       break;
-
-               case GTK_TEXT_WINDOW_BOTTOM:
-                       class = GTK_STYLE_CLASS_BOTTOM;
-                       break;
-
-               case GTK_TEXT_WINDOW_LEFT:
-                       class = GTK_STYLE_CLASS_LEFT;
-                       break;
+               Renderer *renderer = list->data;
 
-               case GTK_TEXT_WINDOW_PRIVATE:
-               case GTK_TEXT_WINDOW_WIDGET:
-               case GTK_TEXT_WINDOW_TEXT:
-               default:
-                       g_return_if_reached ();
+               _gtk_source_gutter_renderer_begin (renderer->renderer,
+                                                  gutter->priv->lines);
        }
 
-       /* Apply classes ourselves, since we are in connect_after and so they
-        * are not set by gtk.
+       gtk_snapshot_push_clip (snapshot,
+                               &GRAPHENE_RECT_INIT (0,
+                                                    0,
+                                                    gtk_widget_get_width (widget),
+                                                    gtk_widget_get_height (widget)));
+
+       /* Now let the renderers draw the content for each line. Because
+        * iterating a Linked-List is slower than iterating a series of line
+        * numbers, we make the renderer list the outter loop, and the
+        * snapshotting of lines (within the renderer) the inner loop as part
+        * of snapshot.
         */
-       gtk_style_context_add_class (style_context, class);
-       gtk_style_context_get_color (style_context,
-                                    gtk_style_context_get_state (style_context),
-                                    &fg_color);
-
-       gdk_cairo_set_source_rgba (cr, &fg_color);
-}
-
-/* Call gtk_source_gutter_renderer_begin() on each renderer. */
-static void
-begin_draw (GtkSourceGutter *gutter,
-            GtkTextView     *view,
-            GArray          *renderer_widths,
-            LinesInfo       *info,
-            cairo_t         *cr)
-{
-       GdkRectangle background_area = { 0 };
-       GdkRectangle cell_area;
-       GList *l;
-       gint renderer_num;
-
-       background_area.x = 0;
-       background_area.height = info->total_height;
-
-       gtk_text_view_buffer_to_window_coords (view,
-                                              gutter->window_type,
-                                              0,
-                                              g_array_index (info->buffer_coords, gint, 0),
-                                              NULL,
-                                              &background_area.y);
-
-       cell_area = background_area;
-
-       for (l = gutter->renderers, renderer_num = 0;
-            l != NULL;
-            l = l->next, renderer_num++)
+       for (list = gutter->priv->renderers; list; list = list->next)
        {
-               Renderer *renderer = l->data;
-               gint width;
-               gint xpad;
-
-               width = g_array_index (renderer_widths, gint, renderer_num);
+               Renderer *renderer = list->data;
 
-               if (!gtk_source_gutter_renderer_get_visible (renderer->renderer))
-               {
-                       g_assert_cmpint (width, ==, 0);
-                       continue;
-               }
-
-               gtk_source_gutter_renderer_get_padding (renderer->renderer,
-                                                       &xpad,
-                                                       NULL);
-
-               background_area.width = width;
-
-               cell_area.width = background_area.width - 2 * xpad;
-               cell_area.x = background_area.x + xpad;
-
-               cairo_save (cr);
-
-               gdk_cairo_rectangle (cr, &background_area);
-               cairo_clip (cr);
-
-               gtk_source_gutter_renderer_begin (renderer->renderer,
-                                                 cr,
-                                                 &background_area,
-                                                 &cell_area,
-                                                 &info->start,
-                                                 &info->end);
-
-               cairo_restore (cr);
-
-               background_area.x += background_area.width;
+               gtk_widget_snapshot_child (widget,
+                                          GTK_WIDGET (renderer->renderer),
+                                          snapshot);
        }
-}
 
-static void
-draw_cells (GtkSourceGutter *gutter,
-            GtkTextView     *view,
-            GArray          *renderer_widths,
-            LinesInfo       *info,
-            cairo_t         *cr)
-{
-       GtkTextBuffer *buffer;
-       GtkTextIter insert_iter;
-       gint cur_line;
-       GtkTextIter selection_start;
-       GtkTextIter selection_end;
-       gint selection_start_line = 0;
-       gint selection_end_line = 0;
-       gboolean has_selection;
-       GtkTextIter start;
-       gint i;
-
-       buffer = gtk_text_view_get_buffer (view);
-
-       gtk_text_buffer_get_iter_at_mark (buffer,
-                                         &insert_iter,
-                                         gtk_text_buffer_get_insert (buffer));
-
-       cur_line = gtk_text_iter_get_line (&insert_iter);
-
-       has_selection = gtk_text_buffer_get_selection_bounds (buffer,
-                                                             &selection_start,
-                                                             &selection_end);
-
-       if (has_selection)
-       {
-               selection_start_line = gtk_text_iter_get_line (&selection_start);
-               selection_end_line = gtk_text_iter_get_line (&selection_end);
-       }
+       gtk_snapshot_pop (snapshot);
 
-       start = info->start;
-       i = 0;
+       /* Allow to call queue_redraw() in end. */
+       gutter->priv->is_drawing = FALSE;
 
-       while (i < info->lines_count)
+       /* Now notify the renderers of completion */
+       for (list = gutter->priv->renderers; list; list = list->next)
        {
-               GtkTextIter end;
-               GdkRectangle background_area;
-               GtkSourceGutterRendererState state;
-               gint pos;
-               gint line_to_paint;
-               gint renderer_num;
-               GList *l;
-
-               end = start;
-
-               if (!gtk_text_iter_ends_line (&end))
-               {
-                       /*
-                        * It turns out that gtk_text_iter_forward_to_line_end
-                        * is slower than jumping to the next line in the
-                        * btree index and then moving backwards a character.
-                        * We don't really care that we might be after the
-                        * newline breaking characters, since those are part
-                        * of the same line (rather than the next line).
-                        */
-                       if (gtk_text_iter_forward_line (&end))
-                       {
-                               gtk_text_iter_backward_char (&end);
-                       }
-               }
-
-               /* Possible improvement: if buffer and window coords have the
-                * same unit, there are probably some possible performance
-                * improvements by avoiding some buffer <-> window coords
-                * conversions.
-                */
-               gtk_text_view_buffer_to_window_coords (view,
-                                                      gutter->window_type,
-                                                      0,
-                                                      g_array_index (info->buffer_coords, gint, i),
-                                                      NULL,
-                                                      &pos);
-
-               line_to_paint = g_array_index (info->line_numbers, gint, i);
-
-               background_area.y = pos;
-               background_area.height = g_array_index (info->line_heights, gint, i);
-               background_area.x = 0;
-
-               state = GTK_SOURCE_GUTTER_RENDERER_STATE_NORMAL;
-
-               if (line_to_paint == cur_line)
-               {
-                       state |= GTK_SOURCE_GUTTER_RENDERER_STATE_CURSOR;
-               }
-
-               if (has_selection &&
-                   selection_start_line <= line_to_paint && line_to_paint <= selection_end_line)
-               {
-                       state |= GTK_SOURCE_GUTTER_RENDERER_STATE_SELECTED;
-               }
-
-               for (l = gutter->renderers, renderer_num = 0;
-                    l != NULL;
-                    l = l->next, renderer_num++)
-               {
-                       Renderer *renderer;
-                       GdkRectangle cell_area;
-                       gint width;
-                       gint xpad;
-                       gint ypad;
-
-                       renderer = l->data;
-                       width = g_array_index (renderer_widths, gint, renderer_num);
-
-                       if (!gtk_source_gutter_renderer_get_visible (renderer->renderer))
-                       {
-                               g_assert_cmpint (width, ==, 0);
-                               continue;
-                       }
-
-                       gtk_source_gutter_renderer_get_padding (renderer->renderer,
-                                                               &xpad,
-                                                               &ypad);
-
-                       background_area.width = width;
-
-                       cell_area.y = background_area.y + ypad;
-                       cell_area.height = background_area.height - 2 * ypad;
-
-                       cell_area.x = background_area.x + xpad;
-                       cell_area.width = background_area.width - 2 * xpad;
-
-                       if (renderer->prelit >= 0 &&
-                           cell_area.y <= renderer->prelit && renderer->prelit <= cell_area.y + 
cell_area.height)
-                       {
-                               state |= GTK_SOURCE_GUTTER_RENDERER_STATE_PRELIT;
-                       }
-
-                       gtk_source_gutter_renderer_query_data (renderer->renderer,
-                                                              &start,
-                                                              &end,
-                                                              state);
-
-                       cairo_save (cr);
+               Renderer *renderer = list->data;
 
-                       gdk_cairo_rectangle (cr, &background_area);
-
-                       cairo_clip (cr);
-
-                       /* Call render with correct area */
-                       gtk_source_gutter_renderer_draw (renderer->renderer,
-                                                        cr,
-                                                        &background_area,
-                                                        &cell_area,
-                                                        &start,
-                                                        &end,
-                                                        state);
-
-                       cairo_restore (cr);
-
-                       background_area.x += background_area.width;
-                       state &= ~GTK_SOURCE_GUTTER_RENDERER_STATE_PRELIT;
-               }
-
-               i++;
-               gtk_text_iter_forward_line (&start);
+               _gtk_source_gutter_renderer_end (renderer->renderer);
        }
 }
 
-static void
-end_draw (GtkSourceGutter *gutter)
-{
-       GList *l;
-
-       for (l = gutter->renderers; l != NULL; l = l->next)
-       {
-               Renderer *renderer = l->data;
-
-               if (gtk_source_gutter_renderer_get_visible (renderer->renderer))
-               {
-                       gtk_source_gutter_renderer_end (renderer->renderer);
-               }
-       }
-}
-
-void
-_gtk_source_gutter_draw (GtkSourceGutter *gutter,
-                         GtkSourceView   *view,
-                         cairo_t         *cr)
-{
-       GdkRectangle clip;
-       GtkTextView *text_view;
-       gint first_y_window_coord;
-       gint last_y_window_coord;
-       gint first_y_buffer_coord;
-       gint last_y_buffer_coord;
-       GArray *renderer_widths;
-       LinesInfo *info;
-       GtkStyleContext *style_context;
-
-       if (!get_clip_rectangle (gutter, view, cr, &clip))
-       {
-               return;
-       }
-
-       gutter->is_drawing = TRUE;
-
-       renderer_widths = g_array_new (FALSE, FALSE, sizeof (gint));
-       calculate_gutter_size (gutter, renderer_widths);
-
-       text_view = GTK_TEXT_VIEW (view);
-
-       first_y_window_coord = clip.y;
-       last_y_window_coord = first_y_window_coord + clip.height;
-
-       /* get the extents of the line printing */
-       gtk_text_view_window_to_buffer_coords (text_view,
-                                              gutter->window_type,
-                                              0,
-                                              first_y_window_coord,
-                                              NULL,
-                                              &first_y_buffer_coord);
-
-       gtk_text_view_window_to_buffer_coords (text_view,
-                                              gutter->window_type,
-                                              0,
-                                              last_y_window_coord,
-                                              NULL,
-                                              &last_y_buffer_coord);
-
-       info = get_lines_info (text_view,
-                              first_y_buffer_coord,
-                              last_y_buffer_coord);
-
-       style_context = gtk_widget_get_style_context (GTK_WIDGET (view));
-       gtk_style_context_save (style_context);
-       apply_style (gutter, view, style_context, cr);
-
-       begin_draw (gutter,
-                   text_view,
-                   renderer_widths,
-                   info,
-                   cr);
-
-       draw_cells (gutter,
-                   text_view,
-                   renderer_widths,
-                   info,
-                   cr);
-
-       /* Allow to call queue_redraw() in ::end. */
-       gutter->is_drawing = FALSE;
-
-       end_draw (gutter);
-
-       gtk_style_context_restore (style_context);
-
-       g_array_free (renderer_widths, TRUE);
-       lines_info_free (info);
-}
-
 static Renderer *
 renderer_at_x (GtkSourceGutter *gutter,
                gint             x,
                gint            *start,
                gint            *width)
 {
-       GList *item;
-       gint s;
-       gint w;
-
-       update_gutter_size (gutter);
+       const GList *item;
 
-       s = 0;
-
-       for (item = gutter->renderers; item; item = g_list_next (item))
+       for (item = gutter->priv->renderers; item; item = g_list_next (item))
        {
                Renderer *renderer = item->data;
-               gint xpad;
-
-               if (!gtk_source_gutter_renderer_get_visible (renderer->renderer))
-               {
-                       continue;
-               }
-
-               w = gtk_source_gutter_renderer_get_size (renderer->renderer);
+               GtkAllocation alloc;
 
-               gtk_source_gutter_renderer_get_padding (renderer->renderer,
-                                                       &xpad,
-                                                       NULL);
+               gtk_widget_get_allocation (GTK_WIDGET (renderer->renderer),
+                                          &alloc);
 
-               s += xpad;
-
-               if (w > 0 && x >= s && x < s + w)
+               if (x >= alloc.x && x <= alloc.x + alloc.width)
                {
-                       if (width)
-                       {
-                               *width = w;
-                       }
-
-                       if (start)
-                       {
-                               *start = s;
-                       }
-
                        return renderer;
                }
-
-               s += w + xpad;
        }
 
        return NULL;
 }
 
-static void
-get_renderer_rect (GtkSourceGutter *gutter,
-                   Renderer        *renderer,
-                   GtkTextIter     *iter,
-                   gint             line,
-                   GdkRectangle    *rectangle,
-                   gint             start)
-{
-       gint y;
-       gint ypad;
-
-       rectangle->x = start;
-
-       gtk_text_view_get_line_yrange (GTK_TEXT_VIEW (gutter->view),
-                                      iter,
-                                      &y,
-                                      &rectangle->height);
-
-       rectangle->width = gtk_source_gutter_renderer_get_size (renderer->renderer);
-
-       gtk_text_view_buffer_to_window_coords (GTK_TEXT_VIEW (gutter->view),
-                                              gutter->window_type,
-                                              0,
-                                              y,
-                                              NULL,
-                                              &rectangle->y);
-
-       gtk_source_gutter_renderer_get_padding (renderer->renderer,
-                                               NULL,
-                                               &ypad);
-
-       rectangle->y += ypad;
-       rectangle->height -= 2 * ypad;
-}
-
 static gboolean
 renderer_query_activatable (GtkSourceGutter *gutter,
                             Renderer        *renderer,
                             GdkEvent        *event,
-                            gint             x,
-                            gint             y,
                             GtkTextIter     *line_iter,
                             GdkRectangle    *rect,
                             gint             start)
@@ -1297,21 +951,28 @@ renderer_query_activatable (GtkSourceGutter *gutter,
        gint y_buf;
        gint yline;
        GtkTextIter iter;
-       GdkRectangle r;
+       GdkRectangle r = {0};
+       gdouble x;
+       gdouble y;
 
        if (!renderer)
        {
                return FALSE;
        }
 
-       gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (gutter->view),
-                                              gutter->window_type,
-                                              x,
-                                              y,
+       if (!gdk_event_get_coords (event, &x, &y))
+       {
+               return FALSE;
+       }
+
+       gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (gutter->priv->view),
+                                              GTK_TEXT_WINDOW_WIDGET,
+                                              (gint)x,
+                                              (gint)y,
                                               NULL,
                                               &y_buf);
 
-       gtk_text_view_get_line_at_y (GTK_TEXT_VIEW (gutter->view),
+       gtk_text_view_get_line_at_y (GTK_TEXT_VIEW (gutter->priv->view),
                                     &iter,
                                     y_buf,
                                     &yline);
@@ -1321,7 +982,7 @@ renderer_query_activatable (GtkSourceGutter *gutter,
                return FALSE;
        }
 
-       get_renderer_rect (gutter, renderer, &iter, yline, &r, start);
+       //get_renderer_rect (gutter, renderer, &iter, yline, &r, start);
 
        if (line_iter)
        {
@@ -1346,21 +1007,18 @@ renderer_query_activatable (GtkSourceGutter *gutter,
 
 static gboolean
 redraw_for_window (GtkSourceGutter *gutter,
-                   GdkEvent        *event,
-                   gboolean         act_on_window,
-                   gint             x,
-                   gint             y)
+                  gboolean         act_on_window,
+                  gint             x,
+                  gint             y)
 {
+       gtk_widget_queue_draw (GTK_WIDGET (gutter));
+
+#if 0
        Renderer *at_x = NULL;
        gint start = 0;
        GList *item;
        gboolean redraw;
 
-       if (event->any.window != get_window (gutter) && act_on_window)
-       {
-               return FALSE;
-       }
-
        if (act_on_window)
        {
                at_x = renderer_at_x (gutter, x, &start, NULL);
@@ -1368,7 +1026,7 @@ redraw_for_window (GtkSourceGutter *gutter,
 
        redraw = FALSE;
 
-       for (item = gutter->renderers; item; item = g_list_next (item))
+       for (item = gutter->priv->renderers; item; item = g_list_next (item))
        {
                Renderer *renderer = item->data;
                gint prelit = renderer->prelit;
@@ -1385,7 +1043,6 @@ redraw_for_window (GtkSourceGutter *gutter,
                        }
                        else if (renderer_query_activatable (gutter,
                                                             renderer,
-                                                            event,
                                                             x,
                                                             y,
                                                             NULL,
@@ -1407,74 +1064,71 @@ redraw_for_window (GtkSourceGutter *gutter,
        {
                do_redraw (gutter);
        }
+#endif
 
        return FALSE;
 }
 
-static gboolean
-on_view_motion_notify_event (GtkSourceView   *view,
-                             GdkEventMotion  *event,
-                             GtkSourceGutter *gutter)
+static void
+on_gutter_motion_enter (GtkSourceGutter          *gutter,
+                        gdouble                   x,
+                        gdouble                   y,
+                        GdkCrossingMode           mode,
+                        GdkNotifyType             notify_type,
+                        GtkEventControllerMotion *motion)
 {
-       return redraw_for_window (gutter,
-                                 (GdkEvent *)event,
-                                 TRUE,
-                                 (gint)event->x,
-                                 (gint)event->y);
+       redraw_for_window (gutter, TRUE, x, y);
 }
 
-static gboolean
-on_view_enter_notify_event (GtkSourceView    *view,
-                            GdkEventCrossing *event,
-                            GtkSourceGutter  *gutter)
+static void
+on_gutter_motion (GtkSourceGutter          *gutter,
+                  gdouble                   x,
+                  gdouble                   y,
+                  GtkEventControllerMotion *motion)
+
 {
-       return redraw_for_window (gutter,
-                                 (GdkEvent *)event,
-                                 TRUE,
-                                 (gint)event->x,
-                                 (gint)event->y);
+       redraw_for_window (gutter, TRUE, x, y);
 }
 
-static gboolean
-on_view_leave_notify_event (GtkSourceView    *view,
-                            GdkEventCrossing *event,
-                            GtkSourceGutter  *gutter)
+static void
+on_gutter_motion_leave (GtkSourceGutter          *gutter,
+                        GdkCrossingMode           mode,
+                        GdkNotifyType             notify_type,
+                        GtkEventControllerMotion *motion)
 {
-       return redraw_for_window (gutter,
-                                 (GdkEvent *)event,
-                                 FALSE,
-                                 (gint)event->x,
-                                 (gint)event->y);
+       redraw_for_window (gutter, FALSE, -1, -1);
 }
 
-static gboolean
-on_view_button_press_event (GtkSourceView   *view,
-                            GdkEventButton  *event,
-                            GtkSourceGutter *gutter)
+static void
+on_gutter_pressed_cb (GtkSourceGutter *gutter,
+                      gint             n_presses,
+                      gdouble          x,
+                      gdouble          y,
+                      GtkGestureClick *click)
 {
+
        Renderer *renderer;
        GtkTextIter line_iter;
        gint start = -1;
        GdkRectangle rect;
+       const GdkEvent *event;
 
-       if (event->window != get_window (gutter))
-       {
-               return FALSE;
-       }
+       g_assert (GTK_SOURCE_IS_GUTTER (gutter));
+       g_assert (GTK_IS_GESTURE_CLICK (click));
+
+       event = gtk_gesture_get_last_event (GTK_GESTURE (click), NULL);
 
-       if (event->type != GDK_BUTTON_PRESS)
+       if (event == NULL)
        {
-               return FALSE;
+               return;
        }
 
        /* Check cell renderer */
-       renderer = renderer_at_x (gutter, event->x, &start, NULL);
+       renderer = renderer_at_x (gutter, x, &start, NULL);
 
        if (renderer_query_activatable (gutter,
                                        renderer,
                                        (GdkEvent *)event,
-                                       (gint)event->x,
-                                       (gint)event->y,
                                        &line_iter,
                                        &rect,
                                        start))
@@ -1486,111 +1140,22 @@ on_view_button_press_event (GtkSourceView   *view,
 
                do_redraw (gutter);
 
-               return TRUE;
-       }
-
-       return FALSE;
-}
-
-static gboolean
-on_view_query_tooltip (GtkSourceView   *view,
-                       gint             x,
-                       gint             y,
-                       gboolean         keyboard_mode,
-                       GtkTooltip      *tooltip,
-                       GtkSourceGutter *gutter)
-{
-       GtkTextView *text_view = GTK_TEXT_VIEW (view);
-       Renderer *renderer;
-       gint start = 0;
-       gint width = 0;
-       gint y_buf;
-       gint yline;
-       GtkTextIter line_iter;
-       GdkRectangle rect;
-
-       if (keyboard_mode)
-       {
-               return FALSE;
-       }
-
-       /* Check cell renderer */
-       renderer = renderer_at_x (gutter, x, &start, &width);
-
-       if (!renderer)
-       {
-               return FALSE;
+               gtk_gesture_set_state (GTK_GESTURE (click),
+                                      GTK_EVENT_SEQUENCE_CLAIMED);
        }
-
-       gtk_text_view_window_to_buffer_coords (text_view,
-                                              gutter->window_type,
-                                              x, y,
-                                              NULL, &y_buf);
-
-       gtk_text_view_get_line_at_y (GTK_TEXT_VIEW (view),
-                                    &line_iter,
-                                    y_buf,
-                                    &yline);
-
-       if (yline > y_buf)
-       {
-               return FALSE;
-       }
-
-       get_renderer_rect (gutter,
-                          renderer,
-                          &line_iter,
-                          yline,
-                          &rect,
-                          start);
-
-       return gtk_source_gutter_renderer_query_tooltip (renderer->renderer,
-                                                        &line_iter,
-                                                        &rect,
-                                                        x,
-                                                        y,
-                                                        tooltip);
 }
 
 static void
 on_view_style_updated (GtkSourceView   *view,
                        GtkSourceGutter *gutter)
 {
-       gtk_source_gutter_queue_draw (gutter);
+       do_redraw (gutter);
 }
 
-/**
- * gtk_source_gutter_get_renderer_at_pos:
- * @gutter: A #GtkSourceGutter.
- * @x: The x position to get identified.
- * @y: The y position to get identified.
- *
- * Finds the #GtkSourceGutterRenderer at (x, y).
- *
- * Returns: (nullable) (transfer none): the renderer at (x, y) or %NULL.
- */
-/* TODO: better document this function. The (x,y) position is different from
- * the position passed to gtk_source_gutter_insert() and
- * gtk_source_gutter_reorder(). The (x,y) coordinate can come from a click
- * event, for example? Is the (x,y) a coordinate of the Gutter's GdkWindow?
- * Where is the (0,0)? And so on.
- * Also, this function doesn't seem to be used.
- */
-GtkSourceGutterRenderer *
-gtk_source_gutter_get_renderer_at_pos (GtkSourceGutter *gutter,
-                                       gint             x,
-                                       gint             y)
+GtkSourceLines *
+_gtk_source_gutter_get_lines (GtkSourceGutter *gutter)
 {
-       Renderer *renderer;
-
        g_return_val_if_fail (GTK_SOURCE_IS_GUTTER (gutter), NULL);
 
-       renderer = renderer_at_x (gutter, x, NULL, NULL);
-
-       if (renderer == NULL)
-       {
-               return NULL;
-       }
-
-       return renderer->renderer;
+       return gutter->priv->lines;
 }
diff --git a/gtksourceview/gtksourcegutter.h b/gtksourceview/gtksourcegutter.h
index 3fdf5b44..498af032 100644
--- a/gtksourceview/gtksourcegutter.h
+++ b/gtksourceview/gtksourcegutter.h
@@ -2,7 +2,7 @@
  *
  * This file is part of GtkSourceView
  *
- * Copyright 2009 - Jesse van den Kieboom
+ * Copyright (C) 2009 - Jesse van den Kieboom
  *
  * GtkSourceView is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -18,7 +18,8 @@
  * along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#pragma once
+#ifndef GTK_SOURCE_GUTTER_H
+#define GTK_SOURCE_GUTTER_H
 
 #if !defined (GTK_SOURCE_H_INSIDE) && !defined (GTK_SOURCE_COMPILATION)
 #error "Only <gtksourceview/gtksource.h> can be included directly."
@@ -30,31 +31,44 @@
 
 G_BEGIN_DECLS
 
-#define GTK_SOURCE_TYPE_GUTTER (gtk_source_gutter_get_type())
+#define GTK_SOURCE_TYPE_GUTTER                 (gtk_source_gutter_get_type ())
+#define GTK_SOURCE_GUTTER(obj)                 (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_SOURCE_TYPE_GUTTER, 
GtkSourceGutter))
+#define GTK_SOURCE_GUTTER_CLASS(klass)         (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_SOURCE_TYPE_GUTTER, 
GtkSourceGutterClass))
+#define GTK_SOURCE_IS_GUTTER(obj)              (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_SOURCE_TYPE_GUTTER))
+#define GTK_SOURCE_IS_GUTTER_CLASS(klass)      (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_SOURCE_TYPE_GUTTER))
+#define GTK_SOURCE_GUTTER_GET_CLASS(obj)       (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_SOURCE_TYPE_GUTTER, 
GtkSourceGutterClass))
 
-GTK_SOURCE_AVAILABLE_IN_ALL
-G_DECLARE_FINAL_TYPE (GtkSourceGutter, gtk_source_gutter, GTK_SOURCE, GUTTER, GObject)
+typedef struct _GtkSourceGutterClass   GtkSourceGutterClass;
+typedef struct _GtkSourceGutterPrivate GtkSourceGutterPrivate;
+
+struct _GtkSourceGutter
+{
+       GtkContainer parent;
+
+       GtkSourceGutterPrivate *priv;
+};
+
+struct _GtkSourceGutterClass
+{
+       GtkContainerClass parent_class;
+
+       /*< private >*/
+       gpointer _reserved[10];
+};
 
-GTK_SOURCE_AVAILABLE_IN_3_24
-GtkSourceView           *gtk_source_gutter_get_view            (GtkSourceGutter         *gutter);
-GTK_SOURCE_AVAILABLE_IN_3_24
-GtkTextWindowType        gtk_source_gutter_get_window_type     (GtkSourceGutter         *gutter);
-GTK_SOURCE_AVAILABLE_IN_ALL
-gboolean                 gtk_source_gutter_insert              (GtkSourceGutter         *gutter,
-                                                                GtkSourceGutterRenderer *renderer,
-                                                                gint                     position);
-GTK_SOURCE_AVAILABLE_IN_ALL
-void                     gtk_source_gutter_reorder             (GtkSourceGutter         *gutter,
-                                                                GtkSourceGutterRenderer *renderer,
-                                                                gint                     position);
 GTK_SOURCE_AVAILABLE_IN_ALL
-void                     gtk_source_gutter_remove              (GtkSourceGutter         *gutter,
-                                                                GtkSourceGutterRenderer *renderer);
+GType              gtk_source_gutter_get_type        (void) G_GNUC_CONST;
+GTK_SOURCE_AVAILABLE_IN_3_24
+GtkSourceView     *gtk_source_gutter_get_view        (GtkSourceGutter         *gutter);
 GTK_SOURCE_AVAILABLE_IN_ALL
-void                     gtk_source_gutter_queue_draw          (GtkSourceGutter         *gutter);
+gboolean           gtk_source_gutter_insert          (GtkSourceGutter         *gutter,
+                                                      GtkSourceGutterRenderer *renderer,
+                                                      gint                     position);
 GTK_SOURCE_AVAILABLE_IN_ALL
-GtkSourceGutterRenderer *gtk_source_gutter_get_renderer_at_pos (GtkSourceGutter         *gutter,
-                                                                gint                     x,
-                                                                gint                     y);
+void               gtk_source_gutter_reorder         (GtkSourceGutter         *gutter,
+                                                      GtkSourceGutterRenderer *renderer,
+                                                      gint                     position);
 
 G_END_DECLS
+
+#endif /* GTK_SOURCE_GUTTER_H */
diff --git a/gtksourceview/gtksourcegutterrenderer-private.h b/gtksourceview/gtksourcegutterrenderer-private.h
index 790fa6df..5f956e3c 100644
--- a/gtksourceview/gtksourcegutterrenderer-private.h
+++ b/gtksourceview/gtksourcegutterrenderer-private.h
@@ -2,7 +2,7 @@
  *
  * This file is part of GtkSourceView
  *
- * Copyright 2010 - Krzesimir Nowak
+ * Copyright (C) 2010 - Krzesimir Nowak
  *
  * GtkSourceView is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -18,16 +18,28 @@
  * along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#pragma once
+#ifndef GTK_SOURCE_GUTTER_RENDERER_PRIVATE_H
+#define GTK_SOURCE_GUTTER_RENDERER_PRIVATE_H
 
 #include <gtk/gtk.h>
+
 #include "gtksourcetypes.h"
 
 G_BEGIN_DECLS
 
 G_GNUC_INTERNAL
-void _gtk_source_gutter_renderer_set_view (GtkSourceGutterRenderer *renderer,
-                                           GtkTextView             *view,
-                                           GtkTextWindowType        window_type);
+void _gtk_source_gutter_renderer_set_view   (GtkSourceGutterRenderer *renderer,
+                                             GtkSourceView           *view);
+G_GNUC_INTERNAL
+void _gtk_source_gutter_renderer_begin      (GtkSourceGutterRenderer *renderer,
+                                             GtkSourceLines          *lines);
+G_GNUC_INTERNAL
+void _gtk_source_gutter_renderer_snapshot   (GtkSourceGutterRenderer *renderer,
+                                             GtkSnapshot             *snapshot,
+                                             GtkSourceLines          *lines);
+G_GNUC_INTERNAL
+void _gtk_source_gutter_renderer_end        (GtkSourceGutterRenderer *renderer);
 
 G_END_DECLS
+
+#endif /* GTK_SOURCE_GUTTER_RENDERER_PRIVATE_H */
diff --git a/gtksourceview/gtksourcegutterrenderer.c b/gtksourceview/gtksourcegutterrenderer.c
index bcc6e5dc..a68a36fe 100644
--- a/gtksourceview/gtksourcegutterrenderer.c
+++ b/gtksourceview/gtksourcegutterrenderer.c
@@ -2,7 +2,7 @@
  *
  * This file is part of GtkSourceView
  *
- * Copyright 2010 - Jesse van den Kieboom
+ * Copyright (C) 2010 - Jesse van den Kieboom
  *
  * GtkSourceView is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -18,10 +18,16 @@
  * along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "config.h"
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
 
+#include "gtksourcebuffer.h"
+#include "gtksourcegutter.h"
+#include "gtksourcegutter-private.h"
 #include "gtksourcegutterrenderer.h"
 #include "gtksourcegutterrenderer-private.h"
+#include "gtksourcelines.h"
 #include "gtksourcestylescheme.h"
 #include "gtksourceview.h"
 #include "gtksource-enumtypes.h"
@@ -39,9 +45,11 @@
  * this case, #GtkSourceGutterRendererAlignmentMode controls the alignment of
  * the cell.
  *
- * The gutter renderer must announce its #GtkSourceGutterRenderer:size. The
- * height is determined by the text view height. The width must be determined by
- * the gutter renderer. The width generally takes into account the entire text
+ * The gutter renderer is a #GtkWidget and is measured using the normal widget
+ * measurement facilities. The width of the gutter will be determined by the
+ * measurements of the gutter renderers.
+ *
+ * The width of a gutter renderer generally takes into account the entire text
  * buffer. For instance, to display the line numbers, if the buffer contains 100
  * lines, the gutter renderer will always set its width such as three digits can
  * be printed, even if only the first 20 lines are shown. Another strategy is to
@@ -51,122 +59,83 @@
  * into account the text buffer to announce its width. It only depends on the
  * icons size displayed in the gutter column.
  *
- * An horizontal and vertical padding can be added with
- * gtk_source_gutter_renderer_set_padding().  The total width of a gutter
- * renderer is its size (#GtkSourceGutterRenderer:size) plus two times the
- * horizontal padding (#GtkSourceGutterRenderer:xpad).
- *
  * When the available size to render a cell is greater than the required size to
  * render the cell contents, the cell contents can be aligned horizontally and
  * vertically with gtk_source_gutter_renderer_set_alignment().
  *
- * The cells rendering occurs in three phases:
- * - begin: the gtk_source_gutter_renderer_begin() function is called when some
- *   cells need to be redrawn. It provides the associated region of the
- *   #GtkTextBuffer. The cells need to be redrawn when the #GtkTextView is
- *   scrolled, or when the state of the cells change (see
- *   #GtkSourceGutterRendererState).
- * - draw: gtk_source_gutter_renderer_draw() is called for each cell that needs
- *   to be drawn.
- * - end: finally, gtk_source_gutter_renderer_end() is called.
+ * The cells rendering occurs using gtk_widget_snapshot(). Implementations
+ * should use gtk_source_gutter_renderer_get_lines() to retrieve information
+ * about the lines to be rendered. To help with aligning content which takes
+ * into account the padding and alignment of a cell, implementations may call
+ * gtk_source_gutter_renderer_align_cell() for a given line number with the
+ * width and height measurement of the content they width to render.
  */
 
-enum
+struct _GtkSourceGutterRendererPrivate
 {
-       ACTIVATE,
-       QUEUE_DRAW,
-       QUERY_TOOLTIP,
-       QUERY_DATA,
-       QUERY_ACTIVATABLE,
-       N_SIGNALS
-};
-
-typedef struct
-{
-       GtkTextView *view;
-       GtkTextBuffer *buffer;
-       GtkTextWindowType window_type;
-
-       gint xpad;
-       gint ypad;
+       GtkSourceGutter *gutter;
+       GtkSourceView   *view;
+       GtkSourceBuffer *buffer;
+       GtkSourceLines  *lines;
 
        gfloat xalign;
        gfloat yalign;
 
-       gint size;
+       gint xpad;
+       gint ypad;
 
        GtkSourceGutterRendererAlignmentMode alignment_mode;
 
-       GdkRGBA background_color;
-
-       guint background_set : 1;
        guint visible : 1;
-} GtkSourceGutterRendererPrivate;
-
-static guint signals[N_SIGNALS];
+};
 
-G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (GtkSourceGutterRenderer, gtk_source_gutter_renderer, 
G_TYPE_INITIALLY_UNOWNED)
+G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (GtkSourceGutterRenderer, gtk_source_gutter_renderer, GTK_TYPE_WIDGET)
 
 enum
 {
        PROP_0,
-       PROP_VISIBLE,
-       PROP_XPAD,
-       PROP_YPAD,
+       PROP_ALIGNMENT_MODE,
+       PROP_LINES,
+       PROP_VIEW,
        PROP_XALIGN,
+       PROP_XPAD,
        PROP_YALIGN,
-       PROP_VIEW,
-       PROP_ALIGNMENT_MODE,
-       PROP_WINDOW_TYPE,
-       PROP_SIZE,
-       PROP_BACKGROUND_RGBA,
-       PROP_BACKGROUND_SET
+       PROP_YPAD,
+       N_PROPS
 };
 
-static void
-set_buffer (GtkSourceGutterRenderer *renderer,
-            GtkTextBuffer           *buffer)
+enum
 {
-       GtkSourceGutterRendererPrivate *priv = gtk_source_gutter_renderer_get_instance_private (renderer);
-
-       if (priv->buffer != NULL)
-       {
-               g_object_remove_weak_pointer (G_OBJECT (priv->buffer),
-                                             (gpointer) &priv->buffer);
-       }
-
-       if (buffer != NULL)
-       {
-               g_object_add_weak_pointer (G_OBJECT (buffer),
-                                          (gpointer) &priv->buffer);
-       }
+       ACTIVATE,
+       QUERY_ACTIVATABLE,
+       QUERY_DATA,
+       N_SIGNALS
+};
 
-       priv->buffer = buffer;
-}
+static GParamSpec *properties[N_PROPS];
+static guint signals[N_SIGNALS];
 
 static void
-emit_buffer_changed (GtkTextView             *view,
+emit_buffer_changed (GtkSourceView           *view,
                      GtkSourceGutterRenderer *renderer)
 {
-       GtkSourceGutterRendererPrivate *priv = gtk_source_gutter_renderer_get_instance_private (renderer);
-       GtkTextBuffer* buffer;
+       GtkSourceBuffer *buffer;
+       GtkSourceBuffer *old_buffer;
 
-       buffer = gtk_text_view_get_buffer (view);
+       old_buffer = renderer->priv->buffer;
+       buffer = GTK_SOURCE_BUFFER (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)));
 
-       if (buffer != priv->buffer)
+       if (buffer == old_buffer)
        {
-               if (GTK_SOURCE_GUTTER_RENDERER_GET_CLASS (renderer)->change_buffer)
-               {
-                       GTK_SOURCE_GUTTER_RENDERER_GET_CLASS (renderer)->change_buffer (renderer,
-                                                                                       priv->buffer);
-               }
-
-               set_buffer (renderer, buffer);
+               return;
        }
+
+       g_set_weak_pointer (&renderer->priv->buffer, buffer);
+       GTK_SOURCE_GUTTER_RENDERER_GET_CLASS (renderer)->change_buffer (renderer, old_buffer);
 }
 
 static void
-on_buffer_changed (GtkTextView             *view,
+on_buffer_changed (GtkSourceView           *view,
                    GParamSpec              *spec,
                    GtkSourceGutterRenderer *renderer)
 {
@@ -174,23 +143,27 @@ on_buffer_changed (GtkTextView             *view,
 }
 
 static void
-renderer_change_view_impl (GtkSourceGutterRenderer *renderer,
-                           GtkTextView             *old_view)
+gtk_source_gutter_renderer_change_buffer (GtkSourceGutterRenderer *renderer,
+                                          GtkSourceBuffer         *buffer)
 {
-       GtkSourceGutterRendererPrivate *priv = gtk_source_gutter_renderer_get_instance_private (renderer);
+}
 
-       if (old_view)
+static void
+gtk_source_gutter_renderer_change_view (GtkSourceGutterRenderer *renderer,
+                                        GtkSourceView           *old_view)
+{
+       if (old_view != NULL)
        {
                g_signal_handlers_disconnect_by_func (old_view,
                                                      G_CALLBACK (on_buffer_changed),
                                                      renderer);
        }
 
-       if (priv->view)
+       if (renderer->priv->view != NULL)
        {
-               emit_buffer_changed (priv->view, renderer);
+               emit_buffer_changed (renderer->priv->view, renderer);
 
-               g_signal_connect (priv->view,
+               g_signal_connect (renderer->priv->view,
                                  "notify::buffer",
                                  G_CALLBACK (on_buffer_changed),
                                  renderer);
@@ -198,196 +171,96 @@ renderer_change_view_impl (GtkSourceGutterRenderer *renderer,
 }
 
 static void
-gtk_source_gutter_renderer_dispose (GObject *object)
+gtk_source_gutter_renderer_snapshot (GtkWidget   *widget,
+                                     GtkSnapshot *snapshot)
 {
-       GtkSourceGutterRenderer *renderer = GTK_SOURCE_GUTTER_RENDERER (object);
-       GtkSourceGutterRendererPrivate *priv = gtk_source_gutter_renderer_get_instance_private (renderer);
-
-       set_buffer (renderer, NULL);
+       GtkSourceGutterRenderer *renderer = GTK_SOURCE_GUTTER_RENDERER (widget);
+       GtkSourceGutterRendererClass *klass = GTK_SOURCE_GUTTER_RENDERER_GET_CLASS (widget);
+       GtkSourceGutterRendererAlignmentMode mode = renderer->priv->alignment_mode;
+       GtkSourceLines *lines = renderer->priv->lines;
+       guint first;
+       guint last;
+       guint line;
+       gint y;
+       gint h;
 
-       if (priv->view)
+       if (lines == NULL || klass->snapshot_line == NULL)
        {
-               _gtk_source_gutter_renderer_set_view (renderer,
-                                                     NULL,
-                                                     GTK_TEXT_WINDOW_PRIVATE);
+               return;
        }
 
-       G_OBJECT_CLASS (gtk_source_gutter_renderer_parent_class)->dispose (object);
-}
-
-static void
-set_visible (GtkSourceGutterRenderer *renderer,
-             gboolean                 visible)
-{
-       GtkSourceGutterRendererPrivate *priv = gtk_source_gutter_renderer_get_instance_private (renderer);
-
-       visible = visible != FALSE;
+       first = gtk_source_lines_get_first (lines);
+       last = gtk_source_lines_get_last (lines);
 
-       if (priv->visible != visible)
+       for (line = first; line <= last; line++)
        {
-               priv->visible = visible;
-               g_object_notify (G_OBJECT (renderer), "visible");
+               gtk_source_lines_get_line_yrange (lines, line, mode, &y, &h);
 
-               gtk_source_gutter_renderer_queue_draw (renderer);
+               klass->query_data (renderer, lines, line);
+               klass->snapshot_line (renderer, snapshot, lines, line);
        }
 }
 
-static gboolean
-set_padding (GtkSourceGutterRenderer *renderer,
-             gint                    *field,
-             gint                     padding,
-             const gchar             *name)
-{
-       if (*field == padding || padding < 0)
-       {
-               return FALSE;
-       }
-
-       *field = padding;
-       g_object_notify (G_OBJECT (renderer), name);
-
-       return TRUE;
-}
-
-static gboolean
-set_xpad (GtkSourceGutterRenderer *renderer,
-          gint                     xpad)
+static void
+gtk_source_gutter_renderer_dispose (GObject *object)
 {
-       GtkSourceGutterRendererPrivate *priv = gtk_source_gutter_renderer_get_instance_private (renderer);
+       GtkSourceGutterRenderer *renderer;
 
-       return set_padding (renderer,
-                           &priv->xpad,
-                           xpad,
-                           "xpad");
-}
+       renderer = GTK_SOURCE_GUTTER_RENDERER (object);
 
-static gboolean
-set_ypad (GtkSourceGutterRenderer *renderer,
-          gint                     ypad)
-{
-       GtkSourceGutterRendererPrivate *priv = gtk_source_gutter_renderer_get_instance_private (renderer);
+       g_clear_weak_pointer (&renderer->priv->buffer);
 
-       return set_padding (renderer,
-                           &priv->ypad,
-                           ypad,
-                           "ypad");
-}
-
-static gboolean
-set_alignment (GtkSourceGutterRenderer *renderer,
-               gfloat                  *field,
-               gfloat                   align,
-               const gchar             *name,
-               gboolean                 emit)
-{
-       if (*field == align || align < 0)
+       if (renderer->priv->view != NULL)
        {
-               return FALSE;
+               _gtk_source_gutter_renderer_set_view (renderer, NULL);
        }
 
-       *field = align;
-       g_object_notify (G_OBJECT (renderer), name);
-
-       if (emit)
-       {
-               gtk_source_gutter_renderer_queue_draw (renderer);
-       }
-
-       return TRUE;
+       G_OBJECT_CLASS (gtk_source_gutter_renderer_parent_class)->dispose (object);
 }
 
-static gboolean
-set_xalign (GtkSourceGutterRenderer *renderer,
-            gfloat                   xalign,
-            gboolean                 emit)
+static void
+gtk_source_gutter_renderer_root (GtkWidget *widget)
 {
-       GtkSourceGutterRendererPrivate *priv = gtk_source_gutter_renderer_get_instance_private (renderer);
+       GtkSourceGutterRenderer *renderer = GTK_SOURCE_GUTTER_RENDERER (widget);
+       GtkWidget *gutter;
 
-       return set_alignment (renderer,
-                             &priv->xalign,
-                             xalign,
-                             "xalign",
-                             emit);
-}
+       GTK_WIDGET_CLASS (gtk_source_gutter_renderer_parent_class)->root (widget);
 
-static gboolean
-set_yalign (GtkSourceGutterRenderer *renderer,
-            gfloat                   yalign,
-            gboolean                 emit)
-{
-       GtkSourceGutterRendererPrivate *priv = gtk_source_gutter_renderer_get_instance_private (renderer);
+       gutter = gtk_widget_get_ancestor (widget, GTK_SOURCE_TYPE_GUTTER);
 
-       return set_alignment (renderer,
-                             &priv->yalign,
-                             yalign,
-                             "yalign",
-                             emit);
+       if (GTK_SOURCE_IS_GUTTER (gutter))
+       {
+               renderer->priv->gutter = GTK_SOURCE_GUTTER (gutter);
+       }
 }
 
 static void
-set_alignment_mode (GtkSourceGutterRenderer              *renderer,
-                    GtkSourceGutterRendererAlignmentMode  mode)
+gtk_source_gutter_renderer_unroot (GtkWidget *widget)
 {
-       GtkSourceGutterRendererPrivate *priv = gtk_source_gutter_renderer_get_instance_private (renderer);
+       GtkSourceGutterRenderer *renderer = GTK_SOURCE_GUTTER_RENDERER (widget);
 
-       if (priv->alignment_mode == mode)
-       {
-               return;
-       }
-
-       priv->alignment_mode = mode;
-       g_object_notify (G_OBJECT (renderer), "alignment-mode");
+       renderer->priv->gutter = NULL;
 
-       gtk_source_gutter_renderer_queue_draw (renderer);
+       GTK_WIDGET_CLASS (gtk_source_gutter_renderer_parent_class)->unroot (widget);
 }
 
 static void
-set_size (GtkSourceGutterRenderer *renderer,
-          gint                     value)
+gtk_source_gutter_renderer_real_begin (GtkSourceGutterRenderer *renderer,
+                                       GtkSourceLines          *lines)
 {
-       GtkSourceGutterRendererPrivate *priv = gtk_source_gutter_renderer_get_instance_private (renderer);
-
-       if (priv->size == value)
-       {
-               return;
-       }
-
-       priv->size = value;
-       g_object_notify (G_OBJECT (renderer), "size");
 }
 
 static void
-set_background_color_set (GtkSourceGutterRenderer *renderer,
-                          gboolean                 isset)
+gtk_source_gutter_renderer_real_end (GtkSourceGutterRenderer *renderer)
 {
-       GtkSourceGutterRendererPrivate *priv = gtk_source_gutter_renderer_get_instance_private (renderer);
-
-       isset = (isset != FALSE);
-
-       if (isset != priv->background_set)
-       {
-               priv->background_set = isset;
-               gtk_source_gutter_renderer_queue_draw (renderer);
-       }
 }
 
 static void
-set_background_color (GtkSourceGutterRenderer *renderer,
-                      const GdkRGBA          *color)
+gtk_source_gutter_renderer_query_data (GtkSourceGutterRenderer *renderer,
+                                       GtkSourceLines          *lines,
+                                       guint                    line)
 {
-       GtkSourceGutterRendererPrivate *priv = gtk_source_gutter_renderer_get_instance_private (renderer);
-
-       if (!color)
-       {
-               set_background_color_set (renderer, FALSE);
-       }
-       else
-       {
-               priv->background_color = *color;
-               priv->background_set = TRUE;
-
-               gtk_source_gutter_renderer_queue_draw (renderer);
-       }
+       g_signal_emit (renderer, signals[QUERY_DATA], 0, lines, line);
 }
 
 static void
@@ -397,45 +270,29 @@ gtk_source_gutter_renderer_set_property (GObject      *object,
                                          GParamSpec   *pspec)
 {
        GtkSourceGutterRenderer *self = GTK_SOURCE_GUTTER_RENDERER (object);
-       GtkSourceGutterRendererPrivate *priv = gtk_source_gutter_renderer_get_instance_private (self);
 
        switch (prop_id)
        {
-               case PROP_VISIBLE:
-                       set_visible (self, g_value_get_boolean (value));
-                       break;
                case PROP_XPAD:
-                       set_xpad (self, g_value_get_int (value));
+                       gtk_source_gutter_renderer_set_xpad (self, g_value_get_int (value));
                        break;
+
                case PROP_YPAD:
-                       set_ypad (self, g_value_get_int (value));
+                       gtk_source_gutter_renderer_set_ypad (self, g_value_get_int (value));
                        break;
+
                case PROP_XALIGN:
-                       set_xalign (self, g_value_get_float (value), TRUE);
+                       gtk_source_gutter_renderer_set_xalign (self, g_value_get_float (value));
                        break;
+
                case PROP_YALIGN:
-                       set_yalign (self, g_value_get_float (value), TRUE);
+                       gtk_source_gutter_renderer_set_yalign (self, g_value_get_float (value));
                        break;
+
                case PROP_ALIGNMENT_MODE:
-                       set_alignment_mode (self, g_value_get_enum (value));
-                       break;
-               case PROP_VIEW:
-                       priv->view = g_value_get_object (value);
-                       break;
-               case PROP_WINDOW_TYPE:
-                       priv->window_type = g_value_get_enum (value);
-                       break;
-               case PROP_SIZE:
-                       set_size (self, g_value_get_int (value));
-                       break;
-               case PROP_BACKGROUND_RGBA:
-                       set_background_color (self,
-                                             g_value_get_boxed (value));
-                       break;
-               case PROP_BACKGROUND_SET:
-                       set_background_color_set (self,
-                                                 g_value_get_boolean (value));
+                       gtk_source_gutter_renderer_set_alignment_mode (self, g_value_get_enum (value));
                        break;
+
                default:
                        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
                        break;
@@ -449,146 +306,104 @@ gtk_source_gutter_renderer_get_property (GObject    *object,
                                          GParamSpec *pspec)
 {
        GtkSourceGutterRenderer *self = GTK_SOURCE_GUTTER_RENDERER (object);
-       GtkSourceGutterRendererPrivate *priv = gtk_source_gutter_renderer_get_instance_private (self);
 
        switch (prop_id)
        {
-               case PROP_VISIBLE:
-                       g_value_set_boolean (value, priv->visible);
-                       break;
-               case PROP_XPAD:
-                       g_value_set_int (value, priv->xpad);
-                       break;
-               case PROP_YPAD:
-                       g_value_set_int (value, priv->ypad);
+               case PROP_LINES:
+                       g_value_set_object (value, self->priv->lines);
                        break;
+
                case PROP_XALIGN:
-                       g_value_set_float (value, priv->xalign);
+                       g_value_set_float (value, self->priv->xalign);
                        break;
+
+               case PROP_XPAD:
+                       g_value_set_int (value, self->priv->xpad);
+                       break;
+
                case PROP_YALIGN:
-                       g_value_set_float (value, priv->yalign);
+                       g_value_set_float (value, self->priv->yalign);
                        break;
+
+               case PROP_YPAD:
+                       g_value_set_int (value, self->priv->ypad);
+                       break;
+
                case PROP_VIEW:
-                       g_value_set_object (value, priv->view);
+                       g_value_set_object (value, self->priv->view);
                        break;
+
                case PROP_ALIGNMENT_MODE:
-                       g_value_set_enum (value, priv->alignment_mode);
-                       break;
-               case PROP_WINDOW_TYPE:
-                       g_value_set_enum (value, priv->window_type);
-                       break;
-               case PROP_SIZE:
-                       g_value_set_int (value, priv->size);
-                       break;
-               case PROP_BACKGROUND_RGBA:
-                       g_value_set_boxed (value, &priv->background_color);
-                       break;
-               case PROP_BACKGROUND_SET:
-                       g_value_set_boolean (value, priv->background_set);
+                       g_value_set_enum (value, self->priv->alignment_mode);
                        break;
+
                default:
                        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
                        break;
        }
 }
 
-static void
-renderer_draw_impl (GtkSourceGutterRenderer      *renderer,
-                    cairo_t                      *cr,
-                    GdkRectangle                 *background_area,
-                    GdkRectangle                 *cell_area,
-                    GtkTextIter                  *start,
-                    GtkTextIter                  *end,
-                    GtkSourceGutterRendererState  state)
-{
-       GtkSourceGutterRendererPrivate *priv = gtk_source_gutter_renderer_get_instance_private (renderer);
-
-       if (priv->background_set)
-       {
-               cairo_save (cr);
-               gdk_cairo_rectangle (cr, background_area);
-               gdk_cairo_set_source_rgba (cr, &priv->background_color);
-               cairo_fill (cr);
-               cairo_restore (cr);
-       }
-       else if ((state & GTK_SOURCE_GUTTER_RENDERER_STATE_CURSOR) != 0 &&
-                GTK_SOURCE_IS_VIEW (priv->view) &&
-                gtk_source_view_get_highlight_current_line (GTK_SOURCE_VIEW (priv->view)))
-       {
-               GtkStyleContext *context;
-
-               context = gtk_widget_get_style_context (GTK_WIDGET (priv->view));
-
-               gtk_style_context_save (context);
-               gtk_style_context_add_class (context, "current-line-number");
-
-               gtk_render_background (context,
-                                      cr,
-                                      background_area->x,
-                                      background_area->y,
-                                      background_area->width,
-                                      background_area->height);
-
-               gtk_style_context_restore (context);
-       }
-}
-
 static void
 gtk_source_gutter_renderer_class_init (GtkSourceGutterRendererClass *klass)
 {
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
+       GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
 
        object_class->dispose = gtk_source_gutter_renderer_dispose;
-
        object_class->get_property = gtk_source_gutter_renderer_get_property;
        object_class->set_property = gtk_source_gutter_renderer_set_property;
 
-       klass->draw = renderer_draw_impl;
-       klass->change_view = renderer_change_view_impl;
+       widget_class->root = gtk_source_gutter_renderer_root;
+       widget_class->unroot = gtk_source_gutter_renderer_unroot;
+       widget_class->snapshot = gtk_source_gutter_renderer_snapshot;
+
+       klass->begin = gtk_source_gutter_renderer_real_begin;
+       klass->end = gtk_source_gutter_renderer_real_end;
+  klass->change_buffer = gtk_source_gutter_renderer_change_buffer;
+       klass->change_view = gtk_source_gutter_renderer_change_view;
+       klass->query_data = gtk_source_gutter_renderer_query_data;
 
        /**
-        * GtkSourceGutterRenderer:visible:
+        * GtkSourceGutterRenderer:lines:
         *
-        * The visibility of the renderer.
-        *
-        **/
-       g_object_class_install_property (object_class,
-                                        PROP_VISIBLE,
-                                        g_param_spec_boolean ("visible",
-                                                              "Visible",
-                                                              "Visible",
-                                                              TRUE,
-                                                              G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+        * The "lines" property contains information about the lines to be
+        * rendered. It should be used by #GtkSourceGutterRenderer
+        * implementations from gtk_widget_snapshot().
+        */
+       properties[PROP_LINES] =
+               g_param_spec_object ("lines",
+                                    "Lines",
+                                    "Information about the lines to render",
+                                    GTK_SOURCE_TYPE_LINES,
+                                    G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
 
        /**
         * GtkSourceGutterRenderer:xpad:
         *
         * The left and right padding of the renderer.
         */
-       g_object_class_install_property (object_class,
-                                        PROP_XPAD,
-                                        g_param_spec_int ("xpad",
-                                                          "X Padding",
-                                                          "The x-padding",
-                                                          -1,
-                                                          G_MAXINT,
-                                                          0,
-                                                          G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+       properties[PROP_XPAD] =
+               g_param_spec_int ("xpad",
+                                 "X Padding",
+                                 "The x-padding",
+                                 0,
+                                 G_MAXINT,
+                                 0,
+                                 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
 
        /**
         * GtkSourceGutterRenderer:ypad:
         *
         * The top and bottom padding of the renderer.
         */
-       g_object_class_install_property (object_class,
-                                        PROP_YPAD,
-                                        g_param_spec_int ("ypad",
-                                                          "Y Padding",
-                                                          "The y-padding",
-                                                          -1,
-                                                          G_MAXINT,
-                                                          0,
-                                                          G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+       properties[PROP_YPAD] =
+               g_param_spec_int ("ypad",
+                                 "Y Padding",
+                                 "The y-padding",
+                                 0,
+                                 G_MAXINT,
+                                 0,
+                                 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
 
        /**
         * GtkSourceGutterRenderer:xalign:
@@ -597,15 +412,14 @@ gtk_source_gutter_renderer_class_init (GtkSourceGutterRendererClass *klass)
         * alignment. 1 for a right alignment. And 0.5 for centering the cells.
         * A value lower than 0 doesn't modify the alignment.
         */
-       g_object_class_install_property (object_class,
-                                        PROP_XALIGN,
-                                        g_param_spec_float ("xalign",
-                                                            "X Alignment",
-                                                            "The x-alignment",
-                                                            -1,
-                                                            1,
-                                                            0,
-                                                            G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+       properties[PROP_XALIGN] =
+               g_param_spec_float ("xalign",
+                                   "X Alignment",
+                                   "The x-alignment",
+                                   0.0,
+                                   1.0,
+                                   0.0,
+                                   G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
 
        /**
         * GtkSourceGutterRenderer:yalign:
@@ -614,15 +428,46 @@ gtk_source_gutter_renderer_class_init (GtkSourceGutterRendererClass *klass)
         * alignment. 1 for a bottom alignment. And 0.5 for centering the cells.
         * A value lower than 0 doesn't modify the alignment.
         */
-       g_object_class_install_property (object_class,
-                                        PROP_YALIGN,
-                                        g_param_spec_float ("yalign",
-                                                            "Y Alignment",
-                                                            "The y-alignment",
-                                                            -1,
-                                                            1,
-                                                            0,
-                                                            G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+       properties[PROP_YALIGN] =
+               g_param_spec_float ("yalign",
+                                   "Y Alignment",
+                                   "The y-alignment",
+                                   0.0,
+                                   1.0,
+                                   0.0,
+                                   G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+
+
+       /**
+        * GtkSourceGutterRenderer:view:
+        *
+        * The view on which the renderer is placed.
+        **/
+       properties[PROP_VIEW] =
+               g_param_spec_object ("view",
+                                    "The View",
+                                    "The view",
+                                    GTK_TYPE_TEXT_VIEW,
+                                    G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
+
+       /**
+        * GtkSourceGutterRenderer:alignment-mode:
+        *
+        * The alignment mode of the renderer. This can be used to indicate
+        * that in the case a cell spans multiple lines (due to text wrapping)
+        * the alignment should work on either the full cell, the first line
+        * or the last line.
+        *
+        **/
+       properties[PROP_ALIGNMENT_MODE] =
+               g_param_spec_enum ("alignment-mode",
+                                  "Alignment Mode",
+                                  "The alignment mode",
+                                  GTK_SOURCE_TYPE_GUTTER_RENDERER_ALIGNMENT_MODE,
+                                  GTK_SOURCE_GUTTER_RENDERER_ALIGNMENT_MODE_CELL,
+                                  G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+
+       g_object_class_install_properties (object_class, N_PROPS, properties);
 
        /**
         * GtkSourceGutterRenderer::activate:
@@ -633,105 +478,22 @@ gtk_source_gutter_renderer_class_init (GtkSourceGutterRendererClass *klass)
         *
         * The ::activate signal is emitted when the renderer is
         * activated.
-        *
         */
        signals[ACTIVATE] =
                g_signal_new ("activate",
-                             G_TYPE_FROM_CLASS (object_class),
+                             G_TYPE_FROM_CLASS (klass),
                              G_SIGNAL_RUN_LAST,
                              G_STRUCT_OFFSET (GtkSourceGutterRendererClass, activate),
                              NULL, NULL,
-                             _gtk_source_marshal_VOID__BOXED_BOXED_BOXED,
+                             _gtk_source_marshal_VOID__BOXED_BOXED_OBJECT,
                              G_TYPE_NONE,
                              3,
-                             GTK_TYPE_TEXT_ITER,
-                             GDK_TYPE_RECTANGLE,
+                             GTK_TYPE_TEXT_ITER | G_SIGNAL_TYPE_STATIC_SCOPE,
+                             GDK_TYPE_RECTANGLE | G_SIGNAL_TYPE_STATIC_SCOPE,
                              GDK_TYPE_EVENT);
        g_signal_set_va_marshaller (signals[ACTIVATE],
                                    G_TYPE_FROM_CLASS (klass),
-                                   _gtk_source_marshal_VOID__BOXED_BOXED_BOXEDv);
-
-       /**
-        * GtkSourceGutterRenderer::queue-draw:
-        * @renderer: the #GtkSourceGutterRenderer who emits the signal
-        *
-        * The ::queue-draw signal is emitted when the renderer needs
-        * to be redrawn. Use gtk_source_gutter_renderer_queue_draw()
-        * to emit this signal from an implementation of the
-        * #GtkSourceGutterRenderer interface.
-        */
-       signals[QUEUE_DRAW] =
-               g_signal_new ("queue-draw",
-                             G_TYPE_FROM_CLASS (object_class),
-                             G_SIGNAL_RUN_LAST,
-                             G_STRUCT_OFFSET (GtkSourceGutterRendererClass, queue_draw),
-                             NULL, NULL,
-                             g_cclosure_marshal_VOID__VOID,
-                             G_TYPE_NONE, 0);
-       g_signal_set_va_marshaller (signals[QUEUE_DRAW],
-                                   G_TYPE_FROM_CLASS (klass),
-                                   g_cclosure_marshal_VOID__VOIDv);
-
-       /**
-        * GtkSourceGutterRenderer::query-tooltip:
-        * @renderer: the #GtkSourceGutterRenderer who emits the signal
-        * @iter: a #GtkTextIter
-        * @area: a #GdkRectangle
-        * @x: the x position (in window coordinates)
-        * @y: the y position (in window coordinates)
-        * @tooltip: a #GtkTooltip
-        *
-        * The ::query-tooltip signal is emitted when the renderer can
-        * show a tooltip.
-        *
-        */
-       signals[QUERY_TOOLTIP] =
-               g_signal_new ("query-tooltip",
-                             G_TYPE_FROM_CLASS (object_class),
-                             G_SIGNAL_RUN_LAST,
-                             G_STRUCT_OFFSET (GtkSourceGutterRendererClass, query_tooltip),
-                             g_signal_accumulator_true_handled,
-                             NULL,
-                             _gtk_source_marshal_BOOLEAN__BOXED_BOXED_INT_INT_OBJECT,
-                             G_TYPE_BOOLEAN,
-                             5,
-                             GTK_TYPE_TEXT_ITER,
-                             GDK_TYPE_RECTANGLE,
-                             G_TYPE_INT,
-                             G_TYPE_INT,
-                             GTK_TYPE_TOOLTIP);
-       g_signal_set_va_marshaller (signals[QUERY_TOOLTIP],
-                                   G_TYPE_FROM_CLASS (klass),
-                                   _gtk_source_marshal_BOOLEAN__BOXED_BOXED_INT_INT_OBJECTv);
-
-       /**
-        * GtkSourceGutterRenderer::query-data:
-        * @renderer: the #GtkSourceGutterRenderer who emits the signal
-        * @start: a #GtkTextIter
-        * @end: a #GtkTextIter
-        * @state: the renderer state
-        *
-        * The ::query-data signal is emitted when the renderer needs
-        * to be filled with data just before a cell is drawn. This can
-        * be used by general renderer implementations to allow render
-        * data to be filled in externally.
-        *
-        */
-       signals[QUERY_DATA] =
-               g_signal_new ("query-data",
-                             G_TYPE_FROM_CLASS (object_class),
-                             G_SIGNAL_RUN_LAST,
-                             G_STRUCT_OFFSET (GtkSourceGutterRendererClass, query_data),
-                             NULL, NULL,
-                             _gtk_source_marshal_VOID__BOXED_BOXED_FLAGS,
-                             G_TYPE_NONE,
-                             3,
-                             GTK_TYPE_TEXT_ITER,
-                             GTK_TYPE_TEXT_ITER,
-                             GTK_SOURCE_TYPE_GUTTER_RENDERER_STATE);
-       g_signal_set_va_marshaller (signals[QUERY_DATA],
-                                   G_TYPE_FROM_CLASS (klass),
-                                   _gtk_source_marshal_VOID__BOXED_BOXED_FLAGSv);
+                                   _gtk_source_marshal_VOID__BOXED_BOXED_OBJECTv);
 
        /**
         * GtkSourceGutterRenderer::query-activatable:
@@ -742,214 +504,46 @@ gtk_source_gutter_renderer_class_init (GtkSourceGutterRendererClass *klass)
         *
         * The ::query-activatable signal is emitted when the renderer
         * can possibly be activated.
-        *
         */
        signals[QUERY_ACTIVATABLE] =
                g_signal_new ("query-activatable",
-                             G_TYPE_FROM_CLASS (object_class),
+                             G_TYPE_FROM_CLASS (klass),
                              G_SIGNAL_RUN_LAST,
                              G_STRUCT_OFFSET (GtkSourceGutterRendererClass, query_activatable),
                              g_signal_accumulator_true_handled,
                              NULL,
-                             _gtk_source_marshal_BOOLEAN__BOXED_BOXED_BOXED,
+                             _gtk_source_marshal_BOOLEAN__BOXED_BOXED_OBJECT,
                              G_TYPE_BOOLEAN,
                              3,
-                             GTK_TYPE_TEXT_ITER,
-                             GDK_TYPE_RECTANGLE,
+                             GTK_TYPE_TEXT_ITER | G_SIGNAL_TYPE_STATIC_SCOPE,
+                             GDK_TYPE_RECTANGLE | G_SIGNAL_TYPE_STATIC_SCOPE,
                              GDK_TYPE_EVENT);
        g_signal_set_va_marshaller (signals[QUERY_ACTIVATABLE],
                                    G_TYPE_FROM_CLASS (klass),
-                                   _gtk_source_marshal_BOOLEAN__BOXED_BOXED_BOXEDv);
-
-       /**
-        * GtkSourceGutterRenderer:view:
-        *
-        * The view on which the renderer is placed.
-        *
-        **/
-       g_object_class_install_property (object_class,
-                                        PROP_VIEW,
-                                        g_param_spec_object ("view",
-                                                             "The View",
-                                                             "The view",
-                                                             GTK_TYPE_TEXT_VIEW,
-                                                             G_PARAM_READABLE));
+                                   _gtk_source_marshal_BOOLEAN__BOXED_BOXED_OBJECTv);
 
-       /**
-        * GtkSourceGutterRenderer:alignment-mode:
-        *
-        * The alignment mode of the renderer. This can be used to indicate
-        * that in the case a cell spans multiple lines (due to text wrapping)
-        * the alignment should work on either the full cell, the first line
-        * or the last line.
-        *
-        **/
-       g_object_class_install_property (object_class,
-                                        PROP_ALIGNMENT_MODE,
-                                        g_param_spec_enum ("alignment-mode",
-                                                           "Alignment Mode",
-                                                           "The alignment mode",
-                                                           GTK_SOURCE_TYPE_GUTTER_RENDERER_ALIGNMENT_MODE,
-                                                           GTK_SOURCE_GUTTER_RENDERER_ALIGNMENT_MODE_CELL,
-                                                           G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+       signals[QUERY_DATA] =
+               g_signal_new ("query-data",
+                             G_TYPE_FROM_CLASS (klass),
+                             G_SIGNAL_RUN_LAST,
+                             0,
+                             NULL, NULL,
+                             _gtk_source_marshal_VOID__OBJECT_UINT,
+                             G_TYPE_NONE,
+                             2,
+                             G_TYPE_OBJECT,
+                             G_TYPE_UINT);
+       g_signal_set_va_marshaller (signals[QUERY_DATA],
+                                   G_TYPE_FROM_CLASS (klass),
+                                   _gtk_source_marshal_VOID__OBJECT_UINTv);
 
-       /**
-        * GtkSourceGutterRenderer:window-type:
-        *
-        * The window type of the view on which the renderer is placed (left,
-        * or right).
-        *
-        **/
-       g_object_class_install_property (object_class,
-                                        PROP_WINDOW_TYPE,
-                                        g_param_spec_enum ("window-type",
-                                                           "Window Type",
-                                                           "The window type",
-                                                           GTK_TYPE_TEXT_WINDOW_TYPE,
-                                                           GTK_TEXT_WINDOW_PRIVATE,
-                                                           G_PARAM_READABLE));
-
-       g_object_class_install_property (object_class,
-                                        PROP_SIZE,
-                                        g_param_spec_int ("size",
-                                                          "Size",
-                                                          "The size",
-                                                          0,
-                                                          G_MAXINT,
-                                                          0,
-                                                          G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
-
-       g_object_class_install_property (object_class,
-                                        PROP_BACKGROUND_RGBA,
-                                        g_param_spec_boxed ("background-rgba",
-                                                            "Background Color",
-                                                            "The background color",
-                                                            GDK_TYPE_RGBA,
-                                                            G_PARAM_READWRITE));
-
-       g_object_class_install_property (object_class,
-                                        PROP_BACKGROUND_SET,
-                                        g_param_spec_boolean ("background-set",
-                                                              "Background Set",
-                                                              "Whether the background color is set",
-                                                              FALSE,
-                                                              G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+  gtk_widget_class_set_css_name (widget_class, "gutterrenderer");
 }
 
 static void
 gtk_source_gutter_renderer_init (GtkSourceGutterRenderer *self)
 {
-}
-
-/**
- * gtk_source_gutter_renderer_begin:
- * @renderer: a #GtkSourceGutterRenderer
- * @cr: a #cairo_t
- * @background_area: a #GdkRectangle
- * @cell_area: a #GdkRectangle
- * @start: a #GtkTextIter
- * @end: a #GtkTextIter
- *
- * Called when drawing a region begins. The region to be drawn is indicated
- * by @start and @end. The purpose is to allow the implementation to precompute
- * some state before the draw method is called for each cell.
- */
-void
-gtk_source_gutter_renderer_begin (GtkSourceGutterRenderer *renderer,
-                                  cairo_t                 *cr,
-                                  GdkRectangle            *background_area,
-                                  GdkRectangle            *cell_area,
-                                  GtkTextIter             *start,
-                                  GtkTextIter             *end)
-{
-       g_return_if_fail (GTK_SOURCE_IS_GUTTER_RENDERER (renderer));
-       g_return_if_fail (cr != NULL);
-       g_return_if_fail (background_area != NULL);
-       g_return_if_fail (cell_area != NULL);
-       g_return_if_fail (start != NULL);
-       g_return_if_fail (end != NULL);
-
-       if (GTK_SOURCE_GUTTER_RENDERER_CLASS (G_OBJECT_GET_CLASS (renderer))->begin)
-       {
-               GTK_SOURCE_GUTTER_RENDERER_CLASS (
-                       G_OBJECT_GET_CLASS (renderer))->begin (renderer,
-                                                              cr,
-                                                              background_area,
-                                                              cell_area,
-                                                              start,
-                                                              end);
-       }
-}
-
-/**
- * gtk_source_gutter_renderer_draw:
- * @renderer: a #GtkSourceGutterRenderer
- * @cr: the cairo render context
- * @background_area: a #GdkRectangle indicating the total area to be drawn
- * @cell_area: a #GdkRectangle indicating the area to draw content
- * @start: a #GtkTextIter
- * @end: a #GtkTextIter
- * @state: a #GtkSourceGutterRendererState
- *
- * Main renderering method. Implementations should implement this method to draw
- * onto the cairo context. The @background_area indicates the total area of the
- * cell to be drawn. The @cell_area indicates the area where content can be
- * drawn (text, images, etc).
- *
- * The @background_area is the @cell_area plus the padding on each side (two
- * times the #GtkSourceGutterRenderer:xpad horizontally and two times the
- * #GtkSourceGutterRenderer:ypad vertically, so that the @cell_area is centered
- * inside @background_area).
- *
- * The @state argument indicates the current state of the renderer and should
- * be taken into account to properly draw the different possible states
- * (cursor, prelit, selected) if appropriate.
- */
-void
-gtk_source_gutter_renderer_draw (GtkSourceGutterRenderer      *renderer,
-                                 cairo_t                      *cr,
-                                 GdkRectangle                 *background_area,
-                                 GdkRectangle                 *cell_area,
-                                 GtkTextIter                  *start,
-                                 GtkTextIter                  *end,
-                                 GtkSourceGutterRendererState  state)
-{
-       g_return_if_fail (GTK_SOURCE_IS_GUTTER_RENDERER (renderer));
-       g_return_if_fail (cr != NULL);
-       g_return_if_fail (background_area != NULL);
-       g_return_if_fail (cell_area != NULL);
-       g_return_if_fail (start != NULL);
-       g_return_if_fail (end != NULL);
-
-       if (GTK_SOURCE_GUTTER_RENDERER_CLASS (G_OBJECT_GET_CLASS (renderer))->draw)
-       {
-               GTK_SOURCE_GUTTER_RENDERER_CLASS (
-                       G_OBJECT_GET_CLASS (renderer))->draw (renderer,
-                                                             cr,
-                                                             background_area,
-                                                             cell_area,
-                                                             start,
-                                                             end,
-                                                             state);
-       }
-}
-
-/**
- * gtk_source_gutter_renderer_end:
- * @renderer: a #GtkSourceGutterRenderer
- *
- * Called when drawing a region of lines has ended.
- *
- **/
-void
-gtk_source_gutter_renderer_end (GtkSourceGutterRenderer *renderer)
-{
-       g_return_if_fail (GTK_SOURCE_IS_GUTTER_RENDERER (renderer));
-
-       if (GTK_SOURCE_GUTTER_RENDERER_CLASS (G_OBJECT_GET_CLASS (renderer))->end)
-       {
-               GTK_SOURCE_GUTTER_RENDERER_CLASS (G_OBJECT_GET_CLASS (renderer))->end (renderer);
-       }
+       self->priv = gtk_source_gutter_renderer_get_instance_private (self);
 }
 
 /**
@@ -968,8 +562,8 @@ gtk_source_gutter_renderer_end (GtkSourceGutterRenderer *renderer)
  **/
 gboolean
 gtk_source_gutter_renderer_query_activatable (GtkSourceGutterRenderer *renderer,
-                                              GtkTextIter             *iter,
-                                              GdkRectangle            *area,
+                                              const GtkTextIter       *iter,
+                                              const GdkRectangle      *area,
                                               GdkEvent                *event)
 {
        gboolean ret;
@@ -1004,8 +598,8 @@ gtk_source_gutter_renderer_query_activatable (GtkSourceGutterRenderer *renderer,
  */
 void
 gtk_source_gutter_renderer_activate (GtkSourceGutterRenderer *renderer,
-                                     GtkTextIter             *iter,
-                                     GdkRectangle            *area,
+                                     const GtkTextIter       *iter,
+                                     const GdkRectangle      *area,
                                      GdkEvent                *event)
 {
        g_return_if_fail (GTK_SOURCE_IS_GUTTER_RENDERER (renderer));
@@ -1017,443 +611,373 @@ gtk_source_gutter_renderer_activate (GtkSourceGutterRenderer *renderer,
 }
 
 /**
- * gtk_source_gutter_renderer_queue_draw:
+ * gtk_source_gutter_renderer_set_alignment_mode:
  * @renderer: a #GtkSourceGutterRenderer
+ * @mode: a #GtkSourceGutterRendererAlignmentMode
  *
- * Emits the #GtkSourceGutterRenderer::queue-draw signal of the renderer. Call
- * this from an implementation to inform that the renderer has changed such that
- * it needs to redraw.
- */
-void
-gtk_source_gutter_renderer_queue_draw (GtkSourceGutterRenderer *renderer)
-{
-       g_return_if_fail (GTK_SOURCE_IS_GUTTER_RENDERER (renderer));
-
-       g_signal_emit (renderer, signals[QUEUE_DRAW], 0);
-}
-
-/**
- * gtk_source_gutter_renderer_query_tooltip:
- * @renderer: a #GtkSourceGutterRenderer.
- * @iter: a #GtkTextIter.
- * @area: a #GdkRectangle.
- * @x: The x position of the tooltip.
- * @y: The y position of the tooltip.
- * @tooltip: a #GtkTooltip.
- *
- * Emits the #GtkSourceGutterRenderer::query-tooltip signal. This function is
- * called from #GtkSourceGutter. Implementations can override the default signal
- * handler or can connect to the signal externally.
- *
- * Returns: %TRUE if the tooltip has been set, %FALSE otherwise
- */
-gboolean
-gtk_source_gutter_renderer_query_tooltip (GtkSourceGutterRenderer *renderer,
-                                          GtkTextIter             *iter,
-                                          GdkRectangle            *area,
-                                          gint                     x,
-                                          gint                     y,
-                                          GtkTooltip              *tooltip)
-{
-       gboolean ret;
-
-       g_return_val_if_fail (GTK_SOURCE_IS_GUTTER_RENDERER (renderer), FALSE);
-       g_return_val_if_fail (iter != NULL, FALSE);
-       g_return_val_if_fail (area != NULL, FALSE);
-       g_return_val_if_fail (GTK_IS_TOOLTIP (tooltip), FALSE);
-
-       ret = FALSE;
-
-       g_signal_emit (renderer,
-                      signals[QUERY_TOOLTIP],
-                      0,
-                      iter,
-                      area,
-                      x,
-                      y,
-                      tooltip,
-                      &ret);
-
-       return ret;
-}
-
-/**
- * gtk_source_gutter_renderer_query_data:
- * @renderer: a #GtkSourceGutterRenderer.
- * @start: a #GtkTextIter.
- * @end: a #GtkTextIter.
- * @state: a #GtkSourceGutterRendererState.
- *
- * Emit the #GtkSourceGutterRenderer::query-data signal. This function is called
- * to query for data just before rendering a cell. This is called from the
- * #GtkSourceGutter.  Implementations can override the default signal handler or
- * can connect a signal handler externally to the
- * #GtkSourceGutterRenderer::query-data signal.
- */
+ * Set the alignment mode. The alignment mode describes the manner in which the
+ * renderer is aligned (see #GtkSourceGutterRenderer:xalign and
+ * #GtkSourceGutterRenderer:yalign).
+ **/
 void
-gtk_source_gutter_renderer_query_data (GtkSourceGutterRenderer      *renderer,
-                                       GtkTextIter                  *start,
-                                       GtkTextIter                  *end,
-                                       GtkSourceGutterRendererState  state)
+gtk_source_gutter_renderer_set_alignment_mode (GtkSourceGutterRenderer              *renderer,
+                                               GtkSourceGutterRendererAlignmentMode  mode)
 {
-       g_return_if_fail (GTK_SOURCE_IS_GUTTER_RENDERER (renderer));
-       g_return_if_fail (start != NULL);
-       g_return_if_fail (end != NULL);
+       g_return_if_fail (GTK_SOURCE_GUTTER_RENDERER (renderer));
+       g_return_if_fail (mode == GTK_SOURCE_GUTTER_RENDERER_ALIGNMENT_MODE_CELL ||
+                         mode == GTK_SOURCE_GUTTER_RENDERER_ALIGNMENT_MODE_FIRST ||
+                         mode == GTK_SOURCE_GUTTER_RENDERER_ALIGNMENT_MODE_LAST);
 
-
-       /* Signal emission is relatively expensive and this code path is
-        * frequent enough to optimize the common case where we only have the
-        * override and no connected handlers.
-        *
-        * This is the same trick used by gtk_widget_draw().
-        */
-       if (G_UNLIKELY (g_signal_has_handler_pending (renderer, signals[QUERY_DATA], 0, FALSE)))
+       if (renderer->priv->alignment_mode != mode)
        {
-               g_signal_emit (renderer, signals[QUERY_DATA], 0, start, end, state);
-       }
-       else if (GTK_SOURCE_GUTTER_RENDERER_GET_CLASS (renderer)->query_data)
-       {
-               GTK_SOURCE_GUTTER_RENDERER_GET_CLASS (renderer)->query_data (renderer, start, end, state);
+               renderer->priv->alignment_mode = mode;
+               g_object_notify_by_pspec (G_OBJECT (renderer),
+                                         properties[PROP_ALIGNMENT_MODE]);
+               gtk_widget_queue_draw (GTK_WIDGET (renderer));
        }
 }
 
 /**
- * gtk_source_gutter_renderer_set_visible:
+ * gtk_source_gutter_renderer_get_alignment_mode:
  * @renderer: a #GtkSourceGutterRenderer
- * @visible: the visibility
  *
- * Set whether the gutter renderer is visible.
+ * Get the alignment mode. The alignment mode describes the manner in which the
+ * renderer is aligned (see :xalign and :yalign).
  *
+ * Returns: a #GtkSourceGutterRendererAlignmentMode
  **/
-void
-gtk_source_gutter_renderer_set_visible (GtkSourceGutterRenderer *renderer,
-                                        gboolean                 visible)
+GtkSourceGutterRendererAlignmentMode
+gtk_source_gutter_renderer_get_alignment_mode (GtkSourceGutterRenderer *renderer)
 {
-       g_return_if_fail (GTK_SOURCE_IS_GUTTER_RENDERER (renderer));
+       g_return_val_if_fail (GTK_SOURCE_IS_GUTTER_RENDERER (renderer), 0);
 
-       set_visible (renderer, visible);
+       return renderer->priv->alignment_mode;
 }
 
 /**
- * gtk_source_gutter_renderer_get_visible:
+ * gtk_source_gutter_renderer_get_view:
  * @renderer: a #GtkSourceGutterRenderer
  *
- * Get whether the gutter renderer is visible.
- *
- * Returns: %TRUE if the renderer is visible, %FALSE otherwise
+ * Get the view associated to the gutter renderer
  *
+ * Returns: (transfer none): a #GtkSourceView
  **/
-gboolean
-gtk_source_gutter_renderer_get_visible (GtkSourceGutterRenderer *renderer)
+GtkSourceView *
+gtk_source_gutter_renderer_get_view (GtkSourceGutterRenderer *renderer)
 {
-       GtkSourceGutterRendererPrivate *priv = gtk_source_gutter_renderer_get_instance_private (renderer);
-
-       g_return_val_if_fail (GTK_SOURCE_IS_GUTTER_RENDERER (renderer), FALSE);
+       g_return_val_if_fail (GTK_SOURCE_IS_GUTTER_RENDERER (renderer), NULL);
 
-       return priv->visible;
+       return GTK_SOURCE_VIEW (renderer->priv->view);
 }
 
-/**
- * gtk_source_gutter_renderer_set_padding:
- * @renderer: a #GtkSourceGutterRenderer
- * @xpad: the x-padding
- * @ypad: the y-padding
- *
- * Set the padding of the gutter renderer. Both @xpad and @ypad can be
- * -1, which means the values will not be changed (this allows changing only
- * one of the values).
- *
- * @xpad is the left and right padding. @ypad is the top and bottom padding.
- */
 void
-gtk_source_gutter_renderer_set_padding (GtkSourceGutterRenderer *renderer,
-                                        gint                     xpad,
-                                        gint                     ypad)
+_gtk_source_gutter_renderer_set_view (GtkSourceGutterRenderer *renderer,
+                                      GtkSourceView           *view)
 {
+       GtkSourceView *old_view;
+
        g_return_if_fail (GTK_SOURCE_IS_GUTTER_RENDERER (renderer));
+       g_return_if_fail (view == NULL || GTK_SOURCE_IS_VIEW (view));
+
+       if (view == renderer->priv->view)
+       {
+               return;
+       }
+
+       old_view = g_steal_pointer (&renderer->priv->view);
+       g_set_object (&renderer->priv->view, view);
+
+       GTK_SOURCE_GUTTER_RENDERER_GET_CLASS (renderer)->change_view (renderer, old_view);
 
-       set_xpad (renderer, xpad);
-       set_ypad (renderer, ypad);
+       g_clear_object (&old_view);
+
+       g_object_notify_by_pspec (G_OBJECT (renderer), properties[PROP_VIEW]);
 }
 
-/**
- * gtk_source_gutter_renderer_get_padding:
- * @renderer: a #GtkSourceGutterRenderer
- * @xpad: (out caller-allocates) (optional): return location for the x-padding,
- *   or %NULL to ignore.
- * @ypad: (out caller-allocates) (optional): return location for the y-padding,
- *   or %NULL to ignore.
- *
- * Get the x-padding and y-padding of the gutter renderer.
- */
-void
-gtk_source_gutter_renderer_get_padding (GtkSourceGutterRenderer *renderer,
-                                        gint                    *xpad,
-                                        gint                    *ypad)
+static void
+get_line_rect (GtkSourceGutterRenderer *renderer,
+               guint                    line,
+               GdkRectangle            *rect)
 {
-       GtkSourceGutterRendererPrivate *priv = gtk_source_gutter_renderer_get_instance_private (renderer);
+       GtkSourceLines *lines = NULL;
 
-       g_return_if_fail (GTK_SOURCE_IS_GUTTER_RENDERER (renderer));
-
-       if (xpad)
+       if (renderer->priv->gutter != NULL)
        {
-               *xpad = priv->xpad;
+               lines = _gtk_source_gutter_get_lines (renderer->priv->gutter);
        }
 
-       if (ypad)
+       if (lines != NULL)
        {
-               *ypad = priv->ypad;
+               gint y;
+               gint height;
+
+               gtk_source_lines_get_line_yrange (lines,
+                                                 line,
+                                                 renderer->priv->alignment_mode,
+                                                 &y,
+                                                 &height);
+
+               rect->x = renderer->priv->xpad;
+               rect->y = y + renderer->priv->ypad;
+               rect->width = gtk_widget_get_width (GTK_WIDGET (renderer));
+               rect->height = height;
+
+               rect->width -= 2 * renderer->priv->xpad;
+               rect->height -= 2 * renderer->priv->ypad;
+       }
+       else
+       {
+               rect->x = 0;
+               rect->y = 0;
+               rect->width = 0;
+               rect->height = 0;
        }
 }
 
 /**
- * gtk_source_gutter_renderer_set_alignment:
- * @renderer: a #GtkSourceGutterRenderer
- * @xalign: the x-alignment
- * @yalign: the y-alignment
+ * gtk_source_gutter_renderer_align_cell:
+ * @renderer: the #GtkSourceGutterRenderer
+ * @line: the line number for content
+ * @width: the width of the content to draw
+ * @height: the height of the content to draw
+ * @x: (out): the X position to render the content
+ * @y: (out): the Y position to render the content
+ *
+ * Locates where to render content that is @width x @height based on
+ * the renderers alignment and padding.
+ *
+ * The location will be placed into @x and @y and is relative to the
+ * renderer's coordinates.
  *
- * Set the alignment of the gutter renderer. Both @xalign and @yalign can be
- * -1, which means the values will not be changed (this allows changing only
- * one of the values).
+ * It is encouraged that renderers use this function when snappshotting
+ * to ensure consistent placement of their contents.
  *
- * @xalign is the horizontal alignment. Set to 0 for a left alignment. 1 for a
- * right alignment. And 0.5 for centering the cells. @yalign is the vertical
- * alignment. Set to 0 for a top alignment. 1 for a bottom alignment.
+ * Since: 5.0
  */
 void
-gtk_source_gutter_renderer_set_alignment (GtkSourceGutterRenderer *renderer,
-                                          gfloat                   xalign,
-                                          gfloat                   yalign)
+gtk_source_gutter_renderer_align_cell (GtkSourceGutterRenderer *renderer,
+                                       guint                    line,
+                                       gfloat                   width,
+                                       gfloat                   height,
+                                       gfloat                  *x,
+                                       gfloat                  *y)
 {
-       gboolean changed_x;
-       gboolean changed_y;
+       GdkRectangle rect;
 
        g_return_if_fail (GTK_SOURCE_IS_GUTTER_RENDERER (renderer));
 
-       changed_x = set_xalign (renderer, xalign, FALSE);
-       changed_y = set_yalign (renderer, yalign, FALSE);
+       get_line_rect (renderer, line, &rect);
 
-       if (changed_x || changed_y)
-       {
-               gtk_source_gutter_renderer_queue_draw (renderer);
-       }
+       *x = rect.x + (rect.width - width) * renderer->priv->xalign;
+       *y = rect.y + (rect.height - height) * renderer->priv->yalign;
 }
 
 /**
- * gtk_source_gutter_renderer_get_alignment:
+ * gtk_source_gutter_renderer_get_xpad:
  * @renderer: a #GtkSourceGutterRenderer
- * @xalign: (out caller-allocates) (optional): return location for the x-alignment,
- *   or %NULL to ignore.
- * @yalign: (out caller-allocates) (optional): return location for the y-alignment,
- *   or %NULL to ignore.
  *
- * Get the x-alignment and y-alignment of the gutter renderer.
+ * Gets the "xpad" property of the #GtkSourceGutterRenderer. This may be used
+ * to adjust the cell rectangle that the renderer will use to draw.
+ *
+ * Since: 5.0
  */
-void
-gtk_source_gutter_renderer_get_alignment (GtkSourceGutterRenderer *renderer,
-                                          gfloat                  *xalign,
-                                          gfloat                  *yalign)
+gint
+gtk_source_gutter_renderer_get_xpad (GtkSourceGutterRenderer *renderer)
 {
-       GtkSourceGutterRendererPrivate *priv = gtk_source_gutter_renderer_get_instance_private (renderer);
-
-       g_return_if_fail (GTK_SOURCE_IS_GUTTER_RENDERER (renderer));
-
-       if (xalign)
-       {
-               *xalign = priv->xalign;
-       }
+       g_return_val_if_fail (GTK_SOURCE_IS_GUTTER_RENDERER (renderer), 0);
 
-       if (yalign)
-       {
-               *yalign = priv->yalign;
-       }
+       return renderer->priv->xpad;
 }
 
 /**
- * gtk_source_gutter_renderer_set_alignment_mode:
+ * gtk_source_gutter_renderer_set_xpad:
  * @renderer: a #GtkSourceGutterRenderer
- * @mode: a #GtkSourceGutterRendererAlignmentMode
+ * @xpad: the Y padding for the drawing cell
  *
- * Set the alignment mode. The alignment mode describes the manner in which the
- * renderer is aligned (see :xalign and :yalign).
+ * Adjusts the "xpad" property of the #GtkSourceGutterRenderer. This may be
+ * used to adjust the cell rectangle that the renderer will use to draw.
  *
- **/
+ * Since: 5.0
+ */
 void
-gtk_source_gutter_renderer_set_alignment_mode (GtkSourceGutterRenderer              *renderer,
-                                               GtkSourceGutterRendererAlignmentMode  mode)
+gtk_source_gutter_renderer_set_xpad (GtkSourceGutterRenderer *renderer,
+                                     gint                     xpad)
 {
        g_return_if_fail (GTK_SOURCE_IS_GUTTER_RENDERER (renderer));
+       g_return_if_fail (xpad >= 0);
 
-       set_alignment_mode (renderer, mode);
+       if (renderer->priv->xpad != xpad)
+       {
+               renderer->priv->xpad = xpad;
+               g_object_notify_by_pspec (G_OBJECT (renderer),
+                                         properties[PROP_XPAD]);
+               gtk_widget_queue_draw (GTK_WIDGET (renderer));
+       }
 }
 
 /**
- * gtk_source_gutter_renderer_get_alignment_mode:
+ * gtk_source_gutter_renderer_get_ypad:
  * @renderer: a #GtkSourceGutterRenderer
  *
- * Get the alignment mode. The alignment mode describes the manner in which the
- * renderer is aligned (see :xalign and :yalign).
- *
- * Returns: a #GtkSourceGutterRendererAlignmentMode
+ * Gets the "ypad" property of the #GtkSourceGutterRenderer. This may be used
+ * to adjust the cell rectangle that the renderer will use to draw.
  *
- **/
-GtkSourceGutterRendererAlignmentMode
-gtk_source_gutter_renderer_get_alignment_mode (GtkSourceGutterRenderer *renderer)
+ * Since: 5.0
+ */
+gint
+gtk_source_gutter_renderer_get_ypad (GtkSourceGutterRenderer *renderer)
 {
-       GtkSourceGutterRendererPrivate *priv = gtk_source_gutter_renderer_get_instance_private (renderer);
-
        g_return_val_if_fail (GTK_SOURCE_IS_GUTTER_RENDERER (renderer), 0);
 
-       return priv->alignment_mode;
+       return renderer->priv->ypad;
 }
 
 /**
- * gtk_source_gutter_renderer_get_window_type:
+ * gtk_source_gutter_renderer_set_ypad:
  * @renderer: a #GtkSourceGutterRenderer
+ * @ypad: the Y padding for the drawing cell
  *
- * Get the #GtkTextWindowType associated with the gutter renderer.
- *
- * Returns: a #GtkTextWindowType
+ * Adjusts the "ypad" property of the #GtkSourceGutterRenderer. This may be
+ * used to adjust the cell rectangle that the renderer will use to draw.
  *
- **/
-GtkTextWindowType
-gtk_source_gutter_renderer_get_window_type (GtkSourceGutterRenderer *renderer)
+ * Since: 5.0
+ */
+void
+gtk_source_gutter_renderer_set_ypad (GtkSourceGutterRenderer *renderer,
+                                     gint                     ypad)
 {
-       GtkSourceGutterRendererPrivate *priv = gtk_source_gutter_renderer_get_instance_private (renderer);
-
-       g_return_val_if_fail (GTK_SOURCE_IS_GUTTER_RENDERER (renderer), GTK_TEXT_WINDOW_PRIVATE);
+       g_return_if_fail (GTK_SOURCE_IS_GUTTER_RENDERER (renderer));
+       g_return_if_fail (ypad >= 0);
 
-       return priv->window_type;
+       if (renderer->priv->ypad != ypad)
+       {
+               renderer->priv->ypad = ypad;
+               g_object_notify_by_pspec (G_OBJECT (renderer),
+                                         properties[PROP_YPAD]);
+               gtk_widget_queue_draw (GTK_WIDGET (renderer));
+       }
 }
 
 /**
- * gtk_source_gutter_renderer_get_view:
+ * gtk_source_gutter_renderer_get_xalign:
  * @renderer: a #GtkSourceGutterRenderer
  *
- * Get the view associated to the gutter renderer
- *
- * Returns: (transfer none): a #GtkTextView
+ * Gets the "xalign" property of the #GtkSourceGutterRenderer. This may be used
+ * to adjust where within the cell rectangle the renderer will draw.
  *
- **/
-GtkTextView *
-gtk_source_gutter_renderer_get_view (GtkSourceGutterRenderer *renderer)
+ * Since: 5.0
+ */
+gfloat
+gtk_source_gutter_renderer_get_xalign (GtkSourceGutterRenderer *renderer)
 {
-       GtkSourceGutterRendererPrivate *priv = gtk_source_gutter_renderer_get_instance_private (renderer);
-
-       g_return_val_if_fail (GTK_SOURCE_IS_GUTTER_RENDERER (renderer), NULL);
+       g_return_val_if_fail (GTK_SOURCE_IS_GUTTER_RENDERER (renderer), 0);
 
-       return priv->view;
+       return renderer->priv->xalign;
 }
 
 /**
- * gtk_source_gutter_renderer_get_size:
+ * gtk_source_gutter_renderer_set_xalign:
  * @renderer: a #GtkSourceGutterRenderer
+ * @xalign: the Y padding for the drawing cell
  *
- * Get the size of the renderer.
- *
- * Returns: the size of the renderer.
+ * Adjusts the "xalign" property of the #GtkSourceGutterRenderer. This may be
+ * used to adjust where within the cell rectangle the renderer will draw.
  *
- **/
-gint
-gtk_source_gutter_renderer_get_size (GtkSourceGutterRenderer *renderer)
+ * Since: 5.0
+ */
+void
+gtk_source_gutter_renderer_set_xalign (GtkSourceGutterRenderer *renderer,
+                                       gfloat                   xalign)
 {
-       GtkSourceGutterRendererPrivate *priv = gtk_source_gutter_renderer_get_instance_private (renderer);
-
-       g_return_val_if_fail (GTK_SOURCE_IS_GUTTER_RENDERER (renderer), 0);
+       g_return_if_fail (GTK_SOURCE_IS_GUTTER_RENDERER (renderer));
+       g_return_if_fail (xalign >= 0);
 
-       return priv->size;
+       if (renderer->priv->xalign != xalign)
+       {
+               renderer->priv->xalign = xalign;
+               g_object_notify_by_pspec (G_OBJECT (renderer),
+                                         properties[PROP_XALIGN]);
+               gtk_widget_queue_draw (GTK_WIDGET (renderer));
+       }
 }
 
 /**
- * gtk_source_gutter_renderer_set_size:
+ * gtk_source_gutter_renderer_get_yalign:
  * @renderer: a #GtkSourceGutterRenderer
- * @size: the size
  *
- * Sets the size of the renderer. A value of -1 specifies that the size
- * is to be determined dynamically.
+ * Gets the "yalign" property of the #GtkSourceGutterRenderer. This may be used
+ * to adjust where within the cell rectangle the renderer will draw.
  *
- **/
-void
-gtk_source_gutter_renderer_set_size (GtkSourceGutterRenderer *renderer,
-                                     gint                     size)
+ * Since: 5.0
+ */
+gfloat
+gtk_source_gutter_renderer_get_yalign (GtkSourceGutterRenderer *renderer)
 {
-       g_return_if_fail (GTK_SOURCE_IS_GUTTER_RENDERER (renderer));
+       g_return_val_if_fail (GTK_SOURCE_IS_GUTTER_RENDERER (renderer), 0);
 
-       set_size (renderer, size);
+       return renderer->priv->yalign;
 }
 
 /**
- * gtk_source_gutter_renderer_get_background:
+ * gtk_source_gutter_renderer_set_yalign:
  * @renderer: a #GtkSourceGutterRenderer
- * @color: (out caller-allocates) (optional): return value for a #GdkRGBA
+ * @yalign: the Y padding for the drawing cell
  *
- * Get the background color of the renderer.
+ * Adjusts the "yalign" property of the #GtkSourceGutterRenderer. This may be
+ * used to adjust where within the cell rectangle the renderer will draw.
  *
- * Returns: %TRUE if the background color is set, %FALSE otherwise
- *
- **/
-gboolean
-gtk_source_gutter_renderer_get_background (GtkSourceGutterRenderer *renderer,
-                                           GdkRGBA                 *color)
+ * Since: 5.0
+ */
+void
+gtk_source_gutter_renderer_set_yalign (GtkSourceGutterRenderer *renderer,
+                                       gfloat                   yalign)
 {
-       GtkSourceGutterRendererPrivate *priv = gtk_source_gutter_renderer_get_instance_private (renderer);
-
-       g_return_val_if_fail (GTK_SOURCE_IS_GUTTER_RENDERER (renderer), FALSE);
+       g_return_if_fail (GTK_SOURCE_IS_GUTTER_RENDERER (renderer));
+       g_return_if_fail (yalign >= 0);
 
-       if (color)
+       if (renderer->priv->yalign != yalign)
        {
-               *color = priv->background_color;
+               renderer->priv->yalign = yalign;
+               g_object_notify_by_pspec (G_OBJECT (renderer),
+                                         properties[PROP_YALIGN]);
+               gtk_widget_queue_draw (GTK_WIDGET (renderer));
        }
-
-       return priv->background_set;
 }
 
 /**
- * gtk_source_gutter_renderer_set_background:
+ * gtk_source_gutter_renderer_get_buffer:
  * @renderer: a #GtkSourceGutterRenderer
- * @color: (nullable): a #GdkRGBA or %NULL
  *
- * Set the background color of the renderer. If @color is set to %NULL, the
- * renderer will not have a background color.
+ * Gets the #GtkSourceBuffer for which the gutter renderer is drawing.
  *
+ * Returns: (transfer none) (nullable): a #GtkTextBuffer or %NULL
+ *
+ * Since: 5.0
  */
-void
-gtk_source_gutter_renderer_set_background (GtkSourceGutterRenderer *renderer,
-                                           const GdkRGBA           *color)
+GtkSourceBuffer *
+gtk_source_gutter_renderer_get_buffer (GtkSourceGutterRenderer *renderer)
 {
-       g_return_if_fail (GTK_SOURCE_IS_GUTTER_RENDERER (renderer));
+       g_return_val_if_fail (GTK_SOURCE_IS_GUTTER_RENDERER (renderer), NULL);
 
-       set_background_color (renderer, color);
+       return renderer->priv->buffer;
 }
 
 void
-_gtk_source_gutter_renderer_set_view (GtkSourceGutterRenderer *renderer,
-                                      GtkTextView             *view,
-                                      GtkTextWindowType        window_type)
+_gtk_source_gutter_renderer_begin (GtkSourceGutterRenderer *renderer,
+                                   GtkSourceLines          *lines)
 {
-       GtkSourceGutterRendererPrivate *priv = gtk_source_gutter_renderer_get_instance_private (renderer);
-
-       GtkTextView *old_view;
-
        g_return_if_fail (GTK_SOURCE_IS_GUTTER_RENDERER (renderer));
-       g_return_if_fail (view == NULL || GTK_IS_TEXT_VIEW (view));
+       g_return_if_fail (GTK_SOURCE_IS_LINES (lines));
 
-       old_view = priv->view;
-
-       priv->window_type = window_type;
-       priv->view = view != NULL ? g_object_ref (view) : NULL;
-
-       if (GTK_SOURCE_GUTTER_RENDERER_GET_CLASS (renderer)->change_view)
-       {
-               GTK_SOURCE_GUTTER_RENDERER_GET_CLASS (renderer)->change_view (renderer,
-                                                                             old_view);
-       }
+       g_set_object (&renderer->priv->lines, lines);
+       GTK_SOURCE_GUTTER_RENDERER_GET_CLASS (renderer)->begin (renderer, lines);
+}
 
-       if (old_view)
-       {
-               g_object_unref (old_view);
-       }
+void
+_gtk_source_gutter_renderer_end (GtkSourceGutterRenderer *renderer)
+{
+       g_return_if_fail (GTK_SOURCE_IS_GUTTER_RENDERER (renderer));
 
-       g_object_notify (G_OBJECT (renderer), "view");
-       g_object_notify (G_OBJECT (renderer), "window_type");
+       GTK_SOURCE_GUTTER_RENDERER_GET_CLASS (renderer)->end (renderer);
+       g_clear_object (&renderer->priv->lines);
 }
diff --git a/gtksourceview/gtksourcegutterrenderer.h b/gtksourceview/gtksourcegutterrenderer.h
index baa413d5..8b8468ff 100644
--- a/gtksourceview/gtksourcegutterrenderer.h
+++ b/gtksourceview/gtksourcegutterrenderer.h
@@ -2,7 +2,7 @@
  *
  * This file is part of GtkSourceView
  *
- * Copyright 2010 - Jesse van den Kieboom
+ * Copyright (C) 2010 - Jesse van den Kieboom
  *
  * GtkSourceView is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -18,7 +18,8 @@
  * along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#pragma once
+#ifndef GTK_SOURCE_GUTTER_RENDERER_H
+#define GTK_SOURCE_GUTTER_RENDERER_H
 
 #if !defined (GTK_SOURCE_H_INSIDE) && !defined (GTK_SOURCE_COMPILATION)
 #error "Only <gtksourceview/gtksource.h> can be included directly."
@@ -30,25 +31,16 @@
 
 G_BEGIN_DECLS
 
-#define GTK_SOURCE_TYPE_GUTTER_RENDERER (gtk_source_gutter_renderer_get_type())
+#define GTK_SOURCE_TYPE_GUTTER_RENDERER                        (gtk_source_gutter_renderer_get_type ())
+#define GTK_SOURCE_GUTTER_RENDERER(obj)                        (G_TYPE_CHECK_INSTANCE_CAST ((obj), 
GTK_SOURCE_TYPE_GUTTER_RENDERER, GtkSourceGutterRenderer))
+#define GTK_SOURCE_GUTTER_RENDERER_CONST(obj)          (G_TYPE_CHECK_INSTANCE_CAST ((obj), 
GTK_SOURCE_TYPE_GUTTER_RENDERER, GtkSourceGutterRenderer const))
+#define GTK_SOURCE_GUTTER_RENDERER_CLASS(klass)                (G_TYPE_CHECK_CLASS_CAST ((klass), 
GTK_SOURCE_TYPE_GUTTER_RENDERER, GtkSourceGutterRendererClass))
+#define GTK_SOURCE_IS_GUTTER_RENDERER(obj)             (G_TYPE_CHECK_INSTANCE_TYPE ((obj), 
GTK_SOURCE_TYPE_GUTTER_RENDERER))
+#define GTK_SOURCE_IS_GUTTER_RENDERER_CLASS(klass)     (G_TYPE_CHECK_CLASS_TYPE ((klass), 
GTK_SOURCE_TYPE_GUTTER_RENDERER))
+#define GTK_SOURCE_GUTTER_RENDERER_GET_CLASS(obj)      (G_TYPE_INSTANCE_GET_CLASS ((obj), 
GTK_SOURCE_TYPE_GUTTER_RENDERER, GtkSourceGutterRendererClass))
 
-/**
- * GtkSourceGutterRendererState:
- * @GTK_SOURCE_GUTTER_RENDERER_STATE_NORMAL: normal state
- * @GTK_SOURCE_GUTTER_RENDERER_STATE_CURSOR: area in the renderer represents the
- * line on which the insert cursor is currently positioned
- * @GTK_SOURCE_GUTTER_RENDERER_STATE_PRELIT: the mouse pointer is currently
- * over the activatable area of the renderer
- * @GTK_SOURCE_GUTTER_RENDERER_STATE_SELECTED: area in the renderer represents
- * a line in the buffer which contains part of the selection
- **/
-typedef enum _GtkSourceGutterRendererState
-{
-       GTK_SOURCE_GUTTER_RENDERER_STATE_NORMAL   = 0,
-       GTK_SOURCE_GUTTER_RENDERER_STATE_CURSOR   = 1 << 0,
-       GTK_SOURCE_GUTTER_RENDERER_STATE_PRELIT   = 1 << 1,
-       GTK_SOURCE_GUTTER_RENDERER_STATE_SELECTED = 1 << 2
-} GtkSourceGutterRendererState;
+typedef struct _GtkSourceGutterRendererClass   GtkSourceGutterRendererClass;
+typedef struct _GtkSourceGutterRendererPrivate GtkSourceGutterRendererPrivate;
 
 /**
  * GtkSourceGutterRendererAlignmentMode:
@@ -63,30 +55,32 @@ typedef enum _GtkSourceGutterRendererAlignmentMode
 {
        GTK_SOURCE_GUTTER_RENDERER_ALIGNMENT_MODE_CELL,
        GTK_SOURCE_GUTTER_RENDERER_ALIGNMENT_MODE_FIRST,
-       GTK_SOURCE_GUTTER_RENDERER_ALIGNMENT_MODE_LAST
+       GTK_SOURCE_GUTTER_RENDERER_ALIGNMENT_MODE_LAST,
 } GtkSourceGutterRendererAlignmentMode;
 
+struct _GtkSourceGutterRenderer
+{
+       GtkWidget parent;
+
+       /*< private >*/
+       GtkSourceGutterRendererPrivate *priv;
+};
+
 struct _GtkSourceGutterRendererClass
 {
-       GInitiallyUnownedClass parent_class;
-
-       /*< public >*/
-       void     (*begin)             (GtkSourceGutterRenderer     *renderer,
-                                      cairo_t                     *cr,
-                                      GdkRectangle                *background_area,
-                                      GdkRectangle                *cell_area,
-                                      GtkTextIter                 *start,
-                                      GtkTextIter                 *end);
-
-       void     (*draw)              (GtkSourceGutterRenderer      *renderer,
-                                      cairo_t                      *cr,
-                                      GdkRectangle                 *background_area,
-                                      GdkRectangle                 *cell_area,
-                                      GtkTextIter                  *start,
-                                      GtkTextIter                  *end,
-                                      GtkSourceGutterRendererState  state);
-
-       void     (*end)               (GtkSourceGutterRenderer      *renderer);
+       GtkWidgetClass parent_class;
+
+  void     (*query_data)            (GtkSourceGutterRenderer      *renderer,
+                                          GtkSourceLines               *lines,
+                                          guint                         line);
+
+       void     (*begin)                 (GtkSourceGutterRenderer      *renderer,
+                                          GtkSourceLines               *lines);
+       void     (*snapshot_line)         (GtkSourceGutterRenderer      *renderer,
+                                          GtkSnapshot                  *snapshot,
+                                          GtkSourceLines               *lines,
+                                          guint                         line);
+       void     (*end)                   (GtkSourceGutterRenderer      *renderer);
 
        /**
         * GtkSourceGutterRendererClass::change_view:
@@ -95,8 +89,8 @@ struct _GtkSourceGutterRendererClass
         *
         * This is called when the text view changes for @renderer.
         */
-       void     (*change_view)       (GtkSourceGutterRenderer      *renderer,
-                                      GtkTextView                  *old_view);
+       void     (*change_view)           (GtkSourceGutterRenderer      *renderer,
+                                          GtkSourceView                *old_view);
 
        /**
         * GtkSourceGutterRendererClass::change_buffer:
@@ -105,122 +99,73 @@ struct _GtkSourceGutterRendererClass
         *
         * This is called when the text buffer changes for @renderer.
         */
-       void     (*change_buffer)     (GtkSourceGutterRenderer      *renderer,
-                                      GtkTextBuffer                *old_buffer);
+       void     (*change_buffer)         (GtkSourceGutterRenderer      *renderer,
+                                          GtkSourceBuffer              *old_buffer);
 
        /* Signal handlers */
-       gboolean (*query_activatable) (GtkSourceGutterRenderer      *renderer,
-                                      GtkTextIter                  *iter,
-                                      GdkRectangle                 *area,
-                                      GdkEvent                     *event);
-
-       void     (*activate)          (GtkSourceGutterRenderer      *renderer,
-                                      GtkTextIter                  *iter,
-                                      GdkRectangle                 *area,
-                                      GdkEvent                     *event);
-
-       void     (*queue_draw)        (GtkSourceGutterRenderer      *renderer);
-
-       gboolean (*query_tooltip)     (GtkSourceGutterRenderer      *renderer,
-                                      GtkTextIter                  *iter,
-                                      GdkRectangle                 *area,
-                                      gint                          x,
-                                      gint                          y,
-                                      GtkTooltip                   *tooltip);
-
-       void     (*query_data)        (GtkSourceGutterRenderer      *renderer,
-                                      GtkTextIter                  *start,
-                                      GtkTextIter                  *end,
-                                      GtkSourceGutterRendererState  state);
+       gboolean (*query_activatable)     (GtkSourceGutterRenderer      *renderer,
+                                          GtkTextIter                  *iter,
+                                          GdkRectangle                 *area,
+                                          GdkEvent                     *event);
+       void     (*activate)              (GtkSourceGutterRenderer      *renderer,
+                                          GtkTextIter                  *iter,
+                                          GdkRectangle                 *area,
+                                          GdkEvent                     *event);
+
 
        /*< private >*/
        gpointer _reserved[20];
 };
 
 GTK_SOURCE_AVAILABLE_IN_ALL
-G_DECLARE_DERIVABLE_TYPE (GtkSourceGutterRenderer, gtk_source_gutter_renderer, GTK_SOURCE, GUTTER_RENDERER, 
GInitiallyUnowned)
-
-GTK_SOURCE_AVAILABLE_IN_ALL
-void                                  gtk_source_gutter_renderer_begin              (GtkSourceGutterRenderer 
             *renderer,
-                                                                                     cairo_t                 
             *cr,
-                                                                                     GdkRectangle            
             *background_area,
-                                                                                     GdkRectangle            
             *cell_area,
-                                                                                     GtkTextIter             
             *start,
-                                                                                     GtkTextIter             
             *end);
+GType                                 gtk_source_gutter_renderer_get_type           (void) G_GNUC_CONST;
 GTK_SOURCE_AVAILABLE_IN_ALL
-void                                  gtk_source_gutter_renderer_draw               (GtkSourceGutterRenderer 
             *renderer,
-                                                                                     cairo_t                 
             *cr,
-                                                                                     GdkRectangle            
             *background_area,
-                                                                                     GdkRectangle            
             *cell_area,
-                                                                                     GtkTextIter             
             *start,
-                                                                                     GtkTextIter             
             *end,
-                                                                                     
GtkSourceGutterRendererState          state);
+gfloat                                gtk_source_gutter_renderer_get_xalign         (GtkSourceGutterRenderer 
             *renderer);
 GTK_SOURCE_AVAILABLE_IN_ALL
-void                                  gtk_source_gutter_renderer_end                (GtkSourceGutterRenderer 
             *renderer);
+void                                  gtk_source_gutter_renderer_set_xalign         (GtkSourceGutterRenderer 
             *renderer,
+                                                                                     gfloat                  
              xalign);
 GTK_SOURCE_AVAILABLE_IN_ALL
-gint                                  gtk_source_gutter_renderer_get_size           (GtkSourceGutterRenderer 
             *renderer);
+gfloat                                gtk_source_gutter_renderer_get_yalign         (GtkSourceGutterRenderer 
             *renderer);
 GTK_SOURCE_AVAILABLE_IN_ALL
-void                                  gtk_source_gutter_renderer_set_size           (GtkSourceGutterRenderer 
             *renderer,
-                                                                                     gint                    
              size);
+void                                  gtk_source_gutter_renderer_set_yalign         (GtkSourceGutterRenderer 
             *renderer,
+                                                                                     gfloat                  
              yalign);
 GTK_SOURCE_AVAILABLE_IN_ALL
-void                                  gtk_source_gutter_renderer_set_visible        (GtkSourceGutterRenderer 
             *renderer,
-                                                                                     gboolean                
              visible);
+gint                                  gtk_source_gutter_renderer_get_xpad           (GtkSourceGutterRenderer 
             *renderer);
 GTK_SOURCE_AVAILABLE_IN_ALL
-gboolean                              gtk_source_gutter_renderer_get_visible        (GtkSourceGutterRenderer 
             *renderer);
+void                                  gtk_source_gutter_renderer_set_xpad           (GtkSourceGutterRenderer 
             *renderer,
+                                                                                     gint                    
              xpad);
 GTK_SOURCE_AVAILABLE_IN_ALL
-void                                  gtk_source_gutter_renderer_get_padding        (GtkSourceGutterRenderer 
             *renderer,
-                                                                                     gint                    
             *xpad,
-                                                                                     gint                    
             *ypad);
+gint                                  gtk_source_gutter_renderer_get_ypad           (GtkSourceGutterRenderer 
             *renderer);
 GTK_SOURCE_AVAILABLE_IN_ALL
-void                                  gtk_source_gutter_renderer_set_padding        (GtkSourceGutterRenderer 
             *renderer,
-                                                                                     gint                    
              xpad,
+void                                  gtk_source_gutter_renderer_set_ypad           (GtkSourceGutterRenderer 
             *renderer,
                                                                                      gint                    
              ypad);
 GTK_SOURCE_AVAILABLE_IN_ALL
-void                                  gtk_source_gutter_renderer_get_alignment      (GtkSourceGutterRenderer 
             *renderer,
-                                                                                     gfloat                  
             *xalign,
-                                                                                     gfloat                  
             *yalign);
-GTK_SOURCE_AVAILABLE_IN_ALL
-void                                  gtk_source_gutter_renderer_set_alignment      (GtkSourceGutterRenderer 
             *renderer,
-                                                                                     gfloat                  
              xalign,
-                                                                                     gfloat                  
              yalign);
+GtkSourceGutterRendererAlignmentMode  gtk_source_gutter_renderer_get_alignment_mode (GtkSourceGutterRenderer 
             *renderer);
 GTK_SOURCE_AVAILABLE_IN_ALL
 void                                  gtk_source_gutter_renderer_set_alignment_mode (GtkSourceGutterRenderer 
             *renderer,
                                                                                      
GtkSourceGutterRendererAlignmentMode  mode);
 GTK_SOURCE_AVAILABLE_IN_ALL
-GtkTextWindowType                     gtk_source_gutter_renderer_get_window_type    (GtkSourceGutterRenderer 
             *renderer);
-GTK_SOURCE_AVAILABLE_IN_ALL
-GtkTextView                          *gtk_source_gutter_renderer_get_view           (GtkSourceGutterRenderer 
             *renderer);
+GtkSourceBuffer                      *gtk_source_gutter_renderer_get_buffer         (GtkSourceGutterRenderer 
             *renderer);
 GTK_SOURCE_AVAILABLE_IN_ALL
-GtkSourceGutterRendererAlignmentMode  gtk_source_gutter_renderer_get_alignment_mode (GtkSourceGutterRenderer 
             *renderer);
-GTK_SOURCE_AVAILABLE_IN_ALL
-gboolean                              gtk_source_gutter_renderer_get_background     (GtkSourceGutterRenderer 
             *renderer,
-                                                                                     GdkRGBA                 
             *color);
-GTK_SOURCE_AVAILABLE_IN_ALL
-void                                  gtk_source_gutter_renderer_set_background     (GtkSourceGutterRenderer 
             *renderer,
-                                                                                     const GdkRGBA           
             *color);
+GtkSourceView                        *gtk_source_gutter_renderer_get_view           (GtkSourceGutterRenderer 
             *renderer);
 GTK_SOURCE_AVAILABLE_IN_ALL
 void                                  gtk_source_gutter_renderer_activate           (GtkSourceGutterRenderer 
             *renderer,
-                                                                                     GtkTextIter             
             *iter,
-                                                                                     GdkRectangle            
             *area,
+                                                                                     const GtkTextIter       
             *iter,
+                                                                                     const GdkRectangle      
             *area,
                                                                                      GdkEvent                
             *event);
 GTK_SOURCE_AVAILABLE_IN_ALL
 gboolean                              gtk_source_gutter_renderer_query_activatable  (GtkSourceGutterRenderer 
             *renderer,
-                                                                                     GtkTextIter             
             *iter,
-                                                                                     GdkRectangle            
             *area,
+                                                                                     const GtkTextIter       
             *iter,
+                                                                                     const GdkRectangle      
             *area,
                                                                                      GdkEvent                
             *event);
 GTK_SOURCE_AVAILABLE_IN_ALL
-void                                  gtk_source_gutter_renderer_queue_draw         (GtkSourceGutterRenderer 
             *renderer);
-GTK_SOURCE_AVAILABLE_IN_ALL
-gboolean                              gtk_source_gutter_renderer_query_tooltip      (GtkSourceGutterRenderer 
             *renderer,
-                                                                                     GtkTextIter             
             *iter,
-                                                                                     GdkRectangle            
             *area,
-                                                                                     gint                    
              x,
-                                                                                     gint                    
              y,
-                                                                                     GtkTooltip              
             *tooltip);
-GTK_SOURCE_AVAILABLE_IN_ALL
-void                                  gtk_source_gutter_renderer_query_data         (GtkSourceGutterRenderer 
             *renderer,
-                                                                                     GtkTextIter             
             *start,
-                                                                                     GtkTextIter             
             *end,
-                                                                                     
GtkSourceGutterRendererState          state);
+void                                  gtk_source_gutter_renderer_align_cell         (GtkSourceGutterRenderer 
             *renderer,
+                                                                                     guint                   
              line,
+                                                                                     gfloat                  
              width,
+                                                                                     gfloat                  
              height,
+                                                                                     gfloat                  
             *x,
+                                                                                     gfloat                  
             *y);
 
 G_END_DECLS
+
+#endif /* GTK_SOURCE_GUTTER_RENDERER_H */
diff --git a/gtksourceview/gtksourcegutterrendererlines.c b/gtksourceview/gtksourcegutterrendererlines.c
index 6f508ce1..a2fdf886 100644
--- a/gtksourceview/gtksourcegutterrendererlines.c
+++ b/gtksourceview/gtksourcegutterrendererlines.c
@@ -2,7 +2,7 @@
  *
  * This file is part of GtkSourceView
  *
- * Copyright 2010 - Jesse van den Kieboom
+ * Copyright (C) 2010 - Jesse van den Kieboom
  *
  * GtkSourceView is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -18,31 +18,23 @@
  * along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "config.h"
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
 
-#include "gtksourcegutterrendererlines-private.h"
+#include "gtksourcegutterrendererlines.h"
+#include "gtksourcelines.h"
 #include "gtksourceutils-private.h"
 #include "gtksourceview.h"
 
-struct _GtkSourceGutterRendererLines
+struct _GtkSourceGutterRendererLinesPrivate
 {
-       GtkSourceGutterRendererText parent_instance;
        gint num_line_digits;
        gint prev_line_num;
        guint cursor_visible : 1;
 };
 
-G_DEFINE_TYPE (GtkSourceGutterRendererLines, _gtk_source_gutter_renderer_lines, 
GTK_SOURCE_TYPE_GUTTER_RENDERER_TEXT)
-
-static GtkTextBuffer *
-get_buffer (GtkSourceGutterRendererLines *renderer)
-{
-       GtkTextView *view;
-
-       view = gtk_source_gutter_renderer_get_view (GTK_SOURCE_GUTTER_RENDERER (renderer));
-
-       return view != NULL ? gtk_text_view_get_buffer (view) : NULL;
-}
+G_DEFINE_TYPE_WITH_PRIVATE (GtkSourceGutterRendererLines, gtk_source_gutter_renderer_lines, 
GTK_SOURCE_TYPE_GUTTER_RENDERER_TEXT)
 
 static inline gint
 count_num_digits (gint num_lines)
@@ -76,33 +68,18 @@ count_num_digits (gint num_lines)
 static void
 recalculate_size (GtkSourceGutterRendererLines *renderer)
 {
+       GtkSourceBuffer *buffer;
        gint num_lines;
-       gint num_digits = 0;
-       GtkTextBuffer *buffer;
-
-       buffer = get_buffer (renderer);
-
-       num_lines = gtk_text_buffer_get_line_count (buffer);
+       gint num_digits;
 
+       buffer = gtk_source_gutter_renderer_get_buffer (GTK_SOURCE_GUTTER_RENDERER (renderer));
+       num_lines = gtk_text_buffer_get_line_count (GTK_TEXT_BUFFER (buffer));
        num_digits = count_num_digits (num_lines);
 
-       if (num_digits != renderer->num_line_digits)
+       if (num_digits != renderer->priv->num_line_digits)
        {
-               gchar markup[24];
-               gint size;
-
-               renderer->num_line_digits = num_digits;
-
-               num_lines = MAX (num_lines, 99);
-
-               g_snprintf (markup, sizeof markup, "<b>%d</b>", num_lines);
-               gtk_source_gutter_renderer_text_measure_markup (GTK_SOURCE_GUTTER_RENDERER_TEXT (renderer),
-                                                               markup,
-                                                               &size,
-                                                               NULL);
-
-               gtk_source_gutter_renderer_set_size (GTK_SOURCE_GUTTER_RENDERER (renderer),
-                                                    size);
+               renderer->priv->num_line_digits = num_digits;
+               gtk_widget_queue_resize (GTK_WIDGET (renderer));
        }
 }
 
@@ -113,21 +90,37 @@ on_buffer_changed (GtkSourceBuffer              *buffer,
        recalculate_size (renderer);
 }
 
+static void
+on_buffer_cursor_moved (GtkSourceBuffer              *buffer,
+                        GtkSourceGutterRendererLines *renderer)
+{
+       if (renderer->priv->cursor_visible)
+       {
+               /* Redraw if the current-line needs updating */
+               gtk_widget_queue_draw (GTK_WIDGET (renderer));
+       }
+}
+
 static void
 gutter_renderer_change_buffer (GtkSourceGutterRenderer *renderer,
-                               GtkTextBuffer           *old_buffer)
+                               GtkSourceBuffer         *old_buffer)
 {
        GtkSourceGutterRendererLines *lines = GTK_SOURCE_GUTTER_RENDERER_LINES (renderer);
-       GtkTextBuffer *buffer;
+       GtkSourceBuffer *buffer;
 
        if (old_buffer != NULL)
        {
                g_signal_handlers_disconnect_by_func (old_buffer,
                                                      on_buffer_changed,
                                                      lines);
+               g_signal_handlers_disconnect_by_func (old_buffer,
+                                                     on_buffer_cursor_moved,
+                                                     lines);
        }
 
-       buffer = get_buffer (lines);
+       buffer = gtk_source_gutter_renderer_get_buffer (renderer);
+
+       lines->priv->prev_line_num = 0;
 
        if (buffer != NULL)
        {
@@ -137,15 +130,17 @@ gutter_renderer_change_buffer (GtkSourceGutterRenderer *renderer,
                                         lines,
                                         0);
 
+               g_signal_connect_object (buffer,
+                                        "cursor-moved",
+                                        G_CALLBACK (on_buffer_cursor_moved),
+                                        lines,
+                                        0);
+
                recalculate_size (lines);
        }
 
-       lines->prev_line_num = 0;
-
-       if (GTK_SOURCE_GUTTER_RENDERER_CLASS (_gtk_source_gutter_renderer_lines_parent_class)->change_buffer 
!= NULL)
-       {
-               GTK_SOURCE_GUTTER_RENDERER_CLASS 
(_gtk_source_gutter_renderer_lines_parent_class)->change_buffer (renderer, old_buffer);
-       }
+       GTK_SOURCE_GUTTER_RENDERER_CLASS (gtk_source_gutter_renderer_lines_parent_class)->change_buffer 
(renderer,
+                                                                                                        
old_buffer);
 }
 
 static void
@@ -153,7 +148,7 @@ on_view_style_updated (GtkTextView                  *view,
                       GtkSourceGutterRendererLines *renderer)
 {
        /* Force to recalculate the size. */
-       renderer->num_line_digits = -1;
+       renderer->priv->num_line_digits = -1;
        recalculate_size (renderer);
 }
 
@@ -162,14 +157,14 @@ on_view_notify_cursor_visible (GtkTextView                  *view,
                                GParamSpec                   *pspec,
                                GtkSourceGutterRendererLines *renderer)
 {
-       renderer->cursor_visible = gtk_text_view_get_cursor_visible (view);
+       renderer->priv->cursor_visible = gtk_text_view_get_cursor_visible (view);
 }
 
 static void
 gutter_renderer_change_view (GtkSourceGutterRenderer *renderer,
-                            GtkTextView             *old_view)
+                            GtkSourceView             *old_view)
 {
-       GtkTextView *new_view;
+       GtkSourceView *new_view;
 
        if (old_view != NULL)
        {
@@ -197,116 +192,11 @@ gutter_renderer_change_view (GtkSourceGutterRenderer *renderer,
                                         renderer,
                                         0);
 
-               GTK_SOURCE_GUTTER_RENDERER_LINES (renderer)->cursor_visible = 
gtk_text_view_get_cursor_visible (new_view);
-       }
-
-       if (GTK_SOURCE_GUTTER_RENDERER_CLASS (_gtk_source_gutter_renderer_lines_parent_class)->change_view != 
NULL)
-       {
-               GTK_SOURCE_GUTTER_RENDERER_CLASS 
(_gtk_source_gutter_renderer_lines_parent_class)->change_view (renderer, old_view);
-       }
-}
-
-static void
-gutter_renderer_query_data (GtkSourceGutterRenderer      *renderer,
-                            GtkTextIter                  *start,
-                            GtkTextIter                  *end,
-                            GtkSourceGutterRendererState  state)
-{
-       GtkSourceGutterRendererLines *lines = GTK_SOURCE_GUTTER_RENDERER_LINES (renderer);
-       gchar text[24];
-       const gchar *textptr = text;
-       gint line;
-       gint len;
-       gboolean current_line;
-
-       line = gtk_text_iter_get_line (start) + 1;
-
-       current_line = (state & GTK_SOURCE_GUTTER_RENDERER_STATE_CURSOR) &&
-                      lines->cursor_visible;
-
-       if G_LIKELY (!current_line)
-       {
-               len = _gtk_source_utils_int_to_string (line, &textptr);
-       }
-       else
-       {
-               len = g_snprintf (text, sizeof text, "<b>%d</b>", line);
-       }
-
-       gtk_source_gutter_renderer_text_set_markup (GTK_SOURCE_GUTTER_RENDERER_TEXT (renderer),
-                                                   textptr,
-                                                   len);
-}
-
-static gint
-get_last_visible_line_number (GtkSourceGutterRendererLines *lines)
-{
-       GtkTextView *view;
-       GdkRectangle visible_rect;
-       GtkTextIter iter;
-
-       view = gtk_source_gutter_renderer_get_view (GTK_SOURCE_GUTTER_RENDERER (lines));
-
-       gtk_text_view_get_visible_rect (view, &visible_rect);
-
-       gtk_text_view_get_line_at_y (view,
-                                    &iter,
-                                    visible_rect.y + visible_rect.height,
-                                    NULL);
-
-       gtk_text_iter_forward_line (&iter);
-
-       return gtk_text_iter_get_line (&iter);
-}
-
-static void
-gutter_renderer_end (GtkSourceGutterRenderer *renderer)
-{
-       GtkSourceGutterRendererLines *lines = GTK_SOURCE_GUTTER_RENDERER_LINES (renderer);
-       GtkTextBuffer *buffer = get_buffer (lines);
-
-       if (buffer != NULL)
-       {
-               gint line_num = get_last_visible_line_number (lines);
-
-               /* When the text is modified in a GtkTextBuffer, GtkTextView tries to
-                * redraw the smallest required region. But the information displayed in
-                * the gutter may become invalid in a bigger region.
-                * See https://bugzilla.gnome.org/show_bug.cgi?id=732418 for an example
-                * where line numbers are not updated correctly when splitting a wrapped
-                * line.
-                * The performances should not be a big problem here. Correctness is
-                * more important than performances. It just triggers a second
-                * draw.
-                * The queue_draw() is called in gutter_renderer_end(), because
-                * the first draw is anyway needed to avoid flickering (if the
-                * first draw is not done, there will be a white region in the
-                * gutter during one frame).
-                * Another solution that has better performances is to compare
-                * the total number of lines in the buffer, instead of the last
-                * visible line. But it has the drawback that the gutter is
-                * continuously redrawn during file loading.
-                *
-                * FIXME A better solution would be to add a vfunc in the
-                * GutterRenderer so that the Gutter can ask each renderer for
-                * the invalidation region, before drawing. So that only one
-                * draw is needed, and the solution would be more generic (if
-                * other renderers also need a different invalidation region
-                * than the GtkTextView). But the GutterRendererClass doesn't
-                * have padding for future expansion, so it must wait for
-                * GtkSourceView 4.
-                */
-               if (lines->prev_line_num != line_num)
-               {
-                       lines->prev_line_num = line_num;
-                       gtk_source_gutter_renderer_queue_draw (renderer);
-               }
+               GTK_SOURCE_GUTTER_RENDERER_LINES (renderer)->priv->cursor_visible = 
gtk_text_view_get_cursor_visible (GTK_TEXT_VIEW (new_view));
        }
 
-       if (GTK_SOURCE_GUTTER_RENDERER_CLASS (_gtk_source_gutter_renderer_lines_parent_class)->end != NULL)
-       {
-               GTK_SOURCE_GUTTER_RENDERER_CLASS (_gtk_source_gutter_renderer_lines_parent_class)->end 
(renderer);
-       }
+       GTK_SOURCE_GUTTER_RENDERER_CLASS (gtk_source_gutter_renderer_lines_parent_class)->change_view 
(renderer,
+                                                                                                      
old_view);
 }
 
 static void
@@ -316,11 +206,11 @@ extend_selection_to_line (GtkSourceGutterRendererLines *renderer,
        GtkTextIter start;
        GtkTextIter end;
        GtkTextIter line_end;
-       GtkTextBuffer *buffer;
+       GtkSourceBuffer *buffer;
 
-       buffer = get_buffer (renderer);
+       buffer = gtk_source_gutter_renderer_get_buffer (GTK_SOURCE_GUTTER_RENDERER (renderer));
 
-       gtk_text_buffer_get_selection_bounds (buffer,
+       gtk_text_buffer_get_selection_bounds (GTK_TEXT_BUFFER (buffer),
                                              &start,
                                              &end);
 
@@ -333,7 +223,7 @@ extend_selection_to_line (GtkSourceGutterRendererLines *renderer,
 
        if (gtk_text_iter_compare (&start, line_start) < 0)
        {
-               gtk_text_buffer_select_range (buffer,
+               gtk_text_buffer_select_range (GTK_TEXT_BUFFER (buffer),
                                              &start,
                                              &line_end);
        }
@@ -341,13 +231,13 @@ extend_selection_to_line (GtkSourceGutterRendererLines *renderer,
        {
                /* if the selection is in this line, extend
                 * the selection to the whole line */
-               gtk_text_buffer_select_range (buffer,
+               gtk_text_buffer_select_range (GTK_TEXT_BUFFER (buffer),
                                              &line_end,
                                              line_start);
        }
        else
        {
-               gtk_text_buffer_select_range (buffer,
+               gtk_text_buffer_select_range (GTK_TEXT_BUFFER (buffer),
                                              &end,
                                              line_start);
        }
@@ -358,9 +248,9 @@ select_line (GtkSourceGutterRendererLines *renderer,
              GtkTextIter                  *line_start)
 {
        GtkTextIter iter;
-       GtkTextBuffer *buffer;
+       GtkSourceBuffer *buffer;
 
-       buffer = get_buffer (renderer);
+       buffer = gtk_source_gutter_renderer_get_buffer (GTK_SOURCE_GUTTER_RENDERER (renderer));
 
        iter = *line_start;
 
@@ -370,7 +260,7 @@ select_line (GtkSourceGutterRendererLines *renderer,
        }
 
        /* Select the line, put the cursor at the end of the line */
-       gtk_text_buffer_select_range (buffer, &iter, line_start);
+       gtk_text_buffer_select_range (GTK_TEXT_BUFFER (buffer), &iter, line_start);
 }
 
 static void
@@ -380,21 +270,35 @@ gutter_renderer_activate (GtkSourceGutterRenderer *renderer,
                           GdkEvent                *event)
 {
        GtkSourceGutterRendererLines *lines;
+       GdkModifierType state;
+       GdkEventType etype;
+       guint button;
 
        lines = GTK_SOURCE_GUTTER_RENDERER_LINES (renderer);
+       etype = gdk_event_get_event_type (event);
 
-       if (event->type == GDK_BUTTON_PRESS && (event->button.button == 1))
+       if (!gdk_event_get_button (event, &button))
        {
-               GtkTextBuffer *buffer;
+               return;
+       }
 
-               buffer = get_buffer (lines);
+       if (!gdk_event_get_state (event, &state))
+       {
+               state = 0;
+       }
+
+       if (etype == GDK_BUTTON_PRESS && button == 1)
+       {
+               GtkSourceBuffer *buffer;
 
-               if ((event->button.state & GDK_CONTROL_MASK) != 0)
+               buffer = gtk_source_gutter_renderer_get_buffer (renderer);
+
+               if ((state & GDK_CONTROL_MASK) != 0)
                {
                        /* Single click + Ctrl -> select the line */
                        select_line (lines, iter);
                }
-               else if ((event->button.state & GDK_SHIFT_MASK) != 0)
+               else if ((state & GDK_SHIFT_MASK) != 0)
                {
                        /* Single click + Shift -> extended current
                           selection to include the clicked line */
@@ -402,13 +306,18 @@ gutter_renderer_activate (GtkSourceGutterRenderer *renderer,
                }
                else
                {
-                       gtk_text_buffer_place_cursor (buffer, iter);
+                       gtk_text_buffer_place_cursor (GTK_TEXT_BUFFER (buffer), iter);
                }
        }
-       else if (event->type == GDK_2BUTTON_PRESS && (event->button.button == 1))
+#if 0
+       /* Requires porting to GtkWidget or drastically changing API,
+        * which is about the same as porting to widget.
+        */
+       else if (etype == GDK_2BUTTON_PRESS && button == 1)
        {
                select_line (lines, iter);
        }
+#endif
 }
 
 static gboolean
@@ -417,29 +326,98 @@ gutter_renderer_query_activatable (GtkSourceGutterRenderer *renderer,
                                    GdkRectangle            *area,
                                    GdkEvent                *event)
 {
-       return get_buffer (GTK_SOURCE_GUTTER_RENDERER_LINES (renderer)) != NULL;
+       return gtk_source_gutter_renderer_get_buffer (renderer) != NULL;
 }
 
 static void
-_gtk_source_gutter_renderer_lines_class_init (GtkSourceGutterRendererLinesClass *klass)
+gtk_source_gutter_renderer_lines_measure (GtkWidget      *widget,
+                                          GtkOrientation  orientation,
+                                          int             for_size,
+                                          int            *minimum,
+                                          int            *natural,
+                                          int            *minimum_baseline,
+                                          int            *natural_baseline)
+{
+       GtkSourceGutterRendererLines *renderer = GTK_SOURCE_GUTTER_RENDERER_LINES (widget);
+
+       if (orientation == GTK_ORIENTATION_VERTICAL)
+       {
+               *minimum = 0;
+               *natural = 0;
+       }
+       else
+       {
+               GtkSourceBuffer *buffer;
+               gchar markup[32];
+               guint num_lines;
+               gint size;
+               gint xpad;
+
+               buffer = gtk_source_gutter_renderer_get_buffer (GTK_SOURCE_GUTTER_RENDERER (renderer));
+               num_lines = MAX (99, gtk_text_buffer_get_line_count (GTK_TEXT_BUFFER (buffer)));
+
+               g_snprintf (markup, sizeof markup, "<b>%u</b>", num_lines);
+               gtk_source_gutter_renderer_text_measure_markup (GTK_SOURCE_GUTTER_RENDERER_TEXT (renderer),
+                                                               markup,
+                                                               &size,
+                                                               NULL);
+
+               xpad = gtk_source_gutter_renderer_get_xpad (GTK_SOURCE_GUTTER_RENDERER (renderer));
+
+               *natural = *minimum = size + xpad * 2;
+       }
+
+       *minimum_baseline = -1;
+       *natural_baseline = -1;
+}
+
+static void
+gtk_source_gutter_renderer_lines_query_data (GtkSourceGutterRenderer *renderer,
+                                             GtkSourceLines          *lines,
+                                             guint                    line)
+{
+       GtkSourceGutterRendererLines *self = GTK_SOURCE_GUTTER_RENDERER_LINES (renderer);
+       gint len;
+
+       if G_UNLIKELY (self->priv->cursor_visible && gtk_source_lines_is_cursor (lines, line))
+       {
+               gchar text[32];
+
+               len = g_snprintf (text, sizeof text, "<b>%d</b>", line + 1);
+               gtk_source_gutter_renderer_text_set_markup (GTK_SOURCE_GUTTER_RENDERER_TEXT (renderer), text, 
len);
+       }
+       else
+       {
+               const gchar *text;
+
+               len = _gtk_source_utils_int_to_string (line + 1, &text);
+               gtk_source_gutter_renderer_text_set_text (GTK_SOURCE_GUTTER_RENDERER_TEXT (renderer), text, 
len);
+       }
+}
+
+static void
+gtk_source_gutter_renderer_lines_class_init (GtkSourceGutterRendererLinesClass *klass)
 {
        GtkSourceGutterRendererClass *renderer_class = GTK_SOURCE_GUTTER_RENDERER_CLASS (klass);
+       GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+       widget_class->measure = gtk_source_gutter_renderer_lines_measure;
 
-       renderer_class->query_data = gutter_renderer_query_data;
-       renderer_class->end = gutter_renderer_end;
        renderer_class->query_activatable = gutter_renderer_query_activatable;
+       renderer_class->query_data = gtk_source_gutter_renderer_lines_query_data;
        renderer_class->activate = gutter_renderer_activate;
        renderer_class->change_buffer = gutter_renderer_change_buffer;
        renderer_class->change_view = gutter_renderer_change_view;
 }
 
 static void
-_gtk_source_gutter_renderer_lines_init (GtkSourceGutterRendererLines *self)
+gtk_source_gutter_renderer_lines_init (GtkSourceGutterRendererLines *self)
 {
+       self->priv = gtk_source_gutter_renderer_lines_get_instance_private (self);
 }
 
 GtkSourceGutterRenderer *
-_gtk_source_gutter_renderer_lines_new (void)
+gtk_source_gutter_renderer_lines_new (void)
 {
        return g_object_new (GTK_SOURCE_TYPE_GUTTER_RENDERER_LINES, NULL);
 }
diff --git a/gtksourceview/gtksourcegutterrendererlines.h b/gtksourceview/gtksourcegutterrendererlines.h
new file mode 100644
index 00000000..2fc8e22a
--- /dev/null
+++ b/gtksourceview/gtksourcegutterrendererlines.h
@@ -0,0 +1,68 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; coding: utf-8 -*-
+ *
+ * This file is part of GtkSourceView
+ *
+ * Copyright (C) 2010 - Jesse van den Kieboom
+ *
+ * GtkSourceView is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * GtkSourceView is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GTK_SOURCE_GUTTER_RENDERER_LINES_H
+#define GTK_SOURCE_GUTTER_RENDERER_LINES_H
+
+#include <gtk/gtk.h>
+#include "gtksourcetypes.h"
+#include "gtksourcetypes-private.h"
+#include "gtksourcegutterrenderertext.h"
+
+G_BEGIN_DECLS
+
+#define GTK_SOURCE_TYPE_GUTTER_RENDERER_LINES          (gtk_source_gutter_renderer_lines_get_type ())
+#define GTK_SOURCE_GUTTER_RENDERER_LINES(obj)          (G_TYPE_CHECK_INSTANCE_CAST ((obj), 
GTK_SOURCE_TYPE_GUTTER_RENDERER_LINES, GtkSourceGutterRendererLines))
+#define GTK_SOURCE_GUTTER_RENDERER_LINES_CONST(obj)    (G_TYPE_CHECK_INSTANCE_CAST ((obj), 
GTK_SOURCE_TYPE_GUTTER_RENDERER_LINES, GtkSourceGutterRendererLines const))
+#define GTK_SOURCE_GUTTER_RENDERER_LINES_CLASS(klass)  (G_TYPE_CHECK_CLASS_CAST ((klass), 
GTK_SOURCE_TYPE_GUTTER_RENDERER_LINES, GtkSourceGutterRendererLinesClass))
+#define GTK_SOURCE_IS_GUTTER_RENDERER_LINES(obj)               (G_TYPE_CHECK_INSTANCE_TYPE ((obj), 
GTK_SOURCE_TYPE_GUTTER_RENDERER_LINES))
+#define GTK_SOURCE_IS_GUTTER_RENDERER_LINES_CLASS(klass)       (G_TYPE_CHECK_CLASS_TYPE ((klass), 
GTK_SOURCE_TYPE_GUTTER_RENDERER_LINES))
+#define GTK_SOURCE_GUTTER_RENDERER_LINES_GET_CLASS(obj)        (G_TYPE_INSTANCE_GET_CLASS ((obj), 
GTK_SOURCE_TYPE_GUTTER_RENDERER_LINES, GtkSourceGutterRendererLinesClass))
+
+typedef struct _GtkSourceGutterRendererLinesClass      GtkSourceGutterRendererLinesClass;
+typedef struct _GtkSourceGutterRendererLinesPrivate    GtkSourceGutterRendererLinesPrivate;
+
+struct _GtkSourceGutterRendererLines
+{
+       /*< private >*/
+       GtkSourceGutterRendererText parent;
+
+       GtkSourceGutterRendererLinesPrivate *priv;
+
+       /*< public >*/
+};
+
+struct _GtkSourceGutterRendererLinesClass
+{
+       /*< private >*/
+       GtkSourceGutterRendererTextClass parent_class;
+
+       /*< public >*/
+};
+
+G_GNUC_INTERNAL
+GType gtk_source_gutter_renderer_lines_get_type (void) G_GNUC_CONST;
+
+G_GNUC_INTERNAL
+GtkSourceGutterRenderer *gtk_source_gutter_renderer_lines_new (void);
+
+G_END_DECLS
+
+#endif /* GTK_SOURCE_GUTTER_RENDERER_LINES_H */
diff --git a/gtksourceview/gtksourcegutterrenderermarks.c b/gtksourceview/gtksourcegutterrenderermarks.c
index 70f9d508..c5c59389 100644
--- a/gtksourceview/gtksourcegutterrenderermarks.c
+++ b/gtksourceview/gtksourcegutterrenderermarks.c
@@ -2,7 +2,7 @@
  *
  * This file is part of GtkSourceView
  *
- * Copyright 2010 - Jesse van den Kieboom
+ * Copyright (C) 2010 - Jesse van den Kieboom
  *
  * GtkSourceView is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -18,31 +18,28 @@
  * along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "config.h"
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
 
-#include "gtksourcegutterrenderermarks-private.h"
+#include "gtksourcegutterrenderermarks.h"
 #include "gtksourceview.h"
 #include "gtksourcebuffer.h"
 #include "gtksourcemarkattributes.h"
 #include "gtksourcemark.h"
 
-#define COMPOSITE_ALPHA 225
-
-struct _GtkSourceGutterRendererMarks
-{
-       GtkSourceGutterRendererPixbuf parent_instance;
-};
+#define COMPOSITE_ALPHA                 225
 
 G_DEFINE_TYPE (GtkSourceGutterRendererMarks, gtk_source_gutter_renderer_marks, 
GTK_SOURCE_TYPE_GUTTER_RENDERER_PIXBUF)
 
 static gint
 sort_marks_by_priority (gconstpointer m1,
-                        gconstpointer m2,
-                        gpointer      data)
+                       gconstpointer m2,
+                       gpointer data)
 {
-       GtkSourceMark *mark1 = (GtkSourceMark *)m1;
-       GtkSourceMark *mark2 = (GtkSourceMark *)m2;
-       GtkSourceView *view = data;
+       GtkSourceMark *mark1 = GTK_SOURCE_MARK (m1);
+       GtkSourceMark *mark2 = GTK_SOURCE_MARK (m2);
+       GtkSourceView *view = GTK_SOURCE_VIEW (data);
        GtkTextIter iter1, iter2;
        gint line1;
        gint line2;
@@ -170,22 +167,19 @@ composite_marks (GtkSourceView *view,
 
 static void
 gutter_renderer_query_data (GtkSourceGutterRenderer      *renderer,
-                            GtkTextIter                  *start,
-                            GtkTextIter                  *end,
-                            GtkSourceGutterRendererState  state)
+                            GtkSourceLines               *lines,
+                            guint                         line)
 {
-       GSList *marks;
-       GdkPixbuf *pixbuf = NULL;
-       gint size = 0;
        GtkSourceView *view;
        GtkSourceBuffer *buffer;
+       GdkPixbuf *pixbuf = NULL;
+       GSList *marks;
+       gint size = 0;
 
        view = GTK_SOURCE_VIEW (gtk_source_gutter_renderer_get_view (renderer));
        buffer = GTK_SOURCE_BUFFER (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)));
 
-       marks = gtk_source_buffer_get_source_marks_at_iter (buffer,
-                                                           start,
-                                                           NULL);
+       marks = gtk_source_buffer_get_source_marks_at_iter (buffer, start, NULL);
 
        if (marks != NULL)
        {
diff --git a/gtksourceview/gtksourcegutterrenderermarks.h b/gtksourceview/gtksourcegutterrenderermarks.h
new file mode 100644
index 00000000..e807f6c8
--- /dev/null
+++ b/gtksourceview/gtksourcegutterrenderermarks.h
@@ -0,0 +1,59 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; coding: utf-8 -*-
+ *
+ * This file is part of GtkSourceView
+ *
+ * Copyright (C) 2010 - Jesse van den Kieboom
+ *
+ * GtkSourceView is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * GtkSourceView is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GTK_SOURCE_GUTTER_RENDERER_MARKS_H
+#define GTK_SOURCE_GUTTER_RENDERER_MARKS_H
+
+#include <gtk/gtk.h>
+#include "gtksourcetypes.h"
+#include "gtksourcetypes-private.h"
+#include "gtksourcegutterrendererpixbuf.h"
+
+G_BEGIN_DECLS
+
+#define GTK_SOURCE_TYPE_GUTTER_RENDERER_MARKS          (gtk_source_gutter_renderer_marks_get_type ())
+#define GTK_SOURCE_GUTTER_RENDERER_MARKS(obj)          (G_TYPE_CHECK_INSTANCE_CAST ((obj), 
GTK_SOURCE_TYPE_GUTTER_RENDERER_MARKS, GtkSourceGutterRendererMarks))
+#define GTK_SOURCE_GUTTER_RENDERER_MARKS_CONST(obj)    (G_TYPE_CHECK_INSTANCE_CAST ((obj), 
GTK_SOURCE_TYPE_GUTTER_RENDERER_MARKS, GtkSourceGutterRendererMarks const))
+#define GTK_SOURCE_GUTTER_RENDERER_MARKS_CLASS(klass)  (G_TYPE_CHECK_CLASS_CAST ((klass), 
GTK_SOURCE_TYPE_GUTTER_RENDERER_MARKS, GtkSourceGutterRendererMarksClass))
+#define GTK_SOURCE_IS_GUTTER_RENDERER_MARKS(obj)       (G_TYPE_CHECK_INSTANCE_TYPE ((obj), 
GTK_SOURCE_TYPE_GUTTER_RENDERER_MARKS))
+#define GTK_SOURCE_IS_GUTTER_RENDERER_MARKS_CLASS(klass)(G_TYPE_CHECK_CLASS_TYPE ((klass), 
GTK_SOURCE_TYPE_GUTTER_RENDERER_MARKS))
+#define GTK_SOURCE_GUTTER_RENDERER_MARKS_GET_CLASS(obj)        (G_TYPE_INSTANCE_GET_CLASS ((obj), 
GTK_SOURCE_TYPE_GUTTER_RENDERER_MARKS, GtkSourceGutterRendererMarksClass))
+
+typedef struct _GtkSourceGutterRendererMarksClass      GtkSourceGutterRendererMarksClass;
+
+struct _GtkSourceGutterRendererMarks
+{
+       GtkSourceGutterRendererPixbuf parent;
+};
+
+struct _GtkSourceGutterRendererMarksClass
+{
+       GtkSourceGutterRendererPixbufClass parent_class;
+};
+
+G_GNUC_INTERNAL
+GType gtk_source_gutter_renderer_marks_get_type (void) G_GNUC_CONST;
+
+G_GNUC_INTERNAL
+GtkSourceGutterRenderer *gtk_source_gutter_renderer_marks_new (void);
+
+G_END_DECLS
+
+#endif /* GTK_SOURCE_GUTTER_RENDERER_MARKS_H */
diff --git a/gtksourceview/gtksourcegutterrendererpixbuf.c b/gtksourceview/gtksourcegutterrendererpixbuf.c
index 46026886..9c6374c4 100644
--- a/gtksourceview/gtksourcegutterrendererpixbuf.c
+++ b/gtksourceview/gtksourcegutterrendererpixbuf.c
@@ -2,7 +2,7 @@
  *
  * This file is part of GtkSourceView
  *
- * Copyright 2010 - Jesse van den Kieboom
+ * Copyright (C) 2010 - Jesse van den Kieboom
  *
  * GtkSourceView is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -18,7 +18,9 @@
  * along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "config.h"
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
 
 #include "gtksourcegutterrendererpixbuf.h"
 #include "gtksourcepixbufhelper-private.h"
@@ -33,10 +35,10 @@
  * #GtkSourceGutter.
  */
 
-typedef struct
+struct _GtkSourceGutterRendererPixbufPrivate
 {
        GtkSourcePixbufHelper *helper;
-} GtkSourceGutterRendererPixbufPrivate;
+};
 
 G_DEFINE_TYPE_WITH_PRIVATE (GtkSourceGutterRendererPixbuf, gtk_source_gutter_renderer_pixbuf, 
GTK_SOURCE_TYPE_GUTTER_RENDERER)
 
@@ -49,153 +51,50 @@ enum
 };
 
 static void
-center_on (GtkSourceGutterRenderer *renderer,
-           GdkRectangle            *cell_area,
-           GtkTextIter             *iter,
-           gint                     width,
-           gint                     height,
-           gfloat                   xalign,
-           gfloat                   yalign,
-           gint                    *x,
-           gint                    *y)
-{
-       GtkTextView *view;
-       GtkTextWindowType window_type;
-       GdkRectangle buffer_location;
-       gint window_y;
-
-       view = gtk_source_gutter_renderer_get_view (renderer);
-       window_type = gtk_source_gutter_renderer_get_window_type (renderer);
-
-       gtk_text_view_get_iter_location (view, iter, &buffer_location);
-
-       gtk_text_view_buffer_to_window_coords (view,
-                                              window_type,
-                                              0, buffer_location.y,
-                                              NULL, &window_y);
-
-       *x = cell_area->x + (cell_area->width - width) * xalign;
-       *y = window_y + (buffer_location.height - height) * yalign;
-}
-
-static void
-gutter_renderer_pixbuf_draw (GtkSourceGutterRenderer      *renderer,
-                             cairo_t                      *cr,
-                             GdkRectangle                 *background_area,
-                             GdkRectangle                 *cell_area,
-                             GtkTextIter                  *start,
-                             GtkTextIter                  *end,
-                             GtkSourceGutterRendererState  state)
+gutter_renderer_pixbuf_snapshot_line (GtkSourceGutterRenderer      *renderer,
+                                      GtkSnapshot                  *snapshot,
+                                      GtkSourceLines               *lines,
+                                      guint                         line)
 {
        GtkSourceGutterRendererPixbuf *pix = GTK_SOURCE_GUTTER_RENDERER_PIXBUF (renderer);
-       GtkSourceGutterRendererPixbufPrivate *priv = gtk_source_gutter_renderer_pixbuf_get_instance_private 
(pix);
+       GtkWidget *widget = GTK_WIDGET (renderer);
+       GdkPaintable *paintable;
+       GtkSourceView *view;
        gint width;
        gint height;
-       gfloat xalign;
-       gfloat yalign;
-       GtkSourceGutterRendererAlignmentMode mode;
-       GtkTextView *view;
-       gint scale;
-       gint x = 0;
-       gint y = 0;
-       GdkPixbuf *pixbuf;
-       cairo_surface_t *surface;
-
-       /* Chain up to draw background */
-       if (GTK_SOURCE_GUTTER_RENDERER_CLASS (gtk_source_gutter_renderer_pixbuf_parent_class)->draw != NULL)
-       {
-               GTK_SOURCE_GUTTER_RENDERER_CLASS (gtk_source_gutter_renderer_pixbuf_parent_class)->draw 
(renderer,
-                                                                                                        cr,
-                                                                                                        
background_area,
-                                                                                                        
cell_area,
-                                                                                                        
start,
-                                                                                                        end,
-                                                                                                        
state);
-       }
+       gfloat x = 0;
+       gfloat y = 0;
+       gint size;
 
        view = gtk_source_gutter_renderer_get_view (renderer);
 
-       pixbuf = gtk_source_pixbuf_helper_render (priv->helper,
-                                                 GTK_WIDGET (view),
-                                                 cell_area->width);
+       width = gtk_widget_get_width (widget);
+       height = gtk_widget_get_height (widget);
+       size = MIN (width, height);
 
-       if (!pixbuf)
-       {
-               return;
-       }
+       paintable = gtk_source_pixbuf_helper_render (pix->priv->helper,
+                                                    GTK_WIDGET (view),
+                                                    size);
 
-       width = gdk_pixbuf_get_width (pixbuf);
-       height = gdk_pixbuf_get_height (pixbuf);
-
-       /*
-        * We might have gotten a pixbuf back from the helper that will allow
-        * us to render for HiDPI. If we detect this, we pretend that we got a
-        * different size back and then gdk_cairo_surface_create_from_pixbuf()
-        * will take care of the rest.
-        */
-       scale = gtk_widget_get_scale_factor (GTK_WIDGET (view));
-       if ((scale > 1) &&
-           ((width > cell_area->width) || (height > cell_area->height)) &&
-           (width <= (cell_area->width * scale)) &&
-           (height <= (cell_area->height * scale)))
+       if (paintable == NULL)
        {
-               width = width / scale;
-               height = height / scale;
-       }
-
-       gtk_source_gutter_renderer_get_alignment (renderer,
-                                                 &xalign,
-                                                 &yalign);
-
-       mode = gtk_source_gutter_renderer_get_alignment_mode (renderer);
-
-       switch (mode)
-       {
-               case GTK_SOURCE_GUTTER_RENDERER_ALIGNMENT_MODE_CELL:
-                       x = cell_area->x + (cell_area->width - width) * xalign;
-                       y = cell_area->y + (cell_area->height - height) * yalign;
-                       break;
-               case GTK_SOURCE_GUTTER_RENDERER_ALIGNMENT_MODE_FIRST:
-                       center_on (renderer,
-                                  cell_area,
-                                  start,
-                                  width,
-                                  height,
-                                  xalign,
-                                  yalign,
-                                  &x,
-                                  &y);
-                       break;
-               case GTK_SOURCE_GUTTER_RENDERER_ALIGNMENT_MODE_LAST:
-                       center_on (renderer,
-                                  cell_area,
-                                  end,
-                                  width,
-                                  height,
-                                  xalign,
-                                  yalign,
-                                  &x,
-                                  &y);
-                       break;
-               default:
-                       g_assert_not_reached ();
+               return;
        }
 
-       surface = gdk_cairo_surface_create_from_pixbuf (pixbuf, scale, NULL);
-       cairo_set_source_surface (cr, surface, x, y);
-
-       cairo_paint (cr);
+       gtk_source_gutter_renderer_align_cell (renderer, line, size, size, &x, &y);
 
-       cairo_surface_destroy (surface);
+       gtk_snapshot_save (snapshot);
+       gtk_snapshot_translate (snapshot, &GRAPHENE_POINT_INIT (x, y));
+       gdk_paintable_snapshot (paintable, snapshot, size, size);
+       gtk_snapshot_restore (snapshot);
 }
 
 static void
 gtk_source_gutter_renderer_pixbuf_finalize (GObject *object)
 {
        GtkSourceGutterRendererPixbuf *renderer = GTK_SOURCE_GUTTER_RENDERER_PIXBUF (object);
-       GtkSourceGutterRendererPixbufPrivate *priv = gtk_source_gutter_renderer_pixbuf_get_instance_private 
(renderer);
 
-       gtk_source_pixbuf_helper_free (priv->helper);
+       gtk_source_pixbuf_helper_free (renderer->priv->helper);
 
        G_OBJECT_CLASS (gtk_source_gutter_renderer_pixbuf_parent_class)->finalize (object);
 }
@@ -204,39 +103,36 @@ static void
 set_pixbuf (GtkSourceGutterRendererPixbuf *renderer,
             GdkPixbuf                     *pixbuf)
 {
-       GtkSourceGutterRendererPixbufPrivate *priv = gtk_source_gutter_renderer_pixbuf_get_instance_private 
(renderer);
-
-       gtk_source_pixbuf_helper_set_pixbuf (priv->helper, pixbuf);
+       gtk_source_pixbuf_helper_set_pixbuf (renderer->priv->helper,
+                                            pixbuf);
 
        g_object_notify (G_OBJECT (renderer), "pixbuf");
 
-       gtk_source_gutter_renderer_queue_draw (GTK_SOURCE_GUTTER_RENDERER (renderer));
+       gtk_widget_queue_draw (GTK_WIDGET (renderer));
 }
 
 static void
 set_gicon (GtkSourceGutterRendererPixbuf *renderer,
            GIcon                         *icon)
 {
-       GtkSourceGutterRendererPixbufPrivate *priv = gtk_source_gutter_renderer_pixbuf_get_instance_private 
(renderer);
-
-       gtk_source_pixbuf_helper_set_gicon (priv->helper, icon);
+       gtk_source_pixbuf_helper_set_gicon (renderer->priv->helper,
+                                           icon);
 
        g_object_notify (G_OBJECT (renderer), "gicon");
 
-       gtk_source_gutter_renderer_queue_draw (GTK_SOURCE_GUTTER_RENDERER (renderer));
+       gtk_widget_queue_draw (GTK_WIDGET (renderer));
 }
 
 static void
 set_icon_name (GtkSourceGutterRendererPixbuf *renderer,
                const gchar                   *icon_name)
 {
-       GtkSourceGutterRendererPixbufPrivate *priv = gtk_source_gutter_renderer_pixbuf_get_instance_private 
(renderer);
-
-       gtk_source_pixbuf_helper_set_icon_name (priv->helper, icon_name);
+       gtk_source_pixbuf_helper_set_icon_name (renderer->priv->helper,
+                                               icon_name);
 
        g_object_notify (G_OBJECT (renderer), "icon-name");
 
-       gtk_source_gutter_renderer_queue_draw (GTK_SOURCE_GUTTER_RENDERER (renderer));
+       gtk_widget_queue_draw (GTK_WIDGET (renderer));
 }
 
 
@@ -273,22 +169,23 @@ gtk_source_gutter_renderer_pixbuf_get_property (GObject    *object,
                                                 GValue     *value,
                                                 GParamSpec *pspec)
 {
-       GtkSourceGutterRendererPixbuf *renderer = GTK_SOURCE_GUTTER_RENDERER_PIXBUF (object);
-       GtkSourceGutterRendererPixbufPrivate *priv = gtk_source_gutter_renderer_pixbuf_get_instance_private 
(renderer);
+       GtkSourceGutterRendererPixbuf *renderer;
+
+       renderer = GTK_SOURCE_GUTTER_RENDERER_PIXBUF (object);
 
        switch (prop_id)
        {
                case PROP_PIXBUF:
                        g_value_set_object (value,
-                                           gtk_source_pixbuf_helper_get_pixbuf (priv->helper));
+                                           gtk_source_pixbuf_helper_get_pixbuf (renderer->priv->helper));
                        break;
                case PROP_ICON_NAME:
                        g_value_set_string (value,
-                                           gtk_source_pixbuf_helper_get_icon_name (priv->helper));
+                                           gtk_source_pixbuf_helper_get_icon_name (renderer->priv->helper));
                        break;
                case PROP_GICON:
                        g_value_set_object (value,
-                                           gtk_source_pixbuf_helper_get_gicon (priv->helper));
+                                           gtk_source_pixbuf_helper_get_gicon (renderer->priv->helper));
                        break;
                default:
                        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -303,11 +200,10 @@ gtk_source_gutter_renderer_pixbuf_class_init (GtkSourceGutterRendererPixbufClass
        GtkSourceGutterRendererClass *renderer_class = GTK_SOURCE_GUTTER_RENDERER_CLASS (klass);
 
        object_class->finalize = gtk_source_gutter_renderer_pixbuf_finalize;
-
        object_class->get_property = gtk_source_gutter_renderer_pixbuf_get_property;
        object_class->set_property = gtk_source_gutter_renderer_pixbuf_set_property;
 
-       renderer_class->draw = gutter_renderer_pixbuf_draw;
+       renderer_class->snapshot_line = gutter_renderer_pixbuf_snapshot_line;
 
        g_object_class_install_property (object_class,
                                         PROP_PIXBUF,
@@ -337,9 +233,9 @@ gtk_source_gutter_renderer_pixbuf_class_init (GtkSourceGutterRendererPixbufClass
 static void
 gtk_source_gutter_renderer_pixbuf_init (GtkSourceGutterRendererPixbuf *self)
 {
-       GtkSourceGutterRendererPixbufPrivate *priv = gtk_source_gutter_renderer_pixbuf_get_instance_private 
(self);
+       self->priv = gtk_source_gutter_renderer_pixbuf_get_instance_private (self);
 
-       priv->helper = gtk_source_pixbuf_helper_new ();
+       self->priv->helper = gtk_source_pixbuf_helper_new ();
 }
 
 /**
@@ -384,11 +280,9 @@ gtk_source_gutter_renderer_pixbuf_set_pixbuf (GtkSourceGutterRendererPixbuf *ren
 GdkPixbuf *
 gtk_source_gutter_renderer_pixbuf_get_pixbuf (GtkSourceGutterRendererPixbuf *renderer)
 {
-       GtkSourceGutterRendererPixbufPrivate *priv = gtk_source_gutter_renderer_pixbuf_get_instance_private 
(renderer);
-
        g_return_val_if_fail (GTK_SOURCE_IS_GUTTER_RENDERER_PIXBUF (renderer), NULL);
 
-       return gtk_source_pixbuf_helper_get_pixbuf (priv->helper);
+       return gtk_source_pixbuf_helper_get_pixbuf (renderer->priv->helper);
 }
 
 /**
@@ -418,11 +312,9 @@ gtk_source_gutter_renderer_pixbuf_set_gicon (GtkSourceGutterRendererPixbuf *rend
 GIcon *
 gtk_source_gutter_renderer_pixbuf_get_gicon (GtkSourceGutterRendererPixbuf *renderer)
 {
-       GtkSourceGutterRendererPixbufPrivate *priv = gtk_source_gutter_renderer_pixbuf_get_instance_private 
(renderer);
-
        g_return_val_if_fail (GTK_SOURCE_IS_GUTTER_RENDERER_PIXBUF (renderer), NULL);
 
-       return gtk_source_pixbuf_helper_get_gicon (priv->helper);
+       return gtk_source_pixbuf_helper_get_gicon (renderer->priv->helper);
 }
 
 /**
@@ -442,9 +334,7 @@ gtk_source_gutter_renderer_pixbuf_set_icon_name (GtkSourceGutterRendererPixbuf *
 const gchar *
 gtk_source_gutter_renderer_pixbuf_get_icon_name (GtkSourceGutterRendererPixbuf *renderer)
 {
-       GtkSourceGutterRendererPixbufPrivate *priv = gtk_source_gutter_renderer_pixbuf_get_instance_private 
(renderer);
-
        g_return_val_if_fail (GTK_SOURCE_IS_GUTTER_RENDERER_PIXBUF (renderer), NULL);
 
-       return gtk_source_pixbuf_helper_get_icon_name (priv->helper);
+       return gtk_source_pixbuf_helper_get_icon_name (renderer->priv->helper);
 }
diff --git a/gtksourceview/gtksourcegutterrendererpixbuf.h b/gtksourceview/gtksourcegutterrendererpixbuf.h
index ee82b6a4..6578fbf7 100644
--- a/gtksourceview/gtksourcegutterrendererpixbuf.h
+++ b/gtksourceview/gtksourcegutterrendererpixbuf.h
@@ -2,7 +2,7 @@
  *
  * This file is part of GtkSourceView
  *
- * Copyright 2010 - Jesse van den Kieboom
+ * Copyright (C) 2010 - Jesse van den Kieboom
  *
  * GtkSourceView is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -18,7 +18,8 @@
  * along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#pragma once
+#ifndef GTK_SOURCE_GUTTER_RENDERER_PIXBUF_H
+#define GTK_SOURCE_GUTTER_RENDERER_PIXBUF_H
 
 #if !defined (GTK_SOURCE_H_INSIDE) && !defined (GTK_SOURCE_COMPILATION)
 #error "Only <gtksourceview/gtksource.h> can be included directly."
@@ -29,35 +30,62 @@
 
 G_BEGIN_DECLS
 
-#define GTK_SOURCE_TYPE_GUTTER_RENDERER_PIXBUF (gtk_source_gutter_renderer_pixbuf_get_type())
+#define GTK_SOURCE_TYPE_GUTTER_RENDERER_PIXBUF                 (gtk_source_gutter_renderer_pixbuf_get_type 
())
+#define GTK_SOURCE_GUTTER_RENDERER_PIXBUF(obj)                 (G_TYPE_CHECK_INSTANCE_CAST ((obj), 
GTK_SOURCE_TYPE_GUTTER_RENDERER_PIXBUF, GtkSourceGutterRendererPixbuf))
+#define GTK_SOURCE_GUTTER_RENDERER_PIXBUF_CONST(obj)           (G_TYPE_CHECK_INSTANCE_CAST ((obj), 
GTK_SOURCE_TYPE_GUTTER_RENDERER_PIXBUF, GtkSourceGutterRendererPixbuf const))
+#define GTK_SOURCE_GUTTER_RENDERER_PIXBUF_CLASS(klass)         (G_TYPE_CHECK_CLASS_CAST ((klass), 
GTK_SOURCE_TYPE_GUTTER_RENDERER_PIXBUF, GtkSourceGutterRendererPixbufClass))
+#define GTK_SOURCE_IS_GUTTER_RENDERER_PIXBUF(obj)              (G_TYPE_CHECK_INSTANCE_TYPE ((obj), 
GTK_SOURCE_TYPE_GUTTER_RENDERER_PIXBUF))
+#define GTK_SOURCE_IS_GUTTER_RENDERER_PIXBUF_CLASS(klass)      (G_TYPE_CHECK_CLASS_TYPE ((klass), 
GTK_SOURCE_TYPE_GUTTER_RENDERER_PIXBUF))
+#define GTK_SOURCE_GUTTER_RENDERER_PIXBUF_GET_CLASS(obj)       (G_TYPE_INSTANCE_GET_CLASS ((obj), 
GTK_SOURCE_TYPE_GUTTER_RENDERER_PIXBUF, GtkSourceGutterRendererPixbufClass))
 
-GTK_SOURCE_AVAILABLE_IN_ALL
-G_DECLARE_DERIVABLE_TYPE (GtkSourceGutterRendererPixbuf, gtk_source_gutter_renderer_pixbuf, GTK_SOURCE, 
GUTTER_RENDERER_PIXBUF, GtkSourceGutterRenderer)
+typedef struct _GtkSourceGutterRendererPixbufClass     GtkSourceGutterRendererPixbufClass;
+typedef struct _GtkSourceGutterRendererPixbufPrivate   GtkSourceGutterRendererPixbufPrivate;
+
+struct _GtkSourceGutterRendererPixbuf
+{
+       /*< private >*/
+       GtkSourceGutterRenderer parent;
+
+       GtkSourceGutterRendererPixbufPrivate *priv;
+
+       /*< public >*/
+};
 
 struct _GtkSourceGutterRendererPixbufClass
 {
+       /*< private >*/
        GtkSourceGutterRendererClass parent_class;
 
-       /*< private >*/
-       gpointer _reserved[10];
+       gpointer padding[10];
 };
 
 GTK_SOURCE_AVAILABLE_IN_ALL
-GtkSourceGutterRenderer *gtk_source_gutter_renderer_pixbuf_new           (void);
+GType gtk_source_gutter_renderer_pixbuf_get_type (void) G_GNUC_CONST;
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-void                     gtk_source_gutter_renderer_pixbuf_set_pixbuf    (GtkSourceGutterRendererPixbuf 
*renderer,
-                                                                          GdkPixbuf                     
*pixbuf);
+GtkSourceGutterRenderer *gtk_source_gutter_renderer_pixbuf_new (void);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-GdkPixbuf               *gtk_source_gutter_renderer_pixbuf_get_pixbuf    (GtkSourceGutterRendererPixbuf 
*renderer);
+void         gtk_source_gutter_renderer_pixbuf_set_pixbuf       (GtkSourceGutterRendererPixbuf *renderer,
+                                                                 GdkPixbuf                     *pixbuf);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-void                     gtk_source_gutter_renderer_pixbuf_set_gicon     (GtkSourceGutterRendererPixbuf 
*renderer,
-                                                                          GIcon                         
*icon);
+GdkPixbuf   *gtk_source_gutter_renderer_pixbuf_get_pixbuf       (GtkSourceGutterRendererPixbuf *renderer);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-GIcon                   *gtk_source_gutter_renderer_pixbuf_get_gicon     (GtkSourceGutterRendererPixbuf 
*renderer);
+void         gtk_source_gutter_renderer_pixbuf_set_gicon        (GtkSourceGutterRendererPixbuf *renderer,
+                                                                 GIcon                         *icon);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-void                     gtk_source_gutter_renderer_pixbuf_set_icon_name (GtkSourceGutterRendererPixbuf 
*renderer,
-                                                                          const gchar                   
*icon_name);
+GIcon       *gtk_source_gutter_renderer_pixbuf_get_gicon        (GtkSourceGutterRendererPixbuf *renderer);
+
+GTK_SOURCE_AVAILABLE_IN_ALL
+void         gtk_source_gutter_renderer_pixbuf_set_icon_name    (GtkSourceGutterRendererPixbuf *renderer,
+                                                                 const gchar                   *icon_name);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-const gchar             *gtk_source_gutter_renderer_pixbuf_get_icon_name (GtkSourceGutterRendererPixbuf 
*renderer);
+const gchar *gtk_source_gutter_renderer_pixbuf_get_icon_name    (GtkSourceGutterRendererPixbuf *renderer);
 
 G_END_DECLS
+
+#endif /* GTK_SOURCE_GUTTER_RENDERER_TEXT_H */
diff --git a/gtksourceview/gtksourcegutterrenderertext.c b/gtksourceview/gtksourcegutterrenderertext.c
index c8085afe..dbdbab76 100644
--- a/gtksourceview/gtksourcegutterrenderertext.c
+++ b/gtksourceview/gtksourcegutterrenderertext.c
@@ -2,7 +2,7 @@
  *
  * This file is part of GtkSourceView
  *
- * Copyright 2010 - Jesse van den Kieboom
+ * Copyright (C) 2010 - Jesse van den Kieboom
  *
  * GtkSourceView is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -18,7 +18,9 @@
  * along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "config.h"
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
 
 #include "gtksourcegutterrenderertext.h"
 
@@ -32,14 +34,14 @@
  * #GtkSourceGutter.
  */
 
-typedef struct
+struct _GtkSourceGutterRendererTextPrivate
 {
-       gchar *text;
-
+       gchar       *text;
        PangoLayout *cached_layout;
-
-       guint is_markup : 1;
-} GtkSourceGutterRendererTextPrivate;
+       GdkRGBA      cached_color;
+       gsize        text_len;
+       guint        is_markup : 1;
+};
 
 G_DEFINE_TYPE_WITH_PRIVATE (GtkSourceGutterRendererText, gtk_source_gutter_renderer_text, 
GTK_SOURCE_TYPE_GUTTER_RENDERER)
 
@@ -47,171 +49,86 @@ enum
 {
        PROP_0,
        PROP_MARKUP,
-       PROP_TEXT
+       PROP_TEXT,
+       N_PROPS
 };
 
 static void
-gutter_renderer_text_begin (GtkSourceGutterRenderer *renderer,
-                            cairo_t                 *cr,
-                            GdkRectangle            *background_area,
-                            GdkRectangle            *cell_area,
-                            GtkTextIter             *start,
-                            GtkTextIter             *end)
+gtk_source_gutter_renderer_text_begin (GtkSourceGutterRenderer *renderer,
+                                       GtkSourceLines          *lines)
 {
-       GtkSourceGutterRendererText *text = GTK_SOURCE_GUTTER_RENDERER_TEXT (renderer);
-       GtkSourceGutterRendererTextPrivate *priv = gtk_source_gutter_renderer_text_get_instance_private 
(text);
-       GtkTextView *view;
 
-       view = gtk_source_gutter_renderer_get_view (renderer);
-
-       g_clear_object (&priv->cached_layout);
-       priv->cached_layout = gtk_widget_create_pango_layout (GTK_WIDGET (view), NULL);
-
-       if (GTK_SOURCE_GUTTER_RENDERER_CLASS (gtk_source_gutter_renderer_text_parent_class)->begin != NULL)
-       {
-               GTK_SOURCE_GUTTER_RENDERER_CLASS (gtk_source_gutter_renderer_text_parent_class)->begin 
(renderer,
-                                                                                                       cr,
-                                                                                                       
background_area,
-                                                                                                       
cell_area,
-                                                                                                       start,
-                                                                                                       end);
-       }
-}
-
-static void
-center_on (GtkTextView  *view,
-           GdkRectangle *cell_area,
-           GtkTextIter  *iter,
-           gint          width,
-           gint          height,
-           gfloat        xalign,
-           gfloat        yalign,
-           gint         *x,
-           gint         *y)
-{
-       GdkRectangle location;
+       GtkSourceGutterRendererText *text = GTK_SOURCE_GUTTER_RENDERER_TEXT (renderer);
 
-       gtk_text_view_get_iter_location (view, iter, &location);
+       GTK_SOURCE_GUTTER_RENDERER_CLASS (gtk_source_gutter_renderer_text_parent_class)->begin (renderer, 
lines);
 
-       *x = cell_area->x + (cell_area->width - width) * xalign;
-       *y = cell_area->y + (location.height - height) * yalign;
+       g_clear_object (&text->priv->cached_layout);
+       text->priv->cached_layout = gtk_widget_create_pango_layout (GTK_WIDGET (renderer), NULL);
 }
 
 static void
-gutter_renderer_text_draw (GtkSourceGutterRenderer      *renderer,
-                           cairo_t                      *cr,
-                           GdkRectangle                 *background_area,
-                           GdkRectangle                 *cell_area,
-                           GtkTextIter                  *start,
-                           GtkTextIter                  *end,
-                           GtkSourceGutterRendererState  state)
+gtk_source_gutter_renderer_text_snapshot_line (GtkSourceGutterRenderer *renderer,
+                                               GtkSnapshot             *snapshot,
+                                               GtkSourceLines          *lines,
+                                               guint                    line)
 {
        GtkSourceGutterRendererText *text = GTK_SOURCE_GUTTER_RENDERER_TEXT (renderer);
-       GtkSourceGutterRendererTextPrivate *priv = gtk_source_gutter_renderer_text_get_instance_private 
(text);
-       GtkTextView *view;
+       PangoLayout *layout;
+       gfloat x;
+       gfloat y;
        gint width;
        gint height;
-       gfloat xalign;
-       gfloat yalign;
-       GtkSourceGutterRendererAlignmentMode mode;
-       gint x = 0;
-       gint y = 0;
-       GtkStyleContext *context;
-
-       /* Chain up to draw background */
-       if (GTK_SOURCE_GUTTER_RENDERER_CLASS (gtk_source_gutter_renderer_text_parent_class)->draw != NULL)
-       {
-               GTK_SOURCE_GUTTER_RENDERER_CLASS (gtk_source_gutter_renderer_text_parent_class)->draw 
(renderer,
-                                                                                                      cr,
-                                                                                                      
background_area,
-                                                                                                      
cell_area,
-                                                                                                      start,
-                                                                                                      end,
-                                                                                                      state);
-       }
-
-       view = gtk_source_gutter_renderer_get_view (renderer);
 
-       if (priv->is_markup)
-       {
-               pango_layout_set_markup (priv->cached_layout,
-                                        priv->text,
-                                        -1);
-       }
-       else
+       if (text->priv->text == NULL || text->priv->text_len == 0)
        {
-               pango_layout_set_text (priv->cached_layout,
-                                      priv->text,
-                                      -1);
+               return;
        }
 
-       pango_layout_get_pixel_size (priv->cached_layout, &width, &height);
+       layout = text->priv->cached_layout;
 
-       gtk_source_gutter_renderer_get_alignment (renderer,
-                                                 &xalign,
-                                                 &yalign);
-
-       /* Avoid calculations if we don't wrap text */
-       if (gtk_text_view_get_wrap_mode (view) == GTK_WRAP_NONE)
+       if (text->priv->is_markup)
        {
-               mode = GTK_SOURCE_GUTTER_RENDERER_ALIGNMENT_MODE_CELL;
+               pango_layout_set_markup (layout,
+                                        text->priv->text,
+                                        text->priv->text_len);
        }
        else
        {
-               mode = gtk_source_gutter_renderer_get_alignment_mode (renderer);
+               pango_layout_set_text (layout,
+                                      text->priv->text,
+                                      text->priv->text_len);
        }
 
-       switch (mode)
-       {
-               case GTK_SOURCE_GUTTER_RENDERER_ALIGNMENT_MODE_CELL:
-                       x = cell_area->x + (cell_area->width - width) * xalign;
-                       y = cell_area->y + (cell_area->height - height) * yalign;
-                       break;
+       pango_layout_get_pixel_size (layout, &width, &height);
 
-               case GTK_SOURCE_GUTTER_RENDERER_ALIGNMENT_MODE_FIRST:
-                       center_on (view,
-                                  cell_area,
-                                  start,
-                                  width,
-                                  height,
-                                  xalign,
-                                  yalign,
-                                  &x,
-                                  &y);
-                       break;
+       gtk_source_gutter_renderer_align_cell (renderer,
+                                              line,
+                                              width,
+                                              height,
+                                              &x,
+                                              &y);
 
-               case GTK_SOURCE_GUTTER_RENDERER_ALIGNMENT_MODE_LAST:
-                       center_on (view,
-                                  cell_area,
-                                  end,
-                                  width,
-                                  height,
-                                  xalign,
-                                  yalign,
-                                  &x,
-                                  &y);
-                       break;
+       gtk_snapshot_render_layout (snapshot,
+                                   gtk_widget_get_style_context (GTK_WIDGET (text)),
+                                   x,
+                                   y,
+                                   layout);
 
-               default:
-                       g_assert_not_reached ();
+       if (text->priv->is_markup)
+       {
+               pango_layout_set_attributes (layout, NULL);
        }
-
-       context = gtk_widget_get_style_context (GTK_WIDGET (view));
-       gtk_render_layout (context, cr, x, y, priv->cached_layout);
 }
 
 static void
-gutter_renderer_text_end (GtkSourceGutterRenderer *renderer)
+gtk_source_gutter_renderer_text_end (GtkSourceGutterRenderer *renderer)
 {
+
        GtkSourceGutterRendererText *text = GTK_SOURCE_GUTTER_RENDERER_TEXT (renderer);
-       GtkSourceGutterRendererTextPrivate *priv = gtk_source_gutter_renderer_text_get_instance_private 
(text);
 
-       g_clear_object (&priv->cached_layout);
+       GTK_SOURCE_GUTTER_RENDERER_CLASS (gtk_source_gutter_renderer_text_parent_class)->end (renderer);
 
-       if (GTK_SOURCE_GUTTER_RENDERER_CLASS (gtk_source_gutter_renderer_text_parent_class)->end != NULL)
-       {
-               GTK_SOURCE_GUTTER_RENDERER_CLASS (gtk_source_gutter_renderer_text_parent_class)->end 
(renderer);
-       }
+       g_clear_object (&text->priv->cached_layout);
 }
 
 static void
@@ -221,7 +138,7 @@ measure_text (GtkSourceGutterRendererText *renderer,
               gint                        *width,
               gint                        *height)
 {
-       GtkTextView *view;
+       GtkSourceView *view;
        PangoLayout *layout;
 
        view = gtk_source_gutter_renderer_get_view (GTK_SOURCE_GUTTER_RENDERER (renderer));
@@ -290,14 +207,52 @@ gtk_source_gutter_renderer_text_measure_markup (GtkSourceGutterRendererText *ren
        measure_text (renderer, markup, NULL, width, height);
 }
 
+static void
+gtk_source_gutter_renderer_text_real_measure (GtkWidget      *widget,
+                                             GtkOrientation  orientation,
+                                             int             for_size,
+                                             int            *minimum,
+                                             int            *natural,
+                                             int            *minimum_baseline,
+                                             int            *natural_baseline)
+{
+       GtkSourceGutterRendererText *renderer = GTK_SOURCE_GUTTER_RENDERER_TEXT (widget);
+
+       *minimum = 0;
+       *natural = 0;
+       *minimum_baseline = -1;
+       *natural_baseline = -1;
+
+       if (orientation == GTK_ORIENTATION_HORIZONTAL)
+       {
+               gint xpad = gtk_source_gutter_renderer_get_xpad (GTK_SOURCE_GUTTER_RENDERER (renderer));
+               gint width = 0;
+               gint height = 0;
+
+               if (renderer->priv->text != NULL)
+               {
+                       if (renderer->priv->is_markup)
+                       {
+                               measure_text (renderer, renderer->priv->text, NULL, &width, &height);
+                       }
+                       else
+                       {
+                               measure_text (renderer, NULL, renderer->priv->text, &width, &height);
+                       }
+               }
+
+               *natural = *minimum = width + 2 * xpad;
+       }
+
+}
+
 static void
 gtk_source_gutter_renderer_text_finalize (GObject *object)
 {
        GtkSourceGutterRendererText *renderer = GTK_SOURCE_GUTTER_RENDERER_TEXT (object);
-       GtkSourceGutterRendererTextPrivate *priv = gtk_source_gutter_renderer_text_get_instance_private 
(renderer);
 
-       g_free (priv->text);
-       g_clear_object (&priv->cached_layout);
+       g_clear_pointer (&renderer->priv->text, g_free);
+       g_clear_object (&renderer->priv->cached_layout);
 
        G_OBJECT_CLASS (gtk_source_gutter_renderer_text_parent_class)->finalize (object);
 }
@@ -308,12 +263,20 @@ set_text (GtkSourceGutterRendererText *renderer,
           gint                         length,
           gboolean                     is_markup)
 {
-       GtkSourceGutterRendererTextPrivate *priv = gtk_source_gutter_renderer_text_get_instance_private 
(renderer);
-
-       g_free (priv->text);
+       g_free (renderer->priv->text);
 
-       priv->text = length >= 0 ? g_strndup (text, length) : g_strdup (text);
-       priv->is_markup = is_markup;
+       if (text == NULL)
+       {
+               renderer->priv->text_len = 0;
+               renderer->priv->text = NULL;
+               renderer->priv->is_markup = FALSE;
+       }
+       else
+       {
+               renderer->priv->text_len = length >= 0 ? length : strlen (text);
+               renderer->priv->text = g_strndup (text, renderer->priv->text_len);
+               renderer->priv->is_markup = !!is_markup;
+       }
 }
 
 static void
@@ -346,16 +309,17 @@ gtk_source_gutter_renderer_text_get_property (GObject    *object,
                                               GValue     *value,
                                               GParamSpec *pspec)
 {
-       GtkSourceGutterRendererText *renderer = GTK_SOURCE_GUTTER_RENDERER_TEXT (object);
-       GtkSourceGutterRendererTextPrivate *priv = gtk_source_gutter_renderer_text_get_instance_private 
(renderer);
+       GtkSourceGutterRendererText *renderer;
+
+       renderer = GTK_SOURCE_GUTTER_RENDERER_TEXT (object);
 
        switch (prop_id)
        {
                case PROP_MARKUP:
-                       g_value_set_string (value, priv->is_markup ? priv->text : NULL);
+                       g_value_set_string (value, renderer->priv->is_markup ? renderer->priv->text : NULL);
                        break;
                case PROP_TEXT:
-                       g_value_set_string (value, !priv->is_markup ? priv->text : NULL);
+                       g_value_set_string (value, !renderer->priv->is_markup ? renderer->priv->text : NULL);
                        break;
                default:
                        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -367,16 +331,18 @@ static void
 gtk_source_gutter_renderer_text_class_init (GtkSourceGutterRendererTextClass *klass)
 {
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
+       GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
        GtkSourceGutterRendererClass *renderer_class = GTK_SOURCE_GUTTER_RENDERER_CLASS (klass);
 
        object_class->finalize = gtk_source_gutter_renderer_text_finalize;
-
        object_class->get_property = gtk_source_gutter_renderer_text_get_property;
        object_class->set_property = gtk_source_gutter_renderer_text_set_property;
 
-       renderer_class->begin = gutter_renderer_text_begin;
-       renderer_class->draw = gutter_renderer_text_draw;
-       renderer_class->end = gutter_renderer_text_end;
+       widget_class->measure = gtk_source_gutter_renderer_text_real_measure;
+
+       renderer_class->begin = gtk_source_gutter_renderer_text_begin;
+       renderer_class->end = gtk_source_gutter_renderer_text_end;
+       renderer_class->snapshot_line = gtk_source_gutter_renderer_text_snapshot_line;
 
        g_object_class_install_property (object_class,
                                         PROP_MARKUP,
@@ -398,9 +364,9 @@ gtk_source_gutter_renderer_text_class_init (GtkSourceGutterRendererTextClass *kl
 static void
 gtk_source_gutter_renderer_text_init (GtkSourceGutterRendererText *self)
 {
-       GtkSourceGutterRendererTextPrivate *priv = gtk_source_gutter_renderer_text_get_instance_private 
(self);
+       self->priv = gtk_source_gutter_renderer_text_get_instance_private (self);
 
-       priv->is_markup = TRUE;
+       self->priv->is_markup = TRUE;
 }
 
 /**
diff --git a/gtksourceview/gtksourcegutterrenderertext.h b/gtksourceview/gtksourcegutterrenderertext.h
index c31600c6..ab8c2a84 100644
--- a/gtksourceview/gtksourcegutterrenderertext.h
+++ b/gtksourceview/gtksourcegutterrenderertext.h
@@ -2,7 +2,7 @@
  *
  * This file is part of GtkSourceView
  *
- * Copyright 2010 - Jesse van den Kieboom
+ * Copyright (C) 2010 - Jesse van den Kieboom
  *
  * GtkSourceView is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -18,7 +18,8 @@
  * along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#pragma once
+#ifndef GTK_SOURCE_GUTTER_RENDERER_TEXT_H
+#define GTK_SOURCE_GUTTER_RENDERER_TEXT_H
 
 #if !defined (GTK_SOURCE_H_INSIDE) && !defined (GTK_SOURCE_COMPILATION)
 #error "Only <gtksourceview/gtksource.h> can be included directly."
@@ -29,38 +30,63 @@
 
 G_BEGIN_DECLS
 
-#define GTK_SOURCE_TYPE_GUTTER_RENDERER_TEXT (gtk_source_gutter_renderer_text_get_type())
+#define GTK_SOURCE_TYPE_GUTTER_RENDERER_TEXT           (gtk_source_gutter_renderer_text_get_type ())
+#define GTK_SOURCE_GUTTER_RENDERER_TEXT(obj)           (G_TYPE_CHECK_INSTANCE_CAST ((obj), 
GTK_SOURCE_TYPE_GUTTER_RENDERER_TEXT, GtkSourceGutterRendererText))
+#define GTK_SOURCE_GUTTER_RENDERER_TEXT_CONST(obj)     (G_TYPE_CHECK_INSTANCE_CAST ((obj), 
GTK_SOURCE_TYPE_GUTTER_RENDERER_TEXT, GtkSourceGutterRendererText const))
+#define GTK_SOURCE_GUTTER_RENDERER_TEXT_CLASS(klass)   (G_TYPE_CHECK_CLASS_CAST ((klass), 
GTK_SOURCE_TYPE_GUTTER_RENDERER_TEXT, GtkSourceGutterRendererTextClass))
+#define GTK_SOURCE_IS_GUTTER_RENDERER_TEXT(obj)                (G_TYPE_CHECK_INSTANCE_TYPE ((obj), 
GTK_SOURCE_TYPE_GUTTER_RENDERER_TEXT))
+#define GTK_SOURCE_IS_GUTTER_RENDERER_TEXT_CLASS(klass)        (G_TYPE_CHECK_CLASS_TYPE ((klass), 
GTK_SOURCE_TYPE_GUTTER_RENDERER_TEXT))
+#define GTK_SOURCE_GUTTER_RENDERER_TEXT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), 
GTK_SOURCE_TYPE_GUTTER_RENDERER_TEXT, GtkSourceGutterRendererTextClass))
+
+typedef struct _GtkSourceGutterRendererTextClass       GtkSourceGutterRendererTextClass;
+typedef struct _GtkSourceGutterRendererTextPrivate     GtkSourceGutterRendererTextPrivate;
+
+struct _GtkSourceGutterRendererText
+{
+       /*< private >*/
+       GtkSourceGutterRenderer parent;
+
+       GtkSourceGutterRendererTextPrivate *priv;
+
+       /*< public >*/
+};
 
 struct _GtkSourceGutterRendererTextClass
 {
+       /*< private >*/
        GtkSourceGutterRendererClass parent_class;
 
-       /*< private >*/
-       gpointer _reserved[10];
+       gpointer padding[10];
 };
 
 GTK_SOURCE_AVAILABLE_IN_ALL
-G_DECLARE_DERIVABLE_TYPE (GtkSourceGutterRendererText, gtk_source_gutter_renderer_text, GTK_SOURCE, 
GUTTER_RENDERER_TEXT, GtkSourceGutterRenderer)
+GType gtk_source_gutter_renderer_text_get_type (void) G_GNUC_CONST;
 
 GTK_SOURCE_AVAILABLE_IN_ALL
-GtkSourceGutterRenderer *gtk_source_gutter_renderer_text_new            (void);
+GtkSourceGutterRenderer *gtk_source_gutter_renderer_text_new (void);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-void                     gtk_source_gutter_renderer_text_set_markup     (GtkSourceGutterRendererText 
*renderer,
-                                                                         const gchar                 *markup,
-                                                                         gint                         
length);
+void gtk_source_gutter_renderer_text_set_markup (GtkSourceGutterRendererText *renderer,
+                                                 const gchar                 *markup,
+                                                 gint                         length);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-void                     gtk_source_gutter_renderer_text_set_text       (GtkSourceGutterRendererText 
*renderer,
-                                                                         const gchar                 *text,
-                                                                         gint                         
length);
+void gtk_source_gutter_renderer_text_set_text (GtkSourceGutterRendererText *renderer,
+                                               const gchar                 *text,
+                                               gint                         length);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-void                     gtk_source_gutter_renderer_text_measure        (GtkSourceGutterRendererText 
*renderer,
-                                                                         const gchar                 *text,
-                                                                         gint                        *width,
-                                                                         gint                        
*height);
+void gtk_source_gutter_renderer_text_measure (GtkSourceGutterRendererText *renderer,
+                                              const gchar                 *text,
+                                              gint                        *width,
+                                              gint                        *height);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-void                     gtk_source_gutter_renderer_text_measure_markup (GtkSourceGutterRendererText 
*renderer,
-                                                                         const gchar                 *markup,
-                                                                         gint                        *width,
-                                                                         gint                        
*height);
+void gtk_source_gutter_renderer_text_measure_markup (GtkSourceGutterRendererText *renderer,
+                                                     const gchar                 *markup,
+                                                     gint                        *width,
+                                                     gint                        *height);
 
 G_END_DECLS
+
+#endif /* GTK_SOURCE_GUTTER_RENDERER_TEXT_H */
diff --git a/gtksourceview/gtksourceinit.c b/gtksourceview/gtksourceinit.c
index d13e5918..4953d44a 100644
--- a/gtksourceview/gtksourceinit.c
+++ b/gtksourceview/gtksourceinit.c
@@ -2,7 +2,7 @@
  *
  * This file is part of GtkSourceView
  *
- * Copyright 2016, 2017 - Sébastien Wilmet <swilmet gnome org>
+ * Copyright (C) 2016, 2017 - Sébastien Wilmet <swilmet gnome org>
  *
  * GtkSourceView is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -18,13 +18,21 @@
  * along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "config.h"
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
 
 #include <glib/gi18n-lib.h>
 
 #include "gtksourceinit.h"
+#include "gtksourcegutterrendererlines.h"
+#include "gtksourcegutterrenderertext.h"
 #include "gtksourcelanguagemanager-private.h"
+#include "gtksourcemap.h"
+#include "gtksourcestyleschemechooserbutton.h"
+#include "gtksourcestyleschemechooserwidget.h"
 #include "gtksourcestyleschememanager-private.h"
+#include "gtksourceview.h"
 
 #ifdef G_OS_WIN32
 #define WIN32_LEAN_AND_MEAN
@@ -156,6 +164,13 @@ gtk_source_init (void)
 
                bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
 
+               g_type_ensure (GTK_SOURCE_TYPE_GUTTER_RENDERER_LINES);
+               g_type_ensure (GTK_SOURCE_TYPE_GUTTER_RENDERER_TEXT);
+               g_type_ensure (GTK_SOURCE_TYPE_MAP);
+               g_type_ensure (GTK_SOURCE_TYPE_STYLE_SCHEME_CHOOSER_BUTTON);
+               g_type_ensure (GTK_SOURCE_TYPE_STYLE_SCHEME_CHOOSER_WIDGET);
+               g_type_ensure (GTK_SOURCE_TYPE_VIEW);
+
                done = TRUE;
        }
 }
diff --git a/gtksourceview/gtksourceinit.h b/gtksourceview/gtksourceinit.h
index 87898b76..36bbbc36 100644
--- a/gtksourceview/gtksourceinit.h
+++ b/gtksourceview/gtksourceinit.h
@@ -1,7 +1,7 @@
 /*
  * This file is part of GtkSourceView
  *
- * Copyright 2017 - Sébastien Wilmet <swilmet gnome org>
+ * Copyright (C) 2017 - Sébastien Wilmet <swilmet gnome org>
  *
  * GtkSourceView is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -17,7 +17,8 @@
  * along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#pragma once
+#ifndef GTK_SOURCE_INIT_H
+#define GTK_SOURCE_INIT_H
 
 #if !defined (GTK_SOURCE_H_INSIDE) && !defined (GTK_SOURCE_COMPILATION)
 #error "Only <gtksourceview/gtksource.h> can be included directly."
@@ -30,8 +31,11 @@
 G_BEGIN_DECLS
 
 GTK_SOURCE_AVAILABLE_IN_4_0
-void gtk_source_init     (void);
+void   gtk_source_init         (void);
+
 GTK_SOURCE_AVAILABLE_IN_4_0
-void gtk_source_finalize (void);
+void   gtk_source_finalize     (void);
 
 G_END_DECLS
+
+#endif /* GTK_SOURCE_INIT_H */
diff --git a/gtksourceview/gtksourceiter.c b/gtksourceview/gtksourceiter.c
index bafc842e..afe94ba0 100644
--- a/gtksourceview/gtksourceiter.c
+++ b/gtksourceview/gtksourceiter.c
@@ -2,7 +2,7 @@
 /*
  * This file is part of GtkSourceView
  *
- * Copyright 2014, 2016 - Sébastien Wilmet <swilmet gnome org>
+ * Copyright (C) 2014, 2016 - Sébastien Wilmet <swilmet gnome org>
  *
  * GtkSourceView is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -18,9 +18,11 @@
  * along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "config.h"
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
 
-#include "gtksourceiter-private.h"
+#include "gtksourceiter.h"
 
 /* GtkTextIter functions. Contains forward/backward functions for word
  * movements, with custom word boundaries that are used for word selection
@@ -66,21 +68,14 @@ _gtk_source_iter_forward_full_word_end (GtkTextIter *iter)
 
        while (g_unichar_isspace (gtk_text_iter_get_char (&pos)))
        {
-               if (!gtk_text_iter_forward_visible_cursor_position (&pos))
-               {
-                       break;
-               }
+               gtk_text_iter_forward_visible_cursor_position (&pos);
        }
 
        while (!gtk_text_iter_is_end (&pos) &&
               !g_unichar_isspace (gtk_text_iter_get_char (&pos)))
        {
                non_blank_found = TRUE;
-
-               if (!gtk_text_iter_forward_visible_cursor_position (&pos))
-               {
-                       break;
-               }
+               gtk_text_iter_forward_visible_cursor_position (&pos);
        }
 
        if (non_blank_found)
@@ -102,11 +97,7 @@ _gtk_source_iter_backward_full_word_start (GtkTextIter *iter)
        while (!gtk_text_iter_is_start (&pos))
        {
                prev = pos;
-
-               if (!gtk_text_iter_backward_visible_cursor_position (&prev))
-               {
-                       break;
-               }
+               gtk_text_iter_backward_visible_cursor_position (&prev);
 
                if (!g_unichar_isspace (gtk_text_iter_get_char (&prev)))
                {
@@ -119,11 +110,7 @@ _gtk_source_iter_backward_full_word_start (GtkTextIter *iter)
        while (!gtk_text_iter_is_start (&pos))
        {
                prev = pos;
-
-               if (!gtk_text_iter_backward_visible_cursor_position (&prev))
-               {
-                       break;
-               }
+               gtk_text_iter_backward_visible_cursor_position (&prev);
 
                if (g_unichar_isspace (gtk_text_iter_get_char (&prev)))
                {
@@ -210,17 +197,11 @@ _gtk_source_iter_forward_extra_natural_word_end (GtkTextIter *iter)
        {
                if (gtk_text_iter_get_char (iter) == '_')
                {
-                       if (!gtk_text_iter_forward_visible_cursor_position (iter))
-                       {
-                               break;
-                       }
+                       gtk_text_iter_forward_visible_cursor_position (iter);
                }
                else if (gtk_text_iter_starts_word (iter))
                {
-                       if (!gtk_text_iter_forward_visible_word_end (iter))
-                       {
-                               break;
-                       }
+                       gtk_text_iter_forward_visible_word_end (iter);
                }
                else
                {
@@ -262,11 +243,7 @@ _gtk_source_iter_backward_extra_natural_word_start (GtkTextIter *iter)
        while (!gtk_text_iter_is_start (iter))
        {
                GtkTextIter prev = *iter;
-
-               if (!gtk_text_iter_backward_visible_cursor_position (&prev))
-               {
-                       break;
-               }
+               gtk_text_iter_backward_visible_cursor_position (&prev);
 
                if (gtk_text_iter_get_char (&prev) == '_')
                {
@@ -274,10 +251,7 @@ _gtk_source_iter_backward_extra_natural_word_start (GtkTextIter *iter)
                }
                else if (gtk_text_iter_ends_word (iter))
                {
-                       if (!gtk_text_iter_backward_visible_word_start (iter))
-                       {
-                               break;
-                       }
+                       gtk_text_iter_backward_visible_word_start (iter);
                }
                else
                {
diff --git a/gtksourceview/gtksourceiter.h b/gtksourceview/gtksourceiter.h
new file mode 100644
index 00000000..4c857d90
--- /dev/null
+++ b/gtksourceview/gtksourceiter.h
@@ -0,0 +1,98 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; coding: utf-8 -*- */
+/*
+ * This file is part of GtkSourceView
+ *
+ * Copyright (C) 2014, 2016 - Sébastien Wilmet <swilmet gnome org>
+ *
+ * GtkSourceView is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * GtkSourceView is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GTK_SOURCE_ITER_H
+#define GTK_SOURCE_ITER_H
+
+#include <gtk/gtk.h>
+
+#include "gtksourcetypes-private.h"
+
+G_BEGIN_DECLS
+
+/* Semi-public functions. */
+
+GTK_SOURCE_INTERNAL
+gboolean       _gtk_source_iter_forward_visible_word_end               (GtkTextIter *iter);
+
+GTK_SOURCE_INTERNAL
+gboolean       _gtk_source_iter_forward_visible_word_ends              (GtkTextIter *iter,
+                                                                        gint         count);
+
+GTK_SOURCE_INTERNAL
+gboolean       _gtk_source_iter_backward_visible_word_start            (GtkTextIter *iter);
+
+GTK_SOURCE_INTERNAL
+gboolean       _gtk_source_iter_backward_visible_word_starts           (GtkTextIter *iter,
+                                                                        gint         count);
+
+GTK_SOURCE_INTERNAL
+void           _gtk_source_iter_extend_selection_word                  (const GtkTextIter *location,
+                                                                        GtkTextIter       *start,
+                                                                        GtkTextIter       *end);
+
+GTK_SOURCE_INTERNAL
+gboolean       _gtk_source_iter_starts_extra_natural_word              (const GtkTextIter *iter,
+                                                                        gboolean           visible);
+
+GTK_SOURCE_INTERNAL
+gboolean       _gtk_source_iter_ends_extra_natural_word                (const GtkTextIter *iter,
+                                                                        gboolean           visible);
+
+GTK_SOURCE_INTERNAL
+void           _gtk_source_iter_get_leading_spaces_end_boundary        (const GtkTextIter *iter,
+                                                                        GtkTextIter       *leading_end);
+
+GTK_SOURCE_INTERNAL
+void           _gtk_source_iter_get_trailing_spaces_start_boundary     (const GtkTextIter *iter,
+                                                                        GtkTextIter       *trailing_start);
+
+/* Internal functions, in the header for unit tests. */
+
+GTK_SOURCE_INTERNAL
+void           _gtk_source_iter_forward_full_word_end                  (GtkTextIter *iter);
+
+GTK_SOURCE_INTERNAL
+void           _gtk_source_iter_backward_full_word_start               (GtkTextIter *iter);
+
+GTK_SOURCE_INTERNAL
+gboolean       _gtk_source_iter_starts_full_word                       (const GtkTextIter *iter);
+
+GTK_SOURCE_INTERNAL
+gboolean       _gtk_source_iter_ends_full_word                         (const GtkTextIter *iter);
+
+GTK_SOURCE_INTERNAL
+void           _gtk_source_iter_forward_extra_natural_word_end         (GtkTextIter *iter);
+
+GTK_SOURCE_INTERNAL
+void           _gtk_source_iter_backward_extra_natural_word_start      (GtkTextIter *iter);
+
+GTK_SOURCE_INTERNAL
+gboolean       _gtk_source_iter_starts_word                            (const GtkTextIter *iter);
+
+GTK_SOURCE_INTERNAL
+gboolean       _gtk_source_iter_ends_word                              (const GtkTextIter *iter);
+
+GTK_SOURCE_INTERNAL
+gboolean       _gtk_source_iter_inside_word                            (const GtkTextIter *iter);
+
+G_END_DECLS
+
+#endif /* GTK_SOURCE_ITER_H */
diff --git a/gtksourceview/gtksourcelanguage-parser-2.c b/gtksourceview/gtksourcelanguage-parser-2.c
index c7c3f809..1cde848f 100644
--- a/gtksourceview/gtksourcelanguage-parser-2.c
+++ b/gtksourceview/gtksourcelanguage-parser-2.c
@@ -3,8 +3,8 @@
  * Language specification parser for 2.0 version .lang files
  * This file is part of GtkSourceView
  *
- * Copyright 2003 - Gustavo Giráldez <gustavo giraldez gmx net>
- * Copyright 2005, 2006 - Emanuele Aina, Marco Barisione
+ * Copyright (C) 2003 - Gustavo Giráldez <gustavo giraldez gmx net>
+ * Copyright (C) 2005, 2006 - Emanuele Aina, Marco Barisione
  *
  * GtkSourceView is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -28,7 +28,9 @@
 #define DEBUG(x)
 #endif
 
-#include "config.h"
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
 
 #include "gtksourcebuffer.h"
 #include "gtksourcelanguage.h"
@@ -135,7 +137,7 @@ static ParserState *parser_state_new           (GtkSourceLanguage      *language
                                                 GHashTable             *loaded_lang_ids);
 static void       parser_state_destroy         (ParserState *parser_state);
 
-static gboolean   file_parse                   (const gchar            *filename,
+static gboolean   file_parse                   (gchar                  *filename,
                                                 GtkSourceLanguage      *language,
                                                 GtkSourceContextData   *ctx_data,
                                                 GHashTable             *defined_regexes,
@@ -577,7 +579,7 @@ add_ref (ParserState               *parser_state,
                        }
                        else
                        {
-                               file_parse (_gtk_source_language_get_file_name (imported_language),
+                               file_parse (imported_language->priv->lang_file_name,
                                            parser_state->language,
                                            parser_state->ctx_data,
                                            parser_state->defined_regexes,
@@ -591,8 +593,8 @@ add_ref (ParserState               *parser_state,
                                        GError *tmp_error2 = NULL;
                                        g_set_error (&tmp_error2, PARSER_ERROR, tmp_error->code,
                                                     "In file '%s' referenced from '%s': %s",
-                                                    _gtk_source_language_get_file_name (imported_language),
-                                                    _gtk_source_language_get_file_name 
(parser_state->language),
+                                                    imported_language->priv->lang_file_name,
+                                                    parser_state->language->priv->lang_file_name,
                                                     tmp_error->message);
                                        g_clear_error (&tmp_error);
                                        tmp_error = tmp_error2;
@@ -1355,7 +1357,7 @@ parse_language_with_id (ParserState *parser_state,
        }
        else
        {
-               file_parse (_gtk_source_language_get_file_name (imported_language),
+               file_parse (imported_language->priv->lang_file_name,
                            parser_state->language,
                            parser_state->ctx_data,
                            parser_state->defined_regexes,
@@ -1589,7 +1591,7 @@ text_reader_structured_error_func (ParserState *parser_state,
 }
 
 static gboolean
-file_parse (const gchar               *filename,
+file_parse (gchar                     *filename,
            GtkSourceLanguage         *language,
            GtkSourceContextData      *ctx_data,
            GHashTable                *defined_regexes,
@@ -1715,17 +1717,13 @@ parser_state_new (GtkSourceLanguage       *language,
                  GHashTable              *loaded_lang_ids)
 {
        ParserState *parser_state;
-       const gchar *id;
-
-       id = gtk_source_language_get_id (language);
-       g_return_val_if_fail (id != NULL, NULL);
-
        parser_state = g_slice_new0 (ParserState);
 
        parser_state->language = language;
        parser_state->ctx_data = ctx_data;
 
-       parser_state->language_decoration = g_strdup_printf ("%s:", id);
+       g_return_val_if_fail (language->priv->id != NULL, NULL);
+       parser_state->language_decoration = g_strdup_printf ("%s:", language->priv->id);
 
        parser_state->current_lang_id = NULL;
 
@@ -1786,13 +1784,13 @@ _gtk_source_language_file_parse_version2 (GtkSourceLanguage       *language,
        GHashTable *defined_regexes, *styles;
        gboolean success;
        GError *error = NULL;
-       const gchar *filename;
+       gchar *filename;
        GHashTable *loaded_lang_ids;
        GQueue *replacements;
 
        g_return_val_if_fail (ctx_data != NULL, FALSE);
 
-       filename = _gtk_source_language_get_file_name (language);
+       filename = language->priv->lang_file_name;
 
        /* TODO: as an optimization tell the parser to merge CDATA
         * as text nodes (XML_PARSE_NOCDATA), and to ignore blank
@@ -1825,7 +1823,7 @@ _gtk_source_language_file_parse_version2 (GtkSourceLanguage       *language,
        if (success)
                g_hash_table_foreach_steal (styles,
                                            (GHRFunc) steal_styles_mapping,
-                                           _gtk_source_language_get_styles (language));
+                                           language->priv->styles);
 
        g_queue_free_full (replacements, (GDestroyNotify) _gtk_source_context_replace_free);
        g_hash_table_destroy (loaded_lang_ids);
diff --git a/gtksourceview/gtksourcelanguage-private.h b/gtksourceview/gtksourcelanguage-private.h
index 73e952dd..9e97707d 100644
--- a/gtksourceview/gtksourcelanguage-private.h
+++ b/gtksourceview/gtksourcelanguage-private.h
@@ -2,7 +2,7 @@
  *
  * This file is part of GtkSourceView
  *
- * Copyright 2003 - Paolo Maggi <paolo maggi polito it>
+ * Copyright (C) 2003 - Paolo Maggi <paolo maggi polito it>
  *
  * GtkSourceView is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -18,7 +18,8 @@
  * along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#pragma once
+#ifndef GTK_SOURCE_LANGUAGE_PRIVATE_H
+#define GTK_SOURCE_LANGUAGE_PRIVATE_H
 
 #include <glib.h>
 
@@ -27,45 +28,77 @@
 
 G_BEGIN_DECLS
 
-#define GTK_SOURCE_LANGUAGE_VERSION_1_0 100
-#define GTK_SOURCE_LANGUAGE_VERSION_2_0 200
+#define GTK_SOURCE_LANGUAGE_VERSION_1_0  100
+#define GTK_SOURCE_LANGUAGE_VERSION_2_0  200
 
-typedef struct
+typedef struct _GtkSourceStyleInfo GtkSourceStyleInfo;
+
+struct _GtkSourceStyleInfo
 {
        gchar *name;
        gchar *map_to;
-} GtkSourceStyleInfo;
+};
+
+struct _GtkSourceLanguagePrivate
+{
+       gchar                    *lang_file_name;
+       gchar                    *translation_domain;
+
+       gchar                    *id;
+       gchar                    *name;
+       gchar                    *section;
+
+       /* Maps ids to GtkSourceStyleInfo objects */
+       /* Names of styles defined in other lang files are not stored */
+       GHashTable               *styles;
+       gboolean                  styles_loaded;
+
+       gint                      version;
+       gboolean                  hidden;
+
+       GHashTable               *properties;
+
+       GtkSourceLanguageManager *language_manager;
+
+       GtkSourceContextData     *ctx_data;
+};
 
 G_GNUC_INTERNAL
-GtkSourceLanguage        *_gtk_source_language_new_from_file          (const gchar              *filename,
-                                                                       GtkSourceLanguageManager *lm);
-G_GNUC_INTERNAL
-GtkSourceLanguageManager *_gtk_source_language_get_language_manager   (GtkSourceLanguage        *language);
-G_GNUC_INTERNAL
-const gchar              *_gtk_source_language_get_file_name          (GtkSourceLanguage        *language);
-G_GNUC_INTERNAL
-const gchar              *_gtk_source_language_manager_get_rng_file   (GtkSourceLanguageManager *lm);
+GtkSourceLanguage       *_gtk_source_language_new_from_file            (const gchar               *filename,
+                                                                        GtkSourceLanguageManager  *lm);
+
 G_GNUC_INTERNAL
-gchar                    *_gtk_source_language_translate_string       (GtkSourceLanguage        *language,
-                                                                       const gchar              *string);
+GtkSourceLanguageManager *_gtk_source_language_get_language_manager    (GtkSourceLanguage        *language);
+
 G_GNUC_INTERNAL
-void                      _gtk_source_language_define_language_styles (GtkSourceLanguage        *language);
+const gchar             *_gtk_source_language_manager_get_rng_file     (GtkSourceLanguageManager *lm);
+
 G_GNUC_INTERNAL
-gboolean                  _gtk_source_language_file_parse_version2    (GtkSourceLanguage        *language,
-                                                                       GtkSourceContextData     *ctx_data);
+gchar                   *_gtk_source_language_translate_string         (GtkSourceLanguage        *language,
+                                                                        const gchar              *string);
+
 G_GNUC_INTERNAL
-GtkSourceEngine          *_gtk_source_language_create_engine          (GtkSourceLanguage        *language);
+void                     _gtk_source_language_define_language_styles   (GtkSourceLanguage        *language);
+
 G_GNUC_INTERNAL
-void                      _gtk_source_language_clear_ctx_data         (GtkSourceLanguage        *language,
-                                                                       GtkSourceContextData     *ctx_data);
+gboolean                 _gtk_source_language_file_parse_version2      (GtkSourceLanguage        *language,
+                                                                        GtkSourceContextData     *ctx_data);
+
 G_GNUC_INTERNAL
-GHashTable               *_gtk_source_language_get_styles             (GtkSourceLanguage        *language);
+GtkSourceEngine         *_gtk_source_language_create_engine            (GtkSourceLanguage        *language);
+
+/* Utility functions for GtkSourceStyleInfo */
 G_GNUC_INTERNAL
-GtkSourceStyleInfo       *_gtk_source_style_info_new                  (const gchar              *name,
-                                                                       const gchar              *map_to);
+GtkSourceStyleInfo      *_gtk_source_style_info_new                    (const gchar              *name,
+                                                                        const gchar              *map_to);
+
 G_GNUC_INTERNAL
-GtkSourceStyleInfo       *_gtk_source_style_info_copy                 (GtkSourceStyleInfo       *info);
+GtkSourceStyleInfo      *_gtk_source_style_info_copy                   (GtkSourceStyleInfo       *info);
+
 G_GNUC_INTERNAL
-void                      _gtk_source_style_info_free                 (GtkSourceStyleInfo       *info);
+void                     _gtk_source_style_info_free                   (GtkSourceStyleInfo       *info);
 
 G_END_DECLS
+
+#endif  /* GTK_SOURCE_LANGUAGE_PRIVATE_H */
+
diff --git a/gtksourceview/gtksourcelanguage.c b/gtksourceview/gtksourcelanguage.c
index b68c08da..43105459 100644
--- a/gtksourceview/gtksourcelanguage.c
+++ b/gtksourceview/gtksourcelanguage.c
@@ -2,7 +2,7 @@
 /*
  * This file is part of GtkSourceView
  *
- * Copyright 2003 - Paolo Maggi <paolo maggi polito it>
+ * Copyright (C) 2003 - Paolo Maggi <paolo maggi polito it>
  *
  * GtkSourceView is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -18,7 +18,9 @@
  * along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "config.h"
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
 
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
@@ -61,41 +63,15 @@ enum {
        PROP_HIDDEN
 };
 
-struct _GtkSourceLanguage
-{
-       GObject                   parent_instance;
-
-       gchar                    *lang_file_name;
-       gchar                    *translation_domain;
-
-       gchar                    *id;
-       gchar                    *name;
-       gchar                    *section;
-
-       /* Maps ids to GtkSourceStyleInfo objects */
-       /* Names of styles defined in other lang files are not stored */
-       GHashTable               *styles;
-       gboolean                  styles_loaded;
-
-       gint                      version;
-       gboolean                  hidden;
-
-       GHashTable               *properties;
-
-       GtkSourceLanguageManager *language_manager;
-
-       GtkSourceContextData     *ctx_data;
-};
-
-G_DEFINE_TYPE (GtkSourceLanguage, gtk_source_language, G_TYPE_OBJECT)
+G_DEFINE_TYPE_WITH_PRIVATE (GtkSourceLanguage, gtk_source_language, G_TYPE_OBJECT)
 
-static GtkSourceLanguage *process_language_node (xmlTextReaderPtr   reader,
-                                                 const gchar       *filename);
-static gboolean           force_styles          (GtkSourceLanguage *language);
+static GtkSourceLanguage *process_language_node (xmlTextReaderPtr       reader,
+                                                const gchar            *filename);
+static gboolean                  force_styles          (GtkSourceLanguage      *language);
 
 GtkSourceLanguage *
 _gtk_source_language_new_from_file (const gchar              *filename,
-                                    GtkSourceLanguageManager *lm)
+                                   GtkSourceLanguageManager *lm)
 {
        GtkSourceLanguage *lang = NULL;
        xmlTextReaderPtr reader = NULL;
@@ -158,9 +134,9 @@ _gtk_source_language_new_from_file (const gchar              *filename,
 
        if (lang != NULL)
        {
-               lang->language_manager = lm;
+               lang->priv->language_manager = lm;
                g_object_add_weak_pointer (G_OBJECT (lm),
-                                          (gpointer) &lang->language_manager);
+                                          (gpointer) &lang->priv->language_manager);
        }
 
        return lang;
@@ -168,9 +144,9 @@ _gtk_source_language_new_from_file (const gchar              *filename,
 
 static void
 gtk_source_language_get_property (GObject    *object,
-                                  guint       prop_id,
-                                  GValue     *value,
-                                  GParamSpec *pspec)
+                                 guint       prop_id,
+                                 GValue     *value,
+                                 GParamSpec *pspec)
 {
        GtkSourceLanguage *language;
 
@@ -181,19 +157,19 @@ gtk_source_language_get_property (GObject    *object,
        switch (prop_id)
        {
                case PROP_ID:
-                       g_value_set_string (value, language->id);
+                       g_value_set_string (value, language->priv->id);
                        break;
 
                case PROP_NAME:
-                       g_value_set_string (value, language->name);
+                       g_value_set_string (value, language->priv->name);
                        break;
 
                case PROP_SECTION:
-                       g_value_set_string (value, language->section);
+                       g_value_set_string (value, language->priv->section);
                        break;
 
                case PROP_HIDDEN:
-                       g_value_set_boolean (value, language->hidden);
+                       g_value_set_boolean (value, language->priv->hidden);
                        break;
 
                default:
@@ -209,11 +185,11 @@ gtk_source_language_dispose (GObject *object)
 
        lang = GTK_SOURCE_LANGUAGE (object);
 
-       if (lang->language_manager != NULL)
+       if (lang->priv->language_manager != NULL)
        {
-               g_object_remove_weak_pointer (G_OBJECT (lang->language_manager),
-                                             (gpointer) &lang->language_manager);
-               lang->language_manager = NULL;
+               g_object_remove_weak_pointer (G_OBJECT (lang->priv->language_manager),
+                                             (gpointer) &lang->priv->language_manager);
+               lang->priv->language_manager = NULL;
        }
 
        G_OBJECT_CLASS (gtk_source_language_parent_class)->dispose (object);
@@ -226,17 +202,17 @@ gtk_source_language_finalize (GObject *object)
 
        lang = GTK_SOURCE_LANGUAGE (object);
 
-       if (lang->ctx_data != NULL)
+       if (lang->priv->ctx_data != NULL)
                g_critical ("context data not freed in gtk_source_language_finalize");
 
-       g_free (lang->lang_file_name);
-       g_free (lang->translation_domain);
-       g_free (lang->name);
-       g_free (lang->section);
-       g_free (lang->id);
-       g_hash_table_destroy (lang->properties);
+       g_free (lang->priv->lang_file_name);
+       g_free (lang->priv->translation_domain);
+       g_free (lang->priv->name);
+       g_free (lang->priv->section);
+       g_free (lang->priv->id);
+       g_hash_table_destroy (lang->priv->properties);
 
-       g_hash_table_destroy (lang->styles);
+       g_hash_table_destroy (lang->priv->styles);
 
        G_OBJECT_CLASS (gtk_source_language_parent_class)->finalize (object);
 }
@@ -290,13 +266,13 @@ gtk_source_language_class_init (GtkSourceLanguageClass *klass)
 static void
 gtk_source_language_init (GtkSourceLanguage *lang)
 {
-       lang = gtk_source_language_get_instance_private (lang);
+       lang->priv = gtk_source_language_get_instance_private (lang);
 
-       lang->styles = g_hash_table_new_full (g_str_hash,
+       lang->priv->styles = g_hash_table_new_full (g_str_hash,
                                                    g_str_equal,
                                                    g_free,
                                                    (GDestroyNotify)_gtk_source_style_info_free);
-       lang->properties = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
+       lang->priv->properties = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
 }
 
 static gboolean
@@ -316,7 +292,7 @@ string_to_bool (const gchar *string)
 
 static void
 process_properties (xmlTextReaderPtr   reader,
-                    GtkSourceLanguage *language)
+                   GtkSourceLanguage *language)
 {
        xmlNodePtr child;
        xmlNodePtr node = NULL;
@@ -360,7 +336,7 @@ process_properties (xmlTextReaderPtr   reader,
                content = xmlNodeGetContent (child);
 
                if (name != NULL && content != NULL)
-                       g_hash_table_insert (language->properties,
+                       g_hash_table_insert (language->priv->properties,
                                             g_strdup ((gchar *) name),
                                             g_strdup ((gchar *) content));
 
@@ -370,8 +346,7 @@ process_properties (xmlTextReaderPtr   reader,
 }
 
 static GtkSourceLanguage *
-process_language_node (xmlTextReaderPtr  reader,
-                       const gchar      *filename)
+process_language_node (xmlTextReaderPtr reader, const gchar *filename)
 {
        xmlChar *version;
        xmlChar *tmp;
@@ -380,29 +355,29 @@ process_language_node (xmlTextReaderPtr  reader,
 
        lang = g_object_new (GTK_SOURCE_TYPE_LANGUAGE, NULL);
 
-       lang->lang_file_name = g_strdup (filename);
+       lang->priv->lang_file_name = g_strdup (filename);
 
        tmp = xmlTextReaderGetAttribute (reader, BAD_CAST "translation-domain");
-       lang->translation_domain = g_strdup ((gchar*) tmp);
+       lang->priv->translation_domain = g_strdup ((gchar*) tmp);
        xmlFree (tmp);
 
        tmp = xmlTextReaderGetAttribute (reader, BAD_CAST "hidden");
        if (tmp != NULL)
-               lang->hidden = string_to_bool ((gchar*) tmp);
+               lang->priv->hidden = string_to_bool ((gchar*) tmp);
        else
-               lang->hidden = FALSE;
+               lang->priv->hidden = FALSE;
        xmlFree (tmp);
 
        tmp = xmlTextReaderGetAttribute (reader, BAD_CAST "mimetypes");
        if (tmp != NULL)
-               g_hash_table_insert (lang->properties,
+               g_hash_table_insert (lang->priv->properties,
                                     g_strdup ("mimetypes"),
                                     g_strdup ((char*) tmp));
        xmlFree (tmp);
 
        tmp = xmlTextReaderGetAttribute (reader, BAD_CAST "globs");
        if (tmp != NULL)
-               g_hash_table_insert (lang->properties,
+               g_hash_table_insert (lang->priv->properties,
                                     g_strdup ("globs"),
                                     g_strdup ((char*) tmp));
        xmlFree (tmp);
@@ -420,23 +395,23 @@ process_language_node (xmlTextReaderPtr  reader,
                        return NULL;
                }
 
-               lang->name = g_strdup ((char*) tmp);
+               lang->priv->name = g_strdup ((char*) tmp);
                untranslated_name = tmp;
        }
        else
        {
-               lang->name = _gtk_source_language_translate_string (lang, (gchar*) tmp);
+               lang->priv->name = _gtk_source_language_translate_string (lang, (gchar*) tmp);
                untranslated_name = tmp;
        }
 
        tmp = xmlTextReaderGetAttribute (reader, BAD_CAST "id");
        if (tmp != NULL)
        {
-               lang->id = g_ascii_strdown ((gchar*) tmp, -1);
+               lang->priv->id = g_ascii_strdown ((gchar*) tmp, -1);
        }
        else
        {
-               lang->id = g_ascii_strdown ((gchar*) untranslated_name, -1);
+               lang->priv->id = g_ascii_strdown ((gchar*) untranslated_name, -1);
        }
        xmlFree (tmp);
        xmlFree (untranslated_name);
@@ -447,15 +422,15 @@ process_language_node (xmlTextReaderPtr  reader,
                tmp = xmlTextReaderGetAttribute (reader, BAD_CAST "section");
 
                if (tmp == NULL)
-                       lang->section = g_strdup (DEFAULT_SECTION);
+                       lang->priv->section = g_strdup (DEFAULT_SECTION);
                else
-                       lang->section = g_strdup ((gchar *) tmp);
+                       lang->priv->section = g_strdup ((gchar *) tmp);
 
                xmlFree (tmp);
        }
        else
        {
-               lang->section = _gtk_source_language_translate_string (lang, (gchar*) tmp);
+               lang->priv->section = _gtk_source_language_translate_string (lang, (gchar*) tmp);
                xmlFree (tmp);
        }
 
@@ -471,11 +446,11 @@ process_language_node (xmlTextReaderPtr  reader,
 
        if (xmlStrcmp (version , BAD_CAST "1.0") == 0)
        {
-               lang->version = GTK_SOURCE_LANGUAGE_VERSION_1_0;
+               lang->priv->version = GTK_SOURCE_LANGUAGE_VERSION_1_0;
        }
        else if (xmlStrcmp (version, BAD_CAST "2.0") == 0)
        {
-               lang->version = GTK_SOURCE_LANGUAGE_VERSION_2_0;
+               lang->priv->version = GTK_SOURCE_LANGUAGE_VERSION_2_0;
        }
        else
        {
@@ -488,7 +463,7 @@ process_language_node (xmlTextReaderPtr  reader,
 
        xmlFree (version);
 
-       if (lang->version == GTK_SOURCE_LANGUAGE_VERSION_2_0)
+       if (lang->priv->version == GTK_SOURCE_LANGUAGE_VERSION_2_0)
                process_properties (reader, lang);
 
        return lang;
@@ -496,11 +471,11 @@ process_language_node (xmlTextReaderPtr  reader,
 
 gchar *
 _gtk_source_language_translate_string (GtkSourceLanguage *language,
-                                       const gchar       *string)
+                                      const gchar       *string)
 {
        g_return_val_if_fail (string != NULL, NULL);
 
-       return _gtk_source_utils_dgettext (language->translation_domain, string);
+       return _gtk_source_utils_dgettext (language->priv->translation_domain, string);
 }
 
 /**
@@ -517,9 +492,9 @@ const gchar *
 gtk_source_language_get_id (GtkSourceLanguage *language)
 {
        g_return_val_if_fail (GTK_SOURCE_IS_LANGUAGE (language), NULL);
-       g_return_val_if_fail (language->id != NULL, NULL);
+       g_return_val_if_fail (language->priv->id != NULL, NULL);
 
-       return language->id;
+       return language->priv->id;
 }
 
 /**
@@ -536,9 +511,9 @@ const gchar *
 gtk_source_language_get_name (GtkSourceLanguage *language)
 {
        g_return_val_if_fail (GTK_SOURCE_IS_LANGUAGE (language), NULL);
-       g_return_val_if_fail (language->name != NULL, NULL);
+       g_return_val_if_fail (language->priv->name != NULL, NULL);
 
-       return language->name;
+       return language->priv->name;
 }
 
 /**
@@ -554,12 +529,12 @@ gtk_source_language_get_name (GtkSourceLanguage *language)
  * Returns: the section of @language.
  **/
 const gchar *
-gtk_source_language_get_section (GtkSourceLanguage *language)
+gtk_source_language_get_section        (GtkSourceLanguage *language)
 {
        g_return_val_if_fail (GTK_SOURCE_IS_LANGUAGE (language), NULL);
-       g_return_val_if_fail (language->section != NULL, NULL);
+       g_return_val_if_fail (language->priv->section != NULL, NULL);
 
-       return language->section;
+       return language->priv->section;
 }
 
 /**
@@ -575,7 +550,7 @@ gtk_source_language_get_hidden (GtkSourceLanguage *language)
 {
        g_return_val_if_fail (GTK_SOURCE_IS_LANGUAGE (language), FALSE);
 
-       return language->hidden;
+       return language->priv->hidden;
 }
 
 /**
@@ -591,12 +566,12 @@ gtk_source_language_get_hidden (GtkSourceLanguage *language)
  **/
 const gchar *
 gtk_source_language_get_metadata (GtkSourceLanguage *language,
-                                  const gchar       *name)
+                                 const gchar       *name)
 {
        g_return_val_if_fail (GTK_SOURCE_IS_LANGUAGE (language), NULL);
        g_return_val_if_fail (name != NULL, NULL);
 
-       return g_hash_table_lookup (language->properties, name);
+       return g_hash_table_lookup (language->priv->properties, name);
 }
 
 /**
@@ -664,17 +639,17 @@ GtkSourceLanguageManager *
 _gtk_source_language_get_language_manager (GtkSourceLanguage *language)
 {
        g_return_val_if_fail (GTK_SOURCE_IS_LANGUAGE (language), NULL);
-       g_return_val_if_fail (language->id != NULL, NULL);
+       g_return_val_if_fail (language->priv->id != NULL, NULL);
 
-       return language->language_manager;
+       return language->priv->language_manager;
 }
 
 /* Highlighting engine creation ------------------------------------------ */
 
 static void
 copy_style_info (const char         *style_id,
-                 GtkSourceStyleInfo *info,
-                 GHashTable         *dest)
+                GtkSourceStyleInfo *info,
+                GHashTable         *dest)
 {
        g_hash_table_insert (dest, g_strdup (style_id),
                             _gtk_source_style_info_copy (info));
@@ -707,7 +682,7 @@ _gtk_source_language_define_language_styles (GtkSourceLanguage *lang)
 
                info = _gtk_source_style_info_new (alias[i][0], alias[i][1]);
 
-               g_hash_table_insert (lang->styles,
+               g_hash_table_insert (lang->priv->styles,
                                     g_strdup (alias[i][0]),
                                     info);
 
@@ -723,9 +698,9 @@ _gtk_source_language_define_language_styles (GtkSourceLanguage *lang)
        if (def_lang != NULL)
        {
                force_styles (def_lang);
-               g_hash_table_foreach (def_lang->styles,
+               g_hash_table_foreach (def_lang->priv->styles,
                                      (GHFunc) copy_style_info,
-                                     lang->styles);
+                                     lang->priv->styles);
        }
 }
 
@@ -733,12 +708,12 @@ _gtk_source_language_define_language_styles (GtkSourceLanguage *lang)
 static GtkSourceContextData *
 gtk_source_language_parse_file (GtkSourceLanguage *language)
 {
-       if (language->ctx_data == NULL)
+       if (language->priv->ctx_data == NULL)
        {
                gboolean success = FALSE;
                GtkSourceContextData *ctx_data;
 
-               if (language->language_manager == NULL)
+               if (language->priv->language_manager == NULL)
                {
                        g_critical ("_gtk_source_language_create_engine() is called after "
                                    "language manager was finalized");
@@ -747,7 +722,7 @@ gtk_source_language_parse_file (GtkSourceLanguage *language)
                {
                        ctx_data = _gtk_source_context_data_new (language);
 
-                       switch (language->version)
+                       switch (language->priv->version)
                        {
                                case GTK_SOURCE_LANGUAGE_VERSION_1_0:
                                        g_warning ("The language definition format version 1 "
@@ -767,15 +742,15 @@ gtk_source_language_parse_file (GtkSourceLanguage *language)
                        if (!success)
                                _gtk_source_context_data_unref (ctx_data);
                        else
-                               language->ctx_data = ctx_data;
+                               language->priv->ctx_data = ctx_data;
                }
        }
        else
        {
-               _gtk_source_context_data_ref (language->ctx_data);
+               _gtk_source_context_data_ref (language->priv->ctx_data);
        }
 
-       return language->ctx_data;
+       return language->priv->ctx_data;
 }
 
 GtkSourceEngine *
@@ -795,16 +770,16 @@ _gtk_source_language_create_engine (GtkSourceLanguage *language)
        return ce ? GTK_SOURCE_ENGINE (ce) : NULL;
 }
 
-typedef struct
+typedef struct _AddStyleIdData AddStyleIdData;
+
+struct _AddStyleIdData
 {
-       gchar     *language_id;
-       GPtrArray *ids_array;
-} AddStyleIdData;
+       gchar             *language_id;
+       GPtrArray         *ids_array;
+};
 
 static void
-add_style_id (gchar                  *id,
-              G_GNUC_UNUSED gpointer  value,
-              AddStyleIdData         *data)
+add_style_id (gchar *id, G_GNUC_UNUSED gpointer value, AddStyleIdData *data)
 {
        if (g_str_has_prefix (id, data->language_id))
                g_ptr_array_add (data->ids_array, g_strdup (id));
@@ -816,14 +791,14 @@ get_style_ids (GtkSourceLanguage *language)
        GPtrArray *ids_array;
        AddStyleIdData data;
 
-       g_return_val_if_fail (language->styles != NULL, NULL);
+       g_return_val_if_fail (language->priv->styles != NULL, NULL);
 
        ids_array = g_ptr_array_new ();
 
-       data.language_id = g_strdup_printf ("%s:", language->id);
+       data.language_id = g_strdup_printf ("%s:", language->priv->id);
        data.ids_array = ids_array;
 
-       g_hash_table_foreach (language->styles,
+       g_hash_table_foreach (language->priv->styles,
                              (GHFunc) add_style_id,
                              &data);
 
@@ -852,7 +827,7 @@ force_styles (GtkSourceLanguage *language)
         * as if we were to create an engine. In the future we can improve
         * this by parsing styles only.
         */
-       if (!language->styles_loaded && language->ctx_data == NULL)
+       if (!language->priv->styles_loaded && language->priv->ctx_data == NULL)
        {
                GtkSourceContextData *ctx_data;
 
@@ -860,7 +835,7 @@ force_styles (GtkSourceLanguage *language)
                if (ctx_data == NULL)
                        return FALSE;
 
-               language->styles_loaded = TRUE;
+               language->priv->styles_loaded = TRUE;
                _gtk_source_context_data_unref (ctx_data);
        }
 
@@ -882,7 +857,7 @@ gchar **
 gtk_source_language_get_style_ids (GtkSourceLanguage *language)
 {
        g_return_val_if_fail (GTK_SOURCE_IS_LANGUAGE (language), NULL);
-       g_return_val_if_fail (language->id != NULL, NULL);
+       g_return_val_if_fail (language->priv->id != NULL, NULL);
 
        if (!force_styles (language))
                return NULL;
@@ -891,17 +866,16 @@ gtk_source_language_get_style_ids (GtkSourceLanguage *language)
 }
 
 static GtkSourceStyleInfo *
-get_style_info (GtkSourceLanguage *language,
-                const char        *style_id)
+get_style_info (GtkSourceLanguage *language, const char *style_id)
 {
        GtkSourceStyleInfo *info;
 
        if (!force_styles (language))
                return NULL;
 
-       g_return_val_if_fail (language->styles != NULL, NULL);
+       g_return_val_if_fail (language->priv->styles != NULL, NULL);
 
-       info = g_hash_table_lookup (language->styles, style_id);
+       info = g_hash_table_lookup (language->priv->styles, style_id);
 
        return info;
 }
@@ -920,12 +894,12 @@ get_style_info (GtkSourceLanguage *language,
  */
 const gchar *
 gtk_source_language_get_style_name (GtkSourceLanguage *language,
-                                    const gchar       *style_id)
+                                   const gchar       *style_id)
 {
        GtkSourceStyleInfo *info;
 
        g_return_val_if_fail (GTK_SOURCE_IS_LANGUAGE (language), NULL);
-       g_return_val_if_fail (language->id != NULL, NULL);
+       g_return_val_if_fail (language->priv->id != NULL, NULL);
        g_return_val_if_fail (style_id != NULL, NULL);
 
        info = get_style_info (language, style_id);
@@ -950,12 +924,12 @@ gtk_source_language_get_style_name (GtkSourceLanguage *language,
  */
 const gchar *
 gtk_source_language_get_style_fallback (GtkSourceLanguage *language,
-                                        const gchar       *style_id)
+                                       const gchar       *style_id)
 {
        GtkSourceStyleInfo *info;
 
        g_return_val_if_fail (GTK_SOURCE_IS_LANGUAGE (language), NULL);
-       g_return_val_if_fail (language->id != NULL, NULL);
+       g_return_val_if_fail (language->priv->id != NULL, NULL);
        g_return_val_if_fail (style_id != NULL, NULL);
 
        info = get_style_info (language, style_id);
@@ -966,8 +940,7 @@ gtk_source_language_get_style_fallback (GtkSourceLanguage *language,
 /* Utility functions for GtkSourceStyleInfo */
 
 GtkSourceStyleInfo *
-_gtk_source_style_info_new (const gchar *name,
-                            const gchar *map_to)
+_gtk_source_style_info_new (const gchar *name, const gchar *map_to)
 {
        GtkSourceStyleInfo *info = g_new0 (GtkSourceStyleInfo, 1);
 
@@ -981,7 +954,6 @@ GtkSourceStyleInfo *
 _gtk_source_style_info_copy (GtkSourceStyleInfo *info)
 {
        g_return_val_if_fail (info != NULL, NULL);
-
        return _gtk_source_style_info_new (info->name, info->map_to);
 }
 
@@ -989,34 +961,11 @@ void
 _gtk_source_style_info_free (GtkSourceStyleInfo *info)
 {
        if (info == NULL)
-       {
                return;
-       }
 
        g_free (info->name);
        g_free (info->map_to);
-       g_free (info);
-}
-
 
-void
-_gtk_source_language_clear_ctx_data (GtkSourceLanguage    *language,
-                                     GtkSourceContextData *ctx_data)
-{
-       if (language->ctx_data == ctx_data)
-       {
-               language->ctx_data = NULL;
-       }
-}
-
-const gchar *
-_gtk_source_language_get_file_name (GtkSourceLanguage *language)
-{
-       return language->lang_file_name;
+       g_free (info);
 }
 
-GHashTable *
-_gtk_source_language_get_styles (GtkSourceLanguage *language)
-{
-       return language->styles;
-}
diff --git a/gtksourceview/gtksourcelanguage.h b/gtksourceview/gtksourcelanguage.h
index f27dbfc3..c1c5b1c6 100644
--- a/gtksourceview/gtksourcelanguage.h
+++ b/gtksourceview/gtksourcelanguage.h
@@ -2,7 +2,7 @@
  *
  * This file is part of GtkSourceView
  *
- * Copyright 2003 - Paolo Maggi <paolo maggi polito it>
+ * Copyright (C) 2003 - Paolo Maggi <paolo maggi polito it>
  *
  * GtkSourceView is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -18,7 +18,8 @@
  * along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#pragma once
+#ifndef GTK_SOURCE_LANGUAGE_H
+#define GTK_SOURCE_LANGUAGE_H
 
 #if !defined (GTK_SOURCE_H_INSIDE) && !defined (GTK_SOURCE_COMPILATION)
 #error "Only <gtksourceview/gtksource.h> can be included directly."
@@ -30,33 +31,69 @@
 
 G_BEGIN_DECLS
 
-#define GTK_SOURCE_TYPE_LANGUAGE (gtk_source_language_get_type())
+#define GTK_SOURCE_TYPE_LANGUAGE               (gtk_source_language_get_type ())
+#define GTK_SOURCE_LANGUAGE(obj)               (G_TYPE_CHECK_INSTANCE_CAST((obj), GTK_SOURCE_TYPE_LANGUAGE, 
GtkSourceLanguage))
+#define GTK_SOURCE_LANGUAGE_CLASS(klass)       (G_TYPE_CHECK_CLASS_CAST((klass), GTK_SOURCE_TYPE_LANGUAGE, 
GtkSourceLanguageClass))
+#define GTK_SOURCE_IS_LANGUAGE(obj)            (G_TYPE_CHECK_INSTANCE_TYPE((obj), GTK_SOURCE_TYPE_LANGUAGE))
+#define GTK_SOURCE_IS_LANGUAGE_CLASS(klass)    (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_SOURCE_TYPE_LANGUAGE))
+#define GTK_SOURCE_LANGUAGE_GET_CLASS(obj)      (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_SOURCE_TYPE_LANGUAGE, 
GtkSourceLanguageClass))
+
+
+typedef struct _GtkSourceLanguageClass         GtkSourceLanguageClass;
+typedef struct _GtkSourceLanguagePrivate       GtkSourceLanguagePrivate;
+
+struct _GtkSourceLanguage
+{
+       GObject parent_instance;
+
+       GtkSourceLanguagePrivate *priv;
+};
+
+struct _GtkSourceLanguageClass
+{
+       GObjectClass parent_class;
+
+       /* Padding for future expansion */
+       gpointer padding[10];
+};
 
 GTK_SOURCE_AVAILABLE_IN_ALL
-G_DECLARE_FINAL_TYPE (GtkSourceLanguage, gtk_source_language, GTK_SOURCE, LANGUAGE, GObject)
+GType            gtk_source_language_get_type          (void) G_GNUC_CONST;
 
 GTK_SOURCE_AVAILABLE_IN_ALL
-const gchar  *gtk_source_language_get_id             (GtkSourceLanguage *language);
+const gchar     *gtk_source_language_get_id            (GtkSourceLanguage *language);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-const gchar  *gtk_source_language_get_name           (GtkSourceLanguage *language);
+const gchar     *gtk_source_language_get_name          (GtkSourceLanguage *language);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-const gchar  *gtk_source_language_get_section        (GtkSourceLanguage *language);
+const gchar     *gtk_source_language_get_section       (GtkSourceLanguage *language);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-gboolean      gtk_source_language_get_hidden         (GtkSourceLanguage *language);
+gboolean         gtk_source_language_get_hidden        (GtkSourceLanguage *language);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-const gchar  *gtk_source_language_get_metadata       (GtkSourceLanguage *language,
-                                                      const gchar       *name);
+const gchar     *gtk_source_language_get_metadata      (GtkSourceLanguage *language,
+                                                        const gchar       *name);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-gchar       **gtk_source_language_get_mime_types     (GtkSourceLanguage *language);
+gchar          **gtk_source_language_get_mime_types    (GtkSourceLanguage *language);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-gchar       **gtk_source_language_get_globs          (GtkSourceLanguage *language);
+gchar          **gtk_source_language_get_globs         (GtkSourceLanguage *language);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-gchar       **gtk_source_language_get_style_ids      (GtkSourceLanguage *language);
+gchar          **gtk_source_language_get_style_ids     (GtkSourceLanguage *language);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-const gchar  *gtk_source_language_get_style_name     (GtkSourceLanguage *language,
-                                                      const gchar       *style_id);
+const gchar    *gtk_source_language_get_style_name     (GtkSourceLanguage *language,
+                                                        const gchar       *style_id);
+
 GTK_SOURCE_AVAILABLE_IN_3_4
-const gchar  *gtk_source_language_get_style_fallback (GtkSourceLanguage *language,
-                                                      const gchar       *style_id);
+const gchar    *gtk_source_language_get_style_fallback (GtkSourceLanguage *language,
+                                                        const gchar       *style_id);
 
 G_END_DECLS
+
+#endif /* GTK_SOURCE_LANGUAGE_H */
+
diff --git a/gtksourceview/gtksourcelanguagemanager-private.h 
b/gtksourceview/gtksourcelanguagemanager-private.h
index 3579d13c..e90836f6 100644
--- a/gtksourceview/gtksourcelanguagemanager-private.h
+++ b/gtksourceview/gtksourcelanguagemanager-private.h
@@ -2,7 +2,7 @@
  *
  * This file is part of GtkSourceView
  *
- * Copyright 2003 - Paolo Maggi <paolo maggi polito it>
+ * Copyright (C) 2003 - Paolo Maggi <paolo maggi polito it>
  *
  * GtkSourceView is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -18,7 +18,8 @@
  * along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#pragma once
+#ifndef GTK_SOURCE_LANGUAGE_MANAGER_PRIVATE_H
+#define GTK_SOURCE_LANGUAGE_MANAGER_PRIVATE_H
 
 #include "gtksourcelanguagemanager.h"
 
@@ -28,3 +29,5 @@ G_GNUC_INTERNAL
 GtkSourceLanguageManager *_gtk_source_language_manager_peek_default (void);
 
 G_END_DECLS
+
+#endif /* GTK_SOURCE_LANGUAGE_MANAGER_PRIVATE_H */
diff --git a/gtksourceview/gtksourcelanguagemanager.c b/gtksourceview/gtksourcelanguagemanager.c
index 3ac329fd..17d6dc40 100644
--- a/gtksourceview/gtksourcelanguagemanager.c
+++ b/gtksourceview/gtksourcelanguagemanager.c
@@ -2,7 +2,7 @@
 /*
  * This file is part of GtkSourceView
  *
- * Copyright 2003-2007 - Paolo Maggi <paolo maggi polito it>
+ * Copyright (C) 2003-2007 - Paolo Maggi <paolo maggi polito it>
  *
  * GtkSourceView is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -18,13 +18,16 @@
  * along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "config.h"
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
 
 #include <string.h>
 #include <gio/gio.h>
 
 #include "gtksourcelanguage.h"
 #include "gtksourcelanguage-private.h"
+#include "gtksourcelanguagemanager.h"
 #include "gtksourcelanguagemanager-private.h"
 #include "gtksourceutils-private.h"
 
@@ -43,9 +46,9 @@
  * given file name and content type.
  */
 
-#define RNG_SCHEMA_FILE   "language2.rng"
-#define LANGUAGE_DIR      "language-specs"
-#define LANG_FILE_SUFFIX  ".lang"
+#define RNG_SCHEMA_FILE                "language2.rng"
+#define LANGUAGE_DIR           "language-specs"
+#define LANG_FILE_SUFFIX       ".lang"
 
 enum {
        PROP_0,
@@ -53,10 +56,8 @@ enum {
        PROP_LANGUAGE_IDS
 };
 
-struct _GtkSourceLanguageManager
+struct _GtkSourceLanguageManagerPrivate
 {
-       GObject          parent_instance;
-
        GHashTable      *language_ids;
 
        gchar          **lang_dirs;
@@ -67,13 +68,13 @@ struct _GtkSourceLanguageManager
 
 static GtkSourceLanguageManager *default_instance;
 
-G_DEFINE_TYPE (GtkSourceLanguageManager, gtk_source_language_manager, G_TYPE_OBJECT)
+G_DEFINE_TYPE_WITH_PRIVATE (GtkSourceLanguageManager, gtk_source_language_manager, G_TYPE_OBJECT)
 
 static void
-gtk_source_language_manager_set_property (GObject      *object,
-                                          guint         prop_id,
-                                          const GValue *value,
-                                          GParamSpec   *pspec)
+gtk_source_language_manager_set_property (GObject      *object,
+                                         guint          prop_id,
+                                         const GValue *value,
+                                         GParamSpec    *pspec)
 {
        GtkSourceLanguageManager *lm;
 
@@ -92,10 +93,10 @@ gtk_source_language_manager_set_property (GObject      *object,
 }
 
 static void
-gtk_source_language_manager_get_property (GObject    *object,
-                                          guint       prop_id,
-                                          GValue     *value,
-                                          GParamSpec *pspec)
+gtk_source_language_manager_get_property (GObject      *object,
+                                         guint          prop_id,
+                                         GValue        *value,
+                                         GParamSpec    *pspec)
 {
        GtkSourceLanguageManager *lm;
 
@@ -120,15 +121,17 @@ gtk_source_language_manager_get_property (GObject    *object,
 static void
 gtk_source_language_manager_finalize (GObject *object)
 {
-       GtkSourceLanguageManager *lm = GTK_SOURCE_LANGUAGE_MANAGER (object);
+       GtkSourceLanguageManager *lm;
 
-       if (lm->language_ids)
-               g_hash_table_destroy (lm->language_ids);
+       lm = GTK_SOURCE_LANGUAGE_MANAGER (object);
+
+       if (lm->priv->language_ids)
+               g_hash_table_destroy (lm->priv->language_ids);
 
-       g_strfreev (lm->ids);
+       g_strfreev (lm->priv->ids);
 
-       g_strfreev (lm->lang_dirs);
-       g_free (lm->rng_file);
+       g_strfreev (lm->priv->lang_dirs);
+       g_free (lm->priv->rng_file);
 
        G_OBJECT_CLASS (gtk_source_language_manager_parent_class)->finalize (object);
 }
@@ -167,11 +170,11 @@ gtk_source_language_manager_class_init (GtkSourceLanguageManagerClass *klass)
 static void
 gtk_source_language_manager_init (GtkSourceLanguageManager *lm)
 {
-       lm = gtk_source_language_manager_get_instance_private (lm);
-       lm->language_ids = NULL;
-       lm->ids = NULL;
-       lm->lang_dirs = NULL;
-       lm->rng_file = NULL;
+       lm->priv = gtk_source_language_manager_get_instance_private (lm);
+       lm->priv->language_ids = NULL;
+       lm->priv->ids = NULL;
+       lm->priv->lang_dirs = NULL;
+       lm->priv->rng_file = NULL;
 }
 
 /**
@@ -243,8 +246,8 @@ notify_search_path (GtkSourceLanguageManager *mgr)
  * </note>
  */
 void
-gtk_source_language_manager_set_search_path (GtkSourceLanguageManager  *lm,
-                                             gchar                    **dirs)
+gtk_source_language_manager_set_search_path (GtkSourceLanguageManager *lm,
+                                            gchar                   **dirs)
 {
        gchar **tmp;
 
@@ -252,14 +255,14 @@ gtk_source_language_manager_set_search_path (GtkSourceLanguageManager  *lm,
 
        /* Search path cannot be changed in the list of available languages
         * as been already computed */
-       g_return_if_fail (lm->ids == NULL);
+       g_return_if_fail (lm->priv->ids == NULL);
 
-       tmp = lm->lang_dirs;
+       tmp = lm->priv->lang_dirs;
 
        if (dirs == NULL)
-               lm->lang_dirs = _gtk_source_utils_get_default_dirs (LANGUAGE_DIR);
+               lm->priv->lang_dirs = _gtk_source_utils_get_default_dirs (LANGUAGE_DIR);
        else
-               lm->lang_dirs = g_strdupv (dirs);
+               lm->priv->lang_dirs = g_strdupv (dirs);
 
        g_strfreev (tmp);
 
@@ -281,10 +284,10 @@ gtk_source_language_manager_get_search_path (GtkSourceLanguageManager *lm)
 {
        g_return_val_if_fail (GTK_SOURCE_IS_LANGUAGE_MANAGER (lm), NULL);
 
-       if (lm->lang_dirs == NULL)
-               lm->lang_dirs = _gtk_source_utils_get_default_dirs (LANGUAGE_DIR);
+       if (lm->priv->lang_dirs == NULL)
+               lm->priv->lang_dirs = _gtk_source_utils_get_default_dirs (LANGUAGE_DIR);
 
-       return (const gchar * const *)lm->lang_dirs;
+       return (const gchar * const *)lm->priv->lang_dirs;
 }
 
 /**
@@ -300,7 +303,7 @@ _gtk_source_language_manager_get_rng_file (GtkSourceLanguageManager *lm)
 {
        g_return_val_if_fail (GTK_SOURCE_IS_LANGUAGE_MANAGER (lm), NULL);
 
-       if (lm->rng_file == NULL)
+       if (lm->priv->rng_file == NULL)
        {
                const gchar * const *dirs;
 
@@ -313,7 +316,7 @@ _gtk_source_language_manager_get_rng_file (GtkSourceLanguageManager *lm)
                        file = g_build_filename (*dirs, RNG_SCHEMA_FILE, NULL);
                        if (g_file_test (file, G_FILE_TEST_EXISTS))
                        {
-                               lm->rng_file = file;
+                               lm->priv->rng_file = file;
                                break;
                        }
 
@@ -321,13 +324,11 @@ _gtk_source_language_manager_get_rng_file (GtkSourceLanguageManager *lm)
                }
        }
 
-       return lm->rng_file;
+       return lm->priv->rng_file;
 }
 
 static gint
-language_compare (const gchar **id1,
-                  const gchar **id2,
-                  GHashTable   *language_ids)
+language_compare (const gchar **id1, const gchar **id2, GHashTable *language_ids)
 {
        GtkSourceLanguage *lang1, *lang2;
        const gchar *name1, *name2;
@@ -347,10 +348,10 @@ ensure_languages (GtkSourceLanguageManager *lm)
        GSList *filenames, *l;
        GPtrArray *ids_array = NULL;
 
-       if (lm->language_ids != NULL)
+       if (lm->priv->language_ids != NULL)
                return;
 
-       lm->language_ids = g_hash_table_new_full (g_str_hash, g_str_equal,
+       lm->priv->language_ids = g_hash_table_new_full (g_str_hash, g_str_equal,
                                                        g_free, g_object_unref);
 
        filenames = _gtk_source_utils_get_file_list ((gchar **)gtk_source_language_manager_get_search_path 
(lm),
@@ -360,7 +361,6 @@ ensure_languages (GtkSourceLanguageManager *lm)
        for (l = filenames; l != NULL; l = l->next)
        {
                GtkSourceLanguage *lang;
-               const gchar *id;
                gchar *filename;
 
                filename = l->data;
@@ -373,18 +373,16 @@ ensure_languages (GtkSourceLanguageManager *lm)
                        continue;
                }
 
-               id = gtk_source_language_get_id (lang);
-
-               if (g_hash_table_lookup (lm->language_ids, id) == NULL)
+               if (g_hash_table_lookup (lm->priv->language_ids, lang->priv->id) == NULL)
                {
-                       g_hash_table_insert (lm->language_ids,
-                                            g_strdup (id),
+                       g_hash_table_insert (lm->priv->language_ids,
+                                            g_strdup (lang->priv->id),
                                             lang);
 
                        if (ids_array == NULL)
                                ids_array = g_ptr_array_new ();
 
-                       g_ptr_array_add (ids_array, g_strdup (id));
+                       g_ptr_array_add (ids_array, g_strdup (lang->priv->id));
                }
                else
                {
@@ -398,12 +396,12 @@ ensure_languages (GtkSourceLanguageManager *lm)
                 * is ready to use in a list of a GUI */
                g_ptr_array_sort_with_data (ids_array,
                                            (GCompareDataFunc)language_compare,
-                                           lm->language_ids);
+                                           lm->priv->language_ids);
 
                /* Ensure the array is NULL terminated */
                g_ptr_array_add (ids_array, NULL);
 
-               lm->ids = (gchar **)g_ptr_array_free (ids_array, FALSE);
+               lm->priv->ids = (gchar **)g_ptr_array_free (ids_array, FALSE);
        }
 
        g_slist_free_full (filenames, g_free);
@@ -428,7 +426,7 @@ gtk_source_language_manager_get_language_ids (GtkSourceLanguageManager *lm)
 
        ensure_languages (lm);
 
-       return (const gchar * const *)lm->ids;
+       return (const gchar * const *)lm->priv->ids;
 }
 
 /**
@@ -445,19 +443,19 @@ gtk_source_language_manager_get_language_ids (GtkSourceLanguageManager *lm)
  */
 GtkSourceLanguage *
 gtk_source_language_manager_get_language (GtkSourceLanguageManager *lm,
-                                          const gchar              *id)
+                                         const gchar              *id)
 {
        g_return_val_if_fail (GTK_SOURCE_IS_LANGUAGE_MANAGER (lm), NULL);
        g_return_val_if_fail (id != NULL, NULL);
 
        ensure_languages (lm);
 
-       return g_hash_table_lookup (lm->language_ids, id);
+       return g_hash_table_lookup (lm->priv->language_ids, id);
 }
 
 static GSList *
 pick_langs_for_filename (GtkSourceLanguageManager *lm,
-                         const gchar              *filename)
+                        const gchar              *filename)
 {
        char *filename_utf8;
        const gchar* const * p;
@@ -499,8 +497,8 @@ pick_langs_for_filename (GtkSourceLanguageManager *lm,
 
 static GtkSourceLanguage *
 pick_lang_for_mime_type_pass (GtkSourceLanguageManager *lm,
-                              const char               *mime_type,
-                              gboolean                  exact_match)
+                             const char               *mime_type,
+                             gboolean                  exact_match)
 {
        const gchar* const * id_ptr;
 
@@ -538,7 +536,7 @@ pick_lang_for_mime_type_pass (GtkSourceLanguageManager *lm,
 
 static GtkSourceLanguage *
 pick_lang_for_mime_type_real (GtkSourceLanguageManager *lm,
-                              const char               *mime_type)
+                             const char               *mime_type)
 {
        GtkSourceLanguage *lang;
        lang = pick_lang_for_mime_type_pass (lm, mime_type, TRUE);
@@ -550,8 +548,8 @@ pick_lang_for_mime_type_real (GtkSourceLanguageManager *lm,
 #ifdef G_OS_WIN32
 static void
 grok_win32_content_type (const gchar  *content_type,
-                         gchar       **alt_filename,
-                         gchar       **mime_type)
+                        gchar       **alt_filename,
+                        gchar       **mime_type)
 {
        *alt_filename = NULL;
        *mime_type = NULL;
@@ -567,7 +565,7 @@ grok_win32_content_type (const gchar  *content_type,
 
 static GtkSourceLanguage *
 pick_lang_for_mime_type (GtkSourceLanguageManager *lm,
-                         const gchar              *content_type)
+                        const gchar              *content_type)
 {
        GtkSourceLanguage *lang = NULL;
 
@@ -647,8 +645,8 @@ pick_lang_for_mime_type (GtkSourceLanguageManager *lm,
  */
 GtkSourceLanguage *
 gtk_source_language_manager_guess_language (GtkSourceLanguageManager *lm,
-                                            const gchar              *filename,
-                                            const gchar              *content_type)
+                                           const gchar              *filename,
+                                           const gchar              *content_type)
 {
        GtkSourceLanguage *lang = NULL;
        GSList *langs = NULL;
diff --git a/gtksourceview/gtksourcelanguagemanager.h b/gtksourceview/gtksourcelanguagemanager.h
index 0c84deb9..df610c42 100644
--- a/gtksourceview/gtksourcelanguagemanager.h
+++ b/gtksourceview/gtksourcelanguagemanager.h
@@ -2,7 +2,7 @@
  *
  * This file is part of GtkSourceView
  *
- * Copyright 2003 - Paolo Maggi <paolo maggi polito it>
+ * Copyright (C) 2003 - Paolo Maggi <paolo maggi polito it>
  *
  * GtkSourceView is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -18,7 +18,8 @@
  * along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#pragma once
+#ifndef GTK_SOURCE_LANGUAGE_MANAGER_H
+#define GTK_SOURCE_LANGUAGE_MANAGER_H
 
 #if !defined (GTK_SOURCE_H_INSIDE) && !defined (GTK_SOURCE_COMPILATION)
 #error "Only <gtksourceview/gtksource.h> can be included directly."
@@ -30,28 +31,60 @@
 
 G_BEGIN_DECLS
 
-#define GTK_SOURCE_TYPE_LANGUAGE_MANAGER (gtk_source_language_manager_get_type())
+#define GTK_SOURCE_TYPE_LANGUAGE_MANAGER               (gtk_source_language_manager_get_type ())
+#define GTK_SOURCE_LANGUAGE_MANAGER(obj)               (G_TYPE_CHECK_INSTANCE_CAST((obj), 
GTK_SOURCE_TYPE_LANGUAGE_MANAGER, GtkSourceLanguageManager))
+#define GTK_SOURCE_LANGUAGE_MANAGER_CLASS(klass)       (G_TYPE_CHECK_CLASS_CAST((klass), 
GTK_SOURCE_TYPE_LANGUAGE_MANAGER, GtkSourceLanguageManagerClass))
+#define GTK_SOURCE_IS_LANGUAGE_MANAGER(obj)            (G_TYPE_CHECK_INSTANCE_TYPE((obj), 
GTK_SOURCE_TYPE_LANGUAGE_MANAGER))
+#define GTK_SOURCE_IS_LANGUAGE_MANAGER_CLASS(klass)    (G_TYPE_CHECK_CLASS_TYPE ((klass), 
GTK_SOURCE_TYPE_LANGUAGE_MANAGER))
+#define GTK_SOURCE_LANGUAGE_MANAGER_GET_CLASS(obj)     (G_TYPE_INSTANCE_GET_CLASS((obj), 
GTK_SOURCE_TYPE_LANGUAGE_MANAGER, GtkSourceLanguageManagerClass))
+
+
+typedef struct _GtkSourceLanguageManagerClass  GtkSourceLanguageManagerClass;
+typedef struct _GtkSourceLanguageManagerPrivate GtkSourceLanguageManagerPrivate;
+
+struct _GtkSourceLanguageManager
+{
+       GObject parent_instance;
+
+       GtkSourceLanguageManagerPrivate *priv;
+};
+
+struct _GtkSourceLanguageManagerClass
+{
+       GObjectClass parent_class;
+
+  /*< private >*/
+       gpointer _reserved[10];
+};
 
 GTK_SOURCE_AVAILABLE_IN_ALL
-G_DECLARE_FINAL_TYPE (GtkSourceLanguageManager, gtk_source_language_manager, GTK_SOURCE, LANGUAGE_MANAGER, 
GObject)
+GType                    gtk_source_language_manager_get_type                  (void) G_GNUC_CONST;
 
 GTK_SOURCE_AVAILABLE_IN_ALL
-GtkSourceLanguageManager *gtk_source_language_manager_new              (void);
+GtkSourceLanguageManager *gtk_source_language_manager_new                      (void);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-GtkSourceLanguageManager *gtk_source_language_manager_get_default      (void);
+GtkSourceLanguageManager *gtk_source_language_manager_get_default              (void);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-const gchar * const      *gtk_source_language_manager_get_search_path  (GtkSourceLanguageManager  *lm);
+const gchar * const *    gtk_source_language_manager_get_search_path           (GtkSourceLanguageManager 
*lm);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-void                      gtk_source_language_manager_set_search_path  (GtkSourceLanguageManager  *lm,
-                                                                        gchar                    **dirs);
+void                     gtk_source_language_manager_set_search_path           (GtkSourceLanguageManager *lm,
+                                                                                gchar                   
**dirs);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-const gchar * const      *gtk_source_language_manager_get_language_ids (GtkSourceLanguageManager  *lm);
+const gchar * const *    gtk_source_language_manager_get_language_ids          (GtkSourceLanguageManager 
*lm);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-GtkSourceLanguage        *gtk_source_language_manager_get_language     (GtkSourceLanguageManager  *lm,
-                                                                        const gchar               *id);
+GtkSourceLanguage       *gtk_source_language_manager_get_language              (GtkSourceLanguageManager *lm,
+                                                                                const gchar              
*id);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-GtkSourceLanguage        *gtk_source_language_manager_guess_language   (GtkSourceLanguageManager  *lm,
-                                                                        const gchar               *filename,
-                                                                        const gchar               
*content_type);
+GtkSourceLanguage       *gtk_source_language_manager_guess_language            (GtkSourceLanguageManager *lm,
+                                                                                const gchar              
*filename,
+                                                                                const gchar              
*content_type);
 
 G_END_DECLS
+
+#endif /* GTK_SOURCE_LANGUAGE_MANAGER_H */
diff --git a/gtksourceview/gtksourcecompletioncontainer-private.h b/gtksourceview/gtksourcelines-private.h
similarity index 54%
rename from gtksourceview/gtksourcecompletioncontainer-private.h
rename to gtksourceview/gtksourcelines-private.h
index dbb5af44..402fbcdf 100644
--- a/gtksourceview/gtksourcecompletioncontainer-private.h
+++ b/gtksourceview/gtksourcelines-private.h
@@ -1,8 +1,8 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; coding: utf-8 -*-
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; coding: utf-8 -*- /
  *
  * This file is part of GtkSourceView
  *
- * Copyright 2013 - Sébastien Wilmet <swilmet gnome org>
+ * Copyright (C) 2019 - Christian Hergert <chergert redhat com>
  *
  * GtkSourceView is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -18,20 +18,20 @@
  * along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#pragma once
+#ifndef GTK_SOURCE_LINES_PRIVATE_H
+#define GTK_SOURCE_LINES_PRIVATE_H
 
 #include <gtk/gtk.h>
 
-#include "gtksourcetypes-private.h"
-
-G_BEGIN_DECLS
-
-#define GTK_SOURCE_TYPE_COMPLETION_CONTAINER (_gtk_source_completion_container_get_type())
+#include "gtksourcelines.h"
 
 G_GNUC_INTERNAL
-G_DECLARE_FINAL_TYPE (GtkSourceCompletionContainer, _gtk_source_completion_container, GTK_SOURCE, 
COMPLETION_CONTAINER, GtkScrolledWindow)
-
+GtkSourceLines *_gtk_source_lines_new             (GtkTextView       *text_view,
+                                                   const GtkTextIter *begin,
+                                                   const GtkTextIter *end,
+                                                   gboolean           needs_wrap_first,
+                                                   gboolean           needs_wrap_last);
 G_GNUC_INTERNAL
-GtkSourceCompletionContainer *_gtk_source_completion_container_new (void);
+guint           _gtk_source_lines_get_cursor_line (GtkSourceLines    *lines);
 
-G_END_DECLS
+#endif /* GTK_SOURCE_LINES_PRIVATE_H */
diff --git a/gtksourceview/gtksourcelines.c b/gtksourceview/gtksourcelines.c
new file mode 100644
index 00000000..65068b11
--- /dev/null
+++ b/gtksourceview/gtksourcelines.c
@@ -0,0 +1,641 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; coding: utf-8 -*- /
+ *
+ * This file is part of GtkSourceView
+ *
+ * Copyright (C) 2019 - Christian Hergert <chergert redhat com>
+ *
+ * GtkSourceView is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * GtkSourceView is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include "gtksourcelines.h"
+#include "gtksourcelines-private.h"
+
+#include "quarkset-inline.h"
+
+struct _GtkSourceLines
+{
+       GObject       parent_instance;
+       GtkTextView  *view;
+       GArray       *lines;
+       GdkRectangle  visible_rect;
+       guint         first;
+       guint         last;
+       guint         cursor_line;
+};
+
+typedef struct
+{
+       QuarkSet classes;
+       gint     y;
+       gint     height;
+       gint     first_height;
+       gint     last_height;
+} LineInfo;
+
+G_DEFINE_TYPE (GtkSourceLines, gtk_source_lines, G_TYPE_OBJECT)
+
+static GQuark q_cursor_line;
+static GQuark q_prelit;
+static GQuark q_selected;
+
+static void
+gtk_source_lines_finalize (GObject *object)
+{
+       GtkSourceLines *lines = (GtkSourceLines *)object;
+
+       g_clear_pointer (&lines->lines, g_array_unref);
+       g_clear_object (&lines->view);
+
+       G_OBJECT_CLASS (gtk_source_lines_parent_class)->finalize (object);
+}
+
+static void
+gtk_source_lines_class_init (GtkSourceLinesClass *klass)
+{
+       GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+       object_class->finalize = gtk_source_lines_finalize;
+
+       q_cursor_line = g_quark_from_static_string ("cursor-line");
+       q_prelit = g_quark_from_static_string ("prelit");
+       q_selected = g_quark_from_static_string ("selected");
+}
+
+static void
+gtk_source_lines_init (GtkSourceLines *self)
+{
+       self->cursor_line = -1;
+}
+
+static void
+clear_line_info (gpointer data)
+{
+       LineInfo *info = data;
+
+       info->y = 0;
+       info->height = 0;
+       quark_set_clear (&info->classes);
+}
+
+GtkSourceLines *
+_gtk_source_lines_new (GtkTextView       *text_view,
+                       const GtkTextIter *begin,
+                       const GtkTextIter *end,
+                       gboolean           needs_wrap_first,
+                       gboolean           needs_wrap_last)
+{
+       GtkSourceLines *lines;
+       GtkTextBuffer *buffer;
+       GtkTextMark *mark;
+       GtkTextIter iter;
+       gboolean single_line;
+       guint cursor_line;
+       guint i;
+
+       g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), NULL);
+       g_return_val_if_fail (begin != NULL, NULL);
+       g_return_val_if_fail (end != NULL, NULL);
+       g_return_val_if_fail (begin != end, NULL);
+
+       buffer = gtk_text_view_get_buffer (text_view);
+
+       g_return_val_if_fail (gtk_text_iter_get_buffer (begin) == buffer, NULL);
+       g_return_val_if_fail (gtk_text_iter_get_buffer (end) == buffer, NULL);
+
+       if (gtk_text_iter_compare (begin, end) > 0)
+       {
+               const GtkTextIter *tmp = begin;
+               begin = end;
+               end = tmp;
+       }
+
+       g_return_val_if_fail (begin != end, NULL);
+
+       lines = g_object_new (GTK_SOURCE_TYPE_LINES, NULL);
+       lines->view = g_object_ref (text_view);
+       lines->first = gtk_text_iter_get_line (begin);
+       lines->last = gtk_text_iter_get_line (end);
+       lines->lines = g_array_sized_new (FALSE,
+                                         FALSE,
+                                         sizeof (LineInfo),
+                                         lines->last - lines->first + 1);
+       g_array_set_clear_func (lines->lines, clear_line_info);
+       gtk_text_view_get_visible_rect (text_view, &lines->visible_rect);
+
+       /* No need to calculate special wrapping if wrap mode is none */
+       if (gtk_text_view_get_wrap_mode (text_view) == GTK_WRAP_NONE)
+       {
+               needs_wrap_first = FALSE;
+               needs_wrap_last = FALSE;
+       }
+
+       single_line = !needs_wrap_first && !needs_wrap_last;
+
+       /* Get the line number containing the cursor to compare while
+        * building the lines to add the "cursor-line" quark.
+        */
+       mark = gtk_text_buffer_get_insert (buffer);
+       gtk_text_buffer_get_iter_at_mark (buffer, &iter, mark);
+       cursor_line = gtk_text_iter_get_line (&iter);
+
+       lines->cursor_line = cursor_line;
+
+       iter = *begin;
+
+       if (!gtk_text_iter_starts_line (&iter))
+       {
+               gtk_text_iter_set_line_offset (&iter, 0);
+       }
+
+       for (i = lines->first; i <= lines->last; i++)
+       {
+               LineInfo info = {0};
+
+               if G_LIKELY (single_line)
+               {
+                       GdkRectangle rect;
+
+                       gtk_text_view_get_iter_location (text_view, &iter, &rect);
+
+                       info.y = rect.y;
+                       info.height = rect.height;
+                       info.first_height = rect.height;
+                       info.last_height = rect.height;
+               }
+               else
+               {
+                       gtk_text_view_get_line_yrange (text_view,
+                                                      &iter,
+                                                      &info.y,
+                                                      &info.height);
+
+                       if (gtk_text_iter_starts_line (&iter) &&
+                           gtk_text_iter_ends_line (&iter))
+                       {
+                               info.first_height = info.height;
+                               info.last_height = info.height;
+                       }
+                       else
+                       {
+                               GdkRectangle rect;
+
+                               if (needs_wrap_first)
+                               {
+
+                                       gtk_text_view_get_iter_location (text_view,
+                                                                        &iter,
+                                                                        &rect);
+                                       info.first_height = rect.height;
+                               }
+                               else
+                               {
+                                       info.first_height = info.height;
+                               }
+
+                               if (needs_wrap_last)
+                               {
+                                       gtk_text_iter_forward_to_line_end (&iter);
+                                       gtk_text_view_get_iter_location (text_view,
+                                                                        &iter,
+                                                                        &rect);
+                                       info.last_height = rect.height;
+                               }
+                               else
+                               {
+                                       info.last_height = info.height;
+                               }
+                       }
+               }
+
+               if G_UNLIKELY (i == cursor_line)
+               {
+                       quark_set_add (&info.classes, q_cursor_line);
+               }
+
+               g_array_append_val (lines->lines, info);
+
+               if G_UNLIKELY (!gtk_text_iter_forward_line (&iter) &&
+                              !gtk_text_iter_is_end (&iter))
+               {
+                       break;
+               }
+       }
+
+       g_return_val_if_fail (lines->lines->len > 0, NULL);
+       g_return_val_if_fail ((lines->last - lines->first) >= (lines->lines->len - 1), NULL);
+
+       return g_steal_pointer (&lines);
+}
+
+/**
+ * gtk_source_lines_add_qclass:
+ * @lines: a #GtkSourceLines
+ * @line: a line number starting from zero
+ * @aname: a class name as a #GQuark
+ *
+ * Adds the class denoted by @qname to @line.
+ *
+ * You may check if a line has @qname by calling
+ * gtk_source_lines_has_qclass().
+ *
+ * You can remove @qname by calling
+ * gtk_source_lines_remove_qclass().
+ *
+ * Since: 5.0
+ */
+void
+gtk_source_lines_add_qclass (GtkSourceLines *lines,
+                             guint           line,
+                             GQuark          qname)
+{
+       LineInfo *info;
+
+       g_return_if_fail (GTK_SOURCE_IS_LINES (lines));
+       g_return_if_fail (qname != 0);
+       g_return_if_fail (line >= lines->first);
+       g_return_if_fail (line <= lines->last);
+       g_return_if_fail (line - lines->first < lines->lines->len);
+
+       info = &g_array_index (lines->lines, LineInfo, line - lines->first);
+       quark_set_add (&info->classes, qname);
+}
+
+/**
+ * gtk_source_lines_add_class:
+ * @lines: a #GtkSourceLines
+ * @line: a line number starting from zero
+ * @name: a class name
+ *
+ * Adds the class @name to @line.
+ *
+ * @name will be converted to a #GQuark as part of this process. A
+ * faster version of this function is available via
+ * gtk_source_lines_add_qclass() for situations where the #GQuark is
+ * known ahead of time.
+ *
+ * Since: 5.0
+ */
+void
+gtk_source_lines_add_class (GtkSourceLines *lines,
+                            guint           line,
+                            const gchar    *name)
+{
+       g_return_if_fail (name != NULL);
+
+       gtk_source_lines_add_qclass (lines,
+                                    line,
+                                    g_quark_from_string (name));
+}
+
+/**
+ * gtk_source_lines_remove_class:
+ * @lines: a #GtkSourceLines
+ * @line: a line number starting from zero
+ * @name: a class name
+ *
+ * Removes the class matching @name from @line.
+ *
+ * A faster version of this function is available via
+ * gtk_source_lines_remove_qclass() for situations where the
+ * #GQuark is known ahead of time.
+ *
+ * Since: 5.0
+ */
+void
+gtk_source_lines_remove_class (GtkSourceLines *lines,
+                               guint           line,
+                               const gchar    *name)
+{
+       GQuark qname;
+
+       g_return_if_fail (name != NULL);
+
+       qname = g_quark_try_string (name);
+
+       if (qname != 0)
+       {
+               gtk_source_lines_remove_qclass (lines, line, qname);
+       }
+}
+
+/**
+ * gtk_source_lines_remove_qclass:
+ * @lines: a #GtkSourceLines
+ * @line: a line number starting from zero
+ * @qname: a #GQuark to remove from @line
+ *
+ * Reverses a call to gtk_source_lines_add_qclass() by removing
+ * the #GQuark matching @qname.
+ *
+ * Since: 5.0
+ */
+void
+gtk_source_lines_remove_qclass (GtkSourceLines *lines,
+                                guint           line,
+                                GQuark          qname)
+{
+       LineInfo *info;
+
+       g_return_if_fail (GTK_SOURCE_IS_LINES (lines));
+       g_return_if_fail (qname != 0);
+       g_return_if_fail (line >= lines->first);
+       g_return_if_fail (line <= lines->last);
+       g_return_if_fail (line - lines->first < lines->lines->len);
+
+       info = &g_array_index (lines->lines, LineInfo, line - lines->first);
+       quark_set_remove (&info->classes, qname);
+}
+
+/**
+ * gtk_source_lines_has_class:
+ * @lines: a #GtkSourceLines
+ * @line: a line number starting from zero
+ * @name: a class name that may be convered to a #GQuark
+ *
+ * Checks to see if gtk_source_lines_add_class() was called with
+ * the @name for @line.
+ *
+ * A faster version of this function is provided via
+ * gtk_source_lines_has_qclass() for situations where the quark
+ * is known ahead of time.
+ *
+ * Returns: %TRUE if @line contains @name
+ *
+ * Since: 5.0
+ */
+gboolean
+gtk_source_lines_has_class (GtkSourceLines *lines,
+                            guint           line,
+                            const gchar    *name)
+{
+       GQuark qname;
+
+       g_return_val_if_fail (name != NULL, FALSE);
+
+       qname = g_quark_try_string (name);
+
+       if (qname == 0)
+       {
+               return FALSE;
+       }
+
+       return gtk_source_lines_has_qclass (lines, line, qname);
+}
+
+/**
+ * gtk_source_lines_has_qclass:
+ * @lines: a #GtkSourceLines
+ * @line: a line number starting from zero
+ * @qname: a #GQuark containing the class name
+ *
+ * Checks to see if gtk_source_lines_add_qclass() was called with
+ * the quark denoted by @qname for @line.
+ *
+ * Returns: %TRUE if @line contains @qname
+ *
+ * Since: 5.0
+ */
+gboolean
+gtk_source_lines_has_qclass (GtkSourceLines *lines,
+                             guint           line,
+                             GQuark          qname)
+{
+       LineInfo *info;
+
+       g_return_val_if_fail (GTK_SOURCE_IS_LINES (lines), FALSE);
+       g_return_val_if_fail (qname != 0, FALSE);
+       g_return_val_if_fail (line >= lines->first, FALSE);
+       g_return_val_if_fail (line <= lines->last, FALSE);
+       g_return_val_if_fail (line - lines->first < lines->lines->len, FALSE);
+
+       info = &g_array_index (lines->lines, LineInfo, line - lines->first);
+
+       return quark_set_contains (&info->classes, qname);
+}
+
+/**
+ * gtk_source_lines_is_cursor:
+ * @lines: a #GtkSourceLines
+ * @line: a line number starting from zero
+ *
+ * Checks to see if @line contains the insertion cursor.
+ *
+ * Returns: %TRUE if the insertion cursor is on @line
+ *
+ * Since: 5.0
+ */
+gboolean
+gtk_source_lines_is_cursor (GtkSourceLines *lines,
+                            guint           line)
+{
+       return gtk_source_lines_has_qclass (lines, line, q_cursor_line);
+}
+
+/**
+ * gtk_source_lines_is_prelit:
+ * @lines: a #GtkSourceLines
+ * @line: a line number starting from zero
+ *
+ * Checks to see if @line is marked as prelit. Generally, this means
+ * the mouse pointer is over the line within the gutter.
+ *
+ * Returns: %TRUE if the line is prelit
+ *
+ * Since: 5.0
+ */
+gboolean
+gtk_source_lines_is_prelit (GtkSourceLines *lines,
+                            guint           line)
+{
+       return gtk_source_lines_has_qclass (lines, line, q_prelit);
+}
+
+/**
+ * gtk_source_lines_is_selected:
+ * @lines: a #GtkSourceLines
+ * @line: a line number starting from zero
+ *
+ * Checks to see if the view had a selection and if that selection overlaps
+ * @line in some way.
+ *
+ * Returns: %TRUE if the line contains a selection
+ *
+ * Since: 5.0
+ */
+gboolean
+gtk_source_lines_is_selected (GtkSourceLines *lines,
+                             guint           line)
+{
+       return gtk_source_lines_has_qclass (lines, line, q_selected);
+}
+
+/**
+ * gtk_source_lines_get_first:
+ * @lines: a #GtkSourceLines
+ *
+ * Gets the line number (starting from 0) for the first line that is
+ * user visible.
+ *
+ * Returns: a line number starting from 0
+ *
+ * Since: 5.0
+ */
+guint
+gtk_source_lines_get_first (GtkSourceLines *lines)
+{
+       g_return_val_if_fail (GTK_SOURCE_IS_LINES (lines), 0);
+
+       return lines->first;
+}
+
+/**
+ * gtk_source_lines_get_last:
+ * @lines: a #GtkSourceLines
+ *
+ * Gets the line number (starting from 0) for the last line that is
+ * user visible.
+ *
+ * Returns: a line number starting from 0
+ *
+ * Since: 5.0
+ */
+guint
+gtk_source_lines_get_last (GtkSourceLines *lines)
+{
+       g_return_val_if_fail (GTK_SOURCE_IS_LINES (lines), 0);
+
+       return lines->last;
+}
+
+/**
+ * gtk_source_lines_get_iter_at_line:
+ * @lines: a #GtkSourceLines
+ * @iter: (out): a location for a #GtkTextIter
+ * @line: the line number
+ *
+ * Gets a #GtkTextIter for the current buffer at @line
+ *
+ * Since: 5.0
+ */
+void
+gtk_source_lines_get_iter_at_line (GtkSourceLines *lines,
+                                  GtkTextIter    *iter,
+                                  guint           line)
+{
+       GtkTextBuffer *buffer;
+
+       g_return_if_fail (GTK_SOURCE_IS_LINES (lines));
+       g_return_if_fail (iter != NULL);
+
+       buffer = gtk_text_view_get_buffer (lines->view);
+       gtk_text_buffer_get_iter_at_line (buffer, iter, line);
+}
+
+/**
+ * gtk_source_lines_get_view:
+ * @lines: a #GtkSourceLines
+ *
+ * Gets the #GtkTextView that the #GtkSourceLines represents.
+ *
+ * Returns: (transfer none) (not nullable): a #GtkTextView
+ *
+ * Since: 5.0
+ */
+GtkTextView *
+gtk_source_lines_get_view (GtkSourceLines *lines)
+{
+       g_return_val_if_fail (GTK_SOURCE_IS_LINES (lines), NULL);
+
+       return lines->view;
+}
+
+/**
+ * gtk_source_lines_get_buffer:
+ * @lines: a #GtkSourceLines
+ *
+ * Gets the #GtkTextBuffer that the #GtkSourceLines represents.
+ *
+ * Returns: (transfer none) (not nullable): a #GtkTextBuffer
+ *
+ * Since: 5.0
+ */
+GtkTextBuffer *
+gtk_source_lines_get_buffer (GtkSourceLines *lines)
+{
+       g_return_val_if_fail (GTK_SOURCE_IS_LINES (lines), NULL);
+
+       return gtk_text_view_get_buffer (lines->view);
+}
+
+/**
+ * gtk_source_lines_get_line_yrange:
+ * @lines: a #GtkSourceLines
+ * @line: a line number starting from zero
+ * @mode: a #GtkSourceGutterRendererAlignmentMode
+ * @y: (out): a location for the Y position in widget coordinates
+ * @height: (out): the line height based on @mode
+ *
+ * Gets the Y range for a line based on @mode.
+ *
+ * The value for @y is relative to the renderers widget coordinates.
+ *
+ * Since: 5.0
+ */
+void
+gtk_source_lines_get_line_yrange (GtkSourceLines                       *lines,
+                                  guint                                 line,
+                                  GtkSourceGutterRendererAlignmentMode  mode,
+                                  gint                                 *y,
+                                  gint                                 *height)
+{
+       LineInfo *info;
+
+       g_return_if_fail (GTK_SOURCE_IS_LINES (lines));
+       g_return_if_fail (line >= lines->first);
+       g_return_if_fail (line <= lines->last);
+
+       info = &g_array_index (lines->lines, LineInfo, line - lines->first);
+
+       if (mode == GTK_SOURCE_GUTTER_RENDERER_ALIGNMENT_MODE_CELL)
+       {
+               *y = info->y;
+               *height = info->height;
+       }
+       else if (mode == GTK_SOURCE_GUTTER_RENDERER_ALIGNMENT_MODE_FIRST)
+       {
+               *y = info->y;
+               *height = info->first_height;
+       }
+       else if (mode == GTK_SOURCE_GUTTER_RENDERER_ALIGNMENT_MODE_LAST)
+       {
+               *y = info->y + info->height - info->last_height;
+               *height = info->last_height;
+       }
+       else
+       {
+               g_return_if_reached ();
+       }
+
+       *y -= lines->visible_rect.y;
+}
+
+guint
+_gtk_source_lines_get_cursor_line (GtkSourceLines *lines)
+{
+       g_return_val_if_fail (GTK_SOURCE_IS_LINES (lines), 0);
+
+       return lines->cursor_line;
+}
diff --git a/gtksourceview/gtksourcelines.h b/gtksourceview/gtksourcelines.h
new file mode 100644
index 00000000..9d8f300c
--- /dev/null
+++ b/gtksourceview/gtksourcelines.h
@@ -0,0 +1,99 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; coding: utf-8 -*- /
+ *
+ * This file is part of GtkSourceView
+ *
+ * Copyright (C) 2019 - Christian Hergert <chergert redhat com>
+ *
+ * GtkSourceView is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * GtkSourceView is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GTK_SOURCE_LINES_H
+#define GTK_SOURCE_LINES_H
+
+#if !defined (GTK_SOURCE_H_INSIDE) && !defined (GTK_SOURCE_COMPILATION)
+#error "Only <gtksourceview/gtksource.h> can be included directly."
+#endif
+
+#include <gtk/gtk.h>
+
+#include "gtksourcetypes.h"
+#include "gtksourcegutterrenderer.h"
+
+G_BEGIN_DECLS
+
+#define GTK_SOURCE_TYPE_LINES (gtk_source_lines_get_type())
+
+GTK_SOURCE_AVAILABLE_IN_ALL
+G_DECLARE_FINAL_TYPE (GtkSourceLines, gtk_source_lines, GTK_SOURCE, LINES, GObject)
+
+GTK_SOURCE_AVAILABLE_IN_ALL
+guint          gtk_source_lines_get_first        (GtkSourceLines                       *lines);
+GTK_SOURCE_AVAILABLE_IN_ALL
+guint          gtk_source_lines_get_last         (GtkSourceLines                       *lines);
+GTK_SOURCE_AVAILABLE_IN_ALL
+void           gtk_source_lines_get_iter_at_line (GtkSourceLines                       *lines,
+                                                  GtkTextIter                          *iter,
+                                                  guint                                 line);
+GTK_SOURCE_AVAILABLE_IN_ALL
+GtkTextView   *gtk_source_lines_get_view         (GtkSourceLines                       *lines);
+GTK_SOURCE_AVAILABLE_IN_ALL
+GtkTextBuffer *gtk_source_lines_get_buffer       (GtkSourceLines                       *lines);
+GTK_SOURCE_AVAILABLE_IN_ALL
+void           gtk_source_lines_get_yrange       (GtkSourceLines                       *lines,
+                                                  guint                                 line,
+                                                  guint                                *line_y,
+                                                  guint                                *line_height);
+GTK_SOURCE_AVAILABLE_IN_ALL
+void           gtk_source_lines_add_qclass       (GtkSourceLines                       *lines,
+                                                  guint                                 line,
+                                                  GQuark                                qname);
+GTK_SOURCE_AVAILABLE_IN_ALL
+void           gtk_source_lines_add_class        (GtkSourceLines                       *lines,
+                                                  guint                                 line,
+                                                  const gchar                          *name);
+GTK_SOURCE_AVAILABLE_IN_ALL
+void           gtk_source_lines_remove_class     (GtkSourceLines                       *lines,
+                                                  guint                                 line,
+                                                  const gchar                          *name);
+GTK_SOURCE_AVAILABLE_IN_ALL
+void           gtk_source_lines_remove_qclass    (GtkSourceLines                       *lines,
+                                                  guint                                 line,
+                                                  GQuark                                qname);
+GTK_SOURCE_AVAILABLE_IN_ALL
+gboolean       gtk_source_lines_has_class        (GtkSourceLines                       *lines,
+                                                  guint                                 line,
+                                                  const gchar                          *name);
+GTK_SOURCE_AVAILABLE_IN_ALL
+gboolean       gtk_source_lines_has_qclass       (GtkSourceLines                       *lines,
+                                                  guint                                 line,
+                                                  GQuark                                qname);
+GTK_SOURCE_AVAILABLE_IN_ALL
+gboolean       gtk_source_lines_is_cursor        (GtkSourceLines                       *lines,
+                                                  guint                                 line);
+GTK_SOURCE_AVAILABLE_IN_ALL
+gboolean       gtk_source_lines_is_prelit        (GtkSourceLines                       *lines,
+                                                  guint                                 line);
+GTK_SOURCE_AVAILABLE_IN_ALL
+gboolean       gtk_source_lines_is_selected      (GtkSourceLines                       *lines,
+                                                  guint                                 line);
+GTK_SOURCE_AVAILABLE_IN_ALL
+void           gtk_source_lines_get_line_yrange  (GtkSourceLines                       *lines,
+                                                  guint                                 line,
+                                                  GtkSourceGutterRendererAlignmentMode  mode,
+                                                  gint                                 *y,
+                                                  gint                                 *height);
+
+G_END_DECLS
+
+#endif /* GTK_SOURCE_LINES_H */
diff --git a/gtksourceview/gtksourcemap.c b/gtksourceview/gtksourcemap.c
index 792776e0..a5d57e5e 100644
--- a/gtksourceview/gtksourcemap.c
+++ b/gtksourceview/gtksourcemap.c
@@ -1,7 +1,7 @@
 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; coding: utf-8 -*- */
 /*
- * Copyright 2015 Christian Hergert <christian hergert me>
- * Copyright 2015 Ignacio Casal Quinteiro <icq gnome org>
+ * Copyright (C) 2015 Christian Hergert <christian hergert me>
+ * Copyright (C) 2015 Ignacio Casal Quinteiro <icq gnome org>
  *
  * GtkSourceView is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -17,16 +17,21 @@
  * along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "config.h"
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
 
-#include "gtksourcemap.h"
 #include <string.h>
+
+#include "gtksourcemap.h"
 #include "gtksourcebuffer.h"
 #include "gtksourcecompletion.h"
 #include "gtksourcestyle-private.h"
 #include "gtksourcestylescheme.h"
 #include "gtksourceutils-private.h"
 
+#define SCRUBBER_MIN_HEIGHT 10
+
 /**
  * SECTION:map
  * @Short_description: Widget that displays a map for a specific #GtkSourceView
@@ -189,6 +194,7 @@ update_scrubber_position (GtkSourceMap *map)
        GdkRectangle scrubber_area;
        GtkAllocation alloc;
        GtkAllocation view_alloc;
+       gint ignored;
        gint child_height;
        gint view_height;
        gint y;
@@ -203,8 +209,16 @@ update_scrubber_position (GtkSourceMap *map)
        gtk_widget_get_allocation (GTK_WIDGET (priv->view), &view_alloc);
        gtk_widget_get_allocation (GTK_WIDGET (map), &alloc);
 
-       gtk_widget_get_preferred_height (GTK_WIDGET (priv->view), NULL, &view_height);
-       gtk_widget_get_preferred_height (GTK_WIDGET (map), NULL, &child_height);
+       gtk_widget_measure (GTK_WIDGET (priv->view),
+                           GTK_ORIENTATION_VERTICAL,
+                           gtk_widget_get_width (GTK_WIDGET (priv->view)),
+                           NULL,
+                           &view_height,
+                           NULL, NULL);
+       GTK_WIDGET_CLASS (gtk_source_map_parent_class)->measure (GTK_WIDGET (map),
+                                                                GTK_ORIENTATION_VERTICAL,
+                                                                gtk_widget_get_width (GTK_WIDGET (map)),
+                                                                &ignored, &child_height, &ignored, &ignored);
 
        gtk_text_view_get_visible_rect (GTK_TEXT_VIEW (priv->view), &visible_area);
        gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW (priv->view), &iter,
@@ -225,28 +239,8 @@ update_scrubber_position (GtkSourceMap *map)
 
        if (memcmp (&scrubber_area, &priv->scrubber_area, sizeof scrubber_area) != 0)
        {
-               GdkWindow *window;
-
-               /*
-                * NOTE:
-                *
-                * Initially we had a gtk_widget_queue_draw() here thinking
-                * that we would hit the pixel cache and everything would be
-                * fine. However, it actually has a noticible improvement on
-                * interactivity to simply invalidate the old and new region
-                * in the widgets primary GdkWindow. Since the window is
-                * not the GTK_TEXT_WINDOW_TEXT, we don't seem to invalidate
-                * the pixel cache. This makes things as interactive as they
-                * were when drawing the scrubber from a parent widget.
-                */
-               window = gtk_text_view_get_window (GTK_TEXT_VIEW (map), GTK_TEXT_WINDOW_WIDGET);
-               if (window != NULL)
-               {
-                       gdk_window_invalidate_rect (window, &priv->scrubber_area, FALSE);
-                       gdk_window_invalidate_rect (window, &scrubber_area, FALSE);
-               }
-
                priv->scrubber_area = scrubber_area;
+               gtk_widget_queue_draw (GTK_WIDGET (map));
        }
 }
 
@@ -334,7 +328,7 @@ gtk_source_map_rebuild_css (GtkSourceMap *map)
        if (background == NULL)
        {
                GtkStyleContext *context;
-               GdkRGBA color;
+               GdkRGBA *color = NULL;
 
                /*
                 * We failed to locate a style for both "map-overlay" and for
@@ -348,13 +342,11 @@ gtk_source_map_rebuild_css (GtkSourceMap *map)
                gtk_style_context_save (context);
                gtk_style_context_add_class (context, "view");
                gtk_style_context_set_state (context, GTK_STATE_FLAG_SELECTED);
-               G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
-               gtk_style_context_get_background_color (context,
-                                                       gtk_style_context_get_state (context),
-                                                       &color);
-               G_GNUC_END_IGNORE_DEPRECATIONS;
+               gtk_style_context_get (context,
+                                      GTK_STYLE_PROPERTY_BACKGROUND_COLOR, &color,
+                                      NULL);
                gtk_style_context_restore (context);
-               background = gdk_rgba_to_string (&color);
+               background = gdk_rgba_to_string (color);
 
                /*
                 * Make sure we alter the alpha. It is possible this could be
@@ -362,6 +354,8 @@ gtk_source_map_rebuild_css (GtkSourceMap *map)
                 * not contain a background color.
                 */
                alter_alpha = TRUE;
+
+               gdk_rgba_free (color);
        }
 
        if (alter_alpha)
@@ -392,7 +386,7 @@ gtk_source_map_rebuild_css (GtkSourceMap *map)
 
        if (gstr->len > 0)
        {
-               gtk_css_provider_load_from_data (priv->css_provider, gstr->str, gstr->len, NULL);
+               gtk_css_provider_load_from_data (priv->css_provider, gstr->str, gstr->len);
        }
 
        g_string_free (gstr, TRUE);
@@ -568,64 +562,60 @@ gtk_source_map_set_font_name (GtkSourceMap *map,
 }
 
 static void
-gtk_source_map_get_preferred_width (GtkWidget *widget,
-                                    gint      *mininum_width,
-                                    gint      *natural_width)
+gtk_source_map_measure (GtkWidget      *widget,
+                        GtkOrientation  orientation,
+                        int             for_size,
+                        int            *minimum,
+                        int            *natural,
+                        int            *minimum_baseline,
+                        int            *natural_baseline)
 {
        GtkSourceMap *map = GTK_SOURCE_MAP (widget);
        GtkSourceMapPrivate *priv;
-       PangoLayout *layout;
-       gint height;
-       gint width;
 
        priv = gtk_source_map_get_instance_private (map);
 
-       if (priv->font_desc == NULL)
+       if (orientation == GTK_ORIENTATION_HORIZONTAL)
        {
-               *mininum_width = *natural_width = DEFAULT_WIDTH;
-               return;
+               if (priv->font_desc == NULL)
+               {
+                       *minimum = *natural = DEFAULT_WIDTH;
+               }
+               else
+               {
+                       PangoLayout *layout;
+                       gint height;
+                       gint width;
+
+                       /*
+                        * FIXME:
+                        *
+                        * This seems like the type of thing we should calculate when
+                        * rebuilding our CSS since it gets used a bunch and changes
+                        * very little.
+                        */
+                       layout = gtk_widget_create_pango_layout (GTK_WIDGET (map), "X");
+                       pango_layout_get_pixel_size (layout, &width, &height);
+                       g_object_unref (layout);
+
+                       width *= gtk_source_view_get_right_margin_position (priv->view);
+
+                       *minimum = *natural = width;
+               }
        }
-
-       /*
-        * FIXME:
-        *
-        * This seems like the type of thing we should calculate when
-        * rebuilding our CSS since it gets used a bunch and changes
-        * very little.
-        */
-       layout = gtk_widget_create_pango_layout (GTK_WIDGET (map), "X");
-       pango_layout_get_pixel_size (layout, &width, &height);
-       g_object_unref (layout);
-
-       width *= gtk_source_view_get_right_margin_position (priv->view);
-
-       *mininum_width = *natural_width = width;
-}
-
-static void
-gtk_source_map_get_preferred_height (GtkWidget *widget,
-                                     gint      *minimum_height,
-                                     gint      *natural_height)
-{
-       GtkSourceMap *map = GTK_SOURCE_MAP (widget);
-       GtkSourceMapPrivate *priv;
-
-       priv = gtk_source_map_get_instance_private (map);
-
-       if (priv->view == NULL)
+       else if (orientation == GTK_ORIENTATION_VERTICAL)
        {
-               *minimum_height = *natural_height = 0;
-               return;
+               GTK_WIDGET_CLASS (gtk_source_map_parent_class)->measure (widget,
+                                                                        orientation,
+                                                                        for_size,
+                                                                        minimum,
+                                                                        natural,
+                                                                        minimum_baseline,
+                                                                        natural_baseline);
+               *minimum = *natural = 0;
        }
-
-       GTK_WIDGET_CLASS (gtk_source_map_parent_class)->get_preferred_height (widget,
-                                                                             minimum_height,
-                                                                             natural_height);
-
-       *minimum_height = 0;
 }
 
-
 /*
  * This scrolls using buffer coordinates.
  * Translate your event location to a buffer coordinate before
@@ -655,12 +645,14 @@ scroll_to_child_point (GtkSourceMap   *map,
 }
 
 static void
-gtk_source_map_size_allocate (GtkWidget     *widget,
-                              GtkAllocation *alloc)
+gtk_source_map_size_allocate (GtkWidget *widget,
+                              int        width,
+                              int        height,
+                              int        baseline)
 {
        GtkSourceMap *map = GTK_SOURCE_MAP (widget);
 
-       GTK_WIDGET_CLASS (gtk_source_map_parent_class)->size_allocate (widget, alloc);
+       GTK_WIDGET_CLASS (gtk_source_map_parent_class)->size_allocate (widget, width, height, baseline);
 
        update_scrubber_position (map);
 }
@@ -722,16 +714,6 @@ connect_view (GtkSourceMap  *map,
                                         map,
                                         G_CONNECT_SWAPPED);
 
-       if ((gtk_widget_get_events (GTK_WIDGET (priv->view)) & GDK_ENTER_NOTIFY_MASK) == 0)
-       {
-               gtk_widget_add_events (GTK_WIDGET (priv->view), GDK_ENTER_NOTIFY_MASK);
-       }
-
-       if ((gtk_widget_get_events (GTK_WIDGET (priv->view)) & GDK_LEAVE_NOTIFY_MASK) == 0)
-       {
-               gtk_widget_add_events (GTK_WIDGET (priv->view), GDK_LEAVE_NOTIFY_MASK);
-       }
-
        /* If we are not visible, we want to block certain signal handlers */
        if (!gtk_widget_get_visible (GTK_WIDGET (map)))
        {
@@ -818,9 +800,9 @@ gtk_source_map_destroy (GtkWidget *widget)
        GTK_WIDGET_CLASS (gtk_source_map_parent_class)->destroy (widget);
 }
 
-static gboolean
-gtk_source_map_draw (GtkWidget *widget,
-                     cairo_t   *cr)
+static void
+gtk_source_map_snapshot (GtkWidget   *widget,
+                         GtkSnapshot *snapshot)
 {
        GtkSourceMap *map = GTK_SOURCE_MAP (widget);
        GtkSourceMapPrivate *priv;
@@ -828,18 +810,27 @@ gtk_source_map_draw (GtkWidget *widget,
 
        priv = gtk_source_map_get_instance_private (map);
 
-       style_context = gtk_widget_get_style_context (widget);
+       GTK_WIDGET_CLASS (gtk_source_map_parent_class)->snapshot (widget, snapshot);
 
-       GTK_WIDGET_CLASS (gtk_source_map_parent_class)->draw (widget, cr);
+       style_context = gtk_widget_get_style_context (widget);
 
        gtk_style_context_save (style_context);
        gtk_style_context_add_class (style_context, "scrubber");
-       gtk_render_background (style_context, cr,
-                              priv->scrubber_area.x, priv->scrubber_area.y,
-                              priv->scrubber_area.width, priv->scrubber_area.height);
+       gtk_snapshot_render_background (snapshot,
+                                       style_context,
+                                       priv->scrubber_area.x, priv->scrubber_area.y,
+                                       priv->scrubber_area.width, priv->scrubber_area.height);
        gtk_style_context_restore (style_context);
+}
 
-       return FALSE;
+static void
+gtk_source_map_snapshot_layer (GtkTextView      *text_view,
+                              GtkTextViewLayer  layer,
+                              GtkSnapshot      *snapshot)
+{
+       /* Avoid drawing layers from GtkSourceView. They details are
+        * too small to see and significantly slow down rendering.
+        */
 }
 
 static void
@@ -891,98 +882,66 @@ gtk_source_map_set_property (GObject      *object,
        }
 }
 
-static gboolean
-gtk_source_map_button_press_event (GtkWidget      *widget,
-                                   GdkEventButton *event)
+static void
+gtk_source_map_drag_update (GtkSourceMap   *map,
+                           gdouble         x,
+                           gdouble         y,
+                           GtkGestureDrag *drag)
 {
-       GtkSourceMap *map = GTK_SOURCE_MAP (widget);
-       GtkSourceMapPrivate *priv;
+       GtkTextBuffer *buffer;
+       GtkAllocation alloc;
+       GdkRectangle area;
+       GtkTextIter iter;
        GdkPoint point;
+       gdouble yratio;
+       gdouble begin_x;
+       gdouble begin_y;
+       gint ignored;
+       gint real_height;
+       gint height;
 
-       priv = gtk_source_map_get_instance_private (map);
+       gtk_widget_get_allocation (GTK_WIDGET (map), &alloc);
+       gtk_gesture_drag_get_start_point (drag, &begin_x, &begin_y);
+       y = CLAMP (begin_y + y, 0, alloc.height);
 
-       point.x = event->x;
-       point.y = event->y;
+       GTK_WIDGET_CLASS (gtk_source_map_parent_class)->measure (GTK_WIDGET (map),
+                                                                GTK_ORIENTATION_VERTICAL,
+                                                                gtk_widget_get_width (GTK_WIDGET (map)),
+                                                                &ignored, &real_height, &ignored, &ignored);
 
-       gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (map),
-                                              GTK_TEXT_WINDOW_WIDGET,
-                                              event->x, event->y,
-                                              &point.x, &point.y);
+       height = MIN (real_height, alloc.height);
 
-       scroll_to_child_point (map, &point);
+       buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (map));
+       gtk_text_buffer_get_end_iter (buffer, &iter);
+       gtk_text_view_get_iter_location (GTK_TEXT_VIEW (map), &iter, &area);
 
-       gtk_grab_add (widget);
+       yratio = CLAMP (y, 0, height) / (gdouble)height;
 
-       priv->in_press = TRUE;
+       point.x = 0;
+       point.y = real_height * yratio;
 
-       return GDK_EVENT_STOP;
+       scroll_to_child_point (map, &point);
 }
 
-static gboolean
-gtk_source_map_button_release_event (GtkWidget      *widget,
-                                     GdkEventButton *event)
+static void
+gtk_source_map_drag_begin (GtkSourceMap   *map,
+                          gdouble         start_x,
+                          gdouble         start_y,
+                          GtkGestureDrag *drag)
 {
-       GtkSourceMap *map = GTK_SOURCE_MAP (widget);
-       GtkSourceMapPrivate *priv;
-
-       priv = gtk_source_map_get_instance_private (map);
-
-       gtk_grab_remove (widget);
-
-       priv->in_press = FALSE;
-
-       return GDK_EVENT_STOP;
+       gtk_gesture_set_state (GTK_GESTURE (drag), GTK_EVENT_SEQUENCE_CLAIMED);
+       gtk_source_map_drag_update (map, 0, 0, drag);
 }
 
 
 static gboolean
-gtk_source_map_motion_notify_event (GtkWidget      *widget,
-                                    GdkEventMotion *event)
-{
-       GtkSourceMap *map = GTK_SOURCE_MAP (widget);
-       GtkSourceMapPrivate *priv;
-
-       priv = gtk_source_map_get_instance_private (map);
-
-       if (priv->in_press && (priv->view != NULL))
-       {
-               GtkTextBuffer *buffer;
-               GtkAllocation alloc;
-               GdkRectangle area;
-               GtkTextIter iter;
-               GdkPoint point;
-               gdouble yratio;
-               gint height;
-
-               gtk_widget_get_allocation (widget, &alloc);
-               gtk_widget_get_preferred_height (widget, NULL, &height);
-               if (height > 0)
-               {
-                       height = MIN (height, alloc.height);
-               }
-
-               buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (map));
-               gtk_text_buffer_get_end_iter (buffer, &iter);
-               gtk_text_view_get_iter_location (GTK_TEXT_VIEW (map), &iter, &area);
-
-               yratio = CLAMP (event->y - alloc.y, 0, height) / (gdouble)height;
-
-               point.x = 0;
-               point.y = (area.y + area.height) * yratio;
-
-               scroll_to_child_point (map, &point);
-       }
-
-       return GDK_EVENT_STOP;
-}
-
-static gboolean
-gtk_source_map_scroll_event (GtkWidget      *widget,
-                             GdkEventScroll *event)
+gtk_source_map_scroll (GtkWidget *widget,
+                       gdouble    x,
+                       gdouble    y)
 {
+       static const gint scroll_acceleration = 6;
        GtkSourceMap *map = GTK_SOURCE_MAP (widget);
        GtkSourceMapPrivate *priv;
-       static const gint scroll_acceleration = 4;
 
        priv = gtk_source_map_get_instance_private (map);
 
@@ -994,36 +953,20 @@ gtk_source_map_scroll_event (GtkWidget      *widget,
         */
        if (priv->view != NULL)
        {
-               gdouble x;
-               gdouble y;
                gint count = 0;
 
-               if (event->direction == GDK_SCROLL_UP)
-               {
-                       count = -scroll_acceleration;
-               }
-               else if (event->direction == GDK_SCROLL_DOWN)
+               if (y > 0)
                {
                        count = scroll_acceleration;
                }
-               else
+               else if (y < 0)
                {
-                       gdk_event_get_scroll_deltas ((GdkEvent *)event, &x, &y);
-
-                       if (y > 0)
-                       {
-                               count = scroll_acceleration;
-                       }
-                       else if (y < 0)
-                       {
-                               count = -scroll_acceleration;
-                       }
+                       count = -scroll_acceleration;
                }
 
                if (count != 0)
                {
-                       g_signal_emit_by_name (priv->view, "move-viewport",
-                                              GTK_SCROLL_STEPS, count);
+                       g_signal_emit_by_name (priv->view, "move-viewport", GTK_SCROLL_STEPS, count);
                        return GDK_EVENT_STOP;
                }
        }
@@ -1031,26 +974,13 @@ gtk_source_map_scroll_event (GtkWidget      *widget,
        return GDK_EVENT_PROPAGATE;
 }
 
-static void
-set_view_cursor (GtkSourceMap *map)
-{
-       GdkWindow *window;
-
-       window = gtk_text_view_get_window (GTK_TEXT_VIEW (map),
-                                          GTK_TEXT_WINDOW_TEXT);
-       if (window != NULL)
-       {
-               gdk_window_set_cursor (window, NULL);
-       }
-}
-
 static void
 gtk_source_map_state_flags_changed (GtkWidget     *widget,
                                     GtkStateFlags  flags)
 {
        GTK_WIDGET_CLASS (gtk_source_map_parent_class)->state_flags_changed (widget, flags);
 
-       set_view_cursor (GTK_SOURCE_MAP (widget));
+       gtk_widget_set_cursor (widget, NULL);
 }
 
 static void
@@ -1058,7 +988,7 @@ gtk_source_map_realize (GtkWidget *widget)
 {
        GTK_WIDGET_CLASS (gtk_source_map_parent_class)->realize (widget);
 
-       set_view_cursor (GTK_SOURCE_MAP (widget));
+       gtk_widget_set_cursor (widget, NULL);
 }
 
 static void
@@ -1108,24 +1038,22 @@ gtk_source_map_class_init (GtkSourceMapClass *klass)
 {
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
        GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+       GtkTextViewClass *text_view_class = GTK_TEXT_VIEW_CLASS (klass);
 
        object_class->get_property = gtk_source_map_get_property;
        object_class->set_property = gtk_source_map_set_property;
 
        widget_class->destroy = gtk_source_map_destroy;
-       widget_class->draw = gtk_source_map_draw;
-       widget_class->get_preferred_height = gtk_source_map_get_preferred_height;
-       widget_class->get_preferred_width = gtk_source_map_get_preferred_width;
+       widget_class->snapshot = gtk_source_map_snapshot;
+       widget_class->measure = gtk_source_map_measure;
        widget_class->hide = gtk_source_map_hide;
        widget_class->size_allocate = gtk_source_map_size_allocate;
-       widget_class->button_press_event = gtk_source_map_button_press_event;
-       widget_class->button_release_event = gtk_source_map_button_release_event;
-       widget_class->motion_notify_event = gtk_source_map_motion_notify_event;
-       widget_class->scroll_event = gtk_source_map_scroll_event;
        widget_class->show = gtk_source_map_show;
        widget_class->state_flags_changed = gtk_source_map_state_flags_changed;
        widget_class->realize = gtk_source_map_realize;
 
+       text_view_class->snapshot_layer = gtk_source_map_snapshot_layer;
+
        properties[PROP_VIEW] =
                g_param_spec_object ("view",
                                     "View",
@@ -1148,7 +1076,9 @@ gtk_source_map_init (GtkSourceMap *map)
 {
        GtkSourceMapPrivate *priv;
        GtkSourceCompletion *completion;
+       GtkEventController *scroll;
        GtkStyleContext *context;
+       GtkGesture *drag;
 
        priv = gtk_source_map_get_instance_private (map);
 
@@ -1165,18 +1095,34 @@ gtk_source_map_init (GtkSourceMap *map)
                      "editable", FALSE,
                      "expand", FALSE,
                      "monospace", TRUE,
-                     "show-line-numbers", FALSE,
-                     "show-line-marks", FALSE,
                      "show-right-margin", FALSE,
                      "visible", TRUE,
                      NULL);
 
-       gtk_widget_add_events (GTK_WIDGET (map), GDK_SCROLL_MASK);
-
        completion = gtk_source_view_get_completion (GTK_SOURCE_VIEW (map));
        gtk_source_completion_block_interactive (completion);
 
-       gtk_source_map_set_font_name (map, "Monospace 1");
+       gtk_source_map_set_font_name (map, "BuilderBlocks 1");
+
+       drag = gtk_gesture_drag_new ();
+       g_signal_connect_swapped (drag,
+                                 "drag-begin",
+                                 G_CALLBACK (gtk_source_map_drag_begin),
+                                 map);
+       g_signal_connect_swapped (drag,
+                                 "drag-update",
+                                 G_CALLBACK (gtk_source_map_drag_update),
+                                 map);
+       gtk_widget_add_controller (GTK_WIDGET (map),
+                                  GTK_EVENT_CONTROLLER (g_steal_pointer (&drag)));
+
+       scroll = gtk_event_controller_scroll_new (GTK_EVENT_CONTROLLER_SCROLL_VERTICAL);
+       gtk_event_controller_set_propagation_phase (scroll, GTK_PHASE_CAPTURE);
+       g_signal_connect_swapped (scroll,
+                                 "scroll",
+                                 G_CALLBACK (gtk_source_map_scroll),
+                                 map);
+       gtk_widget_add_controller (GTK_WIDGET (map), g_steal_pointer (&scroll));
 }
 
 /**
diff --git a/gtksourceview/gtksourcemap.h b/gtksourceview/gtksourcemap.h
index 9fd57c33..d7c9183e 100644
--- a/gtksourceview/gtksourcemap.h
+++ b/gtksourceview/gtksourcemap.h
@@ -1,7 +1,7 @@
 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; coding: utf-8 -*- */
 /*
- * Copyright 2015 Christian Hergert <christian hergert me>
- * Copyright 2015 Ignacio Casal Quinteiro <icq gnome org>
+ * Copyright (C) 2015 Christian Hergert <christian hergert me>
+ * Copyright (C) 2015 Ignacio Casal Quinteiro <icq gnome org>
  *
  * GtkSourceView is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -17,7 +17,8 @@
  * along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#pragma once
+#ifndef GTK_SOURCE_MAP_H
+#define GTK_SOURCE_MAP_H
 
 #if !defined (GTK_SOURCE_H_INSIDE) && !defined (GTK_SOURCE_COMPILATION)
 #error "Only <gtksourceview/gtksource.h> can be included directly."
@@ -30,10 +31,20 @@
 
 G_BEGIN_DECLS
 
-#define GTK_SOURCE_TYPE_MAP (gtk_source_map_get_type())
+#define GTK_SOURCE_TYPE_MAP            (gtk_source_map_get_type())
+#define GTK_SOURCE_MAP(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_SOURCE_TYPE_MAP, 
GtkSourceMap))
+#define GTK_SOURCE_MAP_CONST(obj)      (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_SOURCE_TYPE_MAP, GtkSourceMap 
const))
+#define GTK_SOURCE_MAP_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass),  GTK_SOURCE_TYPE_MAP, 
GtkSourceMapClass))
+#define GTK_SOURCE_IS_MAP(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_SOURCE_TYPE_MAP))
+#define GTK_SOURCE_IS_MAP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),  GTK_SOURCE_TYPE_MAP))
+#define GTK_SOURCE_MAP_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj),  GTK_SOURCE_TYPE_MAP, 
GtkSourceMapClass))
 
-GTK_SOURCE_AVAILABLE_IN_3_18
-G_DECLARE_DERIVABLE_TYPE (GtkSourceMap, gtk_source_map, GTK_SOURCE, MAP, GtkSourceView)
+typedef struct _GtkSourceMapClass GtkSourceMapClass;
+
+struct _GtkSourceMap
+{
+       GtkSourceView parent_instance;
+};
 
 struct _GtkSourceMapClass
 {
@@ -44,11 +55,18 @@ struct _GtkSourceMapClass
 };
 
 GTK_SOURCE_AVAILABLE_IN_3_18
-GtkWidget     *gtk_source_map_new      (void);
+GType                   gtk_source_map_get_type        (void);
+
 GTK_SOURCE_AVAILABLE_IN_3_18
-void           gtk_source_map_set_view (GtkSourceMap  *map,
-                                        GtkSourceView *view);
+GtkWidget              *gtk_source_map_new             (void);
+
+GTK_SOURCE_AVAILABLE_IN_3_18
+void                    gtk_source_map_set_view        (GtkSourceMap  *map,
+                                                        GtkSourceView *view);
+
 GTK_SOURCE_AVAILABLE_IN_3_18
-GtkSourceView *gtk_source_map_get_view (GtkSourceMap  *map);
+GtkSourceView          *gtk_source_map_get_view        (GtkSourceMap  *map);
 
 G_END_DECLS
+
+#endif /* GTK_SOURCE_MAP_H */
diff --git a/gtksourceview/gtksourcemark.c b/gtksourceview/gtksourcemark.c
index 5e32123e..447f03d1 100644
--- a/gtksourceview/gtksourcemark.c
+++ b/gtksourceview/gtksourcemark.c
@@ -2,7 +2,7 @@
 /*
  * This file is part of GtkSourceView
  *
- * Copyright 2007 - Johannes Schmid <jhs gnome org>
+ * Copyright (C) 2007 - Johannes Schmid <jhs gnome org>
  *
  * GtkSourceView is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -18,7 +18,9 @@
  * along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "config.h"
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
 
 #include "gtksourcemark.h"
 #include "gtksourcebuffer.h"
@@ -49,21 +51,24 @@ enum
        PROP_CATEGORY
 };
 
-typedef struct
+struct _GtkSourceMarkPrivate
 {
        gchar *category;
-} GtkSourceMarkPrivate;
+};
 
-G_DEFINE_TYPE_WITH_PRIVATE (GtkSourceMark, gtk_source_mark, GTK_TYPE_TEXT_MARK)
+G_DEFINE_TYPE_WITH_PRIVATE (GtkSourceMark, gtk_source_mark, GTK_TYPE_TEXT_MARK);
 
 static void
 gtk_source_mark_set_property (GObject      *object,
-                              guint         prop_id,
-                              const GValue *value,
-                              GParamSpec   *pspec)
+                             guint         prop_id,
+                             const GValue *value,
+                             GParamSpec   *pspec)
 {
-       GtkSourceMark *mark = GTK_SOURCE_MARK (object);
-       GtkSourceMarkPrivate *priv = gtk_source_mark_get_instance_private (mark);
+       GtkSourceMarkPrivate *priv;
+
+       g_return_if_fail (GTK_SOURCE_IS_MARK (object));
+
+       priv = GTK_SOURCE_MARK (object)->priv;
 
        switch (prop_id)
        {
@@ -81,11 +86,15 @@ gtk_source_mark_set_property (GObject      *object,
 
 static void
 gtk_source_mark_get_property (GObject    *object,
-                              guint       prop_id,
-                              GValue     *value,
-                              GParamSpec *pspec)
+                             guint       prop_id,
+                             GValue     *value,
+                             GParamSpec *pspec)
 {
-       GtkSourceMark *mark = GTK_SOURCE_MARK (object);
+       GtkSourceMark *mark;
+
+       g_return_if_fail (GTK_SOURCE_IS_MARK (object));
+
+       mark = GTK_SOURCE_MARK (object);
 
        switch (prop_id)
        {
@@ -104,9 +113,8 @@ static void
 gtk_source_mark_finalize (GObject *object)
 {
        GtkSourceMark *mark = GTK_SOURCE_MARK (object);
-       GtkSourceMarkPrivate *priv = gtk_source_mark_get_instance_private (mark);
 
-       g_clear_pointer (&priv->category, g_free);
+       g_free (mark->priv->category);
 
        G_OBJECT_CLASS (gtk_source_mark_parent_class)->finalize (object);
 }
@@ -142,6 +150,7 @@ gtk_source_mark_class_init (GtkSourceMarkClass *klass)
 static void
 gtk_source_mark_init (GtkSourceMark *mark)
 {
+       mark->priv = gtk_source_mark_get_instance_private (mark);
 }
 
 /**
@@ -188,11 +197,9 @@ gtk_source_mark_new (const gchar *name,
 const gchar *
 gtk_source_mark_get_category (GtkSourceMark *mark)
 {
-       GtkSourceMarkPrivate *priv = gtk_source_mark_get_instance_private (mark);
-
        g_return_val_if_fail (GTK_SOURCE_IS_MARK (mark), NULL);
 
-       return priv->category;
+       return mark->priv->category;
 }
 
 /**
@@ -211,7 +218,7 @@ gtk_source_mark_get_category (GtkSourceMark *mark)
  */
 GtkSourceMark *
 gtk_source_mark_next (GtkSourceMark *mark,
-                      const gchar   *category)
+                     const gchar   *category)
 {
        GtkTextBuffer *buffer;
 
@@ -245,7 +252,7 @@ gtk_source_mark_next (GtkSourceMark *mark,
  */
 GtkSourceMark *
 gtk_source_mark_prev (GtkSourceMark *mark,
-                      const gchar   *category)
+                     const gchar   *category)
 {
        GtkTextBuffer *buffer;
 
diff --git a/gtksourceview/gtksourcemark.h b/gtksourceview/gtksourcemark.h
index 17bc46e5..0db5f72f 100644
--- a/gtksourceview/gtksourcemark.h
+++ b/gtksourceview/gtksourcemark.h
@@ -2,7 +2,7 @@
  *
  * This file is part of GtkSourceView
  *
- * Copyright 2007 - Johannes Schmid <jhs gnome org>
+ * Copyright (C) 2007 - Johannes Schmid <jhs gnome org>
  *
  * GtkSourceView is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -18,7 +18,8 @@
  * along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#pragma once
+#ifndef GTKSOURCEMARK_H
+#define GTKSOURCEMARK_H
 
 #if !defined (GTK_SOURCE_H_INSIDE) && !defined (GTK_SOURCE_COMPILATION)
 #error "Only <gtksourceview/gtksource.h> can be included directly."
@@ -30,29 +31,50 @@
 
 G_BEGIN_DECLS
 
-#define GTK_SOURCE_TYPE_MARK (gtk_source_mark_get_type())
+#define GTK_SOURCE_TYPE_MARK             (gtk_source_mark_get_type ())
+#define GTK_SOURCE_MARK(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_SOURCE_TYPE_MARK, 
GtkSourceMark))
+#define GTK_SOURCE_MARK_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_SOURCE_TYPE_MARK, 
GtkSourceMarkClass))
+#define GTK_SOURCE_IS_MARK(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_SOURCE_TYPE_MARK))
+#define GTK_SOURCE_IS_MARK_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_SOURCE_TYPE_MARK))
+#define GTK_SOURCE_MARK_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_SOURCE_TYPE_MARK, 
GtkSourceMarkClass))
 
-GTK_SOURCE_AVAILABLE_IN_ALL
-G_DECLARE_DERIVABLE_TYPE (GtkSourceMark, gtk_source_mark, GTK_SOURCE, MARK, GtkTextMark)
+typedef struct _GtkSourceMarkClass GtkSourceMarkClass;
+
+typedef struct _GtkSourceMarkPrivate GtkSourceMarkPrivate;
+
+struct _GtkSourceMark
+{
+       GtkTextMark parent_instance;
+
+       GtkSourceMarkPrivate *priv;
+};
 
 struct _GtkSourceMarkClass
 {
        GtkTextMarkClass parent_class;
 
-       /*< private >*/
-       gpointer _reserved[10];
+       /* Padding for future expansion */
+       gpointer padding[10];
 };
 
 GTK_SOURCE_AVAILABLE_IN_ALL
-GtkSourceMark *gtk_source_mark_new          (const gchar *name,
-                                             const gchar *category);
+GType           gtk_source_mark_get_type (void) G_GNUC_CONST;
+
+GTK_SOURCE_AVAILABLE_IN_ALL
+GtkSourceMark   *gtk_source_mark_new           (const gchar    *name,
+                                                const gchar    *category);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-const gchar   *gtk_source_mark_get_category (GtkSourceMark *mark);
+const gchar    *gtk_source_mark_get_category   (GtkSourceMark  *mark);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-GtkSourceMark *gtk_source_mark_next         (GtkSourceMark *mark,
-                                             const gchar   *category);
+GtkSourceMark  *gtk_source_mark_next           (GtkSourceMark  *mark,
+                                                const gchar    *category);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-GtkSourceMark *gtk_source_mark_prev         (GtkSourceMark *mark,
-                                             const gchar   *category);
+GtkSourceMark  *gtk_source_mark_prev           (GtkSourceMark  *mark,
+                                                const gchar    *category);
 
 G_END_DECLS
+
+#endif /* GTKSOURCEMARK_H */
diff --git a/gtksourceview/gtksourcemarkattributes.c b/gtksourceview/gtksourcemarkattributes.c
index 95f3785f..1c3538dd 100644
--- a/gtksourceview/gtksourcemarkattributes.c
+++ b/gtksourceview/gtksourcemarkattributes.c
@@ -2,8 +2,8 @@
  *
  * This file is part of GtkSourceView
  *
- * Copyright 2010 - Jesse van den Kieboom
- * Copyright 2010 - Krzesimir Nowak
+ * Copyright (C) 2010 - Jesse van den Kieboom
+ * Copyright (C) 2010 - Krzesimir Nowak
  *
  * GtkSourceView is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -19,7 +19,9 @@
  * along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "config.h"
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
 
 #include "gtksourcemarkattributes.h"
 #include "gtksourcemark.h"
@@ -75,10 +77,8 @@
  * takes precedence.
  */
 
-struct _GtkSourceMarkAttributes
+struct _GtkSourceMarkAttributesPrivate
 {
-       GObject parent_instance;
-
        GdkRGBA background;
 
        GtkSourcePixbufHelper *helper;
@@ -86,7 +86,7 @@ struct _GtkSourceMarkAttributes
        guint background_set : 1;
 };
 
-G_DEFINE_TYPE (GtkSourceMarkAttributes, gtk_source_mark_attributes, G_TYPE_OBJECT)
+G_DEFINE_TYPE_WITH_PRIVATE (GtkSourceMarkAttributes, gtk_source_mark_attributes, G_TYPE_OBJECT)
 
 enum
 {
@@ -111,36 +111,36 @@ gtk_source_mark_attributes_finalize (GObject *object)
 {
        GtkSourceMarkAttributes *attributes = GTK_SOURCE_MARK_ATTRIBUTES (object);
 
-       gtk_source_pixbuf_helper_free (attributes->helper);
+       gtk_source_pixbuf_helper_free (attributes->priv->helper);
 
        G_OBJECT_CLASS (gtk_source_mark_attributes_parent_class)->finalize (object);
 }
 
 static void
 set_background (GtkSourceMarkAttributes *attributes,
-                const GdkRGBA           *color)
+               const GdkRGBA           *color)
 {
        if (color)
        {
-               attributes->background = *color;
+               attributes->priv->background = *color;
        }
 
-       attributes->background_set = color != NULL;
+       attributes->priv->background_set = color != NULL;
 
        g_object_notify (G_OBJECT (attributes), "background");
 }
 
 static void
 set_icon_name (GtkSourceMarkAttributes *attributes,
-               const gchar             *icon_name)
+              const gchar             *icon_name)
 {
-       if (g_strcmp0 (gtk_source_pixbuf_helper_get_icon_name (attributes->helper),
+       if (g_strcmp0 (gtk_source_pixbuf_helper_get_icon_name (attributes->priv->helper),
                                                               icon_name) == 0)
        {
                return;
        }
 
-       gtk_source_pixbuf_helper_set_icon_name (attributes->helper,
+       gtk_source_pixbuf_helper_set_icon_name (attributes->priv->helper,
                                                icon_name);
 
        g_object_notify (G_OBJECT (attributes), "icon-name");
@@ -148,14 +148,14 @@ set_icon_name (GtkSourceMarkAttributes *attributes,
 
 static void
 set_pixbuf (GtkSourceMarkAttributes *attributes,
-            const GdkPixbuf         *pixbuf)
+           const GdkPixbuf         *pixbuf)
 {
-       if (gtk_source_pixbuf_helper_get_pixbuf (attributes->helper) == pixbuf)
+       if (gtk_source_pixbuf_helper_get_pixbuf (attributes->priv->helper) == pixbuf)
        {
                return;
        }
 
-       gtk_source_pixbuf_helper_set_pixbuf (attributes->helper,
+       gtk_source_pixbuf_helper_set_pixbuf (attributes->priv->helper,
                                             pixbuf);
 
        g_object_notify (G_OBJECT (attributes), "pixbuf");
@@ -163,14 +163,14 @@ set_pixbuf (GtkSourceMarkAttributes *attributes,
 
 static void
 set_gicon (GtkSourceMarkAttributes *attributes,
-           GIcon                   *gicon)
+          GIcon                   *gicon)
 {
-       if (gtk_source_pixbuf_helper_get_gicon (attributes->helper) == gicon)
+       if (gtk_source_pixbuf_helper_get_gicon (attributes->priv->helper) == gicon)
        {
                return;
        }
 
-       gtk_source_pixbuf_helper_set_gicon (attributes->helper,
+       gtk_source_pixbuf_helper_set_gicon (attributes->priv->helper,
                                            gicon);
 
        g_object_notify (G_OBJECT (attributes), "gicon");
@@ -178,9 +178,9 @@ set_gicon (GtkSourceMarkAttributes *attributes,
 
 static void
 gtk_source_mark_attributes_set_property (GObject      *object,
-                                         guint         prop_id,
-                                         const GValue *value,
-                                         GParamSpec   *pspec)
+                                        guint         prop_id,
+                                        const GValue *value,
+                                        GParamSpec   *pspec)
 {
        GtkSourceMarkAttributes *self = GTK_SOURCE_MARK_ATTRIBUTES (object);
 
@@ -206,18 +206,18 @@ gtk_source_mark_attributes_set_property (GObject      *object,
 
 static void
 gtk_source_mark_attributes_get_property (GObject    *object,
-                                         guint       prop_id,
-                                         GValue     *value,
-                                         GParamSpec *pspec)
+                                        guint       prop_id,
+                                        GValue     *value,
+                                        GParamSpec *pspec)
 {
        GtkSourceMarkAttributes *self = GTK_SOURCE_MARK_ATTRIBUTES (object);
 
        switch (prop_id)
        {
                case PROP_BACKGROUND:
-                       if (self->background_set)
+                       if (self->priv->background_set)
                        {
-                               g_value_set_boxed (value, &self->background);
+                               g_value_set_boxed (value, &self->priv->background);
                        }
                        else
                        {
@@ -226,15 +226,15 @@ gtk_source_mark_attributes_get_property (GObject    *object,
                        break;
                case PROP_PIXBUF:
                        g_value_set_object (value,
-                                           gtk_source_pixbuf_helper_get_pixbuf (self->helper));
+                                           gtk_source_pixbuf_helper_get_pixbuf (self->priv->helper));
                        break;
                case PROP_ICON_NAME:
                        g_value_set_string (value,
-                                           gtk_source_pixbuf_helper_get_icon_name (self->helper));
+                                           gtk_source_pixbuf_helper_get_icon_name (self->priv->helper));
                        break;
                case PROP_GICON:
                        g_value_set_object (value,
-                                           gtk_source_pixbuf_helper_get_gicon (self->helper));
+                                           gtk_source_pixbuf_helper_get_gicon (self->priv->helper));
                        break;
                default:
                        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -362,9 +362,9 @@ gtk_source_mark_attributes_class_init (GtkSourceMarkAttributesClass *klass)
 static void
 gtk_source_mark_attributes_init (GtkSourceMarkAttributes *self)
 {
-       self = gtk_source_mark_attributes_get_instance_private (self);
+       self->priv = gtk_source_mark_attributes_get_instance_private (self);
 
-       self->helper = gtk_source_pixbuf_helper_new ();
+       self->priv->helper = gtk_source_pixbuf_helper_new ();
 }
 
 /**
@@ -389,7 +389,7 @@ gtk_source_mark_attributes_new (void)
  */
 void
 gtk_source_mark_attributes_set_background (GtkSourceMarkAttributes *attributes,
-                                           const GdkRGBA           *background)
+                                          const GdkRGBA           *background)
 {
        g_return_if_fail (GTK_SOURCE_IS_MARK_ATTRIBUTES (attributes));
 
@@ -407,15 +407,15 @@ gtk_source_mark_attributes_set_background (GtkSourceMarkAttributes *attributes,
  */
 gboolean
 gtk_source_mark_attributes_get_background (GtkSourceMarkAttributes *attributes,
-                                           GdkRGBA                 *background)
+                                          GdkRGBA                 *background)
 {
        g_return_val_if_fail (GTK_SOURCE_IS_MARK_ATTRIBUTES (attributes), FALSE);
 
        if (background)
        {
-               *background = attributes->background;
+               *background = attributes->priv->background;
        }
-       return attributes->background_set;
+       return attributes->priv->background_set;
 }
 
 /**
@@ -427,7 +427,7 @@ gtk_source_mark_attributes_get_background (GtkSourceMarkAttributes *attributes,
  */
 void
 gtk_source_mark_attributes_set_icon_name (GtkSourceMarkAttributes *attributes,
-                                          const gchar             *icon_name)
+                                         const gchar             *icon_name)
 {
        g_return_if_fail (GTK_SOURCE_IS_MARK_ATTRIBUTES (attributes));
 
@@ -449,7 +449,7 @@ gtk_source_mark_attributes_get_icon_name (GtkSourceMarkAttributes *attributes)
 {
        g_return_val_if_fail (GTK_SOURCE_IS_MARK_ATTRIBUTES (attributes), NULL);
 
-       return gtk_source_pixbuf_helper_get_icon_name (attributes->helper);
+       return gtk_source_pixbuf_helper_get_icon_name (attributes->priv->helper);
 }
 
 /**
@@ -461,7 +461,7 @@ gtk_source_mark_attributes_get_icon_name (GtkSourceMarkAttributes *attributes)
  */
 void
 gtk_source_mark_attributes_set_gicon (GtkSourceMarkAttributes *attributes,
-                                      GIcon                   *gicon)
+                                     GIcon                   *gicon)
 {
        g_return_if_fail (GTK_SOURCE_IS_MARK_ATTRIBUTES (attributes));
 
@@ -483,7 +483,7 @@ gtk_source_mark_attributes_get_gicon (GtkSourceMarkAttributes *attributes)
 {
        g_return_val_if_fail (GTK_SOURCE_IS_MARK_ATTRIBUTES (attributes), NULL);
 
-       return gtk_source_pixbuf_helper_get_gicon (attributes->helper);
+       return gtk_source_pixbuf_helper_get_gicon (attributes->priv->helper);
 }
 
 /**
@@ -495,7 +495,7 @@ gtk_source_mark_attributes_get_gicon (GtkSourceMarkAttributes *attributes)
  */
 void
 gtk_source_mark_attributes_set_pixbuf (GtkSourceMarkAttributes *attributes,
-                                       const GdkPixbuf         *pixbuf)
+                                      const GdkPixbuf         *pixbuf)
 {
        g_return_if_fail (GTK_SOURCE_IS_MARK_ATTRIBUTES (attributes));
 
@@ -517,7 +517,7 @@ gtk_source_mark_attributes_get_pixbuf (GtkSourceMarkAttributes *attributes)
 {
        g_return_val_if_fail (GTK_SOURCE_IS_MARK_ATTRIBUTES (attributes), NULL);
 
-       return gtk_source_pixbuf_helper_get_pixbuf (attributes->helper);
+       return gtk_source_pixbuf_helper_get_pixbuf (attributes->priv->helper);
 }
 
 /**
@@ -531,21 +531,27 @@ gtk_source_mark_attributes_get_pixbuf (GtkSourceMarkAttributes *attributes)
  * gtk_source_mark_attributes_set_gicon() or
  * gtk_source_mark_attributes_set_icon_name(). @size cannot be lower than 1.
  *
- * Returns: (transfer none): A rendered pixbuf. The pixbuf belongs to @attributes
+ * Returns: (transfer none): A #GdkPaintable. The paintable belongs to @attributes
  * and should not be unreffed.
  */
-const GdkPixbuf *
+GdkPaintable *
 gtk_source_mark_attributes_render_icon (GtkSourceMarkAttributes *attributes,
-                                        GtkWidget               *widget,
-                                        gint                     size)
+                                       GtkWidget               *widget,
+                                       gint                     size)
 {
+       GdkPaintable *ret;
+
        g_return_val_if_fail (GTK_SOURCE_IS_MARK_ATTRIBUTES (attributes), NULL);
        g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
        g_return_val_if_fail (size > 0, NULL);
 
-       return gtk_source_pixbuf_helper_render (attributes->helper,
-                                               widget,
-                                               size);
+       ret = gtk_source_pixbuf_helper_render (attributes->priv->helper,
+                                              widget,
+                                              size);
+
+       g_return_val_if_fail (ret == NULL || GDK_IS_PAINTABLE (ret), NULL);
+
+       return ret;
 }
 
 /**
@@ -562,7 +568,7 @@ gtk_source_mark_attributes_render_icon (GtkSourceMarkAttributes *attributes,
  */
 gchar *
 gtk_source_mark_attributes_get_tooltip_text (GtkSourceMarkAttributes *attributes,
-                                             GtkSourceMark           *mark)
+                                            GtkSourceMark           *mark)
 {
        gchar *ret;
 
@@ -589,7 +595,7 @@ gtk_source_mark_attributes_get_tooltip_text (GtkSourceMarkAttributes *attributes
  */
 gchar *
 gtk_source_mark_attributes_get_tooltip_markup (GtkSourceMarkAttributes *attributes,
-                                               GtkSourceMark           *mark)
+                                              GtkSourceMark           *mark)
 {
        gchar *ret;
 
@@ -601,3 +607,4 @@ gtk_source_mark_attributes_get_tooltip_markup (GtkSourceMarkAttributes *attribut
 
        return ret;
 }
+
diff --git a/gtksourceview/gtksourcemarkattributes.h b/gtksourceview/gtksourcemarkattributes.h
index 29cb0c85..714fdd4c 100644
--- a/gtksourceview/gtksourcemarkattributes.h
+++ b/gtksourceview/gtksourcemarkattributes.h
@@ -2,8 +2,8 @@
  *
  * This file is part of GtkSourceView
  *
- * Copyright 2010 - Jesse van den Kieboom
- * Copyright 2010 - Krzesimir Nowak
+ * Copyright (C) 2010 - Jesse van den Kieboom
+ * Copyright (C) 2010 - Krzesimir Nowak
  *
  * GtkSourceView is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -19,7 +19,8 @@
  * along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#pragma once
+#ifndef GTK_SOURCE_MARK_ATTRIBUTES_H
+#define GTK_SOURCE_MARK_ATTRIBUTES_H
 
 #if !defined (GTK_SOURCE_H_INSIDE) && !defined (GTK_SOURCE_COMPILATION)
 #error "Only <gtksourceview/gtksource.h> can be included directly."
@@ -31,43 +32,82 @@
 
 G_BEGIN_DECLS
 
-#define GTK_SOURCE_TYPE_MARK_ATTRIBUTES (gtk_source_mark_attributes_get_type())
+#define GTK_SOURCE_TYPE_MARK_ATTRIBUTES                        (gtk_source_mark_attributes_get_type ())
+#define GTK_SOURCE_MARK_ATTRIBUTES(obj)                        (G_TYPE_CHECK_INSTANCE_CAST ((obj), 
GTK_SOURCE_TYPE_MARK_ATTRIBUTES, GtkSourceMarkAttributes))
+#define GTK_SOURCE_MARK_ATTRIBUTES_CLASS(klass)                (G_TYPE_CHECK_CLASS_CAST ((klass), 
GTK_SOURCE_TYPE_MARK_ATTRIBUTES, GtkSourceMarkAttributesClass))
+#define GTK_SOURCE_IS_MARK_ATTRIBUTES(obj)             (G_TYPE_CHECK_INSTANCE_TYPE ((obj), 
GTK_SOURCE_TYPE_MARK_ATTRIBUTES))
+#define GTK_SOURCE_IS_MARK_ATTRIBUTES_CLASS(klass)     (G_TYPE_CHECK_CLASS_TYPE ((klass), 
GTK_SOURCE_TYPE_MARK_ATTRIBUTES))
+#define GTK_SOURCE_MARK_ATTRIBUTES_GET_CLASS(obj)      (G_TYPE_INSTANCE_GET_CLASS ((obj), 
GTK_SOURCE_TYPE_MARK_ATTRIBUTES, GtkSourceMarkAttributesClass))
+
+typedef struct _GtkSourceMarkAttributesClass   GtkSourceMarkAttributesClass;
+typedef struct _GtkSourceMarkAttributesPrivate GtkSourceMarkAttributesPrivate;
+
+struct _GtkSourceMarkAttributes
+{
+       /*< private >*/
+       GObject parent;
+
+       GtkSourceMarkAttributesPrivate *priv;
+
+       /*< public >*/
+};
+
+struct _GtkSourceMarkAttributesClass
+{
+       /*< private >*/
+       GObjectClass parent_class;
+
+       gpointer padding[10];
+};
 
 GTK_SOURCE_AVAILABLE_IN_ALL
-G_DECLARE_FINAL_TYPE (GtkSourceMarkAttributes, gtk_source_mark_attributes, GTK_SOURCE, MARK_ATTRIBUTES, 
GObject)
+GType gtk_source_mark_attributes_get_type (void) G_GNUC_CONST;
 
 GTK_SOURCE_AVAILABLE_IN_ALL
-GtkSourceMarkAttributes *gtk_source_mark_attributes_new                (void);
+GtkSourceMarkAttributes *gtk_source_mark_attributes_new (void);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-void                     gtk_source_mark_attributes_set_background     (GtkSourceMarkAttributes *attributes,
-                                                                        const GdkRGBA           *background);
+void             gtk_source_mark_attributes_set_background      (GtkSourceMarkAttributes *attributes,
+                                                                 const GdkRGBA           *background);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-gboolean                 gtk_source_mark_attributes_get_background     (GtkSourceMarkAttributes *attributes,
-                                                                        GdkRGBA                 *background);
+gboolean         gtk_source_mark_attributes_get_background      (GtkSourceMarkAttributes *attributes,
+                                                                 GdkRGBA                 *background);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-void                     gtk_source_mark_attributes_set_icon_name      (GtkSourceMarkAttributes *attributes,
-                                                                        const gchar             *icon_name);
+void             gtk_source_mark_attributes_set_icon_name       (GtkSourceMarkAttributes *attributes,
+                                                                 const gchar             *icon_name);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-const gchar             *gtk_source_mark_attributes_get_icon_name      (GtkSourceMarkAttributes *attributes);
+const gchar     *gtk_source_mark_attributes_get_icon_name       (GtkSourceMarkAttributes *attributes);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-void                     gtk_source_mark_attributes_set_gicon          (GtkSourceMarkAttributes *attributes,
-                                                                        GIcon                   *gicon);
+void             gtk_source_mark_attributes_set_gicon           (GtkSourceMarkAttributes *attributes,
+                                                                 GIcon                   *gicon);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-GIcon                   *gtk_source_mark_attributes_get_gicon          (GtkSourceMarkAttributes *attributes);
+GIcon           *gtk_source_mark_attributes_get_gicon           (GtkSourceMarkAttributes *attributes);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-void                     gtk_source_mark_attributes_set_pixbuf         (GtkSourceMarkAttributes *attributes,
-                                                                        const GdkPixbuf         *pixbuf);
+void             gtk_source_mark_attributes_set_pixbuf          (GtkSourceMarkAttributes *attributes,
+                                                                 const GdkPixbuf         *pixbuf);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-const GdkPixbuf         *gtk_source_mark_attributes_get_pixbuf         (GtkSourceMarkAttributes *attributes);
+const GdkPixbuf *gtk_source_mark_attributes_get_pixbuf          (GtkSourceMarkAttributes *attributes);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-const GdkPixbuf         *gtk_source_mark_attributes_render_icon        (GtkSourceMarkAttributes *attributes,
-                                                                        GtkWidget               *widget,
-                                                                        gint                     size);
+GdkPaintable    *gtk_source_mark_attributes_render_icon         (GtkSourceMarkAttributes *attributes,
+                                                                 GtkWidget               *widget,
+                                                                 gint                   size);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-gchar                   *gtk_source_mark_attributes_get_tooltip_text   (GtkSourceMarkAttributes *attributes,
-                                                                        GtkSourceMark           *mark);
+gchar           *gtk_source_mark_attributes_get_tooltip_text    (GtkSourceMarkAttributes *attributes,
+                                                                 GtkSourceMark           *mark);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-gchar                   *gtk_source_mark_attributes_get_tooltip_markup (GtkSourceMarkAttributes *attributes,
-                                                                        GtkSourceMark           *mark);
+gchar           *gtk_source_mark_attributes_get_tooltip_markup  (GtkSourceMarkAttributes *attributes,
+                                                                 GtkSourceMark           *mark);
 
 G_END_DECLS
+
+#endif /* GTK_SOURCE_MARK_ATTRIBUTES_H */
diff --git a/gtksourceview/gtksourcemarkssequence-private.h b/gtksourceview/gtksourcemarkssequence-private.h
index 0da2194b..6149bea6 100644
--- a/gtksourceview/gtksourcemarkssequence-private.h
+++ b/gtksourceview/gtksourcemarkssequence-private.h
@@ -2,7 +2,7 @@
 /*
  * This file is part of GtkSourceView
  *
- * Copyright 2013 - Sébastien Wilmet <swilmet gnome org>
+ * Copyright (C) 2013 - Sébastien Wilmet <swilmet gnome org>
  *
  * GtkSourceView is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -18,46 +18,79 @@
  * along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#pragma once
+#ifndef GTK_SOURCE_MARKS_SEQUENCE_PRIVATE_H
+#define GTK_SOURCE_MARKS_SEQUENCE_PRIVATE_H
 
 #include <gtk/gtk.h>
+
 #include "gtksourcetypes-private.h"
 
 G_BEGIN_DECLS
 
-#define GTK_SOURCE_TYPE_MARKS_SEQUENCE (_gtk_source_marks_sequence_get_type())
+#define GTK_SOURCE_TYPE_MARKS_SEQUENCE             (_gtk_source_marks_sequence_get_type ())
+#define GTK_SOURCE_MARKS_SEQUENCE(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), 
GTK_SOURCE_TYPE_MARKS_SEQUENCE, GtkSourceMarksSequence))
+#define GTK_SOURCE_MARKS_SEQUENCE_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), 
GTK_SOURCE_TYPE_MARKS_SEQUENCE, GtkSourceMarksSequenceClass))
+#define GTK_SOURCE_IS_MARKS_SEQUENCE(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), 
GTK_SOURCE_TYPE_MARKS_SEQUENCE))
+#define GTK_SOURCE_IS_MARKS_SEQUENCE_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), 
GTK_SOURCE_TYPE_MARKS_SEQUENCE))
+#define GTK_SOURCE_MARKS_SEQUENCE_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), 
GTK_SOURCE_TYPE_MARKS_SEQUENCE, GtkSourceMarksSequenceClass))
+
+typedef struct _GtkSourceMarksSequenceClass    GtkSourceMarksSequenceClass;
+typedef struct _GtkSourceMarksSequencePrivate  GtkSourceMarksSequencePrivate;
+
+struct _GtkSourceMarksSequence
+{
+       GObject parent;
+
+       GtkSourceMarksSequencePrivate *priv;
+};
+
+struct _GtkSourceMarksSequenceClass
+{
+       GObjectClass parent_class;
+};
 
 G_GNUC_INTERNAL
-G_DECLARE_FINAL_TYPE (GtkSourceMarksSequence, _gtk_source_marks_sequence, GTK_SOURCE, MARKS_SEQUENCE, 
GObject)
+GType                   _gtk_source_marks_sequence_get_type            (void) G_GNUC_CONST;
 
 G_GNUC_INTERNAL
-GtkSourceMarksSequence *_gtk_source_marks_sequence_new                (GtkTextBuffer          *buffer);
+GtkSourceMarksSequence *_gtk_source_marks_sequence_new                 (GtkTextBuffer          *buffer);
+
 G_GNUC_INTERNAL
-gboolean                _gtk_source_marks_sequence_is_empty           (GtkSourceMarksSequence *seq);
+gboolean                _gtk_source_marks_sequence_is_empty            (GtkSourceMarksSequence *seq);
+
 G_GNUC_INTERNAL
-void                    _gtk_source_marks_sequence_add                (GtkSourceMarksSequence *seq,
-                                                                       GtkTextMark            *mark);
+void                    _gtk_source_marks_sequence_add                 (GtkSourceMarksSequence *seq,
+                                                                        GtkTextMark            *mark);
+
 G_GNUC_INTERNAL
-void                    _gtk_source_marks_sequence_remove             (GtkSourceMarksSequence *seq,
-                                                                       GtkTextMark            *mark);
+void                    _gtk_source_marks_sequence_remove              (GtkSourceMarksSequence *seq,
+                                                                        GtkTextMark            *mark);
+
 G_GNUC_INTERNAL
-GtkTextMark            *_gtk_source_marks_sequence_next               (GtkSourceMarksSequence *seq,
-                                                                       GtkTextMark            *mark);
+GtkTextMark            *_gtk_source_marks_sequence_next                (GtkSourceMarksSequence *seq,
+                                                                        GtkTextMark            *mark);
+
 G_GNUC_INTERNAL
-GtkTextMark            *_gtk_source_marks_sequence_prev               (GtkSourceMarksSequence *seq,
-                                                                       GtkTextMark            *mark);
+GtkTextMark            *_gtk_source_marks_sequence_prev                (GtkSourceMarksSequence *seq,
+                                                                        GtkTextMark            *mark);
+
 G_GNUC_INTERNAL
-gboolean                _gtk_source_marks_sequence_forward_iter       (GtkSourceMarksSequence *seq,
-                                                                       GtkTextIter            *iter);
+gboolean                _gtk_source_marks_sequence_forward_iter        (GtkSourceMarksSequence *seq,
+                                                                        GtkTextIter            *iter);
+
 G_GNUC_INTERNAL
-gboolean                _gtk_source_marks_sequence_backward_iter      (GtkSourceMarksSequence *seq,
-                                                                       GtkTextIter            *iter);
+gboolean                _gtk_source_marks_sequence_backward_iter       (GtkSourceMarksSequence *seq,
+                                                                        GtkTextIter            *iter);
+
 G_GNUC_INTERNAL
-GSList                 *_gtk_source_marks_sequence_get_marks_at_iter  (GtkSourceMarksSequence *seq,
-                                                                       const GtkTextIter      *iter);
+GSList                 *_gtk_source_marks_sequence_get_marks_at_iter   (GtkSourceMarksSequence *seq,
+                                                                        const GtkTextIter      *iter);
+
 G_GNUC_INTERNAL
-GSList                 *_gtk_source_marks_sequence_get_marks_in_range (GtkSourceMarksSequence *seq,
-                                                                       const GtkTextIter      *iter1,
-                                                                       const GtkTextIter      *iter2);
+GSList                 *_gtk_source_marks_sequence_get_marks_in_range  (GtkSourceMarksSequence *seq,
+                                                                        const GtkTextIter      *iter1,
+                                                                        const GtkTextIter      *iter2);
 
 G_END_DECLS
+
+#endif /* GTK_SOURCE_MARKS_SEQUENCE_PRIVATE_H */
diff --git a/gtksourceview/gtksourcemarkssequence.c b/gtksourceview/gtksourcemarkssequence.c
index c4b723d7..e1128481 100644
--- a/gtksourceview/gtksourcemarkssequence.c
+++ b/gtksourceview/gtksourcemarkssequence.c
@@ -2,7 +2,7 @@
 /*
  * This file is part of GtkSourceView
  *
- * Copyright 2013 - Sébastien Wilmet <swilmet gnome org>
+ * Copyright (C) 2013 - Sébastien Wilmet <swilmet gnome org>
  *
  * GtkSourceView is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -18,7 +18,9 @@
  * along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "config.h"
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
 
 #include "gtksourcemarkssequence-private.h"
 
@@ -41,10 +43,8 @@ enum
        PROP_BUFFER,
 };
 
-struct _GtkSourceMarksSequence
+struct _GtkSourceMarksSequencePrivate
 {
-       GObject parent_instance;
-
        GtkTextBuffer *buffer;
        GSequence *seq;
 
@@ -54,35 +54,35 @@ struct _GtkSourceMarksSequence
        GQuark quark;
 };
 
-G_DEFINE_TYPE (GtkSourceMarksSequence, _gtk_source_marks_sequence, G_TYPE_OBJECT)
+G_DEFINE_TYPE_WITH_PRIVATE (GtkSourceMarksSequence, _gtk_source_marks_sequence, G_TYPE_OBJECT)
 
 static void
 remove_qdata (GtkTextMark            *mark,
-              GtkSourceMarksSequence *seq)
+             GtkSourceMarksSequence *seq)
 {
        g_object_set_qdata (G_OBJECT (mark),
-                           seq->quark,
+                           seq->priv->quark,
                            NULL);
 }
 
 static void
 free_sequence (GtkSourceMarksSequence *seq)
 {
-       if (seq->seq != NULL)
+       if (seq->priv->seq != NULL)
        {
-               g_sequence_foreach (seq->seq,
+               g_sequence_foreach (seq->priv->seq,
                                    (GFunc)remove_qdata,
                                    seq);
 
-               g_sequence_free (seq->seq);
-               seq->seq = NULL;
+               g_sequence_free (seq->priv->seq);
+               seq->priv->seq = NULL;
        }
 }
 
 static gint
 compare_marks (GtkTextMark *mark1,
-               GtkTextMark *mark2,
-               gpointer     user_data)
+              GtkTextMark *mark2,
+              gpointer     user_data)
 {
        GtkTextBuffer *buffer;
        GtkTextIter iter1;
@@ -103,13 +103,13 @@ compare_marks (GtkTextMark *mark1,
 
 static void
 mark_set_cb (GtkTextBuffer          *buffer,
-             GtkTextIter            *location,
-             GtkTextMark            *mark,
-             GtkSourceMarksSequence *seq)
+            GtkTextIter            *location,
+            GtkTextMark            *mark,
+            GtkSourceMarksSequence *seq)
 {
        GSequenceIter *seq_iter;
 
-       seq_iter = g_object_get_qdata (G_OBJECT (mark), seq->quark);
+       seq_iter = g_object_get_qdata (G_OBJECT (mark), seq->priv->quark);
 
        if (seq_iter != NULL)
        {
@@ -121,22 +121,22 @@ mark_set_cb (GtkTextBuffer          *buffer,
 
 static void
 mark_deleted_cb (GtkTextBuffer          *buffer,
-                 GtkTextMark            *mark,
-                 GtkSourceMarksSequence *seq)
+                GtkTextMark            *mark,
+                GtkSourceMarksSequence *seq)
 {
        _gtk_source_marks_sequence_remove (seq, mark);
 }
 
 static void
 set_buffer (GtkSourceMarksSequence *seq,
-            GtkTextBuffer          *buffer)
+           GtkTextBuffer          *buffer)
 {
-       g_assert (seq->buffer == NULL);
+       g_assert (seq->priv->buffer == NULL);
 
-       seq->buffer = buffer;
+       seq->priv->buffer = buffer;
 
        g_object_add_weak_pointer (G_OBJECT (buffer),
-                                  (gpointer *)&seq->buffer);
+                                  (gpointer *)&seq->priv->buffer);
 
        g_signal_connect_object (buffer,
                                 "mark-set",
@@ -156,12 +156,12 @@ _gtk_source_marks_sequence_dispose (GObject *object)
 {
        GtkSourceMarksSequence *seq = GTK_SOURCE_MARKS_SEQUENCE (object);
 
-       if (seq->buffer != NULL)
+       if (seq->priv->buffer != NULL)
        {
-               g_object_remove_weak_pointer (G_OBJECT (seq->buffer),
-                                             (gpointer *)&seq->buffer);
+               g_object_remove_weak_pointer (G_OBJECT (seq->priv->buffer),
+                                             (gpointer *)&seq->priv->buffer);
 
-               seq->buffer = NULL;
+               seq->priv->buffer = NULL;
        }
 
        free_sequence (seq);
@@ -171,9 +171,9 @@ _gtk_source_marks_sequence_dispose (GObject *object)
 
 static void
 _gtk_source_marks_sequence_get_property (GObject    *object,
-                                         guint       prop_id,
-                                         GValue     *value,
-                                         GParamSpec *pspec)
+                                        guint       prop_id,
+                                        GValue     *value,
+                                        GParamSpec *pspec)
 {
        GtkSourceMarksSequence *seq;
 
@@ -184,7 +184,7 @@ _gtk_source_marks_sequence_get_property (GObject    *object,
        switch (prop_id)
        {
                case PROP_BUFFER:
-                       g_value_set_object (value, seq->buffer);
+                       g_value_set_object (value, seq->priv->buffer);
                        break;
 
                default:
@@ -195,9 +195,9 @@ _gtk_source_marks_sequence_get_property (GObject    *object,
 
 static void
 _gtk_source_marks_sequence_set_property (GObject      *object,
-                                         guint         prop_id,
-                                         const GValue *value,
-                                         GParamSpec   *pspec)
+                                        guint         prop_id,
+                                        const GValue *value,
+                                        GParamSpec   *pspec)
 {
        GtkSourceMarksSequence *seq;
 
@@ -242,10 +242,12 @@ _gtk_source_marks_sequence_init (GtkSourceMarksSequence *seq)
 {
        gchar *unique_str;
 
-       seq->seq = g_sequence_new ((GDestroyNotify)g_object_unref);
+       seq->priv = _gtk_source_marks_sequence_get_instance_private (seq);
+
+       seq->priv->seq = g_sequence_new ((GDestroyNotify)g_object_unref);
 
        unique_str = g_strdup_printf ("gtk-source-marks-sequence-%p", seq);
-       seq->quark = g_quark_from_string (unique_str);
+       seq->priv->quark = g_quark_from_string (unique_str);
        g_free (unique_str);
 }
 
@@ -264,20 +266,20 @@ _gtk_source_marks_sequence_is_empty (GtkSourceMarksSequence *seq)
 {
        g_return_val_if_fail (GTK_SOURCE_IS_MARKS_SEQUENCE (seq), TRUE);
 
-       return g_sequence_is_empty (seq->seq);
+       return g_sequence_is_empty (seq->priv->seq);
 }
 
 void
 _gtk_source_marks_sequence_add (GtkSourceMarksSequence *seq,
-                                GtkTextMark            *mark)
+                               GtkTextMark            *mark)
 {
        GSequenceIter *seq_iter;
 
        g_return_if_fail (GTK_SOURCE_IS_MARKS_SEQUENCE (seq));
        g_return_if_fail (GTK_IS_TEXT_MARK (mark));
-       g_return_if_fail (gtk_text_mark_get_buffer (mark) == seq->buffer);
+       g_return_if_fail (gtk_text_mark_get_buffer (mark) == seq->priv->buffer);
 
-       seq_iter = g_object_get_qdata (G_OBJECT (mark), seq->quark);
+       seq_iter = g_object_get_qdata (G_OBJECT (mark), seq->priv->quark);
 
        if (seq_iter != NULL)
        {
@@ -285,46 +287,46 @@ _gtk_source_marks_sequence_add (GtkSourceMarksSequence *seq,
                return;
        }
 
-       seq_iter = g_sequence_insert_sorted (seq->seq,
+       seq_iter = g_sequence_insert_sorted (seq->priv->seq,
                                             mark,
                                             (GCompareDataFunc)compare_marks,
                                             NULL);
 
        g_object_ref (mark);
        g_object_set_qdata (G_OBJECT (mark),
-                           seq->quark,
+                           seq->priv->quark,
                            seq_iter);
 }
 
 void
 _gtk_source_marks_sequence_remove (GtkSourceMarksSequence *seq,
-                                   GtkTextMark            *mark)
+                                  GtkTextMark            *mark)
 {
        GSequenceIter *seq_iter;
 
        g_return_if_fail (GTK_SOURCE_IS_MARKS_SEQUENCE (seq));
        g_return_if_fail (GTK_IS_TEXT_MARK (mark));
 
-       seq_iter = g_object_get_qdata (G_OBJECT (mark), seq->quark);
+       seq_iter = g_object_get_qdata (G_OBJECT (mark), seq->priv->quark);
 
        if (seq_iter != NULL)
        {
-               g_object_set_qdata (G_OBJECT (mark), seq->quark, NULL);
+               g_object_set_qdata (G_OBJECT (mark), seq->priv->quark, NULL);
                g_sequence_remove (seq_iter);
        }
 }
 
 GtkTextMark *
 _gtk_source_marks_sequence_next (GtkSourceMarksSequence *seq,
-                                 GtkTextMark            *mark)
+                                GtkTextMark            *mark)
 {
        GSequenceIter *seq_iter;
 
        g_return_val_if_fail (GTK_SOURCE_IS_MARKS_SEQUENCE (seq), NULL);
        g_return_val_if_fail (GTK_IS_TEXT_MARK (mark), NULL);
-       g_return_val_if_fail (gtk_text_mark_get_buffer (mark) == seq->buffer, NULL);
+       g_return_val_if_fail (gtk_text_mark_get_buffer (mark) == seq->priv->buffer, NULL);
 
-       seq_iter = g_object_get_qdata (G_OBJECT (mark), seq->quark);
+       seq_iter = g_object_get_qdata (G_OBJECT (mark), seq->priv->quark);
 
        g_return_val_if_fail (seq_iter != NULL, NULL);
 
@@ -335,15 +337,15 @@ _gtk_source_marks_sequence_next (GtkSourceMarksSequence *seq,
 
 GtkTextMark *
 _gtk_source_marks_sequence_prev (GtkSourceMarksSequence *seq,
-                                 GtkTextMark            *mark)
+                                GtkTextMark            *mark)
 {
        GSequenceIter *seq_iter;
 
        g_return_val_if_fail (GTK_SOURCE_IS_MARKS_SEQUENCE (seq), NULL);
        g_return_val_if_fail (GTK_IS_TEXT_MARK (mark), NULL);
-       g_return_val_if_fail (gtk_text_mark_get_buffer (mark) == seq->buffer, NULL);
+       g_return_val_if_fail (gtk_text_mark_get_buffer (mark) == seq->priv->buffer, NULL);
 
-       seq_iter = g_object_get_qdata (G_OBJECT (mark), seq->quark);
+       seq_iter = g_object_get_qdata (G_OBJECT (mark), seq->priv->quark);
 
        g_return_val_if_fail (seq_iter != NULL, NULL);
 
@@ -362,33 +364,33 @@ _gtk_source_marks_sequence_prev (GtkSourceMarksSequence *seq,
  */
 gboolean
 _gtk_source_marks_sequence_forward_iter (GtkSourceMarksSequence *seq,
-                                         GtkTextIter            *iter)
+                                        GtkTextIter            *iter)
 {
        GtkTextMark *mark;
        GSequenceIter *seq_iter;
 
        g_return_val_if_fail (GTK_SOURCE_IS_MARKS_SEQUENCE (seq), FALSE);
        g_return_val_if_fail (iter != NULL, FALSE);
-       g_return_val_if_fail (gtk_text_iter_get_buffer (iter) == seq->buffer, FALSE);
+       g_return_val_if_fail (gtk_text_iter_get_buffer (iter) == seq->priv->buffer, FALSE);
 
-       mark = gtk_text_buffer_create_mark (seq->buffer,
+       mark = gtk_text_buffer_create_mark (seq->priv->buffer,
                                            NULL,
                                            iter,
                                            TRUE);
 
-       seq_iter = g_sequence_search (seq->seq,
+       seq_iter = g_sequence_search (seq->priv->seq,
                                      mark,
                                      (GCompareDataFunc)compare_marks,
                                      NULL);
 
-       gtk_text_buffer_delete_mark (seq->buffer, mark);
+       gtk_text_buffer_delete_mark (seq->priv->buffer, mark);
 
        while (!g_sequence_iter_is_end (seq_iter))
        {
                GtkTextMark *cur_mark = g_sequence_get (seq_iter);
                GtkTextIter cur_iter;
 
-               gtk_text_buffer_get_iter_at_mark (seq->buffer, &cur_iter, cur_mark);
+               gtk_text_buffer_get_iter_at_mark (seq->priv->buffer, &cur_iter, cur_mark);
 
                if (gtk_text_iter_compare (iter, &cur_iter) < 0)
                {
@@ -407,26 +409,26 @@ _gtk_source_marks_sequence_forward_iter (GtkSourceMarksSequence *seq,
  */
 gboolean
 _gtk_source_marks_sequence_backward_iter (GtkSourceMarksSequence *seq,
-                                          GtkTextIter            *iter)
+                                         GtkTextIter            *iter)
 {
        GtkTextMark *mark;
        GSequenceIter *seq_iter;
 
        g_return_val_if_fail (GTK_SOURCE_IS_MARKS_SEQUENCE (seq), FALSE);
        g_return_val_if_fail (iter != NULL, FALSE);
-       g_return_val_if_fail (gtk_text_iter_get_buffer (iter) == seq->buffer, FALSE);
+       g_return_val_if_fail (gtk_text_iter_get_buffer (iter) == seq->priv->buffer, FALSE);
 
-       mark = gtk_text_buffer_create_mark (seq->buffer,
+       mark = gtk_text_buffer_create_mark (seq->priv->buffer,
                                            NULL,
                                            iter,
                                            TRUE);
 
-       seq_iter = g_sequence_search (seq->seq,
+       seq_iter = g_sequence_search (seq->priv->seq,
                                      mark,
                                      (GCompareDataFunc)compare_marks,
                                      NULL);
 
-       gtk_text_buffer_delete_mark (seq->buffer, mark);
+       gtk_text_buffer_delete_mark (seq->priv->buffer, mark);
 
        if (g_sequence_iter_is_end (seq_iter))
        {
@@ -446,7 +448,7 @@ _gtk_source_marks_sequence_backward_iter (GtkSourceMarksSequence *seq,
 
                cur_mark = g_sequence_get (seq_iter);
 
-               gtk_text_buffer_get_iter_at_mark (seq->buffer, &cur_iter, cur_mark);
+               gtk_text_buffer_get_iter_at_mark (seq->priv->buffer, &cur_iter, cur_mark);
 
                if (gtk_text_iter_compare (&cur_iter, iter) < 0)
                {
@@ -467,8 +469,8 @@ _gtk_source_marks_sequence_backward_iter (GtkSourceMarksSequence *seq,
 
 GSList *
 _gtk_source_marks_sequence_get_marks_in_range (GtkSourceMarksSequence *seq,
-                                               const GtkTextIter      *iter1,
-                                               const GtkTextIter      *iter2)
+                                              const GtkTextIter      *iter1,
+                                              const GtkTextIter      *iter2)
 {
        GtkTextIter start;
        GtkTextIter end;
@@ -480,25 +482,25 @@ _gtk_source_marks_sequence_get_marks_in_range (GtkSourceMarksSequence *seq,
        g_return_val_if_fail (GTK_SOURCE_IS_MARKS_SEQUENCE (seq), NULL);
        g_return_val_if_fail (iter1 != NULL, NULL);
        g_return_val_if_fail (iter2 != NULL, NULL);
-       g_return_val_if_fail (gtk_text_iter_get_buffer (iter1) == seq->buffer, NULL);
-       g_return_val_if_fail (gtk_text_iter_get_buffer (iter2) == seq->buffer, NULL);
+       g_return_val_if_fail (gtk_text_iter_get_buffer (iter1) == seq->priv->buffer, NULL);
+       g_return_val_if_fail (gtk_text_iter_get_buffer (iter2) == seq->priv->buffer, NULL);
 
        start = *iter1;
        end = *iter2;
 
        gtk_text_iter_order (&start, &end);
 
-       mark_start = gtk_text_buffer_create_mark (seq->buffer,
+       mark_start = gtk_text_buffer_create_mark (seq->priv->buffer,
                                                  NULL,
                                                  &start,
                                                  TRUE);
 
-       seq_iter = g_sequence_search (seq->seq,
+       seq_iter = g_sequence_search (seq->priv->seq,
                                      mark_start,
                                      (GCompareDataFunc)compare_marks,
                                      NULL);
 
-       gtk_text_buffer_delete_mark (seq->buffer, mark_start);
+       gtk_text_buffer_delete_mark (seq->priv->buffer, mark_start);
 
        if (g_sequence_iter_is_end (seq_iter))
        {
@@ -519,7 +521,7 @@ _gtk_source_marks_sequence_get_marks_in_range (GtkSourceMarksSequence *seq,
                GtkTextIter cur_iter;
 
                cur_mark = g_sequence_get (seq_iter);
-               gtk_text_buffer_get_iter_at_mark (seq->buffer, &cur_iter, cur_mark);
+               gtk_text_buffer_get_iter_at_mark (seq->priv->buffer, &cur_iter, cur_mark);
 
                if (gtk_text_iter_compare (&cur_iter, &start) < 0)
                {
@@ -552,7 +554,7 @@ _gtk_source_marks_sequence_get_marks_in_range (GtkSourceMarksSequence *seq,
                GtkTextIter cur_iter;
 
                cur_mark = g_sequence_get (seq_iter);
-               gtk_text_buffer_get_iter_at_mark (seq->buffer, &cur_iter, cur_mark);
+               gtk_text_buffer_get_iter_at_mark (seq->priv->buffer, &cur_iter, cur_mark);
 
                if (gtk_text_iter_compare (&end, &cur_iter) < 0)
                {
@@ -567,7 +569,7 @@ _gtk_source_marks_sequence_get_marks_in_range (GtkSourceMarksSequence *seq,
 
 GSList *
 _gtk_source_marks_sequence_get_marks_at_iter (GtkSourceMarksSequence *seq,
-                                              const GtkTextIter      *iter)
+                                             const GtkTextIter      *iter)
 {
        return _gtk_source_marks_sequence_get_marks_in_range (seq, iter, iter);
 }
diff --git a/gtksourceview/gtksourcemarshalers.list b/gtksourceview/gtksourcemarshalers.list
index de20fb82..7d4032c1 100644
--- a/gtksourceview/gtksourcemarshalers.list
+++ b/gtksourceview/gtksourcemarshalers.list
@@ -1,9 +1,12 @@
-BOOLEAN:BOXED,BOXED,INT,INT,OBJECT
 BOOLEAN:BOXED,BOXED,BOXED
+BOOLEAN:BOXED,BOXED,INT,INT,OBJECT
+BOOLEAN:BOXED,BOXED,OBJECT
 STRING:OBJECT
 VOID:BOXED,BOXED
 VOID:BOXED,BOXED,BOXED
+VOID:BOXED,BOXED,FLAGS
+VOID:BOXED,BOXED,OBJECT
 VOID:BOXED,ENUM
 VOID:BOXED,INT
 VOID:ENUM,INT
-VOID:BOXED,BOXED,FLAGS
+VOID:OBJECT,UINT
diff --git a/gtksourceview/gtksourcepixbufhelper-private.h b/gtksourceview/gtksourcepixbufhelper-private.h
index 58904256..d53e9980 100644
--- a/gtksourceview/gtksourcepixbufhelper-private.h
+++ b/gtksourceview/gtksourcepixbufhelper-private.h
@@ -2,7 +2,7 @@
  *
  * This file is part of GtkSourceView
  *
- * Copyright 2010 - Jesse van den Kieboom
+ * Copyright (C) 2010 - Jesse van den Kieboom
  *
  * GtkSourceView is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -18,36 +18,43 @@
  * along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#pragma once
+#ifndef GTK_SOURCE_PIXBUF_HELPER_PRIVATE_H
+#define GTK_SOURCE_PIXBUF_HELPER_PRIVATE_H
 
 #include <gtk/gtk.h>
 
 #include "gtksourcetypes-private.h"
 
-G_BEGIN_DECLS
-
 G_GNUC_INTERNAL
-GtkSourcePixbufHelper *gtk_source_pixbuf_helper_new           (void);
+GtkSourcePixbufHelper *gtk_source_pixbuf_helper_new (void);
+
 G_GNUC_INTERNAL
-void                   gtk_source_pixbuf_helper_free          (GtkSourcePixbufHelper *helper);
+void gtk_source_pixbuf_helper_free (GtkSourcePixbufHelper *helper);
+
 G_GNUC_INTERNAL
-void                   gtk_source_pixbuf_helper_set_pixbuf    (GtkSourcePixbufHelper *helper,
-                                                               const GdkPixbuf       *pixbuf);
+void gtk_source_pixbuf_helper_set_pixbuf (GtkSourcePixbufHelper *helper,
+                                          const GdkPixbuf       *pixbuf);
+
 G_GNUC_INTERNAL
-GdkPixbuf             *gtk_source_pixbuf_helper_get_pixbuf    (GtkSourcePixbufHelper *helper);
+GdkPixbuf *gtk_source_pixbuf_helper_get_pixbuf (GtkSourcePixbufHelper *helper);
+
 G_GNUC_INTERNAL
-void                   gtk_source_pixbuf_helper_set_icon_name (GtkSourcePixbufHelper *helper,
-                                                               const gchar           *icon_name);
+void gtk_source_pixbuf_helper_set_icon_name (GtkSourcePixbufHelper *helper,
+                                             const gchar           *icon_name);
+
 G_GNUC_INTERNAL
-const gchar           *gtk_source_pixbuf_helper_get_icon_name (GtkSourcePixbufHelper *helper);
+const gchar *gtk_source_pixbuf_helper_get_icon_name (GtkSourcePixbufHelper *helper);
+
 G_GNUC_INTERNAL
-void                   gtk_source_pixbuf_helper_set_gicon     (GtkSourcePixbufHelper *helper,
-                                                               GIcon                 *gicon);
+void gtk_source_pixbuf_helper_set_gicon (GtkSourcePixbufHelper *helper,
+                                         GIcon                 *gicon);
+
 G_GNUC_INTERNAL
-GIcon                 *gtk_source_pixbuf_helper_get_gicon     (GtkSourcePixbufHelper *helper);
+GIcon *gtk_source_pixbuf_helper_get_gicon (GtkSourcePixbufHelper *helper);
+
 G_GNUC_INTERNAL
-GdkPixbuf             *gtk_source_pixbuf_helper_render        (GtkSourcePixbufHelper *helper,
-                                                               GtkWidget             *widget,
-                                                               gint                   size);
+GdkPaintable *gtk_source_pixbuf_helper_render (GtkSourcePixbufHelper *helper,
+                                               GtkWidget             *widget,
+                                               gint                   size);
 
-G_END_DECLS
+#endif /* GTK_SOURCE_PIXBUF_HELPER_PRIVATE_H */
diff --git a/gtksourceview/gtksourcepixbufhelper.c b/gtksourceview/gtksourcepixbufhelper.c
index 6af12974..cddf8173 100644
--- a/gtksourceview/gtksourcepixbufhelper.c
+++ b/gtksourceview/gtksourcepixbufhelper.c
@@ -2,7 +2,7 @@
  *
  * This file is part of GtkSourceView
  *
- * Copyright 2010 - Jesse van den Kieboom
+ * Copyright (C) 2010 - Jesse van den Kieboom
  *
  * GtkSourceView is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -18,7 +18,9 @@
  * along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "config.h"
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
 
 #include "gtksourcepixbufhelper-private.h"
 
@@ -31,7 +33,7 @@ typedef enum _IconType
 
 struct _GtkSourcePixbufHelper
 {
-       GdkPixbuf *cached_pixbuf;
+       GdkPaintable *cached_paintable;
        IconType type;
 
        GdkPixbuf *pixbuf;
@@ -48,40 +50,20 @@ gtk_source_pixbuf_helper_new (void)
 void
 gtk_source_pixbuf_helper_free (GtkSourcePixbufHelper *helper)
 {
-       if (helper->pixbuf)
-       {
-               g_object_unref (helper->pixbuf);
-       }
-
-       if (helper->cached_pixbuf)
-       {
-               g_object_unref (helper->cached_pixbuf);
-       }
-
-       if (helper->gicon)
-       {
-               g_object_unref (helper->gicon);
-       }
-
-       g_free (helper->icon_name);
+       g_clear_object (&helper->pixbuf);
+       g_clear_object (&helper->cached_paintable);
+       g_clear_object (&helper->gicon);
+       g_clear_pointer (&helper->icon_name, g_free);
 
        g_slice_free (GtkSourcePixbufHelper, helper);
 }
 
 static void
 set_cache (GtkSourcePixbufHelper *helper,
-           GdkPixbuf             *pixbuf)
+          GdkPaintable          *paintable)
 {
-       if (helper->cached_pixbuf)
-       {
-               g_object_unref (helper->cached_pixbuf);
-               helper->cached_pixbuf = NULL;
-       }
-
-       if (pixbuf)
-       {
-               helper->cached_pixbuf = pixbuf;
-       }
+       g_clear_object (&helper->cached_paintable);
+       helper->cached_paintable = paintable;
 }
 
 static void
@@ -169,26 +151,10 @@ from_pixbuf (GtkSourcePixbufHelper *helper,
              GtkWidget             *widget,
              gint                   size)
 {
-       if (helper->pixbuf == NULL)
+       if (helper->pixbuf != NULL)
        {
-               return;
-       }
-
-       if (gdk_pixbuf_get_width (helper->pixbuf) <= size)
-       {
-               if (!helper->cached_pixbuf)
-               {
-                       set_cache (helper, gdk_pixbuf_copy (helper->pixbuf));
-               }
-
-               return;
+               set_cache (helper, GDK_PAINTABLE (gdk_texture_new_for_pixbuf (helper->pixbuf)));
        }
-
-       /* Make smaller */
-       set_cache (helper, gdk_pixbuf_scale_simple (helper->pixbuf,
-                                                   size,
-                                                   size,
-                                                   GDK_INTERP_BILINEAR));
 }
 
 static void
@@ -196,13 +162,18 @@ from_gicon (GtkSourcePixbufHelper *helper,
             GtkWidget             *widget,
             gint                   size)
 {
-       GdkScreen *screen;
+       GdkDisplay *display;
        GtkIconTheme *icon_theme;
        GtkIconInfo *info;
        GtkIconLookupFlags flags;
 
-       screen = gtk_widget_get_screen (widget);
-       icon_theme = gtk_icon_theme_get_for_screen (screen);
+       if (helper->gicon == NULL)
+       {
+               return;
+       }
+
+       display = gtk_widget_get_display (widget);
+       icon_theme = gtk_icon_theme_get_for_display (display);
 
        flags = GTK_ICON_LOOKUP_USE_BUILTIN;
 
@@ -213,6 +184,7 @@ from_gicon (GtkSourcePixbufHelper *helper,
 
        if (info)
        {
+
                set_cache (helper, gtk_icon_info_load_icon (info, NULL));
        }
 }
@@ -222,14 +194,19 @@ from_name (GtkSourcePixbufHelper *helper,
            GtkWidget             *widget,
            gint                   size)
 {
-       GdkScreen *screen;
+       GdkDisplay *display;
        GtkIconTheme *icon_theme;
        GtkIconInfo *info;
        GtkIconLookupFlags flags;
        gint scale;
 
-       screen = gtk_widget_get_screen (widget);
-       icon_theme = gtk_icon_theme_get_for_screen (screen);
+       if (helper->icon_name == NULL)
+       {
+               return;
+       }
+
+       display = gtk_widget_get_display (widget);
+       icon_theme = gtk_icon_theme_get_for_display (display);
 
        flags = GTK_ICON_LOOKUP_USE_BUILTIN;
         scale = gtk_widget_get_scale_factor (widget);
@@ -242,33 +219,32 @@ from_name (GtkSourcePixbufHelper *helper,
 
        if (info)
        {
-               GdkPixbuf *pixbuf;
+               GdkPaintable *paintable;
 
                if (gtk_icon_info_is_symbolic (info))
                {
                        GtkStyleContext *context;
 
                        context = gtk_widget_get_style_context (widget);
-                       pixbuf = gtk_icon_info_load_symbolic_for_context (info, context, NULL, NULL);
+                       paintable = gtk_icon_info_load_symbolic_for_context (info, context, NULL, NULL);
                }
                else
                {
-                       pixbuf = gtk_icon_info_load_icon (info, NULL);
+                       paintable = gtk_icon_info_load_icon (info, NULL);
                }
 
-               set_cache (helper, pixbuf);
+               set_cache (helper, paintable);
        }
 }
 
-GdkPixbuf *
+GdkPaintable *
 gtk_source_pixbuf_helper_render (GtkSourcePixbufHelper *helper,
                                  GtkWidget             *widget,
                                  gint                   size)
 {
-       if (helper->cached_pixbuf &&
-           gdk_pixbuf_get_width (helper->cached_pixbuf) == size)
+       if (helper->cached_paintable != NULL)
        {
-               return helper->cached_pixbuf;
+               return helper->cached_paintable;
        }
 
        switch (helper->type)
@@ -286,6 +262,6 @@ gtk_source_pixbuf_helper_render (GtkSourcePixbufHelper *helper,
                        g_assert_not_reached ();
        }
 
-       return helper->cached_pixbuf;
+       return helper->cached_paintable;
 }
 
diff --git a/gtksourceview/gtksourceprintcompositor.c b/gtksourceview/gtksourceprintcompositor.c
index 0bc23b27..a34b30ea 100644
--- a/gtksourceview/gtksourceprintcompositor.c
+++ b/gtksourceview/gtksourceprintcompositor.c
@@ -2,11 +2,11 @@
  *
  * This file is part of GtkSourceView
  *
- * Copyright 2000, 2001 Chema Celorio
- * Copyright 2003  Gustavo Giráldez
- * Copyright 2004  Red Hat, Inc.
- * Copyright 2001-2007  Paolo Maggi
- * Copyright 2008  Paolo Maggi, Paolo Borelli and Yevgen Muntyan
+ * Copyright (C) 2000, 2001 Chema Celorio
+ * Copyright (C) 2003  Gustavo Giráldez
+ * Copyright (C) 2004  Red Hat, Inc.
+ * Copyright (C) 2001-2007  Paolo Maggi
+ * Copyright (C) 2008  Paolo Maggi, Paolo Borelli and Yevgen Muntyan
  *
  * GtkSourceView is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -22,7 +22,9 @@
  * along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "config.h"
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
 
 #include <string.h>
 #include <time.h>
@@ -102,7 +104,7 @@ typedef enum _PaginatorState
        DONE
 } PaginatorState;
 
-typedef struct
+struct _GtkSourcePrintCompositorPrivate
 {
        GtkSourceBuffer         *buffer;
 
@@ -174,7 +176,7 @@ typedef struct
        PangoLanguage           *language; /* must not be freed */
 
        GtkTextMark             *pagination_mark;
-} GtkSourcePrintCompositorPrivate;
+};
 
 enum
 {
@@ -199,8 +201,7 @@ G_DEFINE_TYPE_WITH_PRIVATE (GtkSourcePrintCompositor, gtk_source_print_composito
 #define POINTS_PER_INCH 72
 
 static gdouble
-convert_to_mm (gdouble len,
-               GtkUnit unit)
+convert_to_mm (gdouble len, GtkUnit unit)
 {
        switch (unit)
        {
@@ -221,8 +222,7 @@ convert_to_mm (gdouble len,
 }
 
 static gdouble
-convert_from_mm (gdouble len,
-                 GtkUnit unit)
+convert_from_mm (gdouble len, GtkUnit unit)
 {
        switch (unit)
        {
@@ -244,17 +244,16 @@ convert_from_mm (gdouble len,
 
 static void
 gtk_source_print_compositor_get_property (GObject    *object,
-                                          guint       prop_id,
-                                          GValue     *value,
-                                          GParamSpec *pspec)
+                                         guint       prop_id,
+                                         GValue     *value,
+                                         GParamSpec *pspec)
 {
        GtkSourcePrintCompositor *compositor = GTK_SOURCE_PRINT_COMPOSITOR (object);
-       GtkSourcePrintCompositorPrivate *priv = gtk_source_print_compositor_get_instance_private (compositor);
 
        switch (prop_id)
        {
                case PROP_BUFFER:
-                       g_value_set_object (value, priv->buffer);
+                       g_value_set_object (value, compositor->priv->buffer);
                        break;
                case PROP_TAB_WIDTH:
                        g_value_set_uint (value,
@@ -308,17 +307,16 @@ gtk_source_print_compositor_get_property (GObject    *object,
 
 static void
 gtk_source_print_compositor_set_property (GObject      *object,
-                                          guint         prop_id,
-                                          const GValue *value,
-                                          GParamSpec   *pspec)
+                                         guint         prop_id,
+                                         const GValue *value,
+                                         GParamSpec   *pspec)
 {
        GtkSourcePrintCompositor *compositor = GTK_SOURCE_PRINT_COMPOSITOR (object);
-       GtkSourcePrintCompositorPrivate *priv = gtk_source_print_compositor_get_instance_private (compositor);
 
        switch (prop_id)
        {
                case PROP_BUFFER:
-                       priv->buffer = GTK_SOURCE_BUFFER (g_value_dup_object (value));
+                       compositor->priv->buffer = GTK_SOURCE_BUFFER (g_value_dup_object (value));
                        break;
                case PROP_TAB_WIDTH:
                        gtk_source_print_compositor_set_tab_width (compositor,
@@ -368,41 +366,42 @@ gtk_source_print_compositor_set_property (GObject      *object,
 static void
 gtk_source_print_compositor_finalize (GObject *object)
 {
-       GtkSourcePrintCompositor *compositor = GTK_SOURCE_PRINT_COMPOSITOR (object);
-       GtkSourcePrintCompositorPrivate *priv = gtk_source_print_compositor_get_instance_private (compositor);
+       GtkSourcePrintCompositor *compositor;
 
-       if (priv->pages != NULL)
-               g_array_free (priv->pages, TRUE);
+       compositor = GTK_SOURCE_PRINT_COMPOSITOR (object);
 
-       if (priv->layout != NULL)
-               g_object_unref (priv->layout);
+       if (compositor->priv->pages != NULL)
+               g_array_free (compositor->priv->pages, TRUE);
 
-       if (priv->line_numbers_layout != NULL)
-               g_object_unref (priv->line_numbers_layout);
+       if (compositor->priv->layout != NULL)
+               g_object_unref (compositor->priv->layout);
 
-       if (priv->header_layout != NULL)
-               g_object_unref (priv->header_layout);
+       if (compositor->priv->line_numbers_layout != NULL)
+               g_object_unref (compositor->priv->line_numbers_layout);
 
-       if (priv->footer_layout != NULL)
-               g_object_unref (priv->footer_layout);
+       if (compositor->priv->header_layout != NULL)
+               g_object_unref (compositor->priv->header_layout);
 
-       pango_font_description_free (priv->body_font);
+       if (compositor->priv->footer_layout != NULL)
+               g_object_unref (compositor->priv->footer_layout);
 
-       if (priv->line_numbers_font != NULL)
-               pango_font_description_free (priv->line_numbers_font);
+       pango_font_description_free (compositor->priv->body_font);
 
-       if (priv->header_font != NULL)
-               pango_font_description_free (priv->header_font);
+       if (compositor->priv->line_numbers_font != NULL)
+               pango_font_description_free (compositor->priv->line_numbers_font);
 
-       if (priv->footer_font != NULL)
-               pango_font_description_free (priv->footer_font);
+       if (compositor->priv->header_font != NULL)
+               pango_font_description_free (compositor->priv->header_font);
 
-       g_free (priv->header_format_left);
-       g_free (priv->header_format_right);
-       g_free (priv->header_format_center);
-       g_free (priv->footer_format_left);
-       g_free (priv->footer_format_right);
-       g_free (priv->footer_format_center);
+       if (compositor->priv->footer_font != NULL)
+               pango_font_description_free (compositor->priv->footer_font);
+
+       g_free (compositor->priv->header_format_left);
+       g_free (compositor->priv->header_format_right);
+       g_free (compositor->priv->header_format_center);
+       g_free (compositor->priv->footer_format_left);
+       g_free (compositor->priv->footer_format_right);
+       g_free (compositor->priv->footer_format_center);
 
        G_OBJECT_CLASS (gtk_source_print_compositor_parent_class)->finalize (object);
 }
@@ -410,10 +409,11 @@ gtk_source_print_compositor_finalize (GObject *object)
 static void
 gtk_source_print_compositor_dispose (GObject *object)
 {
-       GtkSourcePrintCompositor *compositor = GTK_SOURCE_PRINT_COMPOSITOR (object);
-       GtkSourcePrintCompositorPrivate *priv = gtk_source_print_compositor_get_instance_private (compositor);
+       GtkSourcePrintCompositor *compositor;
 
-       g_clear_object (&priv->buffer);
+       compositor = GTK_SOURCE_PRINT_COMPOSITOR (object);
+
+       g_clear_object (&compositor->priv->buffer);
 
        G_OBJECT_CLASS (gtk_source_print_compositor_parent_class)->dispose (object);
 }
@@ -691,7 +691,11 @@ gtk_source_print_compositor_class_init (GtkSourcePrintCompositorClass *klass)
 static void
 gtk_source_print_compositor_init (GtkSourcePrintCompositor *compositor)
 {
-       GtkSourcePrintCompositorPrivate *priv = gtk_source_print_compositor_get_instance_private (compositor);
+       GtkSourcePrintCompositorPrivate *priv;
+
+       priv = gtk_source_print_compositor_get_instance_private (compositor);
+
+       compositor->priv = priv;
 
        priv->buffer = NULL;
 
@@ -789,7 +793,6 @@ gtk_source_print_compositor_new_from_view (GtkSourceView *view)
        PangoContext *pango_context;
        PangoFontDescription* font_desc;
        GtkSourcePrintCompositor *compositor;
-       GtkSourcePrintCompositorPrivate *priv;
 
        g_return_val_if_fail (GTK_SOURCE_IS_VIEW (view), NULL);
        g_return_val_if_fail (GTK_SOURCE_IS_BUFFER (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view))), NULL);
@@ -802,16 +805,14 @@ gtk_source_print_compositor_new_from_view (GtkSourceView *view)
                                     "tab-width", gtk_source_view_get_tab_width (view),
                                     "highlight-syntax", gtk_source_buffer_get_highlight_syntax (buffer) != 
FALSE,
                                     "wrap-mode", gtk_text_view_get_wrap_mode (GTK_TEXT_VIEW (view)),
-                                    "print-line-numbers", (gtk_source_view_get_show_line_numbers (view) == 
FALSE) ? 0 : 1,
                                     NULL));
-       priv = gtk_source_print_compositor_get_instance_private (compositor);
 
        /* Set the body font directly since the property get a name while body_font is a PangoFontDescription 
*/
        pango_context = gtk_widget_get_pango_context (GTK_WIDGET (view));
 
        font_desc = pango_context_get_font_description (pango_context);
 
-       priv->body_font = pango_font_description_copy (font_desc);
+       compositor->priv->body_font = pango_font_description_copy (font_desc);
        g_object_notify (G_OBJECT (compositor), "body-font-name"); /* FIXME: is this needed? */
 
        return compositor;
@@ -832,11 +833,9 @@ gtk_source_print_compositor_new_from_view (GtkSourceView *view)
 GtkSourceBuffer *
 gtk_source_print_compositor_get_buffer (GtkSourcePrintCompositor *compositor)
 {
-       GtkSourcePrintCompositorPrivate *priv = gtk_source_print_compositor_get_instance_private (compositor);
-
        g_return_val_if_fail (GTK_SOURCE_IS_PRINT_COMPOSITOR (compositor), NULL);
 
-       return priv->buffer;
+       return compositor->priv->buffer;
 }
 
 /**
@@ -853,18 +852,16 @@ gtk_source_print_compositor_get_buffer (GtkSourcePrintCompositor *compositor)
  */
 void
 gtk_source_print_compositor_set_tab_width (GtkSourcePrintCompositor *compositor,
-                                           guint                     width)
+                                          guint                     width)
 {
-       GtkSourcePrintCompositorPrivate *priv = gtk_source_print_compositor_get_instance_private (compositor);
-
        g_return_if_fail (GTK_SOURCE_IS_PRINT_COMPOSITOR (compositor));
        g_return_if_fail (width > 0 && width <= MAX_TAB_WIDTH);
-       g_return_if_fail (priv->state == INIT);
+       g_return_if_fail (compositor->priv->state == INIT);
 
-       if (width == priv->tab_width)
+       if (width == compositor->priv->tab_width)
                return;
 
-       priv->tab_width = width;
+       compositor->priv->tab_width = width;
 
        g_object_notify (G_OBJECT (compositor), "tab-width");
 }
@@ -882,11 +879,9 @@ gtk_source_print_compositor_set_tab_width (GtkSourcePrintCompositor *compositor,
 guint
 gtk_source_print_compositor_get_tab_width (GtkSourcePrintCompositor *compositor)
 {
-       GtkSourcePrintCompositorPrivate *priv = gtk_source_print_compositor_get_instance_private (compositor);
-
        g_return_val_if_fail (GTK_SOURCE_IS_PRINT_COMPOSITOR (compositor), DEFAULT_TAB_WIDTH);
 
-       return priv->tab_width;
+       return compositor->priv->tab_width;
 }
 
 /**
@@ -903,17 +898,15 @@ gtk_source_print_compositor_get_tab_width (GtkSourcePrintCompositor *compositor)
  */
 void
 gtk_source_print_compositor_set_wrap_mode (GtkSourcePrintCompositor *compositor,
-                                           GtkWrapMode               wrap_mode)
+                                          GtkWrapMode               wrap_mode)
 {
-       GtkSourcePrintCompositorPrivate *priv = gtk_source_print_compositor_get_instance_private (compositor);
-
        g_return_if_fail (GTK_SOURCE_IS_PRINT_COMPOSITOR (compositor));
-       g_return_if_fail (priv->state == INIT);
+       g_return_if_fail (compositor->priv->state == INIT);
 
-       if (wrap_mode == priv->wrap_mode)
+       if (wrap_mode == compositor->priv->wrap_mode)
                return;
 
-       priv->wrap_mode = wrap_mode;
+       compositor->priv->wrap_mode = wrap_mode;
 
        g_object_notify (G_OBJECT (compositor), "wrap-mode");
 }
@@ -931,11 +924,9 @@ gtk_source_print_compositor_set_wrap_mode (GtkSourcePrintCompositor *compositor,
 GtkWrapMode
 gtk_source_print_compositor_get_wrap_mode (GtkSourcePrintCompositor *compositor)
 {
-       GtkSourcePrintCompositorPrivate *priv = gtk_source_print_compositor_get_instance_private (compositor);
-
        g_return_val_if_fail (GTK_SOURCE_IS_PRINT_COMPOSITOR (compositor), GTK_WRAP_NONE);
 
-       return priv->wrap_mode;
+       return compositor->priv->wrap_mode;
 }
 
 /**
@@ -953,19 +944,17 @@ gtk_source_print_compositor_get_wrap_mode (GtkSourcePrintCompositor *compositor)
  **/
 void
 gtk_source_print_compositor_set_highlight_syntax (GtkSourcePrintCompositor *compositor,
-                                                  gboolean                  highlight)
+                                                 gboolean                  highlight)
 {
-       GtkSourcePrintCompositorPrivate *priv = gtk_source_print_compositor_get_instance_private (compositor);
-
        g_return_if_fail (GTK_SOURCE_IS_PRINT_COMPOSITOR (compositor));
-       g_return_if_fail (priv->state == INIT);
+       g_return_if_fail (compositor->priv->state == INIT);
 
        highlight = (highlight != FALSE);
 
-       if (highlight == priv->highlight_syntax)
+       if (highlight == compositor->priv->highlight_syntax)
                return;
 
-       priv->highlight_syntax = highlight;
+       compositor->priv->highlight_syntax = highlight;
 
        g_object_notify (G_OBJECT (compositor), "highlight-syntax");
 }
@@ -985,11 +974,9 @@ gtk_source_print_compositor_set_highlight_syntax (GtkSourcePrintCompositor *comp
 gboolean
 gtk_source_print_compositor_get_highlight_syntax (GtkSourcePrintCompositor *compositor)
 {
-       GtkSourcePrintCompositorPrivate *priv = gtk_source_print_compositor_get_instance_private (compositor);
-
        g_return_val_if_fail (GTK_SOURCE_IS_PRINT_COMPOSITOR (compositor), FALSE);
 
-       return priv->highlight_syntax;
+       return compositor->priv->highlight_syntax;
 }
 
 /**
@@ -1010,18 +997,16 @@ gtk_source_print_compositor_get_highlight_syntax (GtkSourcePrintCompositor *comp
  **/
 void
 gtk_source_print_compositor_set_print_line_numbers (GtkSourcePrintCompositor *compositor,
-                                                    guint                     interval)
+                                                   guint                     interval)
 {
-       GtkSourcePrintCompositorPrivate *priv = gtk_source_print_compositor_get_instance_private (compositor);
-
        g_return_if_fail (GTK_SOURCE_IS_PRINT_COMPOSITOR (compositor));
-       g_return_if_fail (priv->state == INIT);
+       g_return_if_fail (compositor->priv->state == INIT);
        g_return_if_fail (interval <= 100);
 
-       if (interval == priv->print_line_numbers)
+       if (interval == compositor->priv->print_line_numbers)
                return;
 
-       priv->print_line_numbers = interval;
+       compositor->priv->print_line_numbers = interval;
 
        g_object_notify (G_OBJECT (compositor), "print-line-numbers");
 }
@@ -1046,19 +1031,17 @@ gtk_source_print_compositor_set_print_line_numbers (GtkSourcePrintCompositor *co
  **/
 void
 gtk_source_print_compositor_set_print_header (GtkSourcePrintCompositor *compositor,
-                                              gboolean                  print)
+                                             gboolean                  print)
 {
-       GtkSourcePrintCompositorPrivate *priv = gtk_source_print_compositor_get_instance_private (compositor);
-
        g_return_if_fail (GTK_SOURCE_IS_PRINT_COMPOSITOR (compositor));
-       g_return_if_fail (priv->state == INIT);
+       g_return_if_fail (compositor->priv->state == INIT);
 
        print = (print != FALSE);
 
-       if (print == priv->print_header)
+       if (print == compositor->priv->print_header)
                return;
 
-       priv->print_header = print;
+       compositor->priv->print_header = print;
 
        g_object_notify (G_OBJECT (compositor), "print-header");
 }
@@ -1079,11 +1062,9 @@ gtk_source_print_compositor_set_print_header (GtkSourcePrintCompositor *composit
 gboolean
 gtk_source_print_compositor_get_print_header (GtkSourcePrintCompositor *compositor)
 {
-       GtkSourcePrintCompositorPrivate *priv = gtk_source_print_compositor_get_instance_private (compositor);
-
        g_return_val_if_fail (GTK_SOURCE_IS_PRINT_COMPOSITOR (compositor), FALSE);
 
-       return priv->print_header;
+       return compositor->priv->print_header;
 }
 
 /**
@@ -1106,19 +1087,17 @@ gtk_source_print_compositor_get_print_header (GtkSourcePrintCompositor *composit
  **/
 void
 gtk_source_print_compositor_set_print_footer (GtkSourcePrintCompositor *compositor,
-                                              gboolean                  print)
+                                             gboolean                  print)
 {
-       GtkSourcePrintCompositorPrivate *priv = gtk_source_print_compositor_get_instance_private (compositor);
-
        g_return_if_fail (GTK_SOURCE_IS_PRINT_COMPOSITOR (compositor));
-       g_return_if_fail (priv->state == INIT);
+       g_return_if_fail (compositor->priv->state == INIT);
 
        print = (print != FALSE);
 
-       if (print == priv->print_footer)
+       if (print == compositor->priv->print_footer)
                return;
 
-       priv->print_footer = print;
+       compositor->priv->print_footer = print;
 
        g_object_notify (G_OBJECT (compositor), "print-footer");
 }
@@ -1139,11 +1118,9 @@ gtk_source_print_compositor_set_print_footer (GtkSourcePrintCompositor *composit
 gboolean
 gtk_source_print_compositor_get_print_footer (GtkSourcePrintCompositor *compositor)
 {
-       GtkSourcePrintCompositorPrivate *priv = gtk_source_print_compositor_get_instance_private (compositor);
-
        g_return_val_if_fail (GTK_SOURCE_IS_PRINT_COMPOSITOR (compositor), FALSE);
 
-       return priv->print_footer;
+       return compositor->priv->print_footer;
 }
 
 /**
@@ -1180,26 +1157,24 @@ gtk_source_print_compositor_get_print_footer (GtkSourcePrintCompositor *composit
  **/
 void
 gtk_source_print_compositor_set_header_format (GtkSourcePrintCompositor *compositor,
-                                               gboolean                  separator,
-                                               const gchar              *left,
-                                               const gchar              *center,
-                                               const gchar              *right)
+                                              gboolean                  separator,
+                                              const gchar              *left,
+                                              const gchar              *center,
+                                              const gchar              *right)
 {
-       GtkSourcePrintCompositorPrivate *priv = gtk_source_print_compositor_get_instance_private (compositor);
-
        g_return_if_fail (GTK_SOURCE_IS_PRINT_COMPOSITOR (compositor));
-       g_return_if_fail (priv->state == INIT);
+       g_return_if_fail (compositor->priv->state == INIT);
 
        /* FIXME: validate given strings? */
-       g_free (priv->header_format_left);
-       g_free (priv->header_format_center);
-       g_free (priv->header_format_right);
+       g_free (compositor->priv->header_format_left);
+       g_free (compositor->priv->header_format_center);
+       g_free (compositor->priv->header_format_right);
 
-       priv->header_separator = separator;
+       compositor->priv->header_separator = separator;
 
-       priv->header_format_left = g_strdup (left);
-       priv->header_format_center = g_strdup (center);
-       priv->header_format_right = g_strdup (right);
+       compositor->priv->header_format_left = g_strdup (left);
+       compositor->priv->header_format_center = g_strdup (center);
+       compositor->priv->header_format_right = g_strdup (right);
 }
 
 /**
@@ -1217,26 +1192,24 @@ gtk_source_print_compositor_set_header_format (GtkSourcePrintCompositor *composi
  **/
 void
 gtk_source_print_compositor_set_footer_format (GtkSourcePrintCompositor *compositor,
-                                               gboolean                  separator,
-                                               const gchar              *left,
-                                               const gchar              *center,
-                                               const gchar              *right)
+                                              gboolean                  separator,
+                                              const gchar              *left,
+                                              const gchar              *center,
+                                              const gchar              *right)
 {
-       GtkSourcePrintCompositorPrivate *priv = gtk_source_print_compositor_get_instance_private (compositor);
-
        g_return_if_fail (GTK_SOURCE_IS_PRINT_COMPOSITOR (compositor));
-       g_return_if_fail (priv->state == INIT);
+       g_return_if_fail (compositor->priv->state == INIT);
 
        /* FIXME: validate given strings? */
-       g_free (priv->footer_format_left);
-       g_free (priv->footer_format_center);
-       g_free (priv->footer_format_right);
+       g_free (compositor->priv->footer_format_left);
+       g_free (compositor->priv->footer_format_center);
+       g_free (compositor->priv->footer_format_right);
 
-       priv->footer_separator = separator;
+       compositor->priv->footer_separator = separator;
 
-       priv->footer_format_left = g_strdup (left);
-       priv->footer_format_center = g_strdup (center);
-       priv->footer_format_right = g_strdup (right);
+       compositor->priv->footer_format_left = g_strdup (left);
+       compositor->priv->footer_format_center = g_strdup (center);
+       compositor->priv->footer_format_right = g_strdup (right);
 }
 
 /**
@@ -1254,27 +1227,24 @@ gtk_source_print_compositor_set_footer_format (GtkSourcePrintCompositor *composi
 guint
 gtk_source_print_compositor_get_print_line_numbers (GtkSourcePrintCompositor *compositor)
 {
-       GtkSourcePrintCompositorPrivate *priv = gtk_source_print_compositor_get_instance_private (compositor);
-
        g_return_val_if_fail (GTK_SOURCE_IS_PRINT_COMPOSITOR (compositor), 0);
 
-       return priv->print_line_numbers;
+       return compositor->priv->print_line_numbers;
 }
 
 static gboolean
 set_font_description_from_name (GtkSourcePrintCompositor  *compositor,
-                                PangoFontDescription     **font,
-                                const gchar               *font_name)
+                               PangoFontDescription     **font,
+                               const gchar               *font_name)
 {
-       GtkSourcePrintCompositorPrivate *priv = gtk_source_print_compositor_get_instance_private (compositor);
        PangoFontDescription *new;
 
        if (font_name != NULL)
                new = pango_font_description_from_string (font_name);
        else
        {
-               g_return_val_if_fail (priv->body_font != NULL, FALSE);
-               new = pango_font_description_copy (priv->body_font);
+               g_return_val_if_fail (compositor->priv->body_font != NULL, FALSE);
+               new = pango_font_description_copy (compositor->priv->body_font);
        }
 
        if (*font == NULL || !pango_font_description_equal (*font, new))
@@ -1312,16 +1282,14 @@ set_font_description_from_name (GtkSourcePrintCompositor  *compositor,
  */
 void
 gtk_source_print_compositor_set_body_font_name (GtkSourcePrintCompositor *compositor,
-                                                const gchar              *font_name)
+                                               const gchar              *font_name)
 {
-       GtkSourcePrintCompositorPrivate *priv = gtk_source_print_compositor_get_instance_private (compositor);
-
        g_return_if_fail (GTK_SOURCE_IS_PRINT_COMPOSITOR (compositor));
        g_return_if_fail (font_name != NULL);
-       g_return_if_fail (priv->state == INIT);
+       g_return_if_fail (compositor->priv->state == INIT);
 
        if (set_font_description_from_name (compositor,
-                                           &priv->body_font,
+                                           &compositor->priv->body_font,
                                            font_name))
        {
                g_object_notify (G_OBJECT (compositor), "body-font-name");
@@ -1343,11 +1311,9 @@ gtk_source_print_compositor_set_body_font_name (GtkSourcePrintCompositor *compos
 gchar *
 gtk_source_print_compositor_get_body_font_name (GtkSourcePrintCompositor *compositor)
 {
-       GtkSourcePrintCompositorPrivate *priv = gtk_source_print_compositor_get_instance_private (compositor);
-
        g_return_val_if_fail (GTK_SOURCE_IS_PRINT_COMPOSITOR (compositor), NULL);
 
-       return pango_font_description_to_string (priv->body_font);
+       return pango_font_description_to_string (compositor->priv->body_font);
 }
 
 /**
@@ -1371,16 +1337,14 @@ gtk_source_print_compositor_get_body_font_name (GtkSourcePrintCompositor *compos
  */
 void
 gtk_source_print_compositor_set_line_numbers_font_name (GtkSourcePrintCompositor *compositor,
-                                                        const gchar              *font_name)
+                                                       const gchar              *font_name)
 {
-       GtkSourcePrintCompositorPrivate *priv = gtk_source_print_compositor_get_instance_private (compositor);
-
        g_return_if_fail (GTK_SOURCE_IS_PRINT_COMPOSITOR (compositor));
        g_return_if_fail (font_name != NULL);
-       g_return_if_fail (priv->state == INIT);
+       g_return_if_fail (compositor->priv->state == INIT);
 
        if (set_font_description_from_name (compositor,
-                                           &priv->line_numbers_font,
+                                           &compositor->priv->line_numbers_font,
                                            font_name))
        {
                g_object_notify (G_OBJECT (compositor), "line-numbers-font-name");
@@ -1402,17 +1366,15 @@ gtk_source_print_compositor_set_line_numbers_font_name (GtkSourcePrintCompositor
 gchar *
 gtk_source_print_compositor_get_line_numbers_font_name (GtkSourcePrintCompositor *compositor)
 {
-       GtkSourcePrintCompositorPrivate *priv = gtk_source_print_compositor_get_instance_private (compositor);
-
        g_return_val_if_fail (GTK_SOURCE_IS_PRINT_COMPOSITOR (compositor), NULL);
 
-       if (priv->line_numbers_font == NULL)
+       if (compositor->priv->line_numbers_font == NULL)
        {
-               g_return_val_if_fail (priv->body_font != NULL, NULL);
-               priv->line_numbers_font = pango_font_description_copy (priv->body_font);
+               g_return_val_if_fail (compositor->priv->body_font != NULL, NULL);
+               compositor->priv->line_numbers_font = pango_font_description_copy 
(compositor->priv->body_font);
        }
 
-       return pango_font_description_to_string (priv->line_numbers_font);
+       return pango_font_description_to_string (compositor->priv->line_numbers_font);
 }
 
 /**
@@ -1436,16 +1398,14 @@ gtk_source_print_compositor_get_line_numbers_font_name (GtkSourcePrintCompositor
  */
 void
 gtk_source_print_compositor_set_header_font_name (GtkSourcePrintCompositor *compositor,
-                                                  const gchar              *font_name)
+                                                       const gchar              *font_name)
 {
-       GtkSourcePrintCompositorPrivate *priv = gtk_source_print_compositor_get_instance_private (compositor);
-
        g_return_if_fail (GTK_SOURCE_IS_PRINT_COMPOSITOR (compositor));
        g_return_if_fail (font_name != NULL);
-       g_return_if_fail (priv->state == INIT);
+       g_return_if_fail (compositor->priv->state == INIT);
 
        if (set_font_description_from_name (compositor,
-                                           &priv->header_font,
+                                           &compositor->priv->header_font,
                                            font_name))
 
        {
@@ -1468,17 +1428,15 @@ gtk_source_print_compositor_set_header_font_name (GtkSourcePrintCompositor *comp
 gchar *
 gtk_source_print_compositor_get_header_font_name (GtkSourcePrintCompositor *compositor)
 {
-       GtkSourcePrintCompositorPrivate *priv = gtk_source_print_compositor_get_instance_private (compositor);
-
        g_return_val_if_fail (GTK_SOURCE_IS_PRINT_COMPOSITOR (compositor), NULL);
 
-       if (priv->header_font == NULL)
+       if (compositor->priv->header_font == NULL)
        {
-               g_return_val_if_fail (priv->body_font != NULL, NULL);
-               priv->header_font = pango_font_description_copy (priv->body_font);
+               g_return_val_if_fail (compositor->priv->body_font != NULL, NULL);
+               compositor->priv->header_font = pango_font_description_copy (compositor->priv->body_font);
        }
 
-       return pango_font_description_to_string (priv->header_font);
+       return pango_font_description_to_string (compositor->priv->header_font);
 }
 
 /**
@@ -1502,16 +1460,14 @@ gtk_source_print_compositor_get_header_font_name (GtkSourcePrintCompositor *comp
  */
 void
 gtk_source_print_compositor_set_footer_font_name (GtkSourcePrintCompositor *compositor,
-                                                  const gchar              *font_name)
+                                                 const gchar              *font_name)
 {
-       GtkSourcePrintCompositorPrivate *priv = gtk_source_print_compositor_get_instance_private (compositor);
-
        g_return_if_fail (GTK_SOURCE_IS_PRINT_COMPOSITOR (compositor));
        g_return_if_fail (font_name != NULL);
-       g_return_if_fail (priv->state == INIT);
+       g_return_if_fail (compositor->priv->state == INIT);
 
        if (set_font_description_from_name (compositor,
-                                           &priv->footer_font,
+                                           &compositor->priv->footer_font,
                                            font_name))
 
        {
@@ -1534,17 +1490,15 @@ gtk_source_print_compositor_set_footer_font_name (GtkSourcePrintCompositor *comp
 gchar *
 gtk_source_print_compositor_get_footer_font_name (GtkSourcePrintCompositor *compositor)
 {
-       GtkSourcePrintCompositorPrivate *priv = gtk_source_print_compositor_get_instance_private (compositor);
-
        g_return_val_if_fail (GTK_SOURCE_IS_PRINT_COMPOSITOR (compositor), NULL);
 
-       if (priv->footer_font == NULL)
+       if (compositor->priv->footer_font == NULL)
        {
-               g_return_val_if_fail (priv->body_font != NULL, NULL);
-               priv->footer_font = pango_font_description_copy (priv->body_font);
+               g_return_val_if_fail (compositor->priv->body_font != NULL, NULL);
+               compositor->priv->footer_font = pango_font_description_copy (compositor->priv->body_font);
        }
 
-       return pango_font_description_to_string (priv->footer_font);
+       return pango_font_description_to_string (compositor->priv->footer_font);
 }
 
 /**
@@ -1559,14 +1513,12 @@ gtk_source_print_compositor_get_footer_font_name (GtkSourcePrintCompositor *comp
  */
 void
 gtk_source_print_compositor_set_top_margin (GtkSourcePrintCompositor *compositor,
-                                            gdouble                   margin,
-                                            GtkUnit                   unit)
+                                           gdouble                   margin,
+                                           GtkUnit                   unit)
 {
-       GtkSourcePrintCompositorPrivate *priv = gtk_source_print_compositor_get_instance_private (compositor);
-
        g_return_if_fail (GTK_SOURCE_IS_PRINT_COMPOSITOR (compositor));
 
-       priv->margin_top = convert_to_mm (margin, unit);
+       compositor->priv->margin_top = convert_to_mm (margin, unit);
 }
 
 /**
@@ -1582,13 +1534,11 @@ gtk_source_print_compositor_set_top_margin (GtkSourcePrintCompositor *compositor
  */
 gdouble
 gtk_source_print_compositor_get_top_margin (GtkSourcePrintCompositor *compositor,
-                                            GtkUnit                   unit)
+                                           GtkUnit                   unit)
 {
-       GtkSourcePrintCompositorPrivate *priv = gtk_source_print_compositor_get_instance_private (compositor);
-
        g_return_val_if_fail (GTK_SOURCE_IS_PRINT_COMPOSITOR (compositor), 0);
 
-       return convert_from_mm (priv->margin_top, unit);
+       return convert_from_mm (compositor->priv->margin_top, unit);
 }
 
 /**
@@ -1603,14 +1553,12 @@ gtk_source_print_compositor_get_top_margin (GtkSourcePrintCompositor *compositor
  */
 void
 gtk_source_print_compositor_set_bottom_margin (GtkSourcePrintCompositor *compositor,
-                                               gdouble                   margin,
-                                               GtkUnit                   unit)
+                                              gdouble                   margin,
+                                              GtkUnit                   unit)
 {
-       GtkSourcePrintCompositorPrivate *priv = gtk_source_print_compositor_get_instance_private (compositor);
-
        g_return_if_fail (GTK_SOURCE_IS_PRINT_COMPOSITOR (compositor));
 
-       priv->margin_bottom = convert_to_mm (margin, unit);
+       compositor->priv->margin_bottom = convert_to_mm (margin, unit);
 }
 
 /**
@@ -1626,13 +1574,11 @@ gtk_source_print_compositor_set_bottom_margin (GtkSourcePrintCompositor *composi
  */
 gdouble
 gtk_source_print_compositor_get_bottom_margin (GtkSourcePrintCompositor *compositor,
-                                               GtkUnit                   unit)
+                                              GtkUnit                   unit)
 {
-       GtkSourcePrintCompositorPrivate *priv = gtk_source_print_compositor_get_instance_private (compositor);
-
        g_return_val_if_fail (GTK_SOURCE_IS_PRINT_COMPOSITOR (compositor), 0);
 
-       return convert_from_mm (priv->margin_bottom, unit);
+       return convert_from_mm (compositor->priv->margin_bottom, unit);
 }
 
 /**
@@ -1647,14 +1593,12 @@ gtk_source_print_compositor_get_bottom_margin (GtkSourcePrintCompositor *composi
  */
 void
 gtk_source_print_compositor_set_left_margin (GtkSourcePrintCompositor *compositor,
-                                             gdouble                   margin,
-                                             GtkUnit                   unit)
+                                            gdouble                   margin,
+                                            GtkUnit                   unit)
 {
-       GtkSourcePrintCompositorPrivate *priv = gtk_source_print_compositor_get_instance_private (compositor);
-
        g_return_if_fail (GTK_SOURCE_IS_PRINT_COMPOSITOR (compositor));
 
-       priv->margin_left = convert_to_mm (margin, unit);
+       compositor->priv->margin_left = convert_to_mm (margin, unit);
 }
 
 /**
@@ -1670,13 +1614,11 @@ gtk_source_print_compositor_set_left_margin (GtkSourcePrintCompositor *composito
  */
 gdouble
 gtk_source_print_compositor_get_left_margin (GtkSourcePrintCompositor *compositor,
-                                             GtkUnit                   unit)
+                                            GtkUnit                   unit)
 {
-       GtkSourcePrintCompositorPrivate *priv = gtk_source_print_compositor_get_instance_private (compositor);
-
        g_return_val_if_fail (GTK_SOURCE_IS_PRINT_COMPOSITOR (compositor), 0);
 
-       return convert_from_mm (priv->margin_left, unit);
+       return convert_from_mm (compositor->priv->margin_left, unit);
 }
 
 /**
@@ -1691,14 +1633,12 @@ gtk_source_print_compositor_get_left_margin (GtkSourcePrintCompositor *composito
  */
 void
 gtk_source_print_compositor_set_right_margin (GtkSourcePrintCompositor *compositor,
-                                              gdouble                   margin,
-                                              GtkUnit                   unit)
+                                             gdouble                   margin,
+                                             GtkUnit                   unit)
 {
-       GtkSourcePrintCompositorPrivate *priv = gtk_source_print_compositor_get_instance_private (compositor);
-
        g_return_if_fail (GTK_SOURCE_IS_PRINT_COMPOSITOR (compositor));
 
-       priv->margin_right = convert_to_mm (margin, unit);
+       compositor->priv->margin_right = convert_to_mm (margin, unit);
 }
 
 /**
@@ -1714,13 +1654,11 @@ gtk_source_print_compositor_set_right_margin (GtkSourcePrintCompositor *composit
  */
 gdouble
 gtk_source_print_compositor_get_right_margin (GtkSourcePrintCompositor *compositor,
-                                              GtkUnit                   unit)
+                                             GtkUnit                   unit)
 {
-       GtkSourcePrintCompositorPrivate *priv = gtk_source_print_compositor_get_instance_private (compositor);
-
        g_return_val_if_fail (GTK_SOURCE_IS_PRINT_COMPOSITOR (compositor), 0);
 
-       return convert_from_mm (priv->margin_right, unit);
+       return convert_from_mm (compositor->priv->margin_right, unit);
 }
 
 /**
@@ -1736,16 +1674,14 @@ gtk_source_print_compositor_get_right_margin (GtkSourcePrintCompositor *composit
  * Since: 2.2
  */
 gint
-gtk_source_print_compositor_get_n_pages (GtkSourcePrintCompositor *compositor)
+gtk_source_print_compositor_get_n_pages        (GtkSourcePrintCompositor *compositor)
 {
-       GtkSourcePrintCompositorPrivate *priv = gtk_source_print_compositor_get_instance_private (compositor);
-
        g_return_val_if_fail (GTK_SOURCE_IS_PRINT_COMPOSITOR (compositor), -1);
 
-       if (priv->state != DONE)
+       if (compositor->priv->state != DONE)
                return -1;
 
-       return priv->n_pages;
+       return compositor->priv->n_pages;
 }
 
 /* utility functions to deal with coordinates (returns) */
@@ -1753,13 +1689,12 @@ gtk_source_print_compositor_get_n_pages (GtkSourcePrintCompositor *compositor)
 static gdouble
 get_text_x (GtkSourcePrintCompositor *compositor)
 {
-       GtkSourcePrintCompositorPrivate *priv = gtk_source_print_compositor_get_instance_private (compositor);
        gdouble x;
 
-       x = priv->real_margin_left;
+       x = compositor->priv->real_margin_left;
 
-       if (priv->print_line_numbers)
-            x += priv->line_numbers_width + NUMBERS_TEXT_SEPARATION;
+       if (compositor->priv->print_line_numbers)
+            x += compositor->priv->line_numbers_width + NUMBERS_TEXT_SEPARATION;
 
        return x;
 }
@@ -1767,10 +1702,9 @@ get_text_x (GtkSourcePrintCompositor *compositor)
 static gdouble
 get_text_y (GtkSourcePrintCompositor *compositor)
 {
-       GtkSourcePrintCompositorPrivate *priv = gtk_source_print_compositor_get_instance_private (compositor);
        gdouble y;
 
-       y = priv->real_margin_top + priv->header_height;
+       y = compositor->priv->real_margin_top + compositor->priv->header_height;
 
        return y;
 }
@@ -1778,10 +1712,9 @@ get_text_y (GtkSourcePrintCompositor *compositor)
 static gdouble
 get_line_numbers_x (GtkSourcePrintCompositor *compositor)
 {
-       GtkSourcePrintCompositorPrivate *priv = gtk_source_print_compositor_get_instance_private (compositor);
        gdouble x;
 
-       x = priv->real_margin_left;
+       x = compositor->priv->real_margin_left;
 
        return x;
 }
@@ -1789,15 +1722,14 @@ get_line_numbers_x (GtkSourcePrintCompositor *compositor)
 static gdouble
 get_text_width (GtkSourcePrintCompositor *compositor)
 {
-       GtkSourcePrintCompositorPrivate *priv = gtk_source_print_compositor_get_instance_private (compositor);
        gdouble w;
 
-       w = priv->paper_width -
-           priv->real_margin_left -
-           priv->real_margin_right;
+       w = compositor->priv->paper_width -
+           compositor->priv->real_margin_left -
+           compositor->priv->real_margin_right;
 
-       if (priv->print_line_numbers)
-               w -= (priv->line_numbers_width + NUMBERS_TEXT_SEPARATION);
+       if (compositor->priv->print_line_numbers)
+               w -= (compositor->priv->line_numbers_width + NUMBERS_TEXT_SEPARATION);
 
        if (w < convert_from_mm (50, GTK_UNIT_POINTS)) {
                g_warning ("Printable page width too little.");
@@ -1810,14 +1742,13 @@ get_text_width (GtkSourcePrintCompositor *compositor)
 static gdouble
 get_text_height (GtkSourcePrintCompositor *compositor)
 {
-       GtkSourcePrintCompositorPrivate *priv = gtk_source_print_compositor_get_instance_private (compositor);
        double h;
 
-       h = priv->paper_height -
-           priv->real_margin_top -
-           priv->real_margin_bottom -
-           priv->header_height -
-           priv->footer_height;
+       h = compositor->priv->paper_height -
+           compositor->priv->real_margin_top -
+           compositor->priv->real_margin_bottom -
+           compositor->priv->header_height -
+           compositor->priv->footer_height;
 
        if (h < convert_from_mm (50, GTK_UNIT_POINTS)) {
                g_warning ("Printable page height too little.");
@@ -1830,34 +1761,29 @@ get_text_height (GtkSourcePrintCompositor *compositor)
 static gboolean
 is_header_to_print (GtkSourcePrintCompositor *compositor)
 {
-       GtkSourcePrintCompositorPrivate *priv = gtk_source_print_compositor_get_instance_private (compositor);
-
-       return (priv->print_header &&
-              ((priv->header_format_left != NULL) ||
-               (priv->header_format_center != NULL) ||
-               (priv->header_format_right != NULL)));
+       return (compositor->priv->print_header &&
+              ((compositor->priv->header_format_left != NULL) ||
+               (compositor->priv->header_format_center != NULL) ||
+               (compositor->priv->header_format_right != NULL)));
 }
 
 static gboolean
 is_footer_to_print (GtkSourcePrintCompositor *compositor)
 {
-       GtkSourcePrintCompositorPrivate *priv = gtk_source_print_compositor_get_instance_private (compositor);
-
-       return (priv->print_footer &&
-              ((priv->footer_format_left != NULL) ||
-               (priv->footer_format_center != NULL) ||
-               (priv->footer_format_right != NULL)));
+       return (compositor->priv->print_footer &&
+              ((compositor->priv->footer_format_left != NULL) ||
+               (compositor->priv->footer_format_center != NULL) ||
+               (compositor->priv->footer_format_right != NULL)));
 }
 
 static void
 set_layout_tab_width (GtkSourcePrintCompositor *compositor,
-                      PangoLayout              *layout)
+                     PangoLayout              *layout)
 {
-       GtkSourcePrintCompositorPrivate *priv = gtk_source_print_compositor_get_instance_private (compositor);
        gchar *str;
        gint tab_width = 0;
 
-       str = g_strnfill (priv->tab_width, ' ');
+       str = g_strnfill (compositor->priv->tab_width, ' ');
        pango_layout_set_text (layout, str, -1);
        g_free (str);
 
@@ -1881,16 +1807,15 @@ set_layout_tab_width (GtkSourcePrintCompositor *compositor,
 
 static void
 setup_pango_layouts (GtkSourcePrintCompositor *compositor,
-                     GtkPrintContext          *context)
+                    GtkPrintContext          *context)
 {
-       GtkSourcePrintCompositorPrivate *priv = gtk_source_print_compositor_get_instance_private (compositor);
        PangoLayout *layout;
 
        /* Layout for the text */
        layout = gtk_print_context_create_pango_layout (context);
-       pango_layout_set_font_description (layout, priv->body_font);
+       pango_layout_set_font_description (layout, compositor->priv->body_font);
 
-       switch (priv->wrap_mode)
+       switch (compositor->priv->wrap_mode)
        {
                case GTK_WRAP_CHAR:
                        pango_layout_set_wrap (layout, PANGO_WRAP_CHAR);
@@ -1917,21 +1842,21 @@ setup_pango_layouts (GtkSourcePrintCompositor *compositor,
 
        set_layout_tab_width (compositor, layout);
 
-       g_return_if_fail (priv->layout == NULL);
-       priv->layout = layout;
+       g_return_if_fail (compositor->priv->layout == NULL);
+       compositor->priv->layout = layout;
 
        /* Layout for line numbers */
-       if (priv->print_line_numbers > 0)
+       if (compositor->priv->print_line_numbers > 0)
        {
                layout = gtk_print_context_create_pango_layout (context);
 
-               if (priv->line_numbers_font == NULL)
-                       priv->line_numbers_font = pango_font_description_copy_static (priv->body_font);
-               pango_layout_set_font_description (layout, priv->line_numbers_font);
+               if (compositor->priv->line_numbers_font == NULL)
+                       compositor->priv->line_numbers_font = pango_font_description_copy_static 
(compositor->priv->body_font);
+               pango_layout_set_font_description (layout, compositor->priv->line_numbers_font);
                pango_layout_set_alignment (layout, PANGO_ALIGN_RIGHT);
 
-               g_return_if_fail (priv->line_numbers_layout == NULL);
-               priv->line_numbers_layout = layout;
+               g_return_if_fail (compositor->priv->line_numbers_layout == NULL);
+               compositor->priv->line_numbers_layout = layout;
        }
 
        /* Layout for header */
@@ -1939,13 +1864,13 @@ setup_pango_layouts (GtkSourcePrintCompositor *compositor,
        {
                layout = gtk_print_context_create_pango_layout (context);
 
-               if (priv->header_font == NULL)
-                       priv->header_font = pango_font_description_copy_static (priv->body_font);
+               if (compositor->priv->header_font == NULL)
+                       compositor->priv->header_font = pango_font_description_copy_static 
(compositor->priv->body_font);
 
-               pango_layout_set_font_description (layout, priv->header_font);
+               pango_layout_set_font_description (layout, compositor->priv->header_font);
 
-               g_return_if_fail (priv->header_layout == NULL);
-               priv->header_layout = layout;
+               g_return_if_fail (compositor->priv->header_layout == NULL);
+               compositor->priv->header_layout = layout;
        }
 
        /* Layout for footer */
@@ -1953,21 +1878,20 @@ setup_pango_layouts (GtkSourcePrintCompositor *compositor,
        {
                layout = gtk_print_context_create_pango_layout (context);
 
-               if (priv->footer_font == NULL)
-                       priv->footer_font = pango_font_description_copy_static (priv->body_font);
+               if (compositor->priv->footer_font == NULL)
+                       compositor->priv->footer_font = pango_font_description_copy_static 
(compositor->priv->body_font);
 
-               pango_layout_set_font_description (layout, priv->footer_font);
+               pango_layout_set_font_description (layout, compositor->priv->footer_font);
 
-               g_return_if_fail (priv->footer_layout == NULL);
-               priv->footer_layout = layout;
+               g_return_if_fail (compositor->priv->footer_layout == NULL);
+               compositor->priv->footer_layout = layout;
        }
 }
 
 static gchar *
 evaluate_format_string (GtkSourcePrintCompositor *compositor,
-                        const gchar              *format)
+                       const gchar              *format)
 {
-       GtkSourcePrintCompositorPrivate *priv = gtk_source_print_compositor_get_instance_private (compositor);
        GDateTime *now;
        GString *eval;
        gchar *eval_str, *retval;
@@ -1985,9 +1909,9 @@ evaluate_format_string (GtkSourcePrintCompositor *compositor,
                        format = g_utf8_next_char (format);
                        ch = g_utf8_get_char (format);
                        if (ch == 'N')
-                               g_string_append_printf (eval, "%d", priv->current_page + 1);
+                               g_string_append_printf (eval, "%d", compositor->priv->current_page + 1);
                        else if (ch == 'Q')
-                               g_string_append_printf (eval, "%d", priv->n_pages);
+                               g_string_append_printf (eval, "%d", compositor->priv->n_pages);
                        else
                        {
                                g_string_append_c (eval, '%');
@@ -2041,57 +1965,55 @@ get_n_digits (guint n)
 
 static void
 calculate_line_numbers_layout_size (GtkSourcePrintCompositor *compositor,
-                                    GtkPrintContext          *context)
+                                   GtkPrintContext          *context)
 {
-       GtkSourcePrintCompositorPrivate *priv = gtk_source_print_compositor_get_instance_private (compositor);
        gint line_count;
        gint n_digits;
        gchar *str;
 
-       if (priv->print_line_numbers == 0)
+       if (compositor->priv->print_line_numbers == 0)
        {
-               priv->line_numbers_width = 0.0;
-               priv->line_numbers_height = 0.0;
+               compositor->priv->line_numbers_width = 0.0;
+               compositor->priv->line_numbers_height = 0.0;
 
                DEBUG ({
                        g_debug ("line_numbers_width: %f points (%f mm)",
-                                priv->line_numbers_width,
-                                convert_to_mm (priv->line_numbers_width, GTK_UNIT_POINTS));
+                                compositor->priv->line_numbers_width,
+                                convert_to_mm (compositor->priv->line_numbers_width, GTK_UNIT_POINTS));
                        g_debug ("line_numbers_height: %f points (%f mm)",
-                                priv->line_numbers_height,
-                                convert_to_mm (priv->line_numbers_height, GTK_UNIT_POINTS));
+                                compositor->priv->line_numbers_height,
+                                convert_to_mm (compositor->priv->line_numbers_height, GTK_UNIT_POINTS));
                });
 
                return;
        }
 
-       line_count = gtk_text_buffer_get_line_count (GTK_TEXT_BUFFER (priv->buffer));
+       line_count = gtk_text_buffer_get_line_count (GTK_TEXT_BUFFER (compositor->priv->buffer));
        n_digits = get_n_digits (line_count);
        str = g_strnfill (n_digits, '9');
-       pango_layout_set_text (priv->line_numbers_layout, str, -1);
+       pango_layout_set_text (compositor->priv->line_numbers_layout, str, -1);
        g_free (str);
 
-       get_layout_size (priv->line_numbers_layout,
-                        &priv->line_numbers_width,
-                        &priv->line_numbers_height);
+       get_layout_size (compositor->priv->line_numbers_layout,
+                        &compositor->priv->line_numbers_width,
+                        &compositor->priv->line_numbers_height);
 
        DEBUG ({
                g_debug ("line_numbers_width: %f points (%f mm)",
-                        priv->line_numbers_width,
-                        convert_to_mm (priv->line_numbers_width, GTK_UNIT_POINTS));
+                        compositor->priv->line_numbers_width,
+                        convert_to_mm (compositor->priv->line_numbers_width, GTK_UNIT_POINTS));
                g_debug ("line_numbers_height: %f points (%f mm)",
-                        priv->line_numbers_height,
-                        convert_to_mm (priv->line_numbers_height, GTK_UNIT_POINTS));
+                        compositor->priv->line_numbers_height,
+                        convert_to_mm (compositor->priv->line_numbers_height, GTK_UNIT_POINTS));
        });
 }
 
 static gdouble
 calculate_header_footer_height (GtkSourcePrintCompositor *compositor,
-                                GtkPrintContext          *context,
-                                PangoFontDescription     *font,
-                                gdouble                  *d)
+                               GtkPrintContext          *context,
+                               PangoFontDescription     *font,
+                               gdouble                  *d)
 {
-       GtkSourcePrintCompositorPrivate *priv = gtk_source_print_compositor_get_instance_private (compositor);
        PangoContext *pango_context;
        PangoFontMetrics* font_metrics;
        gdouble ascent;
@@ -2102,7 +2024,7 @@ calculate_header_footer_height (GtkSourcePrintCompositor *compositor,
 
        font_metrics = pango_context_get_metrics (pango_context,
                                                  font,
-                                                 priv->language);
+                                                 compositor->priv->language);
 
        ascent = (gdouble) pango_font_metrics_get_ascent (font_metrics) / PANGO_SCALE;
        descent = (gdouble) pango_font_metrics_get_descent (font_metrics) / PANGO_SCALE;
@@ -2118,128 +2040,123 @@ calculate_header_footer_height (GtkSourcePrintCompositor *compositor,
 
 static void
 calculate_header_height (GtkSourcePrintCompositor *compositor,
-                         GtkPrintContext          *context)
+                        GtkPrintContext          *context)
 {
-       GtkSourcePrintCompositorPrivate *priv = gtk_source_print_compositor_get_instance_private (compositor);
-
        if (!is_header_to_print(compositor))
        {
-               priv->header_height = 0.0;
+               compositor->priv->header_height = 0.0;
 
                DEBUG ({
                        g_debug ("header_height: %f points (%f mm)",
-                                priv->header_height,
-                                convert_to_mm (priv->header_height, GTK_UNIT_POINTS));
+                                compositor->priv->header_height,
+                                convert_to_mm (compositor->priv->header_height, GTK_UNIT_POINTS));
                });
 
                return;
        }
 
-       g_return_if_fail (priv->header_font != NULL);
+       g_return_if_fail (compositor->priv->header_font != NULL);
 
-       priv->header_height = calculate_header_footer_height (compositor,
+       compositor->priv->header_height = calculate_header_footer_height (compositor,
                                                                          context,
-                                                                         priv->header_font,
+                                                                         compositor->priv->header_font,
                                                                          NULL);
 
        DEBUG ({
                g_debug ("header_height: %f points (%f mm)",
-                        priv->header_height,
-                        convert_to_mm (priv->header_height, GTK_UNIT_POINTS));
+                        compositor->priv->header_height,
+                        convert_to_mm (compositor->priv->header_height, GTK_UNIT_POINTS));
        });
 }
 
 static void
 calculate_footer_height (GtkSourcePrintCompositor *compositor,
-                         GtkPrintContext          *context)
+                        GtkPrintContext          *context)
 {
-       GtkSourcePrintCompositorPrivate *priv = gtk_source_print_compositor_get_instance_private (compositor);
-
        if (!is_footer_to_print (compositor))
        {
-               priv->footer_height = 0.0;
+               compositor->priv->footer_height = 0.0;
 
                DEBUG ({
                        g_debug ("footer_height: %f points (%f mm)",
-                                priv->footer_height,
-                                convert_to_mm (priv->footer_height, GTK_UNIT_POINTS));
+                                compositor->priv->footer_height,
+                                convert_to_mm (compositor->priv->footer_height, GTK_UNIT_POINTS));
                });
 
 
                return;
        }
 
-       if (priv->footer_font == NULL)
-               priv->footer_font = pango_font_description_copy_static (priv->body_font);
+       if (compositor->priv->footer_font == NULL)
+               compositor->priv->footer_font = pango_font_description_copy_static 
(compositor->priv->body_font);
 
-       priv->footer_height = calculate_header_footer_height (compositor,
+       compositor->priv->footer_height = calculate_header_footer_height (compositor,
                                                                          context,
-                                                                         priv->footer_font,
-                                                                         &priv->footer_font_descent);
+                                                                         compositor->priv->footer_font,
+                                                                         
&compositor->priv->footer_font_descent);
 
        DEBUG ({
                g_debug ("footer_height: %f points (%f mm)",
-                        priv->footer_height,
-                        convert_to_mm (priv->footer_height, GTK_UNIT_POINTS));
+                        compositor->priv->footer_height,
+                        convert_to_mm (compositor->priv->footer_height, GTK_UNIT_POINTS));
        });
 }
 
 static void
 calculate_page_size_and_margins (GtkSourcePrintCompositor *compositor,
-                                 GtkPrintContext          *context)
+                                GtkPrintContext          *context)
 {
-       GtkSourcePrintCompositorPrivate *priv = gtk_source_print_compositor_get_instance_private (compositor);
        GtkPageSetup *page_setup;
 
        /* calculate_line_numbers_layout_size and calculate_header_footer_height
           functions must be called before calculate_page_size_and_margins */
-       g_return_if_fail (priv->line_numbers_width >= 0.0);
-       g_return_if_fail (priv->header_height >= 0.0);
-       g_return_if_fail (priv->footer_height >= 0.0);
+       g_return_if_fail (compositor->priv->line_numbers_width >= 0.0);
+       g_return_if_fail (compositor->priv->header_height >= 0.0);
+       g_return_if_fail (compositor->priv->footer_height >= 0.0);
 
        page_setup = gtk_print_context_get_page_setup (context);
 
-       priv->page_margin_top = gtk_page_setup_get_top_margin (page_setup, GTK_UNIT_POINTS);
-       priv->page_margin_left = gtk_page_setup_get_left_margin (page_setup, GTK_UNIT_POINTS);
+       compositor->priv->page_margin_top = gtk_page_setup_get_top_margin (page_setup, GTK_UNIT_POINTS);
+       compositor->priv->page_margin_left = gtk_page_setup_get_left_margin (page_setup, GTK_UNIT_POINTS);
 
        /* Calculate real margins: the margins specified in the GtkPageSetup object are the "print margins".
           they are used to determine the minimal size for the layout margins. */
-       priv->real_margin_top = MAX (priv->page_margin_top,
-                                                convert_from_mm (priv->margin_top, GTK_UNIT_POINTS));
-       priv->real_margin_bottom = MAX (gtk_page_setup_get_bottom_margin (page_setup, GTK_UNIT_POINTS),
-                                                   convert_from_mm (priv->margin_bottom, GTK_UNIT_POINTS));
-       priv->real_margin_left = MAX (priv->page_margin_left,
-                                                 convert_from_mm (priv->margin_left, GTK_UNIT_POINTS));
-       priv->real_margin_right = MAX (gtk_page_setup_get_right_margin (page_setup, GTK_UNIT_POINTS),
-                                                  convert_from_mm (priv->margin_right, GTK_UNIT_POINTS));
+       compositor->priv->real_margin_top = MAX (compositor->priv->page_margin_top,
+                                                convert_from_mm (compositor->priv->margin_top, 
GTK_UNIT_POINTS));
+       compositor->priv->real_margin_bottom = MAX (gtk_page_setup_get_bottom_margin (page_setup, 
GTK_UNIT_POINTS),
+                                                   convert_from_mm (compositor->priv->margin_bottom, 
GTK_UNIT_POINTS));
+       compositor->priv->real_margin_left = MAX (compositor->priv->page_margin_left,
+                                                 convert_from_mm (compositor->priv->margin_left, 
GTK_UNIT_POINTS));
+       compositor->priv->real_margin_right = MAX (gtk_page_setup_get_right_margin (page_setup, 
GTK_UNIT_POINTS),
+                                                  convert_from_mm (compositor->priv->margin_right, 
GTK_UNIT_POINTS));
 
        DEBUG ({
                g_debug ("real_margin_top: %f points (%f mm)",
-                        priv->real_margin_top,
-                        convert_to_mm (priv->real_margin_top, GTK_UNIT_POINTS));
+                        compositor->priv->real_margin_top,
+                        convert_to_mm (compositor->priv->real_margin_top, GTK_UNIT_POINTS));
                g_debug ("real_margin_bottom: %f points (%f mm)",
-                        priv->real_margin_bottom,
-                        convert_to_mm (priv->real_margin_bottom, GTK_UNIT_POINTS));
+                        compositor->priv->real_margin_bottom,
+                        convert_to_mm (compositor->priv->real_margin_bottom, GTK_UNIT_POINTS));
                g_debug ("real_margin_left: %f points (%f mm)",
-                        priv->real_margin_left,
-                        convert_to_mm (priv->real_margin_left, GTK_UNIT_POINTS));
+                        compositor->priv->real_margin_left,
+                        convert_to_mm (compositor->priv->real_margin_left, GTK_UNIT_POINTS));
                g_debug ("real_margin_righ: %f points (%f mm)",
-                        priv->real_margin_right,
-                        convert_to_mm (priv->real_margin_right, GTK_UNIT_POINTS));
+                        compositor->priv->real_margin_right,
+                        convert_to_mm (compositor->priv->real_margin_right, GTK_UNIT_POINTS));
        });
 
-       priv->paper_width = gtk_page_setup_get_paper_width (page_setup, GTK_UNIT_POINTS);
-       priv->paper_height = gtk_page_setup_get_paper_height (page_setup, GTK_UNIT_POINTS);
+       compositor->priv->paper_width = gtk_page_setup_get_paper_width (page_setup, GTK_UNIT_POINTS);
+       compositor->priv->paper_height = gtk_page_setup_get_paper_height (page_setup, GTK_UNIT_POINTS);
 
        DEBUG ({
                gdouble text_width;
                gdouble text_height;
                g_debug ("paper_width: %f points (%f mm)",
-                        priv->paper_width,
-                        convert_to_mm (priv->paper_width, GTK_UNIT_POINTS));
+                        compositor->priv->paper_width,
+                        convert_to_mm (compositor->priv->paper_width, GTK_UNIT_POINTS));
                g_debug ("paper_heigth: %f points (%f mm)",
-                        priv->paper_height,
-                        convert_to_mm (priv->paper_height, GTK_UNIT_POINTS));
+                        compositor->priv->paper_height,
+                        convert_to_mm (compositor->priv->paper_height, GTK_UNIT_POINTS));
                text_width = get_text_width (compositor);
                text_height = get_text_height (compositor);
                g_debug ("text_width: %f points (%f mm)", text_width, convert_to_mm (text_width, 
GTK_UNIT_POINTS));
@@ -2256,10 +2173,9 @@ static gboolean
 ignore_tag (GtkSourcePrintCompositor *compositor,
             GtkTextTag               *tag)
 {
-       GtkSourcePrintCompositorPrivate *priv = gtk_source_print_compositor_get_instance_private (compositor);
        GtkTextTag *bm_tag;
 
-       bm_tag = _gtk_source_buffer_get_bracket_match_tag (priv->buffer);
+       bm_tag = _gtk_source_buffer_get_bracket_match_tag (compositor->priv->buffer);
        if ((bm_tag != NULL) && (tag == bm_tag))
                return TRUE;
 
@@ -2268,8 +2184,8 @@ ignore_tag (GtkSourcePrintCompositor *compositor,
 
 static GSList *
 get_iter_attrs (GtkSourcePrintCompositor *compositor,
-                GtkTextIter              *iter,
-                GtkTextIter              *limit)
+               GtkTextIter              *iter,
+               GtkTextIter              *limit)
 {
        GSList *attrs = NULL;
        GSList *tags;
@@ -2404,10 +2320,9 @@ is_empty_line (const gchar *text)
 
 static void
 layout_paragraph (GtkSourcePrintCompositor *compositor,
-                  GtkTextIter              *start,
-                  GtkTextIter              *end)
+                 GtkTextIter              *start,
+                 GtkTextIter              *end)
 {
-       GtkSourcePrintCompositorPrivate *priv = gtk_source_print_compositor_get_instance_private (compositor);
        gchar *text;
 
        text = gtk_text_iter_get_slice (start, end);
@@ -2419,22 +2334,22 @@ layout_paragraph (GtkSourcePrintCompositor *compositor,
        if (gtk_text_iter_ends_line (start) ||
            is_empty_line (text))
        {
-               pango_layout_set_text (priv->layout, " ", 1);
+               pango_layout_set_text (compositor->priv->layout, " ", 1);
                g_free (text);
                return;
        }
 
-       pango_layout_set_text (priv->layout, text, -1);
+       pango_layout_set_text (compositor->priv->layout, text, -1);
        g_free (text);
 
-       if (priv->highlight_syntax)
+       if (compositor->priv->highlight_syntax)
        {
                PangoAttrList *attr_list = NULL;
                GtkTextIter segm_start, segm_end;
                int start_index;
 
                /* Make sure it is highlighted even if it was not shown yet */
-               gtk_source_buffer_ensure_highlight (priv->buffer,
+               gtk_source_buffer_ensure_highlight (compositor->priv->buffer,
                                                    start,
                                                    end);
 
@@ -2472,7 +2387,7 @@ layout_paragraph (GtkSourcePrintCompositor *compositor,
                        segm_start = segm_end;
                }
 
-               pango_layout_set_attributes (priv->layout,
+               pango_layout_set_attributes (compositor->priv->layout,
                                             attr_list);
 
                if (attr_list)
@@ -2482,28 +2397,24 @@ layout_paragraph (GtkSourcePrintCompositor *compositor,
 
 static gboolean
 line_is_numbered (GtkSourcePrintCompositor *compositor,
-                  gint                      line_number)
+                 gint                      line_number)
 {
-       GtkSourcePrintCompositorPrivate *priv = gtk_source_print_compositor_get_instance_private (compositor);
-
-       return (priv->print_line_numbers > 0) &&
-              ((line_number + 1) % priv->print_line_numbers == 0);
+       return (compositor->priv->print_line_numbers > 0) &&
+              ((line_number + 1) % compositor->priv->print_line_numbers == 0);
 }
 
 static void
 set_pango_layouts_width (GtkSourcePrintCompositor *compositor)
 {
-       GtkSourcePrintCompositorPrivate *priv = gtk_source_print_compositor_get_instance_private (compositor);
-
-       g_return_if_fail (priv->layout != NULL);
-       pango_layout_set_width (priv->layout,
+       g_return_if_fail (compositor->priv->layout != NULL);
+       pango_layout_set_width (compositor->priv->layout,
                                get_text_width (compositor) * PANGO_SCALE);
 
-       if (priv->print_line_numbers)
+       if (compositor->priv->print_line_numbers)
        {
-               g_return_if_fail (priv->line_numbers_layout != NULL);
-               pango_layout_set_width (priv->line_numbers_layout,
-                                       priv->line_numbers_width * PANGO_SCALE);
+               g_return_if_fail (compositor->priv->line_numbers_layout != NULL);
+               pango_layout_set_width (compositor->priv->line_numbers_layout,
+                                       compositor->priv->line_numbers_width * PANGO_SCALE);
        }
 }
 
@@ -2584,9 +2495,8 @@ set_pango_layouts_width (GtkSourcePrintCompositor *compositor)
  */
 gboolean
 gtk_source_print_compositor_paginate (GtkSourcePrintCompositor *compositor,
-                                      GtkPrintContext          *context)
+                                     GtkPrintContext          *context)
 {
-       GtkSourcePrintCompositorPrivate *priv = gtk_source_print_compositor_get_instance_private (compositor);
        GtkTextIter start, end;
        gint page_start_offset;
        double text_height;
@@ -2598,10 +2508,10 @@ gtk_source_print_compositor_paginate (GtkSourcePrintCompositor *compositor,
        g_return_val_if_fail (GTK_SOURCE_IS_PRINT_COMPOSITOR (compositor), TRUE);
        g_return_val_if_fail (GTK_IS_PRINT_CONTEXT (context), TRUE);
 
-       if (priv->state == DONE)
+       if (compositor->priv->state == DONE)
                return TRUE;
 
-       if (priv->state == INIT)
+       if (compositor->priv->state == INIT)
        {
                PROFILE ({
                        if (pagination_timer != NULL)
@@ -2610,9 +2520,9 @@ gtk_source_print_compositor_paginate (GtkSourcePrintCompositor *compositor,
                        pagination_timer = g_timer_new ();
                });
 
-               g_return_val_if_fail (priv->pages == NULL, TRUE);
+               g_return_val_if_fail (compositor->priv->pages == NULL, TRUE);
 
-               priv->pages = g_array_new (FALSE, FALSE, sizeof (gint));
+               compositor->priv->pages = g_array_new (FALSE, FALSE, sizeof (gint));
 
                setup_pango_layouts (compositor, context);
 
@@ -2625,37 +2535,37 @@ gtk_source_print_compositor_paginate (GtkSourcePrintCompositor *compositor,
                /* Cannot be done when setting up layouts since we need the width */
                set_pango_layouts_width (compositor);
 
-               priv->state = PAGINATING;
+               compositor->priv->state = PAGINATING;
        }
 
-       g_return_val_if_fail (priv->state == PAGINATING, FALSE);
-       g_return_val_if_fail (priv->layout != NULL, FALSE);
+       g_return_val_if_fail (compositor->priv->state == PAGINATING, FALSE);
+       g_return_val_if_fail (compositor->priv->layout != NULL, FALSE);
 
-       if (priv->pagination_mark == NULL)
+       if (compositor->priv->pagination_mark == NULL)
        {
-               gtk_text_buffer_get_start_iter (GTK_TEXT_BUFFER (priv->buffer), &start);
+               gtk_text_buffer_get_start_iter (GTK_TEXT_BUFFER (compositor->priv->buffer), &start);
 
-               priv->pagination_mark = gtk_text_buffer_create_mark (GTK_TEXT_BUFFER (priv->buffer),
+               compositor->priv->pagination_mark = gtk_text_buffer_create_mark (GTK_TEXT_BUFFER 
(compositor->priv->buffer),
                                                                                 NULL,
                                                                                 &start,
                                                                                 TRUE);
 
                /* add the first page start */
                page_start_offset = gtk_text_iter_get_offset (&start);
-               g_array_append_val (priv->pages, page_start_offset);
+               g_array_append_val (compositor->priv->pages, page_start_offset);
        }
        else
        {
-               gtk_text_buffer_get_iter_at_mark (GTK_TEXT_BUFFER (priv->buffer),
+               gtk_text_buffer_get_iter_at_mark (GTK_TEXT_BUFFER (compositor->priv->buffer),
                                                  &start,
-                                                 priv->pagination_mark);
+                                                 compositor->priv->pagination_mark);
        }
 
        DEBUG ({
                g_debug ("Start paginating at %d", gtk_text_iter_get_offset (&start));
        });
 
-       gtk_text_buffer_get_end_iter (GTK_TEXT_BUFFER (priv->buffer), &end);
+       gtk_text_buffer_get_end_iter (GTK_TEXT_BUFFER (compositor->priv->buffer), &end);
 
        cur_height = 0;
        text_height = get_text_height (compositor);
@@ -2677,14 +2587,14 @@ gtk_source_print_compositor_paginate (GtkSourcePrintCompositor *compositor,
 
                layout_paragraph (compositor, &start, &line_end);
 
-               get_layout_size (priv->layout, NULL, &line_height);
+               get_layout_size (compositor->priv->layout, NULL, &line_height);
 
                if (line_is_numbered (compositor, line_number))
                {
-                       g_assert (priv->line_numbers_height > 0);
+                       g_assert (compositor->priv->line_numbers_height > 0);
 
                        line_height = MAX (line_height,
-                                          priv->line_numbers_height);
+                                          compositor->priv->line_numbers_height);
                }
 
 #define EPS (.1)
@@ -2692,8 +2602,8 @@ gtk_source_print_compositor_paginate (GtkSourcePrintCompositor *compositor,
                {
                        /* if we have multiline paragraphs, see how much of
                         * it we can fit in the current page */
-                       if (priv->wrap_mode != GTK_WRAP_NONE &&
-                           pango_layout_get_line_count (priv->layout) > 1)
+                       if (compositor->priv->wrap_mode != GTK_WRAP_NONE &&
+                           pango_layout_get_line_count (compositor->priv->layout) > 1)
                        {
                                PangoLayoutIter *layout_iter;
                                PangoRectangle logical_rect;
@@ -2701,7 +2611,7 @@ gtk_source_print_compositor_paginate (GtkSourcePrintCompositor *compositor,
                                double part_height = 0;
                                gint idx;
 
-                               layout_iter = pango_layout_get_iter (priv->layout);
+                               layout_iter = pango_layout_get_iter (compositor->priv->layout);
 
                                do
                                {
@@ -2713,7 +2623,7 @@ gtk_source_print_compositor_paginate (GtkSourcePrintCompositor *compositor,
                                        if (is_first_line &&
                                            line_is_numbered (compositor, line_number))
                                        {
-                                               layout_line_height = MAX (priv->line_numbers_height,
+                                               layout_line_height = MAX 
(compositor->priv->line_numbers_height,
                                                                          layout_line_height);
                                        }
 
@@ -2739,8 +2649,8 @@ gtk_source_print_compositor_paginate (GtkSourcePrintCompositor *compositor,
 
                                page_start_offset = gtk_text_iter_get_offset (&start);
 
-                               gtk_text_buffer_move_mark (GTK_TEXT_BUFFER (priv->buffer),
-                                                          priv->pagination_mark,
+                               gtk_text_buffer_move_mark (GTK_TEXT_BUFFER (compositor->priv->buffer),
+                                                          compositor->priv->pagination_mark,
                                                           &start);
 
                                /* if the remainder fits on the next page, go
@@ -2761,8 +2671,8 @@ gtk_source_print_compositor_paginate (GtkSourcePrintCompositor *compositor,
                        {
                                page_start_offset = gtk_text_iter_get_offset (&start);
 
-                               gtk_text_buffer_move_mark (GTK_TEXT_BUFFER (priv->buffer),
-                                                          priv->pagination_mark,
+                               gtk_text_buffer_move_mark (GTK_TEXT_BUFFER (compositor->priv->buffer),
+                                                          compositor->priv->pagination_mark,
                                                           &start);
 
                                /* reset cur_height for the next page */
@@ -2771,7 +2681,7 @@ gtk_source_print_compositor_paginate (GtkSourcePrintCompositor *compositor,
                        }
 
                        /* store the start of the new page */
-                       g_array_append_val (priv->pages,
+                       g_array_append_val (compositor->priv->pages,
                                            page_start_offset);
 
                        ++pages_count;
@@ -2798,26 +2708,26 @@ gtk_source_print_compositor_paginate (GtkSourcePrintCompositor *compositor,
                DEBUG ({
                        int i;
 
-                       for (i = 0; i < priv->pages->len; i += 1)
+                       for (i = 0; i < compositor->priv->pages->len; i += 1)
                        {
                                gint offset;
                                GtkTextIter iter;
 
-                               offset = g_array_index (priv->pages, int, i);
-                               gtk_text_buffer_get_iter_at_offset (GTK_TEXT_BUFFER (priv->buffer), &iter, 
offset);
+                               offset = g_array_index (compositor->priv->pages, int, i);
+                               gtk_text_buffer_get_iter_at_offset (GTK_TEXT_BUFFER 
(compositor->priv->buffer), &iter, offset);
 
                                g_debug ("  page %d starts at line %d (offset %d)\n", i, 
gtk_text_iter_get_line (&iter), offset);
                        }
                });
 
-               priv->state = DONE;
+               compositor->priv->state = DONE;
 
-               priv->n_pages = priv->pages->len;
+               compositor->priv->n_pages = compositor->priv->pages->len;
 
                /* Remove the pagination mark */
-               gtk_text_buffer_delete_mark (GTK_TEXT_BUFFER (priv->buffer),
-                                            priv->pagination_mark);
-               priv->pagination_mark = NULL;
+               gtk_text_buffer_delete_mark (GTK_TEXT_BUFFER (compositor->priv->buffer),
+                                            compositor->priv->pagination_mark);
+               compositor->priv->pagination_mark = NULL;
        }
 
        return (done != FALSE);
@@ -2836,38 +2746,36 @@ gtk_source_print_compositor_paginate (GtkSourcePrintCompositor *compositor,
 gdouble
 gtk_source_print_compositor_get_pagination_progress (GtkSourcePrintCompositor *compositor)
 {
-       GtkSourcePrintCompositorPrivate *priv = gtk_source_print_compositor_get_instance_private (compositor);
        GtkTextIter current;
        gint char_count;
 
        g_return_val_if_fail (GTK_SOURCE_IS_PRINT_COMPOSITOR (compositor), 0.0);
 
-       if (priv->state == INIT)
+       if (compositor->priv->state == INIT)
                return 0.0;
 
-       if (priv->state == DONE)
+       if (compositor->priv->state == DONE)
                return 1.0;
 
-       char_count = gtk_text_buffer_get_char_count (GTK_TEXT_BUFFER (priv->buffer));
+       char_count = gtk_text_buffer_get_char_count (GTK_TEXT_BUFFER (compositor->priv->buffer));
        if (char_count == 0)
                return 1.0;
 
-       g_return_val_if_fail (priv->pagination_mark != NULL, 0.0);
+       g_return_val_if_fail (compositor->priv->pagination_mark != NULL, 0.0);
 
-       gtk_text_buffer_get_iter_at_mark (GTK_TEXT_BUFFER (priv->buffer),
+       gtk_text_buffer_get_iter_at_mark (GTK_TEXT_BUFFER (compositor->priv->buffer),
                                          &current,
-                                         priv->pagination_mark);
+                                         compositor->priv->pagination_mark);
 
        return (gdouble) gtk_text_iter_get_offset (&current) / (gdouble) char_count;
 }
 
 static void
 print_header_string (GtkSourcePrintCompositor *compositor,
-                     cairo_t                  *cr,
-                     PangoAlignment            alignment,
-                     const gchar              *format)
+                    cairo_t                  *cr,
+                    PangoAlignment            alignment,
+                    const gchar              *format)
 {
-       GtkSourcePrintCompositorPrivate *priv = gtk_source_print_compositor_get_instance_private (compositor);
        gchar *text;
 
        text = evaluate_format_string (compositor, format);
@@ -2882,31 +2790,31 @@ print_header_string (GtkSourcePrintCompositor *compositor,
                gdouble header_width;
                gdouble x;
 
-               header_width = priv->paper_width -
-                              priv->real_margin_left -
-                              priv->real_margin_right;
+               header_width = compositor->priv->paper_width -
+                              compositor->priv->real_margin_left -
+                              compositor->priv->real_margin_right;
 
-               pango_layout_set_text (priv->header_layout, text, -1);
+               pango_layout_set_text (compositor->priv->header_layout, text, -1);
 
                /* Print only the first line */
-               iter = pango_layout_get_iter (priv->header_layout);
+               iter = pango_layout_get_iter (compositor->priv->header_layout);
                baseline = (gdouble) pango_layout_iter_get_baseline (iter) / (gdouble) PANGO_SCALE;
 
-               get_layout_size (priv->header_layout, &layout_width, &layout_height);
+               get_layout_size (compositor->priv->header_layout, &layout_width, &layout_height);
 
                switch (alignment)
                {
                        case PANGO_ALIGN_RIGHT:
-                               x = priv->real_margin_left + header_width - layout_width;
+                               x = compositor->priv->real_margin_left + header_width - layout_width;
                                break;
 
                        case PANGO_ALIGN_CENTER:
-                               x = priv->real_margin_left + header_width / 2 - layout_width / 2;
+                               x = compositor->priv->real_margin_left + header_width / 2 - layout_width / 2;
                                break;
 
                        case PANGO_ALIGN_LEFT:
                        default:
-                               x = priv->real_margin_left;
+                               x = compositor->priv->real_margin_left;
                                break;
                }
 
@@ -2917,7 +2825,7 @@ print_header_string (GtkSourcePrintCompositor *compositor,
                        cairo_set_source_rgb (cr, 0., 0., 1.);
                        cairo_rectangle (cr,
                                         x,
-                                        priv->real_margin_top,
+                                        compositor->priv->real_margin_top,
                                         layout_width,
                                         layout_height);
                        cairo_stroke (cr);
@@ -2929,7 +2837,7 @@ print_header_string (GtkSourcePrintCompositor *compositor,
 
                cairo_move_to (cr,
                               x,
-                              priv->real_margin_top + baseline);
+                              compositor->priv->real_margin_top + baseline);
 
                pango_cairo_show_layout_line (cr, line);
 
@@ -2940,44 +2848,42 @@ print_header_string (GtkSourcePrintCompositor *compositor,
 
 static void
 print_header (GtkSourcePrintCompositor *compositor,
-              cairo_t                  *cr)
+             cairo_t                  *cr)
 {
-       GtkSourcePrintCompositorPrivate *priv = gtk_source_print_compositor_get_instance_private (compositor);
-
-       pango_cairo_update_layout (cr, priv->header_layout);
+       pango_cairo_update_layout (cr, compositor->priv->header_layout);
 
        /* left format */
-       if (priv->header_format_left != NULL)
+       if (compositor->priv->header_format_left != NULL)
                print_header_string (compositor,
                                     cr,
                                     PANGO_ALIGN_LEFT,
-                                    priv->header_format_left);
+                                    compositor->priv->header_format_left);
 
        /* right format */
-       if (priv->header_format_right != NULL)
+       if (compositor->priv->header_format_right != NULL)
                print_header_string (compositor,
                                     cr,
                                     PANGO_ALIGN_RIGHT,
-                                    priv->header_format_right);
+                                    compositor->priv->header_format_right);
 
        /* center format */
-       if (priv->header_format_center != NULL)
+       if (compositor->priv->header_format_center != NULL)
                print_header_string (compositor,
                                     cr,
                                     PANGO_ALIGN_CENTER,
-                                    priv->header_format_center);
+                                    compositor->priv->header_format_center);
 
        /* separator */
-       if (priv->header_separator)
+       if (compositor->priv->header_separator)
        {
-               gdouble y = priv->real_margin_top +
-                           (1 - SEPARATOR_SPACING_FACTOR) * priv->header_height;
+               gdouble y = compositor->priv->real_margin_top +
+                           (1 - SEPARATOR_SPACING_FACTOR) * compositor->priv->header_height;
 
                cairo_save (cr);
 
-               cairo_move_to (cr, priv->real_margin_left, y);
+               cairo_move_to (cr, compositor->priv->real_margin_left, y);
                cairo_set_line_width (cr, SEPARATOR_LINE_WIDTH);
-               cairo_line_to (cr, priv->paper_width - priv->real_margin_right, y);
+               cairo_line_to (cr, compositor->priv->paper_width - compositor->priv->real_margin_right, y);
                cairo_stroke (cr);
 
                cairo_restore (cr);
@@ -2986,11 +2892,10 @@ print_header (GtkSourcePrintCompositor *compositor,
 
 static void
 print_footer_string (GtkSourcePrintCompositor *compositor,
-                     cairo_t                  *cr,
-                     PangoAlignment            alignment,
-                     const gchar              *format)
+                    cairo_t                  *cr,
+                    PangoAlignment            alignment,
+                    const gchar              *format)
 {
-       GtkSourcePrintCompositorPrivate *priv = gtk_source_print_compositor_get_instance_private (compositor);
        gchar *text;
 
        text = evaluate_format_string (compositor, format);
@@ -3003,44 +2908,44 @@ print_footer_string (GtkSourcePrintCompositor *compositor,
                gdouble footer_width;
                gdouble x;
 
-               footer_width = priv->paper_width -
-                              priv->real_margin_left -
-                              priv->real_margin_right;
+               footer_width = compositor->priv->paper_width -
+                              compositor->priv->real_margin_left -
+                              compositor->priv->real_margin_right;
 
-               pango_layout_set_text (priv->footer_layout, text, -1);
+               pango_layout_set_text (compositor->priv->footer_layout, text, -1);
 
-               get_layout_size (priv->footer_layout, &layout_width, &layout_height);
+               get_layout_size (compositor->priv->footer_layout, &layout_width, &layout_height);
 
                switch (alignment)
                {
                        case PANGO_ALIGN_RIGHT:
-                               x = priv->real_margin_left + footer_width - layout_width;
+                               x = compositor->priv->real_margin_left + footer_width - layout_width;
                                break;
 
                        case PANGO_ALIGN_CENTER:
-                               x = priv->real_margin_left + footer_width / 2 - layout_width / 2;
+                               x = compositor->priv->real_margin_left + footer_width / 2 - layout_width / 2;
                                break;
 
                        case PANGO_ALIGN_LEFT:
                        default:
-                               x = priv->real_margin_left;
+                               x = compositor->priv->real_margin_left;
                                break;
                }
                /* Print only the first line */
-               line = pango_layout_get_line (priv->footer_layout, 0);
+               line = pango_layout_get_line (compositor->priv->footer_layout, 0);
 
                DEBUG ({
                        gdouble w;
                        gdouble h;
 
-                       get_layout_size (priv->footer_layout, &w, &h);
+                       get_layout_size (compositor->priv->footer_layout, &w, &h);
 
                        cairo_save (cr);
                        cairo_set_line_width (cr, 1.);
                        cairo_set_source_rgb (cr, 0., 0., 1.);
                        cairo_rectangle (cr,
                                         x,
-                                        priv->paper_height - priv->real_margin_bottom - h,
+                                        compositor->priv->paper_height - 
compositor->priv->real_margin_bottom - h,
                                         layout_width,
                                         layout_height);
                        cairo_stroke (cr);
@@ -3049,8 +2954,8 @@ print_footer_string (GtkSourcePrintCompositor *compositor,
 
                cairo_move_to (cr,
                               x,
-                              priv->paper_height -
-                               priv->real_margin_bottom - priv->footer_font_descent);
+                              compositor->priv->paper_height -
+                               compositor->priv->real_margin_bottom - compositor->priv->footer_font_descent);
 
                pango_cairo_show_layout_line (cr, line);
 
@@ -3060,45 +2965,43 @@ print_footer_string (GtkSourcePrintCompositor *compositor,
 
 static void
 print_footer (GtkSourcePrintCompositor *compositor,
-              cairo_t                  *cr)
+             cairo_t                  *cr)
 {
-       GtkSourcePrintCompositorPrivate *priv = gtk_source_print_compositor_get_instance_private (compositor);
-
-       pango_cairo_update_layout (cr, priv->footer_layout);
+       pango_cairo_update_layout (cr, compositor->priv->footer_layout);
 
        /* left format */
-       if (priv->footer_format_left != NULL)
+       if (compositor->priv->footer_format_left != NULL)
                print_footer_string (compositor,
                                     cr,
                                     PANGO_ALIGN_LEFT,
-                                    priv->footer_format_left);
+                                    compositor->priv->footer_format_left);
 
        /* right format */
-       if (priv->footer_format_right != NULL)
+       if (compositor->priv->footer_format_right != NULL)
                print_footer_string (compositor,
                                     cr,
                                     PANGO_ALIGN_RIGHT,
-                                    priv->footer_format_right);
+                                    compositor->priv->footer_format_right);
 
        /* center format */
-       if (priv->footer_format_center != NULL)
+       if (compositor->priv->footer_format_center != NULL)
                print_footer_string (compositor,
                                     cr,
                                     PANGO_ALIGN_CENTER,
-                                    priv->footer_format_center);
+                                    compositor->priv->footer_format_center);
 
        /* separator */
-       if (priv->footer_separator)
+       if (compositor->priv->footer_separator)
        {
-               gdouble y = priv->paper_height -
-                           priv->real_margin_bottom -
-                           (1 - SEPARATOR_SPACING_FACTOR) * priv->footer_height;
+               gdouble y = compositor->priv->paper_height -
+                           compositor->priv->real_margin_bottom -
+                           (1 - SEPARATOR_SPACING_FACTOR) * compositor->priv->footer_height;
 
                cairo_save (cr);
 
-               cairo_move_to (cr, priv->real_margin_left, y);
+               cairo_move_to (cr, compositor->priv->real_margin_left, y);
                cairo_set_line_width (cr, SEPARATOR_LINE_WIDTH);
-               cairo_line_to (cr, priv->paper_width - priv->real_margin_right, y);
+               cairo_line_to (cr, compositor->priv->paper_width - compositor->priv->real_margin_right, y);
                cairo_stroke (cr);
 
                cairo_restore (cr);
@@ -3138,10 +3041,9 @@ print_footer (GtkSourcePrintCompositor *compositor,
  */
 void
 gtk_source_print_compositor_draw_page (GtkSourcePrintCompositor *compositor,
-                                       GtkPrintContext          *context,
-                                       gint                      page_nr)
+                                      GtkPrintContext          *context,
+                                      gint                      page_nr)
 {
-       GtkSourcePrintCompositorPrivate *priv = gtk_source_print_compositor_get_instance_private (compositor);
        cairo_t *cr;
        GtkTextIter start, end;
        gint offset;
@@ -3151,13 +3053,13 @@ gtk_source_print_compositor_draw_page (GtkSourcePrintCompositor *compositor,
        g_return_if_fail (GTK_IS_PRINT_CONTEXT (context));
        g_return_if_fail (page_nr >= 0);
 
-       priv->current_page = page_nr;
+       compositor->priv->current_page = page_nr;
 
        cr = gtk_print_context_get_cairo_context (context);
        cairo_set_source_rgb (cr, 0, 0, 0);
        cairo_translate (cr,
-                        -1 * priv->page_margin_left,
-                        -1 * priv->page_margin_top);
+                        -1 * compositor->priv->page_margin_left,
+                        -1 * compositor->priv->page_margin_top);
 
        if (is_header_to_print (compositor))
        {
@@ -3179,18 +3081,18 @@ gtk_source_print_compositor_draw_page (GtkSourcePrintCompositor *compositor,
                cairo_set_line_width (cr, 1.);
                cairo_set_source_rgb (cr, 0., 0., 1.);
                cairo_rectangle (cr,
-                                priv->real_margin_left,
-                                priv->real_margin_top,
-                                priv->paper_width -
-                                       priv->real_margin_left - priv->real_margin_right,
-                                priv->paper_height -
-                                       priv->real_margin_top - priv->real_margin_bottom);
+                                compositor->priv->real_margin_left,
+                                compositor->priv->real_margin_top,
+                                compositor->priv->paper_width -
+                                       compositor->priv->real_margin_left - 
compositor->priv->real_margin_right,
+                                compositor->priv->paper_height -
+                                       compositor->priv->real_margin_top - 
compositor->priv->real_margin_bottom);
                cairo_stroke (cr);
 
                cairo_set_source_rgb (cr, 1., 0., 0.);
                cairo_rectangle (cr,
                                 ln_x, y,
-                                priv->line_numbers_width,
+                                compositor->priv->line_numbers_width,
                                 get_text_height (compositor));
                cairo_stroke (cr);
 
@@ -3204,39 +3106,39 @@ gtk_source_print_compositor_draw_page (GtkSourcePrintCompositor *compositor,
                cairo_set_source_rgb (cr, 1., 0., 0.);
                cairo_rectangle (cr,
                                 0, 0,
-                                priv->paper_width,
-                                priv->paper_height);
+                                compositor->priv->paper_width,
+                                compositor->priv->paper_height);
                cairo_stroke (cr);
 
                cairo_restore (cr);
        });
 
-       g_return_if_fail (priv->layout != NULL);
-       pango_cairo_update_layout (cr, priv->layout);
+       g_return_if_fail (compositor->priv->layout != NULL);
+       pango_cairo_update_layout (cr, compositor->priv->layout);
 
-       if (priv->print_line_numbers)
+       if (compositor->priv->print_line_numbers)
        {
-               g_return_if_fail (priv->line_numbers_layout != NULL);
-               pango_cairo_update_layout (cr, priv->line_numbers_layout);
+               g_return_if_fail (compositor->priv->line_numbers_layout != NULL);
+               pango_cairo_update_layout (cr, compositor->priv->line_numbers_layout);
        }
 
-       g_return_if_fail (priv->buffer != NULL);
-       g_return_if_fail (priv->pages != NULL);
-       g_return_if_fail ((guint) page_nr < priv->pages->len);
+       g_return_if_fail (compositor->priv->buffer != NULL);
+       g_return_if_fail (compositor->priv->pages != NULL);
+       g_return_if_fail ((guint) page_nr < compositor->priv->pages->len);
 
-       offset = g_array_index (priv->pages, int, page_nr);
-       gtk_text_buffer_get_iter_at_offset (GTK_TEXT_BUFFER (priv->buffer),
+       offset = g_array_index (compositor->priv->pages, int, page_nr);
+       gtk_text_buffer_get_iter_at_offset (GTK_TEXT_BUFFER (compositor->priv->buffer),
                                            &start, offset);
 
-       if ((guint) page_nr + 1 < priv->pages->len)
+       if ((guint) page_nr + 1 < compositor->priv->pages->len)
        {
-               offset = g_array_index (priv->pages, int, page_nr + 1);
-               gtk_text_buffer_get_iter_at_offset (GTK_TEXT_BUFFER (priv->buffer),
+               offset = g_array_index (compositor->priv->pages, int, page_nr + 1);
+               gtk_text_buffer_get_iter_at_offset (GTK_TEXT_BUFFER (compositor->priv->buffer),
                                                    &end, offset);
        }
        else
        {
-               gtk_text_buffer_get_end_iter (GTK_TEXT_BUFFER (priv->buffer),
+               gtk_text_buffer_get_end_iter (GTK_TEXT_BUFFER (compositor->priv->buffer),
                                              &end);
        }
 
@@ -3268,7 +3170,7 @@ gtk_source_print_compositor_draw_page (GtkSourcePrintCompositor *compositor,
 
                layout_paragraph (compositor, &start, &line_end);
 
-               get_layout_size (priv->layout, NULL, &line_height);
+               get_layout_size (compositor->priv->layout, NULL, &line_height);
 
                baseline_offset = 0;
 
@@ -3282,15 +3184,15 @@ gtk_source_print_compositor_draw_page (GtkSourcePrintCompositor *compositor,
                        gchar *str;
 
                        str = g_strdup_printf ("%d", line_number + 1);
-                       pango_layout_set_text (priv->line_numbers_layout, str, -1);
+                       pango_layout_set_text (compositor->priv->line_numbers_layout, str, -1);
                        g_free (str);
 
                        /* Adjust the baseline */
-                       iter = pango_layout_get_iter (priv->layout);
+                       iter = pango_layout_get_iter (compositor->priv->layout);
                        baseline = (double) pango_layout_iter_get_baseline (iter) / (double) PANGO_SCALE;
                        pango_layout_iter_free (iter);
 
-                       iter = pango_layout_get_iter (priv->line_numbers_layout);
+                       iter = pango_layout_get_iter (compositor->priv->line_numbers_layout);
                        ln_baseline = (double) pango_layout_iter_get_baseline (iter) / (double) PANGO_SCALE;
                        pango_layout_iter_free (iter);
 
@@ -3304,17 +3206,18 @@ gtk_source_print_compositor_draw_page (GtkSourcePrintCompositor *compositor,
 
                        cairo_move_to (cr, ln_x, y + ln_baseline_offset);
 
-                       g_return_if_fail (priv->line_numbers_layout != NULL);
-                       pango_cairo_show_layout (cr, priv->line_numbers_layout);
+                       g_return_if_fail (compositor->priv->line_numbers_layout != NULL);
+                       pango_cairo_show_layout (cr, compositor->priv->line_numbers_layout);
                }
 
                cairo_move_to (cr, x, y + baseline_offset);
-               pango_cairo_show_layout (cr, priv->layout);
+               pango_cairo_show_layout (cr, compositor->priv->layout);
 
                line_height = MAX (line_height,
-                                  priv->line_numbers_height);
+                                  compositor->priv->line_numbers_height);
 
                y += line_height;
                gtk_text_iter_forward_line (&start);
        }
 }
+
diff --git a/gtksourceview/gtksourceprintcompositor.h b/gtksourceview/gtksourceprintcompositor.h
index 059483fd..748db4e3 100644
--- a/gtksourceview/gtksourceprintcompositor.h
+++ b/gtksourceview/gtksourceprintcompositor.h
@@ -2,8 +2,8 @@
  *
  * This file is part of GtkSourceView
  *
- * Copyright 2003  Gustavo Giráldez
- * Copyright 2007-2008  Paolo Maggi, Paolo Borelli and Yevgen Muntyan
+ * Copyright (C) 2003  Gustavo Giráldez
+ * Copyright (C) 2007-2008  Paolo Maggi, Paolo Borelli and Yevgen Muntyan
  *
  * GtkSourceView is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -19,7 +19,8 @@
  * along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#pragma once
+#ifndef GTK_SOURCE_PRINT_COMPOSITOR_H
+#define GTK_SOURCE_PRINT_COMPOSITOR_H
 
 #if !defined (GTK_SOURCE_H_INSIDE) && !defined (GTK_SOURCE_COMPILATION)
 #error "Only <gtksourceview/gtksource.h> can be included directly."
@@ -31,125 +32,193 @@
 
 G_BEGIN_DECLS
 
-#define GTK_SOURCE_TYPE_PRINT_COMPOSITOR (gtk_source_print_compositor_get_type())
+#define GTK_SOURCE_TYPE_PRINT_COMPOSITOR            (gtk_source_print_compositor_get_type ())
+#define GTK_SOURCE_PRINT_COMPOSITOR(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), 
GTK_SOURCE_TYPE_PRINT_COMPOSITOR, GtkSourcePrintCompositor))
+#define GTK_SOURCE_PRINT_COMPOSITOR_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), 
GTK_SOURCE_TYPE_PRINT_COMPOSITOR, GtkSourcePrintCompositorClass))
+#define GTK_SOURCE_IS_PRINT_COMPOSITOR(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), 
GTK_SOURCE_TYPE_PRINT_COMPOSITOR))
+#define GTK_SOURCE_IS_PRINT_COMPOSITOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), 
GTK_SOURCE_TYPE_PRINT_COMPOSITOR))
+#define GTK_SOURCE_PRINT_COMPOSITOR_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), 
GTK_SOURCE_TYPE_PRINT_COMPOSITOR, GtkSourcePrintCompositorClass))
 
-GTK_SOURCE_AVAILABLE_IN_ALL
-G_DECLARE_DERIVABLE_TYPE (GtkSourcePrintCompositor, gtk_source_print_compositor, GTK_SOURCE, 
PRINT_COMPOSITOR, GObject)
+typedef struct _GtkSourcePrintCompositorClass    GtkSourcePrintCompositorClass;
+typedef struct _GtkSourcePrintCompositorPrivate  GtkSourcePrintCompositorPrivate;
+
+struct _GtkSourcePrintCompositor
+{
+       GObject parent_instance;
+
+       GtkSourcePrintCompositorPrivate *priv;
+};
 
 struct _GtkSourcePrintCompositorClass
 {
        GObjectClass parent_class;
 
-       /*< private >*/
-       gpointer _reserved[10];
+       /* Padding for future expansion */
+       gpointer padding[10];
 };
 
 GTK_SOURCE_AVAILABLE_IN_ALL
-GtkSourcePrintCompositor *gtk_source_print_compositor_new                        (GtkSourceBuffer          
*buffer);
+GType                    gtk_source_print_compositor_get_type          (void) G_GNUC_CONST;
+
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-GtkSourcePrintCompositor *gtk_source_print_compositor_new_from_view              (GtkSourceView            
*view);
+GtkSourcePrintCompositor *gtk_source_print_compositor_new              (GtkSourceBuffer          *buffer);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-GtkSourceBuffer          *gtk_source_print_compositor_get_buffer                 (GtkSourcePrintCompositor 
*compositor);
+GtkSourcePrintCompositor *gtk_source_print_compositor_new_from_view    (GtkSourceView            *view);
+
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-void                      gtk_source_print_compositor_set_tab_width              (GtkSourcePrintCompositor 
*compositor,
-                                                                                  guint                     
width);
+GtkSourceBuffer         *gtk_source_print_compositor_get_buffer        (GtkSourcePrintCompositor 
*compositor);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-guint                     gtk_source_print_compositor_get_tab_width              (GtkSourcePrintCompositor 
*compositor);
+void                     gtk_source_print_compositor_set_tab_width     (GtkSourcePrintCompositor *compositor,
+                                                                        guint                     width);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-void                      gtk_source_print_compositor_set_wrap_mode              (GtkSourcePrintCompositor 
*compositor,
-                                                                                  GtkWrapMode               
wrap_mode);
+guint                    gtk_source_print_compositor_get_tab_width     (GtkSourcePrintCompositor 
*compositor);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-GtkWrapMode               gtk_source_print_compositor_get_wrap_mode              (GtkSourcePrintCompositor 
*compositor);
+void                     gtk_source_print_compositor_set_wrap_mode     (GtkSourcePrintCompositor *compositor,
+                                                                        GtkWrapMode               wrap_mode);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-void                      gtk_source_print_compositor_set_highlight_syntax       (GtkSourcePrintCompositor 
*compositor,
-                                                                                  gboolean                  
highlight);
+GtkWrapMode              gtk_source_print_compositor_get_wrap_mode     (GtkSourcePrintCompositor 
*compositor);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-gboolean                  gtk_source_print_compositor_get_highlight_syntax       (GtkSourcePrintCompositor 
*compositor);
+void                     gtk_source_print_compositor_set_highlight_syntax
+                                                                       (GtkSourcePrintCompositor *compositor,
+                                                                        gboolean                  highlight);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-void                      gtk_source_print_compositor_set_print_line_numbers     (GtkSourcePrintCompositor 
*compositor,
-                                                                                  guint                     
interval);
+gboolean                 gtk_source_print_compositor_get_highlight_syntax
+                                                                       (GtkSourcePrintCompositor 
*compositor);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-guint                     gtk_source_print_compositor_get_print_line_numbers     (GtkSourcePrintCompositor 
*compositor);
+void                     gtk_source_print_compositor_set_print_line_numbers
+                                                                       (GtkSourcePrintCompositor *compositor,
+                                                                        guint                     interval);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-void                      gtk_source_print_compositor_set_body_font_name         (GtkSourcePrintCompositor 
*compositor,
-                                                                                  const gchar              
*font_name);
+guint                    gtk_source_print_compositor_get_print_line_numbers
+                                                                       (GtkSourcePrintCompositor 
*compositor);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-gchar                    *gtk_source_print_compositor_get_body_font_name         (GtkSourcePrintCompositor 
*compositor);
+void                     gtk_source_print_compositor_set_body_font_name
+                                                                       (GtkSourcePrintCompositor *compositor,
+                                                                        const gchar              *font_name);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-void                      gtk_source_print_compositor_set_line_numbers_font_name (GtkSourcePrintCompositor 
*compositor,
-                                                                                  const gchar              
*font_name);
+gchar                   *gtk_source_print_compositor_get_body_font_name
+                                                                       (GtkSourcePrintCompositor 
*compositor);
+
+GTK_SOURCE_AVAILABLE_IN_ALL
+void                     gtk_source_print_compositor_set_line_numbers_font_name
+                                                                       (GtkSourcePrintCompositor *compositor,
+                                                                        const gchar              *font_name);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-gchar                    *gtk_source_print_compositor_get_line_numbers_font_name (GtkSourcePrintCompositor 
*compositor);
+gchar                   *gtk_source_print_compositor_get_line_numbers_font_name
+                                                                       (GtkSourcePrintCompositor 
*compositor);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-void                      gtk_source_print_compositor_set_header_font_name       (GtkSourcePrintCompositor 
*compositor,
-                                                                                  const gchar              
*font_name);
+void                     gtk_source_print_compositor_set_header_font_name
+                                                                       (GtkSourcePrintCompositor *compositor,
+                                                                        const gchar              *font_name);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-gchar                    *gtk_source_print_compositor_get_header_font_name       (GtkSourcePrintCompositor 
*compositor);
+gchar                   *gtk_source_print_compositor_get_header_font_name
+                                                                       (GtkSourcePrintCompositor 
*compositor);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-void                      gtk_source_print_compositor_set_footer_font_name       (GtkSourcePrintCompositor 
*compositor,
-                                                                                  const gchar              
*font_name);
+void                     gtk_source_print_compositor_set_footer_font_name
+                                                                       (GtkSourcePrintCompositor *compositor,
+                                                                        const gchar              *font_name);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-gchar                    *gtk_source_print_compositor_get_footer_font_name       (GtkSourcePrintCompositor 
*compositor);
+gchar                   *gtk_source_print_compositor_get_footer_font_name
+                                                                       (GtkSourcePrintCompositor 
*compositor);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-gdouble                   gtk_source_print_compositor_get_top_margin             (GtkSourcePrintCompositor 
*compositor,
-                                                                                  GtkUnit                   
unit);
+gdouble                          gtk_source_print_compositor_get_top_margin    (GtkSourcePrintCompositor 
*compositor,
+                                                                        GtkUnit                   unit);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-void                      gtk_source_print_compositor_set_top_margin             (GtkSourcePrintCompositor 
*compositor,
-                                                                                  gdouble                   
margin,
-                                                                                  GtkUnit                   
unit);
+void                     gtk_source_print_compositor_set_top_margin    (GtkSourcePrintCompositor *compositor,
+                                                                        gdouble                   margin,
+                                                                        GtkUnit                   unit);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-gdouble                   gtk_source_print_compositor_get_bottom_margin          (GtkSourcePrintCompositor 
*compositor,
-                                                                                  GtkUnit                   
unit);
+gdouble                          gtk_source_print_compositor_get_bottom_margin (GtkSourcePrintCompositor 
*compositor,
+                                                                        GtkUnit                   unit);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-void                      gtk_source_print_compositor_set_bottom_margin          (GtkSourcePrintCompositor 
*compositor,
-                                                                                  gdouble                   
margin,
-                                                                                  GtkUnit                   
unit);
+void                     gtk_source_print_compositor_set_bottom_margin (GtkSourcePrintCompositor *compositor,
+                                                                        gdouble                   margin,
+                                                                        GtkUnit                   unit);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-gdouble                   gtk_source_print_compositor_get_left_margin            (GtkSourcePrintCompositor 
*compositor,
-                                                                                  GtkUnit                   
unit);
+gdouble                          gtk_source_print_compositor_get_left_margin   (GtkSourcePrintCompositor 
*compositor,
+                                                                        GtkUnit                   unit);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-void                      gtk_source_print_compositor_set_left_margin            (GtkSourcePrintCompositor 
*compositor,
-                                                                                  gdouble                   
margin,
-                                                                                  GtkUnit                   
unit);
+void                     gtk_source_print_compositor_set_left_margin   (GtkSourcePrintCompositor *compositor,
+                                                                        gdouble                   margin,
+                                                                        GtkUnit                   unit);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-gdouble                   gtk_source_print_compositor_get_right_margin           (GtkSourcePrintCompositor 
*compositor,
-                                                                                  GtkUnit                   
unit);
+gdouble                          gtk_source_print_compositor_get_right_margin  (GtkSourcePrintCompositor 
*compositor,
+                                                                        GtkUnit                   unit);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-void                      gtk_source_print_compositor_set_right_margin           (GtkSourcePrintCompositor 
*compositor,
-                                                                                  gdouble                   
margin,
-                                                                                  GtkUnit                   
unit);
+void                     gtk_source_print_compositor_set_right_margin  (GtkSourcePrintCompositor *compositor,
+                                                                        gdouble                   margin,
+                                                                        GtkUnit                   unit);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-void                      gtk_source_print_compositor_set_print_header           (GtkSourcePrintCompositor 
*compositor,
-                                                                                  gboolean                  
print);
+void                     gtk_source_print_compositor_set_print_header  (GtkSourcePrintCompositor *compositor,
+                                                                        gboolean                  print);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-gboolean                  gtk_source_print_compositor_get_print_header           (GtkSourcePrintCompositor 
*compositor);
+gboolean                 gtk_source_print_compositor_get_print_header  (GtkSourcePrintCompositor 
*compositor);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-void                      gtk_source_print_compositor_set_print_footer           (GtkSourcePrintCompositor 
*compositor,
-                                                                                  gboolean                  
print);
+void                     gtk_source_print_compositor_set_print_footer  (GtkSourcePrintCompositor *compositor,
+                                                                        gboolean                  print);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-gboolean                  gtk_source_print_compositor_get_print_footer           (GtkSourcePrintCompositor 
*compositor);
+gboolean                 gtk_source_print_compositor_get_print_footer  (GtkSourcePrintCompositor 
*compositor);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-void                      gtk_source_print_compositor_set_header_format          (GtkSourcePrintCompositor 
*compositor,
-                                                                                  gboolean                  
separator,
-                                                                                  const gchar              
*left,
-                                                                                  const gchar              
*center,
-                                                                                  const gchar              
*right);
+void                     gtk_source_print_compositor_set_header_format (GtkSourcePrintCompositor *compositor,
+                                                                        gboolean                  separator,
+                                                                        const gchar              *left,
+                                                                        const gchar              *center,
+                                                                        const gchar              *right);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-void                      gtk_source_print_compositor_set_footer_format          (GtkSourcePrintCompositor 
*compositor,
-                                                                                  gboolean                  
separator,
-                                                                                  const gchar              
*left,
-                                                                                  const gchar              
*center,
-                                                                                  const gchar              
*right);
+void                     gtk_source_print_compositor_set_footer_format (GtkSourcePrintCompositor *compositor,
+                                                                        gboolean                  separator,
+                                                                        const gchar              *left,
+                                                                        const gchar              *center,
+                                                                        const gchar              *right);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-gint                      gtk_source_print_compositor_get_n_pages                (GtkSourcePrintCompositor 
*compositor);
+gint                     gtk_source_print_compositor_get_n_pages       (GtkSourcePrintCompositor 
*compositor);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-gboolean                  gtk_source_print_compositor_paginate                   (GtkSourcePrintCompositor 
*compositor,
-                                                                                  GtkPrintContext          
*context);
+gboolean                 gtk_source_print_compositor_paginate          (GtkSourcePrintCompositor *compositor,
+                                                                        GtkPrintContext          *context);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-gdouble                   gtk_source_print_compositor_get_pagination_progress    (GtkSourcePrintCompositor 
*compositor);
+gdouble                          gtk_source_print_compositor_get_pagination_progress
+                                                                       (GtkSourcePrintCompositor 
*compositor);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-void                      gtk_source_print_compositor_draw_page                  (GtkSourcePrintCompositor 
*compositor,
-                                                                                  GtkPrintContext          
*context,
-                                                                                  gint                      
page_nr);
+void                     gtk_source_print_compositor_draw_page         (GtkSourcePrintCompositor *compositor,
+                                                                        GtkPrintContext          *context,
+                                                                        gint                      page_nr);
 
 G_END_DECLS
+
+#endif /* GTK_SOURCE_PRINT_COMPOSITOR_H */
diff --git a/gtksourceview/gtksourceregex.c b/gtksourceview/gtksourceregex.c
index 691b9dfd..77570837 100644
--- a/gtksourceview/gtksourceregex.c
+++ b/gtksourceview/gtksourceregex.c
@@ -2,8 +2,8 @@
  *
  * This file is part of GtkSourceView
  *
- * Copyright 2003 - Gustavo Giráldez <gustavo giraldez gmx net>
- * Copyright 2005, 2006 - Marco Barisione, Emanuele Aina
+ * Copyright (C) 2003 - Gustavo Giráldez <gustavo giraldez gmx net>
+ * Copyright (C) 2005, 2006 - Marco Barisione, Emanuele Aina
  *
  * GtkSourceView is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -19,13 +19,14 @@
  * along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "config.h"
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
 
+#include "gtksourceregex.h"
 #include <string.h>
 #include <glib.h>
 #include <glib/gi18n-lib.h>
-
-#include "gtksourceregex-private.h"
 #include "gtksourceutils-private.h"
 
 /*
diff --git a/gtksourceview/gtksourceregex.h b/gtksourceview/gtksourceregex.h
new file mode 100644
index 00000000..c4f5e2ad
--- /dev/null
+++ b/gtksourceview/gtksourceregex.h
@@ -0,0 +1,85 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; coding: utf-8 -*-
+ *
+ * This file is part of GtkSourceView
+ *
+ * Copyright (C) 2003 - Gustavo Giráldez <gustavo giraldez gmx net>
+ * Copyright (C) 2005, 2006 - Marco Barisione, Emanuele Aina
+ *
+ * GtkSourceView is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * GtkSourceView is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GTK_SOURCE_REGEX_H
+#define GTK_SOURCE_REGEX_H
+
+#include <glib.h>
+
+#include "gtksourcetypes-private.h"
+
+G_BEGIN_DECLS
+
+GTK_SOURCE_INTERNAL
+GtkSourceRegex *_gtk_source_regex_new          (const gchar         *pattern,
+                                                GRegexCompileFlags   flags,
+                                                GError             **error);
+
+GTK_SOURCE_INTERNAL
+GtkSourceRegex *_gtk_source_regex_ref          (GtkSourceRegex *regex);
+
+GTK_SOURCE_INTERNAL
+void            _gtk_source_regex_unref        (GtkSourceRegex *regex);
+
+GTK_SOURCE_INTERNAL
+GtkSourceRegex *_gtk_source_regex_resolve      (GtkSourceRegex *regex,
+                                                GtkSourceRegex *start_regex,
+                                                const gchar    *matched_text);
+
+GTK_SOURCE_INTERNAL
+gboolean        _gtk_source_regex_is_resolved  (GtkSourceRegex *regex);
+
+GTK_SOURCE_INTERNAL
+gboolean       _gtk_source_regex_match         (GtkSourceRegex *regex,
+                                                const gchar    *line,
+                                                gint             byte_length,
+                                                gint             byte_pos);
+
+GTK_SOURCE_INTERNAL
+gchar          *_gtk_source_regex_fetch        (GtkSourceRegex *regex,
+                                                gint            num);
+
+GTK_SOURCE_INTERNAL
+void            _gtk_source_regex_fetch_pos    (GtkSourceRegex *regex,
+                                                const gchar    *text,
+                                                gint            num,
+                                                gint           *start_pos, /* character offsets */
+                                                gint           *end_pos);  /* character offsets */
+
+GTK_SOURCE_INTERNAL
+void            _gtk_source_regex_fetch_pos_bytes (GtkSourceRegex *regex,
+                                                   gint            num,
+                                                   gint           *start_pos_p, /* byte offsets */
+                                                   gint           *end_pos_p);  /* byte offsets */
+
+GTK_SOURCE_INTERNAL
+void            _gtk_source_regex_fetch_named_pos (GtkSourceRegex *regex,
+                                                   const gchar    *text,
+                                                   const gchar    *name,
+                                                   gint           *start_pos, /* character offsets */
+                                                   gint           *end_pos);  /* character offsets */
+
+GTK_SOURCE_INTERNAL
+const gchar    *_gtk_source_regex_get_pattern  (GtkSourceRegex *regex);
+
+G_END_DECLS
+
+#endif /* GTK_SOURCE_REGEX_H */
diff --git a/gtksourceview/gtksourceregion.c b/gtksourceview/gtksourceregion.c
index c2ee094c..c8b58244 100644
--- a/gtksourceview/gtksourceregion.c
+++ b/gtksourceview/gtksourceregion.c
@@ -2,8 +2,8 @@
  * gtksourceregion.c - GtkTextMark-based region utility
  * This file is part of GtkSourceView
  *
- * Copyright 2002 Gustavo Giráldez <gustavo giraldez gmx net>
- * Copyright 2016 Sébastien Wilmet <swilmet gnome org>
+ * Copyright (C) 2002 Gustavo Giráldez <gustavo giraldez gmx net>
+ * Copyright (C) 2016 Sébastien Wilmet <swilmet gnome org>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -19,7 +19,9 @@
  * along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "config.h"
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
 
 #include "gtksourceregion.h"
 
diff --git a/gtksourceview/gtksourceregion.h b/gtksourceview/gtksourceregion.h
index 757fe513..25d67612 100644
--- a/gtksourceview/gtksourceregion.h
+++ b/gtksourceview/gtksourceregion.h
@@ -2,8 +2,8 @@
  * gtksourceregion.h - GtkTextMark-based region utility
  * This file is part of GtkSourceView
  *
- * Copyright 2002 Gustavo Giráldez <gustavo giraldez gmx net>
- * Copyright 2016 Sébastien Wilmet <swilmet gnome org>
+ * Copyright (C) 2002 Gustavo Giráldez <gustavo giraldez gmx net>
+ * Copyright (C) 2016 Sébastien Wilmet <swilmet gnome org>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -19,7 +19,8 @@
  * along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#pragma once
+#ifndef GTK_SOURCE_REGION_H
+#define GTK_SOURCE_REGION_H
 
 #if !defined (GTK_SOURCE_H_INSIDE) && !defined (GTK_SOURCE_COMPILATION)
 #error "Only <gtksourceview/gtksource.h> can be included directly."
@@ -34,14 +35,16 @@ G_BEGIN_DECLS
 #define GTK_SOURCE_TYPE_REGION (gtk_source_region_get_type ())
 
 GTK_SOURCE_AVAILABLE_IN_3_22
-G_DECLARE_DERIVABLE_TYPE (GtkSourceRegion, gtk_source_region, GTK_SOURCE, REGION, GObject)
+G_DECLARE_DERIVABLE_TYPE (GtkSourceRegion, gtk_source_region,
+                         GTK_SOURCE, REGION,
+                         GObject)
 
 struct _GtkSourceRegionClass
 {
        GObjectClass parent_class;
 
-       /*< private >*/
-       gpointer _reserved[10];
+       /* Padding for future expansion */
+       gpointer padding[10];
 };
 
 /**
@@ -62,48 +65,64 @@ struct _GtkSourceRegionIter
 };
 
 GTK_SOURCE_AVAILABLE_IN_3_22
-GtkSourceRegion *gtk_source_region_new                   (GtkTextBuffer       *buffer);
+GtkSourceRegion *      gtk_source_region_new                   (GtkTextBuffer *buffer);
+
 GTK_SOURCE_AVAILABLE_IN_3_22
-GtkTextBuffer   *gtk_source_region_get_buffer            (GtkSourceRegion     *region);
+GtkTextBuffer *                gtk_source_region_get_buffer            (GtkSourceRegion *region);
+
 GTK_SOURCE_AVAILABLE_IN_3_22
-void             gtk_source_region_add_subregion         (GtkSourceRegion     *region,
-                                                          const GtkTextIter   *_start,
-                                                          const GtkTextIter   *_end);
+void                   gtk_source_region_add_subregion         (GtkSourceRegion   *region,
+                                                                const GtkTextIter *_start,
+                                                                const GtkTextIter *_end);
+
 GTK_SOURCE_AVAILABLE_IN_3_22
-void             gtk_source_region_add_region            (GtkSourceRegion     *region,
-                                                          GtkSourceRegion     *region_to_add);
+void                   gtk_source_region_add_region            (GtkSourceRegion *region,
+                                                                GtkSourceRegion *region_to_add);
+
 GTK_SOURCE_AVAILABLE_IN_3_22
-void             gtk_source_region_subtract_subregion    (GtkSourceRegion     *region,
-                                                          const GtkTextIter   *_start,
-                                                          const GtkTextIter   *_end);
+void                   gtk_source_region_subtract_subregion    (GtkSourceRegion   *region,
+                                                                const GtkTextIter *_start,
+                                                                const GtkTextIter *_end);
+
 GTK_SOURCE_AVAILABLE_IN_3_22
-void             gtk_source_region_subtract_region       (GtkSourceRegion     *region,
-                                                          GtkSourceRegion     *region_to_subtract);
+void                   gtk_source_region_subtract_region       (GtkSourceRegion *region,
+                                                                GtkSourceRegion *region_to_subtract);
+
 GTK_SOURCE_AVAILABLE_IN_3_22
-GtkSourceRegion *gtk_source_region_intersect_subregion   (GtkSourceRegion     *region,
-                                                          const GtkTextIter   *_start,
-                                                          const GtkTextIter   *_end);
+GtkSourceRegion *      gtk_source_region_intersect_subregion   (GtkSourceRegion   *region,
+                                                                const GtkTextIter *_start,
+                                                                const GtkTextIter *_end);
+
 GTK_SOURCE_AVAILABLE_IN_3_22
-GtkSourceRegion *gtk_source_region_intersect_region      (GtkSourceRegion     *region1,
-                                                          GtkSourceRegion     *region2);
+GtkSourceRegion *      gtk_source_region_intersect_region      (GtkSourceRegion *region1,
+                                                                GtkSourceRegion *region2);
+
 GTK_SOURCE_AVAILABLE_IN_3_22
-gboolean         gtk_source_region_is_empty              (GtkSourceRegion     *region);
+gboolean               gtk_source_region_is_empty              (GtkSourceRegion *region);
+
 GTK_SOURCE_AVAILABLE_IN_3_22
-gboolean         gtk_source_region_get_bounds            (GtkSourceRegion     *region,
-                                                          GtkTextIter         *start,
-                                                          GtkTextIter         *end);
+gboolean               gtk_source_region_get_bounds            (GtkSourceRegion *region,
+                                                                GtkTextIter     *start,
+                                                                GtkTextIter     *end);
+
 GTK_SOURCE_AVAILABLE_IN_3_22
-void             gtk_source_region_get_start_region_iter (GtkSourceRegion     *region,
-                                                          GtkSourceRegionIter *iter);
+void                   gtk_source_region_get_start_region_iter (GtkSourceRegion     *region,
+                                                                GtkSourceRegionIter *iter);
+
 GTK_SOURCE_AVAILABLE_IN_3_22
-gboolean         gtk_source_region_iter_is_end           (GtkSourceRegionIter *iter);
+gboolean               gtk_source_region_iter_is_end           (GtkSourceRegionIter *iter);
+
 GTK_SOURCE_AVAILABLE_IN_3_22
-gboolean         gtk_source_region_iter_next             (GtkSourceRegionIter *iter);
+gboolean               gtk_source_region_iter_next             (GtkSourceRegionIter *iter);
+
 GTK_SOURCE_AVAILABLE_IN_3_22
-gboolean         gtk_source_region_iter_get_subregion    (GtkSourceRegionIter *iter,
-                                                          GtkTextIter         *start,
-                                                          GtkTextIter         *end);
+gboolean               gtk_source_region_iter_get_subregion    (GtkSourceRegionIter *iter,
+                                                                GtkTextIter         *start,
+                                                                GtkTextIter         *end);
+
 GTK_SOURCE_AVAILABLE_IN_3_22
-gchar           *gtk_source_region_to_string             (GtkSourceRegion     *region);
+gchar *                        gtk_source_region_to_string             (GtkSourceRegion *region);
 
 G_END_DECLS
+
+#endif /* GTK_SOURCE_REGION_H */
diff --git a/gtksourceview/gtksourcesearchcontext-private.h b/gtksourceview/gtksourcesearchcontext-private.h
index 2838a1b7..8088ba9e 100644
--- a/gtksourceview/gtksourcesearchcontext-private.h
+++ b/gtksourceview/gtksourcesearchcontext-private.h
@@ -2,7 +2,7 @@
  *
  * This file is part of GtkSourceView
  *
- * Copyright 2013, 2016 - Sébastien Wilmet <swilmet gnome org>
+ * Copyright (C) 2013, 2016 - Sébastien Wilmet <swilmet gnome org>
  *
  * GtkSourceView is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -18,7 +18,8 @@
  * along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#pragma once
+#ifndef GTK_SOURCE_SEARCH_CONTEXT_PRIVATE_H
+#define GTK_SOURCE_SEARCH_CONTEXT_PRIVATE_H
 
 #include "gtksourcesearchcontext.h"
 
@@ -31,3 +32,5 @@ void _gtk_source_search_context_update_highlight (GtkSourceSearchContext *search
                                                   gboolean                synchronous);
 
 G_END_DECLS
+
+#endif /* GTK_SOURCE_SEARCH_CONTEXT_PRIVATE_H */
diff --git a/gtksourceview/gtksourcesearchcontext.c b/gtksourceview/gtksourcesearchcontext.c
index 8417a12c..6e02108e 100644
--- a/gtksourceview/gtksourcesearchcontext.c
+++ b/gtksourceview/gtksourcesearchcontext.c
@@ -2,7 +2,7 @@
 /*
  * This file is part of GtkSourceView
  *
- * Copyright 2013-2016 - Sébastien Wilmet <swilmet gnome org>
+ * Copyright (C) 2013-2016 - Sébastien Wilmet <swilmet gnome org>
  *
  * GtkSourceView is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -18,10 +18,13 @@
  * along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "config.h"
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
 
 #include <string.h>
 
+#include "gtksourcesearchcontext.h"
 #include "gtksourcesearchcontext-private.h"
 #include "gtksourcesearchsettings.h"
 #include "gtksourcebuffer.h"
@@ -31,7 +34,7 @@
 #include "gtksourcestylescheme.h"
 #include "gtksourceutils.h"
 #include "gtksourceregion.h"
-#include "gtksourceiter-private.h"
+#include "gtksourceiter.h"
 #include "gtksource-enumtypes.h"
 
 /**
@@ -302,10 +305,8 @@ enum
        PROP_REGEX_ERROR
 };
 
-struct _GtkSourceSearchContext
+struct _GtkSourceSearchContextPrivate
 {
-       GObject parent_instance;
-
        /* Weak ref to the buffer. The buffer has also a weak ref to the search
         * context. A strong ref in either direction would prevent the pointed
         * object to be finalized.
@@ -367,9 +368,9 @@ typedef struct
        guint is_forward : 1;
 } ForwardBackwardData;
 
-G_DEFINE_TYPE (GtkSourceSearchContext, gtk_source_search_context, G_TYPE_OBJECT)
+G_DEFINE_TYPE_WITH_PRIVATE (GtkSourceSearchContext, gtk_source_search_context, G_TYPE_OBJECT);
 
-static void install_idle_scan (GtkSourceSearchContext *search);
+static void            install_idle_scan               (GtkSourceSearchContext *search);
 
 #ifdef ENABLE_DEBUG
 static void
@@ -386,23 +387,23 @@ print_region (GtkSourceRegion *region)
 static void
 sync_found_tag (GtkSourceSearchContext *search)
 {
-       GtkSourceStyle *style = search->match_style;
+       GtkSourceStyle *style = search->priv->match_style;
        GtkSourceStyleScheme *style_scheme;
 
-       if (search->buffer == NULL)
+       if (search->priv->buffer == NULL)
        {
                return;
        }
 
-       if (!search->highlight)
+       if (!search->priv->highlight)
        {
-               gtk_source_style_apply (NULL, search->found_tag);
+               gtk_source_style_apply (NULL, search->priv->found_tag);
                return;
        }
 
        if (style == NULL)
        {
-               style_scheme = gtk_source_buffer_get_style_scheme (GTK_SOURCE_BUFFER (search->buffer));
+               style_scheme = gtk_source_buffer_get_style_scheme (GTK_SOURCE_BUFFER (search->priv->buffer));
 
                if (style_scheme != NULL)
                {
@@ -415,12 +416,12 @@ sync_found_tag (GtkSourceSearchContext *search)
                g_warning ("No match style defined nor 'search-match' style available.");
        }
 
-       gtk_source_style_apply (style, search->found_tag);
+       gtk_source_style_apply (style, search->priv->found_tag);
 }
 
 static void
 text_tag_set_highest_priority (GtkTextTag    *tag,
-                               GtkTextBuffer *buffer)
+                              GtkTextBuffer *buffer)
 {
        GtkTextTagTable *table;
        gint n;
@@ -435,8 +436,8 @@ text_tag_set_highest_priority (GtkTextTag    *tag,
  */
 static gboolean
 get_first_subregion (GtkSourceRegion *region,
-                     GtkTextIter     *start,
-                     GtkTextIter     *end)
+                    GtkTextIter     *start,
+                    GtkTextIter     *end)
 {
        GtkSourceRegionIter region_iter;
 
@@ -470,8 +471,8 @@ get_first_subregion (GtkSourceRegion *region,
  */
 static gboolean
 get_last_subregion (GtkSourceRegion *region,
-                    GtkTextIter     *start,
-                    GtkTextIter     *end)
+                   GtkTextIter     *start,
+                   GtkTextIter     *end)
 {
        GtkSourceRegionIter region_iter;
        gboolean found = FALSE;
@@ -511,43 +512,43 @@ get_last_subregion (GtkSourceRegion *region,
 static void
 clear_task (GtkSourceSearchContext *search)
 {
-       g_clear_object (&search->task_region);
+       g_clear_object (&search->priv->task_region);
 
-       if (search->task != NULL)
+       if (search->priv->task != NULL)
        {
-               GCancellable *cancellable = g_task_get_cancellable (search->task);
+               GCancellable *cancellable = g_task_get_cancellable (search->priv->task);
 
                if (cancellable != NULL)
                {
                        g_cancellable_cancel (cancellable);
-                       g_task_return_error_if_cancelled (search->task);
+                       g_task_return_error_if_cancelled (search->priv->task);
                }
 
-               g_clear_object (&search->task);
+               g_clear_object (&search->priv->task);
        }
 }
 
 static void
 clear_search (GtkSourceSearchContext *search)
 {
-       g_clear_object (&search->scan_region);
-       g_clear_object (&search->high_priority_region);
+       g_clear_object (&search->priv->scan_region);
+       g_clear_object (&search->priv->high_priority_region);
 
-       if (search->idle_scan_id != 0)
+       if (search->priv->idle_scan_id != 0)
        {
-               g_source_remove (search->idle_scan_id);
-               search->idle_scan_id = 0;
+               g_source_remove (search->priv->idle_scan_id);
+               search->priv->idle_scan_id = 0;
        }
 
-       if (search->regex_error != NULL)
+       if (search->priv->regex_error != NULL)
        {
-               g_clear_error (&search->regex_error);
+               g_clear_error (&search->priv->regex_error);
                g_object_notify (G_OBJECT (search), "regex-error");
        }
 
        clear_task (search);
 
-       search->occurrences_count = 0;
+       search->priv->occurrences_count = 0;
 }
 
 static GtkTextSearchFlags
@@ -555,7 +556,7 @@ get_text_search_flags (GtkSourceSearchContext *search)
 {
        GtkTextSearchFlags flags = GTK_TEXT_SEARCH_TEXT_ONLY | GTK_TEXT_SEARCH_VISIBLE_ONLY;
 
-       if (!gtk_source_search_settings_get_case_sensitive (search->settings))
+       if (!gtk_source_search_settings_get_case_sensitive (search->priv->settings))
        {
                flags |= GTK_TEXT_SEARCH_CASE_INSENSITIVE;
        }
@@ -566,11 +567,11 @@ get_text_search_flags (GtkSourceSearchContext *search)
 /* @start_pos is in bytes. */
 static void
 regex_search_get_real_start (GtkSourceSearchContext *search,
-                             const GtkTextIter      *start,
-                             GtkTextIter            *real_start,
-                             gint                   *start_pos)
+                            const GtkTextIter      *start,
+                            GtkTextIter            *real_start,
+                            gint                   *start_pos)
 {
-       gint max_lookbehind = g_regex_get_max_lookbehind (search->regex);
+       gint max_lookbehind = g_regex_get_max_lookbehind (search->priv->regex);
        gint i;
        gchar *text;
 
@@ -592,7 +593,7 @@ regex_search_get_real_start (GtkSourceSearchContext *search,
 
 static GRegexMatchFlags
 regex_search_get_match_options (const GtkTextIter *real_start,
-                                const GtkTextIter *end)
+                               const GtkTextIter *end)
 {
        GRegexMatchFlags match_options = 0;
 
@@ -623,12 +624,12 @@ regex_search_get_match_options (const GtkTextIter *real_start,
  */
 static gboolean
 regex_search_fetch_match (GMatchInfo  *match_info,
-                          const gchar *subject,
-                          gssize       subject_length,
-                          GtkTextIter *iter,
-                          gint        *iter_byte_pos,
-                          GtkTextIter *match_start,
-                          GtkTextIter *match_end)
+                         const gchar *subject,
+                         gssize       subject_length,
+                         GtkTextIter *iter,
+                         gint        *iter_byte_pos,
+                         GtkTextIter *match_start,
+                         GtkTextIter *match_end)
 {
        gint start_byte_pos;
        gint end_byte_pos;
@@ -682,11 +683,11 @@ regex_search_fetch_match (GMatchInfo  *match_info,
  */
 static gboolean
 basic_forward_regex_search (GtkSourceSearchContext *search,
-                            const GtkTextIter      *start_at,
-                            GtkTextIter            *match_start,
-                            GtkTextIter            *match_end,
-                            GtkTextIter            *real_end,
-                            const GtkTextIter      *limit)
+                           const GtkTextIter      *start_at,
+                           GtkTextIter            *match_start,
+                           GtkTextIter            *match_end,
+                           GtkTextIter            *real_end,
+                           const GtkTextIter      *limit)
 {
        GtkTextIter real_start;
        GtkTextIter end;
@@ -694,8 +695,8 @@ basic_forward_regex_search (GtkSourceSearchContext *search,
        gboolean found = FALSE;
        gint nb_lines = 1;
 
-       if (search->regex == NULL ||
-           search->regex_error != NULL)
+       if (search->priv->regex == NULL ||
+           search->priv->regex_error != NULL)
        {
                return FALSE;
        }
@@ -704,7 +705,7 @@ basic_forward_regex_search (GtkSourceSearchContext *search,
 
        if (limit == NULL)
        {
-               gtk_text_buffer_get_end_iter (search->buffer, &end);
+               gtk_text_buffer_get_end_iter (search->priv->buffer, &end);
        }
        else
        {
@@ -726,13 +727,13 @@ basic_forward_regex_search (GtkSourceSearchContext *search,
                subject = gtk_text_iter_get_visible_text (&real_start, &end);
                subject_length = strlen (subject);
 
-               g_regex_match_full (search->regex,
+               g_regex_match_full (search->priv->regex,
                                    subject,
                                    subject_length,
                                    start_pos,
                                    match_options,
                                    &match_info,
-                                   &search->regex_error);
+                                   &search->priv->regex_error);
 
                iter = real_start;
                iter_byte_pos = 0;
@@ -765,7 +766,7 @@ basic_forward_regex_search (GtkSourceSearchContext *search,
                        found = FALSE;
                }
 
-               if (search->regex_error != NULL)
+               if (search->priv->regex_error != NULL)
                {
                        g_object_notify (G_OBJECT (search), "regex-error");
                        found = FALSE;
@@ -799,13 +800,13 @@ basic_forward_regex_search (GtkSourceSearchContext *search,
 
 static gboolean
 basic_forward_search (GtkSourceSearchContext *search,
-                      const GtkTextIter      *iter,
-                      GtkTextIter            *match_start,
-                      GtkTextIter            *match_end,
-                      const GtkTextIter      *limit)
+                     const GtkTextIter      *iter,
+                     GtkTextIter            *match_start,
+                     GtkTextIter            *match_end,
+                     const GtkTextIter      *limit)
 {
        GtkTextIter begin_search = *iter;
-       const gchar *search_text = gtk_source_search_settings_get_search_text (search->settings);
+       const gchar *search_text = gtk_source_search_settings_get_search_text (search->priv->settings);
        GtkTextSearchFlags flags;
 
        if (search_text == NULL)
@@ -813,7 +814,7 @@ basic_forward_search (GtkSourceSearchContext *search,
                return FALSE;
        }
 
-       if (gtk_source_search_settings_get_regex_enabled (search->settings))
+       if (gtk_source_search_settings_get_regex_enabled (search->priv->settings))
        {
                return basic_forward_regex_search (search,
                                                   iter,
@@ -834,7 +835,7 @@ basic_forward_search (GtkSourceSearchContext *search,
                                                               match_end,
                                                               limit);
 
-               if (!found || !gtk_source_search_settings_get_at_word_boundaries (search->settings))
+               if (!found || !gtk_source_search_settings_get_at_word_boundaries (search->priv->settings))
                {
                        return found;
                }
@@ -854,25 +855,25 @@ basic_forward_search (GtkSourceSearchContext *search,
  */
 static gboolean
 basic_backward_regex_search (GtkSourceSearchContext *search,
-                             const GtkTextIter      *start_at,
-                             GtkTextIter            *match_start,
-                             GtkTextIter            *match_end,
-                             const GtkTextIter      *limit)
+                            const GtkTextIter      *start_at,
+                            GtkTextIter            *match_start,
+                            GtkTextIter            *match_end,
+                            const GtkTextIter      *limit)
 {
        GtkTextIter lower_bound;
        GtkTextIter m_start;
        GtkTextIter m_end;
        gboolean found = FALSE;
 
-       if (search->regex == NULL ||
-           search->regex_error != NULL)
+       if (search->priv->regex == NULL ||
+           search->priv->regex_error != NULL)
        {
                return FALSE;
        }
 
        if (limit == NULL)
        {
-               gtk_text_buffer_get_start_iter (search->buffer, &lower_bound);
+               gtk_text_buffer_get_start_iter (search->priv->buffer, &lower_bound);
        }
        else
        {
@@ -901,13 +902,13 @@ basic_backward_regex_search (GtkSourceSearchContext *search,
 
 static gboolean
 basic_backward_search (GtkSourceSearchContext *search,
-                       const GtkTextIter      *iter,
-                       GtkTextIter            *match_start,
-                       GtkTextIter            *match_end,
-                       const GtkTextIter      *limit)
+                      const GtkTextIter      *iter,
+                      GtkTextIter            *match_start,
+                      GtkTextIter            *match_end,
+                      const GtkTextIter      *limit)
 {
        GtkTextIter begin_search = *iter;
-       const gchar *search_text = gtk_source_search_settings_get_search_text (search->settings);
+       const gchar *search_text = gtk_source_search_settings_get_search_text (search->priv->settings);
        GtkTextSearchFlags flags;
 
        if (search_text == NULL)
@@ -915,7 +916,7 @@ basic_backward_search (GtkSourceSearchContext *search,
                return FALSE;
        }
 
-       if (gtk_source_search_settings_get_regex_enabled (search->settings))
+       if (gtk_source_search_settings_get_regex_enabled (search->priv->settings))
        {
                return basic_backward_regex_search (search,
                                                    iter,
@@ -935,7 +936,7 @@ basic_backward_search (GtkSourceSearchContext *search,
                                                                match_end,
                                                                limit);
 
-               if (!found || !gtk_source_search_settings_get_at_word_boundaries (search->settings))
+               if (!found || !gtk_source_search_settings_get_at_word_boundaries (search->priv->settings))
                {
                        return found;
                }
@@ -977,23 +978,23 @@ forward_backward_data_free (ForwardBackwardData *data)
 /* Returns TRUE if finished. */
 static gboolean
 smart_forward_search_async_step (GtkSourceSearchContext *search,
-                                 GtkTextIter            *start_at,
-                                 gboolean               *wrapped_around)
+                                GtkTextIter            *start_at,
+                                gboolean               *wrapped_around)
 {
        GtkTextIter iter = *start_at;
        GtkTextIter limit;
        GtkTextIter region_start = *start_at;
        GtkSourceRegion *region = NULL;
        ForwardBackwardData *task_data;
-       const gchar *search_text = gtk_source_search_settings_get_search_text (search->settings);
+       const gchar *search_text = gtk_source_search_settings_get_search_text (search->priv->settings);
 
        if (gtk_text_iter_is_end (start_at))
        {
                if (search_text != NULL &&
                    !*wrapped_around &&
-                   gtk_source_search_settings_get_wrap_around (search->settings))
+                   gtk_source_search_settings_get_wrap_around (search->priv->settings))
                {
-                       gtk_text_buffer_get_start_iter (search->buffer, start_at);
+                       gtk_text_buffer_get_start_iter (search->priv->buffer, start_at);
                        *wrapped_around = TRUE;
                        return FALSE;
                }
@@ -1003,30 +1004,30 @@ smart_forward_search_async_step (GtkSourceSearchContext *search,
                task_data->is_forward = TRUE;
                task_data->wrapped_around = *wrapped_around;
 
-               g_task_return_pointer (search->task,
+               g_task_return_pointer (search->priv->task,
                                       task_data,
                                       (GDestroyNotify)forward_backward_data_free);
 
-               g_clear_object (&search->task);
+               g_clear_object (&search->priv->task);
                return TRUE;
        }
 
-       if (!gtk_text_iter_has_tag (&iter, search->found_tag))
+       if (!gtk_text_iter_has_tag (&iter, search->priv->found_tag))
        {
-               gtk_text_iter_forward_to_tag_toggle (&iter, search->found_tag);
+               gtk_text_iter_forward_to_tag_toggle (&iter, search->priv->found_tag);
        }
-       else if (!gtk_text_iter_starts_tag (&iter, search->found_tag))
+       else if (!gtk_text_iter_starts_tag (&iter, search->priv->found_tag))
        {
-               gtk_text_iter_backward_to_tag_toggle (&iter, search->found_tag);
+               gtk_text_iter_backward_to_tag_toggle (&iter, search->priv->found_tag);
                region_start = iter;
        }
 
        limit = iter;
-       gtk_text_iter_forward_to_tag_toggle (&limit, search->found_tag);
+       gtk_text_iter_forward_to_tag_toggle (&limit, search->priv->found_tag);
 
-       if (search->scan_region != NULL)
+       if (search->priv->scan_region != NULL)
        {
-               region = gtk_source_region_intersect_subregion (search->scan_region,
+               region = gtk_source_region_intersect_subregion (search->priv->scan_region,
                                                                &region_start,
                                                                &limit);
        }
@@ -1049,23 +1050,23 @@ smart_forward_search_async_step (GtkSourceSearchContext *search,
                        task_data = g_slice_new0 (ForwardBackwardData);
                        task_data->found = TRUE;
                        task_data->match_start =
-                                gtk_text_buffer_create_mark (search->buffer,
+                                gtk_text_buffer_create_mark (search->priv->buffer,
                                                              NULL,
                                                              &match_start,
                                                              TRUE);
                        task_data->match_end =
-                                gtk_text_buffer_create_mark (search->buffer,
+                                gtk_text_buffer_create_mark (search->priv->buffer,
                                                              NULL,
                                                              &match_end,
                                                              FALSE);
                        task_data->is_forward = TRUE;
                        task_data->wrapped_around = *wrapped_around;
 
-                       g_task_return_pointer (search->task,
+                       g_task_return_pointer (search->priv->task,
                                               task_data,
                                               (GDestroyNotify)forward_backward_data_free);
 
-                       g_clear_object (&search->task);
+                       g_clear_object (&search->priv->task);
                        return TRUE;
                }
 
@@ -1076,17 +1077,17 @@ smart_forward_search_async_step (GtkSourceSearchContext *search,
        task_data = g_slice_new0 (ForwardBackwardData);
        task_data->is_forward = TRUE;
        task_data->wrapped_around = *wrapped_around;
-       task_data->start_at = gtk_text_buffer_create_mark (search->buffer,
+       task_data->start_at = gtk_text_buffer_create_mark (search->priv->buffer,
                                                           NULL,
                                                           start_at,
                                                           TRUE);
 
-       g_task_set_task_data (search->task,
+       g_task_set_task_data (search->priv->task,
                              task_data,
                              (GDestroyNotify)forward_backward_data_free);
 
-       g_clear_object (&search->task_region);
-       search->task_region = region;
+       g_clear_object (&search->priv->task_region);
+       search->priv->task_region = region;
 
        install_idle_scan (search);
 
@@ -1099,8 +1100,8 @@ smart_forward_search_async_step (GtkSourceSearchContext *search,
 
 static void
 smart_forward_search_async (GtkSourceSearchContext *search,
-                            const GtkTextIter      *start_at,
-                            gboolean                wrapped_around)
+                           const GtkTextIter      *start_at,
+                           gboolean                wrapped_around)
 {
        GtkTextIter iter = *start_at;
 
@@ -1114,23 +1115,23 @@ smart_forward_search_async (GtkSourceSearchContext *search,
 /* Returns TRUE if finished. */
 static gboolean
 smart_backward_search_async_step (GtkSourceSearchContext *search,
-                                  GtkTextIter            *start_at,
-                                  gboolean               *wrapped_around)
+                                 GtkTextIter            *start_at,
+                                 gboolean               *wrapped_around)
 {
        GtkTextIter iter = *start_at;
        GtkTextIter limit;
        GtkTextIter region_end = *start_at;
        GtkSourceRegion *region = NULL;
        ForwardBackwardData *task_data;
-       const gchar *search_text = gtk_source_search_settings_get_search_text (search->settings);
+       const gchar *search_text = gtk_source_search_settings_get_search_text (search->priv->settings);
 
        if (gtk_text_iter_is_start (start_at))
        {
                if (search_text != NULL &&
                    !*wrapped_around &&
-                   gtk_source_search_settings_get_wrap_around (search->settings))
+                   gtk_source_search_settings_get_wrap_around (search->priv->settings))
                {
-                       gtk_text_buffer_get_end_iter (search->buffer, start_at);
+                       gtk_text_buffer_get_end_iter (search->priv->buffer, start_at);
                        *wrapped_around = TRUE;
                        return FALSE;
                }
@@ -1140,32 +1141,32 @@ smart_backward_search_async_step (GtkSourceSearchContext *search,
                task_data->is_forward = FALSE;
                task_data->wrapped_around = *wrapped_around;
 
-               g_task_return_pointer (search->task,
+               g_task_return_pointer (search->priv->task,
                                       task_data,
                                       (GDestroyNotify)forward_backward_data_free);
 
-               g_clear_object (&search->task);
+               g_clear_object (&search->priv->task);
                return TRUE;
        }
 
-       if (gtk_text_iter_starts_tag (&iter, search->found_tag) ||
-           (!gtk_text_iter_has_tag (&iter, search->found_tag) &&
-            !gtk_text_iter_ends_tag (&iter, search->found_tag)))
+       if (gtk_text_iter_starts_tag (&iter, search->priv->found_tag) ||
+           (!gtk_text_iter_has_tag (&iter, search->priv->found_tag) &&
+            !gtk_text_iter_ends_tag (&iter, search->priv->found_tag)))
        {
-               gtk_text_iter_backward_to_tag_toggle (&iter, search->found_tag);
+               gtk_text_iter_backward_to_tag_toggle (&iter, search->priv->found_tag);
        }
-       else if (gtk_text_iter_has_tag (&iter, search->found_tag))
+       else if (gtk_text_iter_has_tag (&iter, search->priv->found_tag))
        {
-               gtk_text_iter_forward_to_tag_toggle (&iter, search->found_tag);
+               gtk_text_iter_forward_to_tag_toggle (&iter, search->priv->found_tag);
                region_end = iter;
        }
 
        limit = iter;
-       gtk_text_iter_backward_to_tag_toggle (&limit, search->found_tag);
+       gtk_text_iter_backward_to_tag_toggle (&limit, search->priv->found_tag);
 
-       if (search->scan_region != NULL)
+       if (search->priv->scan_region != NULL)
        {
-               region = gtk_source_region_intersect_subregion (search->scan_region,
+               region = gtk_source_region_intersect_subregion (search->priv->scan_region,
                                                                &limit,
                                                                &region_end);
        }
@@ -1188,23 +1189,23 @@ smart_backward_search_async_step (GtkSourceSearchContext *search,
                        task_data = g_slice_new0 (ForwardBackwardData);
                        task_data->found = TRUE;
                        task_data->match_start =
-                               gtk_text_buffer_create_mark (search->buffer,
+                               gtk_text_buffer_create_mark (search->priv->buffer,
                                                             NULL,
                                                             &match_start,
                                                             TRUE);
                        task_data->match_end =
-                               gtk_text_buffer_create_mark (search->buffer,
+                               gtk_text_buffer_create_mark (search->priv->buffer,
                                                             NULL,
                                                             &match_end,
                                                             FALSE);
                        task_data->is_forward = FALSE;
                        task_data->wrapped_around = *wrapped_around;
 
-                       g_task_return_pointer (search->task,
+                       g_task_return_pointer (search->priv->task,
                                               task_data,
                                               (GDestroyNotify)forward_backward_data_free);
 
-                       g_clear_object (&search->task);
+                       g_clear_object (&search->priv->task);
                        return TRUE;
                }
 
@@ -1215,17 +1216,17 @@ smart_backward_search_async_step (GtkSourceSearchContext *search,
        task_data = g_slice_new0 (ForwardBackwardData);
        task_data->is_forward = FALSE;
        task_data->wrapped_around = *wrapped_around;
-       task_data->start_at = gtk_text_buffer_create_mark (search->buffer,
+       task_data->start_at = gtk_text_buffer_create_mark (search->priv->buffer,
                                                           NULL,
                                                           start_at,
                                                           TRUE);
 
-       g_task_set_task_data (search->task,
+       g_task_set_task_data (search->priv->task,
                              task_data,
                              (GDestroyNotify)forward_backward_data_free);
 
-       g_clear_object (&search->task_region);
-       search->task_region = region;
+       g_clear_object (&search->priv->task_region);
+       search->priv->task_region = region;
 
        install_idle_scan (search);
 
@@ -1238,8 +1239,8 @@ smart_backward_search_async_step (GtkSourceSearchContext *search,
 
 static void
 smart_backward_search_async (GtkSourceSearchContext *search,
-                             const GtkTextIter      *start_at,
-                             gboolean                wrapped_around)
+                            const GtkTextIter      *start_at,
+                            gboolean                wrapped_around)
 {
        GtkTextIter iter = *start_at;
 
@@ -1254,8 +1255,8 @@ smart_backward_search_async (GtkSourceSearchContext *search,
  */
 static void
 adjust_subregion (GtkSourceSearchContext *search,
-                  GtkTextIter            *start,
-                  GtkTextIter            *end)
+                 GtkTextIter            *start,
+                 GtkTextIter            *end)
 {
        DEBUG ({
                g_print ("adjust_subregion(), before adjusting: [%u (%u), %u (%u)]\n",
@@ -1263,8 +1264,8 @@ adjust_subregion (GtkSourceSearchContext *search,
                         gtk_text_iter_get_line (end), gtk_text_iter_get_offset (end));
        });
 
-       gtk_text_iter_backward_lines (start, MAX (0, search->text_nb_lines - 1));
-       gtk_text_iter_forward_lines (end, MAX (0, search->text_nb_lines - 1));
+       gtk_text_iter_backward_lines (start, MAX (0, search->priv->text_nb_lines - 1));
+       gtk_text_iter_forward_lines (end, MAX (0, search->priv->text_nb_lines - 1));
 
        if (!gtk_text_iter_starts_line (start))
        {
@@ -1284,12 +1285,12 @@ adjust_subregion (GtkSourceSearchContext *search,
         * not.
         */
 
-       if (gtk_text_iter_has_tag (start, search->found_tag))
+       if (gtk_text_iter_has_tag (start, search->priv->found_tag))
        {
-               if (gtk_source_region_is_empty (search->scan_region))
+               if (gtk_source_region_is_empty (search->priv->scan_region))
                {
                        /* 'start' is in a correct match, we can skip it. */
-                       gtk_text_iter_forward_to_tag_toggle (start, search->found_tag);
+                       gtk_text_iter_forward_to_tag_toggle (start, search->priv->found_tag);
                }
                else
                {
@@ -1297,14 +1298,14 @@ adjust_subregion (GtkSourceSearchContext *search,
                        GtkTextIter tag_end = *start;
                        GtkSourceRegion *region;
 
-                       if (!gtk_text_iter_starts_tag (&tag_start, search->found_tag))
+                       if (!gtk_text_iter_starts_tag (&tag_start, search->priv->found_tag))
                        {
-                               gtk_text_iter_backward_to_tag_toggle (&tag_start, search->found_tag);
+                               gtk_text_iter_backward_to_tag_toggle (&tag_start, search->priv->found_tag);
                        }
 
-                       gtk_text_iter_forward_to_tag_toggle (&tag_end, search->found_tag);
+                       gtk_text_iter_forward_to_tag_toggle (&tag_end, search->priv->found_tag);
 
-                       region = gtk_source_region_intersect_subregion (search->scan_region,
+                       region = gtk_source_region_intersect_subregion (search->priv->scan_region,
                                                                        &tag_start,
                                                                        &tag_end);
 
@@ -1330,15 +1331,15 @@ adjust_subregion (GtkSourceSearchContext *search,
 
        /* Symmetric for 'end'. */
 
-       if (gtk_text_iter_has_tag (end, search->found_tag))
+       if (gtk_text_iter_has_tag (end, search->priv->found_tag))
        {
-               if (gtk_source_region_is_empty (search->scan_region))
+               if (gtk_source_region_is_empty (search->priv->scan_region))
                {
                        /* 'end' is in a correct match, we can skip it. */
 
-                       if (!gtk_text_iter_starts_tag (end, search->found_tag))
+                       if (!gtk_text_iter_starts_tag (end, search->priv->found_tag))
                        {
-                               gtk_text_iter_backward_to_tag_toggle (end, search->found_tag);
+                               gtk_text_iter_backward_to_tag_toggle (end, search->priv->found_tag);
                        }
                }
                else
@@ -1347,14 +1348,14 @@ adjust_subregion (GtkSourceSearchContext *search,
                        GtkTextIter tag_end = *end;
                        GtkSourceRegion *region;
 
-                       if (!gtk_text_iter_starts_tag (&tag_start, search->found_tag))
+                       if (!gtk_text_iter_starts_tag (&tag_start, search->priv->found_tag))
                        {
-                               gtk_text_iter_backward_to_tag_toggle (&tag_start, search->found_tag);
+                               gtk_text_iter_backward_to_tag_toggle (&tag_start, search->priv->found_tag);
                        }
 
-                       gtk_text_iter_forward_to_tag_toggle (&tag_end, search->found_tag);
+                       gtk_text_iter_forward_to_tag_toggle (&tag_end, search->priv->found_tag);
 
-                       region = gtk_source_region_intersect_subregion (search->scan_region,
+                       region = gtk_source_region_intersect_subregion (search->priv->scan_region,
                                                                        &tag_start,
                                                                        &tag_end);
 
@@ -1391,13 +1392,13 @@ adjust_subregion (GtkSourceSearchContext *search,
  */
 static gboolean
 smart_forward_search_without_scanning (GtkSourceSearchContext *search,
-                                       const GtkTextIter      *start_at,
-                                       GtkTextIter            *match_start,
-                                       GtkTextIter            *match_end,
-                                       const GtkTextIter      *stop_at)
+                                      const GtkTextIter      *start_at,
+                                      GtkTextIter            *match_start,
+                                      GtkTextIter            *match_end,
+                                      const GtkTextIter      *stop_at)
 {
        GtkTextIter iter;
-       const gchar *search_text = gtk_source_search_settings_get_search_text (search->settings);
+       const gchar *search_text = gtk_source_search_settings_get_search_text (search->priv->settings);
 
        g_assert (start_at != NULL);
        g_assert (match_start != NULL);
@@ -1415,17 +1416,17 @@ smart_forward_search_without_scanning (GtkSourceSearchContext *search,
        {
                GtkTextIter limit;
 
-               if (!gtk_text_iter_has_tag (&iter, search->found_tag))
+               if (!gtk_text_iter_has_tag (&iter, search->priv->found_tag))
                {
-                       gtk_text_iter_forward_to_tag_toggle (&iter, search->found_tag);
+                       gtk_text_iter_forward_to_tag_toggle (&iter, search->priv->found_tag);
                }
-               else if (!gtk_text_iter_starts_tag (&iter, search->found_tag))
+               else if (!gtk_text_iter_starts_tag (&iter, search->priv->found_tag))
                {
-                       gtk_text_iter_backward_to_tag_toggle (&iter, search->found_tag);
+                       gtk_text_iter_backward_to_tag_toggle (&iter, search->priv->found_tag);
                }
 
                limit = iter;
-               gtk_text_iter_forward_to_tag_toggle (&limit, search->found_tag);
+               gtk_text_iter_forward_to_tag_toggle (&limit, search->priv->found_tag);
 
                if (gtk_text_iter_compare (stop_at, &limit) < 0)
                {
@@ -1453,50 +1454,50 @@ smart_forward_search_without_scanning (GtkSourceSearchContext *search,
  */
 static void
 remove_occurrences_in_range (GtkSourceSearchContext *search,
-                             GtkTextIter            *start,
-                             GtkTextIter            *end)
+                            GtkTextIter            *start,
+                            GtkTextIter            *end)
 {
        GtkTextIter iter;
        GtkTextIter match_start;
        GtkTextIter match_end;
 
-       if ((gtk_text_iter_has_tag (start, search->found_tag) &&
-            !gtk_text_iter_starts_tag (start, search->found_tag)) ||
-           (gtk_source_search_settings_get_at_word_boundaries (search->settings) &&
-            gtk_text_iter_ends_tag (start, search->found_tag)))
+       if ((gtk_text_iter_has_tag (start, search->priv->found_tag) &&
+            !gtk_text_iter_starts_tag (start, search->priv->found_tag)) ||
+           (gtk_source_search_settings_get_at_word_boundaries (search->priv->settings) &&
+            gtk_text_iter_ends_tag (start, search->priv->found_tag)))
        {
-               gtk_text_iter_backward_to_tag_toggle (start, search->found_tag);
+               gtk_text_iter_backward_to_tag_toggle (start, search->priv->found_tag);
        }
 
-       if ((gtk_text_iter_has_tag (end, search->found_tag) &&
-            !gtk_text_iter_starts_tag (end, search->found_tag)) ||
-           (gtk_source_search_settings_get_at_word_boundaries (search->settings) &&
-            gtk_text_iter_starts_tag (end, search->found_tag)))
+       if ((gtk_text_iter_has_tag (end, search->priv->found_tag) &&
+            !gtk_text_iter_starts_tag (end, search->priv->found_tag)) ||
+           (gtk_source_search_settings_get_at_word_boundaries (search->priv->settings) &&
+            gtk_text_iter_starts_tag (end, search->priv->found_tag)))
        {
-               gtk_text_iter_forward_to_tag_toggle (end, search->found_tag);
+               gtk_text_iter_forward_to_tag_toggle (end, search->priv->found_tag);
        }
 
        iter = *start;
 
        while (smart_forward_search_without_scanning (search, &iter, &match_start, &match_end, end))
        {
-               if (search->scan_region == NULL)
+               if (search->priv->scan_region == NULL)
                {
                        /* The occurrence has already been scanned, and thus
                         * occurrence_count take it into account. */
-                       search->occurrences_count--;
+                       search->priv->occurrences_count--;
                }
                else
                {
                        GtkSourceRegion *region;
 
-                       region = gtk_source_region_intersect_subregion (search->scan_region,
+                       region = gtk_source_region_intersect_subregion (search->priv->scan_region,
                                                                        &match_start,
                                                                        &match_end);
 
                        if (gtk_source_region_is_empty (region))
                        {
-                               search->occurrences_count--;
+                               search->priv->occurrences_count--;
                        }
 
                        g_clear_object (&region);
@@ -1505,48 +1506,48 @@ remove_occurrences_in_range (GtkSourceSearchContext *search,
                iter = match_end;
        }
 
-       gtk_text_buffer_remove_tag (search->buffer,
-                                   search->found_tag,
+       gtk_text_buffer_remove_tag (search->priv->buffer,
+                                   search->priv->found_tag,
                                    start,
                                    end);
 }
 
 static void
 scan_subregion (GtkSourceSearchContext *search,
-                GtkTextIter            *start,
-                GtkTextIter            *end)
+               GtkTextIter            *start,
+               GtkTextIter            *end)
 {
        GtkTextIter iter;
        GtkTextIter *limit;
        gboolean found = TRUE;
-       const gchar *search_text = gtk_source_search_settings_get_search_text (search->settings);
+       const gchar *search_text = gtk_source_search_settings_get_search_text (search->priv->settings);
 
        /* Make sure the 'found' tag has the priority over syntax highlighting
         * tags. */
-       text_tag_set_highest_priority (search->found_tag,
-                                      search->buffer);
+       text_tag_set_highest_priority (search->priv->found_tag,
+                                      search->priv->buffer);
 
        adjust_subregion (search, start, end);
        remove_occurrences_in_range (search, start, end);
 
-       if (search->scan_region != NULL)
+       if (search->priv->scan_region != NULL)
        {
                DEBUG ({
                        g_print ("Region to scan, before:\n");
-                       print_region (search->scan_region);
+                       print_region (search->priv->scan_region);
                });
 
-               gtk_source_region_subtract_subregion (search->scan_region, start, end);
+               gtk_source_region_subtract_subregion (search->priv->scan_region, start, end);
 
                DEBUG ({
                        g_print ("Region to scan, after:\n");
-                       print_region (search->scan_region);
+                       print_region (search->priv->scan_region);
                });
        }
 
-       if (search->task_region != NULL)
+       if (search->priv->task_region != NULL)
        {
-               gtk_source_region_subtract_subregion (search->task_region, start, end);
+               gtk_source_region_subtract_subregion (search->priv->task_region, start, end);
        }
 
        if (search_text == NULL)
@@ -1575,12 +1576,12 @@ scan_subregion (GtkSourceSearchContext *search,
 
                if (found)
                {
-                       gtk_text_buffer_apply_tag (search->buffer,
-                                                  search->found_tag,
+                       gtk_text_buffer_apply_tag (search->priv->buffer,
+                                                  search->priv->found_tag,
                                                   &match_start,
                                                   &match_end);
 
-                       search->occurrences_count++;
+                       search->priv->occurrences_count++;
                }
 
                iter = match_end;
@@ -1590,7 +1591,7 @@ scan_subregion (GtkSourceSearchContext *search,
 
 static void
 scan_all_region (GtkSourceSearchContext *search,
-                 GtkSourceRegion        *region)
+                GtkSourceRegion        *region)
 {
        GtkSourceRegionIter region_iter;
 
@@ -1622,7 +1623,7 @@ scan_all_region (GtkSourceSearchContext *search,
  */
 static void
 scan_region_forward (GtkSourceSearchContext *search,
-                     GtkSourceRegion        *region)
+                    GtkSourceRegion        *region)
 {
        gint nb_remaining_lines = SCAN_BATCH_SIZE;
        GtkTextIter start;
@@ -1656,7 +1657,7 @@ scan_region_forward (GtkSourceSearchContext *search,
 /* Same as scan_region_forward(), but begins the scan at the end of the region. */
 static void
 scan_region_backward (GtkSourceSearchContext *search,
-                      GtkSourceRegion        *region)
+                     GtkSourceRegion        *region)
 {
        gint nb_remaining_lines = SCAN_BATCH_SIZE;
        GtkTextIter start;
@@ -1690,12 +1691,12 @@ scan_region_backward (GtkSourceSearchContext *search,
 static void
 resume_task (GtkSourceSearchContext *search)
 {
-       ForwardBackwardData *task_data = g_task_get_task_data (search->task);
+       ForwardBackwardData *task_data = g_task_get_task_data (search->priv->task);
        GtkTextIter start_at;
 
-       g_clear_object (&search->task_region);
+       g_clear_object (&search->priv->task_region);
 
-       gtk_text_buffer_get_iter_at_mark (search->buffer,
+       gtk_text_buffer_get_iter_at_mark (search->priv->buffer,
                                          &start_at,
                                          task_data->start_at);
 
@@ -1716,15 +1717,15 @@ resume_task (GtkSourceSearchContext *search)
 static void
 scan_task_region (GtkSourceSearchContext *search)
 {
-       ForwardBackwardData *task_data = g_task_get_task_data (search->task);
+       ForwardBackwardData *task_data = g_task_get_task_data (search->priv->task);
 
        if (task_data->is_forward)
        {
-               scan_region_forward (search, search->task_region);
+               scan_region_forward (search, search->priv->task_region);
        }
        else
        {
-               scan_region_backward (search, search->task_region);
+               scan_region_backward (search, search->priv->task_region);
        }
 
        resume_task (search);
@@ -1733,33 +1734,33 @@ scan_task_region (GtkSourceSearchContext *search)
 static gboolean
 idle_scan_normal_search (GtkSourceSearchContext *search)
 {
-       if (search->high_priority_region != NULL)
+       if (search->priv->high_priority_region != NULL)
        {
                /* Normally the high priority region is not really big, since it
                 * is the visible area on the screen. So we can highlight it in
                 * one batch.
                 */
-               scan_all_region (search, search->high_priority_region);
+               scan_all_region (search, search->priv->high_priority_region);
 
-               g_clear_object (&search->high_priority_region);
+               g_clear_object (&search->priv->high_priority_region);
                return G_SOURCE_CONTINUE;
        }
 
-       if (search->task_region != NULL)
+       if (search->priv->task_region != NULL)
        {
                scan_task_region (search);
                return G_SOURCE_CONTINUE;
        }
 
-       scan_region_forward (search, search->scan_region);
+       scan_region_forward (search, search->priv->scan_region);
 
-       if (gtk_source_region_is_empty (search->scan_region))
+       if (gtk_source_region_is_empty (search->priv->scan_region))
        {
-               search->idle_scan_id = 0;
+               search->priv->idle_scan_id = 0;
 
                g_object_notify (G_OBJECT (search), "occurrences-count");
 
-               g_clear_object (&search->scan_region);
+               g_clear_object (&search->priv->scan_region);
                return G_SOURCE_REMOVE;
        }
 
@@ -1780,8 +1781,8 @@ regex_search_handle_high_priority_region (GtkSourceSearchContext *search)
        GtkSourceRegion *region;
        GtkSourceRegionIter region_iter;
 
-       region = gtk_source_region_intersect_region (search->high_priority_region,
-                                                    search->scan_region);
+       region = gtk_source_region_intersect_region (search->priv->high_priority_region,
+                                                    search->priv->scan_region);
 
        if (region == NULL)
        {
@@ -1802,8 +1803,8 @@ regex_search_handle_high_priority_region (GtkSourceSearchContext *search)
                        break;
                }
 
-               gtk_text_buffer_remove_tag (search->buffer,
-                                           search->found_tag,
+               gtk_text_buffer_remove_tag (search->priv->buffer,
+                                           search->priv->found_tag,
                                            &subregion_start,
                                            &subregion_end);
 
@@ -1816,9 +1817,9 @@ regex_search_handle_high_priority_region (GtkSourceSearchContext *search)
 /* Returns TRUE if the segment is finished, and FALSE on partial match. */
 static gboolean
 regex_search_scan_segment (GtkSourceSearchContext *search,
-                           const GtkTextIter      *segment_start,
-                           const GtkTextIter      *segment_end,
-                           GtkTextIter            *stopped_at)
+                          const GtkTextIter      *segment_start,
+                          const GtkTextIter      *segment_end,
+                          GtkTextIter            *stopped_at)
 {
        GtkTextIter real_start;
        gint start_pos;
@@ -1834,13 +1835,13 @@ regex_search_scan_segment (GtkSourceSearchContext *search,
 
        g_assert (stopped_at != NULL);
 
-       gtk_text_buffer_remove_tag (search->buffer,
-                                   search->found_tag,
+       gtk_text_buffer_remove_tag (search->priv->buffer,
+                                   search->priv->found_tag,
                                    segment_start,
                                    segment_end);
 
-       if (search->regex == NULL ||
-           search->regex_error != NULL)
+       if (search->priv->regex == NULL ||
+           search->priv->regex_error != NULL)
        {
                *stopped_at = *segment_end;
                return TRUE;
@@ -1888,13 +1889,13 @@ regex_search_scan_segment (GtkSourceSearchContext *search,
               g_free (subject_escaped);
        });
 
-       g_regex_match_full (search->regex,
+       g_regex_match_full (search->priv->regex,
                            subject,
                            subject_length,
                            start_pos,
                            match_options,
                            &match_info,
-                           &search->regex_error);
+                           &search->priv->regex_error);
 
        iter = real_start;
        iter_byte_pos = 0;
@@ -1907,8 +1908,8 @@ regex_search_scan_segment (GtkSourceSearchContext *search,
                                         &match_start,
                                         &match_end))
        {
-               gtk_text_buffer_apply_tag (search->buffer,
-                                          search->found_tag,
+               gtk_text_buffer_apply_tag (search->priv->buffer,
+                                          search->priv->found_tag,
                                           &match_start,
                                           &match_end);
 
@@ -1920,12 +1921,12 @@ regex_search_scan_segment (GtkSourceSearchContext *search,
                         g_free (match_escaped);
                });
 
-               search->occurrences_count++;
+               search->priv->occurrences_count++;
 
-               g_match_info_next (match_info, &search->regex_error);
+               g_match_info_next (match_info, &search->priv->regex_error);
        }
 
-       if (search->regex_error != NULL)
+       if (search->priv->regex_error != NULL)
        {
                g_object_notify (G_OBJECT (search), "regex-error");
        }
@@ -1961,8 +1962,8 @@ regex_search_scan_segment (GtkSourceSearchContext *search,
 
 static void
 regex_search_scan_chunk (GtkSourceSearchContext *search,
-                         const GtkTextIter      *chunk_start,
-                         const GtkTextIter      *chunk_end)
+                        const GtkTextIter      *chunk_start,
+                        const GtkTextIter      *chunk_end)
 {
        GtkTextIter segment_start = *chunk_start;
 
@@ -1992,13 +1993,13 @@ regex_search_scan_chunk (GtkSourceSearchContext *search,
                segment_start = stopped_at;
        }
 
-       gtk_source_region_subtract_subregion (search->scan_region,
+       gtk_source_region_subtract_subregion (search->priv->scan_region,
                                              chunk_start,
                                              &segment_start);
 
-       if (search->task_region != NULL)
+       if (search->priv->task_region != NULL)
        {
-               gtk_source_region_subtract_subregion (search->task_region,
+               gtk_source_region_subtract_subregion (search->priv->task_region,
                                                      chunk_start,
                                                      &segment_start);
        }
@@ -2010,12 +2011,12 @@ regex_search_scan_next_chunk (GtkSourceSearchContext *search)
        GtkTextIter chunk_start;
        GtkTextIter chunk_end;
 
-       if (gtk_source_region_is_empty (search->scan_region))
+       if (gtk_source_region_is_empty (search->priv->scan_region))
        {
                return;
        }
 
-       if (!gtk_source_region_get_bounds (search->scan_region, &chunk_start, NULL))
+       if (!gtk_source_region_get_bounds (search->priv->scan_region, &chunk_start, NULL))
        {
                return;
        }
@@ -2029,16 +2030,16 @@ regex_search_scan_next_chunk (GtkSourceSearchContext *search)
 static gboolean
 idle_scan_regex_search (GtkSourceSearchContext *search)
 {
-       if (search->high_priority_region != NULL)
+       if (search->priv->high_priority_region != NULL)
        {
                regex_search_handle_high_priority_region (search);
-               g_clear_object (&search->high_priority_region);
+               g_clear_object (&search->priv->high_priority_region);
                return G_SOURCE_CONTINUE;
        }
 
        regex_search_scan_next_chunk (search);
 
-       if (search->task != NULL)
+       if (search->priv->task != NULL)
        {
                /* Always resume the task, even if the task region has not been
                 * fully scanned. The task region can be huge (the whole
@@ -2052,13 +2053,13 @@ idle_scan_regex_search (GtkSourceSearchContext *search)
                return G_SOURCE_CONTINUE;
        }
 
-       if (gtk_source_region_is_empty (search->scan_region))
+       if (gtk_source_region_is_empty (search->priv->scan_region))
        {
-               search->idle_scan_id = 0;
+               search->priv->idle_scan_id = 0;
 
                g_object_notify (G_OBJECT (search), "occurrences-count");
 
-               g_clear_object (&search->scan_region);
+               g_clear_object (&search->priv->scan_region);
                return G_SOURCE_REMOVE;
        }
 
@@ -2068,14 +2069,14 @@ idle_scan_regex_search (GtkSourceSearchContext *search)
 static gboolean
 idle_scan_cb (GtkSourceSearchContext *search)
 {
-       if (search->buffer == NULL)
+       if (search->priv->buffer == NULL)
        {
-               search->idle_scan_id = 0;
+               search->priv->idle_scan_id = 0;
                clear_search (search);
                return G_SOURCE_REMOVE;
        }
 
-       return gtk_source_search_settings_get_regex_enabled (search->settings) ?
+       return gtk_source_search_settings_get_regex_enabled (search->priv->settings) ?
               idle_scan_regex_search (search) :
               idle_scan_normal_search (search);
 }
@@ -2083,40 +2084,40 @@ idle_scan_cb (GtkSourceSearchContext *search)
 static void
 install_idle_scan (GtkSourceSearchContext *search)
 {
-       if (search->idle_scan_id == 0)
+       if (search->priv->idle_scan_id == 0)
        {
-               search->idle_scan_id = g_idle_add ((GSourceFunc)idle_scan_cb, search);
+               search->priv->idle_scan_id = g_idle_add ((GSourceFunc)idle_scan_cb, search);
        }
 }
 
 /* Returns TRUE when finished. */
 static gboolean
 smart_forward_search_step (GtkSourceSearchContext *search,
-                           GtkTextIter            *start_at,
-                           GtkTextIter            *match_start,
-                           GtkTextIter            *match_end)
+                          GtkTextIter            *start_at,
+                          GtkTextIter            *match_start,
+                          GtkTextIter            *match_end)
 {
        GtkTextIter iter = *start_at;
        GtkTextIter limit;
        GtkTextIter region_start = *start_at;
        GtkSourceRegion *region = NULL;
 
-       if (!gtk_text_iter_has_tag (&iter, search->found_tag))
+       if (!gtk_text_iter_has_tag (&iter, search->priv->found_tag))
        {
-               gtk_text_iter_forward_to_tag_toggle (&iter, search->found_tag);
+               gtk_text_iter_forward_to_tag_toggle (&iter, search->priv->found_tag);
        }
-       else if (!gtk_text_iter_starts_tag (&iter, search->found_tag))
+       else if (!gtk_text_iter_starts_tag (&iter, search->priv->found_tag))
        {
-               gtk_text_iter_backward_to_tag_toggle (&iter, search->found_tag);
+               gtk_text_iter_backward_to_tag_toggle (&iter, search->priv->found_tag);
                region_start = iter;
        }
 
        limit = iter;
-       gtk_text_iter_forward_to_tag_toggle (&limit, search->found_tag);
+       gtk_text_iter_forward_to_tag_toggle (&limit, search->priv->found_tag);
 
-       if (search->scan_region != NULL)
+       if (search->priv->scan_region != NULL)
        {
-               region = gtk_source_region_intersect_subregion (search->scan_region,
+               region = gtk_source_region_intersect_subregion (search->priv->scan_region,
                                                                &region_start,
                                                                &limit);
        }
@@ -2142,7 +2143,7 @@ smart_forward_search_step (GtkSourceSearchContext *search,
        /* Scan a chunk of the buffer, not the whole 'region'. An occurrence can
         * be found before the 'region' is scanned entirely.
         */
-       if (gtk_source_search_settings_get_regex_enabled (search->settings))
+       if (gtk_source_search_settings_get_regex_enabled (search->priv->settings))
        {
                regex_search_scan_next_chunk (search);
        }
@@ -2159,12 +2160,12 @@ smart_forward_search_step (GtkSourceSearchContext *search,
 /* Doesn't wrap around. */
 static gboolean
 smart_forward_search (GtkSourceSearchContext *search,
-                      const GtkTextIter      *start_at,
-                      GtkTextIter            *match_start,
-                      GtkTextIter            *match_end)
+                     const GtkTextIter      *start_at,
+                     GtkTextIter            *match_start,
+                     GtkTextIter            *match_end)
 {
        GtkTextIter iter = *start_at;
-       const gchar *search_text = gtk_source_search_settings_get_search_text (search->settings);
+       const gchar *search_text = gtk_source_search_settings_get_search_text (search->priv->settings);
 
        g_return_val_if_fail (match_start != NULL, FALSE);
        g_return_val_if_fail (match_end != NULL, FALSE);
@@ -2188,33 +2189,33 @@ smart_forward_search (GtkSourceSearchContext *search,
 /* Returns TRUE when finished. */
 static gboolean
 smart_backward_search_step (GtkSourceSearchContext *search,
-                            GtkTextIter            *start_at,
-                            GtkTextIter            *match_start,
-                            GtkTextIter            *match_end)
+                           GtkTextIter            *start_at,
+                           GtkTextIter            *match_start,
+                           GtkTextIter            *match_end)
 {
        GtkTextIter iter = *start_at;
        GtkTextIter limit;
        GtkTextIter region_end = *start_at;
        GtkSourceRegion *region = NULL;
 
-       if (gtk_text_iter_starts_tag (&iter, search->found_tag) ||
-           (!gtk_text_iter_has_tag (&iter, search->found_tag) &&
-            !gtk_text_iter_ends_tag (&iter, search->found_tag)))
+       if (gtk_text_iter_starts_tag (&iter, search->priv->found_tag) ||
+           (!gtk_text_iter_has_tag (&iter, search->priv->found_tag) &&
+            !gtk_text_iter_ends_tag (&iter, search->priv->found_tag)))
        {
-               gtk_text_iter_backward_to_tag_toggle (&iter, search->found_tag);
+               gtk_text_iter_backward_to_tag_toggle (&iter, search->priv->found_tag);
        }
-       else if (gtk_text_iter_has_tag (&iter, search->found_tag))
+       else if (gtk_text_iter_has_tag (&iter, search->priv->found_tag))
        {
-               gtk_text_iter_forward_to_tag_toggle (&iter, search->found_tag);
+               gtk_text_iter_forward_to_tag_toggle (&iter, search->priv->found_tag);
                region_end = iter;
        }
 
        limit = iter;
-       gtk_text_iter_backward_to_tag_toggle (&limit, search->found_tag);
+       gtk_text_iter_backward_to_tag_toggle (&limit, search->priv->found_tag);
 
-       if (search->scan_region != NULL)
+       if (search->priv->scan_region != NULL)
        {
-               region = gtk_source_region_intersect_subregion (search->scan_region,
+               region = gtk_source_region_intersect_subregion (search->priv->scan_region,
                                                                &limit,
                                                                &region_end);
        }
@@ -2240,7 +2241,7 @@ smart_backward_search_step (GtkSourceSearchContext *search,
        /* Scan a chunk of the buffer, not the whole 'region'. An occurrence can
         * be found before the 'region' is scanned entirely.
         */
-       if (gtk_source_search_settings_get_regex_enabled (search->settings))
+       if (gtk_source_search_settings_get_regex_enabled (search->priv->settings))
        {
                regex_search_scan_next_chunk (search);
        }
@@ -2257,12 +2258,12 @@ smart_backward_search_step (GtkSourceSearchContext *search,
 /* Doesn't wrap around. */
 static gboolean
 smart_backward_search (GtkSourceSearchContext *search,
-                       const GtkTextIter      *start_at,
-                       GtkTextIter            *match_start,
-                       GtkTextIter            *match_end)
+                      const GtkTextIter      *start_at,
+                      GtkTextIter            *match_start,
+                      GtkTextIter            *match_end)
 {
        GtkTextIter iter = *start_at;
-       const gchar *search_text = gtk_source_search_settings_get_search_text (search->settings);
+       const gchar *search_text = gtk_source_search_settings_get_search_text (search->priv->settings);
 
        g_return_val_if_fail (match_start != NULL, FALSE);
        g_return_val_if_fail (match_end != NULL, FALSE);
@@ -2285,27 +2286,27 @@ smart_backward_search (GtkSourceSearchContext *search,
 
 static void
 add_subregion_to_scan (GtkSourceSearchContext *search,
-                       const GtkTextIter      *subregion_start,
-                       const GtkTextIter      *subregion_end)
+                      const GtkTextIter      *subregion_start,
+                      const GtkTextIter      *subregion_end)
 {
        GtkTextIter start = *subregion_start;
        GtkTextIter end = *subregion_end;
 
-       if (search->scan_region == NULL)
+       if (search->priv->scan_region == NULL)
        {
-               search->scan_region = gtk_source_region_new (search->buffer);
+               search->priv->scan_region = gtk_source_region_new (search->priv->buffer);
        }
 
        DEBUG ({
                g_print ("add_subregion_to_scan(): region to scan, before:\n");
-               print_region (search->scan_region);
+               print_region (search->priv->scan_region);
        });
 
-       gtk_source_region_add_subregion (search->scan_region, &start, &end);
+       gtk_source_region_add_subregion (search->priv->scan_region, &start, &end);
 
        DEBUG ({
                g_print ("add_subregion_to_scan(): region to scan, after:\n");
-               print_region (search->scan_region);
+               print_region (search->priv->scan_region);
        });
 
        install_idle_scan (search);
@@ -2315,49 +2316,49 @@ static void
 update_regex (GtkSourceSearchContext *search)
 {
        gboolean regex_error_changed = FALSE;
-       const gchar *search_text = gtk_source_search_settings_get_search_text (search->settings);
+       const gchar *search_text = gtk_source_search_settings_get_search_text (search->priv->settings);
 
-       if (search->regex != NULL)
+       if (search->priv->regex != NULL)
        {
-               g_regex_unref (search->regex);
-               search->regex = NULL;
+               g_regex_unref (search->priv->regex);
+               search->priv->regex = NULL;
        }
 
-       if (search->regex_error != NULL)
+       if (search->priv->regex_error != NULL)
        {
-               g_clear_error (&search->regex_error);
+               g_clear_error (&search->priv->regex_error);
                regex_error_changed = TRUE;
        }
 
        if (search_text != NULL &&
-           gtk_source_search_settings_get_regex_enabled (search->settings))
+           gtk_source_search_settings_get_regex_enabled (search->priv->settings))
        {
                GRegexCompileFlags compile_flags = G_REGEX_OPTIMIZE | G_REGEX_MULTILINE;
                gchar *pattern = (gchar *)search_text;
 
-               search->text_nb_lines = 0;
+               search->priv->text_nb_lines = 0;
 
-               if (!gtk_source_search_settings_get_case_sensitive (search->settings))
+               if (!gtk_source_search_settings_get_case_sensitive (search->priv->settings))
                {
                        compile_flags |= G_REGEX_CASELESS;
                }
 
-               if (gtk_source_search_settings_get_at_word_boundaries (search->settings))
+               if (gtk_source_search_settings_get_at_word_boundaries (search->priv->settings))
                {
                        pattern = g_strdup_printf ("\\b%s\\b", search_text);
                }
 
-               search->regex = g_regex_new (pattern,
+               search->priv->regex = g_regex_new (pattern,
                                                   compile_flags,
                                                   G_REGEX_MATCH_NOTEMPTY,
-                                                  &search->regex_error);
+                                                  &search->priv->regex_error);
 
-               if (search->regex_error != NULL)
+               if (search->priv->regex_error != NULL)
                {
                        regex_error_changed = TRUE;
                }
 
-               if (gtk_source_search_settings_get_at_word_boundaries (search->settings))
+               if (gtk_source_search_settings_get_at_word_boundaries (search->priv->settings))
                {
                        g_free (pattern);
                }
@@ -2376,7 +2377,7 @@ update (GtkSourceSearchContext *search)
        GtkTextIter end;
        GtkSourceBufferInternal *buffer_internal;
 
-       if (search->buffer == NULL)
+       if (search->priv->buffer == NULL)
        {
                return;
        }
@@ -2384,31 +2385,31 @@ update (GtkSourceSearchContext *search)
        clear_search (search);
        update_regex (search);
 
-       search->scan_region = gtk_source_region_new (search->buffer);
+       search->priv->scan_region = gtk_source_region_new (search->priv->buffer);
 
-       gtk_text_buffer_get_bounds (search->buffer, &start, &end);
+       gtk_text_buffer_get_bounds (search->priv->buffer, &start, &end);
        add_subregion_to_scan (search, &start, &end);
 
        /* Notify the GtkSourceViews that the search is starting, so that
         * _gtk_source_search_context_update_highlight() can be called for the
         * visible regions of the buffer.
         */
-       buffer_internal = _gtk_source_buffer_internal_get_from_buffer (GTK_SOURCE_BUFFER (search->buffer));
+       buffer_internal = _gtk_source_buffer_internal_get_from_buffer (GTK_SOURCE_BUFFER 
(search->priv->buffer));
        _gtk_source_buffer_internal_emit_search_start (buffer_internal, search);
 }
 
 static void
 insert_text_before_cb (GtkSourceSearchContext *search,
-                       GtkTextIter            *location,
-                       gchar                  *text,
-                       gint                    length)
+                      GtkTextIter            *location,
+                      gchar                  *text,
+                      gint                    length)
 {
-       const gchar *search_text = gtk_source_search_settings_get_search_text (search->settings);
+       const gchar *search_text = gtk_source_search_settings_get_search_text (search->priv->settings);
 
        clear_task (search);
 
        if (search_text != NULL &&
-           !gtk_source_search_settings_get_regex_enabled (search->settings))
+           !gtk_source_search_settings_get_regex_enabled (search->priv->settings))
        {
                GtkTextIter start = *location;
                GtkTextIter end = *location;
@@ -2420,11 +2421,11 @@ insert_text_before_cb (GtkSourceSearchContext *search,
 
 static void
 insert_text_after_cb (GtkSourceSearchContext *search,
-                      GtkTextIter            *location,
-                      gchar                  *text,
-                      gint                    length)
+                     GtkTextIter            *location,
+                     gchar                  *text,
+                     gint                    length)
 {
-       if (gtk_source_search_settings_get_regex_enabled (search->settings))
+       if (gtk_source_search_settings_get_regex_enabled (search->priv->settings))
        {
                update (search);
        }
@@ -2444,27 +2445,27 @@ insert_text_after_cb (GtkSourceSearchContext *search,
 
 static void
 delete_range_before_cb (GtkSourceSearchContext *search,
-                        GtkTextIter            *delete_start,
-                        GtkTextIter            *delete_end)
+                       GtkTextIter            *delete_start,
+                       GtkTextIter            *delete_end)
 {
        GtkTextIter start_buffer;
        GtkTextIter end_buffer;
-       const gchar *search_text = gtk_source_search_settings_get_search_text (search->settings);
+       const gchar *search_text = gtk_source_search_settings_get_search_text (search->priv->settings);
 
        clear_task (search);
 
-       if (gtk_source_search_settings_get_regex_enabled (search->settings))
+       if (gtk_source_search_settings_get_regex_enabled (search->priv->settings))
        {
                return;
        }
 
-       gtk_text_buffer_get_bounds (search->buffer, &start_buffer, &end_buffer);
+       gtk_text_buffer_get_bounds (search->priv->buffer, &start_buffer, &end_buffer);
 
        if (gtk_text_iter_equal (delete_start, &start_buffer) &&
            gtk_text_iter_equal (delete_end, &end_buffer))
        {
                /* Special case when removing all the text. */
-               search->occurrences_count = 0;
+               search->priv->occurrences_count = 0;
                return;
        }
 
@@ -2473,8 +2474,8 @@ delete_range_before_cb (GtkSourceSearchContext *search,
                GtkTextIter start = *delete_start;
                GtkTextIter end = *delete_end;
 
-               gtk_text_iter_backward_lines (&start, search->text_nb_lines);
-               gtk_text_iter_forward_lines (&end, search->text_nb_lines);
+               gtk_text_iter_backward_lines (&start, search->priv->text_nb_lines);
+               gtk_text_iter_forward_lines (&end, search->priv->text_nb_lines);
 
                remove_occurrences_in_range (search, &start, &end);
                add_subregion_to_scan (search, &start, &end);
@@ -2483,10 +2484,10 @@ delete_range_before_cb (GtkSourceSearchContext *search,
 
 static void
 delete_range_after_cb (GtkSourceSearchContext *search,
-                       GtkTextIter            *start,
-                       GtkTextIter            *end)
+                      GtkTextIter            *start,
+                      GtkTextIter            *end)
 {
-       if (gtk_source_search_settings_get_regex_enabled (search->settings))
+       if (gtk_source_search_settings_get_regex_enabled (search->priv->settings))
        {
                update (search);
        }
@@ -2500,16 +2501,16 @@ static void
 set_buffer (GtkSourceSearchContext *search,
            GtkSourceBuffer        *buffer)
 {
-       g_assert (search->buffer == NULL);
-       g_assert (search->tag_table == NULL);
+       g_assert (search->priv->buffer == NULL);
+       g_assert (search->priv->tag_table == NULL);
 
-       search->buffer = GTK_TEXT_BUFFER (buffer);
+       search->priv->buffer = GTK_TEXT_BUFFER (buffer);
 
        g_object_add_weak_pointer (G_OBJECT (buffer),
-                                  (gpointer *)&search->buffer);
+                                  (gpointer *)&search->priv->buffer);
 
-       search->tag_table = gtk_text_buffer_get_tag_table (search->buffer);
-       g_object_ref (search->tag_table);
+       search->priv->tag_table = gtk_text_buffer_get_tag_table (search->priv->buffer);
+       g_object_ref (search->priv->tag_table);
 
        g_signal_connect_object (buffer,
                                 "insert-text",
@@ -2535,12 +2536,12 @@ set_buffer (GtkSourceSearchContext *search,
                                 search,
                                 G_CONNECT_AFTER | G_CONNECT_SWAPPED);
 
-       search->found_tag = gtk_text_buffer_create_tag (search->buffer, NULL, NULL);
-       g_object_ref (search->found_tag);
+       search->priv->found_tag = gtk_text_buffer_create_tag (search->priv->buffer, NULL, NULL);
+       g_object_ref (search->priv->found_tag);
 
        sync_found_tag (search);
 
-       g_signal_connect_object (search->buffer,
+       g_signal_connect_object (search->priv->buffer,
                                 "notify::style-scheme",
                                 G_CALLBACK (sync_found_tag),
                                 search,
@@ -2588,21 +2589,21 @@ compute_number_of_lines (const gchar *text)
 static void
 search_text_updated (GtkSourceSearchContext *search)
 {
-       if (gtk_source_search_settings_get_regex_enabled (search->settings))
+       if (gtk_source_search_settings_get_regex_enabled (search->priv->settings))
        {
-               search->text_nb_lines = 0;
+               search->priv->text_nb_lines = 0;
        }
        else
        {
-               const gchar *text = gtk_source_search_settings_get_search_text (search->settings);
-               search->text_nb_lines = compute_number_of_lines (text);
+               const gchar *text = gtk_source_search_settings_get_search_text (search->priv->settings);
+               search->priv->text_nb_lines = compute_number_of_lines (text);
        }
 }
 
 static void
 settings_notify_cb (GtkSourceSearchContext  *search,
-                    GParamSpec              *pspec,
-                    GtkSourceSearchSettings *settings)
+                   GParamSpec              *pspec,
+                   GtkSourceSearchSettings *settings)
 {
        const gchar *property = g_param_spec_get_name (pspec);
 
@@ -2616,20 +2617,20 @@ settings_notify_cb (GtkSourceSearchContext  *search,
 
 static void
 set_settings (GtkSourceSearchContext  *search,
-              GtkSourceSearchSettings *settings)
+             GtkSourceSearchSettings *settings)
 {
-       g_assert (search->settings == NULL);
+       g_assert (search->priv->settings == NULL);
 
        if (settings != NULL)
        {
-               search->settings = g_object_ref (settings);
+               search->priv->settings = g_object_ref (settings);
        }
        else
        {
-               search->settings = gtk_source_search_settings_new ();
+               search->priv->settings = gtk_source_search_settings_new ();
        }
 
-       g_signal_connect_object (search->settings,
+       g_signal_connect_object (search->priv->settings,
                                 "notify",
                                 G_CALLBACK (settings_notify_cb),
                                 search,
@@ -2648,25 +2649,25 @@ gtk_source_search_context_dispose (GObject *object)
 
        clear_search (search);
 
-       if (search->found_tag != NULL &&
-           search->tag_table != NULL)
+       if (search->priv->found_tag != NULL &&
+           search->priv->tag_table != NULL)
        {
-               gtk_text_tag_table_remove (search->tag_table,
-                                          search->found_tag);
+               gtk_text_tag_table_remove (search->priv->tag_table,
+                                          search->priv->found_tag);
 
-               g_clear_object (&search->found_tag);
-               g_clear_object (&search->tag_table);
+               g_clear_object (&search->priv->found_tag);
+               g_clear_object (&search->priv->tag_table);
        }
 
-       if (search->buffer != NULL)
+       if (search->priv->buffer != NULL)
        {
-               g_object_remove_weak_pointer (G_OBJECT (search->buffer),
-                                             (gpointer *)&search->buffer);
+               g_object_remove_weak_pointer (G_OBJECT (search->priv->buffer),
+                                             (gpointer *)&search->priv->buffer);
 
-               search->buffer = NULL;
+               search->priv->buffer = NULL;
        }
 
-       g_clear_object (&search->settings);
+       g_clear_object (&search->priv->settings);
 
        G_OBJECT_CLASS (gtk_source_search_context_parent_class)->dispose (object);
 }
@@ -2676,21 +2677,21 @@ gtk_source_search_context_finalize (GObject *object)
 {
        GtkSourceSearchContext *search = GTK_SOURCE_SEARCH_CONTEXT (object);
 
-       if (search->regex != NULL)
+       if (search->priv->regex != NULL)
        {
-               g_regex_unref (search->regex);
+               g_regex_unref (search->priv->regex);
        }
 
-       g_clear_error (&search->regex_error);
+       g_clear_error (&search->priv->regex_error);
 
        G_OBJECT_CLASS (gtk_source_search_context_parent_class)->finalize (object);
 }
 
 static void
 gtk_source_search_context_get_property (GObject    *object,
-                                        guint       prop_id,
-                                        GValue     *value,
-                                        GParamSpec *pspec)
+                                       guint       prop_id,
+                                       GValue     *value,
+                                       GParamSpec *pspec)
 {
        GtkSourceSearchContext *search;
 
@@ -2701,19 +2702,19 @@ gtk_source_search_context_get_property (GObject    *object,
        switch (prop_id)
        {
                case PROP_BUFFER:
-                       g_value_set_object (value, search->buffer);
+                       g_value_set_object (value, search->priv->buffer);
                        break;
 
                case PROP_SETTINGS:
-                       g_value_set_object (value, search->settings);
+                       g_value_set_object (value, search->priv->settings);
                        break;
 
                case PROP_HIGHLIGHT:
-                       g_value_set_boolean (value, search->highlight);
+                       g_value_set_boolean (value, search->priv->highlight);
                        break;
 
                case PROP_MATCH_STYLE:
-                       g_value_set_object (value, search->match_style);
+                       g_value_set_object (value, search->priv->match_style);
                        break;
 
                case PROP_OCCURRENCES_COUNT:
@@ -2732,9 +2733,9 @@ gtk_source_search_context_get_property (GObject    *object,
 
 static void
 gtk_source_search_context_set_property (GObject      *object,
-                                        guint         prop_id,
-                                        const GValue *value,
-                                        GParamSpec   *pspec)
+                                       guint         prop_id,
+                                       const GValue *value,
+                                       GParamSpec   *pspec)
 {
        GtkSourceSearchContext *search;
 
@@ -2889,7 +2890,7 @@ gtk_source_search_context_class_init (GtkSourceSearchContextClass *klass)
 static void
 gtk_source_search_context_init (GtkSourceSearchContext *search)
 {
-       search = gtk_source_search_context_get_instance_private (search);
+       search->priv = gtk_source_search_context_get_instance_private (search);
 }
 
 /**
@@ -2907,7 +2908,7 @@ gtk_source_search_context_init (GtkSourceSearchContext *search)
  */
 GtkSourceSearchContext *
 gtk_source_search_context_new (GtkSourceBuffer         *buffer,
-                               GtkSourceSearchSettings *settings)
+                              GtkSourceSearchSettings *settings)
 {
        g_return_val_if_fail (GTK_SOURCE_IS_BUFFER (buffer), NULL);
        g_return_val_if_fail (settings == NULL || GTK_SOURCE_IS_SEARCH_SETTINGS (settings), NULL);
@@ -2930,7 +2931,7 @@ gtk_source_search_context_get_buffer (GtkSourceSearchContext *search)
 {
        g_return_val_if_fail (GTK_SOURCE_IS_SEARCH_CONTEXT (search), NULL);
 
-       return GTK_SOURCE_BUFFER (search->buffer);
+       return GTK_SOURCE_BUFFER (search->priv->buffer);
 }
 
 /**
@@ -2945,7 +2946,7 @@ gtk_source_search_context_get_settings (GtkSourceSearchContext *search)
 {
        g_return_val_if_fail (GTK_SOURCE_IS_SEARCH_CONTEXT (search), NULL);
 
-       return search->settings;
+       return search->priv->settings;
 }
 
 /**
@@ -2960,7 +2961,7 @@ gtk_source_search_context_get_highlight (GtkSourceSearchContext *search)
 {
        g_return_val_if_fail (GTK_SOURCE_IS_SEARCH_CONTEXT (search), FALSE);
 
-       return search->highlight;
+       return search->priv->highlight;
 }
 
 /**
@@ -2974,15 +2975,15 @@ gtk_source_search_context_get_highlight (GtkSourceSearchContext *search)
  */
 void
 gtk_source_search_context_set_highlight (GtkSourceSearchContext *search,
-                                         gboolean                highlight)
+                                        gboolean                highlight)
 {
        g_return_if_fail (GTK_SOURCE_IS_SEARCH_CONTEXT (search));
 
        highlight = highlight != FALSE;
 
-       if (search->highlight != highlight)
+       if (search->priv->highlight != highlight)
        {
-               search->highlight = highlight;
+               search->priv->highlight = highlight;
                sync_found_tag (search);
 
                g_object_notify (G_OBJECT (search), "highlight");
@@ -3002,7 +3003,7 @@ gtk_source_search_context_get_match_style (GtkSourceSearchContext *search)
 {
        g_return_val_if_fail (GTK_SOURCE_IS_SEARCH_CONTEXT (search), NULL);
 
-       return search->match_style;
+       return search->priv->match_style;
 }
 
 /**
@@ -3019,22 +3020,22 @@ gtk_source_search_context_get_match_style (GtkSourceSearchContext *search)
  */
 void
 gtk_source_search_context_set_match_style (GtkSourceSearchContext *search,
-                                           GtkSourceStyle         *match_style)
+                                          GtkSourceStyle         *match_style)
 {
        g_return_if_fail (GTK_SOURCE_IS_SEARCH_CONTEXT (search));
        g_return_if_fail (match_style == NULL || GTK_SOURCE_IS_STYLE (match_style));
 
-       if (search->match_style == match_style)
+       if (search->priv->match_style == match_style)
        {
                return;
        }
 
-       if (search->match_style != NULL)
+       if (search->priv->match_style != NULL)
        {
-               g_object_unref (search->match_style);
+               g_object_unref (search->priv->match_style);
        }
 
-       search->match_style = match_style;
+       search->priv->match_style = match_style;
 
        if (match_style != NULL)
        {
@@ -3062,12 +3063,12 @@ gtk_source_search_context_get_regex_error (GtkSourceSearchContext *search)
 {
        g_return_val_if_fail (GTK_SOURCE_IS_SEARCH_CONTEXT (search), NULL);
 
-       if (search->regex_error == NULL)
+       if (search->priv->regex_error == NULL)
        {
                return NULL;
        }
 
-       return g_error_copy (search->regex_error);
+       return g_error_copy (search->priv->regex_error);
 }
 
 /**
@@ -3086,12 +3087,12 @@ gtk_source_search_context_get_occurrences_count (GtkSourceSearchContext *search)
 {
        g_return_val_if_fail (GTK_SOURCE_IS_SEARCH_CONTEXT (search), -1);
 
-       if (!gtk_source_region_is_empty (search->scan_region))
+       if (!gtk_source_region_is_empty (search->priv->scan_region))
        {
                return -1;
        }
 
-       return search->occurrences_count;
+       return search->priv->occurrences_count;
 }
 
 /**
@@ -3113,8 +3114,8 @@ gtk_source_search_context_get_occurrences_count (GtkSourceSearchContext *search)
  */
 gint
 gtk_source_search_context_get_occurrence_position (GtkSourceSearchContext *search,
-                                                   const GtkTextIter      *match_start,
-                                                   const GtkTextIter      *match_end)
+                                                  const GtkTextIter      *match_start,
+                                                  const GtkTextIter      *match_end)
 {
        GtkTextIter m_start;
        GtkTextIter m_end;
@@ -3128,16 +3129,16 @@ gtk_source_search_context_get_occurrence_position (GtkSourceSearchContext *searc
        g_return_val_if_fail (match_start != NULL, -1);
        g_return_val_if_fail (match_end != NULL, -1);
 
-       if (search->buffer == NULL)
+       if (search->priv->buffer == NULL)
        {
                return -1;
        }
 
        /* Verify that the [match_start; match_end] region has been scanned. */
 
-       if (search->scan_region != NULL)
+       if (search->priv->scan_region != NULL)
        {
-               region = gtk_source_region_intersect_subregion (search->scan_region,
+               region = gtk_source_region_intersect_subregion (search->priv->scan_region,
                                                                match_start,
                                                                match_end);
 
@@ -3170,11 +3171,11 @@ gtk_source_search_context_get_occurrence_position (GtkSourceSearchContext *searc
         * and the end of the occurrence.
         */
 
-       gtk_text_buffer_get_start_iter (search->buffer, &iter);
+       gtk_text_buffer_get_start_iter (search->priv->buffer, &iter);
 
-       if (search->scan_region != NULL)
+       if (search->priv->scan_region != NULL)
        {
-               region = gtk_source_region_intersect_subregion (search->scan_region,
+               region = gtk_source_region_intersect_subregion (search->priv->scan_region,
                                                                &iter,
                                                                match_end);
 
@@ -3224,10 +3225,10 @@ gtk_source_search_context_get_occurrence_position (GtkSourceSearchContext *searc
  */
 gboolean
 gtk_source_search_context_forward (GtkSourceSearchContext *search,
-                                   const GtkTextIter      *iter,
-                                   GtkTextIter            *match_start,
-                                   GtkTextIter            *match_end,
-                                   gboolean               *has_wrapped_around)
+                                  const GtkTextIter      *iter,
+                                  GtkTextIter            *match_start,
+                                  GtkTextIter            *match_end,
+                                  gboolean               *has_wrapped_around)
 {
        GtkTextIter m_start;
        GtkTextIter m_end;
@@ -3241,17 +3242,17 @@ gtk_source_search_context_forward (GtkSourceSearchContext *search,
                *has_wrapped_around = FALSE;
        }
 
-       if (search->buffer == NULL)
+       if (search->priv->buffer == NULL)
        {
                return FALSE;
        }
 
        found = smart_forward_search (search, iter, &m_start, &m_end);
 
-       if (!found && gtk_source_search_settings_get_wrap_around (search->settings))
+       if (!found && gtk_source_search_settings_get_wrap_around (search->priv->settings))
        {
                GtkTextIter start_iter;
-               gtk_text_buffer_get_start_iter (search->buffer, &start_iter);
+               gtk_text_buffer_get_start_iter (search->priv->buffer, &start_iter);
 
                found = smart_forward_search (search, &start_iter, &m_start, &m_end);
 
@@ -3297,21 +3298,21 @@ gtk_source_search_context_forward (GtkSourceSearchContext *search,
  */
 void
 gtk_source_search_context_forward_async (GtkSourceSearchContext *search,
-                                         const GtkTextIter      *iter,
-                                         GCancellable           *cancellable,
-                                         GAsyncReadyCallback     callback,
-                                         gpointer                user_data)
+                                        const GtkTextIter      *iter,
+                                        GCancellable           *cancellable,
+                                        GAsyncReadyCallback     callback,
+                                        gpointer                user_data)
 {
        g_return_if_fail (GTK_SOURCE_IS_SEARCH_CONTEXT (search));
        g_return_if_fail (iter != NULL);
 
-       if (search->buffer == NULL)
+       if (search->priv->buffer == NULL)
        {
                return;
        }
 
        clear_task (search);
-       search->task = g_task_new (search, cancellable, callback, user_data);
+       search->priv->task = g_task_new (search, cancellable, callback, user_data);
 
        smart_forward_search_async (search, iter, FALSE);
 }
@@ -3337,11 +3338,11 @@ gtk_source_search_context_forward_async (GtkSourceSearchContext *search,
  */
 gboolean
 gtk_source_search_context_forward_finish (GtkSourceSearchContext  *search,
-                                          GAsyncResult            *result,
-                                          GtkTextIter             *match_start,
-                                          GtkTextIter             *match_end,
-                                          gboolean                *has_wrapped_around,
-                                          GError                 **error)
+                                         GAsyncResult            *result,
+                                         GtkTextIter             *match_start,
+                                         GtkTextIter             *match_end,
+                                         gboolean                *has_wrapped_around,
+                                         GError                 **error)
 {
        ForwardBackwardData *data;
        gboolean found;
@@ -3353,7 +3354,7 @@ gtk_source_search_context_forward_finish (GtkSourceSearchContext  *search,
                *has_wrapped_around = FALSE;
        }
 
-       if (search->buffer == NULL)
+       if (search->priv->buffer == NULL)
        {
                return FALSE;
        }
@@ -3373,14 +3374,14 @@ gtk_source_search_context_forward_finish (GtkSourceSearchContext  *search,
        {
                if (match_start != NULL)
                {
-                        gtk_text_buffer_get_iter_at_mark (search->buffer,
+                        gtk_text_buffer_get_iter_at_mark (search->priv->buffer,
                                                           match_start,
                                                           data->match_start);
                }
 
                if (match_end != NULL)
                {
-                        gtk_text_buffer_get_iter_at_mark (search->buffer,
+                        gtk_text_buffer_get_iter_at_mark (search->priv->buffer,
                                                           match_end,
                                                           data->match_end);
                }
@@ -3420,10 +3421,10 @@ gtk_source_search_context_forward_finish (GtkSourceSearchContext  *search,
  */
 gboolean
 gtk_source_search_context_backward (GtkSourceSearchContext *search,
-                                    const GtkTextIter      *iter,
-                                    GtkTextIter            *match_start,
-                                    GtkTextIter            *match_end,
-                                    gboolean               *has_wrapped_around)
+                                   const GtkTextIter      *iter,
+                                   GtkTextIter            *match_start,
+                                   GtkTextIter            *match_end,
+                                   gboolean               *has_wrapped_around)
 {
        GtkTextIter m_start;
        GtkTextIter m_end;
@@ -3437,18 +3438,18 @@ gtk_source_search_context_backward (GtkSourceSearchContext *search,
                *has_wrapped_around = FALSE;
        }
 
-       if (search->buffer == NULL)
+       if (search->priv->buffer == NULL)
        {
                return FALSE;
        }
 
        found = smart_backward_search (search, iter, &m_start, &m_end);
 
-       if (!found && gtk_source_search_settings_get_wrap_around (search->settings))
+       if (!found && gtk_source_search_settings_get_wrap_around (search->priv->settings))
        {
                GtkTextIter end_iter;
 
-               gtk_text_buffer_get_end_iter (search->buffer, &end_iter);
+               gtk_text_buffer_get_end_iter (search->priv->buffer, &end_iter);
 
                found = smart_backward_search (search, &end_iter, &m_start, &m_end);
 
@@ -3494,21 +3495,21 @@ gtk_source_search_context_backward (GtkSourceSearchContext *search,
  */
 void
 gtk_source_search_context_backward_async (GtkSourceSearchContext *search,
-                                          const GtkTextIter      *iter,
-                                          GCancellable           *cancellable,
-                                          GAsyncReadyCallback     callback,
-                                          gpointer                user_data)
+                                         const GtkTextIter      *iter,
+                                         GCancellable           *cancellable,
+                                         GAsyncReadyCallback     callback,
+                                         gpointer                user_data)
 {
        g_return_if_fail (GTK_SOURCE_IS_SEARCH_CONTEXT (search));
        g_return_if_fail (iter != NULL);
 
-       if (search->buffer == NULL)
+       if (search->priv->buffer == NULL)
        {
                return;
        }
 
        clear_task (search);
-       search->task = g_task_new (search, cancellable, callback, user_data);
+       search->priv->task = g_task_new (search, cancellable, callback, user_data);
 
        smart_backward_search_async (search, iter, FALSE);
 }
@@ -3534,11 +3535,11 @@ gtk_source_search_context_backward_async (GtkSourceSearchContext *search,
  */
 gboolean
 gtk_source_search_context_backward_finish (GtkSourceSearchContext  *search,
-                                           GAsyncResult            *result,
-                                           GtkTextIter             *match_start,
-                                           GtkTextIter             *match_end,
-                                           gboolean                *has_wrapped_around,
-                                           GError                 **error)
+                                          GAsyncResult            *result,
+                                          GtkTextIter             *match_start,
+                                          GtkTextIter             *match_end,
+                                          gboolean                *has_wrapped_around,
+                                          GError                 **error)
 {
        return gtk_source_search_context_forward_finish (search,
                                                         result,
@@ -3571,8 +3572,8 @@ regex_replace (GtkSourceSearchContext  *search,
        GError *tmp_error = NULL;
        gboolean replaced = FALSE;
 
-       if (search->regex == NULL ||
-           search->regex_error != NULL)
+       if (search->priv->regex == NULL ||
+           search->priv->regex_error != NULL)
        {
                return FALSE;
        }
@@ -3604,7 +3605,7 @@ regex_replace (GtkSourceSearchContext  *search,
        match_options = regex_search_get_match_options (&real_start, &real_end);
        match_options |= G_REGEX_MATCH_ANCHORED;
 
-       subject_replaced = g_regex_replace (search->regex,
+       subject_replaced = g_regex_replace (search->priv->regex,
                                            subject,
                                            -1,
                                            start_pos,
@@ -3631,10 +3632,10 @@ regex_replace (GtkSourceSearchContext  *search,
 
        match_start_copy = *match_start;
 
-       gtk_text_buffer_begin_user_action (search->buffer);
-       gtk_text_buffer_delete (search->buffer, &match_start_copy, match_end);
-       gtk_text_buffer_insert (search->buffer, match_end, subject_replaced + start_pos, -1);
-       gtk_text_buffer_end_user_action (search->buffer);
+       gtk_text_buffer_begin_user_action (search->priv->buffer);
+       gtk_text_buffer_delete (search->priv->buffer, &match_start_copy, match_end);
+       gtk_text_buffer_insert (search->priv->buffer, match_end, subject_replaced + start_pos, -1);
+       gtk_text_buffer_end_user_action (search->priv->buffer);
 
        replaced = TRUE;
 
@@ -3669,11 +3670,11 @@ end:
  */
 gboolean
 gtk_source_search_context_replace (GtkSourceSearchContext  *search,
-                                   GtkTextIter             *match_start,
-                                   GtkTextIter             *match_end,
-                                   const gchar             *replace,
-                                   gint                     replace_length,
-                                   GError                 **error)
+                                  GtkTextIter             *match_start,
+                                  GtkTextIter             *match_end,
+                                  const gchar             *replace,
+                                  gint                     replace_length,
+                                  GError                 **error)
 {
        GtkTextIter start;
        GtkTextIter end;
@@ -3686,7 +3687,7 @@ gtk_source_search_context_replace (GtkSourceSearchContext  *search,
        g_return_val_if_fail (replace != NULL, FALSE);
        g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
 
-       if (search->buffer == NULL)
+       if (search->priv->buffer == NULL)
        {
                return FALSE;
        }
@@ -3702,29 +3703,29 @@ gtk_source_search_context_replace (GtkSourceSearchContext  *search,
                return FALSE;
        }
 
-       start_mark = gtk_text_buffer_create_mark (search->buffer, NULL, &start, TRUE);
+       start_mark = gtk_text_buffer_create_mark (search->priv->buffer, NULL, &start, TRUE);
 
-       if (gtk_source_search_settings_get_regex_enabled (search->settings))
+       if (gtk_source_search_settings_get_regex_enabled (search->priv->settings))
        {
                replaced = regex_replace (search, &start, &end, replace, error);
        }
        else
        {
-               gtk_text_buffer_begin_user_action (search->buffer);
-               gtk_text_buffer_delete (search->buffer, &start, &end);
-               gtk_text_buffer_insert (search->buffer, &end, replace, replace_length);
-               gtk_text_buffer_end_user_action (search->buffer);
+               gtk_text_buffer_begin_user_action (search->priv->buffer);
+               gtk_text_buffer_delete (search->priv->buffer, &start, &end);
+               gtk_text_buffer_insert (search->priv->buffer, &end, replace, replace_length);
+               gtk_text_buffer_end_user_action (search->priv->buffer);
 
                replaced = TRUE;
        }
 
        if (replaced)
        {
-               gtk_text_buffer_get_iter_at_mark (search->buffer, match_start, start_mark);
+               gtk_text_buffer_get_iter_at_mark (search->priv->buffer, match_start, start_mark);
                *match_end = end;
        }
 
-       gtk_text_buffer_delete_mark (search->buffer, start_mark);
+       gtk_text_buffer_delete_mark (search->priv->buffer, start_mark);
 
        return replaced;
 }
@@ -3748,9 +3749,9 @@ gtk_source_search_context_replace (GtkSourceSearchContext  *search,
  */
 guint
 gtk_source_search_context_replace_all (GtkSourceSearchContext  *search,
-                                       const gchar             *replace,
-                                       gint                     replace_length,
-                                       GError                 **error)
+                                      const gchar             *replace,
+                                      gint                     replace_length,
+                                      GError                 **error)
 {
        GtkTextIter iter;
        GtkTextIter match_start;
@@ -3763,17 +3764,17 @@ gtk_source_search_context_replace_all (GtkSourceSearchContext  *search,
        g_return_val_if_fail (replace != NULL, 0);
        g_return_val_if_fail (error == NULL || *error == NULL, 0);
 
-       if (search->buffer == NULL)
+       if (search->priv->buffer == NULL)
        {
                return 0;
        }
 
-       if (gtk_source_search_settings_get_regex_enabled (search->settings))
+       if (gtk_source_search_settings_get_regex_enabled (search->priv->settings))
        {
                GError *tmp_error = NULL;
 
-               if (search->regex == NULL ||
-                   search->regex_error != NULL)
+               if (search->priv->regex == NULL ||
+                   search->priv->regex_error != NULL)
                {
                        return 0;
                }
@@ -3789,22 +3790,22 @@ gtk_source_search_context_replace_all (GtkSourceSearchContext  *search,
                }
        }
 
-       g_signal_handlers_block_by_func (search->buffer, insert_text_before_cb, search);
-       g_signal_handlers_block_by_func (search->buffer, insert_text_after_cb, search);
-       g_signal_handlers_block_by_func (search->buffer, delete_range_before_cb, search);
-       g_signal_handlers_block_by_func (search->buffer, delete_range_after_cb, search);
+       g_signal_handlers_block_by_func (search->priv->buffer, insert_text_before_cb, search);
+       g_signal_handlers_block_by_func (search->priv->buffer, insert_text_after_cb, search);
+       g_signal_handlers_block_by_func (search->priv->buffer, delete_range_before_cb, search);
+       g_signal_handlers_block_by_func (search->priv->buffer, delete_range_after_cb, search);
 
        highlight_matching_brackets =
-               gtk_source_buffer_get_highlight_matching_brackets (GTK_SOURCE_BUFFER (search->buffer));
+               gtk_source_buffer_get_highlight_matching_brackets (GTK_SOURCE_BUFFER (search->priv->buffer));
 
-       gtk_source_buffer_set_highlight_matching_brackets (GTK_SOURCE_BUFFER (search->buffer),
+       gtk_source_buffer_set_highlight_matching_brackets (GTK_SOURCE_BUFFER (search->priv->buffer),
                                                           FALSE);
 
-       _gtk_source_buffer_save_and_clear_selection (GTK_SOURCE_BUFFER (search->buffer));
+       _gtk_source_buffer_save_and_clear_selection (GTK_SOURCE_BUFFER (search->priv->buffer));
 
-       gtk_text_buffer_get_start_iter (search->buffer, &iter);
+       gtk_text_buffer_get_start_iter (search->priv->buffer, &iter);
 
-       gtk_text_buffer_begin_user_action (search->buffer);
+       gtk_text_buffer_begin_user_action (search->priv->buffer);
 
        while (smart_forward_search (search, &iter, &match_start, &match_end))
        {
@@ -3817,25 +3818,25 @@ gtk_source_search_context_replace_all (GtkSourceSearchContext  *search,
                }
                else
                {
-                       gtk_text_buffer_delete (search->buffer, &match_start, &match_end);
-                       gtk_text_buffer_insert (search->buffer, &match_end, replace, replace_length);
+                       gtk_text_buffer_delete (search->priv->buffer, &match_start, &match_end);
+                       gtk_text_buffer_insert (search->priv->buffer, &match_end, replace, replace_length);
                }
 
                nb_matches_replaced++;
                iter = match_end;
        }
 
-       gtk_text_buffer_end_user_action (search->buffer);
+       gtk_text_buffer_end_user_action (search->priv->buffer);
 
-       _gtk_source_buffer_restore_selection (GTK_SOURCE_BUFFER (search->buffer));
+       _gtk_source_buffer_restore_selection (GTK_SOURCE_BUFFER (search->priv->buffer));
 
-       gtk_source_buffer_set_highlight_matching_brackets (GTK_SOURCE_BUFFER (search->buffer),
+       gtk_source_buffer_set_highlight_matching_brackets (GTK_SOURCE_BUFFER (search->priv->buffer),
                                                           highlight_matching_brackets);
 
-       g_signal_handlers_unblock_by_func (search->buffer, insert_text_before_cb, search);
-       g_signal_handlers_unblock_by_func (search->buffer, insert_text_after_cb, search);
-       g_signal_handlers_unblock_by_func (search->buffer, delete_range_before_cb, search);
-       g_signal_handlers_unblock_by_func (search->buffer, delete_range_after_cb, search);
+       g_signal_handlers_unblock_by_func (search->priv->buffer, insert_text_before_cb, search);
+       g_signal_handlers_unblock_by_func (search->priv->buffer, insert_text_after_cb, search);
+       g_signal_handlers_unblock_by_func (search->priv->buffer, delete_range_before_cb, search);
+       g_signal_handlers_unblock_by_func (search->priv->buffer, delete_range_after_cb, search);
 
        update (search);
 
@@ -3845,9 +3846,9 @@ gtk_source_search_context_replace_all (GtkSourceSearchContext  *search,
 /* Highlight the [start,end] region in priority. */
 void
 _gtk_source_search_context_update_highlight (GtkSourceSearchContext *search,
-                                             const GtkTextIter      *start,
-                                             const GtkTextIter      *end,
-                                             gboolean                synchronous)
+                                            const GtkTextIter      *start,
+                                            const GtkTextIter      *end,
+                                            gboolean                synchronous)
 {
        GtkSourceRegion *region_to_highlight = NULL;
 
@@ -3855,14 +3856,14 @@ _gtk_source_search_context_update_highlight (GtkSourceSearchContext *search,
        g_return_if_fail (start != NULL);
        g_return_if_fail (end != NULL);
 
-       if (search->buffer == NULL ||
-           gtk_source_region_is_empty (search->scan_region) ||
-           !search->highlight)
+       if (search->priv->buffer == NULL ||
+           gtk_source_region_is_empty (search->priv->scan_region) ||
+           !search->priv->highlight)
        {
                return;
        }
 
-       region_to_highlight = gtk_source_region_intersect_subregion (search->scan_region,
+       region_to_highlight = gtk_source_region_intersect_subregion (search->priv->scan_region,
                                                                     start,
                                                                     end);
 
@@ -3873,14 +3874,14 @@ _gtk_source_search_context_update_highlight (GtkSourceSearchContext *search,
 
        if (!synchronous)
        {
-               if (search->high_priority_region == NULL)
+               if (search->priv->high_priority_region == NULL)
                {
-                       search->high_priority_region = region_to_highlight;
+                       search->priv->high_priority_region = region_to_highlight;
                        region_to_highlight = NULL;
                }
                else
                {
-                       gtk_source_region_add_region (search->high_priority_region,
+                       gtk_source_region_add_region (search->priv->high_priority_region,
                                                      region_to_highlight);
                }
 
@@ -3888,11 +3889,11 @@ _gtk_source_search_context_update_highlight (GtkSourceSearchContext *search,
                goto out;
        }
 
-       if (gtk_source_search_settings_get_regex_enabled (search->settings))
+       if (gtk_source_search_settings_get_regex_enabled (search->priv->settings))
        {
                GtkTextIter region_start;
 
-               if (!gtk_source_region_get_bounds (search->scan_region,
+               if (!gtk_source_region_get_bounds (search->priv->scan_region,
                                                   &region_start,
                                                   NULL))
                {
diff --git a/gtksourceview/gtksourcesearchcontext.h b/gtksourceview/gtksourcesearchcontext.h
index bf571c4f..58fae7e6 100644
--- a/gtksourceview/gtksourcesearchcontext.h
+++ b/gtksourceview/gtksourcesearchcontext.h
@@ -2,7 +2,7 @@
  *
  * This file is part of GtkSourceView
  *
- * Copyright 2013, 2016 - Sébastien Wilmet <swilmet gnome org>
+ * Copyright (C) 2013, 2016 - Sébastien Wilmet <swilmet gnome org>
  *
  * GtkSourceView is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -18,7 +18,8 @@
  * along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#pragma once
+#ifndef GTK_SOURCE_SEARCH_CONTEXT_H
+#define GTK_SOURCE_SEARCH_CONTEXT_H
 
 #if !defined (GTK_SOURCE_H_INSIDE) && !defined (GTK_SOURCE_COMPILATION)
 #error "Only <gtksourceview/gtksource.h> can be included directly."
@@ -30,85 +31,126 @@
 
 G_BEGIN_DECLS
 
-#define GTK_SOURCE_TYPE_SEARCH_CONTEXT (gtk_source_search_context_get_type())
+#define GTK_SOURCE_TYPE_SEARCH_CONTEXT             (gtk_source_search_context_get_type ())
+#define GTK_SOURCE_SEARCH_CONTEXT(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), 
GTK_SOURCE_TYPE_SEARCH_CONTEXT, GtkSourceSearchContext))
+#define GTK_SOURCE_SEARCH_CONTEXT_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), 
GTK_SOURCE_TYPE_SEARCH_CONTEXT, GtkSourceSearchContextClass))
+#define GTK_SOURCE_IS_SEARCH_CONTEXT(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), 
GTK_SOURCE_TYPE_SEARCH_CONTEXT))
+#define GTK_SOURCE_IS_SEARCH_CONTEXT_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), 
GTK_SOURCE_TYPE_SEARCH_CONTEXT))
+#define GTK_SOURCE_SEARCH_CONTEXT_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), 
GTK_SOURCE_TYPE_SEARCH_CONTEXT, GtkSourceSearchContextClass))
+
+typedef struct _GtkSourceSearchContextClass    GtkSourceSearchContextClass;
+typedef struct _GtkSourceSearchContextPrivate  GtkSourceSearchContextPrivate;
+
+struct _GtkSourceSearchContext
+{
+       GObject parent;
+
+       GtkSourceSearchContextPrivate *priv;
+};
+
+struct _GtkSourceSearchContextClass
+{
+       GObjectClass parent_class;
+
+       gpointer padding[10];
+};
 
 GTK_SOURCE_AVAILABLE_IN_3_10
-G_DECLARE_FINAL_TYPE (GtkSourceSearchContext, gtk_source_search_context, GTK_SOURCE, SEARCH_CONTEXT, GObject)
+GType                   gtk_source_search_context_get_type                     (void) G_GNUC_CONST;
 
 GTK_SOURCE_AVAILABLE_IN_3_10
-GtkSourceSearchContext  *gtk_source_search_context_new                     (GtkSourceBuffer          *buffer,
-                                                                            GtkSourceSearchSettings  
*settings);
+GtkSourceSearchContext *gtk_source_search_context_new                          (GtkSourceBuffer         
*buffer,
+                                                                                GtkSourceSearchSettings 
*settings);
+
 GTK_SOURCE_AVAILABLE_IN_3_10
-GtkSourceBuffer         *gtk_source_search_context_get_buffer              (GtkSourceSearchContext   
*search);
+GtkSourceBuffer                *gtk_source_search_context_get_buffer                   
(GtkSourceSearchContext  *search);
+
 GTK_SOURCE_AVAILABLE_IN_3_10
-GtkSourceSearchSettings *gtk_source_search_context_get_settings            (GtkSourceSearchContext   
*search);
+GtkSourceSearchSettings        *gtk_source_search_context_get_settings                 
(GtkSourceSearchContext  *search);
+
 GTK_SOURCE_AVAILABLE_IN_3_10
-gboolean                 gtk_source_search_context_get_highlight           (GtkSourceSearchContext   
*search);
+gboolean                gtk_source_search_context_get_highlight                (GtkSourceSearchContext  
*search);
+
 GTK_SOURCE_AVAILABLE_IN_3_10
-void                     gtk_source_search_context_set_highlight           (GtkSourceSearchContext   *search,
-                                                                            gboolean                  
highlight);
+void                    gtk_source_search_context_set_highlight                (GtkSourceSearchContext  
*search,
+                                                                                gboolean                 
highlight);
+
 GTK_SOURCE_AVAILABLE_IN_3_16
-GtkSourceStyle          *gtk_source_search_context_get_match_style         (GtkSourceSearchContext   
*search);
+GtkSourceStyle         *gtk_source_search_context_get_match_style              (GtkSourceSearchContext  
*search);
+
 GTK_SOURCE_AVAILABLE_IN_3_16
-void                     gtk_source_search_context_set_match_style         (GtkSourceSearchContext   *search,
-                                                                            GtkSourceStyle           
*match_style);
+void                    gtk_source_search_context_set_match_style              (GtkSourceSearchContext  
*search,
+                                                                                GtkSourceStyle          
*match_style);
+
 GTK_SOURCE_AVAILABLE_IN_3_10
-GError                  *gtk_source_search_context_get_regex_error         (GtkSourceSearchContext   
*search);
+GError                 *gtk_source_search_context_get_regex_error              (GtkSourceSearchContext  
*search);
+
 GTK_SOURCE_AVAILABLE_IN_3_10
-gint                     gtk_source_search_context_get_occurrences_count   (GtkSourceSearchContext   
*search);
+gint                    gtk_source_search_context_get_occurrences_count        (GtkSourceSearchContext  
*search);
+
 GTK_SOURCE_AVAILABLE_IN_3_10
-gint                     gtk_source_search_context_get_occurrence_position (GtkSourceSearchContext   *search,
-                                                                            const GtkTextIter        
*match_start,
-                                                                            const GtkTextIter        
*match_end);
+gint                    gtk_source_search_context_get_occurrence_position      (GtkSourceSearchContext  
*search,
+                                                                                const GtkTextIter       
*match_start,
+                                                                                const GtkTextIter       
*match_end);
+
 GTK_SOURCE_AVAILABLE_IN_4_0
-gboolean                 gtk_source_search_context_forward                 (GtkSourceSearchContext   *search,
-                                                                            const GtkTextIter        *iter,
-                                                                            GtkTextIter              
*match_start,
-                                                                            GtkTextIter              
*match_end,
-                                                                            gboolean                 
*has_wrapped_around);
+gboolean                gtk_source_search_context_forward                      (GtkSourceSearchContext 
*search,
+                                                                                const GtkTextIter      *iter,
+                                                                                GtkTextIter            
*match_start,
+                                                                                GtkTextIter            
*match_end,
+                                                                                gboolean               
*has_wrapped_around);
+
 GTK_SOURCE_AVAILABLE_IN_3_10
-void                     gtk_source_search_context_forward_async           (GtkSourceSearchContext   *search,
-                                                                            const GtkTextIter        *iter,
-                                                                            GCancellable             
*cancellable,
-                                                                            GAsyncReadyCallback       
callback,
-                                                                            gpointer                  
user_data);
+void                    gtk_source_search_context_forward_async                (GtkSourceSearchContext  
*search,
+                                                                                const GtkTextIter       
*iter,
+                                                                                GCancellable            
*cancellable,
+                                                                                GAsyncReadyCallback      
callback,
+                                                                                gpointer                 
user_data);
+
 GTK_SOURCE_AVAILABLE_IN_4_0
-gboolean                 gtk_source_search_context_forward_finish          (GtkSourceSearchContext   *search,
-                                                                            GAsyncResult             *result,
-                                                                            GtkTextIter              
*match_start,
-                                                                            GtkTextIter              
*match_end,
-                                                                            gboolean                 
*has_wrapped_around,
-                                                                            GError                  **error);
+gboolean                gtk_source_search_context_forward_finish               (GtkSourceSearchContext  
*search,
+                                                                                GAsyncResult            
*result,
+                                                                                GtkTextIter             
*match_start,
+                                                                                GtkTextIter             
*match_end,
+                                                                                gboolean                
*has_wrapped_around,
+                                                                                GError                 
**error);
+
 GTK_SOURCE_AVAILABLE_IN_4_0
-gboolean                 gtk_source_search_context_backward                (GtkSourceSearchContext   *search,
-                                                                            const GtkTextIter        *iter,
-                                                                            GtkTextIter              
*match_start,
-                                                                            GtkTextIter              
*match_end,
-                                                                            gboolean                 
*has_wrapped_around);
+gboolean                gtk_source_search_context_backward                     (GtkSourceSearchContext 
*search,
+                                                                                const GtkTextIter      *iter,
+                                                                                GtkTextIter            
*match_start,
+                                                                                GtkTextIter            
*match_end,
+                                                                                gboolean               
*has_wrapped_around);
+
 GTK_SOURCE_AVAILABLE_IN_3_10
-void                     gtk_source_search_context_backward_async          (GtkSourceSearchContext   *search,
-                                                                            const GtkTextIter        *iter,
-                                                                            GCancellable             
*cancellable,
-                                                                            GAsyncReadyCallback       
callback,
-                                                                            gpointer                  
user_data);
+void                    gtk_source_search_context_backward_async               (GtkSourceSearchContext  
*search,
+                                                                                const GtkTextIter       
*iter,
+                                                                                GCancellable            
*cancellable,
+                                                                                GAsyncReadyCallback      
callback,
+                                                                                gpointer                 
user_data);
+
 GTK_SOURCE_AVAILABLE_IN_4_0
-gboolean                 gtk_source_search_context_backward_finish         (GtkSourceSearchContext   *search,
-                                                                            GAsyncResult             *result,
-                                                                            GtkTextIter              
*match_start,
-                                                                            GtkTextIter              
*match_end,
-                                                                            gboolean                 
*has_wrapped_around,
-                                                                            GError                  **error);
+gboolean                gtk_source_search_context_backward_finish              (GtkSourceSearchContext  
*search,
+                                                                                GAsyncResult            
*result,
+                                                                                GtkTextIter             
*match_start,
+                                                                                GtkTextIter             
*match_end,
+                                                                                gboolean                
*has_wrapped_around,
+                                                                                GError                 
**error);
+
 GTK_SOURCE_AVAILABLE_IN_4_0
-gboolean                 gtk_source_search_context_replace                 (GtkSourceSearchContext   *search,
-                                                                            GtkTextIter              
*match_start,
-                                                                            GtkTextIter              
*match_end,
-                                                                            const gchar              
*replace,
-                                                                            gint                      
replace_length,
-                                                                            GError                  **error);
+gboolean                gtk_source_search_context_replace                      (GtkSourceSearchContext  
*search,
+                                                                                GtkTextIter             
*match_start,
+                                                                                GtkTextIter             
*match_end,
+                                                                                const gchar             
*replace,
+                                                                                gint                     
replace_length,
+                                                                                GError                 
**error);
+
 GTK_SOURCE_AVAILABLE_IN_3_10
-guint                    gtk_source_search_context_replace_all             (GtkSourceSearchContext   *search,
-                                                                            const gchar              
*replace,
-                                                                            gint                      
replace_length,
-                                                                            GError                  **error);
+guint                   gtk_source_search_context_replace_all                  (GtkSourceSearchContext  
*search,
+                                                                                const gchar             
*replace,
+                                                                                gint                     
replace_length,
+                                                                                GError                 
**error);
 
 G_END_DECLS
+
+#endif /* GTK_SOURCE_SEARCH_CONTEXT_H */
diff --git a/gtksourceview/gtksourcesearchsettings.c b/gtksourceview/gtksourcesearchsettings.c
index d9cbbb34..07699f58 100644
--- a/gtksourceview/gtksourcesearchsettings.c
+++ b/gtksourceview/gtksourcesearchsettings.c
@@ -2,7 +2,7 @@
 /*
  * This file is part of GtkSourceView
  *
- * Copyright 2013 - Sébastien Wilmet <swilmet gnome org>
+ * Copyright (C) 2013 - Sébastien Wilmet <swilmet gnome org>
  *
  * GtkSourceView is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -18,7 +18,9 @@
  * along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "config.h"
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
 
 #include "gtksourcesearchsettings.h"
 
@@ -40,63 +42,62 @@ enum
        PROP_CASE_SENSITIVE,
        PROP_AT_WORD_BOUNDARIES,
        PROP_WRAP_AROUND,
-       PROP_REGEX_ENABLED,
-       N_PROPS
+       PROP_REGEX_ENABLED
 };
 
-typedef struct
+struct _GtkSourceSearchSettingsPrivate
 {
        gchar *search_text;
        guint case_sensitive : 1;
        guint at_word_boundaries : 1;
        guint wrap_around : 1;
        guint regex_enabled : 1;
-} GtkSourceSearchSettingsPrivate;
+};
 
 G_DEFINE_TYPE_WITH_PRIVATE (GtkSourceSearchSettings, gtk_source_search_settings, G_TYPE_OBJECT)
 
-static GParamSpec *properties[N_PROPS];
-
 static void
 gtk_source_search_settings_finalize (GObject *object)
 {
        GtkSourceSearchSettings *settings = GTK_SOURCE_SEARCH_SETTINGS (object);
-       GtkSourceSearchSettingsPrivate *priv = gtk_source_search_settings_get_instance_private (settings);
 
-       g_free (priv->search_text);
+       g_free (settings->priv->search_text);
 
        G_OBJECT_CLASS (gtk_source_search_settings_parent_class)->finalize (object);
 }
 
 static void
 gtk_source_search_settings_get_property (GObject    *object,
-                                         guint       prop_id,
-                                         GValue     *value,
-                                         GParamSpec *pspec)
+                                        guint       prop_id,
+                                        GValue     *value,
+                                        GParamSpec *pspec)
 {
-       GtkSourceSearchSettings *settings = GTK_SOURCE_SEARCH_SETTINGS (object);
-       GtkSourceSearchSettingsPrivate *priv = gtk_source_search_settings_get_instance_private (settings);
+       GtkSourceSearchSettings *settings;
+
+       g_return_if_fail (GTK_SOURCE_IS_SEARCH_SETTINGS (object));
+
+       settings = GTK_SOURCE_SEARCH_SETTINGS (object);
 
        switch (prop_id)
        {
                case PROP_SEARCH_TEXT:
-                       g_value_set_string (value, priv->search_text);
+                       g_value_set_string (value, settings->priv->search_text);
                        break;
 
                case PROP_CASE_SENSITIVE:
-                       g_value_set_boolean (value, priv->case_sensitive);
+                       g_value_set_boolean (value, settings->priv->case_sensitive);
                        break;
 
                case PROP_AT_WORD_BOUNDARIES:
-                       g_value_set_boolean (value, priv->at_word_boundaries);
+                       g_value_set_boolean (value, settings->priv->at_word_boundaries);
                        break;
 
                case PROP_WRAP_AROUND:
-                       g_value_set_boolean (value, priv->wrap_around);
+                       g_value_set_boolean (value, settings->priv->wrap_around);
                        break;
 
                case PROP_REGEX_ENABLED:
-                       g_value_set_boolean (value, priv->regex_enabled);
+                       g_value_set_boolean (value, settings->priv->regex_enabled);
                        break;
 
                default:
@@ -107,12 +108,15 @@ gtk_source_search_settings_get_property (GObject    *object,
 
 static void
 gtk_source_search_settings_set_property (GObject      *object,
-                                         guint         prop_id,
-                                         const GValue *value,
-                                         GParamSpec   *pspec)
+                                        guint         prop_id,
+                                        const GValue *value,
+                                        GParamSpec   *pspec)
 {
-       GtkSourceSearchSettings *settings = GTK_SOURCE_SEARCH_SETTINGS (object);
-       GtkSourceSearchSettingsPrivate *priv = gtk_source_search_settings_get_instance_private (settings);
+       GtkSourceSearchSettings *settings;
+
+       g_return_if_fail (GTK_SOURCE_IS_SEARCH_SETTINGS (object));
+
+       settings = GTK_SOURCE_SEARCH_SETTINGS (object);
 
        switch (prop_id)
        {
@@ -121,19 +125,19 @@ gtk_source_search_settings_set_property (GObject      *object,
                        break;
 
                case PROP_CASE_SENSITIVE:
-                       priv->case_sensitive = g_value_get_boolean (value);
+                       settings->priv->case_sensitive = g_value_get_boolean (value);
                        break;
 
                case PROP_AT_WORD_BOUNDARIES:
-                       priv->at_word_boundaries = g_value_get_boolean (value);
+                       settings->priv->at_word_boundaries = g_value_get_boolean (value);
                        break;
 
                case PROP_WRAP_AROUND:
-                       priv->wrap_around = g_value_get_boolean (value);
+                       settings->priv->wrap_around = g_value_get_boolean (value);
                        break;
 
                case PROP_REGEX_ENABLED:
-                       priv->regex_enabled = g_value_get_boolean (value);
+                       settings->priv->regex_enabled = g_value_get_boolean (value);
                        break;
 
                default:
@@ -160,12 +164,15 @@ gtk_source_search_settings_class_init (GtkSourceSearchSettingsClass *klass)
         *
         * Since: 3.10
         */
-       properties[PROP_SEARCH_TEXT] =
-               g_param_spec_string ("search-text",
-                                    "Search text",
-                                    "The text to search",
-                                    NULL,
-                                    G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS);
+       g_object_class_install_property (object_class,
+                                        PROP_SEARCH_TEXT,
+                                        g_param_spec_string ("search-text",
+                                                             "Search text",
+                                                             "The text to search",
+                                                             NULL,
+                                                             G_PARAM_READWRITE |
+                                                             G_PARAM_CONSTRUCT |
+                                                             G_PARAM_STATIC_STRINGS));
 
        /**
         * GtkSourceSearchSettings:case-sensitive:
@@ -174,12 +181,15 @@ gtk_source_search_settings_class_init (GtkSourceSearchSettingsClass *klass)
         *
         * Since: 3.10
         */
-       properties[PROP_CASE_SENSITIVE] =
-               g_param_spec_boolean ("case-sensitive",
-                                     "Case sensitive",
-                                     "Case sensitive",
-                                     FALSE,
-                                     G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS);
+       g_object_class_install_property (object_class,
+                                        PROP_CASE_SENSITIVE,
+                                        g_param_spec_boolean ("case-sensitive",
+                                                              "Case sensitive",
+                                                              "Case sensitive",
+                                                              FALSE,
+                                                              G_PARAM_READWRITE |
+                                                              G_PARAM_CONSTRUCT |
+                                                              G_PARAM_STATIC_STRINGS));
 
        /**
         * GtkSourceSearchSettings:at-word-boundaries:
@@ -189,12 +199,15 @@ gtk_source_search_settings_class_init (GtkSourceSearchSettingsClass *klass)
         *
         * Since: 3.10
         */
-       properties[PROP_AT_WORD_BOUNDARIES] =
-               g_param_spec_boolean ("at-word-boundaries",
-                                     "At word boundaries",
-                                     "Search at word boundaries",
-                                     FALSE,
-                                     G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS);
+       g_object_class_install_property (object_class,
+                                        PROP_AT_WORD_BOUNDARIES,
+                                        g_param_spec_boolean ("at-word-boundaries",
+                                                              "At word boundaries",
+                                                              "Search at word boundaries",
+                                                              FALSE,
+                                                              G_PARAM_READWRITE |
+                                                              G_PARAM_CONSTRUCT |
+                                                              G_PARAM_STATIC_STRINGS));
 
        /**
         * GtkSourceSearchSettings:wrap-around:
@@ -205,12 +218,15 @@ gtk_source_search_settings_class_init (GtkSourceSearchSettingsClass *klass)
         *
         * Since: 3.10
         */
-       properties[PROP_WRAP_AROUND] =
-               g_param_spec_boolean ("wrap-around",
-                                     "Wrap around",
-                                     "Wrap around",
-                                     FALSE,
-                                     G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS);
+       g_object_class_install_property (object_class,
+                                        PROP_WRAP_AROUND,
+                                        g_param_spec_boolean ("wrap-around",
+                                                              "Wrap around",
+                                                              "Wrap around",
+                                                              FALSE,
+                                                              G_PARAM_READWRITE |
+                                                              G_PARAM_CONSTRUCT |
+                                                              G_PARAM_STATIC_STRINGS));
 
        /**
         * GtkSourceSearchSettings:regex-enabled:
@@ -220,19 +236,21 @@ gtk_source_search_settings_class_init (GtkSourceSearchSettingsClass *klass)
         *
         * Since: 3.10
         */
-       properties[PROP_REGEX_ENABLED] =
-               g_param_spec_boolean ("regex-enabled",
-                                     "Regex enabled",
-                                     "Whether to search by regular expression",
-                                     FALSE,
-                                     G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS);
-
-       g_object_class_install_properties (object_class, N_PROPS, properties);
+       g_object_class_install_property (object_class,
+                                        PROP_REGEX_ENABLED,
+                                        g_param_spec_boolean ("regex-enabled",
+                                                              "Regex enabled",
+                                                              "Whether to search by regular expression",
+                                                              FALSE,
+                                                              G_PARAM_READWRITE |
+                                                              G_PARAM_CONSTRUCT |
+                                                              G_PARAM_STATIC_STRINGS));
 }
 
 static void
 gtk_source_search_settings_init (GtkSourceSearchSettings *self)
 {
+       self->priv = gtk_source_search_settings_get_instance_private (self);
 }
 
 /**
@@ -265,32 +283,30 @@ gtk_source_search_settings_new (void)
  */
 void
 gtk_source_search_settings_set_search_text (GtkSourceSearchSettings *settings,
-                                            const gchar             *search_text)
+                                           const gchar             *search_text)
 {
-       GtkSourceSearchSettingsPrivate *priv = gtk_source_search_settings_get_instance_private (settings);
-
        g_return_if_fail (GTK_SOURCE_IS_SEARCH_SETTINGS (settings));
        g_return_if_fail (search_text == NULL || g_utf8_validate (search_text, -1, NULL));
 
-       if ((priv->search_text == NULL &&
+       if ((settings->priv->search_text == NULL &&
             (search_text == NULL || search_text[0] == '\0')) ||
-           g_strcmp0 (priv->search_text, search_text) == 0)
+           g_strcmp0 (settings->priv->search_text, search_text) == 0)
        {
                return;
        }
 
-       g_free (priv->search_text);
+       g_free (settings->priv->search_text);
 
        if (search_text == NULL || search_text[0] == '\0')
        {
-               priv->search_text = NULL;
+               settings->priv->search_text = NULL;
        }
        else
        {
-               priv->search_text = g_strdup (search_text);
+               settings->priv->search_text = g_strdup (search_text);
        }
 
-       g_object_notify_by_pspec (G_OBJECT (settings), properties[PROP_SEARCH_TEXT]);
+       g_object_notify (G_OBJECT (settings), "search-text");
 }
 
 /**
@@ -308,11 +324,9 @@ gtk_source_search_settings_set_search_text (GtkSourceSearchSettings *settings,
 const gchar *
 gtk_source_search_settings_get_search_text (GtkSourceSearchSettings *settings)
 {
-       GtkSourceSearchSettingsPrivate *priv = gtk_source_search_settings_get_instance_private (settings);
-
        g_return_val_if_fail (GTK_SOURCE_IS_SEARCH_SETTINGS (settings), NULL);
 
-       return priv->search_text;
+       return settings->priv->search_text;
 }
 
 /**
@@ -326,18 +340,16 @@ gtk_source_search_settings_get_search_text (GtkSourceSearchSettings *settings)
  */
 void
 gtk_source_search_settings_set_case_sensitive (GtkSourceSearchSettings *settings,
-                                               gboolean                 case_sensitive)
+                                              gboolean                 case_sensitive)
 {
-       GtkSourceSearchSettingsPrivate *priv = gtk_source_search_settings_get_instance_private (settings);
-
        g_return_if_fail (GTK_SOURCE_IS_SEARCH_SETTINGS (settings));
 
        case_sensitive = case_sensitive != FALSE;
 
-       if (priv->case_sensitive != case_sensitive)
+       if (settings->priv->case_sensitive != case_sensitive)
        {
-               priv->case_sensitive = case_sensitive;
-               g_object_notify_by_pspec (G_OBJECT (settings), properties[PROP_CASE_SENSITIVE]);
+               settings->priv->case_sensitive = case_sensitive;
+               g_object_notify (G_OBJECT (settings), "case-sensitive");
        }
 }
 
@@ -351,11 +363,9 @@ gtk_source_search_settings_set_case_sensitive (GtkSourceSearchSettings *settings
 gboolean
 gtk_source_search_settings_get_case_sensitive (GtkSourceSearchSettings *settings)
 {
-       GtkSourceSearchSettingsPrivate *priv = gtk_source_search_settings_get_instance_private (settings);
-
        g_return_val_if_fail (GTK_SOURCE_IS_SEARCH_SETTINGS (settings), FALSE);
 
-       return priv->case_sensitive;
+       return settings->priv->case_sensitive;
 }
 
 /**
@@ -372,18 +382,16 @@ gtk_source_search_settings_get_case_sensitive (GtkSourceSearchSettings *settings
  */
 void
 gtk_source_search_settings_set_at_word_boundaries (GtkSourceSearchSettings *settings,
-                                                   gboolean                 at_word_boundaries)
+                                                  gboolean                 at_word_boundaries)
 {
-       GtkSourceSearchSettingsPrivate *priv = gtk_source_search_settings_get_instance_private (settings);
-
        g_return_if_fail (GTK_SOURCE_IS_SEARCH_SETTINGS (settings));
 
        at_word_boundaries = at_word_boundaries != FALSE;
 
-       if (priv->at_word_boundaries != at_word_boundaries)
+       if (settings->priv->at_word_boundaries != at_word_boundaries)
        {
-               priv->at_word_boundaries = at_word_boundaries;
-               g_object_notify_by_pspec (G_OBJECT (settings), properties[PROP_AT_WORD_BOUNDARIES]);
+               settings->priv->at_word_boundaries = at_word_boundaries;
+               g_object_notify (G_OBJECT (settings), "at-word-boundaries");
        }
 }
 
@@ -397,11 +405,9 @@ gtk_source_search_settings_set_at_word_boundaries (GtkSourceSearchSettings *sett
 gboolean
 gtk_source_search_settings_get_at_word_boundaries (GtkSourceSearchSettings *settings)
 {
-       GtkSourceSearchSettingsPrivate *priv = gtk_source_search_settings_get_instance_private (settings);
-
        g_return_val_if_fail (GTK_SOURCE_IS_SEARCH_SETTINGS (settings), FALSE);
 
-       return priv->at_word_boundaries;
+       return settings->priv->at_word_boundaries;
 }
 
 /**
@@ -418,18 +424,16 @@ gtk_source_search_settings_get_at_word_boundaries (GtkSourceSearchSettings *sett
  */
 void
 gtk_source_search_settings_set_wrap_around (GtkSourceSearchSettings *settings,
-                                            gboolean                 wrap_around)
+                                           gboolean                 wrap_around)
 {
-       GtkSourceSearchSettingsPrivate *priv = gtk_source_search_settings_get_instance_private (settings);
-
        g_return_if_fail (GTK_SOURCE_IS_SEARCH_SETTINGS (settings));
 
        wrap_around = wrap_around != FALSE;
 
-       if (priv->wrap_around != wrap_around)
+       if (settings->priv->wrap_around != wrap_around)
        {
-               priv->wrap_around = wrap_around;
-               g_object_notify_by_pspec (G_OBJECT (settings), properties[PROP_WRAP_AROUND]);
+               settings->priv->wrap_around = wrap_around;
+               g_object_notify (G_OBJECT (settings), "wrap-around");
        }
 }
 
@@ -443,11 +447,9 @@ gtk_source_search_settings_set_wrap_around (GtkSourceSearchSettings *settings,
 gboolean
 gtk_source_search_settings_get_wrap_around (GtkSourceSearchSettings *settings)
 {
-       GtkSourceSearchSettingsPrivate *priv = gtk_source_search_settings_get_instance_private (settings);
-
        g_return_val_if_fail (GTK_SOURCE_IS_SEARCH_SETTINGS (settings), FALSE);
 
-       return priv->wrap_around;
+       return settings->priv->wrap_around;
 }
 
 /**
@@ -467,18 +469,16 @@ gtk_source_search_settings_get_wrap_around (GtkSourceSearchSettings *settings)
  */
 void
 gtk_source_search_settings_set_regex_enabled (GtkSourceSearchSettings *settings,
-                                              gboolean                 regex_enabled)
+                                             gboolean                 regex_enabled)
 {
-       GtkSourceSearchSettingsPrivate *priv = gtk_source_search_settings_get_instance_private (settings);
-
        g_return_if_fail (GTK_SOURCE_IS_SEARCH_SETTINGS (settings));
 
        regex_enabled = regex_enabled != FALSE;
 
-       if (priv->regex_enabled != regex_enabled)
+       if (settings->priv->regex_enabled != regex_enabled)
        {
-               priv->regex_enabled = regex_enabled;
-               g_object_notify_by_pspec (G_OBJECT (settings), properties[PROP_REGEX_ENABLED]);
+               settings->priv->regex_enabled = regex_enabled;
+               g_object_notify (G_OBJECT (settings), "regex-enabled");
        }
 }
 
@@ -492,9 +492,7 @@ gtk_source_search_settings_set_regex_enabled (GtkSourceSearchSettings *settings,
 gboolean
 gtk_source_search_settings_get_regex_enabled (GtkSourceSearchSettings *settings)
 {
-       GtkSourceSearchSettingsPrivate *priv = gtk_source_search_settings_get_instance_private (settings);
-
        g_return_val_if_fail (GTK_SOURCE_IS_SEARCH_SETTINGS (settings), FALSE);
 
-       return priv->regex_enabled;
+       return settings->priv->regex_enabled;
 }
diff --git a/gtksourceview/gtksourcesearchsettings.h b/gtksourceview/gtksourcesearchsettings.h
index 9c0f3b63..7c8f448e 100644
--- a/gtksourceview/gtksourcesearchsettings.h
+++ b/gtksourceview/gtksourcesearchsettings.h
@@ -2,7 +2,7 @@
 /*
  * This file is part of GtkSourceView
  *
- * Copyright 2013 - Sébastien Wilmet <swilmet gnome org>
+ * Copyright (C) 2013 - Sébastien Wilmet <swilmet gnome org>
  *
  * GtkSourceView is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -18,7 +18,8 @@
  * along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#pragma once
+#ifndef GTK_SOURCE_SEARCH_SETTINGS_H
+#define GTK_SOURCE_SEARCH_SETTINGS_H
 
 #if !defined (GTK_SOURCE_H_INSIDE) && !defined (GTK_SOURCE_COMPILATION)
 #error "Only <gtksourceview/gtksource.h> can be included directly."
@@ -30,45 +31,71 @@
 
 G_BEGIN_DECLS
 
-#define GTK_SOURCE_TYPE_SEARCH_SETTINGS (gtk_source_search_settings_get_type())
+#define GTK_SOURCE_TYPE_SEARCH_SETTINGS             (gtk_source_search_settings_get_type ())
+#define GTK_SOURCE_SEARCH_SETTINGS(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), 
GTK_SOURCE_TYPE_SEARCH_SETTINGS, GtkSourceSearchSettings))
+#define GTK_SOURCE_SEARCH_SETTINGS_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), 
GTK_SOURCE_TYPE_SEARCH_SETTINGS, GtkSourceSearchSettingsClass))
+#define GTK_SOURCE_IS_SEARCH_SETTINGS(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), 
GTK_SOURCE_TYPE_SEARCH_SETTINGS))
+#define GTK_SOURCE_IS_SEARCH_SETTINGS_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), 
GTK_SOURCE_TYPE_SEARCH_SETTINGS))
+#define GTK_SOURCE_SEARCH_SETTINGS_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), 
GTK_SOURCE_TYPE_SEARCH_SETTINGS, GtkSourceSearchSettingsClass))
 
-GTK_SOURCE_AVAILABLE_IN_ALL
-G_DECLARE_DERIVABLE_TYPE (GtkSourceSearchSettings, gtk_source_search_settings, GTK_SOURCE, SEARCH_SETTINGS, 
GObject)
+typedef struct _GtkSourceSearchSettingsClass    GtkSourceSearchSettingsClass;
+typedef struct _GtkSourceSearchSettingsPrivate  GtkSourceSearchSettingsPrivate;
+
+struct _GtkSourceSearchSettings
+{
+       GObject parent;
+
+       GtkSourceSearchSettingsPrivate *priv;
+};
 
 struct _GtkSourceSearchSettingsClass
 {
        GObjectClass parent_class;
 
-       /*< private >*/
-       gpointer _reserved[10];
+       gpointer padding[10];
 };
 
 GTK_SOURCE_AVAILABLE_IN_ALL
-GtkSourceSearchSettings *gtk_source_search_settings_new                    (void);
+GType                   gtk_source_search_settings_get_type                    (void) G_GNUC_CONST;
+
+GTK_SOURCE_AVAILABLE_IN_ALL
+GtkSourceSearchSettings *gtk_source_search_settings_new                                (void);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-void                     gtk_source_search_settings_set_search_text        (GtkSourceSearchSettings 
*settings,
-                                                                            const gchar             
*search_text);
+void                    gtk_source_search_settings_set_search_text             (GtkSourceSearchSettings 
*settings,
+                                                                                const gchar             
*search_text);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-const gchar             *gtk_source_search_settings_get_search_text        (GtkSourceSearchSettings 
*settings);
+const gchar            *gtk_source_search_settings_get_search_text             (GtkSourceSearchSettings 
*settings);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-void                     gtk_source_search_settings_set_case_sensitive     (GtkSourceSearchSettings 
*settings,
-                                                                            gboolean                 
case_sensitive);
+void                    gtk_source_search_settings_set_case_sensitive          (GtkSourceSearchSettings 
*settings,
+                                                                                gboolean                 
case_sensitive);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-gboolean                 gtk_source_search_settings_get_case_sensitive     (GtkSourceSearchSettings 
*settings);
+gboolean                gtk_source_search_settings_get_case_sensitive          (GtkSourceSearchSettings 
*settings);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-void                     gtk_source_search_settings_set_at_word_boundaries (GtkSourceSearchSettings 
*settings,
-                                                                            gboolean                 
at_word_boundaries);
+void                    gtk_source_search_settings_set_at_word_boundaries      (GtkSourceSearchSettings 
*settings,
+                                                                                gboolean                 
at_word_boundaries);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-gboolean                 gtk_source_search_settings_get_at_word_boundaries (GtkSourceSearchSettings 
*settings);
+gboolean                gtk_source_search_settings_get_at_word_boundaries      (GtkSourceSearchSettings 
*settings);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-void                     gtk_source_search_settings_set_wrap_around        (GtkSourceSearchSettings 
*settings,
-                                                                            gboolean                 
wrap_around);
+void                    gtk_source_search_settings_set_wrap_around             (GtkSourceSearchSettings 
*settings,
+                                                                                gboolean                 
wrap_around);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-gboolean                 gtk_source_search_settings_get_wrap_around        (GtkSourceSearchSettings 
*settings);
+gboolean                gtk_source_search_settings_get_wrap_around             (GtkSourceSearchSettings 
*settings);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-void                     gtk_source_search_settings_set_regex_enabled      (GtkSourceSearchSettings 
*settings,
-                                                                            gboolean                 
regex_enabled);
+void                    gtk_source_search_settings_set_regex_enabled           (GtkSourceSearchSettings 
*settings,
+                                                                                gboolean                 
regex_enabled);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-gboolean                 gtk_source_search_settings_get_regex_enabled      (GtkSourceSearchSettings 
*settings);
+gboolean                gtk_source_search_settings_get_regex_enabled           (GtkSourceSearchSettings 
*settings);
 
 G_END_DECLS
+
+#endif /* GTK_SOURCE_SEARCH_SETTINGS_H */
diff --git a/gtksourceview/gtksourcespacedrawer-private.h b/gtksourceview/gtksourcespacedrawer-private.h
index e7d3a5b4..0a1a9c48 100644
--- a/gtksourceview/gtksourcespacedrawer-private.h
+++ b/gtksourceview/gtksourcespacedrawer-private.h
@@ -2,7 +2,7 @@
 /*
  * This file is part of GtkSourceView
  *
- * Copyright 2016 - Sébastien Wilmet <swilmet gnome org>
+ * Copyright (C) 2016 - Sébastien Wilmet <swilmet gnome org>
  *
  * GtkSourceView is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -18,21 +18,24 @@
  * along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#pragma once
+#ifndef GTK_SOURCE_SPACE_DRAWER_PRIVATE_H
+#define GTK_SOURCE_SPACE_DRAWER_PRIVATE_H
 
 #include <gtk/gtk.h>
-
 #include "gtksourcetypes.h"
 #include "gtksourcetypes-private.h"
 
 G_BEGIN_DECLS
 
-GTK_SOURCE_INTERNAL
+G_GNUC_INTERNAL
 void _gtk_source_space_drawer_update_color (GtkSourceSpaceDrawer *drawer,
                                             GtkSourceView        *view);
-GTK_SOURCE_INTERNAL
+
+G_GNUC_INTERNAL
 void _gtk_source_space_drawer_draw         (GtkSourceSpaceDrawer *drawer,
                                             GtkSourceView        *view,
-                                            cairo_t              *cr);
+                                            GtkSnapshot          *snapshot);
 
 G_END_DECLS
+
+#endif /* GTK_SOURCE_SPACE_DRAWER_PRIVATE_H */
diff --git a/gtksourceview/gtksourcespacedrawer.c b/gtksourceview/gtksourcespacedrawer.c
index adc32c8c..ed412f3d 100644
--- a/gtksourceview/gtksourcespacedrawer.c
+++ b/gtksourceview/gtksourcespacedrawer.c
@@ -2,12 +2,12 @@
 /*
  * This file is part of GtkSourceView
  *
- * Copyright 2008, 2011, 2016 - Paolo Borelli <pborelli gnome org>
- * Copyright 2008, 2010 - Ignacio Casal Quinteiro <icq gnome org>
- * Copyright 2010 - Garret Regier
- * Copyright 2013 - Arpad Borsos <arpad borsos googlemail com>
- * Copyright 2015, 2016 - Sébastien Wilmet <swilmet gnome org>
- * Copyright 2016 - Christian Hergert <christian hergert me>
+ * Copyright (C) 2008, 2011, 2016 - Paolo Borelli <pborelli gnome org>
+ * Copyright (C) 2008, 2010 - Ignacio Casal Quinteiro <icq gnome org>
+ * Copyright (C) 2010 - Garret Regier
+ * Copyright (C) 2013 - Arpad Borsos <arpad borsos googlemail com>
+ * Copyright (C) 2015, 2016 - Sébastien Wilmet <swilmet gnome org>
+ * Copyright (C) 2016 - Christian Hergert <christian hergert me>
  *
  * GtkSourceView is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -23,13 +23,16 @@
  * along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "config.h"
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
 
 #include "gtksourcespacedrawer.h"
 #include "gtksourcespacedrawer-private.h"
 #include "gtksourcebuffer.h"
 #include "gtksourcebuffer-private.h"
-#include "gtksourceiter-private.h"
+#include "gtksourceiter.h"
+#include "gtksourcestylescheme.h"
 #include "gtksourcestylescheme-private.h"
 #include "gtksourcetag.h"
 #include "gtksourceview.h"
@@ -88,17 +91,39 @@
  * default with a DVD of Matrix, in case the astronauts are bored.
  */
 
-/*
-#define ENABLE_PROFILE
-*/
-#undef ENABLE_PROFILE
+#if 0
+# define ENABLE_PROFILE
+#else
+# undef ENABLE_PROFILE
+#endif
 
-struct _GtkSourceSpaceDrawer
+typedef enum
+{
+       DRAW_TAB,
+       DRAW_NARROW_NBSP,
+       DRAW_NBSP,
+       DRAW_SPACE,
+       DRAW_NEWLINE,
+       N_DRAW
+} Draw;
+
+typedef struct
+{
+       GskRenderNode *node;
+       gint           width;
+       gint           height;
+} CachedNode;
+
+struct _GtkSourceSpaceDrawerPrivate
 {
-       GObject parent_instance;
        GtkSourceSpaceTypeFlags *matrix;
-       GdkRGBA *color;
-       guint enable_matrix : 1;
+
+       CachedNode               cached[N_DRAW];
+
+       GdkRGBA                  color;
+
+       guint                    color_set : 1;
+       guint                    enable_matrix : 1;
 };
 
 enum
@@ -111,7 +136,20 @@ enum
 
 static GParamSpec *properties[N_PROPERTIES];
 
-G_DEFINE_TYPE (GtkSourceSpaceDrawer, gtk_source_space_drawer, G_TYPE_OBJECT)
+G_DEFINE_TYPE_WITH_PRIVATE (GtkSourceSpaceDrawer, gtk_source_space_drawer, G_TYPE_OBJECT)
+
+static void
+gtk_source_space_drawer_purge_cache (GtkSourceSpaceDrawer *drawer)
+{
+       guint i;
+
+       g_return_if_fail (GTK_SOURCE_IS_SPACE_DRAWER (drawer));
+
+       for (i = 0; i < G_N_ELEMENTS (drawer->priv->cached); i++)
+       {
+               g_clear_pointer (&drawer->priv->cached[i].node, gsk_render_node_unref);
+       }
+}
 
 static gint
 get_number_of_locations (void)
@@ -164,7 +202,7 @@ is_zero_matrix (GtkSourceSpaceDrawer *drawer)
 
        for (i = 0; i < num_locations; i++)
        {
-               if (drawer->matrix[i] != 0)
+               if (drawer->priv->matrix[i] != 0)
                {
                        return FALSE;
                }
@@ -184,9 +222,9 @@ set_zero_matrix (GtkSourceSpaceDrawer *drawer)
 
        for (i = 0; i < num_locations; i++)
        {
-               if (drawer->matrix[i] != 0)
+               if (drawer->priv->matrix[i] != 0)
                {
-                       drawer->matrix[i] = 0;
+                       drawer->priv->matrix[i] = 0;
                        changed = TRUE;
                }
        }
@@ -200,7 +238,7 @@ set_zero_matrix (GtkSourceSpaceDrawer *drawer)
 /* AND */
 static GtkSourceSpaceTypeFlags
 get_types_at_all_locations (GtkSourceSpaceDrawer        *drawer,
-                            GtkSourceSpaceLocationFlags  locations)
+                           GtkSourceSpaceLocationFlags  locations)
 {
        GtkSourceSpaceTypeFlags ret = GTK_SOURCE_SPACE_TYPE_ALL;
        gint index;
@@ -215,7 +253,7 @@ get_types_at_all_locations (GtkSourceSpaceDrawer        *drawer,
        {
                if ((locations & 1) == 1)
                {
-                       ret &= drawer->matrix[index];
+                       ret &= drawer->priv->matrix[index];
                        found = TRUE;
                }
 
@@ -229,7 +267,7 @@ get_types_at_all_locations (GtkSourceSpaceDrawer        *drawer,
 /* OR */
 static GtkSourceSpaceTypeFlags
 get_types_at_any_locations (GtkSourceSpaceDrawer        *drawer,
-                            GtkSourceSpaceLocationFlags  locations)
+                           GtkSourceSpaceLocationFlags  locations)
 {
        GtkSourceSpaceTypeFlags ret = GTK_SOURCE_SPACE_TYPE_NONE;
        gint index;
@@ -242,7 +280,7 @@ get_types_at_any_locations (GtkSourceSpaceDrawer        *drawer,
        {
                if ((locations & 1) == 1)
                {
-                       ret |= drawer->matrix[index];
+                       ret |= drawer->priv->matrix[index];
                }
 
                locations >>= 1;
@@ -254,9 +292,9 @@ get_types_at_any_locations (GtkSourceSpaceDrawer        *drawer,
 
 static void
 gtk_source_space_drawer_get_property (GObject    *object,
-                                      guint       prop_id,
-                                      GValue     *value,
-                                      GParamSpec *pspec)
+                                     guint       prop_id,
+                                     GValue     *value,
+                                     GParamSpec *pspec)
 {
        GtkSourceSpaceDrawer *drawer = GTK_SOURCE_SPACE_DRAWER (object);
 
@@ -278,9 +316,9 @@ gtk_source_space_drawer_get_property (GObject    *object,
 
 static void
 gtk_source_space_drawer_set_property (GObject      *object,
-                                      guint         prop_id,
-                                      const GValue *value,
-                                      GParamSpec   *pspec)
+                                     guint         prop_id,
+                                     const GValue *value,
+                                     GParamSpec   *pspec)
 {
        GtkSourceSpaceDrawer *drawer = GTK_SOURCE_SPACE_DRAWER (object);
 
@@ -305,12 +343,8 @@ gtk_source_space_drawer_finalize (GObject *object)
 {
        GtkSourceSpaceDrawer *drawer = GTK_SOURCE_SPACE_DRAWER (object);
 
-       g_free (drawer->matrix);
-
-       if (drawer->color != NULL)
-       {
-               gdk_rgba_free (drawer->color);
-       }
+       gtk_source_space_drawer_purge_cache (drawer);
+       g_free (drawer->priv->matrix);
 
        G_OBJECT_CLASS (gtk_source_space_drawer_parent_class)->finalize (object);
 }
@@ -375,9 +409,9 @@ gtk_source_space_drawer_class_init (GtkSourceSpaceDrawerClass *klass)
 static void
 gtk_source_space_drawer_init (GtkSourceSpaceDrawer *drawer)
 {
-       drawer = gtk_source_space_drawer_get_instance_private (drawer);
+       drawer->priv = gtk_source_space_drawer_get_instance_private (drawer);
 
-       drawer->matrix = g_new0 (GtkSourceSpaceTypeFlags, get_number_of_locations ());
+       drawer->priv->matrix = g_new0 (GtkSourceSpaceTypeFlags, get_number_of_locations ());
 }
 
 /**
@@ -414,7 +448,7 @@ gtk_source_space_drawer_new (void)
  */
 GtkSourceSpaceTypeFlags
 gtk_source_space_drawer_get_types_for_locations (GtkSourceSpaceDrawer        *drawer,
-                                                 GtkSourceSpaceLocationFlags  locations)
+                                                GtkSourceSpaceLocationFlags  locations)
 {
        g_return_val_if_fail (GTK_SOURCE_IS_SPACE_DRAWER (drawer), GTK_SOURCE_SPACE_TYPE_NONE);
 
@@ -434,8 +468,8 @@ gtk_source_space_drawer_get_types_for_locations (GtkSourceSpaceDrawer        *dr
  */
 void
 gtk_source_space_drawer_set_types_for_locations (GtkSourceSpaceDrawer        *drawer,
-                                                 GtkSourceSpaceLocationFlags  locations,
-                                                 GtkSourceSpaceTypeFlags      types)
+                                                GtkSourceSpaceLocationFlags  locations,
+                                                GtkSourceSpaceTypeFlags      types)
 {
        gint index;
        gint num_locations;
@@ -449,9 +483,9 @@ gtk_source_space_drawer_set_types_for_locations (GtkSourceSpaceDrawer        *dr
        while (locations != 0 && index < num_locations)
        {
                if ((locations & 1) == 1 &&
-                   drawer->matrix[index] != types)
+                   drawer->priv->matrix[index] != types)
                {
-                       drawer->matrix[index] = types;
+                       drawer->priv->matrix[index] = types;
                        changed = TRUE;
                }
 
@@ -501,7 +535,7 @@ gtk_source_space_drawer_get_matrix (GtkSourceSpaceDrawer *drawer)
        {
                GVariant *space_types;
 
-               space_types = g_variant_new_uint32 (drawer->matrix[i]);
+               space_types = g_variant_new_uint32 (drawer->priv->matrix[i]);
 
                g_variant_builder_add_value (&builder, space_types);
        }
@@ -526,7 +560,7 @@ gtk_source_space_drawer_get_matrix (GtkSourceSpaceDrawer *drawer)
  */
 void
 gtk_source_space_drawer_set_matrix (GtkSourceSpaceDrawer *drawer,
-                                    GVariant             *matrix)
+                                   GVariant             *matrix)
 {
        gint num_locations;
        gint index;
@@ -560,9 +594,9 @@ gtk_source_space_drawer_set_matrix (GtkSourceSpaceDrawer *drawer,
 
                space_types = g_variant_get_uint32 (child);
 
-               if (drawer->matrix[index] != space_types)
+               if (drawer->priv->matrix[index] != space_types)
                {
-                       drawer->matrix[index] = space_types;
+                       drawer->priv->matrix[index] = space_types;
                        changed = TRUE;
                }
 
@@ -572,9 +606,9 @@ gtk_source_space_drawer_set_matrix (GtkSourceSpaceDrawer *drawer,
 
        while (index < num_locations)
        {
-               if (drawer->matrix[index] != 0)
+               if (drawer->priv->matrix[index] != 0)
                {
-                       drawer->matrix[index] = 0;
+                       drawer->priv->matrix[index] = 0;
                        changed = TRUE;
                }
 
@@ -605,7 +639,7 @@ gtk_source_space_drawer_get_enable_matrix (GtkSourceSpaceDrawer *drawer)
 {
        g_return_val_if_fail (GTK_SOURCE_IS_SPACE_DRAWER (drawer), FALSE);
 
-       return drawer->enable_matrix;
+       return drawer->priv->enable_matrix;
 }
 
 /**
@@ -619,23 +653,23 @@ gtk_source_space_drawer_get_enable_matrix (GtkSourceSpaceDrawer *drawer)
  */
 void
 gtk_source_space_drawer_set_enable_matrix (GtkSourceSpaceDrawer *drawer,
-                                           gboolean              enable_matrix)
+                                          gboolean              enable_matrix)
 {
        g_return_if_fail (GTK_SOURCE_IS_SPACE_DRAWER (drawer));
 
        enable_matrix = enable_matrix != FALSE;
 
-       if (drawer->enable_matrix != enable_matrix)
+       if (drawer->priv->enable_matrix != enable_matrix)
        {
-               drawer->enable_matrix = enable_matrix;
+               drawer->priv->enable_matrix = enable_matrix;
                g_object_notify_by_pspec (G_OBJECT (drawer), properties[PROP_ENABLE_MATRIX]);
        }
 }
 
 static gboolean
 matrix_get_mapping (GValue   *value,
-                    GVariant *variant,
-                    gpointer  user_data)
+                   GVariant *variant,
+                   gpointer  user_data)
 {
        g_value_set_variant (value, variant);
        return TRUE;
@@ -643,8 +677,8 @@ matrix_get_mapping (GValue   *value,
 
 static GVariant *
 matrix_set_mapping (const GValue       *value,
-                    const GVariantType *expected_type,
-                    gpointer            user_data)
+                   const GVariantType *expected_type,
+                   gpointer            user_data)
 {
        return g_value_dup_variant (value);
 }
@@ -670,9 +704,9 @@ matrix_set_mapping (const GValue       *value,
  */
 void
 gtk_source_space_drawer_bind_matrix_setting (GtkSourceSpaceDrawer *drawer,
-                                             GSettings            *settings,
-                                             const gchar          *key,
-                                             GSettingsBindFlags    flags)
+                                            GSettings            *settings,
+                                            const gchar          *key,
+                                            GSettingsBindFlags    flags)
 {
        GVariant *value;
 
@@ -700,7 +734,7 @@ gtk_source_space_drawer_bind_matrix_setting (GtkSourceSpaceDrawer *drawer,
 
 void
 _gtk_source_space_drawer_update_color (GtkSourceSpaceDrawer *drawer,
-                                       GtkSourceView        *view)
+                                      GtkSourceView        *view)
 {
        GtkSourceBuffer *buffer;
        GtkSourceStyleScheme *style_scheme;
@@ -708,11 +742,9 @@ _gtk_source_space_drawer_update_color (GtkSourceSpaceDrawer *drawer,
        g_return_if_fail (GTK_SOURCE_IS_SPACE_DRAWER (drawer));
        g_return_if_fail (GTK_SOURCE_IS_VIEW (view));
 
-       if (drawer->color != NULL)
-       {
-               gdk_rgba_free (drawer->color);
-               drawer->color = NULL;
-       }
+       gtk_source_space_drawer_purge_cache (drawer);
+
+       drawer->priv->color_set = FALSE;
 
        buffer = GTK_SOURCE_BUFFER (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)));
        style_scheme = gtk_source_buffer_get_style_scheme (buffer);
@@ -738,14 +770,15 @@ _gtk_source_space_drawer_update_color (GtkSourceSpaceDrawer *drawer,
                            color_str != NULL &&
                            gdk_rgba_parse (&color, color_str))
                        {
-                               drawer->color = gdk_rgba_copy (&color);
+                               drawer->priv->color = color;
+                               drawer->priv->color_set = TRUE;
                        }
 
                        g_free (color_str);
                }
        }
 
-       if (drawer->color == NULL)
+       if (!drawer->priv->color_set)
        {
                GtkStyleContext *context;
                GdkRGBA color;
@@ -753,12 +786,11 @@ _gtk_source_space_drawer_update_color (GtkSourceSpaceDrawer *drawer,
                context = gtk_widget_get_style_context (GTK_WIDGET (view));
                gtk_style_context_save (context);
                gtk_style_context_set_state (context, GTK_STATE_FLAG_INSENSITIVE);
-               gtk_style_context_get_color (context,
-                                            gtk_style_context_get_state (context),
-                                            &color);
+               gtk_style_context_get_color (context, &color);
                gtk_style_context_restore (context);
 
-               drawer->color = gdk_rgba_copy (&color);
+               drawer->priv->color = color;
+               drawer->priv->color_set = TRUE;
        }
 }
 
@@ -808,61 +840,43 @@ is_whitespace (gunichar ch)
 }
 
 static void
-draw_space_at_pos (cairo_t      *cr,
-                   GdkRectangle  rect)
+draw_space_at_pos (cairo_t *cr,
+                  gdouble  w,
+                  gdouble  h)
 {
-       gint x, y;
-       gdouble w;
-
-       x = rect.x;
-       y = rect.y + rect.height * 2 / 3;
-
-       w = rect.width;
+       const gint x = 0;
+       const gint y = h * 2 / 3;
 
-       cairo_save (cr);
        cairo_move_to (cr, x + w * 0.5, y);
        cairo_arc (cr, x + w * 0.5, y, 0.8, 0, 2 * G_PI);
        cairo_stroke (cr);
-       cairo_restore (cr);
 }
 
 static void
-draw_tab_at_pos (cairo_t      *cr,
-                 GdkRectangle  rect)
+draw_tab_at_pos (cairo_t *cr,
+                gdouble  w,
+                gdouble  h)
 {
-       gint x, y;
-       gdouble w, h;
+       const gint x = 0;
+       const gint y = h * 2 / 3;
 
-       x = rect.x;
-       y = rect.y + rect.height * 2 / 3;
-
-       w = rect.width;
-       h = rect.height;
-
-       cairo_save (cr);
        cairo_move_to (cr, x + w * 1 / 8, y);
        cairo_rel_line_to (cr, w * 6 / 8, 0);
        cairo_rel_line_to (cr, -h * 1 / 4, -h * 1 / 4);
        cairo_rel_move_to (cr, +h * 1 / 4, +h * 1 / 4);
        cairo_rel_line_to (cr, -h * 1 / 4, +h * 1 / 4);
        cairo_stroke (cr);
-       cairo_restore (cr);
 }
 
 static void
-draw_newline_at_pos (cairo_t      *cr,
-                     GdkRectangle  rect)
+draw_newline_at_pos (cairo_t *cr,
+                    gdouble  w,
+                    gdouble  h)
 {
-       gint x, y;
-       gdouble w, h;
-
-       x = rect.x;
-       y = rect.y + rect.height / 3;
-
-       w = 2 * rect.width;
-       h = rect.height;
+       const gint x = 0;
+       const gint y = h / 3;
 
-       cairo_save (cr);
+       w = w * 2;
 
        if (gtk_widget_get_default_direction () == GTK_TEXT_DIR_LTR)
        {
@@ -884,48 +898,50 @@ draw_newline_at_pos (cairo_t      *cr,
        }
 
        cairo_stroke (cr);
-       cairo_restore (cr);
 }
 
 static void
-draw_nbsp_at_pos (cairo_t      *cr,
-                  GdkRectangle  rect,
-                  gboolean      narrowed)
+draw_narrow_nbsp_at_pos (cairo_t *cr,
+                        gdouble  w,
+                        gdouble  h)
 {
-       gint x, y;
-       gdouble w, h;
+       const gint x = 0;
+       const gint y = h / 2;
 
-       x = rect.x;
-       y = rect.y + rect.height / 2;
-
-       w = rect.width;
-       h = rect.height;
-
-       cairo_save (cr);
        cairo_move_to (cr, x + w * 1 / 6, y);
        cairo_rel_line_to (cr, w * 4 / 6, 0);
        cairo_rel_line_to (cr, -w * 2 / 6, +h * 1 / 4);
        cairo_rel_line_to (cr, -w * 2 / 6, -h * 1 / 4);
+       cairo_fill (cr);
+}
 
-       if (narrowed)
-       {
-               cairo_fill (cr);
-       }
-       else
-       {
-               cairo_stroke (cr);
-       }
+static void
+draw_nbsp_at_pos (cairo_t *cr,
+                 gdouble  w,
+                 gdouble  h)
+{
+       const gint x = 0;
+       const gint y = h / 2;
 
-       cairo_restore (cr);
+       cairo_move_to (cr, x + w * 1 / 6, y);
+       cairo_rel_line_to (cr, w * 4 / 6, 0);
+       cairo_rel_line_to (cr, -w * 2 / 6, +h * 1 / 4);
+       cairo_rel_line_to (cr, -w * 2 / 6, -h * 1 / 4);
+       cairo_stroke (cr);
 }
 
 static void
-draw_whitespace_at_iter (GtkTextView *text_view,
-                         GtkTextIter *iter,
-                         cairo_t     *cr)
+draw_whitespace_at_iter (GtkSourceSpaceDrawer *drawer,
+                         GtkTextView          *text_view,
+                         const GtkTextIter    *iter,
+                         const GdkRGBA        *color,
+                         GtkSnapshot          *snapshot)
 {
-       gunichar ch;
+       void (*draw) (cairo_t *cr, gdouble w, gdouble h) = NULL;
+       CachedNode *cache = NULL;
        GdkRectangle rect;
+       gunichar ch;
+       gint ratio = 1;
 
        gtk_text_view_get_iter_location (text_view, iter, &rect);
 
@@ -941,26 +957,73 @@ draw_whitespace_at_iter (GtkTextView *text_view,
 
        if (is_tab (ch))
        {
-               draw_tab_at_pos (cr, rect);
+               draw = draw_tab_at_pos;
+               cache = &drawer->priv->cached[DRAW_TAB];
        }
        else if (is_nbsp (ch))
        {
-               draw_nbsp_at_pos (cr, rect, is_narrowed_nbsp (ch));
+               if (is_narrowed_nbsp (ch))
+               {
+                       draw = draw_narrow_nbsp_at_pos;
+                       cache = &drawer->priv->cached[DRAW_NARROW_NBSP];
+               }
+               else
+               {
+                       draw = draw_nbsp_at_pos;
+                       cache = &drawer->priv->cached[DRAW_NBSP];
+               }
        }
        else if (is_space (ch))
        {
-               draw_space_at_pos (cr, rect);
+               draw = draw_space_at_pos;
+               cache = &drawer->priv->cached[DRAW_SPACE];
        }
        else if (is_newline (iter))
        {
-               draw_newline_at_pos (cr, rect);
+               draw = draw_newline_at_pos;
+               cache = &drawer->priv->cached[DRAW_NEWLINE];
+               ratio = 2;
+       }
+
+       g_assert (draw == NULL || cache != NULL);
+
+       if (draw != NULL)
+       {
+               if (cache->width != rect.width || cache->height != rect.height)
+               {
+                       g_clear_pointer (&cache->node, gsk_render_node_unref);
+               }
+
+               if G_UNLIKELY (cache->node == NULL)
+               {
+                       GtkSnapshot *to_cache;
+                       cairo_t *cr;
+
+                       to_cache = gtk_snapshot_new ();
+                       cr = gtk_snapshot_append_cairo (to_cache,
+                                                       &GRAPHENE_RECT_INIT (0, 0, rect.width * ratio, 
rect.height));
+                       gdk_cairo_set_source_rgba (cr, color);
+                       cairo_set_line_width (cr, 0.8);
+                       cairo_translate (cr, -0.5, -0.5);
+                       draw (cr, rect.width, rect.height);
+                       cairo_destroy (cr);
+
+                       cache->node = gtk_snapshot_free_to_node (g_steal_pointer (&to_cache));
+                       cache->width = rect.width;
+                       cache->height = rect.height;
+               }
+
+               gtk_snapshot_save (snapshot);
+               gtk_snapshot_translate (snapshot, &GRAPHENE_POINT_INIT (rect.x, rect.y));
+               gtk_snapshot_append_node (snapshot, cache->node);
+               gtk_snapshot_restore (snapshot);
        }
 }
 
 static void
 space_needs_drawing_according_to_tag (const GtkTextIter *iter,
-                                      gboolean          *has_tag,
-                                      gboolean          *needs_drawing)
+                                     gboolean          *has_tag,
+                                     gboolean          *needs_drawing)
 {
        GSList *tags;
        GSList *l;
@@ -999,8 +1062,8 @@ space_needs_drawing_according_to_tag (const GtkTextIter *iter,
 
 static GtkSourceSpaceLocationFlags
 get_iter_locations (const GtkTextIter *iter,
-                    const GtkTextIter *leading_end,
-                    const GtkTextIter *trailing_start)
+                   const GtkTextIter *leading_end,
+                   const GtkTextIter *trailing_start)
 {
        GtkSourceSpaceLocationFlags iter_locations = GTK_SOURCE_SPACE_LOCATION_NONE;
 
@@ -1052,9 +1115,9 @@ get_iter_space_type (const GtkTextIter *iter)
 
 static gboolean
 space_needs_drawing_according_to_matrix (GtkSourceSpaceDrawer *drawer,
-                                         const GtkTextIter    *iter,
-                                         const GtkTextIter    *leading_end,
-                                         const GtkTextIter    *trailing_start)
+                                        const GtkTextIter    *iter,
+                                        const GtkTextIter    *leading_end,
+                                        const GtkTextIter    *trailing_start)
 {
        GtkSourceSpaceLocationFlags iter_locations;
        GtkSourceSpaceTypeFlags iter_space_type;
@@ -1069,9 +1132,9 @@ space_needs_drawing_according_to_matrix (GtkSourceSpaceDrawer *drawer,
 
 static gboolean
 space_needs_drawing (GtkSourceSpaceDrawer *drawer,
-                     const GtkTextIter    *iter,
-                     const GtkTextIter    *leading_end,
-                     const GtkTextIter    *trailing_start)
+                    const GtkTextIter    *iter,
+                    const GtkTextIter    *leading_end,
+                    const GtkTextIter    *trailing_start)
 {
        gboolean has_tag;
        gboolean needs_drawing;
@@ -1084,17 +1147,17 @@ space_needs_drawing (GtkSourceSpaceDrawer *drawer,
        }
 
        /* Check the matrix */
-       return (drawer->enable_matrix &&
+       return (drawer->priv->enable_matrix &&
                space_needs_drawing_according_to_matrix (drawer, iter, leading_end, trailing_start));
 }
 
 static void
 get_line_end (GtkTextView       *text_view,
-              const GtkTextIter *start_iter,
-              GtkTextIter       *line_end,
-              gint               max_x,
-              gint               max_y,
-              gboolean           is_wrapping)
+             const GtkTextIter *start_iter,
+             GtkTextIter       *line_end,
+             gint               max_x,
+             gint               max_y,
+             gboolean           is_wrapping)
 {
        gint min;
        gint max;
@@ -1145,11 +1208,11 @@ get_line_end (GtkTextView       *text_view,
 void
 _gtk_source_space_drawer_draw (GtkSourceSpaceDrawer *drawer,
                                GtkSourceView        *view,
-                               cairo_t              *cr)
+                               GtkSnapshot          *snapshot)
 {
        GtkTextView *text_view;
        GtkTextBuffer *buffer;
-       GdkRectangle clip;
+       GdkRectangle visible;
        gint min_x;
        gint min_y;
        gint max_x;
@@ -1174,9 +1237,8 @@ _gtk_source_space_drawer_draw (GtkSourceSpaceDrawer *drawer,
 
        g_return_if_fail (GTK_SOURCE_IS_SPACE_DRAWER (drawer));
        g_return_if_fail (GTK_SOURCE_IS_VIEW (view));
-       g_return_if_fail (cr != NULL);
 
-       if (drawer->color == NULL)
+       if (!drawer->priv->color_set)
        {
                g_warning ("GtkSourceSpaceDrawer: color not set.");
                return;
@@ -1185,32 +1247,24 @@ _gtk_source_space_drawer_draw (GtkSourceSpaceDrawer *drawer,
        text_view = GTK_TEXT_VIEW (view);
        buffer = gtk_text_view_get_buffer (text_view);
 
-       if ((!drawer->enable_matrix || is_zero_matrix (drawer)) &&
+       if ((!drawer->priv->enable_matrix || is_zero_matrix (drawer)) &&
            !_gtk_source_buffer_has_spaces_tag (GTK_SOURCE_BUFFER (buffer)))
        {
                return;
        }
 
-       if (!gdk_cairo_get_clip_rectangle (cr, &clip))
-       {
-               return;
-       }
+       gtk_text_view_get_visible_rect (GTK_TEXT_VIEW (view), &visible);
 
        is_wrapping = gtk_text_view_get_wrap_mode (text_view) != GTK_WRAP_NONE;
 
-       min_x = clip.x;
-       min_y = clip.y;
-       max_x = min_x + clip.width;
-       max_y = min_y + clip.height;
+       min_x = visible.x;
+       min_y = visible.y;
+       max_x = min_x + visible.width;
+       max_y = min_y + visible.height;
 
        gtk_text_view_get_iter_at_location (text_view, &start, min_x, min_y);
        gtk_text_view_get_iter_at_location (text_view, &end, max_x, max_y);
 
-       cairo_save (cr);
-       gdk_cairo_set_source_rgba (cr, drawer->color);
-       cairo_set_line_width (cr, 0.8);
-       cairo_translate (cr, -0.5, -0.5);
-
        iter = start;
        _gtk_source_iter_get_leading_spaces_end_boundary (&iter, &leading_end);
        _gtk_source_iter_get_trailing_spaces_start_boundary (&iter, &trailing_start);
@@ -1225,7 +1279,11 @@ _gtk_source_space_drawer_draw (GtkSourceSpaceDrawer *drawer,
                if ((is_whitespace (ch) || gtk_text_iter_is_end (&iter)) &&
                    space_needs_drawing (drawer, &iter, &leading_end, &trailing_start))
                {
-                       draw_whitespace_at_iter (text_view, &iter, cr);
+                       draw_whitespace_at_iter (drawer,
+                                                text_view,
+                                                &iter,
+                                                &drawer->priv->color,
+                                                snapshot);
                }
 
                if (gtk_text_iter_is_end (&iter) ||
@@ -1278,8 +1336,6 @@ _gtk_source_space_drawer_draw (GtkSourceSpaceDrawer *drawer,
                }
        };
 
-       cairo_restore (cr);
-
 #ifdef ENABLE_PROFILE
        g_timer_stop (timer);
 
diff --git a/gtksourceview/gtksourcespacedrawer.h b/gtksourceview/gtksourcespacedrawer.h
index dff6dacc..d8a0cc86 100644
--- a/gtksourceview/gtksourcespacedrawer.h
+++ b/gtksourceview/gtksourcespacedrawer.h
@@ -2,7 +2,7 @@
 /*
  * This file is part of GtkSourceView
  *
- * Copyright 2016 - Sébastien Wilmet <swilmet gnome org>
+ * Copyright (C) 2016 - Sébastien Wilmet <swilmet gnome org>
  *
  * GtkSourceView is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -18,7 +18,8 @@
  * along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#pragma once
+#ifndef GTK_SOURCE_SPACE_DRAWER_H
+#define GTK_SOURCE_SPACE_DRAWER_H
 
 #if !defined (GTK_SOURCE_H_INSIDE) && !defined (GTK_SOURCE_COMPILATION)
 #error "Only <gtksourceview/gtksource.h> can be included directly."
@@ -30,7 +31,29 @@
 
 G_BEGIN_DECLS
 
-#define GTK_SOURCE_TYPE_SPACE_DRAWER (gtk_source_space_drawer_get_type())
+#define GTK_SOURCE_TYPE_SPACE_DRAWER             (gtk_source_space_drawer_get_type ())
+#define GTK_SOURCE_SPACE_DRAWER(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), 
GTK_SOURCE_TYPE_SPACE_DRAWER, GtkSourceSpaceDrawer))
+#define GTK_SOURCE_SPACE_DRAWER_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), 
GTK_SOURCE_TYPE_SPACE_DRAWER, GtkSourceSpaceDrawerClass))
+#define GTK_SOURCE_IS_SPACE_DRAWER(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), 
GTK_SOURCE_TYPE_SPACE_DRAWER))
+#define GTK_SOURCE_IS_SPACE_DRAWER_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), 
GTK_SOURCE_TYPE_SPACE_DRAWER))
+#define GTK_SOURCE_SPACE_DRAWER_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), 
GTK_SOURCE_TYPE_SPACE_DRAWER, GtkSourceSpaceDrawerClass))
+
+typedef struct _GtkSourceSpaceDrawerClass    GtkSourceSpaceDrawerClass;
+typedef struct _GtkSourceSpaceDrawerPrivate  GtkSourceSpaceDrawerPrivate;
+
+struct _GtkSourceSpaceDrawer
+{
+       GObject parent;
+
+       GtkSourceSpaceDrawerPrivate *priv;
+};
+
+struct _GtkSourceSpaceDrawerClass
+{
+       GObjectClass parent_class;
+
+       gpointer padding[20];
+};
 
 /**
  * GtkSourceSpaceTypeFlags:
@@ -49,12 +72,12 @@ G_BEGIN_DECLS
  */
 typedef enum _GtkSourceSpaceTypeFlags
 {
-       GTK_SOURCE_SPACE_TYPE_NONE      = 0,
-       GTK_SOURCE_SPACE_TYPE_SPACE     = 1 << 0,
-       GTK_SOURCE_SPACE_TYPE_TAB       = 1 << 1,
-       GTK_SOURCE_SPACE_TYPE_NEWLINE   = 1 << 2,
-       GTK_SOURCE_SPACE_TYPE_NBSP      = 1 << 3,
-       GTK_SOURCE_SPACE_TYPE_ALL       = 0xf
+       GTK_SOURCE_SPACE_TYPE_NONE      = 0,
+       GTK_SOURCE_SPACE_TYPE_SPACE     = 1 << 0,
+       GTK_SOURCE_SPACE_TYPE_TAB       = 1 << 1,
+       GTK_SOURCE_SPACE_TYPE_NEWLINE   = 1 << 2,
+       GTK_SOURCE_SPACE_TYPE_NBSP      = 1 << 3,
+       GTK_SOURCE_SPACE_TYPE_ALL       = 0xf
 } GtkSourceSpaceTypeFlags;
 
 /**
@@ -75,39 +98,48 @@ typedef enum _GtkSourceSpaceTypeFlags
  */
 typedef enum _GtkSourceSpaceLocationFlags
 {
-       GTK_SOURCE_SPACE_LOCATION_NONE        = 0,
-       GTK_SOURCE_SPACE_LOCATION_LEADING     = 1 << 0,
-       GTK_SOURCE_SPACE_LOCATION_INSIDE_TEXT = 1 << 1,
-       GTK_SOURCE_SPACE_LOCATION_TRAILING    = 1 << 2,
-       GTK_SOURCE_SPACE_LOCATION_ALL         = 0x7
+       GTK_SOURCE_SPACE_LOCATION_NONE          = 0,
+       GTK_SOURCE_SPACE_LOCATION_LEADING       = 1 << 0,
+       GTK_SOURCE_SPACE_LOCATION_INSIDE_TEXT   = 1 << 1,
+       GTK_SOURCE_SPACE_LOCATION_TRAILING      = 1 << 2,
+       GTK_SOURCE_SPACE_LOCATION_ALL           = 0x7
 } GtkSourceSpaceLocationFlags;
 
 GTK_SOURCE_AVAILABLE_IN_3_24
-G_DECLARE_FINAL_TYPE (GtkSourceSpaceDrawer, gtk_source_space_drawer, GTK_SOURCE, SPACE_DRAWER, GObject)
+GType                  gtk_source_space_drawer_get_type                (void) G_GNUC_CONST;
 
 GTK_SOURCE_AVAILABLE_IN_3_24
-GtkSourceSpaceDrawer    *gtk_source_space_drawer_new                     (void);
+GtkSourceSpaceDrawer * gtk_source_space_drawer_new                     (void);
+
 GTK_SOURCE_AVAILABLE_IN_3_24
-GtkSourceSpaceTypeFlags  gtk_source_space_drawer_get_types_for_locations (GtkSourceSpaceDrawer        
*drawer,
-                                                                          GtkSourceSpaceLocationFlags  
locations);
+GtkSourceSpaceTypeFlags        gtk_source_space_drawer_get_types_for_locations (GtkSourceSpaceDrawer        
*drawer,
+                                                                        GtkSourceSpaceLocationFlags  
locations);
+
 GTK_SOURCE_AVAILABLE_IN_3_24
-void                     gtk_source_space_drawer_set_types_for_locations (GtkSourceSpaceDrawer        
*drawer,
-                                                                          GtkSourceSpaceLocationFlags  
locations,
-                                                                          GtkSourceSpaceTypeFlags      
types);
+void                   gtk_source_space_drawer_set_types_for_locations (GtkSourceSpaceDrawer        *drawer,
+                                                                        GtkSourceSpaceLocationFlags  
locations,
+                                                                        GtkSourceSpaceTypeFlags      types);
+
 GTK_SOURCE_AVAILABLE_IN_3_24
-GVariant                *gtk_source_space_drawer_get_matrix              (GtkSourceSpaceDrawer        
*drawer);
+GVariant *             gtk_source_space_drawer_get_matrix              (GtkSourceSpaceDrawer *drawer);
+
 GTK_SOURCE_AVAILABLE_IN_3_24
-void                     gtk_source_space_drawer_set_matrix              (GtkSourceSpaceDrawer        
*drawer,
-                                                                          GVariant                    
*matrix);
+void                   gtk_source_space_drawer_set_matrix              (GtkSourceSpaceDrawer *drawer,
+                                                                        GVariant             *matrix);
+
 GTK_SOURCE_AVAILABLE_IN_3_24
-gboolean                 gtk_source_space_drawer_get_enable_matrix       (GtkSourceSpaceDrawer        
*drawer);
+gboolean               gtk_source_space_drawer_get_enable_matrix       (GtkSourceSpaceDrawer *drawer);
+
 GTK_SOURCE_AVAILABLE_IN_3_24
-void                     gtk_source_space_drawer_set_enable_matrix       (GtkSourceSpaceDrawer        
*drawer,
-                                                                          gboolean                     
enable_matrix);
+void                   gtk_source_space_drawer_set_enable_matrix       (GtkSourceSpaceDrawer *drawer,
+                                                                        gboolean              enable_matrix);
+
 GTK_SOURCE_AVAILABLE_IN_3_24
-void                     gtk_source_space_drawer_bind_matrix_setting     (GtkSourceSpaceDrawer        
*drawer,
-                                                                          GSettings                   
*settings,
-                                                                          const gchar                 *key,
-                                                                          GSettingsBindFlags           
flags);
+void                   gtk_source_space_drawer_bind_matrix_setting     (GtkSourceSpaceDrawer *drawer,
+                                                                        GSettings            *settings,
+                                                                        const gchar          *key,
+                                                                        GSettingsBindFlags    flags);
 
 G_END_DECLS
+
+#endif /* GTK_SOURCE_SPACE_DRAWER_H */
diff --git a/gtksourceview/gtksourcestyle-private.h b/gtksourceview/gtksourcestyle-private.h
index 739ac6f6..7ae94e08 100644
--- a/gtksourceview/gtksourcestyle-private.h
+++ b/gtksourceview/gtksourcestyle-private.h
@@ -2,7 +2,7 @@
  *
  * This file is part of GtkSourceView
  *
- * Copyright 2003 - Paolo Maggi <paolo maggi polito it>
+ * Copyright (C) 2003 - Paolo Maggi <paolo maggi polito it>
  *
  * GtkSourceView is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -18,7 +18,8 @@
  * along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#pragma once
+#ifndef GTK_SOURCE_STYLE_PRIVATE_H
+#define GTK_SOURCE_STYLE_PRIVATE_H
 
 #include <gtk/gtk.h>
 
@@ -33,15 +34,15 @@ G_BEGIN_DECLS
 
 enum
 {
-       GTK_SOURCE_STYLE_USE_LINE_BACKGROUND = 1 << 0, /*< nick=use_line_background >*/
-       GTK_SOURCE_STYLE_USE_BACKGROUND      = 1 << 1, /*< nick=use_background >*/
-       GTK_SOURCE_STYLE_USE_FOREGROUND      = 1 << 2, /*< nick=use_foreground >*/
-       GTK_SOURCE_STYLE_USE_ITALIC          = 1 << 3, /*< nick=use_italic >*/
-       GTK_SOURCE_STYLE_USE_BOLD            = 1 << 4, /*< nick=use_bold >*/
-       GTK_SOURCE_STYLE_USE_UNDERLINE       = 1 << 5, /*< nick=use_underline >*/
-       GTK_SOURCE_STYLE_USE_STRIKETHROUGH   = 1 << 6, /*< nick=use_strikethrough >*/
-       GTK_SOURCE_STYLE_USE_SCALE           = 1 << 7, /*< nick=use_scale >*/
-       GTK_SOURCE_STYLE_USE_UNDERLINE_COLOR = 1 << 8, /*< nick=use_underline_color >*/
+       GTK_SOURCE_STYLE_USE_LINE_BACKGROUND = 1 << 0,  /*< nick=use_line_background >*/
+       GTK_SOURCE_STYLE_USE_BACKGROUND      = 1 << 1,  /*< nick=use_background >*/
+       GTK_SOURCE_STYLE_USE_FOREGROUND      = 1 << 2,  /*< nick=use_foreground >*/
+       GTK_SOURCE_STYLE_USE_ITALIC          = 1 << 3,  /*< nick=use_italic >*/
+       GTK_SOURCE_STYLE_USE_BOLD            = 1 << 4,  /*< nick=use_bold >*/
+       GTK_SOURCE_STYLE_USE_UNDERLINE       = 1 << 5,  /*< nick=use_underline >*/
+       GTK_SOURCE_STYLE_USE_STRIKETHROUGH   = 1 << 6,  /*< nick=use_strikethrough >*/
+       GTK_SOURCE_STYLE_USE_SCALE           = 1 << 7,  /*< nick=use_scale >*/
+       GTK_SOURCE_STYLE_USE_UNDERLINE_COLOR = 1 << 8   /*< nick=use_underline_color >*/
 };
 
 struct _GtkSourceStyle
@@ -66,3 +67,5 @@ struct _GtkSourceStyle
 };
 
 G_END_DECLS
+
+#endif  /* GTK_SOURCE_STYLE_PRIVATE_H */
diff --git a/gtksourceview/gtksourcestyle.c b/gtksourceview/gtksourcestyle.c
index 65048c84..70fe8445 100644
--- a/gtksourceview/gtksourcestyle.c
+++ b/gtksourceview/gtksourcestyle.c
@@ -2,7 +2,7 @@
  *
  * This file is part of GtkSourceView
  *
- * Copyright 2003 - Paolo Maggi <paolo maggi polito it>
+ * Copyright (C) 2003 - Paolo Maggi <paolo maggi polito it>
  *
  * GtkSourceView is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -18,7 +18,9 @@
  * along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "config.h"
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
 
 #include "gtksourcestyle.h"
 #include "gtksourcestyle-private.h"
@@ -33,14 +35,20 @@
  * which are set when given style is used.
  */
 
-static void gtk_source_style_set_property (GObject      *object,
-                                           guint         prop_id,
-                                           const GValue *value,
-                                           GParamSpec   *pspec);
-static void gtk_source_style_get_property (GObject      *object,
-                                           guint         prop_id,
-                                           GValue       *value,
-                                           GParamSpec   *pspec);
+static void    gtk_source_style_set_property   (GObject      *object,
+                                                guint         prop_id,
+                                                const GValue *value,
+                                                GParamSpec   *pspec);
+
+static void    gtk_source_style_get_property   (GObject      *object,
+                                                guint         prop_id,
+                                                GValue       *value,
+                                                GParamSpec   *pspec);
+
+struct _GtkSourceStyleClass
+{
+       GObjectClass parent_class;
+};
 
 G_DEFINE_TYPE (GtkSourceStyle, gtk_source_style, G_TYPE_OBJECT)
 
@@ -249,9 +257,9 @@ G_STMT_START {                                      \
 
 static void
 gtk_source_style_set_property (GObject      *object,
-                               guint         prop_id,
-                               const GValue *value,
-                               GParamSpec   *pspec)
+                              guint         prop_id,
+                              const GValue *value,
+                              GParamSpec   *pspec)
 {
        GtkSourceStyle *style = GTK_SOURCE_STYLE (object);
        const gchar *string;
@@ -391,10 +399,10 @@ gtk_source_style_set_property (GObject      *object,
 }
 
 static void
-gtk_source_style_get_property (GObject    *object,
-                               guint       prop_id,
-                               GValue     *value,
-                               GParamSpec *pspec)
+gtk_source_style_get_property (GObject      *object,
+                              guint         prop_id,
+                              GValue       *value,
+                              GParamSpec   *pspec)
 {
        GtkSourceStyle *style = GTK_SOURCE_STYLE (object);
 
@@ -530,7 +538,7 @@ gtk_source_style_copy (const GtkSourceStyle *style)
  */
 void
 gtk_source_style_apply (const GtkSourceStyle *style,
-                        GtkTextTag           *tag)
+                       GtkTextTag           *tag)
 {
        g_return_if_fail (GTK_IS_TEXT_TAG (tag));
 
diff --git a/gtksourceview/gtksourcestyle.h b/gtksourceview/gtksourcestyle.h
index 3ae95dc8..8938b339 100644
--- a/gtksourceview/gtksourcestyle.h
+++ b/gtksourceview/gtksourcestyle.h
@@ -2,7 +2,7 @@
  *
  * This file is part of GtkSourceView
  *
- * Copyright 2003 - Paolo Maggi <paolo maggi polito it>
+ * Copyright (C) 2003 - Paolo Maggi <paolo maggi polito it>
  *
  * GtkSourceView is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -18,7 +18,8 @@
  * along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#pragma once
+#ifndef GTK_SOURCE_STYLE_H
+#define GTK_SOURCE_STYLE_H
 
 #if !defined (GTK_SOURCE_H_INSIDE) && !defined (GTK_SOURCE_COMPILATION)
 #error "Only <gtksourceview/gtksource.h> can be included directly."
@@ -30,15 +31,25 @@
 
 G_BEGIN_DECLS
 
-#define GTK_SOURCE_TYPE_STYLE (gtk_source_style_get_type ())
+#define GTK_SOURCE_TYPE_STYLE             (gtk_source_style_get_type ())
+#define GTK_SOURCE_STYLE(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_SOURCE_TYPE_STYLE, 
GtkSourceStyle))
+#define GTK_SOURCE_IS_STYLE(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_SOURCE_TYPE_STYLE))
+#define GTK_SOURCE_STYLE_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_SOURCE_TYPE_STYLE, 
GtkSourceStyleClass))
+#define GTK_SOURCE_IS_STYLE_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_SOURCE_TYPE_STYLE))
+#define GTK_SOURCE_STYLE_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_SOURCE_TYPE_STYLE, 
GtkSourceStyleClass))
+
+typedef struct _GtkSourceStyleClass GtkSourceStyleClass;
 
 GTK_SOURCE_AVAILABLE_IN_ALL
-G_DECLARE_FINAL_TYPE (GtkSourceStyle, gtk_source_style, GTK_SOURCE, STYLE, GObject)
+GType           gtk_source_style_get_type      (void) G_GNUC_CONST;
 
 GTK_SOURCE_AVAILABLE_IN_ALL
-GtkSourceStyle *gtk_source_style_copy  (const GtkSourceStyle *style);
+GtkSourceStyle *gtk_source_style_copy          (const GtkSourceStyle *style);
+
 GTK_SOURCE_AVAILABLE_IN_3_22
-void            gtk_source_style_apply (const GtkSourceStyle *style,
-                                        GtkTextTag           *tag);
+void            gtk_source_style_apply         (const GtkSourceStyle *style,
+                                                GtkTextTag           *tag);
 
 G_END_DECLS
+
+#endif  /* GTK_SOURCE_STYLE_H */
diff --git a/gtksourceview/gtksourcestylescheme-private.h b/gtksourceview/gtksourcestylescheme-private.h
index c2846eea..8aa2e22a 100644
--- a/gtksourceview/gtksourcestylescheme-private.h
+++ b/gtksourceview/gtksourcestylescheme-private.h
@@ -2,7 +2,7 @@
  *
  * This file is part of GtkSourceView
  *
- * Copyright 2003 - Paolo Maggi <paolo maggi polito it>
+ * Copyright (C) 2003 - Paolo Maggi <paolo maggi polito it>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -18,8 +18,12 @@
  * along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#pragma once
+#ifndef GTK_SOURCE_STYLE_SCHEME_PRIVATE_H
+#define GTK_SOURCE_STYLE_SCHEME_PRIVATE_H
 
+#include <gtk/gtk.h>
+
+#include "gtksourcetypes.h"
 #include "gtksourcestylescheme.h"
 
 G_BEGIN_DECLS
@@ -53,3 +57,5 @@ gboolean              _gtk_source_style_scheme_get_background_pattern_color (Gtk
                                                                              GdkRGBA              *color);
 
 G_END_DECLS
+
+#endif  /* GTK_SOURCE_STYLE_SCHEME_H */
diff --git a/gtksourceview/gtksourcestylescheme.c b/gtksourceview/gtksourcestylescheme.c
index 668585e6..93b1c4a5 100644
--- a/gtksourceview/gtksourcestylescheme.c
+++ b/gtksourceview/gtksourcestylescheme.c
@@ -2,7 +2,7 @@
 /*
  * This file is part of GtkSourceView
  *
- * Copyright 2003 - Paolo Maggi <paolo maggi polito it>
+ * Copyright (C) 2003 - Paolo Maggi <paolo maggi polito it>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -18,11 +18,13 @@
  * along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "config.h"
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
 
+#include <glib/gi18n-lib.h>
 #include <libxml/parser.h>
 #include <string.h>
-#include <glib/gi18n-lib.h>
 
 #include "gtksourcestylescheme.h"
 #include "gtksourcestylescheme-private.h"
@@ -78,10 +80,8 @@ enum
        PROP_FILENAME
 };
 
-struct _GtkSourceStyleScheme
+struct _GtkSourceStyleSchemePrivate
 {
-       GObject parent_instance;
-
        gchar *id;
        gchar *name;
        GPtrArray *authors;
@@ -97,34 +97,34 @@ struct _GtkSourceStyleScheme
        GtkCssProvider *css_provider_cursors;
 };
 
-G_DEFINE_TYPE (GtkSourceStyleScheme, gtk_source_style_scheme, G_TYPE_OBJECT)
+G_DEFINE_TYPE_WITH_PRIVATE (GtkSourceStyleScheme, gtk_source_style_scheme, G_TYPE_OBJECT)
 
 static void
 gtk_source_style_scheme_dispose (GObject *object)
 {
        GtkSourceStyleScheme *scheme = GTK_SOURCE_STYLE_SCHEME (object);
 
-       if (scheme->named_colors != NULL)
+       if (scheme->priv->named_colors != NULL)
        {
-               g_hash_table_unref (scheme->named_colors);
-               scheme->named_colors = NULL;
+               g_hash_table_unref (scheme->priv->named_colors);
+               scheme->priv->named_colors = NULL;
        }
 
-       if (scheme->style_cache != NULL)
+       if (scheme->priv->style_cache != NULL)
        {
-               g_hash_table_unref (scheme->style_cache);
-               scheme->style_cache = NULL;
+               g_hash_table_unref (scheme->priv->style_cache);
+               scheme->priv->style_cache = NULL;
        }
 
-       if (scheme->defined_styles != NULL)
+       if (scheme->priv->defined_styles != NULL)
        {
-               g_hash_table_unref (scheme->defined_styles);
-               scheme->defined_styles = NULL;
+               g_hash_table_unref (scheme->priv->defined_styles);
+               scheme->priv->defined_styles = NULL;
        }
 
-       g_clear_object (&scheme->parent);
-       g_clear_object (&scheme->css_provider);
-       g_clear_object (&scheme->css_provider_cursors);
+       g_clear_object (&scheme->priv->parent);
+       g_clear_object (&scheme->priv->css_provider);
+       g_clear_object (&scheme->priv->css_provider_cursors);
 
        G_OBJECT_CLASS (gtk_source_style_scheme_parent_class)->dispose (object);
 }
@@ -134,33 +134,33 @@ gtk_source_style_scheme_finalize (GObject *object)
 {
        GtkSourceStyleScheme *scheme = GTK_SOURCE_STYLE_SCHEME (object);
 
-       if (scheme->authors != NULL)
+       if (scheme->priv->authors != NULL)
        {
-               g_ptr_array_free (scheme->authors, TRUE);
+               g_ptr_array_free (scheme->priv->authors, TRUE);
        }
 
-       g_free (scheme->filename);
-       g_free (scheme->description);
-       g_free (scheme->id);
-       g_free (scheme->name);
-       g_free (scheme->parent_id);
+       g_free (scheme->priv->filename);
+       g_free (scheme->priv->description);
+       g_free (scheme->priv->id);
+       g_free (scheme->priv->name);
+       g_free (scheme->priv->parent_id);
 
        G_OBJECT_CLASS (gtk_source_style_scheme_parent_class)->finalize (object);
 }
 
 static void
-gtk_source_style_scheme_set_property (GObject      *object,
-                                      guint         prop_id,
-                                      const GValue *value,
-                                      GParamSpec   *pspec)
+gtk_source_style_scheme_set_property (GObject     *object,
+                                     guint         prop_id,
+                                     const GValue *value,
+                                     GParamSpec   *pspec)
 {
        GtkSourceStyleScheme *scheme = GTK_SOURCE_STYLE_SCHEME (object);
 
        switch (prop_id)
        {
                case PROP_ID:
-                       g_free (scheme->id);
-                       scheme->id = g_value_dup_string (value);
+                       g_free (scheme->priv->id);
+                       scheme->priv->id = g_value_dup_string (value);
                        break;
 
                default:
@@ -170,29 +170,29 @@ gtk_source_style_scheme_set_property (GObject      *object,
 }
 
 static void
-gtk_source_style_scheme_get_property (GObject    *object,
-                                      guint       prop_id,
-                                      GValue     *value,
-                                      GParamSpec *pspec)
+gtk_source_style_scheme_get_property (GObject   *object,
+                                     guint       prop_id,
+                                     GValue     *value,
+                                     GParamSpec *pspec)
 {
        GtkSourceStyleScheme *scheme = GTK_SOURCE_STYLE_SCHEME (object);
 
        switch (prop_id)
        {
                case PROP_ID:
-                       g_value_set_string (value, scheme->id);
+                       g_value_set_string (value, scheme->priv->id);
                        break;
 
                case PROP_NAME:
-                       g_value_set_string (value, scheme->name);
+                       g_value_set_string (value, scheme->priv->name);
                        break;
 
                case PROP_DESCRIPTION:
-                       g_value_set_string (value, scheme->description);
+                       g_value_set_string (value, scheme->priv->description);
                        break;
 
                case PROP_FILENAME:
-                       g_value_set_string (value, scheme->filename);
+                       g_value_set_string (value, scheme->priv->filename);
                        break;
 
                default:
@@ -277,18 +277,18 @@ unref_if_not_null (gpointer object)
 static void
 gtk_source_style_scheme_init (GtkSourceStyleScheme *scheme)
 {
-       scheme = gtk_source_style_scheme_get_instance_private (scheme);
+       scheme->priv = gtk_source_style_scheme_get_instance_private (scheme);
 
-       scheme->defined_styles = g_hash_table_new_full (g_str_hash, g_str_equal,
+       scheme->priv->defined_styles = g_hash_table_new_full (g_str_hash, g_str_equal,
                                                              g_free, g_object_unref);
 
-       scheme->style_cache = g_hash_table_new_full (g_str_hash, g_str_equal,
+       scheme->priv->style_cache = g_hash_table_new_full (g_str_hash, g_str_equal,
                                                           g_free, unref_if_not_null);
 
-       scheme->named_colors = g_hash_table_new_full (g_str_hash, g_str_equal,
+       scheme->priv->named_colors = g_hash_table_new_full (g_str_hash, g_str_equal,
                                                            g_free, g_free);
 
-       scheme->css_provider = gtk_css_provider_new ();
+       scheme->priv->css_provider = gtk_css_provider_new ();
 }
 
 /**
@@ -303,9 +303,9 @@ const gchar *
 gtk_source_style_scheme_get_id (GtkSourceStyleScheme *scheme)
 {
        g_return_val_if_fail (GTK_SOURCE_IS_STYLE_SCHEME (scheme), NULL);
-       g_return_val_if_fail (scheme->id != NULL, "");
+       g_return_val_if_fail (scheme->priv->id != NULL, "");
 
-       return scheme->id;
+       return scheme->priv->id;
 }
 
 /**
@@ -320,9 +320,9 @@ const gchar *
 gtk_source_style_scheme_get_name (GtkSourceStyleScheme *scheme)
 {
        g_return_val_if_fail (GTK_SOURCE_IS_STYLE_SCHEME (scheme), NULL);
-       g_return_val_if_fail (scheme->name != NULL, "");
+       g_return_val_if_fail (scheme->priv->name != NULL, "");
 
-       return scheme->name;
+       return scheme->priv->name;
 }
 
 /**
@@ -338,7 +338,7 @@ gtk_source_style_scheme_get_description (GtkSourceStyleScheme *scheme)
 {
        g_return_val_if_fail (GTK_SOURCE_IS_STYLE_SCHEME (scheme), NULL);
 
-       return scheme->description;
+       return scheme->priv->description;
 }
 
 /**
@@ -356,12 +356,12 @@ gtk_source_style_scheme_get_authors (GtkSourceStyleScheme *scheme)
 {
        g_return_val_if_fail (GTK_SOURCE_IS_STYLE_SCHEME (scheme), NULL);
 
-       if (scheme->authors == NULL)
+       if (scheme->priv->authors == NULL)
        {
                return NULL;
        }
 
-       return (const gchar * const *)scheme->authors->pdata;
+       return (const gchar * const *)scheme->priv->authors->pdata;
 }
 
 /**
@@ -378,7 +378,7 @@ gtk_source_style_scheme_get_filename (GtkSourceStyleScheme *scheme)
 {
        g_return_val_if_fail (GTK_SOURCE_IS_STYLE_SCHEME (scheme), NULL);
 
-       return scheme->filename;
+       return scheme->priv->filename;
 }
 
 /*
@@ -418,7 +418,7 @@ color_parse (const gchar *color,
  */
 static const gchar *
 get_color_by_name (GtkSourceStyleScheme *scheme,
-                   const gchar          *name)
+                  const gchar          *name)
 {
        const char *color = NULL;
 
@@ -437,11 +437,11 @@ get_color_by_name (GtkSourceStyleScheme *scheme,
        }
        else
        {
-               color = g_hash_table_lookup (scheme->named_colors, name);
+               color = g_hash_table_lookup (scheme->priv->named_colors, name);
 
-               if (color == NULL && scheme->parent != NULL)
+               if (color == NULL && scheme->priv->parent != NULL)
                {
-                       color = get_color_by_name (scheme->parent, name);
+                       color = get_color_by_name (scheme->priv->parent, name);
                }
 
                if (color == NULL)
@@ -455,7 +455,7 @@ get_color_by_name (GtkSourceStyleScheme *scheme,
 
 static GtkSourceStyle *
 fix_style_colors (GtkSourceStyleScheme *scheme,
-                  GtkSourceStyle       *real_style)
+                 GtkSourceStyle       *real_style)
 {
        GtkSourceStyle *style;
        guint i;
@@ -495,47 +495,6 @@ fix_style_colors (GtkSourceStyleScheme *scheme,
        return style;
 }
 
-static GtkSourceStyle *
-gtk_source_style_scheme_get_style_internal (GtkSourceStyleScheme *scheme,
-                                            const gchar          *style_id)
-{
-       GtkSourceStyle *style = NULL;
-       GtkSourceStyle *real_style;
-
-       if (g_hash_table_lookup_extended (scheme->style_cache,
-                                         style_id,
-                                         NULL,
-                                         (gpointer)&style))
-       {
-               return style;
-       }
-
-       real_style = g_hash_table_lookup (scheme->defined_styles, style_id);
-
-       if (real_style == NULL)
-       {
-               if (scheme->parent != NULL)
-               {
-                       style = gtk_source_style_scheme_get_style (scheme->parent,
-                                                                  style_id);
-               }
-               if (style != NULL)
-               {
-                       g_object_ref (style);
-               }
-       }
-       else
-       {
-               style = fix_style_colors (scheme, real_style);
-       }
-
-       g_hash_table_insert (scheme->style_cache,
-                            g_strdup (style_id),
-                            style);
-
-       return style;
-}
-
 /**
  * gtk_source_style_scheme_get_style:
  * @scheme: a #GtkSourceStyleScheme.
@@ -560,37 +519,44 @@ gtk_source_style_scheme_get_style_internal (GtkSourceStyleScheme *scheme,
  */
 GtkSourceStyle *
 gtk_source_style_scheme_get_style (GtkSourceStyleScheme *scheme,
-                                   const gchar          *style_id)
+                                  const gchar          *style_id)
 {
-       GtkSourceStyle *style;
+       GtkSourceStyle *style = NULL;
+       GtkSourceStyle *real_style;
 
        g_return_val_if_fail (GTK_SOURCE_IS_STYLE_SCHEME (scheme), NULL);
        g_return_val_if_fail (style_id != NULL, NULL);
 
+       if (g_hash_table_lookup_extended (scheme->priv->style_cache,
+                                         style_id,
+                                         NULL,
+                                         (gpointer)&style))
+       {
+               return style;
+       }
 
-       style = gtk_source_style_scheme_get_style_internal (scheme, style_id);
+       real_style = g_hash_table_lookup (scheme->priv->defined_styles, style_id);
 
-       if (style == NULL)
+       if (real_style == NULL)
        {
-               /* Long ago, "underlined" was added as a style. The problem with
-                * this is that it defines how something should look rather than
-                * classifying what it is.
-                *
-                * In general, this was used for URLs.
-                *
-                * However, going forward we want to change this but do our best
-                * to not break existing style-schemes. Should "net-address" be
-                * requested, but only "underlined" existed, we will fallback to
-                * the "underlined" style.
-                *
-                * If in the future, we need to support more fallbacks, this should
-                * be changed to a GHashTable to map from src->dst style id.
-                */
-               if (g_str_equal (style_id, "def:net-address"))
+               if (scheme->priv->parent != NULL)
                {
-                       style = gtk_source_style_scheme_get_style_internal (scheme, "def:underlined");
+                       style = gtk_source_style_scheme_get_style (scheme->priv->parent,
+                                                                  style_id);
+               }
+               if (style != NULL)
+               {
+                       g_object_ref (style);
                }
        }
+       else
+       {
+               style = fix_style_colors (scheme, real_style);
+       }
+
+       g_hash_table_insert (scheme->priv->style_cache,
+                            g_strdup (style_id),
+                            style);
 
        return style;
 }
@@ -621,8 +587,8 @@ _gtk_source_style_scheme_get_draw_spaces_style (GtkSourceStyleScheme *scheme)
 
 static gboolean
 get_color (GtkSourceStyle *style,
-           gboolean        foreground,
-           GdkRGBA        *dest)
+          gboolean        foreground,
+          GdkRGBA        *dest)
 {
        const gchar *color;
        guint mask;
@@ -661,7 +627,7 @@ get_color (GtkSourceStyle *style,
  */
 gboolean
 _gtk_source_style_scheme_get_current_line_color (GtkSourceStyleScheme *scheme,
-                                                 GdkRGBA              *color)
+                                                GdkRGBA              *color)
 {
        GtkSourceStyle *style;
 
@@ -692,7 +658,7 @@ _gtk_source_style_scheme_get_background_pattern_color (GtkSourceStyleScheme *sch
 
 static gchar *
 get_cursors_css_style (GtkSourceStyleScheme *scheme,
-                       GtkWidget            *widget)
+                      GtkWidget            *widget)
 {
        GtkSourceStyle *primary_style;
        GtkSourceStyle *secondary_style;
@@ -740,7 +706,6 @@ get_cursors_css_style (GtkSourceStyleScheme *scheme,
                gtk_style_context_set_state (context, GTK_STATE_FLAG_NORMAL);
 
                gtk_style_context_get (context,
-                                      gtk_style_context_get_state (context),
                                       "background-color", &background_color,
                                       NULL);
 
@@ -775,7 +740,7 @@ get_cursors_css_style (GtkSourceStyleScheme *scheme,
  */
 static GtkCssProvider *
 get_css_provider_cursors (GtkSourceStyleScheme *scheme,
-                          GtkWidget            *widget)
+                         GtkWidget            *widget)
 {
        gchar *css;
        GtkCssProvider *provider;
@@ -790,7 +755,7 @@ get_css_provider_cursors (GtkSourceStyleScheme *scheme,
 
        provider = gtk_css_provider_new ();
 
-       gtk_css_provider_load_from_data (provider, css, -1, &error);
+       gtk_css_provider_load_from_data (provider, css, -1);
        g_free (css);
 
        if (error != NULL)
@@ -814,7 +779,7 @@ get_css_provider_cursors (GtkSourceStyleScheme *scheme,
  */
 void
 _gtk_source_style_scheme_apply (GtkSourceStyleScheme *scheme,
-                                GtkSourceView        *view)
+                               GtkSourceView        *view)
 {
        GtkStyleContext *context;
 
@@ -823,32 +788,23 @@ _gtk_source_style_scheme_apply (GtkSourceStyleScheme *scheme,
 
        context = gtk_widget_get_style_context (GTK_WIDGET (view));
        gtk_style_context_add_provider (context,
-                                       GTK_STYLE_PROVIDER (scheme->css_provider),
+                                       GTK_STYLE_PROVIDER (scheme->priv->css_provider),
                                        GTK_SOURCE_STYLE_PROVIDER_PRIORITY);
 
-       G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
-       /* See https://bugzilla.gnome.org/show_bug.cgi?id=708583 */
-       gtk_style_context_invalidate (context);
-       G_GNUC_END_IGNORE_DEPRECATIONS;
-
        /* The CssProvider for the cursors needs that the first provider is
         * applied, to get the background color.
         */
-       if (scheme->css_provider_cursors == NULL)
+       if (scheme->priv->css_provider_cursors == NULL)
        {
-               scheme->css_provider_cursors = get_css_provider_cursors (scheme,
+               scheme->priv->css_provider_cursors = get_css_provider_cursors (scheme,
                                                                               GTK_WIDGET (view));
        }
 
-       if (scheme->css_provider_cursors != NULL)
+       if (scheme->priv->css_provider_cursors != NULL)
        {
                gtk_style_context_add_provider (context,
-                                               GTK_STYLE_PROVIDER (scheme->css_provider_cursors),
+                                               GTK_STYLE_PROVIDER (scheme->priv->css_provider_cursors),
                                                GTK_SOURCE_STYLE_PROVIDER_PRIORITY);
-
-               G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
-               gtk_style_context_invalidate (context);
-               G_GNUC_END_IGNORE_DEPRECATIONS;
        }
 }
 
@@ -863,7 +819,7 @@ _gtk_source_style_scheme_apply (GtkSourceStyleScheme *scheme,
  */
 void
 _gtk_source_style_scheme_unapply (GtkSourceStyleScheme *scheme,
-                                  GtkSourceView        *view)
+                                 GtkSourceView        *view)
 {
        GtkStyleContext *context;
 
@@ -872,18 +828,13 @@ _gtk_source_style_scheme_unapply (GtkSourceStyleScheme *scheme,
 
        context = gtk_widget_get_style_context (GTK_WIDGET (view));
        gtk_style_context_remove_provider (context,
-                                          GTK_STYLE_PROVIDER (scheme->css_provider));
+                                          GTK_STYLE_PROVIDER (scheme->priv->css_provider));
 
-       if (scheme->css_provider_cursors != NULL)
+       if (scheme->priv->css_provider_cursors != NULL)
        {
                gtk_style_context_remove_provider (context,
-                                                  GTK_STYLE_PROVIDER (scheme->css_provider_cursors));
+                                                  GTK_STYLE_PROVIDER (scheme->priv->css_provider_cursors));
        }
-
-       G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
-       /* See https://bugzilla.gnome.org/show_bug.cgi?id=708583 */
-       gtk_style_context_invalidate (context);
-       G_GNUC_END_IGNORE_DEPRECATIONS;
 }
 
 /* --- PARSER ---------------------------------------------------------------- */
@@ -1000,10 +951,9 @@ generate_css_style (GtkSourceStyleScheme *scheme)
        {
                GError *error = NULL;
 
-               gtk_css_provider_load_from_data (scheme->css_provider,
+               gtk_css_provider_load_from_data (scheme->priv->css_provider,
                                                 final_style->str,
-                                                final_style->len,
-                                                &error);
+                                                final_style->len);
 
                if (error != NULL)
                {
@@ -1025,10 +975,10 @@ parse_bool (char *value)
 
 static void
 get_bool (xmlNode    *node,
-          const char *propname,
-          guint      *mask,
-          guint       mask_value,
-          gboolean   *value)
+         const char *propname,
+         guint      *mask,
+         guint       mask_value,
+         gboolean   *value)
 {
        xmlChar *tmp = xmlGetProp (node, BAD_CAST propname);
 
@@ -1042,11 +992,11 @@ get_bool (xmlNode    *node,
 }
 
 static gboolean
-parse_style (GtkSourceStyleScheme  *scheme,
-             xmlNode               *node,
-             gchar                **style_name_p,
-             GtkSourceStyle       **style_p,
-             GError               **error)
+parse_style (GtkSourceStyleScheme *scheme,
+            xmlNode              *node,
+            gchar               **style_name_p,
+            GtkSourceStyle      **style_p,
+            GError              **error)
 {
        GtkSourceStyle *use_style = NULL;
        GtkSourceStyle *result = NULL;
@@ -1213,9 +1163,9 @@ parse_style (GtkSourceStyleScheme  *scheme,
 }
 
 static gboolean
-parse_color (GtkSourceStyleScheme  *scheme,
-             xmlNode               *node,
-             GError               **error)
+parse_color (GtkSourceStyleScheme *scheme,
+            xmlNode              *node,
+            GError              **error)
 {
        xmlChar *name, *value;
        gboolean result = FALSE;
@@ -1229,13 +1179,13 @@ parse_color (GtkSourceStyleScheme  *scheme,
                g_set_error (error, ERROR_QUARK, 0, "value attribute missing in 'color' tag");
        else if (value[0] != '#' || value[1] == 0)
                g_set_error (error, ERROR_QUARK, 0, "value in 'color' tag is not of the form '#RGB' or 
'#name'");
-       else if (g_hash_table_lookup (scheme->named_colors, name) != NULL)
+       else if (g_hash_table_lookup (scheme->priv->named_colors, name) != NULL)
                g_set_error (error, ERROR_QUARK, 0, "duplicated color '%s'", name);
        else
                result = TRUE;
 
        if (result)
-               g_hash_table_insert (scheme->named_colors,
+               g_hash_table_insert (scheme->priv->named_colors,
                                     g_strdup ((char *) name),
                                     g_strdup ((char *) value));
 
@@ -1246,9 +1196,9 @@ parse_color (GtkSourceStyleScheme  *scheme,
 }
 
 static gboolean
-parse_style_scheme_child (GtkSourceStyleScheme  *scheme,
-                          xmlNode               *node,
-                          GError               **error)
+parse_style_scheme_child (GtkSourceStyleScheme *scheme,
+                         xmlNode              *node,
+                         GError              **error)
 {
        if (strcmp ((char*) node->name, "style") == 0)
        {
@@ -1258,7 +1208,7 @@ parse_style_scheme_child (GtkSourceStyleScheme  *scheme,
                if (!parse_style (scheme, node, &style_name, &style, error))
                        return FALSE;
 
-               g_hash_table_insert (scheme->defined_styles, style_name, style);
+               g_hash_table_insert (scheme->priv->defined_styles, style_name, style);
        }
        else if (strcmp ((char*) node->name, "color") == 0)
        {
@@ -1268,23 +1218,23 @@ parse_style_scheme_child (GtkSourceStyleScheme  *scheme,
        else if (strcmp ((char*) node->name, "author") == 0)
        {
                xmlChar *tmp = xmlNodeGetContent (node);
-               if (scheme->authors == NULL)
-                       scheme->authors = g_ptr_array_new_with_free_func (g_free);
+               if (scheme->priv->authors == NULL)
+                       scheme->priv->authors = g_ptr_array_new_with_free_func (g_free);
 
-               g_ptr_array_add (scheme->authors, g_strdup ((char*) tmp));
+               g_ptr_array_add (scheme->priv->authors, g_strdup ((char*) tmp));
 
                xmlFree (tmp);
        }
        else if (strcmp ((char*) node->name, "description") == 0)
        {
                xmlChar *tmp = xmlNodeGetContent (node);
-               scheme->description = g_strdup ((char*) tmp);
+               scheme->priv->description = g_strdup ((char*) tmp);
                xmlFree (tmp);
        }
        else if (strcmp ((char*) node->name, "_description") == 0)
        {
                xmlChar *tmp = xmlNodeGetContent (node);
-               scheme->description = g_strdup (_((char*) tmp));
+               scheme->priv->description = g_strdup (_((char*) tmp));
                xmlFree (tmp);
        }
        else
@@ -1297,9 +1247,9 @@ parse_style_scheme_child (GtkSourceStyleScheme  *scheme,
 }
 
 static void
-parse_style_scheme_element (GtkSourceStyleScheme  *scheme,
-                            xmlNode               *scheme_node,
-                            GError               **error)
+parse_style_scheme_element (GtkSourceStyleScheme *scheme,
+                           xmlNode              *scheme_node,
+                           GError              **error)
 {
        xmlChar *tmp;
        xmlNode *node;
@@ -1332,14 +1282,14 @@ parse_style_scheme_element (GtkSourceStyleScheme  *scheme,
                g_set_error (error, ERROR_QUARK, 0, "missing 'id' attribute");
                return;
        }
-       scheme->id = g_strdup ((char*) tmp);
+       scheme->priv->id = g_strdup ((char*) tmp);
        xmlFree (tmp);
 
        tmp = xmlGetProp (scheme_node, BAD_CAST "_name");
        if (tmp != NULL)
-               scheme->name = g_strdup (_((char*) tmp));
+               scheme->priv->name = g_strdup (_((char*) tmp));
        else if ((tmp = xmlGetProp (scheme_node, BAD_CAST "name")) != NULL)
-               scheme->name = g_strdup ((char*) tmp);
+               scheme->priv->name = g_strdup ((char*) tmp);
        else
        {
                g_set_error (error, ERROR_QUARK, 0, "missing 'name' attribute");
@@ -1349,7 +1299,7 @@ parse_style_scheme_element (GtkSourceStyleScheme  *scheme,
 
        tmp = xmlGetProp (scheme_node, BAD_CAST "parent-scheme");
        if (tmp != NULL)
-               scheme->parent_id = g_strdup ((char*) tmp);
+               scheme->priv->parent_id = g_strdup ((char*) tmp);
        xmlFree (tmp);
 
        for (node = scheme_node->children; node != NULL; node = node->next)
@@ -1358,8 +1308,8 @@ parse_style_scheme_element (GtkSourceStyleScheme  *scheme,
                                return;
 
        /* NULL-terminate the array of authors */
-       if (scheme->authors != NULL)
-               g_ptr_array_add (scheme->authors, NULL);
+       if (scheme->priv->authors != NULL)
+               g_ptr_array_add (scheme->priv->authors, NULL);
 }
 
 /**
@@ -1417,7 +1367,7 @@ _gtk_source_style_scheme_new_from_file (const gchar *filename)
        }
 
        scheme = g_object_new (GTK_SOURCE_TYPE_STYLE_SCHEME, NULL);
-       scheme->filename = g_strdup (filename);
+       scheme->priv->filename = g_strdup (filename);
 
        parse_style_scheme_element (scheme, node, &error);
 
@@ -1455,7 +1405,7 @@ _gtk_source_style_scheme_get_parent_id (GtkSourceStyleScheme *scheme)
 {
        g_return_val_if_fail (GTK_SOURCE_IS_STYLE_SCHEME (scheme), NULL);
 
-       return scheme->parent_id;
+       return scheme->priv->parent_id;
 }
 
 /**
@@ -1471,27 +1421,27 @@ _gtk_source_style_scheme_get_parent_id (GtkSourceStyleScheme *scheme)
  */
 void
 _gtk_source_style_scheme_set_parent (GtkSourceStyleScheme *scheme,
-                                     GtkSourceStyleScheme *parent_scheme)
+                                    GtkSourceStyleScheme *parent_scheme)
 {
        g_return_if_fail (GTK_SOURCE_IS_STYLE_SCHEME (scheme));
        g_return_if_fail (parent_scheme == NULL || GTK_SOURCE_IS_STYLE_SCHEME (parent_scheme));
 
-       if (scheme->parent == parent_scheme)
+       if (scheme->priv->parent == parent_scheme)
        {
                return;
        }
 
-       g_clear_object (&scheme->parent);
+       g_clear_object (&scheme->priv->parent);
 
        if (parent_scheme != NULL)
        {
                g_object_ref (parent_scheme);
        }
 
-       scheme->parent = parent_scheme;
+       scheme->priv->parent = parent_scheme;
 
        /* Update CSS based on parent styles */
-       g_hash_table_remove_all (scheme->style_cache);
+       g_hash_table_remove_all (scheme->priv->style_cache);
        generate_css_style (scheme);
 }
 
diff --git a/gtksourceview/gtksourcestylescheme.h b/gtksourceview/gtksourcestylescheme.h
index 6e598543..4052cca2 100644
--- a/gtksourceview/gtksourcestylescheme.h
+++ b/gtksourceview/gtksourcestylescheme.h
@@ -2,7 +2,7 @@
  *
  * This file is part of GtkSourceView
  *
- * Copyright 2003 - Paolo Maggi <paolo maggi polito it>
+ * Copyright (C) 2003 - Paolo Maggi <paolo maggi polito it>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -18,7 +18,8 @@
  * along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#pragma once
+#ifndef GTK_SOURCE_STYLE_SCHEME_H
+#define GTK_SOURCE_STYLE_SCHEME_H
 
 #if !defined (GTK_SOURCE_H_INSIDE) && !defined (GTK_SOURCE_COMPILATION)
 #error "Only <gtksourceview/gtksource.h> can be included directly."
@@ -30,23 +31,52 @@
 
 G_BEGIN_DECLS
 
-#define GTK_SOURCE_TYPE_STYLE_SCHEME (gtk_source_style_scheme_get_type())
+#define GTK_SOURCE_TYPE_STYLE_SCHEME             (gtk_source_style_scheme_get_type ())
+#define GTK_SOURCE_STYLE_SCHEME(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), 
GTK_SOURCE_TYPE_STYLE_SCHEME, GtkSourceStyleScheme))
+#define GTK_SOURCE_STYLE_SCHEME_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), 
GTK_SOURCE_TYPE_STYLE_SCHEME, GtkSourceStyleSchemeClass))
+#define GTK_SOURCE_IS_STYLE_SCHEME(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), 
GTK_SOURCE_TYPE_STYLE_SCHEME))
+#define GTK_SOURCE_IS_STYLE_SCHEME_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), 
GTK_SOURCE_TYPE_STYLE_SCHEME))
+#define GTK_SOURCE_STYLE_SCHEME_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), 
GTK_SOURCE_TYPE_STYLE_SCHEME, GtkSourceStyleSchemeClass))
+
+typedef struct _GtkSourceStyleSchemePrivate      GtkSourceStyleSchemePrivate;
+typedef struct _GtkSourceStyleSchemeClass        GtkSourceStyleSchemeClass;
+
+struct _GtkSourceStyleScheme
+{
+       GObject base;
+       GtkSourceStyleSchemePrivate *priv;
+};
+
+struct _GtkSourceStyleSchemeClass
+{
+       GObjectClass base_class;
+
+       /* Padding for future expansion */
+       gpointer padding[10];
+};
 
 GTK_SOURCE_AVAILABLE_IN_ALL
-G_DECLARE_FINAL_TYPE (GtkSourceStyleScheme, gtk_source_style_scheme, GTK_SOURCE, STYLE_SCHEME, GObject)
+GType                   gtk_source_style_scheme_get_type                       (void) G_GNUC_CONST;
 
 GTK_SOURCE_AVAILABLE_IN_ALL
-const gchar         *gtk_source_style_scheme_get_id          (GtkSourceStyleScheme *scheme);
+const gchar             *gtk_source_style_scheme_get_id                                (GtkSourceStyleScheme 
*scheme);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-const gchar         *gtk_source_style_scheme_get_name        (GtkSourceStyleScheme *scheme);
+const gchar             *gtk_source_style_scheme_get_name                      (GtkSourceStyleScheme 
*scheme);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-const gchar         *gtk_source_style_scheme_get_description (GtkSourceStyleScheme *scheme);
+const gchar             *gtk_source_style_scheme_get_description               (GtkSourceStyleScheme 
*scheme);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-const gchar * const *gtk_source_style_scheme_get_authors     (GtkSourceStyleScheme *scheme);
+const gchar * const *   gtk_source_style_scheme_get_authors                    (GtkSourceStyleScheme 
*scheme);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-const gchar         *gtk_source_style_scheme_get_filename    (GtkSourceStyleScheme *scheme);
+const gchar             *gtk_source_style_scheme_get_filename                  (GtkSourceStyleScheme 
*scheme);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-GtkSourceStyle      *gtk_source_style_scheme_get_style       (GtkSourceStyleScheme *scheme,
-                                                              const gchar          *style_id);
+GtkSourceStyle         *gtk_source_style_scheme_get_style                      (GtkSourceStyleScheme *scheme,
+                                                                                const gchar          
*style_id);
 
 G_END_DECLS
+
+#endif  /* GTK_SOURCE_STYLE_SCHEME_H */
diff --git a/gtksourceview/gtksourcestyleschemechooser.c b/gtksourceview/gtksourcestyleschemechooser.c
index 56de962d..ce85d6c9 100644
--- a/gtksourceview/gtksourcestyleschemechooser.c
+++ b/gtksourceview/gtksourcestyleschemechooser.c
@@ -2,7 +2,7 @@
  *
  * This file is part of GtkSourceView
  *
- * Copyright 2014 - Ignacio Casal Quinteiro
+ * Copyright (C) 2014 - Ignacio Casal Quinteiro
  *
  * GtkSourceView is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -18,7 +18,9 @@
  * along with GtkSourceView. If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "config.h"
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
 
 #include "gtksourcestyleschemechooser.h"
 #include "gtksourcestylescheme.h"
diff --git a/gtksourceview/gtksourcestyleschemechooser.h b/gtksourceview/gtksourcestyleschemechooser.h
index c0a67106..ea4a8e64 100644
--- a/gtksourceview/gtksourcestyleschemechooser.h
+++ b/gtksourceview/gtksourcestyleschemechooser.h
@@ -2,7 +2,7 @@
  *
  * This file is part of GtkSourceView
  *
- * Copyright 2014 - Ignacio Casal Quinteiro
+ * Copyright (C) 2014 - Ignacio Casal Quinteiro
  *
  * GtkSourceView is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -18,7 +18,8 @@
  * along with GtkSourceView. If not, see <http://www.gnu.org/licenses/>.
  */
 
-#pragma once
+#ifndef GTK_SOURCE_STYLE_SCHEME_CHOOSER_H
+#define GTK_SOURCE_STYLE_SCHEME_CHOOSER_H
 
 #if !defined (GTK_SOURCE_H_INSIDE) && !defined (GTK_SOURCE_COMPILATION)
 #error "Only <gtksourceview/gtksource.h> can be included directly."
@@ -30,29 +31,37 @@
 
 G_BEGIN_DECLS
 
-#define GTK_SOURCE_TYPE_STYLE_SCHEME_CHOOSER (gtk_source_style_scheme_chooser_get_type())
+#define GTK_SOURCE_TYPE_STYLE_SCHEME_CHOOSER                  (gtk_source_style_scheme_chooser_get_type ())
+#define GTK_SOURCE_STYLE_SCHEME_CHOOSER(obj)                  (G_TYPE_CHECK_INSTANCE_CAST ((obj), 
GTK_SOURCE_TYPE_STYLE_SCHEME_CHOOSER, GtkSourceStyleSchemeChooser))
+#define GTK_SOURCE_IS_STYLE_SCHEME_CHOOSER(obj)               (G_TYPE_CHECK_INSTANCE_TYPE ((obj), 
GTK_SOURCE_TYPE_STYLE_SCHEME_CHOOSER))
+#define GTK_SOURCE_STYLE_SCHEME_CHOOSER_GET_IFACE(inst)       (G_TYPE_INSTANCE_GET_INTERFACE ((inst), 
GTK_SOURCE_TYPE_STYLE_SCHEME_CHOOSER, GtkSourceStyleSchemeChooserInterface))
 
-GTK_SOURCE_AVAILABLE_IN_3_16
-G_DECLARE_INTERFACE (GtkSourceStyleSchemeChooser, gtk_source_style_scheme_chooser, GTK_SOURCE, 
STYLE_SCHEME_CHOOSER, GObject)
+typedef struct _GtkSourceStyleSchemeChooserInterface GtkSourceStyleSchemeChooserInterface;
 
 struct _GtkSourceStyleSchemeChooserInterface
 {
        GTypeInterface base_interface;
 
        /* Methods */
-       GtkSourceStyleScheme *(*get_style_scheme) (GtkSourceStyleSchemeChooser *chooser);
+       GtkSourceStyleScheme * (* get_style_scheme)       (GtkSourceStyleSchemeChooser *chooser);
 
-       void                  (*set_style_scheme) (GtkSourceStyleSchemeChooser *chooser,
-                                                  GtkSourceStyleScheme        *scheme);
+       void                   (* set_style_scheme)       (GtkSourceStyleSchemeChooser *chooser,
+                                                          GtkSourceStyleScheme        *scheme);
 
-       /*< private >*/
-       gpointer _reserved[12];
+       /* Padding */
+       gpointer padding[12];
 };
 
 GTK_SOURCE_AVAILABLE_IN_3_16
-GtkSourceStyleScheme *gtk_source_style_scheme_chooser_get_style_scheme (GtkSourceStyleSchemeChooser 
*chooser);
+GType                     gtk_source_style_scheme_chooser_get_type               (void) G_GNUC_CONST;
+
 GTK_SOURCE_AVAILABLE_IN_3_16
-void                  gtk_source_style_scheme_chooser_set_style_scheme (GtkSourceStyleSchemeChooser *chooser,
-                                                                        GtkSourceStyleScheme        *scheme);
+GtkSourceStyleScheme     *gtk_source_style_scheme_chooser_get_style_scheme       
(GtkSourceStyleSchemeChooser *chooser);
+
+GTK_SOURCE_AVAILABLE_IN_3_16
+void                      gtk_source_style_scheme_chooser_set_style_scheme       
(GtkSourceStyleSchemeChooser *chooser,
+                                                                                  GtkSourceStyleScheme       
 *scheme);
 
 G_END_DECLS
+
+#endif /* GTK_SOURCE_STYLE_SCHEME_CHOOSER_H */
diff --git a/gtksourceview/gtksourcestyleschemechooserbutton.c 
b/gtksourceview/gtksourcestyleschemechooserbutton.c
index fb69c0cb..447c6006 100644
--- a/gtksourceview/gtksourcestyleschemechooserbutton.c
+++ b/gtksourceview/gtksourcestyleschemechooserbutton.c
@@ -2,8 +2,8 @@
  *
  * This file is part of GtkSourceView
  *
- * Copyright 2014 - Christian Hergert
- * Copyright 2014 - Ignacio Casal Quinteiro
+ * Copyright (C) 2014 - Christian Hergert
+ * Copyright (C) 2014 - Ignacio Casal Quinteiro
  *
  * GtkSourceView is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -19,7 +19,9 @@
  * along with GtkSourceView. If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "config.h"
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
 
 #include <glib/gi18n-lib.h>
 
@@ -53,14 +55,16 @@ typedef struct
        GtkSourceStyleSchemeChooserWidget *chooser;
 } GtkSourceStyleSchemeChooserButtonPrivate;
 
-static void style_scheme_chooser_interface_init (GtkSourceStyleSchemeChooserInterface *iface);
+static void gtk_source_style_scheme_chooser_button_style_scheme_chooser_interface_init 
(GtkSourceStyleSchemeChooserInterface *iface);
 
 G_DEFINE_TYPE_WITH_CODE (GtkSourceStyleSchemeChooserButton,
                          gtk_source_style_scheme_chooser_button,
                          GTK_TYPE_BUTTON,
                          G_ADD_PRIVATE (GtkSourceStyleSchemeChooserButton)
                          G_IMPLEMENT_INTERFACE (GTK_SOURCE_TYPE_STYLE_SCHEME_CHOOSER,
-                                                style_scheme_chooser_interface_init))
+                                                
gtk_source_style_scheme_chooser_button_style_scheme_chooser_interface_init))
+
+#define GET_PRIV(o) gtk_source_style_scheme_chooser_button_get_instance_private (o)
 
 enum
 {
@@ -72,7 +76,7 @@ static void
 gtk_source_style_scheme_chooser_button_dispose (GObject *object)
 {
        GtkSourceStyleSchemeChooserButton *button = GTK_SOURCE_STYLE_SCHEME_CHOOSER_BUTTON (object);
-       GtkSourceStyleSchemeChooserButtonPrivate *priv = 
gtk_source_style_scheme_chooser_button_get_instance_private (button);
+       GtkSourceStyleSchemeChooserButtonPrivate *priv = GET_PRIV (button);
 
        g_clear_object (&priv->scheme);
 
@@ -131,7 +135,7 @@ dialog_destroy (GtkWidget *widget,
                 gpointer   data)
 {
        GtkSourceStyleSchemeChooserButton *button = GTK_SOURCE_STYLE_SCHEME_CHOOSER_BUTTON (data);
-       GtkSourceStyleSchemeChooserButtonPrivate *priv = 
gtk_source_style_scheme_chooser_button_get_instance_private (button);
+       GtkSourceStyleSchemeChooserButtonPrivate *priv = GET_PRIV (button);
 
        priv->dialog = NULL;
        priv->chooser = NULL;
@@ -151,7 +155,7 @@ dialog_response (GtkDialog *dialog,
        else if (response == GTK_RESPONSE_OK)
        {
                GtkSourceStyleSchemeChooserButton *button = GTK_SOURCE_STYLE_SCHEME_CHOOSER_BUTTON (data);
-               GtkSourceStyleSchemeChooserButtonPrivate *priv = 
gtk_source_style_scheme_chooser_button_get_instance_private (button);
+               GtkSourceStyleSchemeChooserButtonPrivate *priv = GET_PRIV (button);
                GtkSourceStyleScheme *scheme;
 
                scheme = gtk_source_style_scheme_chooser_get_style_scheme (GTK_SOURCE_STYLE_SCHEME_CHOOSER 
(priv->chooser));
@@ -167,7 +171,7 @@ dialog_response (GtkDialog *dialog,
 static void
 ensure_dialog (GtkSourceStyleSchemeChooserButton *button)
 {
-       GtkSourceStyleSchemeChooserButtonPrivate *priv = 
gtk_source_style_scheme_chooser_button_get_instance_private (button);
+       GtkSourceStyleSchemeChooserButtonPrivate *priv = GET_PRIV (button);
        GtkWidget *parent, *dialog, *scrolled_window;
        GtkWidget *content_area;
 
@@ -176,7 +180,7 @@ ensure_dialog (GtkSourceStyleSchemeChooserButton *button)
                return;
        }
 
-       parent = gtk_widget_get_toplevel (GTK_WIDGET (button));
+       parent = GTK_WIDGET (gtk_widget_get_root (GTK_WIDGET (button)));
 
        /* TODO: have a ChooserDialog? */
        priv->dialog = dialog = gtk_dialog_new_with_buttons (_("Select a Style"),
@@ -203,7 +207,7 @@ ensure_dialog (GtkSourceStyleSchemeChooserButton *button)
 
        gtk_container_add (GTK_CONTAINER (scrolled_window), GTK_WIDGET (priv->chooser));
 
-       if (gtk_widget_is_toplevel (parent) && GTK_IS_WINDOW (parent))
+       if (GTK_IS_ROOT (parent) && GTK_IS_WINDOW (parent))
        {
                if (GTK_WINDOW (parent) != gtk_window_get_transient_for (GTK_WINDOW (dialog)))
                {
@@ -224,7 +228,7 @@ static void
 gtk_source_style_scheme_chooser_button_clicked (GtkButton *button)
 {
        GtkSourceStyleSchemeChooserButton *cbutton = GTK_SOURCE_STYLE_SCHEME_CHOOSER_BUTTON (button);
-       GtkSourceStyleSchemeChooserButtonPrivate *priv = 
gtk_source_style_scheme_chooser_button_get_instance_private (cbutton);
+       GtkSourceStyleSchemeChooserButtonPrivate *priv = GET_PRIV (cbutton);
 
        ensure_dialog (cbutton);
 
@@ -259,7 +263,7 @@ static GtkSourceStyleScheme *
 gtk_source_style_scheme_chooser_button_get_style_scheme (GtkSourceStyleSchemeChooser *chooser)
 {
        GtkSourceStyleSchemeChooserButton *button = GTK_SOURCE_STYLE_SCHEME_CHOOSER_BUTTON (chooser);
-       GtkSourceStyleSchemeChooserButtonPrivate *priv = 
gtk_source_style_scheme_chooser_button_get_instance_private (button);
+       GtkSourceStyleSchemeChooserButtonPrivate *priv = GET_PRIV (button);
 
        return priv->scheme;
 }
@@ -267,7 +271,7 @@ gtk_source_style_scheme_chooser_button_get_style_scheme (GtkSourceStyleSchemeCho
 static void
 gtk_source_style_scheme_chooser_button_update_label (GtkSourceStyleSchemeChooserButton *button)
 {
-       GtkSourceStyleSchemeChooserButtonPrivate *priv = 
gtk_source_style_scheme_chooser_button_get_instance_private (button);
+       GtkSourceStyleSchemeChooserButtonPrivate *priv = GET_PRIV (button);
        const gchar *label;
 
        label = priv->scheme != NULL ? gtk_source_style_scheme_get_name (priv->scheme) : NULL;
@@ -279,7 +283,7 @@ gtk_source_style_scheme_chooser_button_set_style_scheme (GtkSourceStyleSchemeCho
                                                          GtkSourceStyleScheme        *scheme)
 {
        GtkSourceStyleSchemeChooserButton *button = GTK_SOURCE_STYLE_SCHEME_CHOOSER_BUTTON (chooser);
-       GtkSourceStyleSchemeChooserButtonPrivate *priv = 
gtk_source_style_scheme_chooser_button_get_instance_private (button);
+       GtkSourceStyleSchemeChooserButtonPrivate *priv = GET_PRIV (button);
 
        if (g_set_object (&priv->scheme, scheme))
        {
@@ -290,7 +294,7 @@ gtk_source_style_scheme_chooser_button_set_style_scheme (GtkSourceStyleSchemeCho
 }
 
 static void
-style_scheme_chooser_interface_init (GtkSourceStyleSchemeChooserInterface *iface)
+gtk_source_style_scheme_chooser_button_style_scheme_chooser_interface_init 
(GtkSourceStyleSchemeChooserInterface *iface)
 {
        iface->get_style_scheme = gtk_source_style_scheme_chooser_button_get_style_scheme;
        iface->set_style_scheme = gtk_source_style_scheme_chooser_button_set_style_scheme;
diff --git a/gtksourceview/gtksourcestyleschemechooserbutton.h 
b/gtksourceview/gtksourcestyleschemechooserbutton.h
index 1615c5cb..1d894ced 100644
--- a/gtksourceview/gtksourcestyleschemechooserbutton.h
+++ b/gtksourceview/gtksourcestyleschemechooserbutton.h
@@ -2,8 +2,8 @@
  *
  * This file is part of GtkSourceView
  *
- * Copyright 2014 - Christian Hergert
- * Copyright 2014 - Ignacio Casal Quinteiro
+ * Copyright (C) 2014 - Christian Hergert
+ * Copyright (C) 2014 - Ignacio Casal Quinteiro
  *
  * GtkSourceView is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -19,7 +19,8 @@
  * along with GtkSourceView. If not, see <http://www.gnu.org/licenses/>.
  */
 
-#pragma once
+#ifndef GTK_SOURCE_STYLE_SCHEME_CHOOSER_BUTTON_H
+#define GTK_SOURCE_STYLE_SCHEME_CHOOSER_BUTTON_H
 
 #if !defined (GTK_SOURCE_H_INSIDE) && !defined (GTK_SOURCE_COMPILATION)
 #error "Only <gtksourceview/gtksource.h> can be included directly."
@@ -31,20 +32,34 @@
 
 G_BEGIN_DECLS
 
-#define GTK_SOURCE_TYPE_STYLE_SCHEME_CHOOSER_BUTTON (gtk_source_style_scheme_chooser_button_get_type())
+#define GTK_SOURCE_TYPE_STYLE_SCHEME_CHOOSER_BUTTON            
(gtk_source_style_scheme_chooser_button_get_type())
+#define GTK_SOURCE_STYLE_SCHEME_CHOOSER_BUTTON(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), 
GTK_SOURCE_TYPE_STYLE_SCHEME_CHOOSER_BUTTON, GtkSourceStyleSchemeChooserButton))
+#define GTK_SOURCE_STYLE_SCHEME_CHOOSER_BUTTON_CONST(obj)      (G_TYPE_CHECK_INSTANCE_CAST ((obj), 
GTK_SOURCE_TYPE_STYLE_SCHEME_CHOOSER_BUTTON, GtkSourceStyleSchemeChooserButton const))
+#define GTK_SOURCE_STYLE_SCHEME_CHOOSER_BUTTON_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass),  
GTK_SOURCE_TYPE_STYLE_SCHEME_CHOOSER_BUTTON, GtkSourceStyleSchemeChooserButtonClass))
+#define GTK_SOURCE_IS_STYLE_SCHEME_CHOOSER_BUTTON(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), 
GTK_SOURCE_TYPE_STYLE_SCHEME_CHOOSER_BUTTON))
+#define GTK_SOURCE_IS_STYLE_SCHEME_CHOOSER_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),  
GTK_SOURCE_TYPE_STYLE_SCHEME_CHOOSER_BUTTON))
+#define GTK_SOURCE_STYLE_SCHEME_CHOOSER_BUTTON_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj),  
GTK_SOURCE_TYPE_STYLE_SCHEME_CHOOSER_BUTTON, GtkSourceStyleSchemeChooserButtonClass))
+
+typedef struct _GtkSourceStyleSchemeChooserButtonClass GtkSourceStyleSchemeChooserButtonClass;
+
+struct _GtkSourceStyleSchemeChooserButton
+{
+       GtkButton parent;
+};
 
 struct _GtkSourceStyleSchemeChooserButtonClass
 {
        GtkButtonClass parent;
 
-       /*< private >*/
-       gpointer _reserved[10];
+       gpointer padding[10];
 };
 
 GTK_SOURCE_AVAILABLE_IN_3_16
-G_DECLARE_DERIVABLE_TYPE (GtkSourceStyleSchemeChooserButton, gtk_source_style_scheme_chooser_button, 
GTK_SOURCE, STYLE_SCHEME_CHOOSER_BUTTON, GtkButton)
+GType                 gtk_source_style_scheme_chooser_button_get_type              (void);
 
 GTK_SOURCE_AVAILABLE_IN_3_16
-GtkWidget *gtk_source_style_scheme_chooser_button_new (void);
+GtkWidget            *gtk_source_style_scheme_chooser_button_new                   (void);
 
 G_END_DECLS
+
+#endif /* GTK_SOURCE_STYLE_SCHEME_CHOOSER_BUTTON_H */
diff --git a/gtksourceview/gtksourcestyleschemechooserwidget.c 
b/gtksourceview/gtksourcestyleschemechooserwidget.c
index 68175b51..11ccfbf1 100644
--- a/gtksourceview/gtksourcestyleschemechooserwidget.c
+++ b/gtksourceview/gtksourcestyleschemechooserwidget.c
@@ -2,8 +2,8 @@
  *
  * This file is part of GtkSourceView
  *
- * Copyright 2014 - Christian Hergert
- * Copyright 2014 - Ignacio Casal Quinteiro
+ * Copyright (C) 2014 - Christian Hergert
+ * Copyright (C) 2014 - Ignacio Casal Quinteiro
  *
  * GtkSourceView is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -19,7 +19,9 @@
  * along with GtkSourceView. If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "config.h"
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
 
 #include "gtksourcestyleschemechooserwidget.h"
 #include "gtksourcestyleschemechooser.h"
@@ -54,14 +56,16 @@ typedef struct
        GtkSourceStyleScheme *scheme;
 } GtkSourceStyleSchemeChooserWidgetPrivate;
 
-static void style_scheme_chooser_interface_init (GtkSourceStyleSchemeChooserInterface *iface);
+static void gtk_source_style_scheme_chooser_widget_style_scheme_chooser_interface_init 
(GtkSourceStyleSchemeChooserInterface *iface);
 
 G_DEFINE_TYPE_WITH_CODE (GtkSourceStyleSchemeChooserWidget,
                          gtk_source_style_scheme_chooser_widget,
                          GTK_TYPE_BIN,
                          G_ADD_PRIVATE (GtkSourceStyleSchemeChooserWidget)
                          G_IMPLEMENT_INTERFACE (GTK_SOURCE_TYPE_STYLE_SCHEME_CHOOSER,
-                                                style_scheme_chooser_interface_init))
+                                                
gtk_source_style_scheme_chooser_widget_style_scheme_chooser_interface_init))
+
+#define GET_PRIV(o) gtk_source_style_scheme_chooser_widget_get_instance_private (o)
 
 enum
 {
@@ -73,7 +77,7 @@ static void
 gtk_source_style_scheme_chooser_widget_dispose (GObject *object)
 {
        GtkSourceStyleSchemeChooserWidget *widget = GTK_SOURCE_STYLE_SCHEME_CHOOSER_WIDGET (object);
-       GtkSourceStyleSchemeChooserWidgetPrivate *priv = 
gtk_source_style_scheme_chooser_widget_get_instance_private (widget);
+       GtkSourceStyleSchemeChooserWidgetPrivate *priv = GET_PRIV (widget);
 
        g_clear_object (&priv->scheme);
 
@@ -134,9 +138,10 @@ make_row (GtkSourceStyleScheme *scheme,
 {
        GtkWidget *row;
        AtkObject *accessible;
-       GtkWidget *event;
        GtkSourceBuffer *buffer;
        GtkWidget *view;
+       GtkWidget *overlay;
+       GtkWidget *label;
        gchar *text;
 
        row = gtk_list_box_row_new ();
@@ -147,11 +152,6 @@ make_row (GtkSourceStyleScheme *scheme,
 
        g_object_set_data (G_OBJECT (row), "scheme", scheme);
 
-       event = gtk_event_box_new ();
-       gtk_event_box_set_above_child (GTK_EVENT_BOX (event), TRUE);
-       gtk_widget_show (event);
-       gtk_container_add (GTK_CONTAINER (row), event);
-
        buffer = gtk_source_buffer_new_with_language (language);
        gtk_source_buffer_set_highlight_matching_brackets (buffer, FALSE);
        gtk_source_buffer_set_style_scheme (buffer, scheme);
@@ -161,18 +161,29 @@ make_row (GtkSourceStyleScheme *scheme,
        gtk_text_buffer_set_text (GTK_TEXT_BUFFER (buffer), text, -1);
        g_free (text);
 
+       overlay = gtk_overlay_new ();
+       gtk_container_add (GTK_CONTAINER (row), overlay);
+       gtk_widget_show (overlay);
+
        view = g_object_new (GTK_SOURCE_TYPE_VIEW,
                             "buffer", buffer,
                             "can-focus", FALSE,
                             "cursor-visible", FALSE,
                             "editable", FALSE,
                             "visible", TRUE,
-                            "show-line-numbers", TRUE,
                             "right-margin-position", 30,
                             "show-right-margin", TRUE,
                             "margin", 2,
                             NULL);
-       gtk_container_add (GTK_CONTAINER (event), view);
+       gtk_container_add (GTK_CONTAINER (overlay), view);
+
+       label = g_object_new (GTK_TYPE_LABEL,
+                             "can-focus", FALSE,
+                             "expand", TRUE,
+                             "selectable", FALSE,
+                             "visible", TRUE,
+                             NULL);
+       gtk_overlay_add_overlay (GTK_OVERLAY (overlay), label);
 
        return row;
 }
@@ -182,7 +193,7 @@ on_row_selected (GtkListBox                        *list_box,
                  GtkListBoxRow                     *row,
                  GtkSourceStyleSchemeChooserWidget *widget)
 {
-       GtkSourceStyleSchemeChooserWidgetPrivate *priv = 
gtk_source_style_scheme_chooser_widget_get_instance_private (widget);
+       GtkSourceStyleSchemeChooserWidgetPrivate *priv = GET_PRIV (widget);
 
        if (row != NULL)
        {
@@ -199,7 +210,7 @@ on_row_selected (GtkListBox                        *list_box,
 
 static void
 destroy_child_cb (GtkWidget *widget,
-                  gpointer   data)
+                 gpointer   data)
 {
        gtk_widget_destroy (widget);
 }
@@ -207,7 +218,7 @@ destroy_child_cb (GtkWidget *widget,
 static void
 gtk_source_style_scheme_chooser_widget_populate (GtkSourceStyleSchemeChooserWidget *widget)
 {
-       GtkSourceStyleSchemeChooserWidgetPrivate *priv = 
gtk_source_style_scheme_chooser_widget_get_instance_private (widget);
+       GtkSourceStyleSchemeChooserWidgetPrivate *priv = GET_PRIV (widget);
        GtkSourceLanguageManager *lm;
        GtkSourceLanguage *lang;
        GtkSourceStyleSchemeManager *manager;
@@ -265,7 +276,7 @@ on_scheme_ids_changed (GtkSourceStyleSchemeManager       *manager,
 static void
 gtk_source_style_scheme_chooser_widget_init (GtkSourceStyleSchemeChooserWidget *widget)
 {
-       GtkSourceStyleSchemeChooserWidgetPrivate *priv = 
gtk_source_style_scheme_chooser_widget_get_instance_private (widget);
+       GtkSourceStyleSchemeChooserWidgetPrivate *priv = GET_PRIV (widget);
        GtkSourceStyleSchemeManager *manager;
 
        priv->list_box = GTK_LIST_BOX (gtk_list_box_new ());
@@ -294,7 +305,7 @@ static GtkSourceStyleScheme *
 gtk_source_style_scheme_chooser_widget_get_style_scheme (GtkSourceStyleSchemeChooser *chooser)
 {
        GtkSourceStyleSchemeChooserWidget *widget = GTK_SOURCE_STYLE_SCHEME_CHOOSER_WIDGET (chooser);
-       GtkSourceStyleSchemeChooserWidgetPrivate *priv = 
gtk_source_style_scheme_chooser_widget_get_instance_private (widget);
+       GtkSourceStyleSchemeChooserWidgetPrivate *priv = GET_PRIV (widget);
 
        return priv->scheme;
 }
@@ -304,7 +315,7 @@ gtk_source_style_scheme_chooser_widget_set_style_scheme (GtkSourceStyleSchemeCho
                                                          GtkSourceStyleScheme        *scheme)
 {
        GtkSourceStyleSchemeChooserWidget *widget = GTK_SOURCE_STYLE_SCHEME_CHOOSER_WIDGET (chooser);
-       GtkSourceStyleSchemeChooserWidgetPrivate *priv = 
gtk_source_style_scheme_chooser_widget_get_instance_private (widget);
+       GtkSourceStyleSchemeChooserWidgetPrivate *priv = GET_PRIV (widget);
 
        if (g_set_object (&priv->scheme, scheme))
        {
@@ -336,7 +347,7 @@ gtk_source_style_scheme_chooser_widget_set_style_scheme (GtkSourceStyleSchemeCho
 }
 
 static void
-style_scheme_chooser_interface_init (GtkSourceStyleSchemeChooserInterface *iface)
+gtk_source_style_scheme_chooser_widget_style_scheme_chooser_interface_init 
(GtkSourceStyleSchemeChooserInterface *iface)
 {
        iface->get_style_scheme = gtk_source_style_scheme_chooser_widget_get_style_scheme;
        iface->set_style_scheme = gtk_source_style_scheme_chooser_widget_set_style_scheme;
diff --git a/gtksourceview/gtksourcestyleschemechooserwidget.h 
b/gtksourceview/gtksourcestyleschemechooserwidget.h
index ceb9320b..dafb1b38 100644
--- a/gtksourceview/gtksourcestyleschemechooserwidget.h
+++ b/gtksourceview/gtksourcestyleschemechooserwidget.h
@@ -2,8 +2,8 @@
  *
  * This file is part of GtkSourceView
  *
- * Copyright 2014 - Christian Hergert
- * Copyright 2014 - Ignacio Casal Quinteiro
+ * Copyright (C) 2014 - Christian Hergert
+ * Copyright (C) 2014 - Ignacio Casal Quinteiro
  *
  * GtkSourceView is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -19,31 +19,47 @@
  * along with GtkSourceView. If not, see <http://www.gnu.org/licenses/>.
  */
 
-#pragma once
+#ifndef GTK_SOURCE_STYLE_SCHEME_CHOOSER_WIDGET_H
+#define GTK_SOURCE_STYLE_SCHEME_CHOOSER_WIDGET_H
 
 #if !defined (GTK_SOURCE_H_INSIDE) && !defined (GTK_SOURCE_COMPILATION)
 #error "Only <gtksourceview/gtksource.h> can be included directly."
 #endif
 
 #include <gtk/gtk.h>
-#include <gtksourceview/gtksourcetypes.h>
+
+#include "gtksourcetypes.h"
 
 G_BEGIN_DECLS
 
-#define GTK_SOURCE_TYPE_STYLE_SCHEME_CHOOSER_WIDGET (gtk_source_style_scheme_chooser_widget_get_type())
+#define GTK_SOURCE_TYPE_STYLE_SCHEME_CHOOSER_WIDGET            
(gtk_source_style_scheme_chooser_widget_get_type())
+#define GTK_SOURCE_STYLE_SCHEME_CHOOSER_WIDGET(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), 
GTK_SOURCE_TYPE_STYLE_SCHEME_CHOOSER_WIDGET, GtkSourceStyleSchemeChooserWidget))
+#define GTK_SOURCE_STYLE_SCHEME_CHOOSER_WIDGET_CONST(obj)      (G_TYPE_CHECK_INSTANCE_CAST ((obj), 
GTK_SOURCE_TYPE_STYLE_SCHEME_CHOOSER_WIDGET, GtkSourceStyleSchemeChooserWidget const))
+#define GTK_SOURCE_STYLE_SCHEME_CHOOSER_WIDGET_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass),  
GTK_SOURCE_TYPE_STYLE_SCHEME_CHOOSER_WIDGET, GtkSourceStyleSchemeChooserWidgetClass))
+#define GTK_SOURCE_IS_STYLE_SCHEME_CHOOSER_WIDGET(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), 
GTK_SOURCE_TYPE_STYLE_SCHEME_CHOOSER_WIDGET))
+#define GTK_SOURCE_IS_STYLE_SCHEME_CHOOSER_WIDGET_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),  
GTK_SOURCE_TYPE_STYLE_SCHEME_CHOOSER_WIDGET))
+#define GTK_SOURCE_STYLE_SCHEME_CHOOSER_WIDGET_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj),  
GTK_SOURCE_TYPE_STYLE_SCHEME_CHOOSER_WIDGET, GtkSourceStyleSchemeChooserWidgetClass))
+
+typedef struct _GtkSourceStyleSchemeChooserWidgetClass GtkSourceStyleSchemeChooserWidgetClass;
+
+struct _GtkSourceStyleSchemeChooserWidget
+{
+       GtkBin parent;
+};
 
 struct _GtkSourceStyleSchemeChooserWidgetClass
 {
        GtkBinClass parent;
 
-       /*< private >*/
-       gpointer _reserved[10];
+       gpointer padding[10];
 };
 
 GTK_SOURCE_AVAILABLE_IN_3_16
-G_DECLARE_DERIVABLE_TYPE (GtkSourceStyleSchemeChooserWidget, gtk_source_style_scheme_chooser_widget, 
GTK_SOURCE, STYLE_SCHEME_CHOOSER_WIDGET, GtkBin)
+GType        gtk_source_style_scheme_chooser_widget_get_type              (void);
 
 GTK_SOURCE_AVAILABLE_IN_3_16
-GtkWidget *gtk_source_style_scheme_chooser_widget_new (void);
+GtkWidget   *gtk_source_style_scheme_chooser_widget_new                   (void);
 
 G_END_DECLS
+
+#endif /* GTK_SOURCE_STYLE_SCHEME_CHOOSER_WIDGET_H */
diff --git a/gtksourceview/gtksourcestyleschememanager-private.h 
b/gtksourceview/gtksourcestyleschememanager-private.h
index 7efc716d..18445c35 100644
--- a/gtksourceview/gtksourcestyleschememanager-private.h
+++ b/gtksourceview/gtksourcestyleschememanager-private.h
@@ -2,7 +2,7 @@
  *
  * This file is part of GtkSourceView
  *
- * Copyright 2003-2007 - Paolo Maggi <paolo maggi polito it>
+ * Copyright (C) 2003-2007 - Paolo Maggi <paolo maggi polito it>
  *
  * GtkSourceView is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -18,8 +18,10 @@
  * along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#pragma once
+#ifndef GTK_SOURCE_STYLE_SCHEME_MANAGER_PRIVATE_H
+#define GTK_SOURCE_STYLE_SCHEME_MANAGER_PRIVATE_H
 
+#include "gtksourcetypes.h"
 #include "gtksourcestyleschememanager.h"
 
 G_BEGIN_DECLS
@@ -28,3 +30,5 @@ G_GNUC_INTERNAL
 GtkSourceStyleSchemeManager *_gtk_source_style_scheme_manager_peek_default (void);
 
 G_END_DECLS
+
+#endif /* GTK_SOURCE_STYLE_SCHEME_MANAGER_PRIVATE_H */
diff --git a/gtksourceview/gtksourcestyleschememanager.c b/gtksourceview/gtksourcestyleschememanager.c
index d609d3f5..142c260c 100644
--- a/gtksourceview/gtksourcestyleschememanager.c
+++ b/gtksourceview/gtksourcestyleschememanager.c
@@ -2,7 +2,7 @@
 /*
  * This file is part of GtkSourceView
  *
- * Copyright 2003-2007 - Paolo Maggi <paolo gnome org>
+ * Copyright (C) 2003-2007 - Paolo Maggi <paolo gnome org>
  *
  * GtkSourceView is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -18,7 +18,9 @@
  * along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "config.h"
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
 
 #include <string.h>
 
@@ -35,13 +37,11 @@
  * Object which provides access to #GtkSourceStyleScheme<!-- -->s.
  */
 
-#define SCHEME_FILE_SUFFIX ".xml"
-#define STYLES_DIR         "styles"
+#define SCHEME_FILE_SUFFIX     ".xml"
+#define STYLES_DIR             "styles"
 
-struct _GtkSourceStyleSchemeManager
+struct _GtkSourceStyleSchemeManagerPrivate
 {
-       GObject          parent_instance;
-
        GHashTable      *schemes_hash;
 
        gchar          **search_path;
@@ -58,13 +58,13 @@ enum {
 
 static GtkSourceStyleSchemeManager *default_instance;
 
-G_DEFINE_TYPE (GtkSourceStyleSchemeManager, gtk_source_style_scheme_manager, G_TYPE_OBJECT)
+G_DEFINE_TYPE_WITH_PRIVATE (GtkSourceStyleSchemeManager, gtk_source_style_scheme_manager, G_TYPE_OBJECT)
 
 static void
-gtk_source_style_scheme_manager_set_property (GObject      *object,
-                                              guint         prop_id,
-                                              const GValue *value,
-                                              GParamSpec   *pspec)
+gtk_source_style_scheme_manager_set_property (GObject     *object,
+                                             guint         prop_id,
+                                             const GValue *value,
+                                             GParamSpec   *pspec)
 {
        GtkSourceStyleSchemeManager *sm;
 
@@ -87,9 +87,9 @@ gtk_source_style_scheme_manager_set_property (GObject      *object,
 
 static void
 gtk_source_style_scheme_manager_get_property (GObject    *object,
-                                              guint       prop_id,
-                                              GValue     *value,
-                                              GParamSpec *pspec)
+                                             guint       prop_id,
+                                             GValue     *value,
+                                             GParamSpec *pspec)
 {
        GtkSourceStyleSchemeManager *sm;
 
@@ -118,14 +118,14 @@ gtk_source_style_scheme_manager_get_property (GObject    *object,
 static void
 free_schemes (GtkSourceStyleSchemeManager *mgr)
 {
-       if (mgr->schemes_hash != NULL)
+       if (mgr->priv->schemes_hash != NULL)
        {
-               g_hash_table_destroy (mgr->schemes_hash);
-               mgr->schemes_hash = NULL;
+               g_hash_table_destroy (mgr->priv->schemes_hash);
+               mgr->priv->schemes_hash = NULL;
        }
 
-       g_strfreev (mgr->ids);
-       mgr->ids = NULL;
+       g_strfreev (mgr->priv->ids);
+       mgr->priv->ids = NULL;
 }
 
 static void
@@ -137,7 +137,7 @@ gtk_source_style_scheme_manager_finalize (GObject *object)
 
        free_schemes (mgr);
 
-       g_strfreev (mgr->search_path);
+       g_strfreev (mgr->priv->search_path);
 
        G_OBJECT_CLASS (gtk_source_style_scheme_manager_parent_class)->finalize (object);
 }
@@ -171,11 +171,11 @@ gtk_source_style_scheme_manager_class_init (GtkSourceStyleSchemeManagerClass *kl
 static void
 gtk_source_style_scheme_manager_init (GtkSourceStyleSchemeManager *mgr)
 {
-       mgr = gtk_source_style_scheme_manager_get_instance_private (mgr);
-       mgr->schemes_hash = NULL;
-       mgr->ids = NULL;
-       mgr->search_path = NULL;
-       mgr->need_reload = TRUE;
+       mgr->priv = gtk_source_style_scheme_manager_get_instance_private (mgr);
+       mgr->priv->schemes_hash = NULL;
+       mgr->priv->ids = NULL;
+       mgr->priv->search_path = NULL;
+       mgr->priv->need_reload = TRUE;
 }
 
 /**
@@ -220,9 +220,9 @@ _gtk_source_style_scheme_manager_peek_default (void)
 }
 
 static gboolean
-build_reference_chain (GtkSourceStyleScheme  *scheme,
-                       GHashTable            *hash,
-                       GSList               **ret)
+build_reference_chain (GtkSourceStyleScheme *scheme,
+                      GHashTable           *hash,
+                      GSList              **ret)
 {
        GSList *chain;
        gboolean retval = TRUE;
@@ -268,8 +268,7 @@ build_reference_chain (GtkSourceStyleScheme  *scheme,
 }
 
 static GSList *
-check_parents (GSList     *schemes,
-               GHashTable *hash)
+check_parents (GSList *schemes, GHashTable *hash)
 {
        GSList *to_check;
 
@@ -306,8 +305,7 @@ check_parents (GSList     *schemes,
 }
 
 static gint
-schemes_compare (GtkSourceStyleScheme *scheme1,
-                 GtkSourceStyleScheme *scheme2)
+schemes_compare (GtkSourceStyleScheme *scheme1, GtkSourceStyleScheme *scheme2)
 {
        const gchar *name1;
        const gchar *name2;
@@ -346,7 +344,7 @@ reload_if_needed (GtkSourceStyleSchemeManager *mgr)
        GSList *l;
        GHashTable *schemes_hash;
 
-       if (!mgr->need_reload)
+       if (!mgr->priv->need_reload)
                return;
 
        schemes_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
@@ -389,17 +387,17 @@ reload_if_needed (GtkSourceStyleSchemeManager *mgr)
 
        free_schemes (mgr);
 
-       mgr->need_reload = FALSE;
-       mgr->schemes_hash = schemes_hash;
+       mgr->priv->need_reload = FALSE;
+       mgr->priv->schemes_hash = schemes_hash;
 
-       mgr->ids = schemes_list_to_ids (schemes);
+       mgr->priv->ids = schemes_list_to_ids (schemes);
        g_slist_free (schemes);
 }
 
 static void
 notify_search_path (GtkSourceStyleSchemeManager *mgr)
 {
-       mgr->need_reload = TRUE;
+       mgr->priv->need_reload = TRUE;
 
        g_object_notify (G_OBJECT (mgr), "search-path");
        g_object_notify (G_OBJECT (mgr), "scheme-ids");
@@ -417,18 +415,18 @@ notify_search_path (GtkSourceStyleSchemeManager *mgr)
  */
 void
 gtk_source_style_scheme_manager_set_search_path (GtkSourceStyleSchemeManager  *manager,
-                                                 gchar                       **path)
+                                                gchar                       **path)
 {
        gchar **tmp;
 
        g_return_if_fail (GTK_SOURCE_IS_STYLE_SCHEME_MANAGER (manager));
 
-       tmp = manager->search_path;
+       tmp = manager->priv->search_path;
 
        if (path == NULL)
-               manager->search_path = _gtk_source_utils_get_default_dirs (STYLES_DIR);
+               manager->priv->search_path = _gtk_source_utils_get_default_dirs (STYLES_DIR);
        else
-               manager->search_path = g_strdupv (path);
+               manager->priv->search_path = g_strdupv (path);
 
        g_strfreev (tmp);
 
@@ -446,26 +444,26 @@ gtk_source_style_scheme_manager_set_search_path (GtkSourceStyleSchemeManager  *m
  */
 void
 gtk_source_style_scheme_manager_append_search_path (GtkSourceStyleSchemeManager *manager,
-                                                    const gchar                 *path)
+                                                   const gchar                 *path)
 {
        guint len = 0;
 
        g_return_if_fail (GTK_SOURCE_IS_STYLE_SCHEME_MANAGER (manager));
        g_return_if_fail (path != NULL);
 
-       if (manager->search_path == NULL)
-               manager->search_path = _gtk_source_utils_get_default_dirs (STYLES_DIR);
+       if (manager->priv->search_path == NULL)
+               manager->priv->search_path = _gtk_source_utils_get_default_dirs (STYLES_DIR);
 
-       g_return_if_fail (manager->search_path != NULL);
+       g_return_if_fail (manager->priv->search_path != NULL);
 
-       len = g_strv_length (manager->search_path);
+       len = g_strv_length (manager->priv->search_path);
 
-       manager->search_path = g_renew (gchar *,
-                                             manager->search_path,
+       manager->priv->search_path = g_renew (gchar *,
+                                             manager->priv->search_path,
                                              len + 2); /* old path + new entry + NULL */
 
-       manager->search_path[len] = g_strdup (path);
-       manager->search_path[len + 1] = NULL;
+       manager->priv->search_path[len] = g_strdup (path);
+       manager->priv->search_path[len + 1] = NULL;
 
        notify_search_path (manager);
 }
@@ -481,7 +479,7 @@ gtk_source_style_scheme_manager_append_search_path (GtkSourceStyleSchemeManager
  */
 void
 gtk_source_style_scheme_manager_prepend_search_path (GtkSourceStyleSchemeManager *manager,
-                                                     const gchar                 *path)
+                                                    const gchar                 *path)
 {
        guint len = 0;
        gchar **new_search_path;
@@ -489,19 +487,19 @@ gtk_source_style_scheme_manager_prepend_search_path (GtkSourceStyleSchemeManager
        g_return_if_fail (GTK_SOURCE_IS_STYLE_SCHEME_MANAGER (manager));
        g_return_if_fail (path != NULL);
 
-       if (manager->search_path == NULL)
-               manager->search_path = _gtk_source_utils_get_default_dirs (STYLES_DIR);
+       if (manager->priv->search_path == NULL)
+               manager->priv->search_path = _gtk_source_utils_get_default_dirs (STYLES_DIR);
 
-       g_return_if_fail (manager->search_path != NULL);
+       g_return_if_fail (manager->priv->search_path != NULL);
 
-       len = g_strv_length (manager->search_path);
+       len = g_strv_length (manager->priv->search_path);
 
        new_search_path = g_new (gchar *, len + 2);
        new_search_path[0] = g_strdup (path);
-       memcpy (new_search_path + 1, manager->search_path, (len + 1) * sizeof (gchar*));
+       memcpy (new_search_path + 1, manager->priv->search_path, (len + 1) * sizeof (gchar*));
 
-       g_free (manager->search_path);
-       manager->search_path = new_search_path;
+       g_free (manager->priv->search_path);
+       manager->priv->search_path = new_search_path;
 
        notify_search_path (manager);
 }
@@ -522,10 +520,10 @@ gtk_source_style_scheme_manager_get_search_path (GtkSourceStyleSchemeManager *ma
 {
        g_return_val_if_fail (GTK_SOURCE_IS_STYLE_SCHEME_MANAGER (manager), NULL);
 
-       if (manager->search_path == NULL)
-               manager->search_path = _gtk_source_utils_get_default_dirs (STYLES_DIR);
+       if (manager->priv->search_path == NULL)
+               manager->priv->search_path = _gtk_source_utils_get_default_dirs (STYLES_DIR);
 
-       return (const gchar * const *)manager->search_path;
+       return (const gchar * const *)manager->priv->search_path;
 }
 
 /**
@@ -541,7 +539,7 @@ gtk_source_style_scheme_manager_force_rescan (GtkSourceStyleSchemeManager *manag
 {
        g_return_if_fail (GTK_SOURCE_IS_STYLE_SCHEME_MANAGER (manager));
 
-       manager->need_reload = TRUE;
+       manager->priv->need_reload = TRUE;
 
        g_object_notify (G_OBJECT (manager), "scheme-ids");
 }
@@ -565,7 +563,7 @@ gtk_source_style_scheme_manager_get_scheme_ids (GtkSourceStyleSchemeManager *man
 
        reload_if_needed (manager);
 
-       return (const gchar * const *)manager->ids;
+       return (const gchar * const *)manager->priv->ids;
 }
 
 /**
@@ -580,12 +578,12 @@ gtk_source_style_scheme_manager_get_scheme_ids (GtkSourceStyleSchemeManager *man
  */
 GtkSourceStyleScheme *
 gtk_source_style_scheme_manager_get_scheme (GtkSourceStyleSchemeManager *manager,
-                                            const gchar                 *scheme_id)
+                                           const gchar                 *scheme_id)
 {
        g_return_val_if_fail (GTK_SOURCE_IS_STYLE_SCHEME_MANAGER (manager), NULL);
        g_return_val_if_fail (scheme_id != NULL, NULL);
 
        reload_if_needed (manager);
 
-       return g_hash_table_lookup (manager->schemes_hash, scheme_id);
+       return g_hash_table_lookup (manager->priv->schemes_hash, scheme_id);
 }
diff --git a/gtksourceview/gtksourcestyleschememanager.h b/gtksourceview/gtksourcestyleschememanager.h
index 3335cf60..78cd8bb2 100644
--- a/gtksourceview/gtksourcestyleschememanager.h
+++ b/gtksourceview/gtksourcestyleschememanager.h
@@ -2,7 +2,7 @@
  *
  * This file is part of GtkSourceView
  *
- * Copyright 2003-2007 - Paolo Maggi <paolo maggi polito it>
+ * Copyright (C) 2003-2007 - Paolo Maggi <paolo maggi polito it>
  *
  * GtkSourceView is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -18,7 +18,8 @@
  * along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#pragma once
+#ifndef GTK_SOURCE_STYLE_SCHEME_MANAGER_H
+#define GTK_SOURCE_STYLE_SCHEME_MANAGER_H
 
 #if !defined (GTK_SOURCE_H_INSIDE) && !defined (GTK_SOURCE_COMPILATION)
 #error "Only <gtksourceview/gtksource.h> can be included directly."
@@ -30,32 +31,67 @@
 
 G_BEGIN_DECLS
 
-#define GTK_SOURCE_TYPE_STYLE_SCHEME_MANAGER (gtk_source_style_scheme_manager_get_type())
+#define GTK_SOURCE_TYPE_STYLE_SCHEME_MANAGER           (gtk_source_style_scheme_manager_get_type ())
+#define GTK_SOURCE_STYLE_SCHEME_MANAGER(obj)           (G_TYPE_CHECK_INSTANCE_CAST((obj), 
GTK_SOURCE_TYPE_STYLE_SCHEME_MANAGER, GtkSourceStyleSchemeManager))
+#define GTK_SOURCE_STYLE_SCHEME_MANAGER_CLASS(klass)   (G_TYPE_CHECK_CLASS_CAST((klass), 
GTK_SOURCE_TYPE_STYLE_SCHEME_MANAGER, GtkSourceStyleSchemeManagerClass))
+#define GTK_SOURCE_IS_STYLE_SCHEME_MANAGER(obj)                (G_TYPE_CHECK_INSTANCE_TYPE((obj), 
GTK_SOURCE_TYPE_STYLE_SCHEME_MANAGER))
+#define GTK_SOURCE_IS_STYLE_SCHEME_MANAGER_CLASS(klass)        (G_TYPE_CHECK_CLASS_TYPE ((klass), 
GTK_SOURCE_TYPE_STYLE_SCHEME_MANAGER))
+#define GTK_SOURCE_STYLE_SCHEME_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), 
GTK_SOURCE_TYPE_STYLE_SCHEME_MANAGER, GtkSourceStyleSchemeManagerClass))
+
+typedef struct _GtkSourceStyleSchemeManagerClass       GtkSourceStyleSchemeManagerClass;
+typedef struct _GtkSourceStyleSchemeManagerPrivate     GtkSourceStyleSchemeManagerPrivate;
+
+struct _GtkSourceStyleSchemeManager
+{
+       GObject parent;
+
+       GtkSourceStyleSchemeManagerPrivate *priv;
+};
+
+struct _GtkSourceStyleSchemeManagerClass
+{
+       GObjectClass parent_class;
+
+       /* Padding for future expansion */
+       gpointer padding[10];
+};
 
 GTK_SOURCE_AVAILABLE_IN_ALL
-G_DECLARE_FINAL_TYPE (GtkSourceStyleSchemeManager, gtk_source_style_scheme_manager, GTK_SOURCE, 
STYLE_SCHEME_MANAGER, GObject)
+GType                   gtk_source_style_scheme_manager_get_type               (void) G_GNUC_CONST;
 
 GTK_SOURCE_AVAILABLE_IN_ALL
-GtkSourceStyleSchemeManager *gtk_source_style_scheme_manager_new                 (void);
+GtkSourceStyleSchemeManager *
+                        gtk_source_style_scheme_manager_new                    (void);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-GtkSourceStyleSchemeManager *gtk_source_style_scheme_manager_get_default         (void);
+GtkSourceStyleSchemeManager *
+                        gtk_source_style_scheme_manager_get_default            (void);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-void                         gtk_source_style_scheme_manager_set_search_path     
(GtkSourceStyleSchemeManager  *manager,
-                                                                                  gchar                      
 **path);
+void                    gtk_source_style_scheme_manager_set_search_path        (GtkSourceStyleSchemeManager  
  *manager,
+                                                                                gchar                        
 **path);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-void                         gtk_source_style_scheme_manager_append_search_path  
(GtkSourceStyleSchemeManager  *manager,
-                                                                                  const gchar                
  *path);
+void                    gtk_source_style_scheme_manager_append_search_path     (GtkSourceStyleSchemeManager  
  *manager,
+                                                                                const gchar                  
  *path);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-void                         gtk_source_style_scheme_manager_prepend_search_path 
(GtkSourceStyleSchemeManager  *manager,
-                                                                                  const gchar                
  *path);
+void                    gtk_source_style_scheme_manager_prepend_search_path    (GtkSourceStyleSchemeManager  
  *manager,
+                                                                                const gchar                  
  *path);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-const gchar * const         *gtk_source_style_scheme_manager_get_search_path     
(GtkSourceStyleSchemeManager  *manager);
+const gchar * const *   gtk_source_style_scheme_manager_get_search_path        (GtkSourceStyleSchemeManager  
  *manager);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-void                         gtk_source_style_scheme_manager_force_rescan        
(GtkSourceStyleSchemeManager  *manager);
+void                    gtk_source_style_scheme_manager_force_rescan           (GtkSourceStyleSchemeManager  
  *manager);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-const gchar * const         *gtk_source_style_scheme_manager_get_scheme_ids      
(GtkSourceStyleSchemeManager  *manager);
+const gchar * const *   gtk_source_style_scheme_manager_get_scheme_ids         (GtkSourceStyleSchemeManager  
  *manager);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-GtkSourceStyleScheme        *gtk_source_style_scheme_manager_get_scheme          
(GtkSourceStyleSchemeManager  *manager,
-                                                                                  const gchar                
  *scheme_id);
+GtkSourceStyleScheme   *gtk_source_style_scheme_manager_get_scheme             (GtkSourceStyleSchemeManager  
  *manager,
+                                                                                const gchar                  
  *scheme_id);
 
 G_END_DECLS
+
+#endif /* GTK_SOURCE_STYLE_SCHEME_MANAGER_H */
diff --git a/gtksourceview/gtksourcetag.c b/gtksourceview/gtksourcetag.c
index ad007e4c..22e6ddee 100644
--- a/gtksourceview/gtksourcetag.c
+++ b/gtksourceview/gtksourcetag.c
@@ -2,7 +2,7 @@
 /*
  * This file is part of GtkSourceView
  *
- * Copyright 2015 - Université Catholique de Louvain
+ * Copyright (C) 2015 - Université Catholique de Louvain
  *
  * GtkSourceView is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -20,7 +20,9 @@
  * Author: Sébastien Wilmet
  */
 
-#include "config.h"
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
 
 #include "gtksourcetag.h"
 
@@ -37,11 +39,13 @@
  * a #GtkTextTag, not a #GtkSourceTag.
  */
 
-typedef struct
+typedef struct _GtkSourceTagPrivate GtkSourceTagPrivate;
+
+struct _GtkSourceTagPrivate
 {
        guint draw_spaces : 1;
        guint draw_spaces_set : 1;
-} GtkSourceTagPrivate;
+};
 
 enum
 {
@@ -54,9 +58,9 @@ G_DEFINE_TYPE_WITH_PRIVATE (GtkSourceTag, gtk_source_tag, GTK_TYPE_TEXT_TAG)
 
 static void
 gtk_source_tag_get_property (GObject    *object,
-                             guint       prop_id,
-                             GValue     *value,
-                             GParamSpec *pspec)
+                            guint       prop_id,
+                            GValue     *value,
+                            GParamSpec *pspec)
 {
        GtkSourceTagPrivate *priv;
 
@@ -80,9 +84,9 @@ gtk_source_tag_get_property (GObject    *object,
 
 static void
 gtk_source_tag_set_property (GObject      *object,
-                             guint         prop_id,
-                             const GValue *value,
-                             GParamSpec   *pspec)
+                            guint         prop_id,
+                            const GValue *value,
+                            GParamSpec   *pspec)
 {
        GtkSourceTag *tag;
        GtkSourceTagPrivate *priv;
diff --git a/gtksourceview/gtksourcetag.h b/gtksourceview/gtksourcetag.h
index 9141b7bf..878a2c52 100644
--- a/gtksourceview/gtksourcetag.h
+++ b/gtksourceview/gtksourcetag.h
@@ -2,7 +2,7 @@
 /*
  * This file is part of GtkSourceView
  *
- * Copyright 2015 - Université Catholique de Louvain
+ * Copyright (C) 2015 - Université Catholique de Louvain
  *
  * GtkSourceView is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -20,7 +20,8 @@
  * Author: Sébastien Wilmet
  */
 
-#pragma once
+#ifndef GTK_SOURCE_TAG_H
+#define GTK_SOURCE_TAG_H
 
 #if !defined (GTK_SOURCE_H_INSIDE) && !defined (GTK_SOURCE_COMPILATION)
 #error "Only <gtksourceview/gtksource.h> can be included directly."
@@ -32,20 +33,24 @@
 
 G_BEGIN_DECLS
 
-#define GTK_SOURCE_TYPE_TAG (gtk_source_tag_get_type())
+#define GTK_SOURCE_TYPE_TAG (gtk_source_tag_get_type ())
 
 GTK_SOURCE_AVAILABLE_IN_3_20
-G_DECLARE_DERIVABLE_TYPE (GtkSourceTag, gtk_source_tag, GTK_SOURCE, TAG, GtkTextTag)
+G_DECLARE_DERIVABLE_TYPE (GtkSourceTag, gtk_source_tag,
+                         GTK_SOURCE, TAG,
+                         GtkTextTag)
 
 struct _GtkSourceTagClass
 {
        GtkTextTagClass parent_class;
 
-  /*< private >*/
+       /*< private >*/
        gpointer _reserved[10];
 };
 
 GTK_SOURCE_AVAILABLE_IN_3_20
-GtkTextTag *gtk_source_tag_new (const gchar *name);
+GtkTextTag *   gtk_source_tag_new              (const gchar *name);
 
 G_END_DECLS
+
+#endif /* GTK_SOURCE_TAG_H */
diff --git a/gtksourceview/gtksourcetypes-private.h b/gtksourceview/gtksourcetypes-private.h
index 002a144d..48d0c248 100644
--- a/gtksourceview/gtksourcetypes-private.h
+++ b/gtksourceview/gtksourcetypes-private.h
@@ -1,7 +1,7 @@
 /*
  * This file is part of GtkSourceView
  *
- * Copyright 2012, 2013, 2016 - Sébastien Wilmet <swilmet gnome org>
+ * Copyright (C) 2012, 2013, 2016 - Sébastien Wilmet <swilmet gnome org>
  *
  * GtkSourceView is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -17,24 +17,23 @@
  * along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#pragma once
+#ifndef GTK_SOURCE_TYPES_PRIVATE_H
+#define GTK_SOURCE_TYPES_PRIVATE_H
 
 #include <glib.h>
 
 G_BEGIN_DECLS
 
-typedef struct _GtkSourceBufferInputStream      GtkSourceBufferInputStream;
-typedef struct _GtkSourceBufferOutputStream     GtkSourceBufferOutputStream;
-typedef struct _GtkSourceCompletionContainer    GtkSourceCompletionContainer;
-typedef struct _GtkSourceCompletionModel        GtkSourceCompletionModel;
-typedef struct _GtkSourceContextEngine          GtkSourceContextEngine;
-typedef struct _GtkSourceEngine                 GtkSourceEngine;
-typedef struct _GtkSourceGutterRendererLines    GtkSourceGutterRendererLines;
-typedef struct _GtkSourceGutterRendererMarks    GtkSourceGutterRendererMarks;
-typedef struct _GtkSourceMarksSequence          GtkSourceMarksSequence;
-typedef struct _GtkSourcePixbufHelper           GtkSourcePixbufHelper;
-typedef struct _GtkSourceRegex                  GtkSourceRegex;
-typedef struct _GtkSourceUndoManagerDefault     GtkSourceUndoManagerDefault;
+typedef struct _GtkSourceBufferInputStream   GtkSourceBufferInputStream;
+typedef struct _GtkSourceBufferOutputStream  GtkSourceBufferOutputStream;
+typedef struct _GtkSourceCompletionModel     GtkSourceCompletionModel;
+typedef struct _GtkSourceContextEngine       GtkSourceContextEngine;
+typedef struct _GtkSourceEngine              GtkSourceEngine;
+typedef struct _GtkSourceGutterRendererLines GtkSourceGutterRendererLines;
+typedef struct _GtkSourceGutterRendererMarks GtkSourceGutterRendererMarks;
+typedef struct _GtkSourceMarksSequence       GtkSourceMarksSequence;
+typedef struct _GtkSourcePixbufHelper        GtkSourcePixbufHelper;
+typedef struct _GtkSourceRegex               GtkSourceRegex;
 
 #ifdef _MSC_VER
 /* For Visual Studio, we need to export the symbols used by the unit tests */
@@ -44,3 +43,5 @@ typedef struct _GtkSourceUndoManagerDefault     GtkSourceUndoManagerDefault;
 #endif
 
 G_END_DECLS
+
+#endif /* GTK_SOURCE_TYPES_PRIVATE_H */
diff --git a/gtksourceview/gtksourcetypes.h b/gtksourceview/gtksourcetypes.h
index ae358abc..9fd2d4e1 100644
--- a/gtksourceview/gtksourcetypes.h
+++ b/gtksourceview/gtksourcetypes.h
@@ -1,7 +1,7 @@
 /*
  * This file is part of GtkSourceView
  *
- * Copyright 2012-2016 - Sébastien Wilmet <swilmet gnome org>
+ * Copyright (C) 2012-2016 - Sébastien Wilmet <swilmet gnome org>
  *
  * GtkSourceView is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -17,7 +17,8 @@
  * along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#pragma once
+#ifndef GTK_SOURCE_TYPES_H
+#define GTK_SOURCE_TYPES_H
 
 #if !defined (GTK_SOURCE_H_INSIDE) && !defined (GTK_SOURCE_COMPILATION)
 #error "Only <gtksourceview/gtksource.h> can be included directly."
@@ -35,37 +36,39 @@ G_BEGIN_DECLS
  * https://bugzilla.gnome.org/show_bug.cgi?id=679424#c20
  */
 
-typedef struct _GtkSourceBuffer                    GtkSourceBuffer;
-typedef struct _GtkSourceCompletionContext         GtkSourceCompletionContext;
-typedef struct _GtkSourceCompletion                GtkSourceCompletion;
-typedef struct _GtkSourceCompletionInfo            GtkSourceCompletionInfo;
-typedef struct _GtkSourceCompletionItem            GtkSourceCompletionItem;
-typedef struct _GtkSourceCompletionProposal        GtkSourceCompletionProposal;
-typedef struct _GtkSourceCompletionProvider        GtkSourceCompletionProvider;
-typedef struct _GtkSourceEncoding                  GtkSourceEncoding;
-typedef struct _GtkSourceFile                      GtkSourceFile;
-typedef struct _GtkSourceFileLoader                GtkSourceFileLoader;
-typedef struct _GtkSourceFileSaver                 GtkSourceFileSaver;
-typedef struct _GtkSourceGutter                    GtkSourceGutter;
-typedef struct _GtkSourceGutterRenderer            GtkSourceGutterRenderer;
-typedef struct _GtkSourceGutterRendererPixbuf      GtkSourceGutterRendererPixbuf;
-typedef struct _GtkSourceGutterRendererText        GtkSourceGutterRendererText;
-typedef struct _GtkSourceLanguage                  GtkSourceLanguage;
-typedef struct _GtkSourceLanguageManager           GtkSourceLanguageManager;
-typedef struct _GtkSourceMap                       GtkSourceMap;
-typedef struct _GtkSourceMarkAttributes            GtkSourceMarkAttributes;
-typedef struct _GtkSourceMark                      GtkSourceMark;
-typedef struct _GtkSourcePrintCompositor           GtkSourcePrintCompositor;
-typedef struct _GtkSourceSearchContext             GtkSourceSearchContext;
-typedef struct _GtkSourceSearchSettings            GtkSourceSearchSettings;
-typedef struct _GtkSourceSpaceDrawer               GtkSourceSpaceDrawer;
-typedef struct _GtkSourceStyle                     GtkSourceStyle;
-typedef struct _GtkSourceStyleSchemeChooserButton  GtkSourceStyleSchemeChooserButton;
-typedef struct _GtkSourceStyleSchemeChooser        GtkSourceStyleSchemeChooser;
-typedef struct _GtkSourceStyleSchemeChooserWidget  GtkSourceStyleSchemeChooserWidget;
-typedef struct _GtkSourceStyleScheme               GtkSourceStyleScheme;
-typedef struct _GtkSourceStyleSchemeManager        GtkSourceStyleSchemeManager;
-typedef struct _GtkSourceUndoManager               GtkSourceUndoManager;
-typedef struct _GtkSourceView                      GtkSourceView;
+typedef struct _GtkSourceBuffer                 GtkSourceBuffer;
+typedef struct _GtkSourceCompletionContext      GtkSourceCompletionContext;
+typedef struct _GtkSourceCompletion             GtkSourceCompletion;
+typedef struct _GtkSourceCompletionInfo         GtkSourceCompletionInfo;
+typedef struct _GtkSourceCompletionItem         GtkSourceCompletionItem;
+typedef struct _GtkSourceCompletionProposal     GtkSourceCompletionProposal;
+typedef struct _GtkSourceCompletionProvider     GtkSourceCompletionProvider;
+typedef struct _GtkSourceEncoding               GtkSourceEncoding;
+typedef struct _GtkSourceFile                   GtkSourceFile;
+typedef struct _GtkSourceFileLoader             GtkSourceFileLoader;
+typedef struct _GtkSourceFileSaver              GtkSourceFileSaver;
+typedef struct _GtkSourceGutter                 GtkSourceGutter;
+typedef struct _GtkSourceGutterRenderer         GtkSourceGutterRenderer;
+typedef struct _GtkSourceGutterRendererPixbuf   GtkSourceGutterRendererPixbuf;
+typedef struct _GtkSourceGutterRendererText     GtkSourceGutterRendererText;
+typedef struct _GtkSourceLanguage               GtkSourceLanguage;
+typedef struct _GtkSourceLanguageManager        GtkSourceLanguageManager;
+typedef struct _GtkSourceLines                  GtkSourceLines;
+typedef struct _GtkSourceMap                    GtkSourceMap;
+typedef struct _GtkSourceMarkAttributes         GtkSourceMarkAttributes;
+typedef struct _GtkSourceMark                   GtkSourceMark;
+typedef struct _GtkSourcePrintCompositor        GtkSourcePrintCompositor;
+typedef struct _GtkSourceSearchContext          GtkSourceSearchContext;
+typedef struct _GtkSourceSearchSettings         GtkSourceSearchSettings;
+typedef struct _GtkSourceSpaceDrawer            GtkSourceSpaceDrawer;
+typedef struct _GtkSourceStyle                  GtkSourceStyle;
+typedef struct _GtkSourceStyleScheme            GtkSourceStyleScheme;
+typedef struct _GtkSourceStyleSchemeChooser     GtkSourceStyleSchemeChooser;
+typedef struct _GtkSourceStyleSchemeChooserButton GtkSourceStyleSchemeChooserButton;
+typedef struct _GtkSourceStyleSchemeChooserWidget GtkSourceStyleSchemeChooserWidget;
+typedef struct _GtkSourceStyleSchemeManager     GtkSourceStyleSchemeManager;
+typedef struct _GtkSourceView                   GtkSourceView;
 
 G_END_DECLS
+
+#endif /* GTK_SOURCE_TYPES_H */
diff --git a/gtksourceview/gtksourceutils-private.h b/gtksourceview/gtksourceutils-private.h
index 25dd7b03..217c38cd 100644
--- a/gtksourceview/gtksourceutils-private.h
+++ b/gtksourceview/gtksourceutils-private.h
@@ -2,9 +2,9 @@
  *
  * This file is part of GtkSourceView
  *
- * Copyright 2007 - Gustavo Giráldez
- * Copyright 2007 - Paolo Maggi
- * Copyright 2017 - Sébastien Wilmet <swilmet gnome org>
+ * Copyright (C) 2007 - Gustavo Giráldez
+ * Copyright (C) 2007 - Paolo Maggi
+ * Copyright (C) 2017 - Sébastien Wilmet <swilmet gnome org>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -20,7 +20,8 @@
  * along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#pragma once
+#ifndef GTK_SOURCE_UTILS_PRIVATE_H
+#define GTK_SOURCE_UTILS_PRIVATE_H
 
 #include <glib.h>
 #include <pango/pango.h>
@@ -28,22 +29,28 @@
 G_BEGIN_DECLS
 
 G_GNUC_INTERNAL
-gchar  **_gtk_source_utils_get_default_dirs              (const gchar                 *basename);
+gchar **       _gtk_source_utils_get_default_dirs              (const gchar *basename);
+
 G_GNUC_INTERNAL
-GSList  *_gtk_source_utils_get_file_list                 (gchar                      **path,
-                                                          const gchar                 *suffix,
-                                                          gboolean                     only_dirs);
+GSList *       _gtk_source_utils_get_file_list                 (gchar       **path,
+                                                                const gchar  *suffix,
+                                                                gboolean      only_dirs);
+
 G_GNUC_INTERNAL
-gint     _gtk_source_utils_string_to_int                 (const gchar                 *str);
+gint           _gtk_source_utils_string_to_int                 (const gchar *str);
+
 G_GNUC_INTERNAL
-gint     _gtk_source_utils_int_to_string                 (guint                        value,
-                                                          const gchar                **outstr);
+gint           _gtk_source_utils_int_to_string                 (guint         value,
+                                                                const gchar **outstr);
+
 G_GNUC_INTERNAL
-gchar   *_gtk_source_utils_pango_font_description_to_css (const PangoFontDescription  *font_desc);
+gchar *                _gtk_source_utils_pango_font_description_to_css (const PangoFontDescription 
*font_desc);
 
 /* Note: it returns duplicated string. */
 G_GNUC_INTERNAL
-gchar   *_gtk_source_utils_dgettext                      (const gchar                 *domain,
-                                                          const gchar                 *msgid) 
G_GNUC_FORMAT(2);
+gchar *                _gtk_source_utils_dgettext                      (const gchar *domain,
+                                                                const gchar *msgid) G_GNUC_FORMAT(2);
 
 G_END_DECLS
+
+#endif /* GTK_SOURCE_UTILS_PRIVATE_H */
diff --git a/gtksourceview/gtksourceutils.c b/gtksourceview/gtksourceutils.c
index 9024c667..9095aae5 100644
--- a/gtksourceview/gtksourceutils.c
+++ b/gtksourceview/gtksourceutils.c
@@ -2,10 +2,10 @@
 /*
  * This file is part of GtkSourceView
  *
- * Copyright 2005 - Paolo Borelli
- * Copyright 2007 - Gustavo Giráldez
- * Copyright 2007 - Paolo Maggi
- * Copyright 2013, 2017 - Sébastien Wilmet <swilmet gnome org>
+ * Copyright (C) 2005 - Paolo Borelli
+ * Copyright (C) 2007 - Gustavo Giráldez
+ * Copyright (C) 2007 - Paolo Maggi
+ * Copyright (C) 2013, 2017 - Sébastien Wilmet <swilmet gnome org>
  *
  * GtkSourceView is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -29,7 +29,9 @@
  * Utility functions.
  */
 
-#include "config.h"
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
 
 #include "gtksourceutils.h"
 #include "gtksourceutils-private.h"
diff --git a/gtksourceview/gtksourceutils.h b/gtksourceview/gtksourceutils.h
index 2f4faf9e..8fdc784d 100644
--- a/gtksourceview/gtksourceutils.h
+++ b/gtksourceview/gtksourceutils.h
@@ -2,7 +2,7 @@
  *
  * This file is part of GtkSourceView
  *
- * Copyright 2013 - Sébastien Wilmet <swilmet gnome org>
+ * Copyright (C) 2013 - Sébastien Wilmet <swilmet gnome org>
  *
  * GtkSourceView is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -18,7 +18,8 @@
  * along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#pragma once
+#ifndef GTK_SOURCE_UTILS_H
+#define GTK_SOURCE_UTILS_H
 
 #if !defined (GTK_SOURCE_H_INSIDE) && !defined (GTK_SOURCE_COMPILATION)
 #error "Only <gtksourceview/gtksource.h> can be included directly."
@@ -31,8 +32,11 @@
 G_BEGIN_DECLS
 
 GTK_SOURCE_AVAILABLE_IN_3_10
-gchar *gtk_source_utils_unescape_search_text (const gchar *text);
+gchar          *gtk_source_utils_unescape_search_text          (const gchar    *text);
+
 GTK_SOURCE_AVAILABLE_IN_3_10
-gchar *gtk_source_utils_escape_search_text   (const gchar *text);
+gchar          *gtk_source_utils_escape_search_text            (const gchar    *text);
 
 G_END_DECLS
+
+#endif /* GTK_SOURCE_UTILS_H */
diff --git a/gtksourceview/gtksourceversion.c b/gtksourceview/gtksourceversion.c
index f6927492..2533f729 100644
--- a/gtksourceview/gtksourceversion.c
+++ b/gtksourceview/gtksourceversion.c
@@ -2,7 +2,7 @@
  *
  * This file is part of GtkSourceView
  *
- * Copyright 2015 - Paolo Borelli <pborelli gnome org>
+ * Copyright (C) 2015 - Paolo Borelli <pborelli gnome org>
  *
  * GtkSourceView is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -18,7 +18,9 @@
  * along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "config.h"
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
 
 #include "gtksourceversion.h"
 
diff --git a/gtksourceview/gtksourceview.c b/gtksourceview/gtksourceview.c
index afa014c6..238d37ba 100644
--- a/gtksourceview/gtksourceview.c
+++ b/gtksourceview/gtksourceview.c
@@ -2,10 +2,10 @@
 /*
  * This file is part of GtkSourceView
  *
- * Copyright 2001 Mikael Hermansson <tyan linux se> and
- *                Chris Phelps <chicane reninet com>
- * Copyright 2002 Jeroen Zwartepoorte
- * Copyright 2003 Gustavo Giráldez and Paolo Maggi
+ * Copyright (C) 2001 - Mikael Hermansson <tyan linux se> and
+ *                      Chris Phelps <chicane reninet com>
+ * Copyright (C) 2002 - Jeroen Zwartepoorte
+ * Copyright (C) 2003 - Gustavo Giráldez and Paolo Maggi
  *
  * GtkSourceView is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -21,11 +21,13 @@
  * along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "config.h"
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
 
 #include "gtksourceview.h"
 
-#include <string.h> /* For strlen */
+#include <string.h>
 #include <fribidi.h>
 #include <gtk/gtk.h>
 #include <gdk/gdkkeysyms.h>
@@ -35,19 +37,18 @@
 #include "gtksourcebuffer.h"
 #include "gtksourcebuffer-private.h"
 #include "gtksourcebufferinternal-private.h"
+#include "gtksourcecompletion.h"
+#include "gtksourcegutter.h"
+#include "gtksourcegutter-private.h"
+#include "gtksourcegutterrendererlines.h"
 #include "gtksource-enumtypes.h"
 #include "gtksourcemark.h"
 #include "gtksourcemarkattributes.h"
 #include "gtksource-marshal.h"
 #include "gtksourcestylescheme-private.h"
-#include "gtksourcecompletion.h"
 #include "gtksourcecompletion-private.h"
 #include "gtksourcecompletionprovider.h"
-#include "gtksourcegutter.h"
-#include "gtksourcegutter-private.h"
-#include "gtksourcegutterrendererlines-private.h"
-#include "gtksourcegutterrenderermarks-private.h"
-#include "gtksourceiter-private.h"
+#include "gtksourceiter.h"
 #include "gtksourcesearchcontext-private.h"
 #include "gtksourcespacedrawer.h"
 #include "gtksourcespacedrawer-private.h"
@@ -137,23 +138,22 @@
 #define PROFILE(x)
 #endif
 
-#define GUTTER_PIXMAP                   16
-#define DEFAULT_TAB_WIDTH               8
-#define MAX_TAB_WIDTH                   32
-#define MAX_INDENT_WIDTH                32
+#define GUTTER_PIXMAP                  16
+#define DEFAULT_TAB_WIDTH              8
+#define MAX_TAB_WIDTH                  32
+#define MAX_INDENT_WIDTH               32
 
-#define DEFAULT_RIGHT_MARGIN_POSITION   80
-#define MAX_RIGHT_MARGIN_POSITION       1000
+#define DEFAULT_RIGHT_MARGIN_POSITION  80
+#define MAX_RIGHT_MARGIN_POSITION      1000
 
-#define RIGHT_MARGIN_LINE_ALPHA         40
-#define RIGHT_MARGIN_OVERLAY_ALPHA      15
+#define RIGHT_MARGIN_LINE_ALPHA                40
+#define RIGHT_MARGIN_OVERLAY_ALPHA     15
 
 enum
 {
        UNDO,
        REDO,
        SHOW_COMPLETION,
-       LINE_MARK_ACTIVATED,
        MOVE_LINES,
        MOVE_WORDS,
        SMART_HOME_END,
@@ -169,7 +169,6 @@ enum
        PROP_0,
        PROP_COMPLETION,
        PROP_SHOW_LINE_NUMBERS,
-       PROP_SHOW_LINE_MARKS,
        PROP_TAB_WIDTH,
        PROP_INDENT_WIDTH,
        PROP_AUTO_INDENT,
@@ -184,7 +183,7 @@ enum
        PROP_SPACE_DRAWER
 };
 
-typedef struct
+struct _GtkSourceViewPrivate
 {
        GtkSourceStyleScheme *style_scheme;
        GdkRGBA *right_margin_line_color;
@@ -200,7 +199,6 @@ typedef struct
        GtkSourceGutter *right_gutter;
 
        GtkSourceGutterRenderer *line_renderer;
-       GtkSourceGutterRenderer *marks_renderer;
 
        GdkRGBA current_line_color;
 
@@ -216,7 +214,6 @@ typedef struct
 
        guint tabs_set : 1;
        guint show_line_numbers : 1;
-       guint show_line_marks : 1;
        guint auto_indent : 1;
        guint insert_spaces : 1;
        guint highlight_current_line : 1;
@@ -225,13 +222,15 @@ typedef struct
        guint current_line_color_set : 1;
        guint background_pattern_color_set : 1;
        guint smart_backspace : 1;
-} GtkSourceViewPrivate;
+};
+
+typedef struct _MarkCategory MarkCategory;
 
-typedef struct
+struct _MarkCategory
 {
        GtkSourceMarkAttributes *attributes;
        gint priority;
-} MarkCategory;
+};
 
 static guint signals[N_SIGNALS];
 
@@ -247,75 +246,73 @@ typedef enum _GtkSourceViewDropTypes {
        TARGET_COLOR = 200
 } GtkSourceViewDropTypes;
 
+#if 0
 static const GtkTargetEntry drop_types[] = {
        {(gchar *)"application/x-color", 0, TARGET_COLOR}
 };
+#endif
 
-static void           gtk_source_view_dispose              (GObject                 *object);
-static void           gtk_source_view_finalize             (GObject                 *object);
-static void           gtk_source_view_undo                 (GtkSourceView           *view);
-static void           gtk_source_view_redo                 (GtkSourceView           *view);
-static void           gtk_source_view_show_completion_real (GtkSourceView           *view);
-static GtkTextBuffer *gtk_source_view_create_buffer        (GtkTextView             *view);
-static void           remove_source_buffer                 (GtkSourceView           *view);
-static void           set_source_buffer                    (GtkSourceView           *view,
-                                                            GtkTextBuffer           *buffer);
-static void           gtk_source_view_populate_popup       (GtkTextView             *view,
-                                                            GtkWidget               *popup);
-static void           gtk_source_view_move_cursor          (GtkTextView             *text_view,
-                                                            GtkMovementStep          step,
-                                                            gint                     count,
-                                                            gboolean                 extend_selection);
-static void           gtk_source_view_delete_from_cursor   (GtkTextView             *text_view,
-                                                            GtkDeleteType            type,
-                                                            gint                     count);
-static gboolean       gtk_source_view_extend_selection     (GtkTextView             *text_view,
-                                                            GtkTextExtendSelection   granularity,
-                                                            const GtkTextIter       *location,
-                                                            GtkTextIter             *start,
-                                                            GtkTextIter             *end);
-static void           gtk_source_view_get_lines            (GtkTextView             *text_view,
-                                                            gint                     first_y,
-                                                            gint                     last_y,
-                                                            GArray                  *buffer_coords,
-                                                            GArray                  *line_heights,
-                                                            GArray                  *numbers,
-                                                            gint                    *countp);
-static gboolean       gtk_source_view_draw                 (GtkWidget               *widget,
-                                                            cairo_t                 *cr);
-static void           gtk_source_view_move_lines           (GtkSourceView           *view,
-                                                            gboolean                 down);
-static void           gtk_source_view_move_words           (GtkSourceView           *view,
-                                                            gint                     step);
-static gboolean       gtk_source_view_key_press_event      (GtkWidget               *widget,
-                                                            GdkEventKey             *event);
-static void           view_dnd_drop                        (GtkTextView             *view,
-                                                            GdkDragContext          *context,
-                                                            gint                     x,
-                                                            gint                     y,
-                                                            GtkSelectionData        *selection_data,
-                                                            guint                    info,
-                                                            guint                    timestamp,
-                                                            gpointer                 data);
-static gint           calculate_real_tab_width             (GtkSourceView           *view,
-                                                            guint                    tab_size,
-                                                            gchar                    c);
-static void           gtk_source_view_set_property         (GObject                 *object,
-                                                            guint                    prop_id,
-                                                            const GValue            *value,
-                                                            GParamSpec              *pspec);
-static void           gtk_source_view_get_property         (GObject                 *object,
-                                                            guint                    prop_id,
-                                                            GValue                  *value,
-                                                            GParamSpec              *pspec);
-static void           gtk_source_view_style_updated        (GtkWidget               *widget);
-static void           gtk_source_view_update_style_scheme  (GtkSourceView           *view);
-static void           gtk_source_view_draw_layer           (GtkTextView             *view,
-                                                            GtkTextViewLayer         layer,
-                                                            cairo_t                 *cr);
-static MarkCategory  *mark_category_new                    (GtkSourceMarkAttributes *attributes,
-                                                            gint                     priority);
-static void           mark_category_free                   (MarkCategory            *category);
+/* Prototypes. */
+static void    gtk_source_view_dispose                 (GObject            *object);
+static void    gtk_source_view_finalize                (GObject            *object);
+static void    gtk_source_view_show_completion_real    (GtkSourceView      *view);
+static GtkTextBuffer * gtk_source_view_create_buffer   (GtkTextView        *view);
+static void    remove_source_buffer                    (GtkSourceView      *view);
+static void    set_source_buffer                       (GtkSourceView      *view,
+                                                        GtkTextBuffer      *buffer);
+static void    gtk_source_view_move_cursor             (GtkTextView        *text_view,
+                                                        GtkMovementStep     step,
+                                                        gint                count,
+                                                        gboolean            extend_selection);
+static void    gtk_source_view_delete_from_cursor      (GtkTextView        *text_view,
+                                                        GtkDeleteType       type,
+                                                        gint                count);
+static gboolean gtk_source_view_extend_selection       (GtkTextView            *text_view,
+                                                        GtkTextExtendSelection  granularity,
+                                                        const GtkTextIter      *location,
+                                                        GtkTextIter            *start,
+                                                        GtkTextIter            *end);
+static void    gtk_source_view_get_lines               (GtkTextView       *text_view,
+                                                        gint               first_y,
+                                                        gint               last_y,
+                                                        GArray            *buffer_coords,
+                                                        GArray            *line_heights,
+                                                        GArray            *numbers,
+                                                        gint              *countp);
+static void    gtk_source_view_move_lines              (GtkSourceView     *view,
+                                                        gboolean           down);
+static void    gtk_source_view_move_words              (GtkSourceView     *view,
+                                                        gint               step);
+static gboolean        gtk_source_view_key_pressed             (GtkSourceView     *view,
+                                                        guint              keyval,
+                                                        guint              keycode,
+                                                        guint              state,
+                                                        GtkEventControllerKey *controller);
+static gint    calculate_real_tab_width                (GtkSourceView     *view,
+                                                        guint              tab_size,
+                                                        gchar              c);
+static void    gtk_source_view_set_property            (GObject           *object,
+                                                        guint              prop_id,
+                                                        const GValue      *value,
+                                                        GParamSpec        *pspec);
+static void    gtk_source_view_get_property            (GObject           *object,
+                                                        guint              prop_id,
+                                                        GValue            *value,
+                                                        GParamSpec        *pspec);
+static void    gtk_source_view_style_updated           (GtkWidget         *widget);
+static void    gtk_source_view_update_style_scheme     (GtkSourceView     *view);
+
+static MarkCategory *mark_category_new                  (GtkSourceMarkAttributes *attributes,
+                                                         gint priority);
+static void          mark_category_free                 (MarkCategory *category);
+static void     gtk_source_view_ensure_redrawn_rect_is_highlighted (GtkSourceView *view,
+                                                                   GdkRectangle  *clip);
+static void     gtk_source_view_snapshot_layer (GtkTextView      *text_view,
+                                               GtkTextViewLayer  layer,
+                                               GtkSnapshot      *snapshot);
+static void     gtk_source_view_snapshot       (GtkWidget   *widget,
+                                                GtkSnapshot *snapshot);
+static void     gtk_source_view_queue_draw     (GtkSourceView *view);
 
 static void
 gtk_source_view_constructed (GObject *object)
@@ -329,7 +326,7 @@ gtk_source_view_constructed (GObject *object)
 
 static void
 gtk_source_view_move_to_matching_bracket (GtkSourceView *view,
-                                          gboolean       extend_selection)
+                                         gboolean       extend_selection)
 {
        GtkTextView *text_view = GTK_TEXT_VIEW (view);
        GtkTextBuffer *buffer;
@@ -364,7 +361,7 @@ gtk_source_view_move_to_matching_bracket (GtkSourceView *view,
 
 static void
 gtk_source_view_change_number (GtkSourceView *view,
-                               gint           count)
+                              gint           count)
 {
        GtkTextView *text_view = GTK_TEXT_VIEW (view);
        GtkTextBuffer *buffer;
@@ -426,7 +423,7 @@ gtk_source_view_change_number (GtkSourceView *view,
 
 static void
 gtk_source_view_change_case (GtkSourceView           *view,
-                             GtkSourceChangeCaseType  case_type)
+                            GtkSourceChangeCaseType  case_type)
 {
        GtkSourceBuffer *buffer;
        GtkTextIter start, end;
@@ -444,6 +441,27 @@ gtk_source_view_change_case (GtkSourceView           *view,
        gtk_source_buffer_change_case (buffer, case_type, &start, &end);
 }
 
+static void
+gtk_source_view_activate_change_case (GtkWidget   *widget,
+                                      const gchar *action_name,
+                                      GVariant    *parameter)
+{
+       GEnumClass *klass;
+       GEnumValue *value;
+       const gchar *nick;
+
+       nick = g_variant_get_string (parameter, NULL);
+       klass = g_type_class_ref (GTK_SOURCE_TYPE_CHANGE_CASE_TYPE);
+       value = g_enum_get_value_by_nick (klass, nick);
+
+       if (value != NULL)
+       {
+               gtk_source_view_change_case (GTK_SOURCE_VIEW (widget), value->value);
+       }
+
+       g_type_class_unref (klass);
+}
+
 static void
 gtk_source_view_join_lines (GtkSourceView *view)
 {
@@ -478,19 +496,15 @@ gtk_source_view_class_init (GtkSourceViewClass *klass)
        object_class->get_property = gtk_source_view_get_property;
        object_class->set_property = gtk_source_view_set_property;
 
-       widget_class->key_press_event = gtk_source_view_key_press_event;
-       widget_class->draw = gtk_source_view_draw;
+       widget_class->snapshot = gtk_source_view_snapshot;
        widget_class->style_updated = gtk_source_view_style_updated;
 
-       textview_class->populate_popup = gtk_source_view_populate_popup;
        textview_class->move_cursor = gtk_source_view_move_cursor;
        textview_class->delete_from_cursor = gtk_source_view_delete_from_cursor;
        textview_class->extend_selection = gtk_source_view_extend_selection;
        textview_class->create_buffer = gtk_source_view_create_buffer;
-       textview_class->draw_layer = gtk_source_view_draw_layer;
+       textview_class->snapshot_layer = gtk_source_view_snapshot_layer;
 
-       klass->undo = gtk_source_view_undo;
-       klass->redo = gtk_source_view_redo;
        klass->show_completion = gtk_source_view_show_completion_real;
        klass->move_lines = gtk_source_view_move_lines;
        klass->move_words = gtk_source_view_move_words;
@@ -522,19 +536,6 @@ gtk_source_view_class_init (GtkSourceViewClass *klass)
                                                               FALSE,
                                                               G_PARAM_READWRITE |
                                                               G_PARAM_STATIC_STRINGS));
-       /**
-        * GtkSourceView:show-line-marks:
-        *
-        * Whether to display line mark pixbufs
-        */
-       g_object_class_install_property (object_class,
-                                        PROP_SHOW_LINE_MARKS,
-                                        g_param_spec_boolean ("show-line-marks",
-                                                              "Show Line Marks",
-                                                              "Whether to display line mark pixbufs",
-                                                              FALSE,
-                                                              G_PARAM_READWRITE |
-                                                              G_PARAM_STATIC_STRINGS));
 
        /**
         * GtkSourceView:tab-width:
@@ -702,30 +703,6 @@ gtk_source_view_class_init (GtkSourceViewClass *klass)
                                                              G_PARAM_READABLE |
                                                              G_PARAM_STATIC_STRINGS));
 
-       signals[UNDO] =
-               g_signal_new ("undo",
-                             G_TYPE_FROM_CLASS (klass),
-                             G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
-                             G_STRUCT_OFFSET (GtkSourceViewClass, undo),
-                             NULL, NULL,
-                             g_cclosure_marshal_VOID__VOID,
-                             G_TYPE_NONE, 0);
-       g_signal_set_va_marshaller (signals[UNDO],
-                                   G_TYPE_FROM_CLASS (klass),
-                                   g_cclosure_marshal_VOID__VOIDv);
-
-       signals[REDO] =
-               g_signal_new ("redo",
-                             G_TYPE_FROM_CLASS (klass),
-                             G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
-                             G_STRUCT_OFFSET (GtkSourceViewClass, redo),
-                             NULL, NULL,
-                             g_cclosure_marshal_VOID__VOID,
-                             G_TYPE_NONE, 0);
-       g_signal_set_va_marshaller (signals[REDO],
-                                   G_TYPE_FROM_CLASS (klass),
-                                   g_cclosure_marshal_VOID__VOIDv);
-
        /**
         * GtkSourceView::show-completion:
         * @view: The #GtkSourceView who emits the signal
@@ -753,31 +730,6 @@ gtk_source_view_class_init (GtkSourceViewClass *klass)
                                    G_TYPE_FROM_CLASS (klass),
                                    g_cclosure_marshal_VOID__VOIDv);
 
-       /**
-        * GtkSourceView::line-mark-activated:
-        * @view: the #GtkSourceView
-        * @iter: a #GtkTextIter
-        * @event: the #GdkEvent that activated the event
-        *
-        * Emitted when a line mark has been activated (for instance when there
-        * was a button press in the line marks gutter). You can use @iter to
-        * determine on which line the activation took place.
-        */
-       signals[LINE_MARK_ACTIVATED] =
-               g_signal_new ("line-mark-activated",
-                             G_TYPE_FROM_CLASS (klass),
-                             G_SIGNAL_RUN_LAST,
-                             G_STRUCT_OFFSET (GtkSourceViewClass, line_mark_activated),
-                             NULL, NULL,
-                             _gtk_source_marshal_VOID__BOXED_BOXED,
-                             G_TYPE_NONE,
-                             2,
-                             GTK_TYPE_TEXT_ITER,
-                             GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
-       g_signal_set_va_marshaller (signals[LINE_MARK_ACTIVATED],
-                                   G_TYPE_FROM_CLASS (klass),
-                                   _gtk_source_marshal_VOID__BOXED_BOXEDv);
-
        /**
         * GtkSourceView::move-lines:
         * @view: the #GtkSourceView which received the signal.
@@ -946,20 +898,11 @@ gtk_source_view_class_init (GtkSourceViewClass *klass)
                                    G_TYPE_FROM_CLASS (klass),
                                    g_cclosure_marshal_VOID__VOIDv);
 
+       gtk_widget_class_install_action (widget_class, "source.change-case", "s",
+                                        gtk_source_view_activate_change_case);
+
        binding_set = gtk_binding_set_by_class (klass);
 
-       gtk_binding_entry_add_signal (binding_set,
-                                     GDK_KEY_z,
-                                     GDK_CONTROL_MASK,
-                                     "undo", 0);
-       gtk_binding_entry_add_signal (binding_set,
-                                     GDK_KEY_z,
-                                     GDK_CONTROL_MASK | GDK_SHIFT_MASK,
-                                     "redo", 0);
-       gtk_binding_entry_add_signal (binding_set,
-                                     GDK_KEY_F14,
-                                     0,
-                                     "undo", 0);
        gtk_binding_entry_add_signal (binding_set,
                                      GDK_KEY_space,
                                      GDK_CONTROL_MASK,
@@ -1133,9 +1076,9 @@ gtk_source_view_buildable_interface_init (GtkBuildableIface *iface)
 
 static void
 gtk_source_view_set_property (GObject      *object,
-                              guint         prop_id,
-                              const GValue *value,
-                              GParamSpec   *pspec)
+                             guint         prop_id,
+                             const GValue *value,
+                             GParamSpec   *pspec)
 {
        GtkSourceView *view;
 
@@ -1149,10 +1092,6 @@ gtk_source_view_set_property (GObject      *object,
                        gtk_source_view_set_show_line_numbers (view, g_value_get_boolean (value));
                        break;
 
-               case PROP_SHOW_LINE_MARKS:
-                       gtk_source_view_set_show_line_marks (view, g_value_get_boolean (value));
-                       break;
-
                case PROP_TAB_WIDTH:
                        gtk_source_view_set_tab_width (view, g_value_get_uint (value));
                        break;
@@ -1205,9 +1144,9 @@ gtk_source_view_set_property (GObject      *object,
 
 static void
 gtk_source_view_get_property (GObject    *object,
-                              guint       prop_id,
-                              GValue     *value,
-                              GParamSpec *pspec)
+                             guint       prop_id,
+                             GValue     *value,
+                             GParamSpec *pspec)
 {
        GtkSourceView *view;
 
@@ -1225,10 +1164,6 @@ gtk_source_view_get_property (GObject    *object,
                        g_value_set_boolean (value, gtk_source_view_get_show_line_numbers (view));
                        break;
 
-               case PROP_SHOW_LINE_MARKS:
-                       g_value_set_boolean (value, gtk_source_view_get_show_line_marks (view));
-                       break;
-
                case PROP_TAB_WIDTH:
                        g_value_set_uint (value, gtk_source_view_get_tab_width (view));
                        break;
@@ -1285,10 +1220,10 @@ gtk_source_view_get_property (GObject    *object,
 
 static void
 space_drawer_notify_cb (GtkSourceSpaceDrawer *space_drawer,
-                        GParamSpec           *pspec,
-                        GtkSourceView        *view)
+                       GParamSpec           *pspec,
+                       GtkSourceView        *view)
 {
-       gtk_widget_queue_draw (GTK_WIDGET (view));
+       gtk_source_view_queue_draw (view);
 }
 
 static void
@@ -1300,48 +1235,66 @@ notify_buffer_cb (GtkSourceView *view)
 static void
 gtk_source_view_init (GtkSourceView *view)
 {
-       GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
        GtkStyleContext *context;
+       GtkEventController *key;
+#if 0
        GtkTargetList *target_list;
+#endif
+
+       view->priv = gtk_source_view_get_instance_private (view);
 
+       view->priv->tab_width = DEFAULT_TAB_WIDTH;
+       view->priv->tabs_set = FALSE;
+       view->priv->indent_width = -1;
+       view->priv->indent_on_tab = TRUE;
+       view->priv->smart_home_end = GTK_SOURCE_SMART_HOME_END_DISABLED;
+       view->priv->right_margin_pos = DEFAULT_RIGHT_MARGIN_POSITION;
+       view->priv->cached_right_margin_pos = -1;
 
-       priv->tab_width = DEFAULT_TAB_WIDTH;
-       priv->tabs_set = FALSE;
-       priv->indent_width = -1;
-       priv->indent_on_tab = TRUE;
-       priv->smart_home_end = GTK_SOURCE_SMART_HOME_END_DISABLED;
-       priv->right_margin_pos = DEFAULT_RIGHT_MARGIN_POSITION;
-       priv->cached_right_margin_pos = -1;
+       /* Default to monospace */
+       gtk_text_view_set_monospace (GTK_TEXT_VIEW (view), TRUE);
 
        gtk_text_view_set_left_margin (GTK_TEXT_VIEW (view), 2);
        gtk_text_view_set_right_margin (GTK_TEXT_VIEW (view), 2);
 
-       priv->right_margin_line_color = NULL;
-       priv->right_margin_overlay_color = NULL;
+       view->priv->right_margin_line_color = NULL;
+       view->priv->right_margin_overlay_color = NULL;
 
-       priv->space_drawer = gtk_source_space_drawer_new ();
-       g_signal_connect_object (priv->space_drawer,
+       view->priv->space_drawer = gtk_source_space_drawer_new ();
+       g_signal_connect_object (view->priv->space_drawer,
                                 "notify",
                                 G_CALLBACK (space_drawer_notify_cb),
                                 view,
                                 0);
 
-       priv->mark_categories = g_hash_table_new_full (g_str_hash,
+       view->priv->mark_categories = g_hash_table_new_full (g_str_hash,
                                                             g_str_equal,
                                                             (GDestroyNotify) g_free,
                                                             (GDestroyNotify) mark_category_free);
 
+       key = gtk_event_controller_key_new ();
+       gtk_event_controller_set_propagation_phase (key, GTK_PHASE_CAPTURE);
+       g_signal_connect_swapped (key,
+                                 "key-pressed",
+                                 G_CALLBACK (gtk_source_view_key_pressed),
+                                 view);
+       gtk_widget_add_controller (GTK_WIDGET (view), g_steal_pointer (&key));
+
+#if 0
        target_list = gtk_drag_dest_get_target_list (GTK_WIDGET (view));
        g_return_if_fail (target_list != NULL);
 
        gtk_target_list_add_table (target_list, drop_types, G_N_ELEMENTS (drop_types));
+#endif
 
        gtk_widget_set_has_tooltip (GTK_WIDGET (view), TRUE);
 
+#if 0
        g_signal_connect (view,
                          "drag_data_received",
                          G_CALLBACK (view_dnd_drop),
                          NULL);
+#endif
 
        g_signal_connect (view,
                          "notify::buffer",
@@ -1356,13 +1309,10 @@ static void
 gtk_source_view_dispose (GObject *object)
 {
        GtkSourceView *view = GTK_SOURCE_VIEW (object);
-       GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
 
-       g_clear_object (&priv->completion);
-       g_clear_object (&priv->left_gutter);
-       g_clear_object (&priv->right_gutter);
-       g_clear_object (&priv->style_scheme);
-       g_clear_object (&priv->space_drawer);
+       g_clear_object (&view->priv->completion);
+       g_clear_object (&view->priv->style_scheme);
+       g_clear_object (&view->priv->space_drawer);
 
        remove_source_buffer (view);
 
@@ -1381,21 +1331,20 @@ static void
 gtk_source_view_finalize (GObject *object)
 {
        GtkSourceView *view = GTK_SOURCE_VIEW (object);
-       GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
 
-       if (priv->right_margin_line_color != NULL)
+       if (view->priv->right_margin_line_color != NULL)
        {
-               gdk_rgba_free (priv->right_margin_line_color);
+               gdk_rgba_free (view->priv->right_margin_line_color);
        }
 
-       if (priv->right_margin_overlay_color != NULL)
+       if (view->priv->right_margin_overlay_color != NULL)
        {
-               gdk_rgba_free (priv->right_margin_overlay_color);
+               gdk_rgba_free (view->priv->right_margin_overlay_color);
        }
 
-       if (priv->mark_categories)
+       if (view->priv->mark_categories)
        {
-               g_hash_table_destroy (priv->mark_categories);
+               g_hash_table_destroy (view->priv->mark_categories);
        }
 
        G_OBJECT_CLASS (gtk_source_view_parent_class)->finalize (object);
@@ -1403,8 +1352,8 @@ gtk_source_view_finalize (GObject *object)
 
 static void
 get_visible_region (GtkTextView *text_view,
-                    GtkTextIter *start,
-                    GtkTextIter *end)
+                   GtkTextIter *start,
+                   GtkTextIter *end)
 {
        GdkRectangle visible_rect;
 
@@ -1424,11 +1373,26 @@ get_visible_region (GtkTextView *text_view,
        gtk_text_iter_forward_line (end);
 }
 
+static void
+changed_cb (GtkSourceBuffer *buffer,
+            GtkSourceView   *view)
+{
+       if (view->priv->left_gutter != NULL)
+       {
+               gtk_widget_queue_draw (GTK_WIDGET (view->priv->left_gutter));
+       }
+
+       if (view->priv->right_gutter != NULL)
+       {
+               gtk_widget_queue_draw (GTK_WIDGET (view->priv->right_gutter));
+       }
+}
+
 static void
 highlight_updated_cb (GtkSourceBuffer *buffer,
-                      GtkTextIter     *_start,
-                      GtkTextIter     *_end,
-                      GtkTextView     *text_view)
+                     GtkTextIter     *_start,
+                     GtkTextIter     *_end,
+                     GtkTextView     *text_view)
 {
        GtkTextIter start;
        GtkTextIter end;
@@ -1502,10 +1466,9 @@ highlight_updated_cb (GtkSourceBuffer *buffer,
 
 static void
 search_start_cb (GtkSourceBufferInternal *buffer_internal,
-                 GtkSourceSearchContext  *search_context,
-                 GtkSourceView           *view)
+                GtkSourceSearchContext  *search_context,
+                GtkSourceView           *view)
 {
-       GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
        GtkTextIter visible_start;
        GtkTextIter visible_end;
        GtkSourceBuffer *buffer_search;
@@ -1513,7 +1476,7 @@ search_start_cb (GtkSourceBufferInternal *buffer_internal,
        get_visible_region (GTK_TEXT_VIEW (view), &visible_start, &visible_end);
 
        buffer_search = gtk_source_search_context_get_buffer (search_context);
-       g_assert (buffer_search == priv->source_buffer);
+       g_assert (buffer_search == view->priv->source_buffer);
 
        _gtk_source_search_context_update_highlight (search_context,
                                                     &visible_start,
@@ -1523,74 +1486,89 @@ search_start_cb (GtkSourceBufferInternal *buffer_internal,
 
 static void
 source_mark_updated_cb (GtkSourceBuffer *buffer,
-                        GtkSourceMark   *mark,
-                        GtkTextView     *text_view)
+                       GtkSourceMark   *mark,
+                       GtkTextView     *text_view)
 {
        /* TODO do something more intelligent here, namely
         * invalidate only the area under the mark if possible */
-       gtk_widget_queue_draw (GTK_WIDGET (text_view));
+       gtk_source_view_queue_draw (GTK_SOURCE_VIEW (text_view));
 }
 
 static void
 buffer_style_scheme_changed_cb (GtkSourceBuffer *buffer,
-                                GParamSpec      *pspec,
-                                GtkSourceView   *view)
+                               GParamSpec      *pspec,
+                               GtkSourceView   *view)
 {
        gtk_source_view_update_style_scheme (view);
 }
 
+static void
+buffer_has_selection_changed_cb (GtkSourceBuffer *buffer,
+                                GParamSpec      *pspec,
+                                GtkSourceView   *view)
+{
+       gtk_widget_action_set_enabled (GTK_WIDGET (view),
+                                      "source.change-case",
+                                      (gtk_text_view_get_editable (GTK_TEXT_VIEW (view)) &&
+                                       gtk_text_buffer_get_has_selection (GTK_TEXT_BUFFER (buffer))));
+}
+
 static void
 implicit_trailing_newline_changed_cb (GtkSourceBuffer *buffer,
-                                      GParamSpec      *pspec,
-                                      GtkSourceView   *view)
+                                     GParamSpec      *pspec,
+                                     GtkSourceView   *view)
 {
        /* For drawing or not a trailing newline. */
-       gtk_widget_queue_draw (GTK_WIDGET (view));
+       gtk_source_view_queue_draw (view);
 }
 
 static void
 remove_source_buffer (GtkSourceView *view)
 {
-       GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
-
-       if (priv->source_buffer != NULL)
+       if (view->priv->source_buffer != NULL)
        {
                GtkSourceBufferInternal *buffer_internal;
 
-               g_signal_handlers_disconnect_by_func (priv->source_buffer,
+               g_signal_handlers_disconnect_by_func (view->priv->source_buffer,
+                                                     changed_cb,
+                                                     view);
+
+               g_signal_handlers_disconnect_by_func (view->priv->source_buffer,
                                                      highlight_updated_cb,
                                                      view);
 
-               g_signal_handlers_disconnect_by_func (priv->source_buffer,
+               g_signal_handlers_disconnect_by_func (view->priv->source_buffer,
                                                      source_mark_updated_cb,
                                                      view);
 
-               g_signal_handlers_disconnect_by_func (priv->source_buffer,
+               g_signal_handlers_disconnect_by_func (view->priv->source_buffer,
                                                      buffer_style_scheme_changed_cb,
                                                      view);
 
-               g_signal_handlers_disconnect_by_func (priv->source_buffer,
+               g_signal_handlers_disconnect_by_func (view->priv->source_buffer,
+                                                     buffer_has_selection_changed_cb,
+                                                     view);
+
+               g_signal_handlers_disconnect_by_func (view->priv->source_buffer,
                                                      implicit_trailing_newline_changed_cb,
                                                      view);
 
-               buffer_internal = _gtk_source_buffer_internal_get_from_buffer (priv->source_buffer);
+               buffer_internal = _gtk_source_buffer_internal_get_from_buffer (view->priv->source_buffer);
 
                g_signal_handlers_disconnect_by_func (buffer_internal,
                                                      search_start_cb,
                                                      view);
 
-               g_object_unref (priv->source_buffer);
-               priv->source_buffer = NULL;
+               g_object_unref (view->priv->source_buffer);
+               view->priv->source_buffer = NULL;
        }
 }
 
 static void
 set_source_buffer (GtkSourceView *view,
-                   GtkTextBuffer *buffer)
+                  GtkTextBuffer *buffer)
 {
-       GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
-
-       if (buffer == (GtkTextBuffer*) priv->source_buffer)
+       if (buffer == (GtkTextBuffer*) view->priv->source_buffer)
        {
                return;
        }
@@ -1601,7 +1579,12 @@ set_source_buffer (GtkSourceView *view,
        {
                GtkSourceBufferInternal *buffer_internal;
 
-               priv->source_buffer = g_object_ref (GTK_SOURCE_BUFFER (buffer));
+               view->priv->source_buffer = g_object_ref (GTK_SOURCE_BUFFER (buffer));
+
+               g_signal_connect (buffer,
+                                 "changed",
+                                 G_CALLBACK (changed_cb),
+                                 view);
 
                g_signal_connect (buffer,
                                  "highlight-updated",
@@ -1623,103 +1606,28 @@ set_source_buffer (GtkSourceView *view,
                                  G_CALLBACK (implicit_trailing_newline_changed_cb),
                                  view);
 
-               buffer_internal = _gtk_source_buffer_internal_get_from_buffer (priv->source_buffer);
+               g_signal_connect (buffer,
+                                 "notify::has-selection",
+                                 G_CALLBACK (buffer_has_selection_changed_cb),
+                                 view);
+
+               buffer_internal = _gtk_source_buffer_internal_get_from_buffer (view->priv->source_buffer);
 
                g_signal_connect (buffer_internal,
                                  "search-start",
                                  G_CALLBACK (search_start_cb),
                                  view);
-       }
-
-       gtk_source_view_update_style_scheme (view);
-}
-
-static void
-scroll_to_insert (GtkSourceView *view,
-                  GtkTextBuffer *buffer)
-{
-       GtkTextMark *insert;
-       GtkTextIter iter;
-       GdkRectangle visible, location;
-
-       insert = gtk_text_buffer_get_insert (buffer);
-       gtk_text_buffer_get_iter_at_mark (buffer, &iter, insert);
-
-       gtk_text_view_get_visible_rect (GTK_TEXT_VIEW (view), &visible);
-       gtk_text_view_get_iter_location (GTK_TEXT_VIEW (view), &iter, &location);
 
-       if (location.y < visible.y || visible.y + visible.height < location.y)
-       {
-               gtk_text_view_scroll_to_mark (GTK_TEXT_VIEW (view),
-                                             insert,
-                                             0.0,
-                                             TRUE,
-                                             0.5, 0.5);
+               buffer_has_selection_changed_cb (GTK_SOURCE_BUFFER (buffer), NULL, view);
        }
-       else if (location.x < visible.x || visible.x + visible.width < location.x)
-       {
-               gdouble position;
-               GtkAdjustment *adjustment;
-
-               /* We revert the vertical position of the view because
-                * _scroll_to_iter will cause it to move and the
-                * insert mark is already visible vertically. */
-
-               adjustment = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (view));
-               position = gtk_adjustment_get_value (adjustment);
-
-               /* Must use _to_iter as _to_mark scrolls in an
-                * idle handler and would prevent use from
-                * reverting the vertical position of the view. */
-               gtk_text_view_scroll_to_iter (GTK_TEXT_VIEW (view),
-                                             &iter,
-                                             0.0,
-                                             TRUE,
-                                             0.5, 0.0);
-
-               gtk_adjustment_set_value (adjustment, position);
-       }
-}
 
-static void
-gtk_source_view_undo (GtkSourceView *view)
-{
-       GtkTextBuffer *buffer;
-
-       g_return_if_fail (GTK_SOURCE_IS_VIEW (view));
-
-       buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
-
-       if (gtk_text_view_get_editable (GTK_TEXT_VIEW (view)) &&
-           GTK_SOURCE_IS_BUFFER (buffer) &&
-           gtk_source_buffer_can_undo (GTK_SOURCE_BUFFER (buffer)))
-       {
-               gtk_source_buffer_undo (GTK_SOURCE_BUFFER (buffer));
-               scroll_to_insert (view, buffer);
-       }
-}
-
-static void
-gtk_source_view_redo (GtkSourceView *view)
-{
-       GtkTextBuffer *buffer;
-
-       g_return_if_fail (GTK_SOURCE_IS_VIEW (view));
-
-       buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
-
-       if (gtk_text_view_get_editable (GTK_TEXT_VIEW (view)) &&
-           GTK_SOURCE_IS_BUFFER (buffer) &&
-           gtk_source_buffer_can_redo (GTK_SOURCE_BUFFER (buffer)))
-       {
-               gtk_source_buffer_redo (GTK_SOURCE_BUFFER (buffer));
-               scroll_to_insert (view, buffer);
-       }
+       gtk_source_view_update_style_scheme (view);
 }
 
 static void
 gtk_source_view_show_completion_real (GtkSourceView *view)
 {
+#if 0
        GtkSourceCompletion *completion;
        GtkSourceCompletionContext *context;
 
@@ -1729,43 +1637,13 @@ gtk_source_view_show_completion_real (GtkSourceView *view)
        gtk_source_completion_start (completion,
                                     gtk_source_completion_get_providers (completion),
                                     context);
+#endif
 }
 
-static void
-menu_item_activate_change_case_cb (GtkWidget   *menu_item,
-                                   GtkTextView *text_view)
-{
-       GtkTextBuffer *buffer;
-       GtkTextIter start, end;
-
-       buffer = gtk_text_view_get_buffer (text_view);
-       if (!GTK_SOURCE_IS_BUFFER (buffer))
-       {
-               return;
-       }
-
-       if (gtk_text_buffer_get_selection_bounds (buffer, &start, &end))
-       {
-               GtkSourceChangeCaseType case_type;
-
-               case_type = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (menu_item), "change-case"));
-               gtk_source_buffer_change_case (GTK_SOURCE_BUFFER (buffer), case_type, &start, &end);
-       }
-}
-
-static void
-menu_item_activate_cb (GtkWidget   *menu_item,
-                       GtkTextView *text_view)
-{
-       const gchar *gtksignal;
-
-       gtksignal = g_object_get_data (G_OBJECT (menu_item), "gtk-signal");
-       g_signal_emit_by_name (G_OBJECT (text_view), gtksignal);
-}
-
+#if 0
 static void
 gtk_source_view_populate_popup (GtkTextView *text_view,
-                                GtkWidget   *popup)
+                               GtkWidget   *popup)
 {
        GtkTextBuffer *buffer;
        GtkMenuShell *menu;
@@ -1794,24 +1672,14 @@ gtk_source_view_populate_popup (GtkTextView *text_view,
 
                /* create redo menu_item. */
                menu_item = gtk_menu_item_new_with_mnemonic (_("_Redo"));
-               g_object_set_data (G_OBJECT (menu_item), "gtk-signal", (gpointer)"redo");
-               g_signal_connect (G_OBJECT (menu_item), "activate",
-                                 G_CALLBACK (menu_item_activate_cb), text_view);
+               gtk_actionable_set_action_name (GTK_ACTIONABLE (menu_item), "text.redo");
                gtk_menu_shell_prepend (menu, menu_item);
-               gtk_widget_set_sensitive (menu_item,
-                                         (gtk_text_view_get_editable (text_view) &&
-                                          gtk_source_buffer_can_redo (GTK_SOURCE_BUFFER (buffer))));
                gtk_widget_show (menu_item);
 
                /* create undo menu_item. */
                menu_item = gtk_menu_item_new_with_mnemonic (_("_Undo"));
-               g_object_set_data (G_OBJECT (menu_item), "gtk-signal", (gpointer)"undo");
-               g_signal_connect (G_OBJECT (menu_item), "activate",
-                                 G_CALLBACK (menu_item_activate_cb), text_view);
+               gtk_actionable_set_action_name (GTK_ACTIONABLE (menu_item), "text.undo");
                gtk_menu_shell_prepend (menu, menu_item);
-               gtk_widget_set_sensitive (menu_item,
-                                         (gtk_text_view_get_editable (text_view) &&
-                                          gtk_source_buffer_can_undo (GTK_SOURCE_BUFFER (buffer))));
                gtk_widget_show (menu_item);
        }
 
@@ -1824,58 +1692,36 @@ gtk_source_view_populate_popup (GtkTextView *text_view,
        case_menu = GTK_MENU_SHELL (gtk_menu_new ());
 
        menu_item = gtk_menu_item_new_with_mnemonic (_("All _Upper Case"));
-       g_object_set_data (G_OBJECT (menu_item), "change-case", 
GINT_TO_POINTER(GTK_SOURCE_CHANGE_CASE_UPPER));
-       g_signal_connect (G_OBJECT (menu_item), "activate",
-                         G_CALLBACK (menu_item_activate_change_case_cb), text_view);
+       gtk_actionable_set_detailed_action_name ("source.change-case('upper')");
        gtk_menu_shell_append (case_menu, menu_item);
-       gtk_widget_set_sensitive (menu_item,
-                                 (gtk_text_view_get_editable (text_view) &&
-                                  gtk_text_buffer_get_has_selection (buffer)));
        gtk_widget_show (menu_item);
 
        menu_item = gtk_menu_item_new_with_mnemonic (_("All _Lower Case"));
-       g_object_set_data (G_OBJECT (menu_item), "change-case", 
GINT_TO_POINTER(GTK_SOURCE_CHANGE_CASE_LOWER));
-       g_signal_connect (G_OBJECT (menu_item), "activate",
-                         G_CALLBACK (menu_item_activate_change_case_cb), text_view);
+       gtk_actionable_set_detailed_action_name ("source.change-case('lower')");
        gtk_menu_shell_append (case_menu, menu_item);
-       gtk_widget_set_sensitive (menu_item,
-                                 (gtk_text_view_get_editable (text_view) &&
-                                  gtk_text_buffer_get_has_selection (buffer)));
        gtk_widget_show (menu_item);
 
        menu_item = gtk_menu_item_new_with_mnemonic (_("_Invert Case"));
-       g_object_set_data (G_OBJECT (menu_item), "change-case", 
GINT_TO_POINTER(GTK_SOURCE_CHANGE_CASE_TOGGLE));
-       g_signal_connect (G_OBJECT (menu_item), "activate",
-                         G_CALLBACK (menu_item_activate_change_case_cb), text_view);
+       gtk_actionable_set_detailed_action_name ("source.change-case('toggle')");
        gtk_menu_shell_append (case_menu, menu_item);
-       gtk_widget_set_sensitive (menu_item,
-                                 (gtk_text_view_get_editable (text_view) &&
-                                  gtk_text_buffer_get_has_selection (buffer)));
        gtk_widget_show (menu_item);
 
        menu_item = gtk_menu_item_new_with_mnemonic (_("_Title Case"));
-       g_object_set_data (G_OBJECT (menu_item), "change-case", 
GINT_TO_POINTER(GTK_SOURCE_CHANGE_CASE_TITLE));
-       g_signal_connect (G_OBJECT (menu_item), "activate",
-                         G_CALLBACK (menu_item_activate_change_case_cb), text_view);
+       gtk_actionable_set_detailed_action_name ("source.change-case('title')");
        gtk_menu_shell_append (case_menu, menu_item);
-       gtk_widget_set_sensitive (menu_item,
-                                 (gtk_text_view_get_editable (text_view) &&
-                                  gtk_text_buffer_get_has_selection (buffer)));
        gtk_widget_show (menu_item);
 
        menu_item = gtk_menu_item_new_with_mnemonic (_("C_hange Case"));
        gtk_menu_item_set_submenu (GTK_MENU_ITEM (menu_item), GTK_WIDGET (case_menu));
        gtk_menu_shell_append (menu, menu_item);
-       gtk_widget_set_sensitive (menu_item,
-                                 (gtk_text_view_get_editable (text_view) &&
-                                  gtk_text_buffer_get_has_selection (buffer)));
        gtk_widget_show (menu_item);
 }
+#endif
 
 static void
 move_cursor (GtkTextView       *text_view,
-             const GtkTextIter *new_location,
-             gboolean           extend_selection)
+            const GtkTextIter *new_location,
+            gboolean           extend_selection)
 {
        GtkTextBuffer *buffer = gtk_text_view_get_buffer (text_view);
        GtkTextMark *insert = gtk_text_buffer_get_insert (buffer);
@@ -1894,8 +1740,8 @@ move_cursor (GtkTextView       *text_view,
 
 static void
 move_to_first_char (GtkTextView *text_view,
-                    GtkTextIter *iter,
-                    gboolean     display_line)
+                   GtkTextIter *iter,
+                   gboolean     display_line)
 {
        GtkTextIter last;
 
@@ -1939,8 +1785,8 @@ move_to_first_char (GtkTextView *text_view,
 
 static void
 move_to_last_char (GtkTextView *text_view,
-                   GtkTextIter *iter,
-                   gboolean     display_line)
+                  GtkTextIter *iter,
+                  gboolean     display_line)
 {
        GtkTextIter first;
 
@@ -1983,10 +1829,10 @@ move_to_last_char (GtkTextView *text_view,
 
 static void
 do_cursor_move_home_end (GtkTextView *text_view,
-                         GtkTextIter *cur,
-                         GtkTextIter *iter,
-                         gboolean     extend_selection,
-                         gint         count)
+                        GtkTextIter *cur,
+                        GtkTextIter *iter,
+                        gboolean     extend_selection,
+                        gint         count)
 {
        /* if we are clearing selection, we need to move_cursor even
         * if we are at proper iter because selection_bound may need
@@ -2001,12 +1847,11 @@ do_cursor_move_home_end (GtkTextView *text_view,
 /* Returns %TRUE if handled. */
 static gboolean
 move_cursor_smart_home_end (GtkTextView     *text_view,
-                            GtkMovementStep  step,
-                            gint             count,
-                            gboolean         extend_selection)
+                           GtkMovementStep  step,
+                           gint             count,
+                           gboolean         extend_selection)
 {
        GtkSourceView *source_view = GTK_SOURCE_VIEW (text_view);
-       GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (source_view);
        GtkTextBuffer *buffer = gtk_text_view_get_buffer (text_view);
        gboolean move_display_line;
        GtkTextMark *mark;
@@ -2037,7 +1882,7 @@ move_cursor_smart_home_end (GtkTextView     *text_view,
                        at_home = gtk_text_iter_starts_line (&cur);
                }
 
-               switch (priv->smart_home_end)
+               switch (source_view->priv->smart_home_end)
                {
                        case GTK_SOURCE_SMART_HOME_END_BEFORE:
                                if (!gtk_text_iter_equal (&cur, &iter) || at_home)
@@ -2095,7 +1940,7 @@ move_cursor_smart_home_end (GtkTextView     *text_view,
                        at_end = gtk_text_iter_ends_line (&cur);
                }
 
-               switch (priv->smart_home_end)
+               switch (source_view->priv->smart_home_end)
                {
                        case GTK_SOURCE_SMART_HOME_END_BEFORE:
                                if (!gtk_text_iter_equal (&cur, &iter) || at_end)
@@ -2140,8 +1985,8 @@ move_cursor_smart_home_end (GtkTextView     *text_view,
 
 static void
 move_cursor_words (GtkTextView *text_view,
-                   gint         count,
-                   gboolean     extend_selection)
+                  gint         count,
+                  gboolean     extend_selection)
 {
        GtkTextBuffer *buffer;
        GtkTextIter insert;
@@ -2211,9 +2056,9 @@ move_cursor_words (GtkTextView *text_view,
 
 static void
 gtk_source_view_move_cursor (GtkTextView     *text_view,
-                             GtkMovementStep  step,
-                             gint             count,
-                             gboolean         extend_selection)
+                            GtkMovementStep  step,
+                            gint             count,
+                            gboolean         extend_selection)
 {
        if (!gtk_text_view_get_cursor_visible (text_view))
        {
@@ -2256,8 +2101,8 @@ chain_up:
 
 static void
 gtk_source_view_delete_from_cursor (GtkTextView   *text_view,
-                                    GtkDeleteType  type,
-                                    gint           count)
+                                   GtkDeleteType  type,
+                                   gint           count)
 {
        GtkTextBuffer *buffer = gtk_text_view_get_buffer (text_view);
        GtkTextIter insert;
@@ -2302,10 +2147,10 @@ gtk_source_view_delete_from_cursor (GtkTextView   *text_view,
 
 static gboolean
 gtk_source_view_extend_selection (GtkTextView            *text_view,
-                                  GtkTextExtendSelection  granularity,
-                                  const GtkTextIter      *location,
-                                  GtkTextIter            *start,
-                                  GtkTextIter            *end)
+                                 GtkTextExtendSelection  granularity,
+                                 const GtkTextIter      *location,
+                                 GtkTextIter            *start,
+                                 GtkTextIter            *end)
 {
        if (granularity == GTK_TEXT_EXTEND_SELECTION_WORD)
        {
@@ -2322,45 +2167,37 @@ gtk_source_view_extend_selection (GtkTextView            *text_view,
 
 static void
 gtk_source_view_ensure_redrawn_rect_is_highlighted (GtkSourceView *view,
-                                                    cairo_t       *cr)
+                                                   GdkRectangle  *clip)
 {
-       GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
-       GdkRectangle clip;
        GtkTextIter iter1, iter2;
 
-       if (priv->source_buffer == NULL ||
-           !gdk_cairo_get_clip_rectangle (cr, &clip))
-       {
-               return;
-       }
-
-       gtk_text_view_get_line_at_y (GTK_TEXT_VIEW (view), &iter1, clip.y, NULL);
+       gtk_text_view_get_line_at_y (GTK_TEXT_VIEW (view), &iter1, clip->y, NULL);
        gtk_text_iter_backward_line (&iter1);
-       gtk_text_view_get_line_at_y (GTK_TEXT_VIEW (view), &iter2, clip.y + clip.height, NULL);
+       gtk_text_view_get_line_at_y (GTK_TEXT_VIEW (view), &iter2, clip->y + clip->height, NULL);
        gtk_text_iter_forward_line (&iter2);
 
        DEBUG ({
-               g_print ("    draw area: %d - %d\n", clip.y, clip.y + clip.height);
+               g_print ("    draw area: %d - %d\n", clip->y, clip->y + clip->height);
                g_print ("    lines to update: %d - %d\n",
                         gtk_text_iter_get_line (&iter1),
                         gtk_text_iter_get_line (&iter2));
        });
 
-       _gtk_source_buffer_update_syntax_highlight (priv->source_buffer,
+       _gtk_source_buffer_update_syntax_highlight (view->priv->source_buffer,
                                                    &iter1, &iter2, FALSE);
-       _gtk_source_buffer_update_search_highlight (priv->source_buffer,
+       _gtk_source_buffer_update_search_highlight (view->priv->source_buffer,
                                                    &iter1, &iter2, FALSE);
 }
 
 /* This function is taken from gtk+/tests/testtext.c */
 static void
 gtk_source_view_get_lines (GtkTextView *text_view,
-                           gint         first_y,
-                           gint         last_y,
-                           GArray      *buffer_coords,
-                           GArray      *line_heights,
-                           GArray      *numbers,
-                           gint        *countp)
+                          gint         first_y,
+                          gint         last_y,
+                          GArray      *buffer_coords,
+                          GArray      *line_heights,
+                          GArray      *numbers,
+                          gint        *countp)
 {
        GtkTextIter iter;
        gint count;
@@ -2434,31 +2271,37 @@ gtk_source_view_get_lines (GtkTextView *text_view,
  */
 static void
 gtk_source_view_paint_line_background (GtkTextView   *text_view,
-                                       cairo_t       *cr,
+                                       GtkSnapshot   *snapshot,
                                        int            y, /* in buffer coordinates */
                                        int            height,
                                        const GdkRGBA *color)
 {
-       gdouble x1, y1, x2, y2;
-
-       cairo_save (cr);
-       cairo_clip_extents (cr, &x1, &y1, &x2, &y2);
+       static const float widths[4] = { 1, 0, 1, 0 };
+       GdkRGBA colors[4] = { *color, *color, *color, *color };
+       GdkRectangle visible_rect;
 
-       gdk_cairo_set_source_rgba (cr, (GdkRGBA *)color);
-       cairo_set_line_width (cr, 1);
-       cairo_rectangle (cr, x1 + .5, y + .5, x2 - x1 - 1, height - 1);
-       cairo_stroke_preserve (cr);
-       cairo_fill (cr);
-       cairo_restore (cr);
+       gtk_text_view_get_visible_rect (text_view, &visible_rect);
+       gtk_snapshot_append_border (snapshot,
+                                   &GSK_ROUNDED_RECT_INIT (visible_rect.x,
+                                                           y,
+                                                           visible_rect.width,
+                                                           height),
+                                   widths,
+                                   colors);
+       gtk_snapshot_append_color (snapshot,
+                                  color,
+                                  &GRAPHENE_RECT_INIT (visible_rect.x,
+                                                       y,
+                                                       visible_rect.width,
+                                                       height));
 }
 
 static void
 gtk_source_view_paint_marks_background (GtkSourceView *view,
-                                        cairo_t       *cr)
+                                        GtkSnapshot   *snapshot)
 {
-       GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
        GtkTextView *text_view;
-       GdkRectangle clip;
+       GdkRectangle visible_rect;
        GArray *numbers;
        GArray *pixels;
        GArray *heights;
@@ -2466,17 +2309,18 @@ gtk_source_view_paint_marks_background (GtkSourceView *view,
        gint count;
        gint i;
 
-       if (priv->source_buffer == NULL ||
-           !_gtk_source_buffer_has_source_marks (priv->source_buffer) ||
-           !gdk_cairo_get_clip_rectangle (cr, &clip))
+       if (view->priv->source_buffer == NULL ||
+           !_gtk_source_buffer_has_source_marks (view->priv->source_buffer))
        {
                return;
        }
 
        text_view = GTK_TEXT_VIEW (view);
 
-       y1 = clip.y;
-       y2 = y1 + clip.height;
+       gtk_text_view_get_visible_rect (text_view, &visible_rect);
+
+       y1 = visible_rect.y;
+       y2 = y1 + visible_rect.height;
 
        numbers = g_array_new (FALSE, FALSE, sizeof (gint));
        pixels = g_array_new (FALSE, FALSE, sizeof (gint));
@@ -2522,7 +2366,7 @@ gtk_source_view_paint_marks_background (GtkSourceView *view,
 
                line_to_paint = g_array_index (numbers, gint, i);
 
-               marks = gtk_source_buffer_get_source_marks_at_line (priv->source_buffer,
+               marks = gtk_source_buffer_get_source_marks_at_line (view->priv->source_buffer,
                                                                    line_to_paint,
                                                                    NULL);
 
@@ -2552,7 +2396,7 @@ gtk_source_view_paint_marks_background (GtkSourceView *view,
                if (priority != -1)
                {
                        gtk_source_view_paint_line_background (text_view,
-                                                              cr,
+                                                              snapshot,
                                                               g_array_index (pixels, gint, i),
                                                               g_array_index (heights, gint, i),
                                                               &background);
@@ -2566,11 +2410,10 @@ gtk_source_view_paint_marks_background (GtkSourceView *view,
 
 static void
 gtk_source_view_paint_right_margin (GtkSourceView *view,
-                                    cairo_t       *cr)
+                                    GtkSnapshot   *snapshot)
 {
-       GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
        GtkTextView *text_view = GTK_TEXT_VIEW (view);
-       GdkRectangle clip;
+       GdkRectangle visible_rect;
        gdouble x;
 
 #ifdef ENABLE_PROFILE
@@ -2584,48 +2427,40 @@ gtk_source_view_paint_right_margin (GtkSourceView *view,
        g_timer_start (timer);
 #endif
 
-       g_return_if_fail (priv->right_margin_line_color != NULL);
+       g_return_if_fail (view->priv->right_margin_line_color != NULL);
 
-       if (!gdk_cairo_get_clip_rectangle (cr, &clip))
-       {
-               return;
-       }
+        gtk_text_view_get_visible_rect (text_view, &visible_rect);
 
-       if (priv->cached_right_margin_pos < 0)
+       if (view->priv->cached_right_margin_pos < 0)
        {
-               priv->cached_right_margin_pos =
+               view->priv->cached_right_margin_pos =
                        calculate_real_tab_width (view,
-                                                 priv->right_margin_pos,
+                                                 view->priv->right_margin_pos,
                                                  '_');
        }
 
-       x = priv->cached_right_margin_pos + gtk_text_view_get_left_margin (text_view);
+       x = view->priv->cached_right_margin_pos + gtk_text_view_get_left_margin (text_view);
 
-       cairo_save (cr);
-       cairo_set_line_width (cr, 1.0);
+       gtk_snapshot_save (snapshot);
 
-       if (x + 1 >= clip.x && x <= clip.x + clip.width)
-       {
-               cairo_move_to (cr, x + 0.5, clip.y);
-               cairo_line_to (cr, x + 0.5, clip.y + clip.height);
-
-               gdk_cairo_set_source_rgba (cr, priv->right_margin_line_color);
-               cairo_stroke (cr);
-       }
+       gtk_snapshot_append_color (snapshot,
+                                  view->priv->right_margin_line_color,
+                                  &GRAPHENE_RECT_INIT (x,
+                                                       visible_rect.y,
+                                                       1,
+                                                       visible_rect.height));
 
-       /* Only draw the overlay when the style scheme explicitly sets it. */
-       if (priv->right_margin_overlay_color != NULL && clip.x + clip.width > x + 1)
+       if (view->priv->right_margin_overlay_color != NULL)
        {
-               /* Draw the rectangle next to the line (x+1). */
-               cairo_rectangle (cr,
-                                x + 1, clip.y,
-                                clip.x + clip.width - (x + 1), clip.height);
-
-               gdk_cairo_set_source_rgba (cr, priv->right_margin_overlay_color);
-               cairo_fill (cr);
+               gtk_snapshot_append_color (snapshot,
+                                          view->priv->right_margin_overlay_color,
+                                          &GRAPHENE_RECT_INIT (x + 1,
+                                                               visible_rect.y,
+                                                               visible_rect.x + visible_rect.width,
+                                                               visible_rect.height));
        }
 
-       cairo_restore (cr);
+       gtk_snapshot_restore (snapshot);
 
        PROFILE ({
                g_timer_stop (timer);
@@ -2637,7 +2472,7 @@ gtk_source_view_paint_right_margin (GtkSourceView *view,
 
 static gint
 realign (gint  offset,
-         guint align)
+        guint align)
 {
        if (offset > 0 && align > 0)
        {
@@ -2652,16 +2487,17 @@ realign (gint  offset,
 
 static void
 gtk_source_view_paint_background_pattern_grid (GtkSourceView *view,
-                                               cairo_t       *cr)
+                                              GtkSnapshot   *snapshot)
 {
-       GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
-       GdkRectangle clip;
+       GdkRectangle visible_rect;
        gint x, y, x2, y2;
        PangoContext *context;
        PangoLayout *layout;
        gint grid_width = 16;
        gint grid_height = 16;
 
+       gtk_text_view_get_visible_rect (GTK_TEXT_VIEW (view), &visible_rect);
+
        context = gtk_widget_get_pango_context (GTK_WIDGET (view));
        layout = pango_layout_new (context);
        pango_layout_set_text (layout, "X", 1);
@@ -2672,40 +2508,28 @@ gtk_source_view_paint_background_pattern_grid (GtkSourceView *view,
        grid_height = MAX (1, grid_height / 2);
        grid_width = MAX (1, grid_width);
 
-       cairo_save (cr);
-
-       gdk_cairo_get_clip_rectangle (cr, &clip);
-
-       cairo_set_line_width (cr, 1.0);
-       gdk_cairo_set_source_rgba (cr, &priv->background_pattern_color);
-
        /* Align our drawing position with a multiple of the grid size. */
-       x = realign (clip.x - grid_width, grid_width);
-       y = realign (clip.y - grid_height, grid_height);
-       x2 = realign (x + clip.width + grid_width * 2, grid_width);
-       y2 = realign (y + clip.height + grid_height * 2, grid_height);
-
-       for (; x <= x2; x += grid_width)
-       {
-               cairo_move_to (cr, x + .5, clip.y - .5);
-               cairo_line_to (cr, x + .5, clip.y + clip.height - .5);
-       }
-
-       for (; y <= y2; y += grid_height)
-       {
-               cairo_move_to (cr, clip.x + .5, y - .5);
-               cairo_line_to (cr, clip.x + clip.width + .5, y - .5);
-       }
-
-       cairo_stroke (cr);
-       cairo_restore (cr);
+       x = realign (visible_rect.x - grid_width, grid_width);
+       y = realign (visible_rect.y - grid_height, grid_height);
+       x2 = realign (x + visible_rect.width + grid_width * 2, grid_width);
+       y2 = realign (y + visible_rect.height + grid_height * 2, grid_height);
+
+       gtk_snapshot_push_repeat (snapshot,
+                                 &GRAPHENE_RECT_INIT (x, y, x2 - x, y2 - y),
+                                 &GRAPHENE_RECT_INIT (x, y, grid_width, grid_height));
+       gtk_snapshot_append_color (snapshot,
+                                  &view->priv->background_pattern_color,
+                                  &GRAPHENE_RECT_INIT (x, y, 1, grid_height));
+       gtk_snapshot_append_color (snapshot,
+                                  &view->priv->background_pattern_color,
+                                  &GRAPHENE_RECT_INIT (x, y, grid_width, 1));
+       gtk_snapshot_pop (snapshot);
 }
 
 static void
 gtk_source_view_paint_current_line_highlight (GtkSourceView *view,
-                                              cairo_t       *cr)
+                                              GtkSnapshot   *snapshot)
 {
-       GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
        GtkTextBuffer *buffer;
        GtkTextIter cur;
        gint y;
@@ -2718,101 +2542,66 @@ gtk_source_view_paint_current_line_highlight (GtkSourceView *view,
        gtk_text_view_get_line_yrange (GTK_TEXT_VIEW (view), &cur, &y, &height);
 
        gtk_source_view_paint_line_background (GTK_TEXT_VIEW (view),
-                                              cr,
+                                              snapshot,
                                               y, height,
-                                              &priv->current_line_color);
+                                              &view->priv->current_line_color);
 }
 
 static void
-gtk_source_view_draw_layer (GtkTextView      *text_view,
-                            GtkTextViewLayer  layer,
-                            cairo_t          *cr)
+gtk_source_view_snapshot_layer (GtkTextView      *text_view,
+                                GtkTextViewLayer  layer,
+                                GtkSnapshot      *snapshot)
 {
-       GtkSourceView *view = GTK_SOURCE_VIEW (text_view);
-       GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
+       GtkSourceView *view;
+
+       view = GTK_SOURCE_VIEW (text_view);
 
-       cairo_save (cr);
+       gtk_snapshot_save (snapshot);
 
        if (layer == GTK_TEXT_VIEW_LAYER_BELOW_TEXT)
        {
-               gtk_source_view_ensure_redrawn_rect_is_highlighted (view, cr);
-
-               if (priv->background_pattern == GTK_SOURCE_BACKGROUND_PATTERN_TYPE_GRID &&
-                   priv->background_pattern_color_set)
+               if (view->priv->background_pattern == GTK_SOURCE_BACKGROUND_PATTERN_TYPE_GRID &&
+                   view->priv->background_pattern_color_set)
                {
-                       gtk_source_view_paint_background_pattern_grid (view, cr);
+                       gtk_source_view_paint_background_pattern_grid (view, snapshot);
                }
 
                if (gtk_widget_is_sensitive (GTK_WIDGET (view)) &&
-                   priv->highlight_current_line &&
-                   priv->current_line_color_set)
+                   view->priv->highlight_current_line &&
+                   view->priv->current_line_color_set)
                {
-                       gtk_source_view_paint_current_line_highlight (view, cr);
+                       gtk_source_view_paint_current_line_highlight (view, snapshot);
                }
 
-               gtk_source_view_paint_marks_background (view, cr);
+               gtk_source_view_paint_marks_background (view, snapshot);
        }
        else if (layer == GTK_TEXT_VIEW_LAYER_ABOVE_TEXT)
        {
                /* Draw the right margin vertical line + overlay. */
-               if (priv->show_right_margin)
+               if (view->priv->show_right_margin)
                {
-                       gtk_source_view_paint_right_margin (view, cr);
+                       gtk_source_view_paint_right_margin (view, snapshot);
                }
 
-               if (priv->space_drawer != NULL)
+               if (view->priv->space_drawer != NULL)
                {
-                       _gtk_source_space_drawer_draw (priv->space_drawer, view, cr);
+                       _gtk_source_space_drawer_draw (view->priv->space_drawer, view, snapshot);
                }
        }
 
-       cairo_restore (cr);
+       gtk_snapshot_restore (snapshot);
 }
 
-static gboolean
-gtk_source_view_draw (GtkWidget *widget,
-                      cairo_t   *cr)
+static void
+gtk_source_view_snapshot (GtkWidget   *widget,
+                          GtkSnapshot *snapshot)
 {
-       GtkSourceView *view = GTK_SOURCE_VIEW (widget);
-       GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
-       gboolean event_handled;
-
-#ifdef ENABLE_PROFILE
-       static GTimer *timer = NULL;
-       if (timer == NULL)
-       {
-               timer = g_timer_new ();
-       }
-
-       g_timer_start (timer);
-#endif
-
-       DEBUG ({
-               g_print ("> gtk_source_view_draw start\n");
-       });
-
-       event_handled = GTK_WIDGET_CLASS (gtk_source_view_parent_class)->draw (widget, cr);
-
-       if (priv->left_gutter != NULL)
-       {
-               _gtk_source_gutter_draw (priv->left_gutter, view, cr);
-       }
-
-       if (priv->right_gutter != NULL)
-       {
-               _gtk_source_gutter_draw (priv->right_gutter, view, cr);
-       }
+       GdkRectangle visible_rect;
 
-       PROFILE ({
-               g_timer_stop (timer);
-               g_print ("    gtk_source_view_draw time: %g (sec * 1000)\n",
-                        g_timer_elapsed (timer, NULL) * 1000);
-       });
-       DEBUG ({
-               g_print ("> gtk_source_view_draw end\n");
-       });
+       gtk_text_view_get_visible_rect (GTK_TEXT_VIEW (widget), &visible_rect);
+       gtk_source_view_ensure_redrawn_rect_is_highlighted (GTK_SOURCE_VIEW (widget), &visible_rect);
 
-       return event_handled;
+       GTK_WIDGET_CLASS (gtk_source_view_parent_class)->snapshot (widget, snapshot);
 }
 
 /* This is a pretty important function... We call it when the tab_stop is changed,
@@ -2918,11 +2707,9 @@ gtk_source_view_new_with_buffer (GtkSourceBuffer *buffer)
 gboolean
 gtk_source_view_get_show_line_numbers (GtkSourceView *view)
 {
-       GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
-
        g_return_val_if_fail (GTK_SOURCE_IS_VIEW (view), FALSE);
 
-       return priv->show_line_numbers;
+       return view->priv->show_line_numbers;
 }
 
 /**
@@ -2934,27 +2721,25 @@ gtk_source_view_get_show_line_numbers (GtkSourceView *view)
  */
 void
 gtk_source_view_set_show_line_numbers (GtkSourceView *view,
-                                       gboolean       show)
+                                      gboolean       show)
 {
-       GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
-
        g_return_if_fail (GTK_SOURCE_IS_VIEW (view));
 
        show = show != FALSE;
 
-       if (show == priv->show_line_numbers)
+       if (show == view->priv->show_line_numbers)
        {
                return;
        }
 
-       if (priv->line_renderer == NULL)
+       if (view->priv->line_renderer == NULL)
        {
                GtkSourceGutter *gutter;
 
                gutter = gtk_source_view_get_gutter (view, GTK_TEXT_WINDOW_LEFT);
 
-               priv->line_renderer = _gtk_source_gutter_renderer_lines_new ();
-               g_object_set (priv->line_renderer,
+               view->priv->line_renderer = gtk_source_gutter_renderer_lines_new ();
+               g_object_set (view->priv->line_renderer,
                              "alignment-mode", GTK_SOURCE_GUTTER_RENDERER_ALIGNMENT_MODE_FIRST,
                              "yalign", 0.5,
                              "xalign", 1.0,
@@ -2962,106 +2747,23 @@ gtk_source_view_set_show_line_numbers (GtkSourceView *view,
                              NULL);
 
                gtk_source_gutter_insert (gutter,
-                                         priv->line_renderer,
+                                         view->priv->line_renderer,
                                          GTK_SOURCE_VIEW_GUTTER_POSITION_LINES);
        }
 
-       gtk_source_gutter_renderer_set_visible (priv->line_renderer, show);
-       priv->show_line_numbers = show;
+       gtk_widget_set_visible (GTK_WIDGET (view->priv->line_renderer), show);
+       view->priv->show_line_numbers = show;
 
        g_object_notify (G_OBJECT (view), "show_line_numbers");
 }
 
-/**
- * gtk_source_view_get_show_line_marks:
- * @view: a #GtkSourceView.
- *
- * Returns whether line marks are displayed beside the text.
- *
- * Return value: %TRUE if the line marks are displayed.
- *
- * Since: 2.2
- */
-gboolean
-gtk_source_view_get_show_line_marks (GtkSourceView *view)
-{
-       GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
-
-       g_return_val_if_fail (GTK_SOURCE_IS_VIEW (view), FALSE);
-
-       return priv->show_line_marks;
-}
-
-static void
-gutter_renderer_marks_activate (GtkSourceGutterRenderer *renderer,
-                                GtkTextIter             *iter,
-                                const GdkRectangle      *area,
-                                GdkEvent                *event,
-                                GtkSourceView           *view)
-{
-       g_signal_emit (view,
-                      signals[LINE_MARK_ACTIVATED],
-                      0,
-                      iter,
-                      event);
-}
-
-/**
- * gtk_source_view_set_show_line_marks:
- * @view: a #GtkSourceView.
- * @show: whether line marks should be displayed.
- *
- * If %TRUE line marks will be displayed beside the text.
- *
- * Since: 2.2
- */
-void
-gtk_source_view_set_show_line_marks (GtkSourceView *view,
-                                     gboolean       show)
-{
-       GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
-
-       g_return_if_fail (GTK_SOURCE_IS_VIEW (view));
-
-       show = show != FALSE;
-
-       if (show == priv->show_line_marks)
-       {
-               return;
-       }
-
-       if (priv->marks_renderer == NULL)
-       {
-               GtkSourceGutter *gutter;
-
-               gutter = gtk_source_view_get_gutter (view, GTK_TEXT_WINDOW_LEFT);
-
-               priv->marks_renderer = gtk_source_gutter_renderer_marks_new ();
-
-               gtk_source_gutter_insert (gutter,
-                                         priv->marks_renderer,
-                                         GTK_SOURCE_VIEW_GUTTER_POSITION_MARKS);
-
-               g_signal_connect (priv->marks_renderer,
-                                 "activate",
-                                 G_CALLBACK (gutter_renderer_marks_activate),
-                                 view);
-       }
-
-       gtk_source_gutter_renderer_set_visible (priv->marks_renderer, show);
-       priv->show_line_marks = show;
-
-       g_object_notify (G_OBJECT (view), "show_line_marks");
-}
-
 static gboolean
 set_tab_stops_internal (GtkSourceView *view)
 {
-       GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
        PangoTabArray *tab_array;
        gint real_tab_width;
 
-       real_tab_width = calculate_real_tab_width (view, priv->tab_width, ' ');
+       real_tab_width = calculate_real_tab_width (view, view->priv->tab_width, ' ');
 
        if (real_tab_width < 0)
        {
@@ -3073,7 +2775,7 @@ set_tab_stops_internal (GtkSourceView *view)
 
        gtk_text_view_set_tabs (GTK_TEXT_VIEW (view),
                                tab_array);
-       priv->tabs_set = TRUE;
+       view->priv->tabs_set = TRUE;
 
        pango_tab_array_free (tab_array);
 
@@ -3091,21 +2793,20 @@ set_tab_stops_internal (GtkSourceView *view)
  */
 void
 gtk_source_view_set_tab_width (GtkSourceView *view,
-                               guint          width)
+                              guint          width)
 {
-       GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
        guint save_width;
 
        g_return_if_fail (GTK_SOURCE_VIEW (view));
        g_return_if_fail (0 < width && width <= MAX_TAB_WIDTH);
 
-       if (priv->tab_width == width)
+       if (view->priv->tab_width == width)
        {
                return;
        }
 
-       save_width = priv->tab_width;
-       priv->tab_width = width;
+       save_width = view->priv->tab_width;
+       view->priv->tab_width = width;
        if (set_tab_stops_internal (view))
        {
                g_object_notify (G_OBJECT (view), "tab-width");
@@ -3113,7 +2814,7 @@ gtk_source_view_set_tab_width (GtkSourceView *view,
        else
        {
                g_warning ("Impossible to set tab width.");
-               priv->tab_width = save_width;
+               view->priv->tab_width = save_width;
        }
 }
 
@@ -3128,11 +2829,9 @@ gtk_source_view_set_tab_width (GtkSourceView *view,
 guint
 gtk_source_view_get_tab_width (GtkSourceView *view)
 {
-       GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
-
        g_return_val_if_fail (GTK_SOURCE_IS_VIEW (view), DEFAULT_TAB_WIDTH);
 
-       return priv->tab_width;
+       return view->priv->tab_width;
 }
 
 /**
@@ -3163,16 +2862,14 @@ gtk_source_view_get_tab_width (GtkSourceView *view)
  */
 void
 gtk_source_view_set_indent_width (GtkSourceView *view,
-                                  gint           width)
+                                 gint           width)
 {
-       GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
-
        g_return_if_fail (GTK_SOURCE_VIEW (view));
        g_return_if_fail (width == -1 || (0 < width && width <= MAX_INDENT_WIDTH));
 
-       if (priv->indent_width != width)
+       if (view->priv->indent_width != width)
        {
-               priv->indent_width = width;
+               view->priv->indent_width = width;
                g_object_notify (G_OBJECT (view), "indent-width");
        }
 }
@@ -3189,16 +2886,14 @@ gtk_source_view_set_indent_width (GtkSourceView *view,
 gint
 gtk_source_view_get_indent_width (GtkSourceView *view)
 {
-       GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
-
        g_return_val_if_fail (GTK_SOURCE_IS_VIEW (view), 0);
 
-       return priv->indent_width;
+       return view->priv->indent_width;
 }
 
 static gchar *
 compute_indentation (GtkSourceView *view,
-                     GtkTextIter   *cur)
+                    GtkTextIter   *cur)
 {
        GtkTextIter start;
        GtkTextIter end;
@@ -3235,16 +2930,14 @@ compute_indentation (GtkSourceView *view,
 static guint
 get_real_indent_width (GtkSourceView *view)
 {
-       GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
-
-       return priv->indent_width < 0 ?
-              priv->tab_width :
-              (guint) priv->indent_width;
+       return view->priv->indent_width < 0 ?
+              view->priv->tab_width :
+              (guint) view->priv->indent_width;
 }
 
 static gchar *
 get_indent_string (guint tabs,
-                   guint spaces)
+                  guint spaces)
 {
        gchar *str;
 
@@ -3278,10 +2971,9 @@ get_indent_string (guint tabs,
  */
 void
 gtk_source_view_indent_lines (GtkSourceView *view,
-                              GtkTextIter   *start,
-                              GtkTextIter   *end)
+                             GtkTextIter   *start,
+                             GtkTextIter   *end)
 {
-       GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
        GtkTextBuffer *buf;
        gboolean bracket_hl;
        GtkTextMark *start_mark, *end_mark;
@@ -3291,9 +2983,9 @@ gtk_source_view_indent_lines (GtkSourceView *view,
        guint spaces = 0;
        gint i;
 
-       if (priv->completion != NULL)
+       if (view->priv->completion != NULL)
        {
-               gtk_source_completion_block_interactive (priv->completion);
+               gtk_source_completion_block_interactive (view->priv->completion);
        }
 
        buf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
@@ -3313,20 +3005,20 @@ gtk_source_view_indent_lines (GtkSourceView *view,
                end_line--;
        }
 
-       if (priv->insert_spaces)
+       if (view->priv->insert_spaces)
        {
                spaces = get_real_indent_width (view);
 
                tab_buffer = g_strnfill (spaces, ' ');
        }
-       else if (priv->indent_width > 0 &&
-                priv->indent_width != (gint)priv->tab_width)
+       else if (view->priv->indent_width > 0 &&
+                view->priv->indent_width != (gint)view->priv->tab_width)
        {
                guint indent_width;
 
                indent_width = get_real_indent_width (view);
-               spaces = indent_width % priv->tab_width;
-               tabs = indent_width / priv->tab_width;
+               spaces = indent_width % view->priv->tab_width;
+               tabs = indent_width / view->priv->tab_width;
 
                tab_buffer = get_indent_string (tabs, spaces);
        }
@@ -3369,9 +3061,9 @@ gtk_source_view_indent_lines (GtkSourceView *view,
                /* if tabs are allowed try to merge the spaces
                 * with the tab we are going to insert (if any) */
                iter2 = iter;
-               while (!priv->insert_spaces &&
+               while (!view->priv->insert_spaces &&
                       (gtk_text_iter_get_char (&iter2) == ' ') &&
-                       replaced_spaces < priv->tab_width)
+                       replaced_spaces < view->priv->tab_width)
                {
                        ++replaced_spaces;
 
@@ -3383,8 +3075,8 @@ gtk_source_view_indent_lines (GtkSourceView *view,
                        gchar *indent_buf;
                        guint t, s;
 
-                       t = tabs + (spaces + replaced_spaces) / priv->tab_width;
-                       s = (spaces + replaced_spaces) % priv->tab_width;
+                       t = tabs + (spaces + replaced_spaces) / view->priv->tab_width;
+                       s = (spaces + replaced_spaces) % view->priv->tab_width;
                        indent_buf = get_indent_string (t, s);
 
                        gtk_text_buffer_delete (buf, &iter, &iter2);
@@ -3404,9 +3096,9 @@ gtk_source_view_indent_lines (GtkSourceView *view,
 
        gtk_source_buffer_set_highlight_matching_brackets (GTK_SOURCE_BUFFER (buf), bracket_hl);
 
-       if (priv->completion != NULL)
+       if (view->priv->completion != NULL)
        {
-               gtk_source_completion_unblock_interactive (priv->completion);
+               gtk_source_completion_unblock_interactive (view->priv->completion);
        }
 
        gtk_text_view_scroll_mark_onscreen (GTK_TEXT_VIEW (view),
@@ -3433,10 +3125,9 @@ gtk_source_view_indent_lines (GtkSourceView *view,
  */
 void
 gtk_source_view_unindent_lines (GtkSourceView *view,
-                                GtkTextIter   *start,
-                                GtkTextIter   *end)
+                               GtkTextIter   *start,
+                               GtkTextIter   *end)
 {
-       GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
        GtkTextBuffer *buf;
        gboolean bracket_hl;
        GtkTextMark *start_mark, *end_mark;
@@ -3445,9 +3136,9 @@ gtk_source_view_unindent_lines (GtkSourceView *view,
        gint indent_width;
        gint i;
 
-       if (priv->completion != NULL)
+       if (view->priv->completion != NULL)
        {
-               gtk_source_completion_block_interactive (priv->completion);
+               gtk_source_completion_block_interactive (view->priv->completion);
        }
 
        buf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
@@ -3467,7 +3158,7 @@ gtk_source_view_unindent_lines (GtkSourceView *view,
                end_line--;
        }
 
-       tab_width = priv->tab_width;
+       tab_width = view->priv->tab_width;
        indent_width = get_real_indent_width (view);
 
        gtk_text_buffer_begin_user_action (buf);
@@ -3517,9 +3208,9 @@ gtk_source_view_unindent_lines (GtkSourceView *view,
 
        gtk_source_buffer_set_highlight_matching_brackets (GTK_SOURCE_BUFFER (buf), bracket_hl);
 
-       if (priv->completion != NULL)
+       if (view->priv->completion != NULL)
        {
-               gtk_source_completion_unblock_interactive (priv->completion);
+               gtk_source_completion_unblock_interactive (view->priv->completion);
        }
 
        gtk_text_view_scroll_mark_onscreen (GTK_TEXT_VIEW (view),
@@ -3535,14 +3226,13 @@ gtk_source_view_unindent_lines (GtkSourceView *view,
 
 static gint
 get_line_offset_in_equivalent_spaces (GtkSourceView *view,
-                                      GtkTextIter   *iter)
+                                     GtkTextIter   *iter)
 {
-       GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
        GtkTextIter i;
        gint tab_width;
        gint n = 0;
 
-       tab_width = priv->tab_width;
+       tab_width = view->priv->tab_width;
 
        i = *iter;
        gtk_text_iter_set_line_offset (&i, 0);
@@ -3569,15 +3259,14 @@ get_line_offset_in_equivalent_spaces (GtkSourceView *view,
 
 static void
 insert_tab_or_spaces (GtkSourceView *view,
-                      GtkTextIter   *start,
-                      GtkTextIter   *end)
+                     GtkTextIter   *start,
+                     GtkTextIter   *end)
 {
-       GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
        GtkTextBuffer *buf;
        gchar *tab_buf;
        gint cursor_offset = 0;
 
-       if (priv->insert_spaces)
+       if (view->priv->insert_spaces)
        {
                gint indent_width;
                gint pos;
@@ -3591,8 +3280,8 @@ insert_tab_or_spaces (GtkSourceView *view,
 
                tab_buf = g_strnfill (spaces, ' ');
        }
-       else if (priv->indent_width > 0 &&
-                priv->indent_width != (gint)priv->tab_width)
+       else if (view->priv->indent_width > 0 &&
+                view->priv->indent_width != (gint)view->priv->tab_width)
        {
                GtkTextIter iter;
                gint i;
@@ -3606,7 +3295,7 @@ insert_tab_or_spaces (GtkSourceView *view,
                gint tabs;
                gint spaces;
 
-               tab_width = priv->tab_width;
+               tab_width = view->priv->tab_width;
                indent_width = get_real_indent_width (view);
 
                /* CHECK: is this a performance problem? */
@@ -3681,7 +3370,7 @@ insert_tab_or_spaces (GtkSourceView *view,
 
 static void
 gtk_source_view_move_words (GtkSourceView *view,
-                            gint           step)
+                           gint           step)
 {
        GtkTextBuffer *buf;
        GtkTextIter s, e, ns, ne;
@@ -3852,7 +3541,7 @@ remove_trailing_newline (GtkTextBuffer *buffer)
 
 static void
 gtk_source_view_move_lines (GtkSourceView *view,
-                            gboolean       down)
+                           gboolean       down)
 {
        GtkTextBuffer *buffer;
        GtkTextIter start;
@@ -3954,7 +3643,6 @@ gtk_source_view_move_lines (GtkSourceView *view,
 static gboolean
 do_smart_backspace (GtkSourceView *view)
 {
-       GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
        GtkTextBuffer *buffer;
        gboolean default_editable;
        GtkTextIter insert;
@@ -3963,7 +3651,7 @@ do_smart_backspace (GtkSourceView *view)
        guint visual_column;
        gint indent_width;
 
-       buffer = GTK_TEXT_BUFFER (priv->source_buffer);
+       buffer = GTK_TEXT_BUFFER (view->priv->source_buffer);
        default_editable = gtk_text_view_get_editable (GTK_TEXT_VIEW (view));
 
        if (gtk_text_buffer_get_selection_bounds (buffer, &insert, &end))
@@ -3979,10 +3667,10 @@ do_smart_backspace (GtkSourceView *view)
        }
 
        visual_column = gtk_source_view_get_visual_column (view, &insert);
-       indent_width = priv->indent_width;
+       indent_width = view->priv->indent_width;
        if (indent_width <= 0)
        {
-               indent_width = priv->tab_width;
+               indent_width = view->priv->tab_width;
        }
 
        g_return_val_if_fail (indent_width > 0, FALSE);
@@ -4027,14 +3715,13 @@ do_smart_backspace (GtkSourceView *view)
 static gboolean
 do_ctrl_backspace (GtkSourceView *view)
 {
-       GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
        GtkTextBuffer *buffer;
        GtkTextIter insert;
        GtkTextIter end;
        GtkTextIter leading_end;
        gboolean default_editable;
 
-       buffer = GTK_TEXT_BUFFER (priv->source_buffer);
+       buffer = GTK_TEXT_BUFFER (view->priv->source_buffer);
        default_editable = gtk_text_view_get_editable (GTK_TEXT_VIEW (view));
 
        if (gtk_text_buffer_get_selection_bounds (buffer, &insert, &end))
@@ -4069,11 +3756,12 @@ do_ctrl_backspace (GtkSourceView *view)
 }
 
 static gboolean
-gtk_source_view_key_press_event (GtkWidget   *widget,
-                                 GdkEventKey *event)
+gtk_source_view_key_pressed (GtkSourceView         *view,
+                            guint                  keyval,
+                            guint                  keycode,
+                            guint                  state,
+                            GtkEventControllerKey *controller)
 {
-       GtkSourceView *view = GTK_SOURCE_VIEW (widget);
-       GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
        GtkTextBuffer *buf;
        GtkTextIter cur;
        GtkTextMark *mark;
@@ -4081,22 +3769,22 @@ gtk_source_view_key_press_event (GtkWidget   *widget,
        gint key;
        gboolean editable;
 
-       buf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (widget));
+       buf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
 
-       editable = gtk_text_view_get_editable (GTK_TEXT_VIEW (widget));
+       editable = gtk_text_view_get_editable (GTK_TEXT_VIEW (view));
 
        /* Be careful when testing for modifier state equality:
         * caps lock, num lock,etc need to be taken into account */
        modifiers = gtk_accelerator_get_default_mod_mask ();
 
-       key = event->keyval;
+       key = keyval;
 
        mark = gtk_text_buffer_get_insert (buf);
        gtk_text_buffer_get_iter_at_mark (buf, &cur, mark);
 
        if ((key == GDK_KEY_Return || key == GDK_KEY_KP_Enter) &&
-           !(event->state & GDK_SHIFT_MASK) &&
-           priv->auto_indent)
+           !(state & GDK_SHIFT_MASK) &&
+           view->priv->auto_indent)
        {
                /* Auto-indent means that when you press ENTER at the end of a
                 * line, the new line is automatically indented at the same
@@ -4110,6 +3798,7 @@ gtk_source_view_key_press_event (GtkWidget   *widget,
 
                if (indent != NULL)
                {
+#if 0
                        /* Allow input methods to internally handle a key press event.
                         * If this function returns TRUE, then no further processing should be done
                         * for this keystroke. */
@@ -4118,6 +3807,7 @@ gtk_source_view_key_press_event (GtkWidget   *widget,
                                g_free (indent);
                                return GDK_EVENT_STOP;
                        }
+#endif
 
                        /* Delete any selected text to preserve behavior without auto-indent */
                        gtk_text_buffer_delete_selection (buf,
@@ -4135,8 +3825,7 @@ gtk_source_view_key_press_event (GtkWidget   *widget,
                        gtk_text_buffer_insert (buf, &cur, indent, strlen (indent));
                        g_free (indent);
                        gtk_text_buffer_end_user_action (buf);
-                       gtk_text_view_scroll_mark_onscreen (GTK_TEXT_VIEW (widget),
-                                                           mark);
+                       gtk_text_view_scroll_mark_onscreen (GTK_TEXT_VIEW (view), mark);
                        return GDK_EVENT_STOP;
                }
        }
@@ -4145,8 +3834,8 @@ gtk_source_view_key_press_event (GtkWidget   *widget,
         * with shift+tab key is GDK_ISO_Left_Tab (yay! on win32 and mac too!)
         */
        if ((key == GDK_KEY_Tab || key == GDK_KEY_KP_Tab || key == GDK_KEY_ISO_Left_Tab) &&
-           ((event->state & modifiers) == 0 ||
-            (event->state & modifiers) == GDK_SHIFT_MASK) &&
+           ((state & modifiers) == 0 ||
+            (state & modifiers) == GDK_SHIFT_MASK) &&
            editable &&
            gtk_text_view_get_accepts_tab (GTK_TEXT_VIEW (view)))
        {
@@ -4155,10 +3844,10 @@ gtk_source_view_key_press_event (GtkWidget   *widget,
 
                has_selection = gtk_text_buffer_get_selection_bounds (buf, &s, &e);
 
-               if (priv->indent_on_tab)
+               if (view->priv->indent_on_tab)
                {
                        /* shift+tab: always unindent */
-                       if (event->state & GDK_SHIFT_MASK)
+                       if (state & GDK_SHIFT_MASK)
                        {
                                _gtk_source_buffer_save_and_clear_selection (GTK_SOURCE_BUFFER (buf));
                                gtk_source_view_unindent_lines (view, &s, &e);
@@ -4187,14 +3876,14 @@ gtk_source_view_key_press_event (GtkWidget   *widget,
 
        if (key == GDK_KEY_BackSpace)
        {
-               if ((event->state & modifiers) == 0)
+               if ((state & modifiers) == 0)
                {
-                       if (priv->smart_backspace && do_smart_backspace (view))
+                       if (view->priv->smart_backspace && do_smart_backspace (view))
                        {
                                return GDK_EVENT_STOP;
                        }
                }
-               else if ((event->state & modifiers) == GDK_CONTROL_MASK)
+               else if ((state & modifiers) == GDK_CONTROL_MASK)
                {
                        if (do_ctrl_backspace (view))
                        {
@@ -4203,7 +3892,7 @@ gtk_source_view_key_press_event (GtkWidget   *widget,
                }
        }
 
-       return GTK_WIDGET_CLASS (gtk_source_view_parent_class)->key_press_event (widget, event);
+       return GDK_EVENT_PROPAGATE;
 }
 
 /**
@@ -4217,11 +3906,9 @@ gtk_source_view_key_press_event (GtkWidget   *widget,
 gboolean
 gtk_source_view_get_auto_indent (GtkSourceView *view)
 {
-       GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
-
        g_return_val_if_fail (GTK_SOURCE_IS_VIEW (view), FALSE);
 
-       return priv->auto_indent;
+       return view->priv->auto_indent;
 }
 
 /**
@@ -4238,17 +3925,15 @@ gtk_source_view_get_auto_indent (GtkSourceView *view)
  */
 void
 gtk_source_view_set_auto_indent (GtkSourceView *view,
-                                 gboolean       enable)
+                                gboolean       enable)
 {
-       GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
-
        g_return_if_fail (GTK_SOURCE_IS_VIEW (view));
 
        enable = enable != FALSE;
 
-       if (priv->auto_indent != enable)
+       if (view->priv->auto_indent != enable)
        {
-               priv->auto_indent = enable;
+               view->priv->auto_indent = enable;
                g_object_notify (G_OBJECT (view), "auto_indent");
        }
 }
@@ -4265,11 +3950,9 @@ gtk_source_view_set_auto_indent (GtkSourceView *view,
 gboolean
 gtk_source_view_get_insert_spaces_instead_of_tabs (GtkSourceView *view)
 {
-       GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
-
        g_return_val_if_fail (GTK_SOURCE_IS_VIEW (view), FALSE);
 
-       return priv->insert_spaces;
+       return view->priv->insert_spaces;
 }
 
 /**
@@ -4283,17 +3966,15 @@ gtk_source_view_get_insert_spaces_instead_of_tabs (GtkSourceView *view)
  */
 void
 gtk_source_view_set_insert_spaces_instead_of_tabs (GtkSourceView *view,
-                                                   gboolean       enable)
+                                                  gboolean       enable)
 {
-       GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
-
        g_return_if_fail (GTK_SOURCE_IS_VIEW (view));
 
        enable = enable != FALSE;
 
-       if (priv->insert_spaces != enable)
+       if (view->priv->insert_spaces != enable)
        {
-               priv->insert_spaces = enable;
+               view->priv->insert_spaces = enable;
                g_object_notify (G_OBJECT (view), "insert_spaces_instead_of_tabs");
        }
 }
@@ -4310,11 +3991,9 @@ gtk_source_view_set_insert_spaces_instead_of_tabs (GtkSourceView *view,
 gboolean
 gtk_source_view_get_indent_on_tab (GtkSourceView *view)
 {
-       GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
-
        g_return_val_if_fail (GTK_SOURCE_IS_VIEW (view), FALSE);
 
-       return priv->indent_on_tab;
+       return view->priv->indent_on_tab;
 }
 
 /**
@@ -4334,82 +4013,59 @@ gtk_source_view_get_indent_on_tab (GtkSourceView *view)
  */
 void
 gtk_source_view_set_indent_on_tab (GtkSourceView *view,
-                                   gboolean       enable)
+                                  gboolean       enable)
 {
-       GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
-
        g_return_if_fail (GTK_SOURCE_IS_VIEW (view));
 
        enable = enable != FALSE;
 
-       if (priv->indent_on_tab != enable)
+       if (view->priv->indent_on_tab != enable)
        {
-               priv->indent_on_tab = enable;
+               view->priv->indent_on_tab = enable;
                g_object_notify (G_OBJECT (view), "indent_on_tab");
        }
 }
 
+#if 0
 static void
 view_dnd_drop (GtkTextView      *view,
-               GdkDragContext   *context,
-               gint              x,
-               gint              y,
-               GtkSelectionData *selection_data,
-               guint             info,
-               guint             timestamp,
-               gpointer          data)
+              GdkDragContext   *context,
+              gint              x,
+              gint              y,
+              GtkSelectionData *selection_data,
+              guint             info,
+              guint             timestamp,
+              gpointer          data)
 {
 
        GtkTextIter iter;
 
        if (info == TARGET_COLOR)
        {
-               GdkRGBA rgba;
+               guint16 *vals;
                gchar string[] = "#000000";
                gint buffer_x;
                gint buffer_y;
                gint length = gtk_selection_data_get_length (selection_data);
-               guint format;
 
                if (length < 0)
                {
                        return;
                }
 
-               format = gtk_selection_data_get_format (selection_data);
-
-               if (format == 8 && length == 4)
-               {
-                       guint8 *vals;
-
-                       vals = (gpointer) gtk_selection_data_get_data (selection_data);
-
-                       rgba.red = vals[0] / 256.0;
-                       rgba.green = vals[1] / 256.0;
-                       rgba.blue = vals[2] / 256.0;
-                       rgba.alpha = 1.0;
-               }
-               else if (format == 16 && length == 8)
-               {
-                       guint16 *vals;
-
-                       vals = (gpointer) gtk_selection_data_get_data (selection_data);
-
-                       rgba.red = vals[0] / 65535.0;
-                       rgba.green = vals[1] / 65535.0;
-                       rgba.blue = vals[2] / 65535.0;
-                       rgba.alpha = 1.0;
-               }
-               else
+               if (gtk_selection_data_get_format (selection_data) != 16 || length != 8)
                {
                        g_warning ("Received invalid color data\n");
                        return;
                }
 
-               g_snprintf (string, sizeof string, "#%02X%02X%02X",
-                           (gint)(rgba.red * 256),
-                           (gint)(rgba.green * 256),
-                           (gint)(rgba.blue * 256));
+               vals = (gpointer) gtk_selection_data_get_data (selection_data);
+
+               vals[0] /= 256;
+               vals[1] /= 256;
+               vals[2] /= 256;
+
+               g_snprintf (string, sizeof (string), "#%02X%02X%02X", vals[0], vals[1], vals[2]);
 
                gtk_text_view_window_to_buffer_coords (view,
                                                       GTK_TEXT_WINDOW_TEXT,
@@ -4438,6 +4094,7 @@ view_dnd_drop (GtkTextView      *view,
                return;
        }
 }
+#endif
 
 /**
  * gtk_source_view_get_highlight_current_line:
@@ -4450,11 +4107,9 @@ view_dnd_drop (GtkTextView      *view,
 gboolean
 gtk_source_view_get_highlight_current_line (GtkSourceView *view)
 {
-       GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
-
        g_return_val_if_fail (GTK_SOURCE_IS_VIEW (view), FALSE);
 
-       return priv->highlight_current_line;
+       return view->priv->highlight_current_line;
 }
 
 /**
@@ -4466,19 +4121,17 @@ gtk_source_view_get_highlight_current_line (GtkSourceView *view)
  */
 void
 gtk_source_view_set_highlight_current_line (GtkSourceView *view,
-                                            gboolean       highlight)
+                                           gboolean       highlight)
 {
-       GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
-
        g_return_if_fail (GTK_SOURCE_IS_VIEW (view));
 
        highlight = highlight != FALSE;
 
-       if (priv->highlight_current_line != highlight)
+       if (view->priv->highlight_current_line != highlight)
        {
-               priv->highlight_current_line = highlight;
+               view->priv->highlight_current_line = highlight;
 
-               gtk_widget_queue_draw (GTK_WIDGET (view));
+               gtk_source_view_queue_draw (view);
 
                g_object_notify (G_OBJECT (view), "highlight_current_line");
        }
@@ -4495,11 +4148,9 @@ gtk_source_view_set_highlight_current_line (GtkSourceView *view,
 gboolean
 gtk_source_view_get_show_right_margin (GtkSourceView *view)
 {
-       GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
-
        g_return_val_if_fail (GTK_SOURCE_IS_VIEW (view), FALSE);
 
-       return priv->show_right_margin;
+       return view->priv->show_right_margin;
 }
 
 /**
@@ -4511,19 +4162,17 @@ gtk_source_view_get_show_right_margin (GtkSourceView *view)
  */
 void
 gtk_source_view_set_show_right_margin (GtkSourceView *view,
-                                       gboolean       show)
+                                      gboolean       show)
 {
-       GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
-
        g_return_if_fail (GTK_SOURCE_IS_VIEW (view));
 
        show = show != FALSE;
 
-       if (priv->show_right_margin != show)
+       if (view->priv->show_right_margin != show)
        {
-               priv->show_right_margin = show;
+               view->priv->show_right_margin = show;
 
-               gtk_widget_queue_draw (GTK_WIDGET (view));
+               gtk_source_view_queue_draw (view);
 
                g_object_notify (G_OBJECT (view), "show-right-margin");
        }
@@ -4540,11 +4189,9 @@ gtk_source_view_set_show_right_margin (GtkSourceView *view,
 guint
 gtk_source_view_get_right_margin_position (GtkSourceView *view)
 {
-       GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
-
        g_return_val_if_fail (GTK_SOURCE_IS_VIEW (view), DEFAULT_RIGHT_MARGIN_POSITION);
 
-       return priv->right_margin_pos;
+       return view->priv->right_margin_pos;
 }
 
 /**
@@ -4556,19 +4203,17 @@ gtk_source_view_get_right_margin_position (GtkSourceView *view)
  */
 void
 gtk_source_view_set_right_margin_position (GtkSourceView *view,
-                                           guint          pos)
+                                          guint          pos)
 {
-       GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
-
        g_return_if_fail (GTK_SOURCE_IS_VIEW (view));
        g_return_if_fail (1 <= pos && pos <= MAX_RIGHT_MARGIN_POSITION);
 
-       if (priv->right_margin_pos != pos)
+       if (view->priv->right_margin_pos != pos)
        {
-               priv->right_margin_pos = pos;
-               priv->cached_right_margin_pos = -1;
+               view->priv->right_margin_pos = pos;
+               view->priv->cached_right_margin_pos = -1;
 
-               gtk_widget_queue_draw (GTK_WIDGET (view));
+               gtk_source_view_queue_draw (view);
 
                g_object_notify (G_OBJECT (view), "right-margin-position");
        }
@@ -4588,15 +4233,13 @@ void
 gtk_source_view_set_smart_backspace (GtkSourceView *view,
                                      gboolean       smart_backspace)
 {
-       GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
-
        g_return_if_fail (GTK_SOURCE_IS_VIEW (view));
 
        smart_backspace = smart_backspace != FALSE;
 
-       if (smart_backspace != priv->smart_backspace)
+       if (smart_backspace != view->priv->smart_backspace)
        {
-               priv->smart_backspace = smart_backspace;
+               view->priv->smart_backspace = smart_backspace;
                g_object_notify (G_OBJECT (view), "smart-backspace");
        }
 }
@@ -4615,11 +4258,9 @@ gtk_source_view_set_smart_backspace (GtkSourceView *view,
 gboolean
 gtk_source_view_get_smart_backspace (GtkSourceView *view)
 {
-       GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
-
        g_return_val_if_fail (GTK_SOURCE_IS_VIEW (view), FALSE);
 
-       return priv->smart_backspace;
+       return view->priv->smart_backspace;
 }
 
 /**
@@ -4632,15 +4273,13 @@ gtk_source_view_get_smart_backspace (GtkSourceView *view)
  */
 void
 gtk_source_view_set_smart_home_end (GtkSourceView             *view,
-                                    GtkSourceSmartHomeEndType  smart_home_end)
+                                   GtkSourceSmartHomeEndType  smart_home_end)
 {
-       GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
-
        g_return_if_fail (GTK_SOURCE_IS_VIEW (view));
 
-       if (priv->smart_home_end != smart_home_end)
+       if (view->priv->smart_home_end != smart_home_end)
        {
-               priv->smart_home_end = smart_home_end;
+               view->priv->smart_home_end = smart_home_end;
                g_object_notify (G_OBJECT (view), "smart_home_end");
        }
 }
@@ -4657,11 +4296,9 @@ gtk_source_view_set_smart_home_end (GtkSourceView             *view,
 GtkSourceSmartHomeEndType
 gtk_source_view_get_smart_home_end (GtkSourceView *view)
 {
-       GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
-
        g_return_val_if_fail (GTK_SOURCE_IS_VIEW (view), FALSE);
 
-       return priv->smart_home_end;
+       return view->priv->smart_home_end;
 }
 
 /**
@@ -4676,9 +4313,8 @@ gtk_source_view_get_smart_home_end (GtkSourceView *view)
  */
 guint
 gtk_source_view_get_visual_column (GtkSourceView     *view,
-                                   const GtkTextIter *iter)
+                                  const GtkTextIter *iter)
 {
-       GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
        GtkTextIter position;
        guint column;
        guint tab_width;
@@ -4687,7 +4323,7 @@ gtk_source_view_get_visual_column (GtkSourceView     *view,
        g_return_val_if_fail (iter != NULL, 0);
 
        column = 0;
-       tab_width = priv->tab_width;
+       tab_width = view->priv->tab_width;
 
        position = *iter;
        gtk_text_iter_set_line_offset (&position, 0);
@@ -4717,58 +4353,53 @@ gtk_source_view_get_visual_column (GtkSourceView     *view,
 static void
 update_background_pattern_color (GtkSourceView *view)
 {
-       GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
-
-       if (priv->style_scheme == NULL)
+       if (view->priv->style_scheme == NULL)
        {
-               priv->background_pattern_color_set = FALSE;
+               view->priv->background_pattern_color_set = FALSE;
                return;
        }
 
-       priv->background_pattern_color_set =
-               _gtk_source_style_scheme_get_background_pattern_color (priv->style_scheme,
-                                                                      &priv->background_pattern_color);
+       view->priv->background_pattern_color_set =
+               _gtk_source_style_scheme_get_background_pattern_color (view->priv->style_scheme,
+                                                                      &view->priv->background_pattern_color);
 }
 
 static void
 update_current_line_color (GtkSourceView *view)
 {
-       GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
-
-       if (priv->style_scheme == NULL)
+       if (view->priv->style_scheme == NULL)
        {
-               priv->current_line_color_set = FALSE;
+               view->priv->current_line_color_set = FALSE;
                return;
        }
 
-       priv->current_line_color_set =
-               _gtk_source_style_scheme_get_current_line_color (priv->style_scheme,
-                                                                &priv->current_line_color);
+       view->priv->current_line_color_set =
+               _gtk_source_style_scheme_get_current_line_color (view->priv->style_scheme,
+                                                                &view->priv->current_line_color);
 }
 
 static void
 update_right_margin_colors (GtkSourceView *view)
 {
-       GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
        GtkWidget *widget = GTK_WIDGET (view);
 
-       if (priv->right_margin_line_color != NULL)
+       if (view->priv->right_margin_line_color != NULL)
        {
-               gdk_rgba_free (priv->right_margin_line_color);
-               priv->right_margin_line_color = NULL;
+               gdk_rgba_free (view->priv->right_margin_line_color);
+               view->priv->right_margin_line_color = NULL;
        }
 
-       if (priv->right_margin_overlay_color != NULL)
+       if (view->priv->right_margin_overlay_color != NULL)
        {
-               gdk_rgba_free (priv->right_margin_overlay_color);
-               priv->right_margin_overlay_color = NULL;
+               gdk_rgba_free (view->priv->right_margin_overlay_color);
+               view->priv->right_margin_overlay_color = NULL;
        }
 
-       if (priv->style_scheme != NULL)
+       if (view->priv->style_scheme != NULL)
        {
                GtkSourceStyle *style;
 
-               style = _gtk_source_style_scheme_get_right_margin_style (priv->style_scheme);
+               style = _gtk_source_style_scheme_get_right_margin_style (view->priv->style_scheme);
 
                if (style != NULL)
                {
@@ -4785,8 +4416,8 @@ update_right_margin_colors (GtkSourceView *view)
                            color_str != NULL &&
                            gdk_rgba_parse (&color, color_str))
                        {
-                               priv->right_margin_line_color = gdk_rgba_copy (&color);
-                               priv->right_margin_line_color->alpha =
+                               view->priv->right_margin_line_color = gdk_rgba_copy (&color);
+                               view->priv->right_margin_line_color->alpha =
                                        RIGHT_MARGIN_LINE_ALPHA / 255.;
                        }
 
@@ -4802,8 +4433,8 @@ update_right_margin_colors (GtkSourceView *view)
                            color_str != NULL &&
                            gdk_rgba_parse (&color, color_str))
                        {
-                               priv->right_margin_overlay_color = gdk_rgba_copy (&color);
-                               priv->right_margin_overlay_color->alpha =
+                               view->priv->right_margin_overlay_color = gdk_rgba_copy (&color);
+                               view->priv->right_margin_overlay_color->alpha =
                                        RIGHT_MARGIN_OVERLAY_ALPHA / 255.;
                        }
 
@@ -4811,7 +4442,7 @@ update_right_margin_colors (GtkSourceView *view)
                }
        }
 
-       if (priv->right_margin_line_color == NULL)
+       if (view->priv->right_margin_line_color == NULL)
        {
                GtkStyleContext *context;
                GdkRGBA color;
@@ -4819,13 +4450,11 @@ update_right_margin_colors (GtkSourceView *view)
                context = gtk_widget_get_style_context (widget);
                gtk_style_context_save (context);
                gtk_style_context_set_state (context, GTK_STATE_FLAG_NORMAL);
-               gtk_style_context_get_color (context,
-                                            gtk_style_context_get_state (context),
-                                            &color);
+               gtk_style_context_get_color (context, &color);
                gtk_style_context_restore (context);
 
-               priv->right_margin_line_color = gdk_rgba_copy (&color);
-               priv->right_margin_line_color->alpha =
+               view->priv->right_margin_line_color = gdk_rgba_copy (&color);
+               view->priv->right_margin_line_color->alpha =
                        RIGHT_MARGIN_LINE_ALPHA / 255.;
        }
 }
@@ -4833,24 +4462,21 @@ update_right_margin_colors (GtkSourceView *view)
 static void
 update_style (GtkSourceView *view)
 {
-       GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
-
        update_background_pattern_color (view);
        update_current_line_color (view);
        update_right_margin_colors (view);
 
-       if (priv->space_drawer != NULL)
+       if (view->priv->space_drawer != NULL)
        {
-               _gtk_source_space_drawer_update_color (priv->space_drawer, view);
+               _gtk_source_space_drawer_update_color (view->priv->space_drawer, view);
        }
 
-       gtk_widget_queue_draw (GTK_WIDGET (view));
+       gtk_source_view_queue_draw (view);
 }
 
 static void
 gtk_source_view_update_style_scheme (GtkSourceView *view)
 {
-       GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
        GtkTextBuffer *buffer;
        GtkSourceStyleScheme *new_scheme = NULL;
 
@@ -4861,21 +4487,21 @@ gtk_source_view_update_style_scheme (GtkSourceView *view)
                new_scheme = gtk_source_buffer_get_style_scheme (GTK_SOURCE_BUFFER (buffer));
        }
 
-       if (priv->style_scheme == new_scheme)
+       if (view->priv->style_scheme == new_scheme)
        {
                return;
        }
 
-       if (priv->style_scheme != NULL)
+       if (view->priv->style_scheme != NULL)
        {
-               _gtk_source_style_scheme_unapply (priv->style_scheme, view);
+               _gtk_source_style_scheme_unapply (view->priv->style_scheme, view);
        }
 
-       g_set_object (&priv->style_scheme, new_scheme);
+       g_set_object (&view->priv->style_scheme, new_scheme);
 
-       if (priv->style_scheme != NULL)
+       if (view->priv->style_scheme != NULL)
        {
-               _gtk_source_style_scheme_apply (priv->style_scheme, view);
+               _gtk_source_style_scheme_apply (view->priv->style_scheme, view);
        }
 
        update_style (view);
@@ -4885,7 +4511,6 @@ static void
 gtk_source_view_style_updated (GtkWidget *widget)
 {
        GtkSourceView *view = GTK_SOURCE_VIEW (widget);
-       GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
 
        /* Call default handler first. */
        if (GTK_WIDGET_CLASS (gtk_source_view_parent_class)->style_updated != NULL)
@@ -4896,20 +4521,20 @@ gtk_source_view_style_updated (GtkWidget *widget)
        /* Re-set tab stops, but only if we already modified them, i.e.
         * do nothing with good old 8-space tabs.
         */
-       if (priv->tabs_set)
+       if (view->priv->tabs_set)
        {
                set_tab_stops_internal (view);
        }
 
        /* Make sure the margin position is recalculated on next redraw. */
-       priv->cached_right_margin_pos = -1;
+       view->priv->cached_right_margin_pos = -1;
 
        update_style (view);
 }
 
 static MarkCategory *
 mark_category_new (GtkSourceMarkAttributes *attributes,
-                   gint                     priority)
+                  gint                     priority)
 {
        MarkCategory* category = g_slice_new (MarkCategory);
 
@@ -4942,16 +4567,14 @@ mark_category_free (MarkCategory *category)
 GtkSourceCompletion *
 gtk_source_view_get_completion (GtkSourceView *view)
 {
-       GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
-
        g_return_val_if_fail (GTK_SOURCE_IS_VIEW (view), NULL);
 
-       if (priv->completion == NULL)
+       if (view->priv->completion == NULL)
        {
-               priv->completion = _gtk_source_completion_new (view);
+               view->priv->completion = _gtk_source_completion_new (view);
        }
 
-       return priv->completion;
+       return view->priv->completion;
 }
 
 /**
@@ -4970,32 +4593,38 @@ gtk_source_view_get_completion (GtkSourceView *view)
  */
 GtkSourceGutter *
 gtk_source_view_get_gutter (GtkSourceView     *view,
-                            GtkTextWindowType  window_type)
+                           GtkTextWindowType  window_type)
 {
-       GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
-
        g_return_val_if_fail (GTK_SOURCE_IS_VIEW (view), NULL);
        g_return_val_if_fail (window_type == GTK_TEXT_WINDOW_LEFT ||
                              window_type == GTK_TEXT_WINDOW_RIGHT, NULL);
 
        if (window_type == GTK_TEXT_WINDOW_LEFT)
        {
-               if (priv->left_gutter == NULL)
+               if (view->priv->left_gutter == NULL)
                {
-                       priv->left_gutter = _gtk_source_gutter_new (view, window_type);
+                       view->priv->left_gutter = _gtk_source_gutter_new (window_type);
+                       gtk_text_view_set_gutter (GTK_TEXT_VIEW (view),
+                                                 GTK_TEXT_WINDOW_LEFT,
+                                                 GTK_WIDGET (view->priv->left_gutter));
                }
 
-               return priv->left_gutter;
+               return view->priv->left_gutter;
        }
-       else
+       else if (window_type == GTK_TEXT_WINDOW_RIGHT)
        {
-               if (priv->right_gutter == NULL)
+               if (view->priv->right_gutter == NULL)
                {
-                       priv->right_gutter = _gtk_source_gutter_new (view, window_type);
+                       view->priv->right_gutter = _gtk_source_gutter_new (window_type);
+                       gtk_text_view_set_gutter (GTK_TEXT_VIEW (view),
+                                                 GTK_TEXT_WINDOW_RIGHT,
+                                                 GTK_WIDGET (view->priv->right_gutter));
                }
 
-               return priv->right_gutter;
+               return view->priv->right_gutter;
        }
+
+       g_return_val_if_reached (NULL);
 }
 
 /**
@@ -5009,11 +4638,10 @@ gtk_source_view_get_gutter (GtkSourceView     *view,
  */
 void
 gtk_source_view_set_mark_attributes (GtkSourceView           *view,
-                                     const gchar             *category,
-                                     GtkSourceMarkAttributes *attributes,
-                                     gint                     priority)
+                                    const gchar             *category,
+                                    GtkSourceMarkAttributes *attributes,
+                                    gint                     priority)
 {
-       GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
        MarkCategory *mark_category;
 
        g_return_if_fail (GTK_SOURCE_IS_VIEW (view));
@@ -5022,7 +4650,7 @@ gtk_source_view_set_mark_attributes (GtkSourceView           *view,
        g_return_if_fail (priority >= 0);
 
        mark_category = mark_category_new (attributes, priority);
-       g_hash_table_replace (priv->mark_categories,
+       g_hash_table_replace (view->priv->mark_categories,
                              g_strdup (category),
                              mark_category);
 }
@@ -5040,16 +4668,15 @@ gtk_source_view_set_mark_attributes (GtkSourceView           *view,
  */
 GtkSourceMarkAttributes *
 gtk_source_view_get_mark_attributes (GtkSourceView *view,
-                                     const gchar   *category,
-                                     gint          *priority)
+                                    const gchar   *category,
+                                    gint          *priority)
 {
-       GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
        MarkCategory *mark_category;
 
        g_return_val_if_fail (GTK_SOURCE_IS_VIEW (view), NULL);
        g_return_val_if_fail (category != NULL, NULL);
 
-       mark_category = g_hash_table_lookup (priv->mark_categories,
+       mark_category = g_hash_table_lookup (view->priv->mark_categories,
                                             category);
 
        if (mark_category != NULL)
@@ -5076,17 +4703,15 @@ gtk_source_view_get_mark_attributes (GtkSourceView *view,
  */
 void
 gtk_source_view_set_background_pattern (GtkSourceView                  *view,
-                                        GtkSourceBackgroundPatternType  background_pattern)
+                                       GtkSourceBackgroundPatternType  background_pattern)
 {
-       GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
-
        g_return_if_fail (GTK_SOURCE_IS_VIEW (view));
 
-       if (priv->background_pattern != background_pattern)
+       if (view->priv->background_pattern != background_pattern)
        {
-               priv->background_pattern = background_pattern;
+               view->priv->background_pattern = background_pattern;
 
-               gtk_widget_queue_draw (GTK_WIDGET (view));
+               gtk_source_view_queue_draw (view);
 
                g_object_notify (G_OBJECT (view), "background-pattern");
        }
@@ -5105,11 +4730,9 @@ gtk_source_view_set_background_pattern (GtkSourceView                  *view,
 GtkSourceBackgroundPatternType
 gtk_source_view_get_background_pattern (GtkSourceView *view)
 {
-       GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
-
        g_return_val_if_fail (GTK_SOURCE_IS_VIEW (view), GTK_SOURCE_BACKGROUND_PATTERN_TYPE_NONE);
 
-       return priv->background_pattern;
+       return view->priv->background_pattern;
 }
 
 /**
@@ -5126,9 +4749,23 @@ gtk_source_view_get_background_pattern (GtkSourceView *view)
 GtkSourceSpaceDrawer *
 gtk_source_view_get_space_drawer (GtkSourceView *view)
 {
-       GtkSourceViewPrivate *priv = gtk_source_view_get_instance_private (view);
-
        g_return_val_if_fail (GTK_SOURCE_IS_VIEW (view), NULL);
 
-       return priv->space_drawer;
+       return view->priv->space_drawer;
+}
+
+static void
+gtk_source_view_queue_draw (GtkSourceView *view)
+{
+       gtk_widget_queue_draw (GTK_WIDGET (view));
+
+       if (view->priv->left_gutter != NULL)
+       {
+               gtk_widget_queue_draw (GTK_WIDGET (view->priv->left_gutter));
+       }
+
+       if (view->priv->right_gutter != NULL)
+       {
+               gtk_widget_queue_draw (GTK_WIDGET (view->priv->right_gutter));
+       }
 }
diff --git a/gtksourceview/gtksourceview.h b/gtksourceview/gtksourceview.h
index 40ef7e96..3f3eb48b 100644
--- a/gtksourceview/gtksourceview.h
+++ b/gtksourceview/gtksourceview.h
@@ -2,9 +2,9 @@
  *
  * This file is part of GtkSourceView
  *
- * Copyright 2001 Mikael Hermansson <tyan linux se> and
- *                Chris Phelps <chicane reninet com>
- * Copyright 2003 Gustavo Giráldez and Paolo Maggi
+ * Copyright (C) 2001 - Mikael Hermansson <tyan linux se> and
+ *                       Chris Phelps <chicane reninet com>
+ * Copyright (C) 2003 - Gustavo Giráldez and Paolo Maggi
  *
  * GtkSourceView is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -20,7 +20,8 @@
  * along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#pragma once
+#ifndef GTK_SOURCE_VIEW_H
+#define GTK_SOURCE_VIEW_H
 
 #if !defined (GTK_SOURCE_H_INSIDE) && !defined (GTK_SOURCE_COMPILATION)
 #error "Only <gtksourceview/gtksource.h> can be included directly."
@@ -32,7 +33,15 @@
 
 G_BEGIN_DECLS
 
-#define GTK_SOURCE_TYPE_VIEW (gtk_source_view_get_type())
+#define GTK_SOURCE_TYPE_VIEW             (gtk_source_view_get_type ())
+#define GTK_SOURCE_VIEW(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_SOURCE_TYPE_VIEW, 
GtkSourceView))
+#define GTK_SOURCE_VIEW_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_SOURCE_TYPE_VIEW, 
GtkSourceViewClass))
+#define GTK_SOURCE_IS_VIEW(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_SOURCE_TYPE_VIEW))
+#define GTK_SOURCE_IS_VIEW_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_SOURCE_TYPE_VIEW))
+#define GTK_SOURCE_VIEW_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_SOURCE_TYPE_VIEW, 
GtkSourceViewClass))
+
+typedef struct _GtkSourceViewClass GtkSourceViewClass;
+typedef struct _GtkSourceViewPrivate GtkSourceViewPrivate;
 
 /**
  * GtkSourceViewGutterPosition:
@@ -80,123 +89,167 @@ typedef enum _GtkSourceBackgroundPatternType
        GTK_SOURCE_BACKGROUND_PATTERN_TYPE_GRID
 } GtkSourceBackgroundPatternType;
 
-GTK_SOURCE_AVAILABLE_IN_ALL
-G_DECLARE_DERIVABLE_TYPE (GtkSourceView, gtk_source_view, GTK_SOURCE, VIEW, GtkTextView)
+struct _GtkSourceView
+{
+       GtkTextView parent;
+
+       GtkSourceViewPrivate *priv;
+};
 
 struct _GtkSourceViewClass
 {
        GtkTextViewClass parent_class;
 
-       void (*undo)                (GtkSourceView *view);
-       void (*redo)                (GtkSourceView *view);
-       void (*line_mark_activated) (GtkSourceView *view,
-                                    GtkTextIter   *iter,
-                                    GdkEvent      *event);
-       void (*show_completion)     (GtkSourceView *view);
-       void (*move_lines)          (GtkSourceView *view,
-                                    gboolean       down);
-       void (*move_words)          (GtkSourceView *view,
-                                    gint           step);
+       void (*show_completion) (GtkSourceView *view);
+       void (*move_lines) (GtkSourceView *view,
+                           gboolean       down);
+
+       void (*move_words) (GtkSourceView *view,
+                           gint           step);
 
        /*< private >*/
        gpointer _reserved[20];
 };
 
 GTK_SOURCE_AVAILABLE_IN_ALL
-GtkWidget                      *gtk_source_view_new                               (void);
+GType           gtk_source_view_get_type               (void) G_GNUC_CONST;
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-GtkWidget                      *gtk_source_view_new_with_buffer                   (GtkSourceBuffer           
     *buffer);
+GtkWidget      *gtk_source_view_new                    (void);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-void                            gtk_source_view_set_show_line_numbers             (GtkSourceView             
     *view,
-                                                                                   gboolean                  
      show);
+GtkWidget      *gtk_source_view_new_with_buffer        (GtkSourceBuffer *buffer);
+
+GTK_SOURCE_AVAILABLE_IN_ALL
+void            gtk_source_view_set_show_line_numbers  (GtkSourceView   *view,
+                                                        gboolean         show);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-gboolean                        gtk_source_view_get_show_line_numbers             (GtkSourceView             
     *view);
+gboolean        gtk_source_view_get_show_line_numbers  (GtkSourceView   *view);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-void                            gtk_source_view_set_tab_width                     (GtkSourceView             
     *view,
-                                                                                   guint                     
      width);
+void            gtk_source_view_set_tab_width          (GtkSourceView   *view,
+                                                        guint            width);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-guint                           gtk_source_view_get_tab_width                     (GtkSourceView             
     *view);
+guint            gtk_source_view_get_tab_width          (GtkSourceView   *view);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-void                            gtk_source_view_set_indent_width                  (GtkSourceView             
     *view,
-                                                                                   gint                      
      width);
+void            gtk_source_view_set_indent_width       (GtkSourceView   *view,
+                                                        gint             width);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-gint                            gtk_source_view_get_indent_width                  (GtkSourceView             
     *view);
+gint            gtk_source_view_get_indent_width       (GtkSourceView   *view);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-void                            gtk_source_view_set_auto_indent                   (GtkSourceView             
     *view,
-                                                                                   gboolean                  
      enable);
+void            gtk_source_view_set_auto_indent        (GtkSourceView   *view,
+                                                        gboolean         enable);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-gboolean                        gtk_source_view_get_auto_indent                   (GtkSourceView             
     *view);
+gboolean        gtk_source_view_get_auto_indent        (GtkSourceView   *view);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-void                            gtk_source_view_set_insert_spaces_instead_of_tabs (GtkSourceView             
     *view,
-                                                                                   gboolean                  
      enable);
+void            gtk_source_view_set_insert_spaces_instead_of_tabs
+                                                       (GtkSourceView   *view,
+                                                        gboolean         enable);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-gboolean                        gtk_source_view_get_insert_spaces_instead_of_tabs (GtkSourceView             
     *view);
+gboolean        gtk_source_view_get_insert_spaces_instead_of_tabs
+                                                       (GtkSourceView   *view);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-void                            gtk_source_view_set_indent_on_tab                 (GtkSourceView             
     *view,
-                                                                                   gboolean                  
      enable);
+void            gtk_source_view_set_indent_on_tab      (GtkSourceView   *view,
+                                                        gboolean         enable);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-gboolean                        gtk_source_view_get_indent_on_tab                 (GtkSourceView             
     *view);
+gboolean        gtk_source_view_get_indent_on_tab      (GtkSourceView   *view);
+
 GTK_SOURCE_AVAILABLE_IN_3_16
-void                            gtk_source_view_indent_lines                      (GtkSourceView             
     *view,
-                                                                                   GtkTextIter               
     *start,
-                                                                                   GtkTextIter               
     *end);
+void            gtk_source_view_indent_lines           (GtkSourceView   *view,
+                                                        GtkTextIter     *start,
+                                                        GtkTextIter     *end);
+
 GTK_SOURCE_AVAILABLE_IN_3_16
-void                            gtk_source_view_unindent_lines                    (GtkSourceView             
     *view,
-                                                                                   GtkTextIter               
     *start,
-                                                                                   GtkTextIter               
     *end);
-GTK_SOURCE_AVAILABLE_IN_ALL
-void                            gtk_source_view_set_highlight_current_line        (GtkSourceView             
     *view,
-                                                                                   gboolean                  
      highlight);
-GTK_SOURCE_AVAILABLE_IN_ALL
-gboolean                        gtk_source_view_get_highlight_current_line        (GtkSourceView             
     *view);
+void            gtk_source_view_unindent_lines         (GtkSourceView   *view,
+                                                        GtkTextIter     *start,
+                                                        GtkTextIter     *end);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-void                            gtk_source_view_set_show_right_margin             (GtkSourceView             
     *view,
-                                                                                   gboolean                  
      show);
+void            gtk_source_view_set_highlight_current_line
+                                                       (GtkSourceView   *view,
+                                                        gboolean         highlight);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-gboolean                        gtk_source_view_get_show_right_margin             (GtkSourceView             
     *view);
+gboolean        gtk_source_view_get_highlight_current_line
+                                                       (GtkSourceView   *view);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-void                            gtk_source_view_set_right_margin_position         (GtkSourceView             
     *view,
-                                                                                   guint                     
      pos);
+void            gtk_source_view_set_show_right_margin  (GtkSourceView   *view,
+                                                        gboolean         show);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-guint                           gtk_source_view_get_right_margin_position         (GtkSourceView             
     *view);
+gboolean        gtk_source_view_get_show_right_margin  (GtkSourceView   *view);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-void                            gtk_source_view_set_show_line_marks               (GtkSourceView             
     *view,
-                                                                                   gboolean                  
      show);
+void            gtk_source_view_set_right_margin_position
+                                                       (GtkSourceView   *view,
+                                                        guint            pos);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-gboolean                        gtk_source_view_get_show_line_marks               (GtkSourceView             
     *view);
+guint           gtk_source_view_get_right_margin_position
+                                                       (GtkSourceView   *view);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-void                            gtk_source_view_set_mark_attributes               (GtkSourceView             
     *view,
-                                                                                   const gchar               
     *category,
-                                                                                   GtkSourceMarkAttributes   
     *attributes,
-                                                                                   gint                      
      priority);
+void             gtk_source_view_set_mark_attributes    (GtkSourceView           *view,
+                                                         const gchar             *category,
+                                                         GtkSourceMarkAttributes *attributes,
+                                                         gint                     priority);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-GtkSourceMarkAttributes        *gtk_source_view_get_mark_attributes               (GtkSourceView             
     *view,
-                                                                                   const gchar               
     *category,
-                                                                                   gint                      
     *priority);
+GtkSourceMarkAttributes *
+                 gtk_source_view_get_mark_attributes    (GtkSourceView           *view,
+                                                         const gchar             *category,
+                                                         gint                    *priority);
+
 GTK_SOURCE_AVAILABLE_IN_3_18
-void                            gtk_source_view_set_smart_backspace               (GtkSourceView             
     *view,
-                                                                                   gboolean                  
      smart_backspace);
+void            gtk_source_view_set_smart_backspace    (GtkSourceView   *view,
+                                                        gboolean        smart_backspace);
+
 GTK_SOURCE_AVAILABLE_IN_3_18
-gboolean                        gtk_source_view_get_smart_backspace               (GtkSourceView             
     *view);
+gboolean        gtk_source_view_get_smart_backspace    (GtkSourceView   *view);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-void                            gtk_source_view_set_smart_home_end                (GtkSourceView             
     *view,
-                                                                                   GtkSourceSmartHomeEndType 
      smart_home_end);
+void            gtk_source_view_set_smart_home_end     (GtkSourceView             *view,
+                                                        GtkSourceSmartHomeEndType  smart_home_end);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-GtkSourceSmartHomeEndType       gtk_source_view_get_smart_home_end                (GtkSourceView             
     *view);
+GtkSourceSmartHomeEndType
+                gtk_source_view_get_smart_home_end     (GtkSourceView   *view);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-guint                           gtk_source_view_get_visual_column                 (GtkSourceView             
     *view,
-                                                                                   const GtkTextIter         
     *iter);
+guint           gtk_source_view_get_visual_column      (GtkSourceView     *view,
+                                                        const GtkTextIter *iter);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-GtkSourceCompletion            *gtk_source_view_get_completion                    (GtkSourceView             
     *view);
+GtkSourceCompletion *
+                gtk_source_view_get_completion         (GtkSourceView   *view);
+
 GTK_SOURCE_AVAILABLE_IN_ALL
-GtkSourceGutter                *gtk_source_view_get_gutter                        (GtkSourceView             
     *view,
-                                                                                   GtkTextWindowType         
      window_type);
+GtkSourceGutter *gtk_source_view_get_gutter            (GtkSourceView     *view,
+                                                        GtkTextWindowType  window_type);
+
 GTK_SOURCE_AVAILABLE_IN_3_16
-void                            gtk_source_view_set_background_pattern            (GtkSourceView             
     *view,
-                                                                                   
GtkSourceBackgroundPatternType  background_pattern);
+void            gtk_source_view_set_background_pattern (GtkSourceView                  *view,
+                                                         GtkSourceBackgroundPatternType  background_pattern);
+
 GTK_SOURCE_AVAILABLE_IN_3_16
-GtkSourceBackgroundPatternType  gtk_source_view_get_background_pattern            (GtkSourceView             
     *view);
+GtkSourceBackgroundPatternType
+                gtk_source_view_get_background_pattern (GtkSourceView   *view);
+
 GTK_SOURCE_AVAILABLE_IN_3_24
-GtkSourceSpaceDrawer           *gtk_source_view_get_space_drawer                  (GtkSourceView             
     *view);
+GtkSourceSpaceDrawer *
+                gtk_source_view_get_space_drawer       (GtkSourceView   *view);
 
 G_END_DECLS
+
+#endif /* end of GTK_SOURCE_VIEW_H */
diff --git a/gtksourceview/meson.build b/gtksourceview/meson.build
index 3a1e99d3..ea63b500 100644
--- a/gtksourceview/meson.build
+++ b/gtksourceview/meson.build
@@ -25,6 +25,7 @@ core_public_h = files([
   'gtksourceinit.h',
   'gtksourcelanguage.h',
   'gtksourcelanguagemanager.h',
+  'gtksourcelines.h',
   'gtksourcemap.h',
   'gtksourcemark.h',
   'gtksourcemarkattributes.h',
@@ -41,7 +42,6 @@ core_public_h = files([
   'gtksourcestyleschememanager.h',
   'gtksourcetag.h',
   'gtksourcetypes.h',
-  'gtksourceundomanager.h',
   'gtksourceutils.h',
   'gtksourceview.h',
 ])
@@ -65,6 +65,7 @@ core_public_c = files([
   'gtksourceinit.c',
   'gtksourcelanguage.c',
   'gtksourcelanguagemanager.c',
+  'gtksourcelines.c',
   'gtksourcemap.c',
   'gtksourcemark.c',
   'gtksourcemarkattributes.c',
@@ -80,7 +81,6 @@ core_public_c = files([
   'gtksourcestyleschemechooserwidget.c',
   'gtksourcestyleschememanager.c',
   'gtksourcetag.c',
-  'gtksourceundomanager.c',
   'gtksourceutils.c',
   'gtksourceversion.c',
   'gtksourceview.c',
@@ -90,18 +90,16 @@ core_private_c = files([
   'gtksourcebufferinputstream.c',
   'gtksourcebufferinternal.c',
   'gtksourcebufferoutputstream.c',
-  'gtksourcecompletioncontainer.c',
   'gtksourcecompletionmodel.c',
   'gtksourcecontextengine.c',
   'gtksourceengine.c',
   'gtksourcegutterrendererlines.c',
-  'gtksourcegutterrenderermarks.c',
+  # 'gtksourcegutterrenderermarks.c',
   'gtksourceiter.c',
   'gtksourcelanguage-parser-2.c',
   'gtksourcemarkssequence.c',
   'gtksourcepixbufhelper.c',
   'gtksourceregex.c',
-  'gtksourceundomanagerdefault.c',
 ])
 
 core_c_args = [
@@ -146,7 +144,7 @@ core_enums_header = '''
 # error "Only <gtksourceview/gtksource.h> can be included directly."
 #endif
 
-#include "gtksourceversion.h"
+#include <gtksourceview/gtksourceversion.h>
 '''
 
 core_enums = gnome.mkenums_simple('gtksource-enumtypes',
@@ -264,12 +262,12 @@ if generate_gir
       identifier_prefix: 'GtkSource',
         export_packages: [package_string],
               link_with: gtksource_lib,
-               includes: [ 'Gdk-3.0', 'Gtk-3.0' ],
+               includes: [ 'Gtk-4.0' ],
                 install: true,
         install_dir_gir: girdir,
     install_dir_typelib: typelibdir,
              extra_args: [ '--c-include=gtksourceview/gtksource.h',
-                          '--warn-all' ],
+                           '--warn-all' ],
   )
 
   gtksource_dep_sources += [
@@ -289,12 +287,11 @@ if generate_gir
             install: true,
         install_dir: vapidir,
            packages: [ 'atk',
-                       'gdk-3.0',
-                      'gdk-pixbuf-2.0',
-                      'gio-2.0',
-                      'gtk+-3.0',
-                      'pango',
-                      'cairo' ],
+                       'gdk-pixbuf-2.0',
+                       'gio-2.0',
+                       'gtk4',
+                       'pango',
+                       'cairo' ],
     )
   endif
 endif
@@ -311,7 +308,7 @@ gtksource_pc_reqs = [
   'glib-2.0 @0@'.format(glib_req),
   'gobject-2.0 @0@'.format(glib_req),
   'gio-2.0 @0@'.format(glib_req),
-  'gtk+-3.0 @0@'.format(gtk_req),
+  'gtk4 @0@'.format(gtk_req),
 ]
 
 gtksource_pc_private_reqs = []
diff --git a/gtksourceview/quarkset-inline.h b/gtksourceview/quarkset-inline.h
new file mode 100644
index 00000000..acd6e334
--- /dev/null
+++ b/gtksourceview/quarkset-inline.h
@@ -0,0 +1,188 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; coding: utf-8 -*- */
+/*
+ * This file is part of GtkSourceView
+ *
+ * Copyright (C) 2019 Christian Hergert <chergert redhat com>
+ *
+ * GtkSourceView is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * GtkSourceView is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __QUARK_SET_INLINE_H__
+#define __QUARK_SET_INLINE_H__
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+typedef struct _QuarkSet
+{
+       gint32 len;
+       union {
+               GQuark  embed[2];
+               GQuark *alloc;
+       } u;
+} QuarkSet;
+
+static inline gboolean
+quark_set_is_embed (QuarkSet *set)
+{
+       return set->len >= 0;
+}
+
+static inline void
+quark_set_clear (QuarkSet *set)
+{
+       if (set->len < 0)
+       {
+               g_free (set->u.alloc);
+       }
+
+       set->len = 0;
+       set->u.alloc = NULL;
+}
+
+static inline gboolean
+quark_set_contains (QuarkSet *set,
+                    GQuark    quark)
+{
+       GQuark *quarks;
+       guint i;
+       guint len;
+
+       if (set->len == 0)
+       {
+               return FALSE;
+       }
+
+       if (quark_set_is_embed (set))
+       {
+               quarks = set->u.embed;
+               len = set->len;
+       }
+       else
+       {
+               quarks = set->u.alloc;
+               len = ABS (set->len);
+       }
+
+       for (i = 0; i < len; i++)
+       {
+               if (quarks[i] == quark)
+               {
+                       return TRUE;
+               }
+       }
+
+       return FALSE;
+}
+
+static inline void
+quark_set_add (QuarkSet *set,
+               GQuark    quark)
+{
+       if (quark_set_contains (set, quark))
+       {
+               return;
+       }
+
+       if G_LIKELY (set->len == 0 || set->len == 1)
+       {
+               G_STATIC_ASSERT (G_N_ELEMENTS (set->u.embed) == 2);
+
+               set->u.embed[set->len++] = quark;
+       }
+       else if (set->len == G_N_ELEMENTS (set->u.embed))
+       {
+               GQuark *alloc = g_new (GQuark, set->len + 1);
+               guint i;
+
+               for (i = 0; i < set->len; i++)
+               {
+                       alloc[i] = set->u.embed[i];
+               }
+
+               alloc[set->len] = quark;
+               set->len = -(set->len + 1);
+               set->u.alloc = alloc;
+       }
+       else if (set->len < 0)
+       {
+               guint len = ABS (set->len);
+
+               set->u.alloc = g_realloc_n (set->u.alloc, len + 1, sizeof (GQuark));
+               set->u.alloc[len] = quark;
+               set->len--; /* = -(len + 1) */
+       }
+       else
+       {
+               g_assert_not_reached ();
+       }
+}
+
+static inline void
+quark_set_remove (QuarkSet *set,
+                  GQuark    quark)
+{
+       if (set->len == 0)
+       {
+               return;
+       }
+       else if (set->len == -1 && set->u.alloc[0] == quark)
+       {
+               quark_set_clear (set);
+               return;
+       }
+       else if (set->len > 0)
+       {
+               G_STATIC_ASSERT (G_N_ELEMENTS (set->u.embed) == 2);
+
+               if (set->u.embed[0] == quark)
+               {
+                       set->u.embed[0] = set->u.embed[1];
+                       set->len--;
+               }
+               else if (set->u.embed[1] == quark)
+               {
+                       set->len--;
+               }
+       }
+       else if (set->len < 0)
+       {
+               guint len = ABS (set->len);
+               guint i;
+
+               for (i = 0; i < len; i++)
+               {
+                       if (set->u.alloc[i] == quark)
+                       {
+                               if (i + 1 < len)
+                               {
+                                       set->u.alloc[i] = set->u.alloc[len - 1];
+                               }
+
+                               set->len++; /* = -(len - 1) */
+
+                               break;
+                       }
+               }
+       }
+       else
+       {
+               g_assert_not_reached ();
+       }
+}
+
+G_END_DECLS
+
+#endif /* __QUARK_SET_INLINE_H__ */
diff --git a/meson.build b/meson.build
index 8574775d..ce737f47 100644
--- a/meson.build
+++ b/meson.build
@@ -64,7 +64,7 @@ build_gtk_doc = get_option('gtk_doc')
 # Dependencies
 cc = meson.get_compiler('c')
 
-glib_req_version = '2.48'
+glib_req_version = '2.62'
 gtk_req_version = '3.96'
 
 libm_dep = cc.find_library('m', required: false)
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 5fe44fe0..a1f7b9bf 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -39,6 +39,5 @@ gtksourceview/gtksourcestylescheme.c
 gtksourceview/gtksourcestyleschemechooserbutton.c
 gtksourceview/gtksourcestyleschememanager.c
 gtksourceview/gtksourcetag.c
-gtksourceview/gtksourceundomanagerdefault.c
 gtksourceview/gtksourceutils.c
 gtksourceview/gtksourceview.c
diff --git a/tests/meson.build b/tests/meson.build
index eb078ee8..a33e8228 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -9,7 +9,6 @@ tests_sources = {
                      'search': ['test-search.c'],
         'search-performances': ['test-search-performances.c'],
               'space-drawing': ['test-space-drawing.c'],
-  'undo-manager-performances': ['test-undo-manager-performances.c'],
                      'widget': ['test-widget.c'],
 }
 
diff --git a/tests/test-completion.c b/tests/test-completion.c
index 6830d904..669a6398 100644
--- a/tests/test-completion.c
+++ b/tests/test-completion.c
@@ -37,9 +37,9 @@ struct _TestProvider
        gint priority;
        gchar *name;
 
-       GdkPixbuf *provider_icon;
+       GdkPaintable *provider_icon;
 
-       GdkPixbuf *item_icon;
+       GdkPaintable *item_icon;
        GIcon *item_gicon;
 
        /* If it's a random provider, a subset of 'proposals' are choosen on
@@ -115,9 +115,14 @@ test_provider_populate (GtkSourceCompletionProvider *completion_provider,
 static GdkPixbuf *
 test_provider_get_icon (GtkSourceCompletionProvider *provider)
 {
+#if 0
        TestProvider *tp = (TestProvider *)provider;
 
        return tp->is_random ? NULL : tp->provider_icon;
+#else
+       /* TODO: Switch to texture API */
+       return NULL;
+#endif
 }
 
 static void
@@ -199,7 +204,7 @@ test_provider_set_fixed (TestProvider *provider,
        item = gtk_source_completion_item_new ();
        gtk_source_completion_item_set_markup (item, "A very <b>long</b> proposal. I <i>repeat</i>, a very 
long proposal!");
        gtk_source_completion_item_set_text (item, "A very long proposal. I repeat, a very long proposal!");
-       gtk_source_completion_item_set_icon (item, provider->item_icon);
+       /* gtk_source_completion_item_set_icon (item, provider->item_icon); */
        gtk_source_completion_item_set_info (item, "To test the horizontal scrollbar and the markup.");
        proposals = g_list_prepend (proposals, item);
 
@@ -222,7 +227,7 @@ test_provider_set_fixed (TestProvider *provider,
                item = gtk_source_completion_item_new ();
                gtk_source_completion_item_set_label (item, name);
                gtk_source_completion_item_set_text (item, name);
-               gtk_source_completion_item_set_icon (item, provider->item_icon);
+               /* gtk_source_completion_item_set_icon (item, provider->item_icon); */
                gtk_source_completion_item_set_info (item, "The extra info of the proposal.\nA second line.");
                proposals = g_list_prepend (proposals, item);
 
@@ -251,7 +256,7 @@ test_provider_set_random (TestProvider *provider,
                item = gtk_source_completion_item_new ();
                gtk_source_completion_item_set_label (item, name);
                gtk_source_completion_item_set_text (item, name);
-               gtk_source_completion_item_set_icon (item, provider->item_icon);
+               /* gtk_source_completion_item_set_icon (item, provider->item_icon); */
                proposals = g_list_prepend (proposals, item);
 
                g_free (padding);
@@ -454,9 +459,10 @@ create_window (void)
 }
 
 int
-main (int argc, char *argv[])
+main (int   argc,
+      char *argv[])
 {
-       gtk_init (&argc, &argv);
+       gtk_init ();
 
        create_window ();
 
diff --git a/tests/test-search-performances.c b/tests/test-search-performances.c
index 7c68323a..f2a08b36 100644
--- a/tests/test-search-performances.c
+++ b/tests/test-search-performances.c
@@ -58,7 +58,7 @@ main (int argc, char *argv[])
        GtkTextSearchFlags flags;
        gchar *regex_pattern;
 
-       gtk_init (&argc, &argv);
+       gtk_init ();
 
        buffer = gtk_source_buffer_new (NULL);
 
diff --git a/tests/test-search.c b/tests/test-search.c
index 75ae96de..e59eed4a 100644
--- a/tests/test-search.c
+++ b/tests/test-search.c
@@ -154,7 +154,7 @@ static void
 search_entry_changed_cb (TestSearch *search,
                         GtkEntry   *entry)
 {
-       const gchar *text = gtk_entry_get_text (entry);
+       const gchar *text = gtk_editable_get_text (GTK_EDITABLE (entry));
        gchar *unescaped_text = gtk_source_utils_unescape_search_text (text);
 
        gtk_source_search_settings_set_search_text (search->priv->search_settings, unescaped_text);
@@ -270,7 +270,7 @@ button_replace_clicked_cb (TestSearch *search,
        gtk_source_search_context_replace (search->priv->search_context,
                                           &match_start,
                                           &match_end,
-                                          gtk_entry_get_text (search->priv->replace_entry),
+                                          gtk_editable_get_text (GTK_EDITABLE (search->priv->replace_entry)),
                                           replace_length,
                                           NULL);
 
@@ -293,7 +293,7 @@ button_replace_all_clicked_cb (TestSearch *search,
        gint replace_length = gtk_entry_buffer_get_bytes (entry_buffer);
 
        gtk_source_search_context_replace_all (search->priv->search_context,
-                                              gtk_entry_get_text (search->priv->replace_entry),
+                                              gtk_editable_get_text (GTK_EDITABLE 
(search->priv->replace_entry)),
                                               replace_length,
                                               NULL);
 }
@@ -462,7 +462,7 @@ main (gint argc, gchar *argv[])
        GtkWidget *window;
        TestSearch *search;
 
-       gtk_init (&argc, &argv);
+       gtk_init ();
 
        window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
 
diff --git a/tests/test-space-drawing.c b/tests/test-space-drawing.c
index e6940348..d5f734fd 100644
--- a/tests/test-space-drawing.c
+++ b/tests/test-space-drawing.c
@@ -141,14 +141,14 @@ create_window (void)
 
        gtk_container_add (GTK_CONTAINER (window), hgrid);
 
-       gtk_widget_show_all (window);
+       gtk_window_present (GTK_WINDOW (window));
 }
 
 gint
 main (gint    argc,
       gchar **argv)
 {
-       gtk_init (&argc, &argv);
+       gtk_init ();
 
        create_window ();
 
diff --git a/tests/test-widget.c b/tests/test-widget.c
index 5ca68c8a..660b462d 100644
--- a/tests/test-widget.c
+++ b/tests/test-widget.c
@@ -61,6 +61,7 @@ struct _TestWidgetPrivate
        GtkLabel *cursor_position_info;
        GtkSourceStyleSchemeChooserButton *chooser_button;
        GtkComboBoxText *background_pattern;
+       GtkWidget *top;
 };
 
 GType test_widget_get_type (void);
@@ -183,7 +184,7 @@ print_language_style_ids (GtkSourceLanguage *language)
 {
        gchar **styles;
 
-       g_assert_nonnull (language);
+       g_assert (language != NULL);
 
        styles = gtk_source_language_get_style_ids (language);
 
@@ -295,8 +296,10 @@ static void
 show_line_marks_toggled_cb (TestWidget     *self,
                            GtkCheckButton *button)
 {
+#if 0
        gboolean enabled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));
        gtk_source_view_set_show_line_marks (self->priv->view, enabled);
+#endif
 }
 
 static void
@@ -472,7 +475,7 @@ open_button_clicked_cb (TestWidget *self)
        gint response;
        static gchar *last_dir;
 
-       main_window = gtk_widget_get_toplevel (GTK_WIDGET (self->priv->view));
+       main_window = GTK_WIDGET (gtk_widget_get_root (GTK_WIDGET (self->priv->view)));
 
        chooser = gtk_file_chooser_dialog_new ("Open file...",
                                               GTK_WINDOW (main_window),
@@ -543,7 +546,7 @@ paginate (GtkPrintOperation        *operation,
        {
                gint n_pages;
 
-               g_assert_cmpint (gtk_source_print_compositor_get_pagination_progress (compositor), ==, 1.0);
+               g_assert (gtk_source_print_compositor_get_pagination_progress (compositor) == 1.0);
                g_print ("Pagination progress: %.2f %%\n", 
gtk_source_print_compositor_get_pagination_progress (compositor) * 100.0);
 
                n_pages = gtk_source_print_compositor_get_n_pages (compositor);
@@ -779,6 +782,7 @@ mark_set_cb (GtkTextBuffer *buffer,
        }
 }
 
+#if 0
 static void
 line_mark_activated_cb (GtkSourceGutter *gutter,
                        GtkTextIter     *iter,
@@ -812,6 +816,7 @@ line_mark_activated_cb (GtkSourceGutter *gutter,
 
        g_slist_free (mark_list);
 }
+#endif
 
 static void
 bracket_matched_cb (GtkSourceBuffer           *buffer,
@@ -980,15 +985,21 @@ test_widget_class_init (TestWidgetClass *klass)
 
 static void
 show_top_border_window_toggled_cb (GtkToggleButton *checkbutton,
-                                  TestWidget      *self)
+                                   TestWidget      *self)
 {
        gint size;
 
        size = gtk_toggle_button_get_active (checkbutton) ? 20 : 0;
 
-       gtk_text_view_set_border_window_size (GTK_TEXT_VIEW (self->priv->view),
-                                             GTK_TEXT_WINDOW_TOP,
-                                             size);
+       if (self->priv->top == NULL)
+       {
+               self->priv->top = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
+               gtk_text_view_set_gutter (GTK_TEXT_VIEW (self->priv->view),
+                                         GTK_TEXT_WINDOW_TOP,
+                                         GTK_WIDGET (self->priv->top));
+       }
+
+       gtk_widget_set_size_request (self->priv->top, -1, size);
 }
 
 static void
@@ -1037,10 +1048,12 @@ test_widget_init (TestWidget *self)
 
        add_source_mark_attributes (self->priv->view);
 
+#if 0
        g_signal_connect (self->priv->view,
                          "line-mark-activated",
                          G_CALLBACK (line_mark_activated_cb),
                          self);
+#endif
 
        g_object_bind_property (self->priv->chooser_button,
                                "style-scheme",
@@ -1070,7 +1083,7 @@ test_widget_init (TestWidget *self)
                                space_drawer, "enable-matrix",
                                G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
 
-       open_file (self, TOP_SRCDIR "/gtksourceview/gtksourcebuffer.c");
+       open_file (self, TOP_SRCDIR "/gtksourcebuffer.c");
 }
 
 static TestWidget *
@@ -1085,7 +1098,7 @@ main (int argc, char *argv[])
        GtkWidget *window;
        TestWidget *test_widget;
 
-       gtk_init (&argc, &argv);
+       gtk_init ();
        gtk_source_init ();
 
        window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
diff --git a/testsuite/meson.build b/testsuite/meson.build
index f842a07a..8fac92c9 100644
--- a/testsuite/meson.build
+++ b/testsuite/meson.build
@@ -32,7 +32,6 @@ testsuite_sources = [
   ['test-space-drawer'],
   ['test-stylescheme'],
   ['test-styleschememanager'],
-  ['test-undo-manager'],
   ['test-utils'],
   ['test-view'],
 ]


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]