Add support for literal segments to linter

This commit is contained in:
Foo 2015-05-17 14:58:18 +03:00
parent bfd9a21bbb
commit 72f8b59998
3 changed files with 45 additions and 3 deletions

View File

@ -172,6 +172,15 @@ Detailed description of used dictionary keys:
<config-themes-seg-after>`, :ref:`before <config-themes-seg-before>`) will <config-themes-seg-after>`, :ref:`before <config-themes-seg-before>`) will
be ignored. be ignored.
.. note::
If target is inclusion of the segment in powerline upstream all segment
functions that output *only* subsegments with ``literal_contents`` key
must contain the following string in documentation::
No highlight groups are used (literal segment).
String must be present on the separate line.
.. _dev-segments-draw_inner_divider: .. _dev-segments-draw_inner_divider:
``draw_hard_divider``, ``draw_soft_divider``, ``draw_inner_divider`` ``draw_hard_divider``, ``draw_soft_divider``, ``draw_inner_divider``

View File

@ -381,7 +381,10 @@ def check_segment_function(function_name, data, context, echoerr):
hl_groups = [] hl_groups = []
divider_hl_group = None divider_hl_group = None
hadproblem = False
if func.__doc__: if func.__doc__:
NO_H_G_USED_STR = 'No highlight groups are used (literal segment).'
H_G_USED_STR = 'Highlight groups used: ' H_G_USED_STR = 'Highlight groups used: '
LHGUS = len(H_G_USED_STR) LHGUS = len(H_G_USED_STR)
D_H_G_USED_STR = 'Divider highlight group used: ' D_H_G_USED_STR = 'Divider highlight group used: '
@ -391,6 +394,20 @@ def check_segment_function(function_name, data, context, echoerr):
for i, line in enumerate(func.__doc__.split('\n')): for i, line in enumerate(func.__doc__.split('\n')):
if H_G_USED_STR in line: if H_G_USED_STR in line:
idx = line.index(H_G_USED_STR) + LHGUS idx = line.index(H_G_USED_STR) + LHGUS
if hl_groups is None:
idx -= LHGUS
mark = Mark(mark_name, i + 1, idx + 1, func.__doc__, pointer + idx)
echoerr(
context='Error while checking theme (key {key})'.format(key=context.key),
context_mark=function_name.mark,
problem=(
'found highlight group definition in addition to sentense stating that '
'no highlight groups are used'
),
problem_mark=mark,
)
hadproblem = True
continue
hl_groups.append(( hl_groups.append((
line[idx:], line[idx:],
(mark_name, i + 1, idx + 1, func.__doc__), (mark_name, i + 1, idx + 1, func.__doc__),
@ -400,10 +417,24 @@ def check_segment_function(function_name, data, context, echoerr):
idx = line.index(D_H_G_USED_STR) + LDHGUS + 2 idx = line.index(D_H_G_USED_STR) + LDHGUS + 2
mark = Mark(mark_name, i + 1, idx + 1, func.__doc__, pointer + idx) mark = Mark(mark_name, i + 1, idx + 1, func.__doc__, pointer + idx)
divider_hl_group = MarkedUnicode(line[idx:-3], mark) divider_hl_group = MarkedUnicode(line[idx:-3], mark)
elif NO_H_G_USED_STR in line:
idx = line.index(NO_H_G_USED_STR)
if hl_groups:
mark = Mark(mark_name, i + 1, idx + 1, func.__doc__, pointer + idx)
echoerr(
context='Error while checking theme (key {key})'.format(key=context.key),
context_mark=function_name.mark,
problem=(
'found sentense stating that no highlight groups are used '
'in addition to highlight group definition'
),
problem_mark=mark,
)
hadproblem = True
continue
hl_groups = None
pointer += len(line) + len('\n') pointer += len(line) + len('\n')
hadproblem = False
if divider_hl_group: if divider_hl_group:
r = hl_exists(divider_hl_group, data, context, echoerr, allow_gradients=True) r = hl_exists(divider_hl_group, data, context, echoerr, allow_gradients=True)
if r: if r:
@ -466,7 +497,7 @@ def check_segment_function(function_name, data, context, echoerr):
h[0], list_sep.join(r)) h[0], list_sep.join(r))
) )
hadproblem = True hadproblem = True
else: elif hl_groups is not None:
r = hl_exists(function_name, data, context, echoerr, allow_gradients=True) r = hl_exists(function_name, data, context, echoerr, allow_gradients=True)
if r: if r:
echoerr( echoerr(

View File

@ -748,6 +748,8 @@ def tab(pl, segment_info, end=False):
:param bool end: :param bool end:
In place of starting region for the current tab end it. In place of starting region for the current tab end it.
No highlight groups are used (literal segment).
''' '''
try: try:
return [{ return [{