Skip to content

Commit 1e3ccb1

Browse files
liskintbabej
authored andcommitted
vwtags: Distinguish (tag kinds) between header, preset and viewport
For tagbar to correctly nest the tags, we need to remember kinds of parent scopes as well. This wasn't done in the original taskwiki implementation.
1 parent 07dc2b8 commit 1e3ccb1

3 files changed

Lines changed: 21 additions & 19 deletions

File tree

extra/vwtags.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,39 +15,41 @@
1515
def match_header(line, syntax):
1616
m = re.search(regexp.VIEWPORT[syntax], line)
1717
if m:
18-
return m
18+
return 'viewport', m
1919

2020
m = re.search(regexp.PRESET[syntax], line)
2121
if m:
22-
return m
22+
return 'preset', m
2323

2424
m = re.search(regexp.HEADER[syntax], line)
2525
if m:
26-
return m
26+
return 'header', m
2727

28-
return None
28+
return None, None
2929

3030

3131
def process(file_content, filename, syntax):
32-
state = [""]*6
32+
parents = [None] * 6
3333
for lnum, line in enumerate(file_content):
34-
m = match_header(line, syntax)
34+
cur_kind_long, m = match_header(line, syntax)
3535
if not m:
3636
continue
3737

38-
cur_lvl = len(m.group('header_start'))
38+
cur_lvl = len(m.group('header_start')) - 1
3939
cur_tag = m.group('name').strip()
4040
cur_searchterm = "^" + m.group(0).rstrip("\r\n") + "$"
41-
cur_kind = "h"
41+
cur_kind = cur_kind_long[0]
4242

43-
state[cur_lvl-1] = cur_tag
44-
for i in range(cur_lvl, 6):
45-
state[i] = ""
43+
assert cur_lvl < len(parents)
44+
parents[cur_lvl] = cur_kind_long, cur_tag
45+
for i in range(cur_lvl + 1, len(parents)):
46+
parents[i] = None
4647

47-
scope = "&&&".join(
48-
[state[i] for i in range(0, cur_lvl-1) if state[i] != ""])
48+
parent_scopes = [p for p in parents[0:cur_lvl] if p]
49+
scope = "&&&".join([tag for _, tag in parent_scopes])
4950
if scope:
50-
scope = "\theader:" + scope
51+
parent_kind, _ = parent_scopes[-1]
52+
scope = "\t" + parent_kind + ":" + scope
5153

5254
yield('{0}\t{1}\t/{2}/;"\t{3}\tline:{4}{5}'.format(
5355
cur_tag, filename, cur_searchterm, cur_kind, str(lnum+1), scope))

taskwiki/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,9 +346,9 @@ def integrate_tagbar(self):
346346
if tagbar_available:
347347
vim.vars['tagbar_type_vimwiki'] = {
348348
'ctagstype': 'default',
349-
'kinds': ['h:header'],
349+
'kinds': ['h:header', 'p:preset', 'v:viewport'],
350350
'sro': '&&&',
351-
'kind2scope': {'h': 'header'},
351+
'kind2scope': {'h': 'header', 'p': 'preset', 'v': 'viewport'},
352352
'sort': 0,
353353
'ctagsbin': os.path.join(BASE_DIR, 'extra/vwtags.py'),
354354
'ctagsargs': cache().markup_syntax

tests/test_vwtags.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ class TestTagsViewportsPresets(MultiSyntaxTagsTest):
7777

7878
expected_output = [
7979
re.compile(r"^a file.wiki /.*/;\" h line:1$"),
80-
re.compile(r"^b file.wiki /.*/;\" h line:2 header:a$"),
81-
re.compile(r"^c file.wiki /.*/;\" h line:3 header:a$"),
82-
re.compile(r"^d file.wiki /.*/;\" h line:4 header:a&&&c$"),
80+
re.compile(r"^b file.wiki /.*/;\" v line:2 header:a$"),
81+
re.compile(r"^c file.wiki /.*/;\" p line:3 header:a$"),
82+
re.compile(r"^d file.wiki /.*/;\" v line:4 preset:a&&&c$"),
8383
]
8484

8585

0 commit comments

Comments
 (0)