gtksourceview.SourceBuffer
Prev |  | Next

## gtksourceview.SourceBuffer

gtksourceview.SourceBuffer — Text buffer object for gtksourceview.SourceView

## Synopsis

    class gtksourceview.SourceBuffer(gtk.TextBuffer):
        gtksourceview.SourceBuffer(buffer=None)
        def set_check_brackets(check_brackets)
        def get_check_brackets()
        def set_bracket_match_style(style)
        def set_highlight(highlight)
        def get_highlight()
        def set_max_undo_levels(max_undo_levels)
        def get_max_undo_levels()
        def set_language(language)
        def get_language()
        def set_escape_char(escape_char)
        def get_escape_char()
        def can_undo()
        def can_redo()
        def undo()
        def redo()
        def begin_not_undoable_action()
        def end_not_undoable_action()

    Functions

        def gtksourceview.gtk_source_buffer_new_with_language(gtksourceview.SourceLanguage)

## Ancestry

    +-- gobject.GObject
      +-- gtk.TextBuffer
        +-- gtksourceview.SourceBuffer

## Properties

"check-brackets" | Read-Write | If `TRUE` bracket match highlighting is activated.
"escape-char" | Read-Write | Escaping character for syntax patterns.
"highlight" | Read-Write | If `TRUE` the syntax highlighting is activated.
"language" | Read-Write | Language object to get highlighting patterns from.
"max-undo-levels" | Read-Write | Number of undo levels for the buffer.

## Description

The `gtksourceview.SourceBuffer` is the model for `gtksourceview.SourceView` widgets. It extends the `gtk.TextBuffer` object by adding features necessary to display and edit source code. It also implements support for undo/redo operations.

To create a `gtksourceview.SourceBuffer` use `gtksourceview.gtk_source_buffer_new`() or `gtksourceview.gtk_source_buffer_new_with_language`. The second form is just a convenience function which allows you to initially set a `gtksourceview.SourceLanguage`.

By default highlighting is enabled, but you can disable it with `set_highlight`(). This can be useful if you're not using `gtksourceview.SourceLanguage` objects to set the highlighting patterns, and instead you're manually adding `gtksourceview.SourceTag` objects to the buffer's tag table.

## Constructor

        gtksourceview.SourceBuffer(table=None)

`table` : | a `gtksourceview.SourceTagTable` or `None`
Returns : | a new `gtksourceview.SourceBuffer`.

Creates a new `gtksourceview.SourceBuffer` object.

## Methods

### gtksourceview.SourceBuffer.set_check_brackets

        def set_check_brackets(check_brackets)

`check_brackets` : | if `TRUE` turns on the matching brackets highlight.

The `set_check_brackets`() method controls the bracket match highlighting function in the buffer. If activated, when you position your cursor over a bracket character (a parenthesis, a square bracket, etc.) the matching opening or closing bracket character will be highlighted. You can specify the style with the `set_bracket_match_style` function.

### gtksourceview.SourceBuffer.get_check_brackets

        def get_check_brackets()

Returns : | `TRUE` if the matching brackets highlight is active, `FALSE` otherwise.

The `get_check_brackets`() method returns the value of the "check-brackets" property which determines if the matching brackets highlight is active.

### gtksourceview.SourceBuffer.set_bracket_match_style

        def set_bracket_match_style(style)

`style` : | the `gtksourceview.SourceTagStyle` specifying colors and text attributes.

The `set_bracket_match_style`() method sets the style used for highlighting matching brackets.

### gtksourceview.SourceBuffer.set_highlight

        def set_highlight(highlight)

`highlight` : | if `TRUE` turns on the source highlighting.

The `set_highlight`() method controls whether text is highlighted in the buffer. If `highlight` is `TRUE` , the text will be highlighted according to the patterns installed in the buffer (either set with `set_language` or by adding individual `gtksourceview.SourceTag` tags to the buffer's tag table). Otherwise, any current highlighted text will be restored to the default buffer style.

Tags not of `gtksourceview.SourceTag` type will not be removed by this option, and normal GtkTextTag priority settings apply when highlighting is enabled.

If not using a `gtksourceview.SourceLanguage` for setting the highlighting patterns in the buffer, it is recommended for performance reasons that you add all the `gtksourceview.SourceTag` tags with highlighting disabled and enable it when finished.

### gtksourceview.SourceBuffer.get_highlight

        def get_highlight()

Returns : | `TRUE` if the source highlighting is active, `FALSE` otherwise.

The `get_highlight`() method returns the value of the "highlight" property which determines if the text highlighting is active.

### gtksourceview.SourceBuffer.set_max_undo_levels

        def set_max_undo_levels(max_undo_levels)

`max_undo_levels` : | the desired maximum number of undo levels.

The `set_max_undo_levels`() method 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.

A new action is started whenever the function `begin_user_action` is called. In general, this happens whenever the user presses any key which modifies the buffer, but the undo manager will try to merge similar consecutive actions, such as multiple character insertions into one action. But, inserting a newline does start a new action.

### gtksourceview.SourceBuffer.get_max_undo_levels

        def get_max_undo_levels()

Returns : | the maximum number of possible undo levels.

The `get_max_undo_levels`() method returns the value of the "max-undo-levels" property which determines the number of undo levels the buffer will track for buffer edits.

### gtksourceview.SourceBuffer.set_language

        def set_language(language)

`language` : | A `gtksourceview.SourceLanguage` or `None`.

The `set_check_brackets`() method Sets the `gtksourceview.SourceLanguage` the source buffer will use, adding `gtksourceview.SourceTag` tags with the language's patterns and setting the escape character with `set_escape_char`. Note that this will remove any `gtksourceview.SourceTag` tags currently in the buffer's tag table. The buffer holds a reference to the `language` set.

### gtksourceview.SourceBuffer.get_language

        def get_language()

Returns : | the `gtksourceview.SourceLanguage` set by `set_language`.

The `get_check_brackets`() method determines the `gtksourceview.SourceLanguage` used by the buffer. The returned object should not be unreferenced by the user.

### gtksourceview.SourceBuffer.set_escape_char

        def set_escape_char(escape_char)

`escape_char` : | the escape character the buffer should use.

The `set_check_brackets`() method sets the escape character to be used by the highlighting engine.

When performing the initial analysis, the engine will discard a matching syntax pattern if it's prefixed with an odd number of escape characters. This allows for example to correctly highlight strings with escaped quotes embedded.

This setting affects only syntax patterns (i.e. those defined in `gtksourceview.SourceTag` tags).

### gtksourceview.SourceBuffer.get_escape_char

        def get_escape_char()

Returns : | the UTF-8 character for the escape character the buffer is using.

The `get_escape_char`() method determines the escaping character used by the source buffer highlighting engine.

### gtksourceview.SourceBuffer.can_undo

        def can_undo()

Returns : | `TRUE` if it's possible to undo the last action.

The `can_undo`() method determines whether a source buffer can undo the last action.

### gtksourceview.SourceBuffer.can_redo

        def can_redo()

Returns : | `TRUE` if a redo is possible.

The `can_redo`() method Determines whether a source buffer can redo the last action (i.e. if the last operation was an undo).

### gtksourceview.SourceBuffer.undo

        def undo()

The `undo`() Undoes the last user action which modified the buffer. Use `can_undo` to check whether a call to this function will have any effect.

Actions are defined as groups of operations between a call to `begin_user_action`() and `end_user_action`(), or sequences of similar edits (inserts or deletes) on the same line.

### gtksourceview.SourceBuffer.redo

        def redo()

The `redo`() method redoes the last undo operation. Use `can_redo` to check whether a call to this function will have any effect.

### gtksourceview.SourceBuffer.begin_not_undoable_action

        def begin_not_undoable_action()

The `begin_not_undoable_action`() 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 `begin_not_undoable_action`() / `end_not_undoable_action`() blocks.

### gtksourceview.SourceBuffer.end_not_undoable_action

        def end_not_undoable_action()

The `end_not_undoable_action`() method 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.

## Functions

### gtksourceview.SourceBuffer.gtk_source_buffer_new_with_language

        def gtksourceview.SourceBuffer.gtk_source_buffer_new_with_language(language)

`language` : | a `gtksourceview.SourceLanguage`.
Returns : | a new source buffer which will highlight text according to `language`.

Creates a new source buffer using the highlighting patterns in `language`. This is equivalent to creating a new source buffer with the default tag table and then calling `set_language`

Prev |  | Next
gtksourceview.SourceView | Home | gtksourceview.SourceLanguage