1
2
3
4
5
6
buf = window.get_active_doc().get_buffer()
start, end = buf.get_selection_bounds()
if start:
    selection = buf.get_text(start, end)
    buf.delete_selection(True, True)
    buf.insert_at_cursor(selection.upper())