@register(u'transpose-chars')
def transpose_chars(event):
 b = event.current_buffer
 p = b.cursor_position
 if (p == 0):
  return
 elif ((p == len(b.text)) or (b.text[p] == u'\n')):
  b.swap_characters_before_cursor()
 else:
  b.cursor_position += b.document.get_cursor_right_position()
  b.swap_characters_before_cursor()

@ register ( u'transpose-chars' ) def transpose_chars ( event ) : b = event . current_buffer p = b . cursor_position if ( p == 0 ) : return elif ( ( p == len ( b . text ) ) or ( b . text [ p ] == u'\n' ) ) : b . swap_characters_before_cursor ( ) else : b . cursor_position += b . document . get_cursor_right_position ( ) b . swap_characters_before_cursor ( )
emulate emacs transpose-char behavior: at the beginning of the buffer .