Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vwtask: honour tabstop setting #406

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions taskwiki/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ def __init__(self, number):
self.data = []
self.buffer_number = number

def options(self):
return util.get_buffer(self.buffer_number).options

def obtain(self):
self.data = util.get_buffer(self.buffer_number)[:]

Expand Down
3 changes: 2 additions & 1 deletion taskwiki/sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,9 @@ def build_indentation(self, indent):
self.vwtask['indent'] = ' ' * indent
self.vwtask.update_in_buffer()

tabstop = self.vwtask.cache.buffer.options()['tabstop']
for child in self.children:
child.build_indentation(indent + 4)
child.build_indentation(indent + tabstop)

def sort(self):
self.children.sort()
Expand Down
12 changes: 7 additions & 5 deletions taskwiki/vwtask.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,17 +340,19 @@ def __str__(self):
' #' + self.uuid.vim_representation(self.cache) if self.uuid else '',
])

def _normalise_indent(self, string):
tabstop = self.cache.buffer.options()['tabstop']
return string.replace('\t', ' ' * tabstop)

def find_parent_task(self):
# If this task is not indented, we have nothing to do here
if not self['indent']:
return None

for i in reversed(range(0, self['line_number'])):
# Tab is equal to four spaces
# TODO: Source this from tabstop setting, but this would be only
# useful for mixed tab/space indentations
indentation = len(self.cache.buffer[i].replace('\t', ' ')) - len(self.cache.buffer[i].lstrip())
indent = self['indent'].replace('\t', ' ')
line = self.cache.buffer[i]
indentation = len(self._normalise_indent(line)) - len(line.lstrip())
indent = self._normalise_indent(self['indent'])

if indentation < len(indent):
# The from_line constructor returns None if line doesn't match a task
Expand Down