Skip to content

Commit 1b236f1

Browse files
committed
Adds TaskWikiOpen command
1 parent 377aac6 commit 1b236f1

5 files changed

Lines changed: 149 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: 15 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,15 @@ 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+
607618
----------------------------------------------------------------------------
608619
Interactive commands.
609620

@@ -733,6 +744,10 @@ constructs.
733744
Example:
734745
let g:taskwiki_maplocalleader=",t"
735746

747+
*taskwiki_taskopen_notes_folder*
748+
The folder where taskopen has been configured to store notes. Defaults
749+
to $HOME/tasknotes (taskopen default).
750+
736751
=============================================================================
737752
9. TROUBLESHOOTING *taskwiki-trouble*
738753

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: 33 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,10 @@ 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+
8691
@classmethod
8792
def save_action(cls, method, *args):
8893
cls.last_action = {'method': method, 'args': args}
@@ -123,6 +128,34 @@ def info(self):
123128
util.show_in_split(out, name='info', activate_cursorline=True)
124129
break # Show only one task
125130

131+
@errors.pretty_exception_handler
132+
def open(self):
133+
compatible_annotation_found = False
134+
for vimwikitask in self.tasks:
135+
for annotation in vimwikitask.task["annotations"]:
136+
annotation = annotation["description"]
137+
proc = subprocess.Popen(["xdg-open", annotation])
138+
try:
139+
proc.wait(0.3)
140+
except subprocess.TimeoutExpired:
141+
compatible_annotation_found = True
142+
143+
if not compatible_annotation_found:
144+
print("No compatible annotation found.")
145+
146+
@errors.pretty_exception_handler
147+
def note(self):
148+
for vimwikitask in self.tasks:
149+
if "Notes" not in [
150+
a["description"] for a in vimwikitask.task["annotations"]
151+
]:
152+
self.annotate("Notes")
153+
154+
note_path = os.path.join(self.taskopen_notes_folder,
155+
vimwikitask.task["uuid"] + ".md")
156+
vim.command("edit " + note_path)
157+
break # Add not to only one task
158+
126159
@errors.pretty_exception_handler
127160
def edit(self):
128161
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)