1 # Coding = UTF-8 2 Import sublime, sublime_plugin 3 4 class autoalignmentcommand (sublime_plugin.textcommand): 5 def run (self, edit ): 6 pre_row =-1 7 pos_max_x = 0.0 8 for Region in self. view. sel (): 9 (row, col) = self. view. rowcol (region. begin () 10 if ROW = pre_row: 11 sublime. error_message (U "cannot select two locations in the same row !! ") 12 return13 pre_row = row14 point_end = region. end () 15 vec_pos = self. view. text_to_layout (point_end) 16 if vec_pos [0]> pos_max_x: 17 print vec_pos [0] 18 pos_max_x = vec_pos [0] 19 20 for Region in self. view. sel (): 21 pos_cur_x = self. view. text_to_layout (region. end () [0] 22 print "pos_cur_x", pos_cur_x23 if pos_cur_x <pos_max_x: 24 self. view. insert (edit, region. end (), "\ t ")
The effect is as follows:
After twice
Http://www.sublimetext.com/docs/2/api_reference.html
Sublime text alignment