[gtksourceview/wip/chergert/gsv-gtk4: 31/144] buffer: modernize GtkSourceBuffer



commit d32f48b58e31275807ce1077df2bb91a3e2a8cc6
Author: Christian Hergert <chergert redhat com>
Date:   Wed Jan 8 16:30:11 2020 -0800

    buffer: modernize GtkSourceBuffer
    
     - Use G_DECLARE*
     - Align similar functions
     - Use get_instance_private()
     - Remove autocleanup helpers

 gtksourceview/gtksourceautocleanups.h   |   1 -
 gtksourceview/gtksourcebuffer-private.h |  74 +++---
 gtksourceview/gtksourcebuffer.c         | 394 +++++++++++++++++++-------------
 gtksourceview/gtksourcebuffer.h         | 217 +++++++-----------
 4 files changed, 346 insertions(+), 340 deletions(-)
---
diff --git a/gtksourceview/gtksourceautocleanups.h b/gtksourceview/gtksourceautocleanups.h
index 550fa1c4..eb1b2293 100644
--- a/gtksourceview/gtksourceautocleanups.h
+++ b/gtksourceview/gtksourceautocleanups.h
@@ -28,7 +28,6 @@ G_BEGIN_DECLS
 
 #ifndef __GI_SCANNER__
 
-G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkSourceBuffer, g_object_unref)
 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkSourceCompletion, g_object_unref)
 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkSourceCompletionContext, g_object_unref)
 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkSourceCompletionInfo, g_object_unref)
diff --git a/gtksourceview/gtksourcebuffer-private.h b/gtksourceview/gtksourcebuffer-private.h
index 2b86e14d..492c33c8 100644
--- a/gtksourceview/gtksourcebuffer-private.h
+++ b/gtksourceview/gtksourcebuffer-private.h
@@ -29,62 +29,48 @@
 G_BEGIN_DECLS
 
 GTK_SOURCE_INTERNAL
-void                    _gtk_source_buffer_update_syntax_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
-void                    _gtk_source_buffer_update_search_highlight     (GtkSourceBuffer        *buffer,
-                                                                        const GtkTextIter      *start,
-                                                                        const GtkTextIter      *end,
-                                                                        gboolean                synchronous);
-
+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_next            (GtkSourceBuffer        *buffer,
-                                                                        GtkSourceMark          *mark,
-                                                                        const gchar            *category);
-
+GtkSourceMark            *_gtk_source_buffer_source_mark_next            (GtkSourceBuffer        *buffer,
+                                                                          GtkSourceMark          *mark,
+                                                                          const gchar            *category);
 GTK_SOURCE_INTERNAL
-GtkSourceMark          *_gtk_source_buffer_source_mark_prev            (GtkSourceBuffer        *buffer,
-                                                                        GtkSourceMark          *mark,
-                                                                        const gchar            *category);
-
+GtkSourceMark            *_gtk_source_buffer_source_mark_prev            (GtkSourceBuffer        *buffer,
+                                                                          GtkSourceMark          *mark,
+                                                                          const gchar            *category);
 GTK_SOURCE_INTERNAL
-GtkTextTag             *_gtk_source_buffer_get_bracket_match_tag       (GtkSourceBuffer        *buffer);
-
+GtkTextTag               *_gtk_source_buffer_get_bracket_match_tag       (GtkSourceBuffer        *buffer);
 GTK_SOURCE_INTERNAL
-void                    _gtk_source_buffer_add_search_context          (GtkSourceBuffer        *buffer,
-                                                                        GtkSourceSearchContext 
*search_context);
-
+void                      _gtk_source_buffer_add_search_context          (GtkSourceBuffer        *buffer,
+                                                                          GtkSourceSearchContext 
*search_context);
 GTK_SOURCE_INTERNAL
-void                    _gtk_source_buffer_set_as_invalid_character    (GtkSourceBuffer        *buffer,
-                                                                        const GtkTextIter      *start,
-                                                                        const GtkTextIter      *end);
-
+void                      _gtk_source_buffer_set_as_invalid_character    (GtkSourceBuffer        *buffer,
+                                                                          const GtkTextIter      *start,
+                                                                          const GtkTextIter      *end);
 GTK_SOURCE_INTERNAL
-gboolean                _gtk_source_buffer_has_invalid_chars           (GtkSourceBuffer        *buffer);
-
+gboolean                  _gtk_source_buffer_has_invalid_chars           (GtkSourceBuffer        *buffer);
 GTK_SOURCE_INTERNAL
-GtkSourceBracketMatchType
-                        _gtk_source_buffer_find_bracket_match          (GtkSourceBuffer        *buffer,
-                                                                        const GtkTextIter      *pos,
-                                                                        GtkTextIter            *bracket,
-                                                                        GtkTextIter            
*bracket_match);
-
+GtkSourceBracketMatchType _gtk_source_buffer_find_bracket_match          (GtkSourceBuffer        *buffer,
+                                                                          const GtkTextIter      *pos,
+                                                                          GtkTextIter            *bracket,
+                                                                          GtkTextIter            
*bracket_match);
 GTK_SOURCE_INTERNAL
-void                    _gtk_source_buffer_save_and_clear_selection    (GtkSourceBuffer        *buffer);
-
+void                      _gtk_source_buffer_save_and_clear_selection    (GtkSourceBuffer        *buffer);
 GTK_SOURCE_INTERNAL
-void                    _gtk_source_buffer_restore_selection           (GtkSourceBuffer        *buffer);
-
+void                      _gtk_source_buffer_restore_selection           (GtkSourceBuffer        *buffer);
 GTK_SOURCE_INTERNAL
-gboolean                _gtk_source_buffer_is_undo_redo_enabled        (GtkSourceBuffer        *buffer);
-
+gboolean                  _gtk_source_buffer_is_undo_redo_enabled        (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
diff --git a/gtksourceview/gtksourcebuffer.c b/gtksourceview/gtksourcebuffer.c
index bad12f1d..76c5ef05 100644
--- a/gtksourceview/gtksourcebuffer.c
+++ b/gtksourceview/gtksourcebuffer.c
@@ -190,7 +190,7 @@ enum
        N_PROPERTIES
 };
 
-struct _GtkSourceBufferPrivate
+typedef struct
 {
        GtkTextTag *bracket_match_tag;
        GtkSourceBracketMatchType bracket_match_state;
@@ -218,7 +218,7 @@ struct _GtkSourceBufferPrivate
        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];
@@ -272,7 +272,9 @@ static void
 gtk_source_buffer_check_tag_for_spaces (GtkSourceBuffer *buffer,
                                         GtkSourceTag    *tag)
 {
-       if (!buffer->priv->has_draw_spaces_tag)
+       GtkSourceBufferPrivate *priv = gtk_source_buffer_get_instance_private (buffer);
+
+       if (!priv->has_draw_spaces_tag)
        {
                gboolean draw_spaces_set;
 
@@ -282,7 +284,7 @@ gtk_source_buffer_check_tag_for_spaces (GtkSourceBuffer *buffer,
 
                if (draw_spaces_set)
                {
-                       buffer->priv->has_draw_spaces_tag = TRUE;
+                       priv->has_draw_spaces_tag = TRUE;
                }
        }
 }
@@ -314,9 +316,10 @@ 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 (buffer->priv->undo_manager == NULL)
+       if (priv->undo_manager == NULL)
        {
                /* This will install the default undo manager */
                gtk_source_buffer_set_undo_manager (buffer, NULL);
@@ -587,35 +590,37 @@ static void
 set_undo_manager (GtkSourceBuffer      *buffer,
                   GtkSourceUndoManager *manager)
 {
-       if (manager == buffer->priv->undo_manager)
+       GtkSourceBufferPrivate *priv = gtk_source_buffer_get_instance_private (buffer);
+
+       if (manager == priv->undo_manager)
        {
                return;
        }
 
-       if (buffer->priv->undo_manager != NULL)
+       if (priv->undo_manager != NULL)
        {
-               g_signal_handlers_disconnect_by_func (buffer->priv->undo_manager,
+               g_signal_handlers_disconnect_by_func (priv->undo_manager,
                                                      G_CALLBACK (gtk_source_buffer_can_undo_handler),
                                                      buffer);
 
-               g_signal_handlers_disconnect_by_func (buffer->priv->undo_manager,
+               g_signal_handlers_disconnect_by_func (priv->undo_manager,
                                                      G_CALLBACK (gtk_source_buffer_can_redo_handler),
                                                      buffer);
 
-               g_object_unref (buffer->priv->undo_manager);
-               buffer->priv->undo_manager = NULL;
+               g_object_unref (priv->undo_manager);
+               priv->undo_manager = NULL;
        }
 
        if (manager != NULL)
        {
-               buffer->priv->undo_manager = g_object_ref (manager);
+               priv->undo_manager = g_object_ref (manager);
 
-               g_signal_connect (buffer->priv->undo_manager,
+               g_signal_connect (priv->undo_manager,
                                  "can-undo-changed",
                                  G_CALLBACK (gtk_source_buffer_can_undo_handler),
                                  buffer);
 
-               g_signal_connect (buffer->priv->undo_manager,
+               g_signal_connect (priv->undo_manager,
                                  "can-redo-changed",
                                  G_CALLBACK (gtk_source_buffer_can_redo_handler),
                                  buffer);
@@ -630,8 +635,9 @@ static void
 search_context_weak_notify_cb (GtkSourceBuffer *buffer,
                               GObject         *search_context)
 {
-       buffer->priv->search_contexts = g_list_remove (buffer->priv->search_contexts,
-                                                      search_context);
+       GtkSourceBufferPrivate *priv = gtk_source_buffer_get_instance_private (buffer);
+
+       priv->search_contexts = g_list_remove (priv->search_contexts, search_context);
 }
 
 static void
@@ -639,8 +645,6 @@ 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;
@@ -665,29 +669,30 @@ 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 (buffer->priv->bracket_highlighting_timeout_id != 0)
+       if (priv->bracket_highlighting_timeout_id != 0)
        {
-               g_source_remove (buffer->priv->bracket_highlighting_timeout_id);
-               buffer->priv->bracket_highlighting_timeout_id = 0;
+               g_source_remove (priv->bracket_highlighting_timeout_id);
+               priv->bracket_highlighting_timeout_id = 0;
        }
 
-       if (buffer->priv->undo_manager != NULL)
+       if (priv->undo_manager != NULL)
        {
                set_undo_manager (buffer, NULL);
        }
 
-       if (buffer->priv->highlight_engine != NULL)
+       if (priv->highlight_engine != NULL)
        {
-               _gtk_source_engine_attach_buffer (buffer->priv->highlight_engine, NULL);
+               _gtk_source_engine_attach_buffer (priv->highlight_engine, NULL);
        }
 
-       g_clear_object (&buffer->priv->highlight_engine);
-       g_clear_object (&buffer->priv->language);
-       g_clear_object (&buffer->priv->style_scheme);
+       g_clear_object (&priv->highlight_engine);
+       g_clear_object (&priv->language);
+       g_clear_object (&priv->style_scheme);
 
-       for (l = buffer->priv->search_contexts; l != NULL; l = l->next)
+       for (l = priv->search_contexts; l != NULL; l = l->next)
        {
                GtkSourceSearchContext *search_context = l->data;
 
@@ -696,15 +701,15 @@ gtk_source_buffer_dispose (GObject *object)
                                     buffer);
        }
 
-       g_list_free (buffer->priv->search_contexts);
-       buffer->priv->search_contexts = NULL;
+       g_list_free (priv->search_contexts);
+       priv->search_contexts = NULL;
 
-       g_clear_object (&buffer->priv->all_source_marks);
+       g_clear_object (&priv->all_source_marks);
 
-       if (buffer->priv->source_marks != NULL)
+       if (priv->source_marks != NULL)
        {
-               g_hash_table_unref (buffer->priv->source_marks);
-               buffer->priv->source_marks = NULL;
+               g_hash_table_unref (priv->source_marks);
+               priv->source_marks = NULL;
        }
 
        G_OBJECT_CLASS (gtk_source_buffer_parent_class)->dispose (object);
@@ -716,11 +721,7 @@ gtk_source_buffer_set_property (GObject      *object,
                                const GValue *value,
                                GParamSpec   *pspec)
 {
-       GtkSourceBuffer *buffer;
-
-       g_return_if_fail (GTK_SOURCE_IS_BUFFER (object));
-
-       buffer = GTK_SOURCE_BUFFER (object);
+       GtkSourceBuffer *buffer = GTK_SOURCE_BUFFER (object);
 
        switch (prop_id)
        {
@@ -764,32 +765,29 @@ gtk_source_buffer_get_property (GObject    *object,
                                GValue     *value,
                                GParamSpec *pspec)
 {
-       GtkSourceBuffer *buffer;
-
-       g_return_if_fail (GTK_SOURCE_IS_BUFFER (object));
-
-       buffer = GTK_SOURCE_BUFFER (object);
+       GtkSourceBuffer *buffer = GTK_SOURCE_BUFFER (object);
+       GtkSourceBufferPrivate *priv = gtk_source_buffer_get_instance_private (buffer);
 
        switch (prop_id)
        {
                case PROP_HIGHLIGHT_SYNTAX:
-                       g_value_set_boolean (value, buffer->priv->highlight_syntax);
+                       g_value_set_boolean (value, priv->highlight_syntax);
                        break;
 
                case PROP_HIGHLIGHT_MATCHING_BRACKETS:
-                       g_value_set_boolean (value, buffer->priv->highlight_brackets);
+                       g_value_set_boolean (value, priv->highlight_brackets);
                        break;
 
                case PROP_MAX_UNDO_LEVELS:
-                       g_value_set_int (value, buffer->priv->max_undo_levels);
+                       g_value_set_int (value, priv->max_undo_levels);
                        break;
 
                case PROP_LANGUAGE:
-                       g_value_set_object (value, buffer->priv->language);
+                       g_value_set_object (value, priv->language);
                        break;
 
                case PROP_STYLE_SCHEME:
-                       g_value_set_object (value, buffer->priv->style_scheme);
+                       g_value_set_object (value, priv->style_scheme);
                        break;
 
                case PROP_CAN_UNDO:
@@ -801,11 +799,11 @@ gtk_source_buffer_get_property (GObject    *object,
                        break;
 
                case PROP_UNDO_MANAGER:
-                       g_value_set_object (value, buffer->priv->undo_manager);
+                       g_value_set_object (value, priv->undo_manager);
                        break;
 
                case PROP_IMPLICIT_TRAILING_NEWLINE:
-                       g_value_set_boolean (value, buffer->priv->implicit_trailing_newline);
+                       g_value_set_boolean (value, priv->implicit_trailing_newline);
                        break;
 
                default:
@@ -825,6 +823,8 @@ 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);
@@ -873,34 +873,37 @@ gtk_source_buffer_can_redo_handler (GtkSourceUndoManager *manager,
 static void
 update_bracket_match_style (GtkSourceBuffer *buffer)
 {
+       GtkSourceBufferPrivate *priv = gtk_source_buffer_get_instance_private (buffer);
        GtkSourceStyle *style = NULL;
 
-       if (buffer->priv->bracket_match_tag == NULL)
+       if (priv->bracket_match_tag == NULL)
        {
                return;
        }
 
-       if (buffer->priv->style_scheme != NULL)
+       if (priv->style_scheme != NULL)
        {
-               style = _gtk_source_style_scheme_get_matching_brackets_style (buffer->priv->style_scheme);
+               style = _gtk_source_style_scheme_get_matching_brackets_style (priv->style_scheme);
        }
 
-       gtk_source_style_apply (style, buffer->priv->bracket_match_tag);
+       gtk_source_style_apply (style, priv->bracket_match_tag);
 }
 
 static GtkTextTag *
 get_bracket_match_tag (GtkSourceBuffer *buffer)
 {
-       if (buffer->priv->bracket_match_tag == NULL)
+       GtkSourceBufferPrivate *priv = gtk_source_buffer_get_instance_private (buffer);
+
+       if (priv->bracket_match_tag == NULL)
        {
-               buffer->priv->bracket_match_tag =
+               priv->bracket_match_tag =
                        gtk_text_buffer_create_tag (GTK_TEXT_BUFFER (buffer),
                                                    NULL,
                                                    NULL);
                update_bracket_match_style (buffer);
        }
 
-       return buffer->priv->bracket_match_tag;
+       return priv->bracket_match_tag;
 }
 
 /* This is private, just used by the print compositor to not print bracket
@@ -910,7 +913,9 @@ get_bracket_match_tag (GtkSourceBuffer *buffer)
 GtkTextTag *
 _gtk_source_buffer_get_bracket_match_tag (GtkSourceBuffer *buffer)
 {
-       return buffer->priv->bracket_match_tag;
+       GtkSourceBufferPrivate *priv = gtk_source_buffer_get_instance_private (buffer);
+
+       return priv->bracket_match_tag;
 }
 
 static gunichar
@@ -1057,15 +1062,14 @@ remove_tag_with_minimal_damage (GtkTextBuffer     *buffer,
 static void
 update_bracket_highlighting (GtkSourceBuffer *source_buffer)
 {
-       GtkTextBuffer *buffer;
+       GtkTextBuffer *buffer = GTK_TEXT_BUFFER (source_buffer);
+       GtkSourceBufferPrivate *priv = gtk_source_buffer_get_instance_private (source_buffer);
        GtkTextIter insert_iter;
        GtkTextIter bracket;
        GtkTextIter bracket_match;
        GtkSourceBracketMatchType previous_state;
 
-       buffer = GTK_TEXT_BUFFER (source_buffer);
-
-       if (source_buffer->priv->bracket_match_tag != NULL)
+       if (priv->bracket_match_tag != NULL)
        {
                GtkTextIter start;
                GtkTextIter end;
@@ -1073,20 +1077,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),
-                                               source_buffer->priv->bracket_match_tag,
+                                               priv->bracket_match_tag,
                                                &start,
                                                &end);
        }
 
-       if (!source_buffer->priv->highlight_brackets)
+       if (!priv->highlight_brackets)
        {
-               if (source_buffer->priv->bracket_match_tag != NULL)
+               if (priv->bracket_match_tag != NULL)
                {
                        GtkTextTagTable *table;
 
                        table = gtk_text_buffer_get_tag_table (buffer);
-                       gtk_text_tag_table_remove (table, source_buffer->priv->bracket_match_tag);
-                       source_buffer->priv->bracket_match_tag = NULL;
+                       gtk_text_tag_table_remove (table, priv->bracket_match_tag);
+                       priv->bracket_match_tag = NULL;
                }
 
                return;
@@ -1096,14 +1100,14 @@ update_bracket_highlighting (GtkSourceBuffer *source_buffer)
                                          &insert_iter,
                                          gtk_text_buffer_get_insert (buffer));
 
-       previous_state = source_buffer->priv->bracket_match_state;
-       source_buffer->priv->bracket_match_state =
+       previous_state = priv->bracket_match_state;
+       priv->bracket_match_state =
                _gtk_source_buffer_find_bracket_match (source_buffer,
                                                       &insert_iter,
                                                       &bracket,
                                                       &bracket_match);
 
-       if (source_buffer->priv->bracket_match_state == GTK_SOURCE_BRACKET_MATCH_FOUND)
+       if (priv->bracket_match_state == GTK_SOURCE_BRACKET_MATCH_FOUND)
        {
                GtkTextIter next_iter;
 
@@ -1133,13 +1137,13 @@ update_bracket_highlighting (GtkSourceBuffer *source_buffer)
         * positions are nonbrackets.
         */
        if (previous_state != GTK_SOURCE_BRACKET_MATCH_NONE ||
-           source_buffer->priv->bracket_match_state != GTK_SOURCE_BRACKET_MATCH_NONE)
+           priv->bracket_match_state != GTK_SOURCE_BRACKET_MATCH_NONE)
        {
                g_signal_emit (source_buffer,
                               buffer_signals[BRACKET_MATCHED],
                               0,
                               NULL,
-                              source_buffer->priv->bracket_match_state);
+                              priv->bracket_match_state);
        }
 }
 
@@ -1147,19 +1151,22 @@ 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);
 
-       buffer->priv->bracket_highlighting_timeout_id = 0;
+       priv->bracket_highlighting_timeout_id = 0;
        return G_SOURCE_REMOVE;
 }
 
 static void
 queue_bracket_highlighting_update (GtkSourceBuffer *buffer)
 {
-       if (buffer->priv->bracket_highlighting_timeout_id != 0)
+       GtkSourceBufferPrivate *priv = gtk_source_buffer_get_instance_private (buffer);
+
+       if (priv->bracket_highlighting_timeout_id != 0)
        {
-               g_source_remove (buffer->priv->bracket_highlighting_timeout_id);
+               g_source_remove (priv->bracket_highlighting_timeout_id);
        }
 
        /* Queue an update to the bracket location instead of doing it
@@ -1179,7 +1186,7 @@ queue_bracket_highlighting_update (GtkSourceBuffer *buffer)
         * If we had access to a GdkFrameClock, we might consider using
         * ::update() or ::after-paint() to synchronize this.
         */
-       buffer->priv->bracket_highlighting_timeout_id =
+       priv->bracket_highlighting_timeout_id =
                gdk_threads_add_timeout_full (G_PRIORITY_LOW,
                                              UPDATE_BRACKET_DELAY,
                                              bracket_highlighting_timeout_cb,
@@ -1211,12 +1218,13 @@ 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 (source_buffer->priv->highlight_engine != NULL)
+       if (priv->highlight_engine != NULL)
        {
-               _gtk_source_engine_text_inserted (source_buffer->priv->highlight_engine,
+               _gtk_source_engine_text_inserted (priv->highlight_engine,
                                                  start_offset,
                                                  end_offset);
        }
@@ -1309,6 +1317,7 @@ 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);
@@ -1325,9 +1334,9 @@ gtk_source_buffer_real_delete_range (GtkTextBuffer *buffer,
        cursor_moved (source_buffer);
 
        /* emit text deleted for engines */
-       if (source_buffer->priv->highlight_engine != NULL)
+       if (priv->highlight_engine != NULL)
        {
-               _gtk_source_engine_text_deleted (source_buffer->priv->highlight_engine,
+               _gtk_source_engine_text_deleted (priv->highlight_engine,
                                                 offset, length);
        }
 }
@@ -1534,9 +1543,11 @@ _gtk_source_buffer_find_bracket_match (GtkSourceBuffer   *buffer,
 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 (buffer->priv->undo_manager);
+       return gtk_source_undo_manager_can_undo (priv->undo_manager);
 }
 
 /**
@@ -1551,9 +1562,11 @@ gtk_source_buffer_can_undo (GtkSourceBuffer *buffer)
 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 (buffer->priv->undo_manager);
+       return gtk_source_undo_manager_can_redo (priv->undo_manager);
 }
 
 /**
@@ -1602,9 +1615,11 @@ gtk_source_buffer_redo (GtkSourceBuffer *buffer)
 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 buffer->priv->max_undo_levels;
+       return priv->max_undo_levels;
 }
 
 /**
@@ -1624,18 +1639,20 @@ 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 (buffer->priv->max_undo_levels == max_undo_levels)
+       if (priv->max_undo_levels == max_undo_levels)
        {
                return;
        }
 
-       buffer->priv->max_undo_levels = max_undo_levels;
+       priv->max_undo_levels = max_undo_levels;
 
-       if (GTK_SOURCE_IS_UNDO_MANAGER_DEFAULT (buffer->priv->undo_manager))
+       if (GTK_SOURCE_IS_UNDO_MANAGER_DEFAULT (priv->undo_manager))
        {
-               gtk_source_undo_manager_default_set_max_undo_levels (GTK_SOURCE_UNDO_MANAGER_DEFAULT 
(buffer->priv->undo_manager),
+               gtk_source_undo_manager_default_set_max_undo_levels (GTK_SOURCE_UNDO_MANAGER_DEFAULT 
(priv->undo_manager),
                                                                     max_undo_levels);
        }
 
@@ -1645,20 +1662,22 @@ gtk_source_buffer_set_max_undo_levels (GtkSourceBuffer *buffer,
 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 (buffer->priv->undo_manager == NULL)
+       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 (buffer->priv->undo_manager))
+       if (!GTK_SOURCE_IS_UNDO_MANAGER_DEFAULT (priv->undo_manager))
        {
                return TRUE;
        }
 
-       return buffer->priv->max_undo_levels != 0;
+       return priv->max_undo_levels != 0;
 }
 
 /**
@@ -1676,9 +1695,11 @@ _gtk_source_buffer_is_undo_redo_enabled (GtkSourceBuffer *buffer)
 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 (buffer->priv->undo_manager);
+       gtk_source_undo_manager_begin_not_undoable_action (priv->undo_manager);
 }
 
 /**
@@ -1693,9 +1714,11 @@ gtk_source_buffer_begin_not_undoable_action (GtkSourceBuffer *buffer)
 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 (buffer->priv->undo_manager);
+       gtk_source_undo_manager_end_not_undoable_action (priv->undo_manager);
 }
 
 /**
@@ -1711,9 +1734,11 @@ 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 buffer->priv->highlight_brackets;
+       return priv->highlight_brackets;
 }
 
 /**
@@ -1730,13 +1755,15 @@ 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 != buffer->priv->highlight_brackets)
+       if (highlight != priv->highlight_brackets)
        {
-               buffer->priv->highlight_brackets = highlight;
+               priv->highlight_brackets = highlight;
 
                update_bracket_highlighting (buffer);
 
@@ -1756,9 +1783,11 @@ 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 buffer->priv->highlight_syntax;
+       return priv->highlight_syntax;
 }
 
 /**
@@ -1780,13 +1809,15 @@ 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 (buffer->priv->highlight_syntax != highlight)
+       if (priv->highlight_syntax != highlight)
        {
-               buffer->priv->highlight_syntax = highlight;
+               priv->highlight_syntax = highlight;
                g_object_notify_by_pspec (G_OBJECT (buffer), buffer_properties[PROP_HIGHLIGHT_SYNTAX]);
        }
 }
@@ -1808,36 +1839,38 @@ 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 (&buffer->priv->language, language))
+       if (!g_set_object (&priv->language, language))
        {
                return;
        }
 
-       if (buffer->priv->highlight_engine != NULL)
+       if (priv->highlight_engine != NULL)
        {
                /* disconnect the old engine */
-               _gtk_source_engine_attach_buffer (buffer->priv->highlight_engine, NULL);
-               g_object_unref (buffer->priv->highlight_engine);
-               buffer->priv->highlight_engine = NULL;
+               _gtk_source_engine_attach_buffer (priv->highlight_engine, NULL);
+               g_object_unref (priv->highlight_engine);
+               priv->highlight_engine = NULL;
        }
 
        if (language != NULL)
        {
                /* get a new engine */
-               buffer->priv->highlight_engine = _gtk_source_language_create_engine (language);
+               priv->highlight_engine = _gtk_source_language_create_engine (language);
 
-               if (buffer->priv->highlight_engine != NULL)
+               if (priv->highlight_engine != NULL)
                {
-                       _gtk_source_engine_attach_buffer (buffer->priv->highlight_engine,
+                       _gtk_source_engine_attach_buffer (priv->highlight_engine,
                                                          GTK_TEXT_BUFFER (buffer));
 
-                       if (buffer->priv->style_scheme != NULL)
+                       if (priv->style_scheme != NULL)
                        {
-                               _gtk_source_engine_set_style_scheme (buffer->priv->highlight_engine,
-                                                                    buffer->priv->style_scheme);
+                               _gtk_source_engine_set_style_scheme (priv->highlight_engine,
+                                                                    priv->style_scheme);
                        }
                }
        }
@@ -1859,9 +1892,11 @@ 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 buffer->priv->language;
+       return priv->language;
 }
 
 /*
@@ -1879,11 +1914,13 @@ _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 (buffer->priv->highlight_engine != NULL)
+       if (priv->highlight_engine != NULL)
        {
-               _gtk_source_engine_update_highlight (buffer->priv->highlight_engine,
+               _gtk_source_engine_update_highlight (priv->highlight_engine,
                                                     start,
                                                     end,
                                                     synchronous);
@@ -1896,11 +1933,12 @@ _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 = buffer->priv->search_contexts; l != NULL; l = l->next)
+       for (l = priv->search_contexts; l != NULL; l = l->next)
        {
                GtkSourceSearchContext *search_context = l->data;
 
@@ -1959,16 +1997,18 @@ 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 (&buffer->priv->style_scheme, scheme))
+       if (g_set_object (&priv->style_scheme, scheme))
        {
                update_bracket_match_style (buffer);
 
-               if (buffer->priv->highlight_engine != NULL)
+               if (priv->highlight_engine != NULL)
                {
-                       _gtk_source_engine_set_style_scheme (buffer->priv->highlight_engine, scheme);
+                       _gtk_source_engine_set_style_scheme (priv->highlight_engine, scheme);
                }
 
                g_object_notify_by_pspec (G_OBJECT (buffer), buffer_properties[PROP_STYLE_SCHEME]);
@@ -1989,29 +2029,33 @@ 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 buffer->priv->style_scheme;
+       return 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 (buffer->priv->all_source_marks,
+       _gtk_source_marks_sequence_add (priv->all_source_marks,
                                        GTK_TEXT_MARK (mark));
 
        category = gtk_source_mark_get_category (mark);
-       seq = g_hash_table_lookup (buffer->priv->source_marks, category);
+       seq = g_hash_table_lookup (priv->source_marks, category);
 
        if (seq == NULL)
        {
                seq = _gtk_source_marks_sequence_new (GTK_TEXT_BUFFER (buffer));
 
-               g_hash_table_insert (buffer->priv->source_marks,
+               g_hash_table_insert (priv->source_marks,
                                     g_strdup (category),
                                     seq);
        }
@@ -2046,15 +2090,16 @@ 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 (source_buffer->priv->source_marks, category);
+               seq = g_hash_table_lookup (priv->source_marks, category);
 
                if (_gtk_source_marks_sequence_is_empty (seq))
                {
-                       g_hash_table_remove (source_buffer->priv->source_marks, category);
+                       g_hash_table_remove (priv->source_marks, category);
                }
 
                g_signal_emit (buffer, buffer_signals[SOURCE_MARK_UPDATED], 0, mark);
@@ -2069,17 +2114,21 @@ gtk_source_buffer_real_mark_deleted (GtkTextBuffer *buffer,
 static void
 gtk_source_buffer_real_undo (GtkSourceBuffer *buffer)
 {
-       g_return_if_fail (gtk_source_undo_manager_can_undo (buffer->priv->undo_manager));
+       GtkSourceBufferPrivate *priv = gtk_source_buffer_get_instance_private (buffer);
 
-       gtk_source_undo_manager_undo (buffer->priv->undo_manager);
+       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)
 {
-       g_return_if_fail (gtk_source_undo_manager_can_redo (buffer->priv->undo_manager));
+       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 (buffer->priv->undo_manager);
+       gtk_source_undo_manager_redo (priv->undo_manager);
 }
 
 /**
@@ -2137,9 +2186,11 @@ static GtkSourceMarksSequence *
 get_marks_sequence (GtkSourceBuffer *buffer,
                    const gchar     *category)
 {
+       GtkSourceBufferPrivate *priv = gtk_source_buffer_get_instance_private (buffer);
+
        return category == NULL ?
-               buffer->priv->all_source_marks :
-               g_hash_table_lookup (buffer->priv->source_marks, category);
+               priv->all_source_marks :
+               g_hash_table_lookup (priv->source_marks, category);
 }
 
 GtkSourceMark *
@@ -2380,11 +2431,13 @@ 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 (buffer->priv->all_source_marks != NULL)
+       if (priv->all_source_marks != NULL)
        {
-               return !_gtk_source_marks_sequence_is_empty (buffer->priv->all_source_marks);
+               return !_gtk_source_marks_sequence_is_empty (priv->all_source_marks);
        }
 
        return FALSE;
@@ -2582,6 +2635,7 @@ 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));
@@ -2597,13 +2651,13 @@ _gtk_source_buffer_save_and_clear_selection (GtkSourceBuffer *buffer)
                GtkTextIter insert_iter;
                GtkTextIter selection_bound_iter;
 
-               g_assert (buffer->priv->tmp_insert_mark == NULL);
-               g_assert (buffer->priv->tmp_selection_bound_mark == NULL);
+               g_assert (priv->tmp_insert_mark == NULL);
+               g_assert (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));
-               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);
+               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);
 
                gtk_text_buffer_place_cursor (buf, &insert_iter);
        }
@@ -2612,10 +2666,12 @@ _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 (buffer->priv->tmp_insert_mark != NULL &&
-           buffer->priv->tmp_selection_bound_mark != NULL)
+       if (priv->tmp_insert_mark != NULL &&
+           priv->tmp_selection_bound_mark != NULL)
        {
                GtkTextBuffer *buf;
                GtkTextIter insert_iter;
@@ -2623,15 +2679,15 @@ _gtk_source_buffer_restore_selection (GtkSourceBuffer *buffer)
 
                buf = GTK_TEXT_BUFFER (buffer);
 
-               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_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_select_range (buf, &insert_iter, &selection_bound_iter);
 
-               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;
+               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;
        }
 }
 
@@ -3148,6 +3204,8 @@ 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));
 
@@ -3155,7 +3213,7 @@ gtk_source_buffer_set_undo_manager (GtkSourceBuffer      *buffer,
        {
                manager = g_object_new (GTK_SOURCE_TYPE_UNDO_MANAGER_DEFAULT,
                                        "buffer", buffer,
-                                       "max-undo-levels", buffer->priv->max_undo_levels,
+                                       "max-undo-levels", priv->max_undo_levels,
                                        NULL);
        }
        else
@@ -3183,25 +3241,29 @@ gtk_source_buffer_set_undo_manager (GtkSourceBuffer      *buffer,
 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 buffer->priv->undo_manager;
+       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 (buffer->priv->search_contexts, search_context) != NULL)
+       if (g_list_find (priv->search_contexts, search_context) != NULL)
        {
                return;
        }
 
-       buffer->priv->search_contexts = g_list_prepend (buffer->priv->search_contexts,
+       priv->search_contexts = g_list_prepend (priv->search_contexts,
                                                        search_context);
 
        g_object_weak_ref (G_OBJECT (search_context),
@@ -3214,14 +3276,15 @@ sync_invalid_char_tag (GtkSourceBuffer *buffer,
                       GParamSpec      *pspec,
                       gpointer         data)
 {
+       GtkSourceBufferPrivate *priv = gtk_source_buffer_get_instance_private (buffer);
        GtkSourceStyle *style = NULL;
 
-       if (buffer->priv->style_scheme != NULL)
+       if (priv->style_scheme != NULL)
        {
-               style = gtk_source_style_scheme_get_style (buffer->priv->style_scheme, "def:error");
+               style = gtk_source_style_scheme_get_style (priv->style_scheme, "def:error");
        }
 
-       gtk_source_style_apply (style, buffer->priv->invalid_char_tag);
+       gtk_source_style_apply (style, priv->invalid_char_tag);
 }
 
 static void
@@ -3241,9 +3304,11 @@ _gtk_source_buffer_set_as_invalid_character (GtkSourceBuffer   *buffer,
                                             const GtkTextIter *start,
                                             const GtkTextIter *end)
 {
-       if (buffer->priv->invalid_char_tag == NULL)
+       GtkSourceBufferPrivate *priv = gtk_source_buffer_get_instance_private (buffer);
+
+       if (priv->invalid_char_tag == NULL)
        {
-               buffer->priv->invalid_char_tag = gtk_text_buffer_create_tag (GTK_TEXT_BUFFER (buffer),
+               priv->invalid_char_tag = gtk_text_buffer_create_tag (GTK_TEXT_BUFFER (buffer),
                                                                             "invalid-char-style",
                                                                             NULL);
 
@@ -3258,11 +3323,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 (buffer->priv->invalid_char_tag,
+       text_tag_set_highest_priority (priv->invalid_char_tag,
                                       GTK_TEXT_BUFFER (buffer));
 
        gtk_text_buffer_apply_tag (GTK_TEXT_BUFFER (buffer),
-                                  buffer->priv->invalid_char_tag,
+                                  priv->invalid_char_tag,
                                   start,
                                   end);
 }
@@ -3270,19 +3335,20 @@ _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 (buffer->priv->invalid_char_tag == NULL)
+       if (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, buffer->priv->invalid_char_tag) ||
-           gtk_text_iter_forward_to_tag_toggle (&start, buffer->priv->invalid_char_tag))
+       if (gtk_text_iter_starts_tag (&start, priv->invalid_char_tag) ||
+           gtk_text_iter_forward_to_tag_toggle (&start, priv->invalid_char_tag))
        {
                return TRUE;
        }
@@ -3317,13 +3383,15 @@ 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 (buffer->priv->implicit_trailing_newline != implicit_trailing_newline)
+       if (priv->implicit_trailing_newline != implicit_trailing_newline)
        {
-               buffer->priv->implicit_trailing_newline = implicit_trailing_newline;
+               priv->implicit_trailing_newline = implicit_trailing_newline;
                g_object_notify_by_pspec (G_OBJECT (buffer), 
buffer_properties[PROP_IMPLICIT_TRAILING_NEWLINE]);
        }
 }
@@ -3338,9 +3406,11 @@ 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 buffer->priv->implicit_trailing_newline;
+       return priv->implicit_trailing_newline;
 }
 
 /**
@@ -3405,7 +3475,9 @@ 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 buffer->priv->has_draw_spaces_tag;
+       return priv->has_draw_spaces_tag;
 }
diff --git a/gtksourceview/gtksourcebuffer.h b/gtksourceview/gtksourcebuffer.h
index 40307380..c6dda139 100644
--- a/gtksourceview/gtksourcebuffer.h
+++ b/gtksourceview/gtksourcebuffer.h
@@ -33,15 +33,10 @@
 
 G_BEGIN_DECLS
 
-#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))
+#define GTK_SOURCE_TYPE_BUFFER (gtk_source_buffer_get_type())
 
-typedef struct _GtkSourceBufferClass           GtkSourceBufferClass;
-typedef struct _GtkSourceBufferPrivate         GtkSourceBufferPrivate;
+GTK_SOURCE_AVAILABLE_IN_ALL
+G_DECLARE_DERIVABLE_TYPE (GtkSourceBuffer, gtk_source_buffer, GTK_SOURCE, BUFFER, GtkTextBuffer)
 
 /**
  * GtkSourceBracketMatchType:
@@ -93,13 +88,6 @@ typedef enum _GtkSourceSortFlags
        GTK_SOURCE_SORT_FLAGS_REMOVE_DUPLICATES = 1 << 2,
 } GtkSourceSortFlags;
 
-struct _GtkSourceBuffer
-{
-       GtkTextBuffer parent_instance;
-
-       GtkSourceBufferPrivate *priv;
-};
-
 struct _GtkSourceBufferClass
 {
        GtkTextBufferClass parent_class;
@@ -117,160 +105,121 @@ struct _GtkSourceBufferClass
 };
 
 GTK_SOURCE_AVAILABLE_IN_ALL
-GType                   gtk_source_buffer_get_type                             (void) G_GNUC_CONST;
-
+GtkSourceBuffer       *gtk_source_buffer_new                                   (GtkTextTagTable         
*table);
 GTK_SOURCE_AVAILABLE_IN_ALL
-GtkSourceBuffer                *gtk_source_buffer_new                                  (GtkTextTagTable      
  *table);
-
+GtkSourceBuffer       *gtk_source_buffer_new_with_language                     (GtkSourceLanguage       
*language);
 GTK_SOURCE_AVAILABLE_IN_ALL
-GtkSourceBuffer        *gtk_source_buffer_new_with_language                    (GtkSourceLanguage      
*language);
-
+gboolean               gtk_source_buffer_get_highlight_syntax                  (GtkSourceBuffer         
*buffer);
 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);
-
+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);
-
+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);
-
+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);
-
+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);
-
+void                   gtk_source_buffer_set_max_undo_levels                   (GtkSourceBuffer         
*buffer,
+                                                                                gint                     
max_undo_levels);
 GTK_SOURCE_AVAILABLE_IN_ALL
-GtkSourceLanguage      *gtk_source_buffer_get_language                         (GtkSourceBuffer        
*buffer);
-
+GtkSourceLanguage     *gtk_source_buffer_get_language                          (GtkSourceBuffer         
*buffer);
 GTK_SOURCE_AVAILABLE_IN_ALL
-void                    gtk_source_buffer_set_language                         (GtkSourceBuffer        
*buffer,
-                                                                                GtkSourceLanguage      
*language);
-
+void                   gtk_source_buffer_set_language                          (GtkSourceBuffer         
*buffer,
+                                                                                GtkSourceLanguage       
*language);
 GTK_SOURCE_AVAILABLE_IN_ALL
-gboolean                gtk_source_buffer_can_undo                             (GtkSourceBuffer        
*buffer);
-
+gboolean               gtk_source_buffer_can_undo                              (GtkSourceBuffer         
*buffer);
 GTK_SOURCE_AVAILABLE_IN_ALL
-gboolean                gtk_source_buffer_can_redo                             (GtkSourceBuffer        
*buffer);
-
+gboolean               gtk_source_buffer_can_redo                              (GtkSourceBuffer         
*buffer);
 GTK_SOURCE_AVAILABLE_IN_ALL
-GtkSourceStyleScheme    *gtk_source_buffer_get_style_scheme                    (GtkSourceBuffer        
*buffer);
-
+GtkSourceStyleScheme  *gtk_source_buffer_get_style_scheme                      (GtkSourceBuffer         
*buffer);
 GTK_SOURCE_AVAILABLE_IN_ALL
-void                    gtk_source_buffer_set_style_scheme                     (GtkSourceBuffer        
*buffer,
-                                                                                GtkSourceStyleScheme   
*scheme);
-
+void                   gtk_source_buffer_set_style_scheme                      (GtkSourceBuffer         
*buffer,
+                                                                                GtkSourceStyleScheme    
*scheme);
 GTK_SOURCE_AVAILABLE_IN_ALL
-void                    gtk_source_buffer_ensure_highlight                     (GtkSourceBuffer        
*buffer,
-                                                                                const GtkTextIter      
*start,
-                                                                                const GtkTextIter      *end);
-
+void                   gtk_source_buffer_ensure_highlight                      (GtkSourceBuffer         
*buffer,
+                                                                                const GtkTextIter       
*start,
+                                                                                const GtkTextIter       
*end);
 GTK_SOURCE_AVAILABLE_IN_ALL
-void                    gtk_source_buffer_undo                                 (GtkSourceBuffer        
*buffer);
-
+void                   gtk_source_buffer_undo                                  (GtkSourceBuffer         
*buffer);
 GTK_SOURCE_AVAILABLE_IN_ALL
-void                    gtk_source_buffer_redo                                 (GtkSourceBuffer        
*buffer);
-
+void                   gtk_source_buffer_redo                                  (GtkSourceBuffer         
*buffer);
 GTK_SOURCE_AVAILABLE_IN_ALL
-void                    gtk_source_buffer_begin_not_undoable_action            (GtkSourceBuffer        
*buffer);
-
+void                   gtk_source_buffer_begin_not_undoable_action             (GtkSourceBuffer         
*buffer);
 GTK_SOURCE_AVAILABLE_IN_ALL
-void                    gtk_source_buffer_end_not_undoable_action              (GtkSourceBuffer        
*buffer);
-
+void                   gtk_source_buffer_end_not_undoable_action               (GtkSourceBuffer         
*buffer);
 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);
-
+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);
-
+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_set_undo_manager                      (GtkSourceBuffer         
*buffer,
+                                                                                GtkSourceUndoManager    
*manager);
 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);
-
+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,
-                                                                                ...);
+GtkTextTag            *gtk_source_buffer_create_source_tag                     (GtkSourceBuffer         
*buffer,
+                                                                                const gchar             
*tag_name,
+                                                                                const gchar             
*first_property_name,
+                                                                                ...);
+
 
 G_END_DECLS


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