mirror of
https://github.com/tbabej/taskwiki.git
synced 2025-08-19 15:53:07 +02:00
taskwiki: Make taskwiki commands work on ranges
This commit is contained in:
parent
cfde8cc5b8
commit
82223ed2df
3 changed files with 24 additions and 8 deletions
|
@ -7,5 +7,5 @@ augroup taskwiki
|
|||
execute "autocmd BufWrite *.".expand('%:e')." python update_to_tw()"
|
||||
augroup END
|
||||
|
||||
command! TaskWikiInfo :py CurrentTask().info()
|
||||
command! TaskWikiLink :py CurrentTask().link()
|
||||
command! -range TaskWikiInfo :<line1>,<line2>py SelectedTasks().info()
|
||||
command! -range TaskWikiLink :<line1>,<line2>py SelectedTasks().link()
|
||||
|
|
|
@ -47,19 +47,32 @@ def update_to_tw():
|
|||
cache.update_buffer()
|
||||
cache.evaluate_viewports()
|
||||
|
||||
class CurrentTask(object):
|
||||
class SelectedTasks(object):
|
||||
def __init__(self):
|
||||
self.task = vwtask.VimwikiTask.from_current_line(cache)
|
||||
self.tw = tw
|
||||
|
||||
# Reset cache, otherwise old line content may be used
|
||||
cache.reset()
|
||||
|
||||
# Load the current tasks
|
||||
range_tasks = [vwtask.VimwikiTask.from_line(cache, i)
|
||||
for i in util.selected_line_numbers()]
|
||||
self.tasks = [t for t in range_tasks if t is not None]
|
||||
|
||||
if not self.tasks:
|
||||
print("No tasks selected.")
|
||||
|
||||
def info(self):
|
||||
info = self.tw.execute_command([self.task['uuid'], 'info'])
|
||||
for vimwikitask in self.tasks:
|
||||
info = self.tw.execute_command([vimwikitask['uuid'], 'info'])
|
||||
util.show_in_split(info)
|
||||
break # Show only one task
|
||||
|
||||
def link(self):
|
||||
path = util.get_absolute_filepath()
|
||||
self.task.task.add_annotation("wiki: {0}".format(path))
|
||||
print("Task \"{0}\" linked.".format(self.task['description']))
|
||||
for vimwikitask in self.tasks:
|
||||
vimwikitask.task.add_annotation("wiki: {0}".format(path))
|
||||
print("Task \"{0}\" linked.".format(vimwikitask['description']))
|
||||
|
||||
if __name__ == '__main__':
|
||||
update_from_tw()
|
||||
|
|
|
@ -72,6 +72,9 @@ def get_current_line_number():
|
|||
row, column = vim.current.window.cursor
|
||||
return row - 1
|
||||
|
||||
def selected_line_numbers():
|
||||
return range(vim.current.range.start, vim.current.range.end + 1)
|
||||
|
||||
def show_in_split(lines, size=None, position="belowright"):
|
||||
if size is None:
|
||||
size = len(lines)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue