Skip to content

Instantly share code, notes, and snippets.

@phillipberndt
Created May 26, 2015 09:28
Show Gist options
  • Save phillipberndt/67055649d869d065cb3c to your computer and use it in GitHub Desktop.
Save phillipberndt/67055649d869d065cb3c to your computer and use it in GitHub Desktop.
#include <gtk/gtk.h>
void main() {
GtkTextIter start, end, inspos, tagpos;
gsize length;
GtkTextBuffer *buffer = gtk_text_buffer_new(NULL);
GtkTextTag *tag1 = gtk_text_buffer_create_tag(buffer, "tagone", NULL);
GtkTextTag *tag2 = gtk_text_buffer_create_tag(buffer, "tagtwo", NULL);
gtk_text_buffer_get_iter_at_mark(buffer, &inspos, gtk_text_buffer_get_insert(buffer));
gtk_text_buffer_insert_interactive(buffer, &inspos, "tag1", 4, TRUE);
gtk_text_iter_backward_chars(&inspos, 4);
gtk_text_buffer_get_iter_at_mark(buffer, &tagpos, gtk_text_buffer_get_insert(buffer));
gtk_text_buffer_apply_tag(buffer, tag1, &inspos, &tagpos);
gtk_text_buffer_get_iter_at_mark(buffer, &inspos, gtk_text_buffer_get_insert(buffer));
gtk_text_buffer_insert_interactive(buffer, &inspos, "tags12", 6, TRUE);
gtk_text_iter_backward_chars(&inspos, 6);
gtk_text_buffer_get_iter_at_mark(buffer, &tagpos, gtk_text_buffer_get_insert(buffer));
gtk_text_buffer_apply_tag(buffer, tag1, &inspos, &tagpos);
gtk_text_buffer_apply_tag(buffer, tag2, &inspos, &tagpos);
gtk_text_buffer_get_iter_at_mark(buffer, &inspos, gtk_text_buffer_get_insert(buffer));
gtk_text_buffer_insert_interactive(buffer, &inspos, "notags", 6, TRUE);
gtk_text_buffer_get_start_iter(buffer, &start);
gtk_text_buffer_get_end_iter(buffer, &end);
GdkAtom format = gtk_text_buffer_register_serialize_tagset(buffer, NULL);
guint8 *serialized = gtk_text_buffer_serialize(buffer, buffer, format, &start, &end, &length);
write(1, serialized, length);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment