@@ -86,6 +86,9 @@ function! vimwiki_tasks#read()
86
86
endif
87
87
let l: i += 1
88
88
endwhile
89
+ if vimwiki_tasks#config (' update_tasklists' , 1 )
90
+ call vimwiki_tasks#update_task_lists ()
91
+ endif
89
92
endfunction
90
93
91
94
function ! vimwiki_tasks#get_defaults ()
@@ -366,7 +369,11 @@ function! s:UuidsInBuffer()
366
369
return l: uuids
367
370
endfunction
368
371
369
- function ! vimwiki_tasks#insert_tasks (filter , bang )
372
+ " a:1 boolean, if 1 the tasklist filter will be inserted, otherwise not (not
373
+ " that the config parameter is also taken into account, but it can be
374
+ " overriden by setting a:1 to a value other than 1. This case is used during
375
+ " the updating of the taskslists where the filter should not be inserted again
376
+ function ! vimwiki_tasks#insert_tasks (filter , bang , line , ... )
370
377
echo " Loading tasks..."
371
378
redraw
372
379
let l: report = vimwiki_tasks#config (' report' , ' all' )
@@ -384,15 +391,24 @@ function! vimwiki_tasks#insert_tasks(filter, bang)
384
391
call add (l: lines , l: line )
385
392
endif
386
393
endfor
394
+ let l: num_added = 0
387
395
if len (l: lines ) > 0
388
- call append (line (' .' ), l: lines )
396
+ " XXX: check if current line is empty and replace it, otherwise
397
+ " append?
398
+ if vimwiki_tasks#config (' include_tasklist' , 1 ) && (a: 0 == 0 || a: 0 > 0 && a: 1 == 1 )
399
+ let l: num_added += 1
400
+ " TODO: add correct indent?
401
+ call append (a: line , ' %% TaskList: ' .a: filter )
402
+ endif
403
+ call append (a: line + l: num_added , l: lines )
389
404
" fix the indent of the new lines
390
405
exec " normal! " .(len (l: lines )+ 1 )." =="
391
406
redraw " get rid of the 'XX lines indented' message
392
407
" and set the '[ to the first new line
393
408
normal jm[
394
409
endif
395
410
echo " Inserted " .len (l: lines )." task(s)"
411
+ return len (l: lines ) + l: num_added
396
412
endfunction
397
413
398
414
function ! vimwiki_tasks#current_task_do (task_cmd)
@@ -413,3 +429,19 @@ function! vimwiki_tasks#current_task_do(task_cmd)
413
429
echo " Could not find a task on this line!"
414
430
endif
415
431
endfunction
432
+
433
+ function ! vimwiki_tasks#update_task_lists ()
434
+ let l: i = 1
435
+ while l: i <= line (' $' )
436
+ let l: line = getline (l: i )
437
+ let l: tasklist = matchstr (l: line , ' \v\%\%\s*TaskList:\s*\zs(.*$)' )
438
+ if l: tasklist != ' '
439
+ " ok we found a tasklist, try to add new tasks
440
+ let l: num_added = 0
441
+ let l: num_added += vimwiki_tasks#insert_tasks (l: tasklist , ' ' , l: i , 0 )
442
+ let l: i += l: num_added + 1
443
+ else
444
+ let l: i += 1
445
+ endif
446
+ endwhile
447
+ endfunction
0 commit comments