diff --git a/taskwiki/decorators.py b/taskwiki/decorators.py new file mode 100644 index 0000000..70acd15 --- /dev/null +++ b/taskwiki/decorators.py @@ -0,0 +1,12 @@ +import vim # pylint: disable=F0401 + +def hold_vim_cursor(original_function): + """ + Decorator that wrap around to save cursor position and restore it + """ + + def wrapped_function(*args, **kwargs): + vim.command('let save_pos = getpos(".")') + original_function(*args, **kwargs) + vim.command('call setpos(".", save_pos)') + return wrapped_function diff --git a/taskwiki/main.py b/taskwiki/main.py index 058a1d3..f791a51 100644 --- a/taskwiki/main.py +++ b/taskwiki/main.py @@ -16,6 +16,7 @@ from taskwiki import cache as cache_module from taskwiki import sort from taskwiki import util from taskwiki import viewport +from taskwiki import decorators cache = cache_module.CacheRegistry() @@ -25,6 +26,7 @@ cache.load_current() class WholeBuffer(object): @staticmethod @errors.pretty_exception_handler + @decorators.hold_vim_cursor def update_from_tw(): """ Updates all the incomplete tasks in the vimwiki file if the info from TW is different. @@ -42,6 +44,7 @@ class WholeBuffer(object): @staticmethod @errors.pretty_exception_handler + @decorators.hold_vim_cursor def update_to_tw(): """ Updates all tasks that differ from their TaskWarrior representation.