def run(self, edit):
today = datetime.date.today()
month_name = calendar.month_name[today.month]
# find line that match month and day in same line
m_regex = (r"^\s+{month}\:.+[\s\.]{day}[{norm_sym}{done_sym}].*$"
.format(month=month_name,
day=today.day,
norm_sym=NORMAL_SYMBOL,
done_sym=DONE_SYMBOL))
found_region = self.view.find(m_regex, 0)
if found_region != NOT_FOUND:
line_r = self.view.line(found_region)
line = self.view.substr(line_r)
day_format = get_weekday_format(today.year, today.month, today.day)
with_symbol = ("{day}{done_sym} "
.format(day=day_format.rstrip(' '),
done_sym=DONE_SYMBOL))
if with_symbol in line:
day_str = with_symbol
scope = "today.done.chain"
else:
day_str = day_format
scope = "today.chain"
start_i = found_region.begin() + line.index(day_str)
end_i = start_i + len(day_str)
# highlight region, reversed start/end
# so that the cursor starts from the beginning
# regions.add(sublime.Region(end_i, start_i))
self.view.erase_regions(TODAY_KEY)
regions = [sublime.Region(end_i, start_i)]
self.view.add_regions(
TODAY_KEY,
regions,
scope,
"dot",
sublime.DRAW_SQUIGGLY_UNDERLINE
)
评论列表
文章目录