Skip to content

Commit ee1be31

Browse files
nkakourosliskin
andcommitted
Adds TaskWikiOpen command
Co-authored-by: Tomáš Janoušek <[email protected]>
1 parent 925d8ed commit ee1be31

File tree

5 files changed

+160
-0
lines changed

5 files changed

+160
-0
lines changed

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ RUN apk add --no-cache \
6969
make \
7070
patchelf \
7171
tzdata \
72+
xdg-utils \
7273
xvfb-run
7374
RUN ln -sf /usr/share/zoneinfo/Etc/UTC /etc/localtime
7475

doc/taskwiki.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,8 @@ vn m |:TaskWikiMod|
531531
n t |:TaskWikiTags|
532532
vn + |:TaskWikiStart|
533533
vn - |:TaskWikiStop|
534+
n o |:TaskWikiOpen|
535+
n n |:TaskWikiNote|
534536

535537
=============================================================================
536538
7. COMMANDS *taskwiki-commands*
@@ -634,6 +636,19 @@ selected tasks.
634636

635637
Supports |cmdline-completion|.
636638

639+
*:TaskWikiOpen*
640+
Opens annotations in the selected task(s) containing links to local files,
641+
urls, etc.
642+
643+
*:TaskWikiNote*
644+
Adds a note to the task under cursor and opens it to be edit. This command
645+
is compatible with the taskopen utility (available at
646+
https://github.com/jschlatow/taskopen).
647+
648+
See:
649+
|taskwiki_taskopen_notes_folder|
650+
|taskwiki_taskopen_notes_regex|.
651+
637652
----------------------------------------------------------------------------
638653
Interactive commands.
639654

@@ -767,6 +782,13 @@ constructs.
767782
Example:
768783
let g:taskwiki_maplocalleader=",t"
769784

785+
*taskwiki_taskopen_notes_folder*
786+
The folder where taskopen has been configured to store notes. Defaults
787+
to $HOME/tasknotes ().
788+
789+
*taskwiki_taskopen_notes_regex*
790+
The annotation to add for tasks that have a note. Defaults to Notes.
791+
770792
=============================================================================
771793
9. TROUBLESHOOTING *taskwiki-trouble*
772794

ftplugin/vimwiki/taskwiki.vim

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ execute "command! -buffer -nargs=* TaskWikiTags :" . g:taskwiki_py .
7575

7676
" Commands that operate on tasks in the buffer
7777
execute "command! -buffer -range TaskWikiInfo :<line1>,<line2>" . g:taskwiki_py . "SelectedTasks().info()"
78+
execute "command! -buffer -range TaskWikiOpen :<line1>,<line2>" . g:taskwiki_py . "SelectedTasks().open()"
79+
execute "command! -buffer -range TaskWikiNote :<line1>,<line2>" . g:taskwiki_py . "SelectedTasks().note()"
7880
execute "command! -buffer -range TaskWikiEdit :<line1>,<line2>" . g:taskwiki_py . "SelectedTasks().edit()"
7981
execute "command! -buffer -range TaskWikiLink :<line1>,<line2>" . g:taskwiki_py . "SelectedTasks().link()"
8082
execute "command! -buffer -range TaskWikiGrid :<line1>,<line2>" . g:taskwiki_py . "SelectedTasks().grid()"
@@ -130,6 +132,8 @@ if !exists('g:taskwiki_suppress_mappings')
130132
nnoremap <silent><buffer> <LocalLeader>hm :TaskWikiHistoryMonthly<CR>
131133
nnoremap <silent><buffer> <LocalLeader>ha :TaskWikiHistoryAnnual<CR>
132134
nnoremap <silent><buffer> <LocalLeader>i :TaskWikiInfo<CR>
135+
nnoremap <silent><buffer> <LocalLeader>o :TaskWikiOpen<CR>
136+
nnoremap <silent><buffer> <LocalLeader>n :TaskWikiNote<CR>
133137
nnoremap <silent><buffer> <LocalLeader>l :TaskWikiLink<CR>
134138
nnoremap <silent><buffer> <LocalLeader>m :TaskWikiMod<CR>
135139
nnoremap <silent><buffer> <LocalLeader>p :TaskWikiProjects<CR>
@@ -149,6 +153,8 @@ if !exists('g:taskwiki_suppress_mappings')
149153
vnoremap <silent><buffer> <LocalLeader>e :TaskWikiEdit<CR>
150154
vnoremap <silent><buffer> <LocalLeader>g :TaskWikiGrid<CR>
151155
vnoremap <silent><buffer> <LocalLeader>i :TaskWikiInfo<CR>
156+
vnoremap <silent><buffer> <LocalLeader>o :TaskWikiOpen<CR>
157+
vnoremap <silent><buffer> <LocalLeader>n :TaskWikiNote<CR>
152158
vnoremap <silent><buffer> <LocalLeader>l :TaskWikiLink<CR>
153159
vnoremap <silent><buffer> <LocalLeader>m :TaskWikiMod<CR>
154160
vnoremap <silent><buffer> <LocalLeader>. :TaskWikiRedo<CR>

taskwiki/main.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import six
77
import sys
88
import vim # pylint: disable=F0401
9+
import subprocess
910

1011
# Insert the taskwiki on the python path
1112
BASE_DIR = vim.eval("s:plugin_path")
@@ -85,6 +86,14 @@ def __init__(self):
8586
if not self.tasks:
8687
print("No tasks selected.")
8788

89+
self.taskopen_notes_folder = (
90+
util.get_var("taskwiki_taskopen_notes_folder", default="~/tasknotes")
91+
)
92+
93+
self.taskopen_notes_regex = (
94+
util.get_var("taskwiki_taskopen_notes_regex") or "Notes"
95+
)
96+
8897
@classmethod
8998
def save_action(cls, method, *args):
9099
cls.last_action = {'method': method, 'args': args}
@@ -125,6 +134,34 @@ def info(self):
125134
util.show_in_split(out, name='info', activate_cursorline=True)
126135
break # Show only one task
127136

137+
@errors.pretty_exception_handler
138+
def open(self):
139+
compatible_annotation_found = False
140+
for vimwikitask in self.tasks:
141+
for annotation in vimwikitask.task["annotations"]:
142+
annotation = annotation["description"]
143+
proc = subprocess.Popen(["xdg-open", annotation])
144+
try:
145+
proc.wait(0.3)
146+
except subprocess.TimeoutExpired:
147+
compatible_annotation_found = True
148+
149+
if not compatible_annotation_found:
150+
print("No compatible annotation found.")
151+
152+
@errors.pretty_exception_handler
153+
def note(self):
154+
for vimwikitask in self.tasks:
155+
if self.taskopen_notes_regex not in [
156+
a["description"] for a in vimwikitask.task["annotations"]
157+
]:
158+
self.annotate(self.taskopen_notes_regex)
159+
160+
note_path = os.path.join(self.taskopen_notes_folder,
161+
vimwikitask.task["uuid"] + ".md")
162+
vim.command("edit " + note_path)
163+
break # Add not to only one task
164+
128165
@errors.pretty_exception_handler
129166
def edit(self):
130167
for vimwikitask in self.tasks:

tests/test_selected.py

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1372,3 +1372,97 @@ def execute(self):
13721372

13731373
self.tasks[0].refresh()
13741374
assert self.tasks[0]['project'] == "Home"
1375+
1376+
1377+
class TestAddTaskNote(IntegrationTest):
1378+
1379+
viminput = """
1380+
* [ ] test task 1 #{uuid}
1381+
"""
1382+
1383+
vimoutput = """
1384+
* [ ] test task 1 #{uuid}
1385+
"""
1386+
1387+
tasks = [
1388+
dict(description="test task 1"),
1389+
]
1390+
1391+
def execute(self):
1392+
# Create a note
1393+
self.command("let g:taskwiki_taskopen_notes_folder='~'")
1394+
self.command(
1395+
"TaskWikiNote",
1396+
regex='Task "test task 1" annotated',
1397+
lines=3
1398+
)
1399+
self.command("w", silent=False)
1400+
self.command("bd", silent=False)
1401+
1402+
# Re-opening the note should not create a new one
1403+
self.command(
1404+
"TaskWikiNote",
1405+
regex=" 0L, 0C$"
1406+
)
1407+
self.command("w", silent=False)
1408+
self.command("bd", silent=False)
1409+
1410+
# Note should be listed in task annotations
1411+
self.command("TaskWikiInfo")
1412+
1413+
output = '\n'.join(self.read_buffer())
1414+
1415+
data = r"Annotation of 'Notes' added"
1416+
1417+
assert re.search(data, output, re.MULTILINE)
1418+
1419+
self.command("bd")
1420+
1421+
1422+
class TestTaskOpenWithNoAnnotation(IntegrationTest):
1423+
1424+
viminput = """
1425+
* [ ] test task 1 #{uuid}
1426+
"""
1427+
1428+
vimoutput = """
1429+
* [ ] test task 1 #{uuid}
1430+
"""
1431+
1432+
tasks = [
1433+
dict(description="test task 1"),
1434+
]
1435+
1436+
def execute(self):
1437+
self.command(
1438+
"TaskWikiOpen",
1439+
regex='No compatible annotation found.',
1440+
lines=1
1441+
)
1442+
1443+
1444+
class TestTaskOpenWithIncompatibleAnnotation(IntegrationTest):
1445+
1446+
viminput = """
1447+
* [ ] test task 1 #{uuid}
1448+
"""
1449+
1450+
vimoutput = """
1451+
* [ ] test task 1 #{uuid}
1452+
"""
1453+
1454+
tasks = [
1455+
dict(description="test task 1"),
1456+
]
1457+
1458+
def execute(self):
1459+
# Create an annotation
1460+
self.command(
1461+
"TaskWikiAnnotate what is this",
1462+
silent=False
1463+
)
1464+
self.command(
1465+
"TaskWikiOpen",
1466+
regex='No compatible annotation found.',
1467+
lines=1
1468+
)

0 commit comments

Comments
 (0)