Skip to content

Commit 81b2d19

Browse files
committed
Adds TaskWikiOpen command
1 parent 377aac6 commit 81b2d19

5 files changed

Lines changed: 157 additions & 0 deletions

File tree

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: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,8 @@ vn m |:TaskWikiMod|
506506
n t |:TaskWikiTags|
507507
vn + |:TaskWikiStart|
508508
vn - |:TaskWikiStop|
509+
n o |:TaskWikiOpen|
510+
n n |:TaskWikiNote|
509511

510512
=============================================================================
511513
7. COMMANDS *taskwiki-commands*
@@ -604,6 +606,16 @@ selected tasks.
604606
*:TaskWikiMod* [mods]
605607
Opens a prompt for task modification, for selected task(s).
606608

609+
*:TaskWikiOpen*
610+
Opens annotations in the selected task(s) containing links to local files,
611+
urls, etc.
612+
613+
*:TaskWikiNote*
614+
Adds a note to the task under cursor and opens it to be edit. This command
615+
is compatible with the taskopen utility. See
616+
|taskwiki_taskopen_notes_folder|
617+
|taskwiki_taskopen_notes_regex|.
618+
607619
----------------------------------------------------------------------------
608620
Interactive commands.
609621

@@ -733,6 +745,13 @@ constructs.
733745
Example:
734746
let g:taskwiki_maplocalleader=",t"
735747

748+
*taskwiki_taskopen_notes_folder*
749+
The folder where taskopen has been configured to store notes. Defaults
750+
to $HOME/tasknotes ().
751+
752+
*taskwiki_taskopen_notes_regex*
753+
The annotation to add for tasks that have a note. Defaults to Notes.
754+
736755
=============================================================================
737756
9. TROUBLESHOOTING *taskwiki-trouble*
738757

ftplugin/vimwiki/taskwiki.vim

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

7272
" Commands that operate on tasks in the buffer
7373
execute "command! -buffer -range TaskWikiInfo :<line1>,<line2>" . g:taskwiki_py . "SelectedTasks().info()"
74+
execute "command! -buffer -range TaskWikiOpen :<line1>,<line2>" . g:taskwiki_py . "SelectedTasks().open()"
75+
execute "command! -buffer -range TaskWikiNote :<line1>,<line2>" . g:taskwiki_py . "SelectedTasks().note()"
7476
execute "command! -buffer -range TaskWikiEdit :<line1>,<line2>" . g:taskwiki_py . "SelectedTasks().edit()"
7577
execute "command! -buffer -range TaskWikiLink :<line1>,<line2>" . g:taskwiki_py . "SelectedTasks().link()"
7678
execute "command! -buffer -range TaskWikiGrid :<line1>,<line2>" . g:taskwiki_py . "SelectedTasks().grid()"
@@ -125,6 +127,8 @@ if !exists('g:taskwiki_suppress_mappings')
125127
nnoremap <silent><buffer> <LocalLeader>hm :TaskWikiHistoryMonthly<CR>
126128
nnoremap <silent><buffer> <LocalLeader>ha :TaskWikiHistoryAnnual<CR>
127129
nnoremap <silent><buffer> <LocalLeader>i :TaskWikiInfo<CR>
130+
nnoremap <silent><buffer> <LocalLeader>o :TaskWikiOpen<CR>
131+
nnoremap <silent><buffer> <LocalLeader>n :TaskWikiNote<CR>
128132
nnoremap <silent><buffer> <LocalLeader>l :TaskWikiLink<CR>
129133
nnoremap <silent><buffer> <LocalLeader>m :TaskWikiMod<CR>
130134
nnoremap <silent><buffer> <LocalLeader>p :TaskWikiProjects<CR>
@@ -144,6 +148,8 @@ if !exists('g:taskwiki_suppress_mappings')
144148
vnoremap <silent><buffer> <LocalLeader>e :TaskWikiEdit<CR>
145149
vnoremap <silent><buffer> <LocalLeader>g :TaskWikiGrid<CR>
146150
vnoremap <silent><buffer> <LocalLeader>i :TaskWikiInfo<CR>
151+
vnoremap <silent><buffer> <LocalLeader>o :TaskWikiOpen<CR>
152+
vnoremap <silent><buffer> <LocalLeader>n :TaskWikiNote<CR>
147153
vnoremap <silent><buffer> <LocalLeader>l :TaskWikiLink<CR>
148154
vnoremap <silent><buffer> <LocalLeader>m :TaskWikiMod<CR>
149155
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")
@@ -83,6 +84,14 @@ def __init__(self):
8384
if not self.tasks:
8485
print("No tasks selected.")
8586

87+
self.taskopen_notes_folder = (
88+
util.get_var("taskwiki_taskopen_notes_folder") or "~/tasknotes"
89+
)
90+
91+
self.taskopen_notes_regex = (
92+
util.get_var("taskwiki_taskopen_notes_regex") or "Notes"
93+
)
94+
8695
@classmethod
8796
def save_action(cls, method, *args):
8897
cls.last_action = {'method': method, 'args': args}
@@ -123,6 +132,34 @@ def info(self):
123132
util.show_in_split(out, name='info', activate_cursorline=True)
124133
break # Show only one task
125134

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

tests/test_selected.py

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

13301330
self.tasks[0].refresh()
13311331
assert self.tasks[0]['project'] == "Home"
1332+
1333+
1334+
class TestAddTaskNote(IntegrationTest):
1335+
1336+
viminput = """
1337+
* [ ] test task 1 #{uuid}
1338+
"""
1339+
1340+
vimoutput = """
1341+
* [ ] test task 1 #{uuid}
1342+
"""
1343+
1344+
tasks = [
1345+
dict(description="test task 1"),
1346+
]
1347+
1348+
def execute(self):
1349+
# Create a note
1350+
self.command("let g:taskwiki_taskopen_notes_folder='~'")
1351+
self.command(
1352+
"TaskWikiNote",
1353+
regex='Task "test task 1" annotated',
1354+
lines=3
1355+
)
1356+
self.command("w", silent=False)
1357+
self.command("bd", silent=False)
1358+
1359+
# Re-opening the note should not create a new one
1360+
self.command(
1361+
"TaskWikiNote",
1362+
regex=" 0L, 0C$"
1363+
)
1364+
self.command("w", silent=False)
1365+
self.command("bd", silent=False)
1366+
1367+
# Note should be listed in task annotations
1368+
self.command("TaskWikiInfo")
1369+
1370+
output = '\n'.join(self.read_buffer())
1371+
1372+
data = r"Annotation of 'Notes' added"
1373+
1374+
assert re.search(data, output, re.MULTILINE)
1375+
1376+
self.command("bd")
1377+
1378+
1379+
class TestTaskOpenWithNoAnnotation(IntegrationTest):
1380+
1381+
viminput = """
1382+
* [ ] test task 1 #{uuid}
1383+
"""
1384+
1385+
vimoutput = """
1386+
* [ ] test task 1 #{uuid}
1387+
"""
1388+
1389+
tasks = [
1390+
dict(description="test task 1"),
1391+
]
1392+
1393+
def execute(self):
1394+
self.command(
1395+
"TaskWikiOpen",
1396+
regex='No compatible annotation found.',
1397+
lines=1
1398+
)
1399+
1400+
1401+
class TestTaskOpenWithIncompatibleAnnotation(IntegrationTest):
1402+
1403+
viminput = """
1404+
* [ ] test task 1 #{uuid}
1405+
"""
1406+
1407+
vimoutput = """
1408+
* [ ] test task 1 #{uuid}
1409+
"""
1410+
1411+
tasks = [
1412+
dict(description="test task 1"),
1413+
]
1414+
1415+
def execute(self):
1416+
# Create an annotation
1417+
self.command(
1418+
"TaskWikiAnnotate what is this",
1419+
silent=False
1420+
)
1421+
self.command(
1422+
"TaskWikiOpen",
1423+
regex='No compatible annotation found.',
1424+
lines=1
1425+
)

0 commit comments

Comments
 (0)