Commit eaf382a0 authored by Jacek Sowiński's avatar Jacek Sowiński

Use "conditional characters" in list_format

These conditional characters should be specified **inside** curly braces
({}) and **after** percent sign (%). They can appear in two groups:
before and after particular placeholder.

Example:
"list_format = %{(}p{)}"

If priority of given todo is C, "list_format" set above will now resolve
to (C), but also won't display empty parentheses if there is no priority
set.

Fixes issue mentioned in 8650033b
parent a5fc3af3
......@@ -15,7 +15,7 @@ auto_creation_date = 1
hide_tags = id,p,ical
indent = 0
list_limit = -1
list_format = |%i| (%p) %s
list_format = |%i| %{(}p{)} %s
[tags]
tag_start = t
......
......@@ -69,7 +69,7 @@ class _Config:
'hide_tags': 'id,p,ical',
'indent': '0',
'list_limit': '-1',
'list_format': '|%i| (%p) %s',
'list_format': '|%i| %{(}p{)} %s',
},
'tags': {
......
......@@ -173,7 +173,37 @@ class PrettyPrinterFormatFilter(PrettyPrinterFilter):
p_todo_str = self.format
for placeholder, getter in placeholders.items():
p_todo_str = re.sub(r'%\[?{}\]?'.format(placeholder), getter(p_todo), p_todo_str)
repl = getter(p_todo)
pattern = (r'(?P<start>.*)'
r'%(?P<before>{{.+?}})?'
r'\[?(?P<placeholder>{})\]?'
r'(?P<after>{{.+?}})?'
r'(?P<whitespace>\s)*'
r'(?P<end>.*)').format(placeholder)
if repl == '':
p_todo_str = re.sub(pattern, match.group('start') + match.group('end'), p_todo_str)
else:
def strip_braces(p_matchobj):
try:
before = p_matchobj.group('before').strip('{}')
except AttributeError:
before = ''
placeholder = p_matchobj.group('placeholder')
try:
after = p_matchobj.group('after').strip('{}')
except AttributeError:
after = ''
whitespace = p_matchobj.group('whitespace') or ''
start = p_matchobj.group('start') or ''
end = p_matchobj.group('end') or ''
return start + before + '%' + placeholder + after + whitespace + end
p_todo_str = re.sub(pattern, strip_braces, p_todo_str)
p_todo_str = re.sub(r'%{}'.format(placeholder), repl, p_todo_str)
return p_todo_str
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment