Fievel work for python3 support

This commit is contained in:
David Beniamine
2016-09-05 15:26:03 +02:00
5 changed files with 13 additions and 13 deletions

View File

@@ -7,5 +7,5 @@
# Website: http://github.com/freitass/todo.txt-vim # Website: http://github.com/freitass/todo.txt-vim
# Version: 0.1 # Version: 0.1
from after import regex_date_after from dateregex.after import regex_date_after
from before import regex_date_before from dateregex.before import regex_date_before

View File

@@ -20,7 +20,7 @@ def _year_regex_after(year):
regex = '|' + year[0:idx] regex = '|' + year[0:idx]
regex += '9' if digit == '8' else '[%s-9]' % str(int(digit) + 1) regex += '9' if digit == '8' else '[%s-9]' % str(int(digit) + 1)
if idx < len(year) - 1: if idx < len(year) - 1:
regex += '\d{%s}' % (len(year) - (idx + 1)) regex += '\d{%s}' % (len(year) - (idx + 1))
year_regex += regex year_regex += regex
year_regex += ')' year_regex += ')'
@@ -40,7 +40,7 @@ def _month_regex_after(year, month):
if digit2 == '8': if digit2 == '8':
month_regex = r'(' + month_regex + r'|09)' month_regex = r'(' + month_regex + r'|09)'
else: else:
month_regex = r'(' + month_regex + r'|0[%s-9])' month_regex = r'(' + month_regex + r'|0[%s-9])'
month_regex = month_regex % str(int(digit2) + 1) month_regex = month_regex % str(int(digit2) + 1)
return '-'.join((year, month_regex, r'\d{2}')) return '-'.join((year, month_regex, r'\d{2}'))

View File

@@ -10,7 +10,7 @@
from datetime import date, timedelta, MINYEAR from datetime import date, timedelta, MINYEAR
def _year_regex_before(year): def _year_regex_before(year):
if int(year) <= MINYEAR: if int(year) <= MINYEAR:
return None return None
year_regex = r'(' year_regex = r'('
year_regex += r'\d{1,%s}' % str(len(year) - 1) if len(year) > 1 else '' year_regex += r'\d{1,%s}' % str(len(year) - 1) if len(year) > 1 else ''
@@ -19,12 +19,11 @@ def _year_regex_before(year):
regex = '|' + year[0:idx] regex = '|' + year[0:idx]
regex += '0' if digit == '1' else '[0-%s]' % str(int(digit) - 1) regex += '0' if digit == '1' else '[0-%s]' % str(int(digit) - 1)
if idx < len(year) - 1: if idx < len(year) - 1:
regex += '\d{%s}' % (len(year) - (idx + 1)) regex += '\d{%s}' % (len(year) - (idx + 1))
year_regex += regex year_regex += regex
year_regex += ')' year_regex += ')'
return '-'.join((year_regex, r'\d{2}', r'\d{2}')) return '-'.join((year_regex, r'\d{2}', r'\d{2}'))
def _month_regex_before(year, month): def _month_regex_before(year, month):
if month == '01': if month == '01':
return None return None
@@ -33,7 +32,7 @@ def _month_regex_before(year, month):
if digit1 == '0': if digit1 == '0':
month_regex = '01' if month == '02' else r'0[1-%s]' % str(int(digit2) - 1) month_regex = '01' if month == '02' else r'0[1-%s]' % str(int(digit2) - 1)
elif month == '10': elif month == '10':
month_regex = r'0\d' month_regex = r'0\d'
elif month == '11': elif month == '11':
month_regex = r'(0\d|10)' month_regex = r'(0\d|10)'
else: else:
@@ -63,7 +62,6 @@ def _day_regex_before(year, month, day):
return '-'.join((year, month, day_regex)) return '-'.join((year, month, day_regex))
def regex_date_before(given_date): def regex_date_before(given_date):
year, month, day = given_date.isoformat().split('-') year, month, day = given_date.isoformat().split('-')

View File

@@ -16,11 +16,11 @@ if os.path.isdir(dateregex_dir):
sys.path.insert(0, dateregex_dir) sys.path.insert(0, dateregex_dir)
def add_due_date_syntax_highlight(): def add_due_date_syntax_highlight():
try: try:
from dateregex import regex_date_before from dateregex import regex_date_before
except ImportError: except ImportError:
print("dateregex module not found. Overdue dates won't be highlighted") print("dateregex module not found. Overdue dates won't be highlighted")
return return
regex = regex_date_before(date.today()) regex = regex_date_before(date.today())
regex = r'(^|<)due:%s(>|$)' % regex regex = r'(^|<)due:%s(>|$)' % regex

View File

@@ -51,10 +51,12 @@ highlight default link TodoDate PreProc
highlight default link TodoProject Special highlight default link TodoProject Special
highlight default link TodoContext Special highlight default link TodoContext Special
let b:curdir = expand('<sfile>:p:h')
let s:script_dir = b:curdir . "/python/"
if has('python') if has('python')
let b:curdir = expand('<sfile>:p:h')
let s:script_dir = b:curdir . "/python/"
execute "pyfile " . s:script_dir. "todo.py" execute "pyfile " . s:script_dir. "todo.py"
elseif has('python3')
execute "py3file " . s:script_dir. "todo.py"
endif endif
let b:current_syntax = "todo" let b:current_syntax = "todo"