mirror of
https://github.com/tbabej/taskwiki.git
synced 2025-08-20 01:03:06 +02:00
ftplugin: Only load the python plugin once
This makes opening wiki pages significantly faster and also prevents clearing the entire cache every time.
This commit is contained in:
parent
b722c29f9e
commit
f3fe7aca21
3 changed files with 30 additions and 7 deletions
|
@ -21,12 +21,18 @@ if exists("g:taskwiki_disable")
|
|||
finish
|
||||
endif
|
||||
|
||||
if !exists("g:did_python_taskwiki")
|
||||
" Determine the plugin path
|
||||
let s:plugin_path = escape(expand('<sfile>:p:h:h:h'), '\')
|
||||
|
||||
" Execute the main body of taskwiki source
|
||||
execute g:taskwiki_pyfile . s:plugin_path . '/taskwiki/main.py'
|
||||
|
||||
let g:did_python_taskwiki = 1
|
||||
endif
|
||||
|
||||
execute g:taskwiki_py . "WholeBuffer.update_from_tw()"
|
||||
|
||||
augroup taskwiki
|
||||
autocmd! * <buffer>
|
||||
" Update to TW upon saving
|
||||
|
|
|
@ -32,7 +32,7 @@ class WholeBuffer(object):
|
|||
Updates all the incomplete tasks in the vimwiki file if the info from TW is different.
|
||||
"""
|
||||
|
||||
c = cache()
|
||||
c = cache.load_current()
|
||||
c.reset()
|
||||
c.load_tasks()
|
||||
c.load_presets()
|
||||
|
@ -51,7 +51,7 @@ class WholeBuffer(object):
|
|||
Updates all tasks that differ from their TaskWarrior representation.
|
||||
"""
|
||||
|
||||
c = cache()
|
||||
c = cache.load_current()
|
||||
c.reset()
|
||||
c.load_tasks()
|
||||
c.load_presets()
|
||||
|
@ -637,6 +637,5 @@ class ChooseSplitTags(CallbackSplitMixin, SplitTags):
|
|||
|
||||
|
||||
if __name__ == '__main__':
|
||||
WholeBuffer.update_from_tw()
|
||||
Meta().integrate_tagbar()
|
||||
Meta().set_proper_colors()
|
||||
|
|
18
tests/test_ftplugin.py
Normal file
18
tests/test_ftplugin.py
Normal file
|
@ -0,0 +1,18 @@
|
|||
import os
|
||||
from tests.base import IntegrationTest
|
||||
|
||||
|
||||
class TestCachePreserved(IntegrationTest):
|
||||
|
||||
def execute(self):
|
||||
testfile2 = os.path.join(self.dir, "testwiki2.txt")
|
||||
|
||||
self.command("w", regex="written$", lines=1)
|
||||
self.command("w {}".format(testfile2), regex="written$", lines=1)
|
||||
|
||||
self.client.edit(testfile2)
|
||||
|
||||
# check that all buffers have a cache entry
|
||||
cache_keys = self.client.eval('py3eval("sorted(cache.caches.keys())")')
|
||||
buffers = self.client.eval('py3eval("sorted(b.number for b in vim.buffers)")')
|
||||
assert cache_keys == buffers
|
Loading…
Add table
Add a link
Reference in a new issue