sublime text 另一种对齐
效果如下:
http://sublime-text-unofficial-documentation.readthedocs.org/en/latest/extensibility/plugins.html
1 #coding=utf-8 2 import sublime, sublime_plugin 3 4 class AutoAlignmentCommand(sublime_plugin.TextCommand): 5 def auto_align(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 -1 13 pre_row = row 14 point_begin = region.begin() 15 vec_pos = self.view.text_to_layout(point_begin) 16 if vec_pos[0] > pos_max_x: 17 print (vec_pos[0]) 18 pos_max_x = vec_pos[0] 19 20 is_finished = True 21 for region in self.view.sel(): 22 pos_cur_x = self.view.text_to_layout(region.begin())[0] 23 print ("pos_cur_x:", pos_cur_x) 24 if pos_cur_x < pos_max_x: 25 self.view.insert(edit, region.begin(), "\t") 26 is_finished = False 27 28 return is_finished 29 30 def run(self, edit): 31 count = 0 32 while True: 33 # 防止死循环,最多循环50次 34 count = count + 1 35 ret = self.auto_align(edit) 36 if count > 50 or ret == -1 or ret == True: 37 return
http://www.sublimetext.com/docs/2/api_reference.html
+V why_null 请备注:from博客园