码迷,mamicode.com
首页 > 其他好文 > 详细

sublime text 另一种对齐

时间:2014-09-29 21:11:21      阅读:234      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   io   os   for   sp   div   

 

 

 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")

 

 

效果如下:

bubuko.com,布布扣

 

用两次之后

 

bubuko.com,布布扣

 

 

 

http://www.sublimetext.com/docs/2/api_reference.html

sublime text 另一种对齐

标签:style   blog   http   color   io   os   for   sp   div   

原文地址:http://www.cnblogs.com/hangj/p/4000823.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!