The operations between TextBuffer.BeginUserAction() and TextBuffer.EndUserAction() can then be grouped when creating an undo stack. Gtk.TextBuffer maintains a count of calls to TextBuffer.BeginUserAction() that have not been closed with a call to TextBuffer.EndUserAction(), and emits TextBuffer.UserActionBegun and TextBuffer.UserActionEnded signals only for the outermost pair of calls. This allows you to build user actions from other user actions.
The "interactive" buffer mutation functions, such as TextBuffer.InsertInteractive(), automatically call begin/end user action around the buffer operations they perform, so there is no need to add extra calls if you user action consists solely of a single call to one of those functions.