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"不能在同一行选中两个位置!!") 12 return 13 pre_row = row 14 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_x 23 if pos_cur_x < pos_max_x: 24 self.view.insert(edit, region.end(), "\t")
效果如下:
用两次之后
http://www.sublimetext.com/docs/2/api_reference.html
时间: 2024-10-17 18:23:32