代码拉取完成,页面将自动刷新
import re
import sublime
import sublime_plugin
import unicodedata
def visual_width(view, pt, tabsize):
width = 0
while pt>0 and view.rowcol(pt)[1]>0:
pt -= 1
c = view.substr(pt)
if ord(c) < 255:
width += 1
else:
c = unicodedata.east_asian_width(c)
width += c in ("F", "W") and 2 or 1
return width
class ColAlignCommand(sublime_plugin.TextCommand):
def run(self, edit, follow="\n; ,([{:"):
view = self.view
origin = []
maxwidth = 0
offset = 0
tabSize = view.settings().get('tab_size')
regions = view.sel()
if len(regions) == 1:
region = regions[0]
pos = region.begin()
end = region.end()
col = view.rowcol(pos)[1]
line = view.line(pos - 1)
if pos == end and re.match(r'^( )+;-{2,}$', view.substr(line)):
view.insert(edit, pos, "-" * (54 - col))
else:
view.insert(edit, pos, " "*(tabSize - col % tabSize))
return
for region in regions:
lines = view.lines(region)
if len(lines)!=1:
view.run_command("indent")
return
pos = region.begin()
while view.substr(pos) == " ": pos+=1
while pos > 0:
if view.substr(pos - 1) in follow:
break
pos -= 1
width = visual_width(view, pos, tabSize)
origin.append((pos, width))
if maxwidth < width:
maxwidth = width + width % 2
origin.sort()
count = 0
for (pos, width) in origin:
width = maxwidth - width
if width>0:
view.insert(edit, pos+offset, " " * width)
count+=1
offset+=width
if count == 0:
for (pos, width) in origin:
if(width != -1):
view.insert(edit, pos+offset, " ")
offset+=1
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。