mirror of
https://github.com/tbabej/taskwiki.git
synced 2025-08-19 15:53:07 +02:00
Restructure the whole plugin
This commit is contained in:
parent
17e7047565
commit
fb90391538
6 changed files with 67 additions and 44 deletions
|
@ -1 +0,0 @@
|
|||
# (c) 2014, Tomas Babej
|
|
@ -1,5 +1,5 @@
|
|||
let s:plugin_path = escape(expand('<sfile>:p:h'), '\')
|
||||
execute 'pyfile ' . s:plugin_path . '/../autoload/taskwiki.py'
|
||||
let s:plugin_path = escape(expand('<sfile>:p:h:h'), '\')
|
||||
execute 'pyfile ' . s:plugin_path . '/taskwiki/taskwiki.py'
|
||||
|
||||
augroup taskwiki
|
||||
" when saving the file sync the tasks from vimwiki to TW
|
||||
|
|
0
autoload/.gitignore → taskwiki/.gitignore
vendored
0
autoload/.gitignore → taskwiki/.gitignore
vendored
1
taskwiki/__init__.py
Normal file
1
taskwiki/__init__.py
Normal file
|
@ -0,0 +1 @@
|
|||
# (c) 2014-2015, Tomas Babej
|
45
taskwiki/regexp.py
Normal file
45
taskwiki/regexp.py
Normal file
|
@ -0,0 +1,45 @@
|
|||
import re
|
||||
|
||||
# Unnamed building blocks
|
||||
UUID_UNNAMED = r'[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}'
|
||||
DUE_UNNAMED = r'\(\d{4}-\d\d-\d\d( \d\d:\d\d)?\)'
|
||||
SPACE_UNNAMED = r'\s*'
|
||||
NONEMPTY_SPACE_UNNAMED = r'\s+'
|
||||
FINAL_SEGMENT_SEPARATOR_UNNAMED = r'(\s+|$)'
|
||||
|
||||
TEXT_FORBIDDEN_SUFFIXES = (
|
||||
r'\s', # Text cannot end with whitespace
|
||||
r' !', r' !!', r' !!!', # Any priority value
|
||||
r'\(\d{4}-\d\d-\d\d\)', r'\(\d{4}-\d\d-\d\d \d\d:\d\d\)', # Any datetime value
|
||||
r'\(\d{4}-\d\d-\d\d', # Any datetime value
|
||||
UUID_UNNAMED, # Text cannot end with UUID
|
||||
)
|
||||
|
||||
# Building blocks
|
||||
BRACKET_OPENING = re.escape('* [')
|
||||
BRACKET_CLOSING = re.escape('] ')
|
||||
EMPTY_SPACE = r'(?P<space>\s*)'
|
||||
UUID = r'(?P<uuid>{0})'.format(UUID_UNNAMED)
|
||||
DUE = r'(?P<due>{0})'.format(DUE_UNNAMED)
|
||||
UUID_COMMENT = '#{0}'.format(UUID)
|
||||
TEXT = r'(?P<text>.+' + ''.join(['(?<!%s)' % suffix for suffix in TEXT_FORBIDDEN_SUFFIXES]) + ')'
|
||||
COMPLETION_MARK = r'(?P<completed>.)'
|
||||
PRIORITY = r'(?P<priority>!{1,3})'
|
||||
|
||||
GENERIC_TASK = re.compile(''.join([
|
||||
EMPTY_SPACE,
|
||||
BRACKET_OPENING,
|
||||
COMPLETION_MARK,
|
||||
BRACKET_CLOSING,
|
||||
TEXT,
|
||||
FINAL_SEGMENT_SEPARATOR_UNNAMED,
|
||||
'(', PRIORITY, FINAL_SEGMENT_SEPARATOR_UNNAMED, ')?'
|
||||
'(', DUE, FINAL_SEGMENT_SEPARATOR_UNNAMED, ')?'
|
||||
'(', UUID_COMMENT, FINAL_SEGMENT_SEPARATOR_UNNAMED, ')?' # UUID is not there for new tasks
|
||||
]))
|
||||
|
||||
PROJECT_DEFINITION = re.compile(r'Project: (?P<project>.*)(?<!\s)')
|
||||
|
||||
DATETIME_FORMAT = "(%Y-%m-%d %H:%M)"
|
||||
DATE_FORMAT = "(%Y-%m-%d)"
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
import copy
|
||||
import pytz
|
||||
import re
|
||||
import vim
|
||||
|
@ -5,48 +6,11 @@ import vim
|
|||
from datetime import datetime
|
||||
from tasklib.task import TaskWarrior, Task
|
||||
|
||||
# Unnamed building blocks
|
||||
UUID_UNNAMED = r'[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}'
|
||||
DUE_UNNAMED = r'\(\d{4}-\d\d-\d\d( \d\d:\d\d)?\)'
|
||||
SPACE_UNNAMED = r'\s*'
|
||||
NONEMPTY_SPACE_UNNAMED = r'\s+'
|
||||
FINAL_SEGMENT_SEPARATOR_UNNAMED = r'(\s+|$)'
|
||||
vim.command("echom '%s'" % vim.eval("s:plugin_path"))
|
||||
# update the sys path to include the jedi_vim script
|
||||
sys.path.insert(0, vim.eval("s:plugin_path") + "/taskwiki")
|
||||
|
||||
TEXT_FORBIDDEN_SUFFIXES = (
|
||||
r'\s', # Text cannot end with whitespace
|
||||
r' !', r' !!', r' !!!', # Any priority value
|
||||
r'\(\d{4}-\d\d-\d\d\)', r'\(\d{4}-\d\d-\d\d \d\d:\d\d\)', # Any datetime value
|
||||
r'\(\d{4}-\d\d-\d\d', # Any datetime value
|
||||
UUID_UNNAMED, # Text cannot end with UUID
|
||||
)
|
||||
|
||||
# Building blocks
|
||||
BRACKET_OPENING = re.escape('* [')
|
||||
BRACKET_CLOSING = re.escape('] ')
|
||||
EMPTY_SPACE = r'(?P<space>\s*)'
|
||||
UUID = r'(?P<uuid>{0})'.format(UUID_UNNAMED)
|
||||
DUE = r'(?P<due>{0})'.format(DUE_UNNAMED)
|
||||
UUID_COMMENT = '#{0}'.format(UUID)
|
||||
TEXT = r'(?P<text>.+' + ''.join(['(?<!%s)' % suffix for suffix in TEXT_FORBIDDEN_SUFFIXES]) + ')'
|
||||
COMPLETION_MARK = r'(?P<completed>.)'
|
||||
PRIORITY = r'(?P<priority>!{1,3})'
|
||||
|
||||
GENERIC_TASK = re.compile(''.join([
|
||||
EMPTY_SPACE,
|
||||
BRACKET_OPENING,
|
||||
COMPLETION_MARK,
|
||||
BRACKET_CLOSING,
|
||||
TEXT,
|
||||
FINAL_SEGMENT_SEPARATOR_UNNAMED,
|
||||
'(', PRIORITY, FINAL_SEGMENT_SEPARATOR_UNNAMED, ')?'
|
||||
'(', DUE, FINAL_SEGMENT_SEPARATOR_UNNAMED, ')?'
|
||||
'(', UUID_COMMENT, FINAL_SEGMENT_SEPARATOR_UNNAMED, ')?' # UUID is not there for new tasks
|
||||
]))
|
||||
|
||||
PROJECT_DEFINITION = re.compile(r'Project: (?P<project>.*)(?<!\s)')
|
||||
|
||||
DATETIME_FORMAT = "(%Y-%m-%d %H:%M)"
|
||||
DATE_FORMAT = "(%Y-%m-%d)"
|
||||
from regexp import *
|
||||
|
||||
"""
|
||||
How this plugin works:
|
||||
|
@ -62,6 +26,11 @@ tw = TaskWarrior()
|
|||
local_timezone = pytz.timezone('Europe/Bratislava')
|
||||
|
||||
class TaskCache(object):
|
||||
"""
|
||||
A cache that holds all the tasks in the given file and prevents
|
||||
multiple redundant taskwarrior calls.
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
self.cache = dict()
|
||||
|
||||
|
@ -75,6 +44,7 @@ class TaskCache(object):
|
|||
return task
|
||||
|
||||
def __iter__(self):
|
||||
# iterated_cache = {
|
||||
while self.cache.keys():
|
||||
for key in list(self.cache.keys()):
|
||||
task = self.cache[key]
|
||||
|
@ -86,6 +56,9 @@ class TaskCache(object):
|
|||
def reset(self):
|
||||
self.cache = dict()
|
||||
|
||||
# def update_tasks(self):
|
||||
# tasks = [t
|
||||
|
||||
cache = TaskCache()
|
||||
|
||||
|
||||
|
@ -294,6 +267,11 @@ def update_to_tw():
|
|||
task.update_in_buffer()
|
||||
|
||||
|
||||
class ViewPort(object):
|
||||
"""
|
||||
Represents viewport with a given filter.
|
||||
"""
|
||||
|
||||
if __name__ == '__main__':
|
||||
update_from_tw()
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue