def newline_with_copy_margin(event):
 b = event.current_buffer
 cursor_start_pos = b.document.cursor_position_col
 b.newline(copy_margin=True)
 b.cursor_up(count=1)
 cursor_end_pos = b.document.cursor_position_col
 if (cursor_start_pos != cursor_end_pos):
  pos_diff = (cursor_start_pos - cursor_end_pos)
  b.cursor_right(count=pos_diff)

def newline_with_copy_margin ( event ) : b = event . current_buffer cursor_start_pos = b . document . cursor_position_col b . newline ( copy_margin = True ) b . cursor_up ( count = 1 ) cursor_end_pos = b . document . cursor_position_col if ( cursor_start_pos != cursor_end_pos ) : pos_diff = ( cursor_start_pos - cursor_end_pos ) b . cursor_right ( count = pos_diff )
preserve margin and cursor position when using control-o to insert a newline in emacs mode .