Skip to content

Commit

Permalink
vwtask: honour tabstop setting
Browse files Browse the repository at this point in the history
This makes Taskwiki honour the value of `tabstop` set for the current
buffer instead of always rewriting the indentation of dependent tasks
with four spaces regardless of that setting.

Relates-to: 146d089
GitHub: closes tools-life#405
  • Loading branch information
pacien committed Mar 26, 2022
1 parent 925d8ed commit b25162b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
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

0 comments on commit b25162b

Please sign in to comment.