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

posted on   明天有风吹  阅读(1900)  评论(0编辑  收藏  举报

编辑推荐:
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通

导航

+V atob('d2h5X251bGw=')

请备注:from博客园

点击右上角即可分享
微信分享提示